X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=disk%2Fpart_dos.c;h=cf1a36ebb826699e9b391f6d68a9fad0c5806430;hb=HEAD;hp=37087a6ac3b2e2ba6d9db2b250ac35d463142db3;hpb=412665b46134f93464c09405e02f08ac9c62526d;p=karo-tx-uboot.git diff --git a/disk/part_dos.c b/disk/part_dos.c index 37087a6ac3..cf1a36ebb8 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -3,23 +3,7 @@ * Raymond Lo, lo@routefree.com * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ /* @@ -37,6 +21,8 @@ #ifdef HAVE_BLOCK_DEVICE +#define DOS_PART_DEFAULT_SECTOR 512 + /* Convert char[4] in little endian format to the host format integer */ static inline int le32_to_int(unsigned char *le32) @@ -74,13 +60,26 @@ static void print_one_part(dos_partition_t *p, int ext_part_sector, static int test_block_type(unsigned char *buffer) { + int slot; + struct dos_partition *p; + if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) || (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) { return (-1); } /* no DOS Signature at all */ - if (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 || - strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0) { - return DOS_PBR; /* is PBR */ + p = (struct dos_partition *)&buffer[DOS_PART_TBL_OFFSET]; + for (slot = 0; slot < 3; slot++) { + if (p->boot_ind != 0 && p->boot_ind != 0x80) { + if (!slot && + (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET], + "FAT", 3) == 0 || + strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET], + "FAT32", 5) == 0)) { + return DOS_PBR; /* is PBR */ + } else { + return -1; + } + } } return DOS_MBR; /* Is MBR */ } @@ -171,6 +170,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); dos_partition_t *pt; int i; + int dos_type; if (dev_desc->block_read (dev_desc->dev, ext_part_sector, 1, (ulong *) buffer) != 1) { printf ("** Can't read partition table on %d:%d **\n", @@ -201,9 +201,10 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part (pt->sys_ind != 0) && (part_num == which_part) && (is_extended(pt->sys_ind) == 0)) { - info->blksz = 512; - info->start = ext_part_sector + le32_to_int (pt->start4); - info->size = le32_to_int (pt->size4); + info->blksz = DOS_PART_DEFAULT_SECTOR; + info->start = (lbaint_t)(ext_part_sector + + le32_to_int(pt->start4)); + info->size = (lbaint_t)le32_to_int(pt->size4); switch(dev_desc->if_type) { case IF_TYPE_IDE: case IF_TYPE_SATA: @@ -255,6 +256,22 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part part_num, which_part, info, disksig); } } + + /* Check for DOS PBR if no partition is found */ + dos_type = test_block_type(buffer); + + if (dos_type == DOS_PBR) { + info->start = 0; + info->size = dev_desc->lba; + info->blksz = DOS_PART_DEFAULT_SECTOR; + info->bootable = 0; + sprintf ((char *)info->type, "U-Boot"); +#ifdef CONFIG_PARTITION_UUIDS + info->uuid[0] = 0; +#endif + return 0; + } + return -1; }