summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-08-14 01:48:45 +0200
committerTom Rini <trini@konsulko.com>2023-08-22 15:17:52 -0400
commite2b5cc608b23418d5bcd5e2fe0b5d93593d02e97 (patch)
treef3a78e90fa17789164827111b166804ad3cea042 /disk
parent3f9cff669bbc4ed48ede1705fbaf671f3f4ce0e1 (diff)
downloadu-boot-e2b5cc608b23418d5bcd5e2fe0b5d93593d02e97.tar.gz
u-boot-e2b5cc608b23418d5bcd5e2fe0b5d93593d02e97.tar.bz2
u-boot-e2b5cc608b23418d5bcd5e2fe0b5d93593d02e97.zip
disk: dos: Infer MBR partition sector size from underlying drive sector size
Block devices with 4k sectors imply the MBR sectors are also 4k instead of regular 512B. Avoid hard-coding the 512B sector size and isntead read the current block device sector size from it, and if the sector size is larger than 512B, use the block device sector size. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'disk')
-rw-r--r--disk/part_dos.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 56e61884de..1b81297d96 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -207,8 +207,9 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
struct disk_partition *info, uint disksig)
{
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+ struct disk_partition wdinfo = { 0 };
dos_partition_t *pt;
- int i;
+ int i, ret;
int dos_type;
/* set a maximum recursion level */
@@ -236,6 +237,10 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]);
#endif
+ ret = part_get_info_whole_disk(dev_desc, &wdinfo);
+ if (ret)
+ return ret;
+
/* Print all primary/logical partitions */
pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET);
for (i = 0; i < 4; i++, pt++) {
@@ -247,7 +252,10 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
(pt->sys_ind != 0) &&
(part_num == which_part) &&
(ext_part_sector == 0 || is_extended(pt->sys_ind) == 0)) {
- info->blksz = DOS_PART_DEFAULT_SECTOR;
+ if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+ info->blksz = wdinfo.blksz;
+ else
+ info->blksz = DOS_PART_DEFAULT_SECTOR;
info->start = (lbaint_t)(ext_part_sector +
get_unaligned_le32(pt->start4));
info->size = (lbaint_t)get_unaligned_le32(pt->size4);
@@ -289,7 +297,10 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
if (dos_type == DOS_PBR) {
info->start = 0;
info->size = dev_desc->lba;
- info->blksz = DOS_PART_DEFAULT_SECTOR;
+ if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR)
+ info->blksz = wdinfo.blksz;
+ else
+ info->blksz = DOS_PART_DEFAULT_SECTOR;
info->bootable = 0;
strcpy((char *)info->type, "U-Boot");
#if CONFIG_IS_ENABLED(PARTITION_UUIDS)