diff mbox

[U-Boot] disk: part_dos.c: Add a PBR check when MBR checking fails

Message ID 1402026506-30461-1-git-send-email-darwin.dingel@alliedtelesis.co.nz
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Darwin Dingel June 6, 2014, 3:48 a.m. UTC
Bug: SDCard with a messed up partition but still has a FAT signature
intact is readable in Linux but unreadable in uboot with 'fatls'.

Fix: When partition info checking fails, there is no checking for a
FAT signature (DOS_PBR) which will fail 'fatls'. FAT signature checking
is done when no valid partition is found in partition table. If FAT
signature is found, the disk will be read as PBR and continue
processing.

Signed-off-by: Darwin Dingel <darwin.dingel@alliedtelesis.co.nz>
---
 disk/part_dos.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Tom Rini June 11, 2014, 10:18 p.m. UTC | #1
On Fri, Jun 06, 2014 at 03:48:26PM +1200, Darwin Dingel wrote:

> Bug: SDCard with a messed up partition but still has a FAT signature
> intact is readable in Linux but unreadable in uboot with 'fatls'.
> 
> Fix: When partition info checking fails, there is no checking for a
> FAT signature (DOS_PBR) which will fail 'fatls'. FAT signature checking
> is done when no valid partition is found in partition table. If FAT
> signature is found, the disk will be read as PBR and continue
> processing.
> 
> Signed-off-by: Darwin Dingel <darwin.dingel@alliedtelesis.co.nz>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 05c3933..3796aaa 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -21,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)
@@ -168,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",
@@ -198,7 +201,7 @@  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->blksz = DOS_PART_DEFAULT_SECTOR;
 			info->start = ext_part_sector + le32_to_int (pt->start4);
 			info->size  = le32_to_int (pt->size4);
 			switch(dev_desc->if_type) {
@@ -252,6 +255,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;
 }