From 5ff4609f855b9851af572f0ba9b66e8a5837fd8c Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:41 +0200 Subject: disk: Drop always true conditional check if (device_get_uclass_id(dev) == UCLASS_PARTITION) is always true, because this disk_blk_read() function calls dev_get_blk() above and checks its return value for non-NULL. The dev_get_blk() performs the same device_get_uclass_id(dev) check and returns NULL if not UCLASS_PARTITION. Drop the duplicate check. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index d32747e2242..5974dd8c2ec 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -186,10 +186,8 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t start, return -ENOSYS; start_in_disk = start; - if (device_get_uclass_id(dev) == UCLASS_PARTITION) { - part = dev_get_uclass_plat(dev); - start_in_disk += part->gpt_part_info.start; - } + part = dev_get_uclass_plat(dev); + start_in_disk += part->gpt_part_info.start; if (blkcache_read(desc->uclass_id, desc->devnum, start_in_disk, blkcnt, desc->blksz, buffer)) -- cgit v1.2.3 From 91d3066c907dedb3d45fd16e11f938bf46eafec7 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:42 +0200 Subject: disk: Simplify disk_blk_read() using blk_read() The disk_blk_read() can be simplified using blk_read(), the only things which needs to be handled are the read offset based on the partition properties, and the block device ops which are coming from the parent udevice, not the partition udevice. The later is currently not implemented correctly as far as I can tell, since the current code extracts block device descriptor from the parent udevice which is OK, but extracts block device operations from the partition udevice, which does not seem OK. Switching to the blk_read() fixes that too. The dev_get_blk() usage is simplified using UCLASS_PARTITION check. Add non-confusing documentation what this really does. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 5974dd8c2ec..6daece1288f 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -168,36 +168,26 @@ static struct blk_desc *dev_get_blk(struct udevice *dev) return desc; } +/** + * disk_blk_read() - Read from a block device partition + * + * @dev: Device to read from (partition udevice) + * @start: Start block for the read (from start of partition) + * @blkcnt: Number of blocks to read (within the partition) + * @buffer: Place to put the data + * @return number of blocks read (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ unsigned long disk_blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *buffer) { - struct blk_desc *desc; - const struct blk_ops *ops; - struct disk_part *part; - lbaint_t start_in_disk; - ulong blks_read; - - desc = dev_get_blk(dev); - if (!desc) - return -ENOSYS; + struct disk_part *part = dev_get_uclass_plat(dev); - ops = blk_get_ops(dev); - if (!ops->read) + if (device_get_uclass_id(dev) != UCLASS_PARTITION) return -ENOSYS; - start_in_disk = start; - part = dev_get_uclass_plat(dev); - start_in_disk += part->gpt_part_info.start; - - if (blkcache_read(desc->uclass_id, desc->devnum, start_in_disk, blkcnt, - desc->blksz, buffer)) - return blkcnt; - blks_read = ops->read(dev, start, blkcnt, buffer); - if (blks_read == blkcnt) - blkcache_fill(desc->uclass_id, desc->devnum, start_in_disk, - blkcnt, desc->blksz, buffer); - - return blks_read; + return blk_read(dev_get_parent(dev), start + part->gpt_part_info.start, + blkcnt, buffer); } unsigned long disk_blk_write(struct udevice *dev, lbaint_t start, -- cgit v1.2.3 From 9161c2c90d00c46e944cfeb4091230ec460a9981 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:43 +0200 Subject: disk: Simplify disk_blk_{write, erase}() using blk_{write, erase}() These two functions are basically identical, just call the blk_*() functions from disk_blk_*() functions. The only difference is that the disk_blk_*() functions have to use parent block device as the udevice implementing block device operations. Add documentation on what those functions really do. The documentation is not wrong even though it likely does look that way. The write/erase functions really do not take into account the partition offset. This will be fixed in the next patch. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 66 +++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 6daece1288f..5cb1594e015 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -149,25 +149,6 @@ U_BOOT_DRIVER(blk_partition) = { /* * BLOCK IO APIs */ -static struct blk_desc *dev_get_blk(struct udevice *dev) -{ - struct blk_desc *desc; - - switch (device_get_uclass_id(dev)) { - /* - * We won't support UCLASS_BLK with dev_* interfaces. - */ - case UCLASS_PARTITION: - desc = dev_get_uclass_plat(dev_get_parent(dev)); - break; - default: - desc = NULL; - break; - } - - return desc; -} - /** * disk_blk_read() - Read from a block device partition * @@ -190,42 +171,41 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t start, blkcnt, buffer); } +/** + * disk_blk_write() - Write to a block device + * + * @dev: Device to write to + * @start: Start block for the write + * @blkcnt: Number of blocks to write + * @buffer: Data to write + * @return number of blocks written (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ unsigned long disk_blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, const void *buffer) { - struct blk_desc *desc; - const struct blk_ops *ops; - - desc = dev_get_blk(dev); - if (!desc) - return -ENOSYS; - - ops = blk_get_ops(dev); - if (!ops->write) + if (device_get_uclass_id(dev) != UCLASS_PARTITION) return -ENOSYS; - blkcache_invalidate(desc->uclass_id, desc->devnum); - - return ops->write(dev, start, blkcnt, buffer); + return blk_write(dev_get_parent(dev), start, blkcnt, buffer); } +/** + * disk_blk_erase() - Erase part of a block device + * + * @dev: Device to erase + * @start: Start block for the erase + * @blkcnt: Number of blocks to erase + * @return number of blocks erased (which may be less than @blkcnt), + * or -ve on error. This never returns 0 unless @blkcnt is 0 + */ unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt) { - struct blk_desc *desc; - const struct blk_ops *ops; - - desc = dev_get_blk(dev); - if (!desc) - return -ENOSYS; - - ops = blk_get_ops(dev); - if (!ops->erase) + if (device_get_uclass_id(dev) != UCLASS_PARTITION) return -ENOSYS; - blkcache_invalidate(desc->uclass_id, desc->devnum); - - return ops->erase(dev, start, blkcnt); + return blk_erase(dev_get_parent(dev), start, blkcnt); } UCLASS_DRIVER(partition) = { -- cgit v1.2.3 From 2bc0dfef9f27c03f24784f4f2382079caff05df1 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:44 +0200 Subject: disk: Handle partition to block device offset conversion Convert the read/write/erase offset from one within a partition to one within a block device, to correctly access the data on the block device for both write and erase operations. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 68 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 16 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 5cb1594e015..32722cf9176 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -17,6 +17,36 @@ #include #include +/** + * disk_blk_part_validate() - Check whether access to partition is within limits + * + * @dev: Device (partition udevice) + * @start: Start block for the access(from start of partition) + * @blkcnt: Number of blocks to access (within the partition) + * @return 0 on valid block range, or -ve on error. + */ +static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, lbaint_t blkcnt) +{ + if (device_get_uclass_id(dev) != UCLASS_PARTITION) + return -ENOSYS; + + return 0; +} + +/** + * disk_blk_part_offset() - Compute offset from start of block device + * + * @dev: Device (partition udevice) + * @start: Start block for the access (from start of partition) + * @return Start block for the access (from start of block device) + */ +static lbaint_t disk_blk_part_offset(struct udevice *dev, lbaint_t start) +{ + struct disk_part *part = dev_get_uclass_plat(dev); + + return start + part->gpt_part_info.start; +} + int part_create_block_devices(struct udevice *blk_dev) { int part, count; @@ -162,21 +192,21 @@ U_BOOT_DRIVER(blk_partition) = { unsigned long disk_blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, void *buffer) { - struct disk_part *part = dev_get_uclass_plat(dev); + int ret = disk_blk_part_validate(dev, start, blkcnt); - if (device_get_uclass_id(dev) != UCLASS_PARTITION) - return -ENOSYS; + if (ret) + return ret; - return blk_read(dev_get_parent(dev), start + part->gpt_part_info.start, + return blk_read(dev_get_parent(dev), disk_blk_part_offset(dev, start), blkcnt, buffer); } /** * disk_blk_write() - Write to a block device * - * @dev: Device to write to - * @start: Start block for the write - * @blkcnt: Number of blocks to write + * @dev: Device to write to (partition udevice) + * @start: Start block for the write (from start of partition) + * @blkcnt: Number of blocks to write (within the partition) * @buffer: Data to write * @return number of blocks written (which may be less than @blkcnt), * or -ve on error. This never returns 0 unless @blkcnt is 0 @@ -184,28 +214,34 @@ unsigned long disk_blk_read(struct udevice *dev, lbaint_t start, unsigned long disk_blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, const void *buffer) { - if (device_get_uclass_id(dev) != UCLASS_PARTITION) - return -ENOSYS; + int ret = disk_blk_part_validate(dev, start, blkcnt); + + if (ret) + return ret; - return blk_write(dev_get_parent(dev), start, blkcnt, buffer); + return blk_write(dev_get_parent(dev), disk_blk_part_offset(dev, start), + blkcnt, buffer); } /** * disk_blk_erase() - Erase part of a block device * - * @dev: Device to erase - * @start: Start block for the erase - * @blkcnt: Number of blocks to erase + * @dev: Device to erase (partition udevice) + * @start: Start block for the erase (from start of partition) + * @blkcnt: Number of blocks to erase (within the partition) * @return number of blocks erased (which may be less than @blkcnt), * or -ve on error. This never returns 0 unless @blkcnt is 0 */ unsigned long disk_blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt) { - if (device_get_uclass_id(dev) != UCLASS_PARTITION) - return -ENOSYS; + int ret = disk_blk_part_validate(dev, start, blkcnt); + + if (ret) + return ret; - return blk_erase(dev_get_parent(dev), start, blkcnt); + return blk_erase(dev_get_parent(dev), disk_blk_part_offset(dev, start), + blkcnt); } UCLASS_DRIVER(partition) = { -- cgit v1.2.3 From bfd98b9a634e5922ca60597f59d83afdaa7c99ad Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:45 +0200 Subject: disk: Extend disk_blk_part_validate() with range checking Check whether access is out of bounds of the partition and return an error. This way there is no danger of esp. write or erase outside of the confines of partition. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 32722cf9176..f262105375b 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -27,9 +27,17 @@ */ static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, lbaint_t blkcnt) { + struct disk_part *part = dev_get_uclass_plat(dev); + if (device_get_uclass_id(dev) != UCLASS_PARTITION) return -ENOSYS; + if (start >= part->gpt_part_info.size) + return -E2BIG; + + if ((start + blkcnt) > part->gpt_part_info.size) + return -ERANGE; + return 0; } -- cgit v1.2.3 From 30a12e080104dc7cbdead7e9adc4f5ec4f7a3c40 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:46 +0200 Subject: disk: Switch part_blk_*() functions to disk_blk_*() The behavior of the part_blk_*() functions is now identical to disk_blk_*() functions, switch the former to the later. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 93 +++++++----------------------------------------------- 1 file changed, 12 insertions(+), 81 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index f262105375b..90a7c6f0f8a 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -103,87 +103,6 @@ int part_create_block_devices(struct udevice *blk_dev) return 0; } -static ulong part_blk_read(struct udevice *dev, lbaint_t start, - lbaint_t blkcnt, void *buffer) -{ - struct udevice *parent; - struct disk_part *part; - const struct blk_ops *ops; - - parent = dev_get_parent(dev); - ops = blk_get_ops(parent); - if (!ops->read) - return -ENOSYS; - - part = dev_get_uclass_plat(dev); - if (start >= part->gpt_part_info.size) - return 0; - - if ((start + blkcnt) > part->gpt_part_info.size) - blkcnt = part->gpt_part_info.size - start; - start += part->gpt_part_info.start; - - return ops->read(parent, start, blkcnt, buffer); -} - -static ulong part_blk_write(struct udevice *dev, lbaint_t start, - lbaint_t blkcnt, const void *buffer) -{ - struct udevice *parent; - struct disk_part *part; - const struct blk_ops *ops; - - parent = dev_get_parent(dev); - ops = blk_get_ops(parent); - if (!ops->write) - return -ENOSYS; - - part = dev_get_uclass_plat(dev); - if (start >= part->gpt_part_info.size) - return 0; - - if ((start + blkcnt) > part->gpt_part_info.size) - blkcnt = part->gpt_part_info.size - start; - start += part->gpt_part_info.start; - - return ops->write(parent, start, blkcnt, buffer); -} - -static ulong part_blk_erase(struct udevice *dev, lbaint_t start, - lbaint_t blkcnt) -{ - struct udevice *parent; - struct disk_part *part; - const struct blk_ops *ops; - - parent = dev_get_parent(dev); - ops = blk_get_ops(parent); - if (!ops->erase) - return -ENOSYS; - - part = dev_get_uclass_plat(dev); - if (start >= part->gpt_part_info.size) - return 0; - - if ((start + blkcnt) > part->gpt_part_info.size) - blkcnt = part->gpt_part_info.size - start; - start += part->gpt_part_info.start; - - return ops->erase(parent, start, blkcnt); -} - -static const struct blk_ops blk_part_ops = { - .read = part_blk_read, - .write = part_blk_write, - .erase = part_blk_erase, -}; - -U_BOOT_DRIVER(blk_partition) = { - .name = "blk_partition", - .id = UCLASS_PARTITION, - .ops = &blk_part_ops, -}; - /* * BLOCK IO APIs */ @@ -257,3 +176,15 @@ UCLASS_DRIVER(partition) = { .per_device_plat_auto = sizeof(struct disk_part), .name = "partition", }; + +static const struct blk_ops blk_part_ops = { + .read = disk_blk_read, + .write = disk_blk_write, + .erase = disk_blk_erase, +}; + +U_BOOT_DRIVER(blk_partition) = { + .name = "blk_partition", + .id = UCLASS_PARTITION, + .ops = &blk_part_ops, +}; -- cgit v1.2.3 From 804f7d63f26c00a64e2945fced4841abf200c0c0 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:46:47 +0200 Subject: disk: Move part_create_block_devices() to blk uclass Move part_create_block_devices() to blk uclass and unexpose the function. This can now be internal to the block uclass. Signed-off-by: Marek Vasut --- disk/disk-uclass.c | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) (limited to 'disk') diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 90a7c6f0f8a..efe4bf1f949 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -55,54 +55,6 @@ static lbaint_t disk_blk_part_offset(struct udevice *dev, lbaint_t start) return start + part->gpt_part_info.start; } -int part_create_block_devices(struct udevice *blk_dev) -{ - int part, count; - struct blk_desc *desc = dev_get_uclass_plat(blk_dev); - struct disk_partition info; - struct disk_part *part_data; - char devname[32]; - struct udevice *dev; - int ret; - - if (!CONFIG_IS_ENABLED(PARTITIONS) || !blk_enabled()) - return 0; - - if (device_get_uclass_id(blk_dev) != UCLASS_BLK) - return 0; - - /* Add devices for each partition */ - for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { - if (part_get_info(desc, part, &info)) - continue; - snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name, - part); - - ret = device_bind_driver(blk_dev, "blk_partition", - strdup(devname), &dev); - if (ret) - return ret; - - part_data = dev_get_uclass_plat(dev); - part_data->partnum = part; - part_data->gpt_part_info = info; - count++; - - ret = device_probe(dev); - if (ret) { - debug("Can't probe\n"); - count--; - device_unbind(dev); - - continue; - } - } - debug("%s: %d partitions found in %s\n", __func__, count, - blk_dev->name); - - return 0; -} - /* * BLOCK IO APIs */ -- cgit v1.2.3 From e2b5cc608b23418d5bcd5e2fe0b5d93593d02e97 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 14 Aug 2023 01:48:45 +0200 Subject: 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 Reviewed-by: Simon Glass --- disk/part_dos.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'disk') diff --git a/disk/part_dos.c b/disk/part_dos.c index 56e61884def..1b81297d967 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) -- cgit v1.2.3 From 5aab05d97e299635431fc833fdd4605cc7ebfe0b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:24 -0600 Subject: part: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the partition code to just use 'desc', as is done with driver model. Signed-off-by: Simon Glass --- disk/part.c | 178 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 86 insertions(+), 92 deletions(-) (limited to 'disk') diff --git a/disk/part.c b/disk/part.c index eec02f58988..8035dcb8a42 100644 --- a/disk/part.c +++ b/disk/part.c @@ -42,25 +42,25 @@ static struct part_driver *part_driver_get_type(int part_type) return NULL; } -static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc) +static struct part_driver *part_driver_lookup_type(struct blk_desc *desc) { struct part_driver *drv = ll_entry_start(struct part_driver, part_driver); const int n_ents = ll_entry_count(struct part_driver, part_driver); struct part_driver *entry; - if (dev_desc->part_type == PART_TYPE_UNKNOWN) { + if (desc->part_type == PART_TYPE_UNKNOWN) { for (entry = drv; entry != drv + n_ents; entry++) { int ret; - ret = entry->test(dev_desc); + ret = entry->test(desc); if (!ret) { - dev_desc->part_type = entry->part_type; + desc->part_type = entry->part_type; return entry; } } } else { - return part_driver_get_type(dev_desc->part_type); + return part_driver_get_type(desc->part_type); } /* Not found */ @@ -85,25 +85,25 @@ int part_get_type_by_name(const char *name) static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) { - struct blk_desc *dev_desc; + struct blk_desc *desc; int ret; if (!blk_enabled()) return NULL; - dev_desc = blk_get_devnum_by_uclass_idname(ifname, dev); - if (!dev_desc) { + desc = blk_get_devnum_by_uclass_idname(ifname, dev); + if (!desc) { debug("%s: No device for iface '%s', dev %d\n", __func__, ifname, dev); return NULL; } - ret = blk_dselect_hwpart(dev_desc, hwpart); + ret = blk_dselect_hwpart(desc, hwpart); if (ret) { debug("%s: Failed to select h/w partition: err-%d\n", __func__, ret); return NULL; } - return dev_desc; + return desc; } struct blk_desc *blk_get_dev(const char *ifname, int dev) @@ -140,29 +140,24 @@ static lba512_t lba512_muldiv(lba512_t block_count, lba512_t mul_by, return bc_quot * mul_by + ((bc_rem * mul_by) >> right_shift); } -void dev_print(struct blk_desc *dev_desc) +void dev_print(struct blk_desc *desc) { lba512_t lba512; /* number of blocks if 512bytes block size */ - if (dev_desc->type == DEV_TYPE_UNKNOWN) { + if (desc->type == DEV_TYPE_UNKNOWN) { puts ("not available\n"); return; } - switch (dev_desc->uclass_id) { + switch (desc->uclass_id) { case UCLASS_SCSI: - printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", - dev_desc->target,dev_desc->lun, - dev_desc->vendor, - dev_desc->product, - dev_desc->revision); + printf("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n", desc->target, + desc->lun, desc->vendor, desc->product, desc->revision); break; case UCLASS_IDE: case UCLASS_AHCI: - printf ("Model: %s Firm: %s Ser#: %s\n", - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); + printf("Model: %s Firm: %s Ser#: %s\n", desc->vendor, + desc->revision, desc->product); break; case UCLASS_MMC: case UCLASS_USB: @@ -171,27 +166,27 @@ void dev_print(struct blk_desc *dev_desc) case UCLASS_HOST: case UCLASS_BLKMAP: printf ("Vendor: %s Rev: %s Prod: %s\n", - dev_desc->vendor, - dev_desc->revision, - dev_desc->product); + desc->vendor, + desc->revision, + desc->product); break; case UCLASS_VIRTIO: - printf("%s VirtIO Block Device\n", dev_desc->vendor); + printf("%s VirtIO Block Device\n", desc->vendor); break; case UCLASS_EFI_MEDIA: - printf("EFI media Block Device %d\n", dev_desc->devnum); + printf("EFI media Block Device %d\n", desc->devnum); break; case UCLASS_INVALID: puts("device type unknown\n"); return; default: - printf("Unhandled device type: %i\n", dev_desc->uclass_id); + printf("Unhandled device type: %i\n", desc->uclass_id); return; } puts (" Type: "); - if (dev_desc->removable) + if (desc->removable) puts ("Removable "); - switch (dev_desc->type & 0x1F) { + switch (desc->type & 0x1F) { case DEV_TYPE_HARDDISK: puts ("Hard Disk"); break; @@ -205,17 +200,17 @@ void dev_print(struct blk_desc *dev_desc) puts ("Tape"); break; default: - printf ("# %02X #", dev_desc->type & 0x1F); + printf("# %02X #", desc->type & 0x1F); break; } puts ("\n"); - if (dev_desc->lba > 0L && dev_desc->blksz > 0L) { + if (desc->lba > 0L && desc->blksz > 0L) { ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem; lbaint_t lba; - lba = dev_desc->lba; + lba = desc->lba; - lba512 = (lba * (dev_desc->blksz/512)); + lba512 = lba * (desc->blksz / 512); /* round to 1 digit */ /* 2048 = (1024 * 1024) / 512 MB */ mb = lba512_muldiv(lba512, 10, 11); @@ -227,7 +222,7 @@ void dev_print(struct blk_desc *dev_desc) gb_quot = gb / 10; gb_rem = gb - (10 * gb_quot); #ifdef CONFIG_LBA48 - if (dev_desc->lba48) + if (desc->lba48) printf (" Supports 48-bit addressing\n"); #endif #if defined(CONFIG_SYS_64BIT_LBA) @@ -235,42 +230,42 @@ void dev_print(struct blk_desc *dev_desc) mb_quot, mb_rem, gb_quot, gb_rem, lba, - dev_desc->blksz); + desc->blksz); #else printf (" Capacity: %lu.%lu MB = %lu.%lu GB (%lu x %lu)\n", mb_quot, mb_rem, gb_quot, gb_rem, (ulong)lba, - dev_desc->blksz); + desc->blksz); #endif } else { puts (" Capacity: not available\n"); } } -void part_init(struct blk_desc *dev_desc) +void part_init(struct blk_desc *desc) { struct part_driver *drv = ll_entry_start(struct part_driver, part_driver); const int n_ents = ll_entry_count(struct part_driver, part_driver); struct part_driver *entry; - blkcache_invalidate(dev_desc->uclass_id, dev_desc->devnum); + blkcache_invalidate(desc->uclass_id, desc->devnum); - dev_desc->part_type = PART_TYPE_UNKNOWN; + desc->part_type = PART_TYPE_UNKNOWN; for (entry = drv; entry != drv + n_ents; entry++) { int ret; - ret = entry->test(dev_desc); + ret = entry->test(desc); debug("%s: try '%s': ret=%d\n", __func__, entry->name, ret); if (!ret) { - dev_desc->part_type = entry->part_type; + desc->part_type = entry->part_type; break; } } } -static void print_part_header(const char *type, struct blk_desc *dev_desc) +static void print_part_header(const char *type, struct blk_desc *desc) { #if CONFIG_IS_ENABLED(MAC_PARTITION) || \ CONFIG_IS_ENABLED(DOS_PARTITION) || \ @@ -278,7 +273,7 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc) CONFIG_IS_ENABLED(AMIGA_PARTITION) || \ CONFIG_IS_ENABLED(EFI_PARTITION) puts ("\nPartition Map for "); - switch (dev_desc->uclass_id) { + switch (desc->uclass_id) { case UCLASS_IDE: puts ("IDE"); break; @@ -314,28 +309,28 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc) break; } printf (" device %d -- Partition Type: %s\n\n", - dev_desc->devnum, type); + desc->devnum, type); #endif /* any CONFIG_..._PARTITION */ } -void part_print(struct blk_desc *dev_desc) +void part_print(struct blk_desc *desc) { struct part_driver *drv; - drv = part_driver_lookup_type(dev_desc); + drv = part_driver_lookup_type(desc); if (!drv) { printf("## Unknown partition table type %x\n", - dev_desc->part_type); + desc->part_type); return; } PRINTF("## Testing for valid %s partition ##\n", drv->name); - print_part_header(drv->name, dev_desc); + print_part_header(drv->name, desc); if (drv->print) - drv->print(dev_desc); + drv->print(desc); } -int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, +int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, struct disk_partition *info) { struct part_driver *drv; @@ -350,14 +345,14 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, #endif if (part_type == PART_TYPE_UNKNOWN) { - drv = part_driver_lookup_type(dev_desc); + drv = part_driver_lookup_type(desc); } else { drv = part_driver_get_type(part_type); } if (!drv) { debug("## Unknown partition table type %x\n", - dev_desc->part_type); + desc->part_type); return -EPROTONOSUPPORT; } if (!drv->get_info) { @@ -365,7 +360,7 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, drv->name); return -ENOSYS; } - if (drv->get_info(dev_desc, part, info) == 0) { + if (drv->get_info(desc, part, info) == 0) { PRINTF("## Valid %s partition found ##\n", drv->name); return 0; } @@ -374,18 +369,18 @@ int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type, return -ENOENT; } -int part_get_info(struct blk_desc *dev_desc, int part, +int part_get_info(struct blk_desc *desc, int part, struct disk_partition *info) { - return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info); + return part_get_info_by_type(desc, part, PART_TYPE_UNKNOWN, info); } -int part_get_info_whole_disk(struct blk_desc *dev_desc, +int part_get_info_whole_disk(struct blk_desc *desc, struct disk_partition *info) { info->start = 0; - info->size = dev_desc->lba; - info->blksz = dev_desc->blksz; + info->size = desc->lba; + info->blksz = desc->blksz; info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); @@ -400,7 +395,7 @@ int part_get_info_whole_disk(struct blk_desc *dev_desc, } int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, - struct blk_desc **dev_desc) + struct blk_desc **desc) { char *ep; char *dup_str = NULL; @@ -436,8 +431,8 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, } } - *dev_desc = get_dev_hwpart(ifname, dev, hwpart); - if (!(*dev_desc) || ((*dev_desc)->type == DEV_TYPE_UNKNOWN)) { + *desc = get_dev_hwpart(ifname, dev, hwpart); + if (!(*desc) || ((*desc)->type == DEV_TYPE_UNKNOWN)) { debug("** Bad device %s %s **\n", ifname, dev_hwpart_str); dev = -ENODEV; goto cleanup; @@ -449,8 +444,8 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str, * Always should be done, otherwise hw partition 0 will return * stale data after displaying a non-zero hw partition. */ - if ((*dev_desc)->uclass_id == UCLASS_MMC) - part_init(*dev_desc); + if ((*desc)->uclass_id == UCLASS_MMC) + part_init(*desc); } cleanup: @@ -461,7 +456,7 @@ cleanup: #define PART_UNSPECIFIED -2 #define PART_AUTO -1 int blk_get_device_part_str(const char *ifname, const char *dev_part_str, - struct blk_desc **dev_desc, + struct blk_desc **desc, struct disk_partition *info, int allow_whole_dev) { int ret; @@ -474,7 +469,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, int part; struct disk_partition tmpinfo; - *dev_desc = NULL; + *desc = NULL; memset(info, 0, sizeof(*info)); #if IS_ENABLED(CONFIG_SANDBOX) || IS_ENABLED(CONFIG_SEMIHOSTING) @@ -533,7 +528,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, } /* Look up the device */ - dev = blk_get_device_by_str(ifname, dev_str, dev_desc); + dev = blk_get_device_by_str(ifname, dev_str, desc); if (dev < 0) { printf("** Bad device specification %s %s **\n", ifname, dev_str); @@ -565,9 +560,8 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, * No partition table on device, * or user requested partition 0 (entire device). */ - if (((*dev_desc)->part_type == PART_TYPE_UNKNOWN) || - (part == 0)) { - if (!(*dev_desc)->lba) { + if (((*desc)->part_type == PART_TYPE_UNKNOWN) || !part) { + if (!(*desc)->lba) { printf("** Bad device size - %s %s **\n", ifname, dev_str); ret = -EINVAL; @@ -586,9 +580,9 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, goto cleanup; } - (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); + (*desc)->log2blksz = LOG2((*desc)->blksz); - part_get_info_whole_disk(*dev_desc, info); + part_get_info_whole_disk(*desc, info); ret = 0; goto cleanup; @@ -606,7 +600,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, * other than "auto", use that partition number directly. */ if (part != PART_AUTO) { - ret = part_get_info(*dev_desc, part, info); + ret = part_get_info(*desc, part, info); if (ret) { printf("** Invalid partition %d **\n", part); goto cleanup; @@ -618,7 +612,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, */ part = 0; for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { - ret = part_get_info(*dev_desc, p, info); + ret = part_get_info(*desc, p, info); if (ret) continue; @@ -662,7 +656,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str, goto cleanup; } - (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); + (*desc)->log2blksz = LOG2((*desc)->blksz); ret = part; goto cleanup; @@ -672,14 +666,14 @@ cleanup: return ret; } -int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, +int part_get_info_by_name(struct blk_desc *desc, const char *name, struct disk_partition *info) { struct part_driver *part_drv; int ret; int i; - part_drv = part_driver_lookup_type(dev_desc); + part_drv = part_driver_lookup_type(desc); if (!part_drv) return -1; @@ -690,7 +684,7 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, } for (i = 1; i < part_drv->max_entries; i++) { - ret = part_drv->get_info(dev_desc, i, info); + ret = part_drv->get_info(desc, i, info); if (ret != 0) { /* no more entries in table */ break; @@ -710,18 +704,18 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, * Parse a device number and partition name string in the form of * "devicenum.hwpartnum#partition_name", for example "0.1#misc". devicenum and * hwpartnum are both optional, defaulting to 0. If the partition is found, - * sets dev_desc and part_info accordingly with the information of the + * sets desc and part_info accordingly with the information of the * partition with the given partition_name. * * @param[in] dev_iface Device interface * @param[in] dev_part_str Input string argument, like "0.1#misc" - * @param[out] dev_desc Place to store the device description pointer + * @param[out] desc Place to store the device description pointer * @param[out] part_info Place to store the partition information * Return: 0 on success, or a negative on error */ static int part_get_info_by_dev_and_name(const char *dev_iface, const char *dev_part_str, - struct blk_desc **dev_desc, + struct blk_desc **desc, struct disk_partition *part_info) { char *dup_str = NULL; @@ -743,11 +737,11 @@ static int part_get_info_by_dev_and_name(const char *dev_iface, return -EINVAL; } - ret = blk_get_device_by_str(dev_iface, dev_str, dev_desc); + ret = blk_get_device_by_str(dev_iface, dev_str, desc); if (ret < 0) goto cleanup; - ret = part_get_info_by_name(*dev_desc, part_str, part_info); + ret = part_get_info_by_name(*desc, part_str, part_info); if (ret < 0) printf("Could not find \"%s\" partition\n", part_str); @@ -758,35 +752,35 @@ cleanup: int part_get_info_by_dev_and_name_or_num(const char *dev_iface, const char *dev_part_str, - struct blk_desc **dev_desc, + struct blk_desc **desc, struct disk_partition *part_info, int allow_whole_dev) { int ret; /* Split the part_name if passed as "$dev_num#part_name". */ - ret = part_get_info_by_dev_and_name(dev_iface, dev_part_str, - dev_desc, part_info); + ret = part_get_info_by_dev_and_name(dev_iface, dev_part_str, desc, + part_info); if (ret >= 0) return ret; /* * Couldn't lookup by name, try looking up the partition description * directly. */ - ret = blk_get_device_part_str(dev_iface, dev_part_str, - dev_desc, part_info, allow_whole_dev); + ret = blk_get_device_part_str(dev_iface, dev_part_str, desc, part_info, + allow_whole_dev); if (ret < 0) printf("Couldn't find partition %s %s\n", dev_iface, dev_part_str); return ret; } -void part_set_generic_name(const struct blk_desc *dev_desc, - int part_num, char *name) +void part_set_generic_name(const struct blk_desc *desc, int part_num, + char *name) { char *devtype; - switch (dev_desc->uclass_id) { + switch (desc->uclass_id) { case UCLASS_IDE: case UCLASS_AHCI: devtype = "hd"; @@ -805,7 +799,7 @@ void part_set_generic_name(const struct blk_desc *dev_desc, break; } - sprintf(name, "%s%c%d", devtype, 'a' + dev_desc->devnum, part_num); + sprintf(name, "%s%c%d", devtype, 'a' + desc->devnum, part_num); } int part_get_bootable(struct blk_desc *desc) -- cgit v1.2.3 From 3557e8d223cc84425fd6aa6e35a18ca03dcc2ab9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:25 -0600 Subject: part: amiga: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the amiga code to just use 'desc'. Signed-off-by: Simon Glass --- disk/part_amiga.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'disk') diff --git a/disk/part_amiga.c b/disk/part_amiga.c index 45d3a704866..65e30fea558 100644 --- a/disk/part_amiga.c +++ b/disk/part_amiga.c @@ -125,7 +125,7 @@ static void print_part_info(struct partition_block *p) * the ID AMIGA_ID_RDISK ('RDSK') and needs to have a valid * sum-to-zero checksum */ -struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc) +struct rigid_disk_block *get_rdisk(struct blk_desc *desc) { int i; int limit; @@ -139,7 +139,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc) for (i=0; i Date: Thu, 24 Aug 2023 13:55:26 -0600 Subject: part: dos: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the dos code to just use 'desc'. Signed-off-by: Simon Glass --- disk/part_dos.c | 63 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) (limited to 'disk') diff --git a/disk/part_dos.c b/disk/part_dos.c index 1b81297d967..cc050ca8c49 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -98,27 +98,26 @@ static int test_block_type(unsigned char *buffer) return -1; } -static int part_test_dos(struct blk_desc *dev_desc) +static int part_test_dos(struct blk_desc *desc) { #ifndef CONFIG_SPL_BUILD ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, - DIV_ROUND_UP(dev_desc->blksz, sizeof(legacy_mbr))); + DIV_ROUND_UP(desc->blksz, sizeof(legacy_mbr))); - if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) + if (blk_dread(desc, 0, 1, (ulong *)mbr) != 1) return -1; if (test_block_type((unsigned char *)mbr) != DOS_MBR) return -1; - if (dev_desc->sig_type == SIG_TYPE_NONE && - mbr->unique_mbr_signature != 0) { - dev_desc->sig_type = SIG_TYPE_MBR; - dev_desc->mbr_sig = mbr->unique_mbr_signature; + if (desc->sig_type == SIG_TYPE_NONE && mbr->unique_mbr_signature) { + desc->sig_type = SIG_TYPE_MBR; + desc->mbr_sig = mbr->unique_mbr_signature; } #else - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz); - if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1) + if (blk_dread(desc, 0, 1, (ulong *)buffer) != 1) return -1; if (test_block_type(buffer) != DOS_MBR) @@ -130,12 +129,12 @@ static int part_test_dos(struct blk_desc *dev_desc) /* Print a partition that is relative to its Extended partition table */ -static void print_partition_extended(struct blk_desc *dev_desc, +static void print_partition_extended(struct blk_desc *desc, lbaint_t ext_part_sector, lbaint_t relative, int part_num, unsigned int disksig) { - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz); dos_partition_t *pt; int i; @@ -146,9 +145,9 @@ static void print_partition_extended(struct blk_desc *dev_desc, return; } - if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) { + if (blk_dread(desc, ext_part_sector, 1, (ulong *)buffer) != 1) { printf ("** Can't read partition table on %d:" LBAFU " **\n", - dev_desc->devnum, ext_part_sector); + desc->devnum, ext_part_sector); return; } i=test_block_type(buffer); @@ -189,9 +188,9 @@ static void print_partition_extended(struct blk_desc *dev_desc, lbaint_t lba_start = get_unaligned_le32 (pt->start4) + relative; - print_partition_extended(dev_desc, lba_start, - ext_part_sector == 0 ? lba_start : relative, - part_num, disksig); + print_partition_extended(desc, lba_start, + !ext_part_sector ? lba_start : + relative, part_num, disksig); } } @@ -201,12 +200,12 @@ static void print_partition_extended(struct blk_desc *dev_desc, /* Print a partition that is relative to its Extended partition table */ -static int part_get_info_extended(struct blk_desc *dev_desc, +static int part_get_info_extended(struct blk_desc *desc, lbaint_t ext_part_sector, lbaint_t relative, int part_num, int which_part, struct disk_partition *info, uint disksig) { - ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, desc->blksz); struct disk_partition wdinfo = { 0 }; dos_partition_t *pt; int i, ret; @@ -219,9 +218,9 @@ static int part_get_info_extended(struct blk_desc *dev_desc, return -1; } - if (blk_dread(dev_desc, ext_part_sector, 1, (ulong *)buffer) != 1) { + if (blk_dread(desc, ext_part_sector, 1, (ulong *)buffer) != 1) { printf ("** Can't read partition table on %d:" LBAFU " **\n", - dev_desc->devnum, ext_part_sector); + desc->devnum, ext_part_sector); return -1; } if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 || @@ -237,7 +236,7 @@ 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); + ret = part_get_info_whole_disk(desc, &wdinfo); if (ret) return ret; @@ -259,7 +258,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc, info->start = (lbaint_t)(ext_part_sector + get_unaligned_le32(pt->start4)); info->size = (lbaint_t)get_unaligned_le32(pt->size4); - part_set_generic_name(dev_desc, part_num, + part_set_generic_name(desc, part_num, (char *)info->name); /* sprintf(info->type, "%d, pt->sys_ind); */ strcpy((char *)info->type, "U-Boot"); @@ -285,7 +284,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc, lbaint_t lba_start = get_unaligned_le32 (pt->start4) + relative; - return part_get_info_extended(dev_desc, lba_start, + return part_get_info_extended(desc, lba_start, ext_part_sector == 0 ? lba_start : relative, part_num, which_part, info, disksig); } @@ -296,7 +295,7 @@ 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->size = desc->lba; if (wdinfo.blksz > DOS_PART_DEFAULT_SECTOR) info->blksz = wdinfo.blksz; else @@ -312,16 +311,16 @@ static int part_get_info_extended(struct blk_desc *dev_desc, return -1; } -static void __maybe_unused part_print_dos(struct blk_desc *dev_desc) +static void __maybe_unused part_print_dos(struct blk_desc *desc) { printf("Part\tStart Sector\tNum Sectors\tUUID\t\tType\n"); - print_partition_extended(dev_desc, 0, 0, 1, 0); + print_partition_extended(desc, 0, 0, 1, 0); } -static int __maybe_unused part_get_info_dos(struct blk_desc *dev_desc, int part, - struct disk_partition *info) +static int __maybe_unused part_get_info_dos(struct blk_desc *desc, int part, + struct disk_partition *info) { - return part_get_info_extended(dev_desc, 0, 0, 1, part, info, 0); + return part_get_info_extended(desc, 0, 0, 1, part, info, 0); } int is_valid_dos_buf(void *buf) @@ -501,20 +500,20 @@ int layout_mbr_partitions(struct disk_partition *p, int count, } #endif -int write_mbr_sector(struct blk_desc *dev_desc, void *buf) +int write_mbr_sector(struct blk_desc *desc, void *buf) { if (is_valid_dos_buf(buf)) return -1; /* write MBR */ - if (blk_dwrite(dev_desc, 0, 1, buf) != 1) { + if (blk_dwrite(desc, 0, 1, buf) != 1) { printf("%s: failed writing '%s' (1 blks at 0x0)\n", __func__, "MBR"); return 1; } /* Update the partition table entries*/ - part_init(dev_desc); + part_init(desc); return 0; } -- cgit v1.2.3 From 7ed781fb4ce0292902f325ac07e4120233a87d4c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:27 -0600 Subject: part: efi: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the efi code to just use 'desc'. Signed-off-by: Simon Glass --- disk/part_efi.c | 228 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 112 insertions(+), 116 deletions(-) (limited to 'disk') diff --git a/disk/part_efi.c b/disk/part_efi.c index 80a44dc9f07..4ac21868d08 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -51,12 +51,12 @@ static inline u32 efi_crc32(const void *buf, u32 len) static int pmbr_part_valid(struct partition *part); static int is_pmbr_valid(legacy_mbr * mbr); -static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, - gpt_header *pgpt_head, gpt_entry **pgpt_pte); -static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, +static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, + gpt_entry **pgpt_pte); +static gpt_entry *alloc_read_gpt_entries(struct blk_desc *desc, gpt_header *pgpt_head); static int is_pte_valid(gpt_entry * pte); -static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, +static int find_valid_gpt(struct blk_desc *desc, gpt_header *gpt_head, gpt_entry **pgpt_pte); static char *print_efiname(gpt_entry *pte) @@ -195,14 +195,14 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h) * UUID is displayed as 32 hexadecimal digits, in 5 groups, * separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters */ -int get_disk_guid(struct blk_desc * dev_desc, char *guid) +int get_disk_guid(struct blk_desc *desc, char *guid) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); gpt_entry *gpt_pte = NULL; unsigned char *guid_bin; /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) return -EINVAL; guid_bin = gpt_head->disk_guid.b; @@ -213,15 +213,15 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid) return 0; } -void part_print_efi(struct blk_desc *dev_desc) +void part_print_efi(struct blk_desc *desc) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); gpt_entry *gpt_pte = NULL; int i = 0; unsigned char *uuid; /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) return; debug("%s: gpt-entry at %p\n", __func__, gpt_pte); @@ -255,10 +255,10 @@ void part_print_efi(struct blk_desc *dev_desc) return; } -int part_get_info_efi(struct blk_desc *dev_desc, int part, +int part_get_info_efi(struct blk_desc *desc, int part, struct disk_partition *info) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, desc->blksz); gpt_entry *gpt_pte = NULL; /* "part" argument must be at least 1 */ @@ -268,7 +268,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, } /* This function validates AND fills in the GPT header and PTE */ - if (find_valid_gpt(dev_desc, gpt_head, &gpt_pte) != 1) + if (find_valid_gpt(desc, gpt_head, &gpt_pte) != 1) return -EINVAL; if (part > le32_to_cpu(gpt_head->num_partition_entries) || @@ -283,7 +283,7 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, /* The ending LBA is inclusive, to calculate size, add 1 to it */ info->size = (lbaint_t)le64_to_cpu(gpt_pte[part - 1].ending_lba) + 1 - info->start; - info->blksz = dev_desc->blksz; + info->blksz = desc->blksz; snprintf((char *)info->name, sizeof(info->name), "%s", print_efiname(&gpt_pte[part - 1])); @@ -306,12 +306,12 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part, return 0; } -static int part_test_efi(struct blk_desc *dev_desc) +static int part_test_efi(struct blk_desc *desc) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, desc->blksz); /* Read legacy MBR from block 0 and validate it */ - if ((blk_dread(dev_desc, 0, 1, (ulong *)legacymbr) != 1) + if ((blk_dread(desc, 0, 1, (ulong *)legacymbr) != 1) || (is_pmbr_valid(legacymbr) != 1)) { return -1; } @@ -320,23 +320,23 @@ static int part_test_efi(struct blk_desc *dev_desc) /** * set_protective_mbr(): Set the EFI protective MBR - * @param dev_desc - block device descriptor + * @param desc - block device descriptor * * Return: - zero on success, otherwise error */ -static int set_protective_mbr(struct blk_desc *dev_desc) +static int set_protective_mbr(struct blk_desc *desc) { /* Setup the Protective MBR */ - ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, p_mbr, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, p_mbr, 1, desc->blksz); if (p_mbr == NULL) { log_debug("calloc failed!\n"); return -ENOMEM; } /* Read MBR to backup boot code if it exists */ - if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) { + if (blk_dread(desc, 0, 1, p_mbr) != 1) { log_debug("** Can't read from device %d **\n", - dev_desc->devnum); + desc->devnum); return -EIO; } @@ -348,27 +348,26 @@ static int set_protective_mbr(struct blk_desc *dev_desc) p_mbr->signature = MSDOS_MBR_SIGNATURE; p_mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT; p_mbr->partition_record[0].start_sect = 1; - p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1; + p_mbr->partition_record[0].nr_sects = (u32)desc->lba - 1; /* Write MBR sector to the MMC device */ - if (blk_dwrite(dev_desc, 0, 1, p_mbr) != 1) { - log_debug("** Can't write to device %d **\n", dev_desc->devnum); + if (blk_dwrite(desc, 0, 1, p_mbr) != 1) { + log_debug("** Can't write to device %d **\n", desc->devnum); return -EIO; } return 0; } -int write_gpt_table(struct blk_desc *dev_desc, - gpt_header *gpt_h, gpt_entry *gpt_e) +int write_gpt_table(struct blk_desc *desc, gpt_header *gpt_h, gpt_entry *gpt_e) { const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries - * sizeof(gpt_entry)), dev_desc); + * sizeof(gpt_entry)), desc); u32 calc_crc32; - debug("max lba: %x\n", (u32) dev_desc->lba); + debug("max lba: %x\n", (u32)desc->lba); /* Setup the Protective MBR */ - if (set_protective_mbr(dev_desc) < 0) + if (set_protective_mbr(desc) < 0) goto err; /* Generate CRC for the Primary GPT Header */ @@ -382,20 +381,20 @@ int write_gpt_table(struct blk_desc *dev_desc, gpt_h->header_crc32 = cpu_to_le32(calc_crc32); /* Write the First GPT to the block right after the Legacy MBR */ - if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) + if (blk_dwrite(desc, 1, 1, gpt_h) != 1) goto err; - if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), + if (blk_dwrite(desc, le64_to_cpu(gpt_h->partition_entry_lba), pte_blk_cnt, gpt_e) != pte_blk_cnt) goto err; prepare_backup_gpt_header(gpt_h); - if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) + if (blk_dwrite(desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) + 1, pte_blk_cnt, gpt_e) != pte_blk_cnt) goto err; - if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, + if (blk_dwrite(desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, gpt_h) != 1) goto err; @@ -403,11 +402,11 @@ int write_gpt_table(struct blk_desc *dev_desc, return 0; err: - log_debug("** Can't write to device %d **\n", dev_desc->devnum); + log_debug("** Can't write to device %d **\n", desc->devnum); return -EIO; } -int gpt_fill_pte(struct blk_desc *dev_desc, +int gpt_fill_pte(struct blk_desc *desc, gpt_header *gpt_h, gpt_entry *gpt_e, struct disk_partition *partitions, int parts) { @@ -430,7 +429,7 @@ int gpt_fill_pte(struct blk_desc *dev_desc, size_t pte_start = gpt_h->partition_entry_lba; size_t pte_end = pte_start + gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / - dev_desc->blksz; + desc->blksz; for (i = 0; i < parts; i++) { /* partition starting lba */ @@ -527,7 +526,7 @@ int gpt_fill_pte(struct blk_desc *dev_desc, return 0; } -static uint32_t partition_entries_offset(struct blk_desc *dev_desc) +static uint32_t partition_entries_offset(struct blk_desc *desc) { uint32_t offset_blks = 2; uint32_t __maybe_unused offset_bytes; @@ -543,8 +542,8 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc) * CONFIG_EFI_PARTITION_ENTRIES_OFF. */ offset_bytes = - PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc); - offset_blks = offset_bytes / dev_desc->blksz; + PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, desc); + offset_blks = offset_bytes / desc->blksz; #endif #if defined(CONFIG_OF_CONTROL) @@ -556,8 +555,8 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc) config_offset = ofnode_conf_read_int( "u-boot,efi-partition-entries-offset", -EINVAL); if (config_offset != -EINVAL) { - offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc); - offset_blks = offset_bytes / dev_desc->blksz; + offset_bytes = PAD_TO_BLOCKSIZE(config_offset, desc); + offset_blks = offset_bytes / desc->blksz; } #endif @@ -573,17 +572,17 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc) return offset_blks; } -int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, - char *str_guid, int parts_count) +int gpt_fill_header(struct blk_desc *desc, gpt_header *gpt_h, char *str_guid, + int parts_count) { gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT); gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); gpt_h->my_lba = cpu_to_le64(1); - gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); - gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); + gpt_h->alternate_lba = cpu_to_le64(desc->lba - 1); + gpt_h->last_usable_lba = cpu_to_le64(desc->lba - 34); gpt_h->partition_entry_lba = - cpu_to_le64(partition_entries_offset(dev_desc)); + cpu_to_le64(partition_entries_offset(desc)); gpt_h->first_usable_lba = cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); @@ -597,14 +596,14 @@ int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, return 0; } -int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, +int gpt_restore(struct blk_desc *desc, char *str_disk_guid, struct disk_partition *partitions, int parts_count) { gpt_header *gpt_h; gpt_entry *gpt_e; int ret, size; - size = PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc); + size = PAD_TO_BLOCKSIZE(sizeof(gpt_header), desc); gpt_h = malloc_cache_aligned(size); if (gpt_h == NULL) { log_debug("calloc failed!\n"); @@ -613,7 +612,7 @@ int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, memset(gpt_h, 0, size); size = PAD_TO_BLOCKSIZE(GPT_ENTRY_NUMBERS * sizeof(gpt_entry), - dev_desc); + desc); gpt_e = malloc_cache_aligned(size); if (gpt_e == NULL) { log_debug("calloc failed!\n"); @@ -623,17 +622,17 @@ int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, memset(gpt_e, 0, size); /* Generate Primary GPT header (LBA1) */ - ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); + ret = gpt_fill_header(desc, gpt_h, str_disk_guid, parts_count); if (ret) goto err; /* Generate partition entries */ - ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); + ret = gpt_fill_pte(desc, gpt_h, gpt_e, partitions, parts_count); if (ret) goto err; /* Write GPT partition table */ - ret = write_gpt_table(dev_desc, gpt_h, gpt_e); + ret = write_gpt_table(desc, gpt_h, gpt_e); err: free(gpt_e); @@ -664,14 +663,14 @@ static void gpt_convert_efi_name_to_char(char *s, void *es, int n) } } -int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, +int gpt_verify_headers(struct blk_desc *desc, gpt_header *gpt_head, gpt_entry **gpt_pte) { /* * This function validates AND * fills in the GPT header and PTE */ - if (is_gpt_valid(dev_desc, + if (is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, gpt_pte) != 1) { log_debug("Invalid GPT\n"); @@ -684,12 +683,12 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, /* * Check that the alternate_lba entry points to the last LBA */ - if (le64_to_cpu(gpt_head->alternate_lba) != (dev_desc->lba - 1)) { + if (le64_to_cpu(gpt_head->alternate_lba) != (desc->lba - 1)) { log_debug("Misplaced Backup GPT\n"); return -1; } - if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), + if (is_gpt_valid(desc, (desc->lba - 1), gpt_head, gpt_pte) != 1) { log_debug("Invalid Backup GPT\n"); return -1; @@ -698,7 +697,7 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, return 0; } -static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_desc) +static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *desc) { u32 calc_crc32; u64 val; @@ -707,7 +706,7 @@ static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_d val = le64_to_cpu(gpt_h->my_lba); gpt_h->my_lba = gpt_h->alternate_lba; gpt_h->alternate_lba = cpu_to_le64(val); - gpt_h->partition_entry_lba = cpu_to_le64(partition_entries_offset(dev_desc)); + gpt_h->partition_entry_lba = cpu_to_le64(partition_entries_offset(desc)); gpt_h->header_crc32 = 0; @@ -716,22 +715,22 @@ static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_d gpt_h->header_crc32 = cpu_to_le32(calc_crc32); } -static int write_one_gpt_table(struct blk_desc *dev_desc, - gpt_header *gpt_h, gpt_entry *gpt_e) +static int write_one_gpt_table(struct blk_desc *desc, gpt_header *gpt_h, + gpt_entry *gpt_e) { const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries - * sizeof(gpt_entry)), dev_desc); + * sizeof(gpt_entry)), desc); lbaint_t start; int ret = 0; start = le64_to_cpu(gpt_h->my_lba); - if (blk_dwrite(dev_desc, start, 1, gpt_h) != 1) { + if (blk_dwrite(desc, start, 1, gpt_h) != 1) { ret = -1; goto out; } start = le64_to_cpu(gpt_h->partition_entry_lba); - if (blk_dwrite(dev_desc, start, pte_blk_cnt, gpt_e) != pte_blk_cnt) { + if (blk_dwrite(desc, start, pte_blk_cnt, gpt_e) != pte_blk_cnt) { ret = -1; goto out; } @@ -740,17 +739,17 @@ static int write_one_gpt_table(struct blk_desc *dev_desc, return ret; } -int gpt_repair_headers(struct blk_desc *dev_desc) +int gpt_repair_headers(struct blk_desc *desc) { - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h1, 1, dev_desc->blksz); - ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h2, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h1, 1, desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_h2, 1, desc->blksz); gpt_entry *gpt_e1 = NULL, *gpt_e2 = NULL; int is_gpt1_valid, is_gpt2_valid; int ret = -1; - is_gpt1_valid = is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, + is_gpt1_valid = is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_h1, &gpt_e1); - is_gpt2_valid = is_gpt_valid(dev_desc, dev_desc->lba - 1, + is_gpt2_valid = is_gpt_valid(desc, desc->lba - 1, gpt_h2, &gpt_e2); if (is_gpt1_valid && is_gpt2_valid) { @@ -760,13 +759,13 @@ int gpt_repair_headers(struct blk_desc *dev_desc) if (is_gpt1_valid && !is_gpt2_valid) { prepare_backup_gpt_header(gpt_h1); - ret = write_one_gpt_table(dev_desc, gpt_h1, gpt_e1); + ret = write_one_gpt_table(desc, gpt_h1, gpt_e1); goto out; } if (!is_gpt1_valid && is_gpt2_valid) { - restore_primary_gpt_header(gpt_h2, dev_desc); - ret = write_one_gpt_table(dev_desc, gpt_h2, gpt_e2); + restore_primary_gpt_header(gpt_h2, desc); + ret = write_one_gpt_table(desc, gpt_h2, gpt_e2); goto out; } @@ -784,7 +783,7 @@ int gpt_repair_headers(struct blk_desc *dev_desc) return ret; } -int gpt_verify_partitions(struct blk_desc *dev_desc, +int gpt_verify_partitions(struct blk_desc *desc, struct disk_partition *partitions, int parts, gpt_header *gpt_head, gpt_entry **gpt_pte) { @@ -793,7 +792,7 @@ int gpt_verify_partitions(struct blk_desc *dev_desc, gpt_entry *gpt_e; int ret, i; - ret = gpt_verify_headers(dev_desc, gpt_head, gpt_pte); + ret = gpt_verify_headers(desc, gpt_head, gpt_pte); if (ret) return ret; @@ -862,28 +861,27 @@ int gpt_verify_partitions(struct blk_desc *dev_desc, return 0; } -int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf) +int is_valid_gpt_buf(struct blk_desc *desc, void *buf) { gpt_header *gpt_h; gpt_entry *gpt_e; /* determine start of GPT Header in the buffer */ - gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * - dev_desc->blksz); + gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * desc->blksz); if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, - dev_desc->lba)) + desc->lba)) return -1; /* determine start of GPT Entries in the buffer */ gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * - dev_desc->blksz); + desc->blksz); if (validate_gpt_entries(gpt_h, gpt_e)) return -1; return 0; } -int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) +int write_mbr_and_gpt_partitions(struct blk_desc *desc, void *buf) { gpt_header *gpt_h; gpt_entry *gpt_e; @@ -891,24 +889,22 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) lbaint_t lba; int cnt; - if (is_valid_gpt_buf(dev_desc, buf)) + if (is_valid_gpt_buf(desc, buf)) return -1; /* determine start of GPT Header in the buffer */ - gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * - dev_desc->blksz); + gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * desc->blksz); /* determine start of GPT Entries in the buffer */ - gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * - dev_desc->blksz); + gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * desc->blksz); gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * le32_to_cpu(gpt_h->sizeof_partition_entry)), - dev_desc); + desc); /* write MBR */ lba = 0; /* MBR is always at 0 */ cnt = 1; /* MBR (1 block) */ - if (blk_dwrite(dev_desc, lba, cnt, buf) != cnt) { + if (blk_dwrite(desc, lba, cnt, buf) != cnt) { log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n", "MBR", cnt, lba); return 1; @@ -917,7 +913,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) /* write Primary GPT */ lba = GPT_PRIMARY_PARTITION_TABLE_LBA; cnt = 1; /* GPT Header (1 block) */ - if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { + if (blk_dwrite(desc, lba, cnt, gpt_h) != cnt) { log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n", "Primary GPT Header", cnt, lba); return 1; @@ -925,7 +921,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) lba = le64_to_cpu(gpt_h->partition_entry_lba); cnt = gpt_e_blk_cnt; - if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { + if (blk_dwrite(desc, lba, cnt, gpt_e) != cnt) { log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n", "Primary GPT Entries", cnt, lba); return 1; @@ -936,7 +932,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) /* write Backup GPT */ lba = le64_to_cpu(gpt_h->partition_entry_lba); cnt = gpt_e_blk_cnt; - if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { + if (blk_dwrite(desc, lba, cnt, gpt_e) != cnt) { log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n", "Backup GPT Entries", cnt, lba); return 1; @@ -944,14 +940,14 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) lba = le64_to_cpu(gpt_h->my_lba); cnt = 1; /* GPT Header (1 block) */ - if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { + if (blk_dwrite(desc, lba, cnt, gpt_h) != cnt) { log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n", "Backup GPT Header", cnt, lba); return 1; } /* Update the partition table entries*/ - part_init(dev_desc); + part_init(desc); return 0; } @@ -1008,25 +1004,25 @@ static int is_pmbr_valid(legacy_mbr * mbr) * Description: returns 1 if valid, 0 on error, 2 if ignored header * If valid, returns pointers to PTEs. */ -static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, - gpt_header *pgpt_head, gpt_entry **pgpt_pte) +static int is_gpt_valid(struct blk_desc *desc, u64 lba, gpt_header *pgpt_head, + gpt_entry **pgpt_pte) { /* Confirm valid arguments prior to allocation. */ - if (!dev_desc || !pgpt_head) { + if (!desc || !pgpt_head) { log_debug("Invalid Argument(s)\n"); return 0; } - ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, mbr, 1, dev_desc->blksz); + ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, mbr, 1, desc->blksz); /* Read MBR Header from device */ - if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) { + if (blk_dread(desc, 0, 1, (ulong *)mbr) != 1) { log_debug("Can't read MBR header\n"); return 0; } /* Read GPT Header from device */ - if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) { + if (blk_dread(desc, (lbaint_t)lba, 1, pgpt_head) != 1) { log_debug("Can't read GPT header\n"); return 0; } @@ -1037,23 +1033,23 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, return 2; } - if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) + if (validate_gpt_header(pgpt_head, (lbaint_t)lba, desc->lba)) return 0; - if (dev_desc->sig_type == SIG_TYPE_NONE) { + if (desc->sig_type == SIG_TYPE_NONE) { efi_guid_t empty = {}; if (memcmp(&pgpt_head->disk_guid, &empty, sizeof(empty))) { - dev_desc->sig_type = SIG_TYPE_GUID; - memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, - sizeof(empty)); + desc->sig_type = SIG_TYPE_GUID; + memcpy(&desc->guid_sig, &pgpt_head->disk_guid, + sizeof(empty)); } else if (mbr->unique_mbr_signature != 0) { - dev_desc->sig_type = SIG_TYPE_MBR; - dev_desc->mbr_sig = mbr->unique_mbr_signature; + desc->sig_type = SIG_TYPE_MBR; + desc->mbr_sig = mbr->unique_mbr_signature; } } /* Read and allocate Partition Table Entries */ - *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); + *pgpt_pte = alloc_read_gpt_entries(desc, pgpt_head); if (!*pgpt_pte) return 0; @@ -1075,20 +1071,20 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, * Description: returns 1 if found a valid gpt, 0 on error. * If valid, returns pointers to PTEs. */ -static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, +static int find_valid_gpt(struct blk_desc *desc, gpt_header *gpt_head, gpt_entry **pgpt_pte) { int r; - r = is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, + r = is_gpt_valid(desc, GPT_PRIMARY_PARTITION_TABLE_LBA, gpt_head, pgpt_pte); if (r != 1) { if (r != 2) log_debug("Invalid GPT\n"); - if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), gpt_head, - pgpt_pte) != 1) { + if (is_gpt_valid(desc, desc->lba - 1, gpt_head, pgpt_pte) + != 1) { log_debug("Invalid Backup GPT\n"); return 0; } @@ -1100,21 +1096,21 @@ static int find_valid_gpt(struct blk_desc *dev_desc, gpt_header *gpt_head, /** * alloc_read_gpt_entries(): reads partition entries from disk - * @dev_desc + * @desc * @gpt - GPT header * * Description: Returns ptes on success, NULL on error. * Allocates space for PTEs based on information found in @gpt. * Notes: remember to free pte when you're done! */ -static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, +static gpt_entry *alloc_read_gpt_entries(struct blk_desc *desc, gpt_header *pgpt_head) { size_t count = 0, blk_cnt; lbaint_t blk; gpt_entry *pte = NULL; - if (!dev_desc || !pgpt_head) { + if (!desc || !pgpt_head) { log_debug("Invalid Argument(s)\n"); return NULL; } @@ -1130,7 +1126,7 @@ static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, /* Allocate memory for PTE, remember to FREE */ if (count != 0) { pte = memalign(ARCH_DMA_MINALIGN, - PAD_TO_BLOCKSIZE(count, dev_desc)); + PAD_TO_BLOCKSIZE(count, desc)); } if (count == 0 || pte == NULL) { @@ -1141,8 +1137,8 @@ static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, /* Read GPT Entries from device */ blk = le64_to_cpu(pgpt_head->partition_entry_lba); - blk_cnt = BLOCK_CNT(count, dev_desc); - if (blk_dread(dev_desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) { + blk_cnt = BLOCK_CNT(count, desc); + if (blk_dread(desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) { log_debug("Can't read GPT Entries\n"); free(pte); return NULL; -- cgit v1.2.3 From 06e293ed7c89db5a89d2cc72b73b18efe820899f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:28 -0600 Subject: part: iso: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the iso code to just use 'desc'. Signed-off-by: Simon Glass --- disk/part_iso.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'disk') diff --git a/disk/part_iso.c b/disk/part_iso.c index 4cd619bf46d..6ac6d95be92 100644 --- a/disk/part_iso.c +++ b/disk/part_iso.c @@ -46,7 +46,7 @@ unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start, } /* only boot records will be listed as valid partitions */ -int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, +int part_get_info_iso_verb(struct blk_desc *desc, int part_num, struct disk_partition *info, int verb) { int i,offset,entry_num; @@ -58,23 +58,23 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf; iso_init_def_entry_t *pide; - if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512)) + if (desc->blksz != CD_SECTSIZE && desc->blksz != 512) return -1; /* the first sector (sector 0x10) must be a primary volume desc */ blkaddr=PVD_OFFSET; - if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1) + if (iso_dread(desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1) return -1; if(ppr->desctype!=0x01) { if(verb) printf ("** First descriptor is NOT a primary desc on %d:%d **\n", - dev_desc->devnum, part_num); + desc->devnum, part_num); return (-1); } if(strncmp((char *)ppr->stand_ident,"CD001",5)!=0) { if(verb) printf ("** Wrong ISO Ident: %s on %d:%d **\n", - ppr->stand_ident, dev_desc->devnum, part_num); + ppr->stand_ident, desc->devnum, part_num); return (-1); } lastsect = le32_to_cpu(ppr->firstsek_LEpathtab1_LE); @@ -83,14 +83,14 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, PRINTF(" Lastsect:%08lx\n",lastsect); for(i=blkaddr;idesctype==0x00) break; /* boot entry found */ if(ppr->desctype==0xff) { if(verb) printf ("** No valid boot catalog found on %d:%d **\n", - dev_desc->devnum, part_num); + desc->devnum, part_num); return (-1); } } @@ -98,15 +98,15 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, if(strncmp(pbr->ident_str,"EL TORITO SPECIFICATION",23)!=0) { if(verb) printf ("** Wrong El Torito ident: %s on %d:%d **\n", - pbr->ident_str, dev_desc->devnum, part_num); + pbr->ident_str, desc->devnum, part_num); return (-1); } bootaddr = get_unaligned_le32(pbr->pointer); PRINTF(" Boot Entry at: %08lX\n",bootaddr); - if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) { + if (iso_dread(desc, bootaddr, 1, (ulong *)tmpbuf) != 1) { if(verb) printf ("** Can't read Boot Entry at %lX on %d:%d **\n", - bootaddr, dev_desc->devnum, part_num); + bootaddr, desc->devnum, part_num); return (-1); } chksum=0; @@ -116,20 +116,20 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, if(chksum!=0) { if(verb) printf("** Checksum Error in booting catalog validation entry on %d:%d **\n", - dev_desc->devnum, part_num); + desc->devnum, part_num); return (-1); } if((pve->key[0]!=0x55)||(pve->key[1]!=0xAA)) { if(verb) printf ("** Key 0x55 0xAA error on %d:%d **\n", - dev_desc->devnum, part_num); + desc->devnum, part_num); return(-1); } #ifdef CHECK_FOR_POWERPC_PLATTFORM if(pve->platform!=0x01) { if(verb) printf ("** No PowerPC platform CD on %d:%d **\n", - dev_desc->devnum, part_num); + desc->devnum, part_num); return(-1); } #endif @@ -137,7 +137,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, entry_num=1; offset=0x20; strcpy((char *)info->type, "U-Boot"); - part_set_generic_name(dev_desc, part_num, (char *)info->name); + part_set_generic_name(desc, part_num, (char *)info->name); /* the bootcatalog (including validation Entry) is limited to 2048Bytes * (63 boot entries + validation entry) */ while(offset<2048) { @@ -159,7 +159,7 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, else { if(verb) printf ("** Partition %d not found on device %d **\n", - part_num, dev_desc->devnum); + part_num, desc->devnum); return(-1); } } @@ -167,13 +167,13 @@ int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num, * searched w/o succsess */ if(verb) printf ("** Partition %d not found on device %d **\n", - part_num, dev_desc->devnum); + part_num, desc->devnum); return(-1); found: if(pide->boot_ind!=0x88) { if(verb) printf("** Partition %d is not bootable on device %d **\n", - part_num, dev_desc->devnum); + part_num, desc->devnum); return (-1); } switch(pide->boot_media) { @@ -189,7 +189,7 @@ found: newblkaddr = get_unaligned_le32(pide->rel_block_addr); info->start=newblkaddr; - if (dev_desc->blksz == 512) { + if (desc->blksz == 512) { info->size *= 4; info->start *= 4; info->blksz = 512; @@ -199,20 +199,20 @@ found: return 0; } -static int part_get_info_iso(struct blk_desc *dev_desc, int part_num, +static int part_get_info_iso(struct blk_desc *desc, int part_num, struct disk_partition *info) { - return part_get_info_iso_verb(dev_desc, part_num, info, 0); + return part_get_info_iso_verb(desc, part_num, info, 0); } -static void part_print_iso(struct blk_desc *dev_desc) +static void part_print_iso(struct blk_desc *desc) { struct disk_partition info; int i; - if (part_get_info_iso_verb(dev_desc, 1, &info, 0) == -1) { + if (part_get_info_iso_verb(desc, 1, &info, 0) == -1) { printf("** No boot partition found on device %d **\n", - dev_desc->devnum); + desc->devnum); return; } printf("Part Start Sect x Size Type\n"); @@ -221,14 +221,14 @@ static void part_print_iso(struct blk_desc *dev_desc) printf(" %2d %8" LBAFlength "u %8" LBAFlength "u %6ld %.32s\n", i, info.start, info.size, info.blksz, info.type); i++; - } while (part_get_info_iso_verb(dev_desc, i, &info, 0) != -1); + } while (part_get_info_iso_verb(desc, i, &info, 0) != -1); } -static int part_test_iso(struct blk_desc *dev_desc) +static int part_test_iso(struct blk_desc *desc) { struct disk_partition info; - return part_get_info_iso_verb(dev_desc, 1, &info, 0); + return part_get_info_iso_verb(desc, 1, &info, 0); } U_BOOT_PART_TYPE(iso) = { -- cgit v1.2.3 From 060148a371ba229c2a909f5013ed25c51915195c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:29 -0600 Subject: part: nac: Use desc instead of dev_desc The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the mac code to just use 'desc'. Signed-off-by: Simon Glass --- disk/part_mac.c | 59 ++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'disk') diff --git a/disk/part_mac.c b/disk/part_mac.c index ae8263f755a..db5e203be59 100644 --- a/disk/part_mac.c +++ b/disk/part_mac.c @@ -31,21 +31,20 @@ extern ldiv_t ldiv (long int __numer, long int __denom); #endif -static int part_mac_read_ddb(struct blk_desc *dev_desc, - mac_driver_desc_t *ddb_p); -static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, +static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p); +static int part_mac_read_pdb(struct blk_desc *desc, int part, mac_partition_t *pdb_p); /* * Test for a valid MAC partition */ -static int part_test_mac(struct blk_desc *dev_desc) +static int part_test_mac(struct blk_desc *desc) { ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); ulong i, n; - if (part_mac_read_ddb (dev_desc, ddesc)) { + if (part_mac_read_ddb(desc, ddesc)) { /* * error reading Driver Descriptor Block, * or no valid Signature @@ -55,8 +54,8 @@ static int part_test_mac(struct blk_desc *dev_desc) n = 1; /* assuming at least one partition */ for (i=1; i<=n; ++i) { - if ((blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) || - (mpart->signature != MAC_PARTITION_MAGIC) ) { + if ((blk_dread(desc, i, 1, (ulong *)mpart) != 1) || + mpart->signature != MAC_PARTITION_MAGIC) { return (-1); } /* update partition count */ @@ -65,14 +64,14 @@ static int part_test_mac(struct blk_desc *dev_desc) return (0); } -static void part_print_mac(struct blk_desc *dev_desc) +static void part_print_mac(struct blk_desc *desc) { ulong i, n; ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); ldiv_t mb, gb; - if (part_mac_read_ddb (dev_desc, ddesc)) { + if (part_mac_read_ddb(desc, ddesc)) { /* * error reading Driver Descriptor Block, * or no valid Signature @@ -110,15 +109,15 @@ static void part_print_mac(struct blk_desc *dev_desc) char c; printf ("%4ld: ", i); - if (blk_dread(dev_desc, i, 1, (ulong *)mpart) != 1) { + if (blk_dread(desc, i, 1, (ulong *)mpart) != 1) { printf ("** Can't read Partition Map on %d:%ld **\n", - dev_desc->devnum, i); + desc->devnum, i); return; } if (mpart->signature != MAC_PARTITION_MAGIC) { printf("** Bad Signature on %d:%ld - expected 0x%04x, got 0x%04x\n", - dev_desc->devnum, i, MAC_PARTITION_MAGIC, + desc->devnum, i, MAC_PARTITION_MAGIC, mpart->signature); return; } @@ -154,10 +153,9 @@ static void part_print_mac(struct blk_desc *dev_desc) /* * Read Device Descriptor Block */ -static int part_mac_read_ddb(struct blk_desc *dev_desc, - mac_driver_desc_t *ddb_p) +static int part_mac_read_ddb(struct blk_desc *desc, mac_driver_desc_t *ddb_p) { - if (blk_dread(dev_desc, 0, 1, (ulong *)ddb_p) != 1) { + if (blk_dread(desc, 0, 1, (ulong *)ddb_p) != 1) { debug("** Can't read Driver Descriptor Block **\n"); return (-1); } @@ -171,7 +169,7 @@ static int part_mac_read_ddb(struct blk_desc *dev_desc, /* * Read Partition Descriptor Block */ -static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, +static int part_mac_read_pdb(struct blk_desc *desc, int part, mac_partition_t *pdb_p) { int n = 1; @@ -182,15 +180,15 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, * partition 1 first since this is the only way to * know how many partitions we have. */ - if (blk_dread(dev_desc, n, 1, (ulong *)pdb_p) != 1) { - printf ("** Can't read Partition Map on %d:%d **\n", - dev_desc->devnum, n); + if (blk_dread(desc, n, 1, (ulong *)pdb_p) != 1) { + printf("** Can't read Partition Map on %d:%d **\n", + desc->devnum, n); return (-1); } if (pdb_p->signature != MAC_PARTITION_MAGIC) { printf("** Bad Signature on %d:%d: expected 0x%04x, got 0x%04x\n", - dev_desc->devnum, n, MAC_PARTITION_MAGIC, + desc->devnum, n, MAC_PARTITION_MAGIC, pdb_p->signature); return (-1); } @@ -199,10 +197,9 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, return (0); if ((part < 1) || (part > pdb_p->map_count)) { - printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n", - dev_desc->devnum, part, - dev_desc->devnum, - dev_desc->devnum, pdb_p->map_count); + printf("** Invalid partition %d:%d [%d:1...%d:%d only]\n", + desc->devnum, part, desc->devnum, desc->devnum, + pdb_p->map_count); return (-1); } @@ -213,21 +210,19 @@ static int part_mac_read_pdb(struct blk_desc *dev_desc, int part, /* NOTREACHED */ } -static int part_get_info_mac(struct blk_desc *dev_desc, int part, - struct disk_partition *info) +static int part_get_info_mac(struct blk_desc *desc, int part, + struct disk_partition *info) { ALLOC_CACHE_ALIGN_BUFFER(mac_driver_desc_t, ddesc, 1); ALLOC_CACHE_ALIGN_BUFFER(mac_partition_t, mpart, 1); - if (part_mac_read_ddb (dev_desc, ddesc)) { - return (-1); - } + if (part_mac_read_ddb(desc, ddesc)) + return -1; info->blksz = ddesc->blk_size; - if (part_mac_read_pdb (dev_desc, part, mpart)) { - return (-1); - } + if (part_mac_read_pdb(desc, part, mpart)) + return -1; info->start = mpart->start_block; info->size = mpart->block_count; -- cgit v1.2.3 From ade2316da3cd76abe7649d34abb84f1370fb942d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:30 -0600 Subject: part: Add comments for static functions Some internal functions could do with a few comments, to explain what they do. Add these, to make the code easier to follow. Signed-off-by: Simon Glass --- disk/part.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'disk') diff --git a/disk/part.c b/disk/part.c index 8035dcb8a42..9190e880618 100644 --- a/disk/part.c +++ b/disk/part.c @@ -26,6 +26,12 @@ /* Check all partition types */ #define PART_TYPE_ALL -1 +/** + * part_driver_get_type() - Get a driver given its type + * + * @part_type: Partition type to find the driver for + * Return: Driver for that type, or NULL if none + */ static struct part_driver *part_driver_get_type(int part_type) { struct part_driver *drv = @@ -42,6 +48,22 @@ static struct part_driver *part_driver_get_type(int part_type) return NULL; } +/** + * part_driver_lookup_type() - Look up the partition driver for a blk device + * + * If @desc->part_type is PART_TYPE_UNKNOWN, this checks each parition driver + * against the blk device to see if there is a valid partition table acceptable + * to that driver. + * + * If @desc->part_type is already set, it just returns the driver for that + * type, without testing if the driver can find a valid partition on the + * descriptor. + * + * On success it updates @desc->part_type if set to PART_TYPE_UNKNOWN on entry + * + * @dev_desc: Device descriptor + * Return: Driver found, or NULL if none + */ static struct part_driver *part_driver_lookup_type(struct blk_desc *desc) { struct part_driver *drv = @@ -83,6 +105,16 @@ int part_get_type_by_name(const char *name) return PART_TYPE_UNKNOWN; } +/** + * get_dev_hwpart() - Get the descriptor for a device with hardware partitions + * + * @ifname: Interface name (e.g. "ide", "scsi") + * @dev: Device number (0 for first device on that interface, 1 for + * second, etc. + * @hwpart: Hardware partition, or 0 if none (used for MMC) + * Return: pointer to the block device, or NULL if not available, or an + * error occurred. + */ static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart) { struct blk_desc *desc; -- cgit v1.2.3 From c5f1d005f51783a5b34d6164ab66289eb1f4a45b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:31 -0600 Subject: part: Add accessors for struct disk_partition uuid This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass --- disk/part.c | 8 ++------ disk/part_dos.c | 17 ++++++++--------- disk/part_efi.c | 31 ++++++++++++++++--------------- 3 files changed, 26 insertions(+), 30 deletions(-) (limited to 'disk') diff --git a/disk/part.c b/disk/part.c index 9190e880618..91c6ac42cc8 100644 --- a/disk/part.c +++ b/disk/part.c @@ -368,10 +368,8 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, struct part_driver *drv; if (blk_enabled()) { -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) /* The common case is no UUID support */ - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif @@ -416,9 +414,7 @@ int part_get_info_whole_disk(struct blk_desc *desc, info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif diff --git a/disk/part_dos.c b/disk/part_dos.c index cc050ca8c49..33374384373 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -231,10 +231,8 @@ static int part_get_info_extended(struct blk_desc *desc, return -1; } -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - if (!ext_part_sector) + if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector) disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]); -#endif ret = part_get_info_whole_disk(desc, &wdinfo); if (ret) @@ -263,9 +261,12 @@ static int part_get_info_extended(struct blk_desc *desc, /* sprintf(info->type, "%d, pt->sys_ind); */ strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(pt); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - sprintf(info->uuid, "%08x-%02x", disksig, part_num); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + char str[12]; + + sprintf(str, "%08x-%02x", disksig, part_num); + disk_partition_set_uuid(info, str); + } info->sys_ind = pt->sys_ind; return 0; } @@ -302,9 +303,7 @@ static int part_get_info_extended(struct blk_desc *desc, info->blksz = DOS_PART_DEFAULT_SECTOR; info->bootable = 0; strcpy((char *)info->type, "U-Boot"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); return 0; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 4ac21868d08..a6f7375cd38 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *desc, int part, print_efiname(&gpt_pte[part - 1])); strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(&gpt_pte[part - 1]); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, - UUID_STR_FORMAT_GUID); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, + (char *)disk_partition_uuid(info), + UUID_STR_FORMAT_GUID); + } #ifdef CONFIG_PARTITION_TYPE_GUID uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, info->type_guid, UUID_STR_FORMAT_GUID); @@ -415,10 +416,7 @@ int gpt_fill_pte(struct blk_desc *desc, le64_to_cpu(gpt_h->last_usable_lba); int i, k; size_t efiname_len, dosname_len; -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - char *str_uuid; unsigned char *bin_uuid; -#endif #ifdef CONFIG_PARTITION_TYPE_GUID char *str_type_guid; unsigned char *bin_type_guid; @@ -487,16 +485,19 @@ int gpt_fill_pte(struct blk_desc *desc, &partition_basic_data_guid, 16); #endif -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - str_uuid = partitions[i].uuid; - bin_uuid = gpt_e[i].unique_partition_guid.b; + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + const char *str_uuid; + + str_uuid = disk_partition_uuid(&partitions[i]); + bin_uuid = gpt_e[i].unique_partition_guid.b; - if (uuid_str_to_bin(str_uuid, bin_uuid, UUID_STR_FORMAT_GUID)) { - log_debug("Partition no. %d: invalid guid: %s\n", - i, str_uuid); - return -EINVAL; + if (uuid_str_to_bin(str_uuid, bin_uuid, + UUID_STR_FORMAT_GUID)) { + log_debug("Partition no. %d: invalid guid: %s\n", + i, str_uuid); + return -EINVAL; + } } -#endif /* partition attributes */ memset(&gpt_e[i].attributes, 0, -- cgit v1.2.3 From bcd645428c340254a0f6e3b040fd36c3006fab6c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:32 -0600 Subject: part: Add accessors for struct disk_partition type_uuid This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass --- disk/part.c | 8 ++------ disk/part_efi.c | 9 +++++---- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'disk') diff --git a/disk/part.c b/disk/part.c index 91c6ac42cc8..72241b7b232 100644 --- a/disk/part.c +++ b/disk/part.c @@ -370,9 +370,7 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, if (blk_enabled()) { /* The common case is no UUID support */ disk_partition_clr_uuid(info); -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0] = 0; -#endif + disk_partition_clr_type_guid(info); if (part_type == PART_TYPE_UNKNOWN) { drv = part_driver_lookup_type(desc); @@ -415,9 +413,7 @@ int part_get_info_whole_disk(struct blk_desc *desc, strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); disk_partition_clr_uuid(info); -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0] = 0; -#endif + disk_partition_clr_type_guid(info); return 0; } diff --git a/disk/part_efi.c b/disk/part_efi.c index a6f7375cd38..20867521382 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -294,10 +294,11 @@ int part_get_info_efi(struct blk_desc *desc, int part, (char *)disk_partition_uuid(info), UUID_STR_FORMAT_GUID); } -#ifdef CONFIG_PARTITION_TYPE_GUID - uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, - info->type_guid, UUID_STR_FORMAT_GUID); -#endif + if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { + uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, + (char *)disk_partition_type_uuid(info), + UUID_STR_FORMAT_GUID); + } log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start, info->size, info->name); -- cgit v1.2.3 From fbd644e7026f89f09cfa854fbf846449579f1684 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 24 Aug 2023 13:55:34 -0600 Subject: part: efi: Add debugging for the signature check Add a little more debugging for the initial signature check. Drop the pointless check for NULL. Also set a log category while we are here. Signed-off-by: Simon Glass --- disk/part_efi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'disk') diff --git a/disk/part_efi.c b/disk/part_efi.c index 20867521382..39382c5faee 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -9,6 +9,9 @@ * when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this * limits the maximum size of addressable storage to < 2 tebibytes */ + +#define LOG_CATEGORY LOGC_FS + #include #include #include @@ -976,17 +979,23 @@ static int pmbr_part_valid(struct partition *part) /* * is_pmbr_valid(): test Protective MBR for validity * + * @mbr: Pointer to Master Boot-Record data + * * Returns: 1 if PMBR is valid, 0 otherwise. * Validity depends on two things: * 1) MSDOS signature is in the last two bytes of the MBR * 2) One partition of type 0xEE is found, checked by pmbr_part_valid() */ -static int is_pmbr_valid(legacy_mbr * mbr) +static int is_pmbr_valid(legacy_mbr *mbr) { + uint sig = le16_to_cpu(mbr->signature); int i = 0; - if (!mbr || le16_to_cpu(mbr->signature) != MSDOS_MBR_SIGNATURE) + if (sig != MSDOS_MBR_SIGNATURE) { + log_debug("Invalid signature %x\n", sig); return 0; + } + log_debug("Signature %x valid\n", sig); for (i = 0; i < 4; i++) { if (pmbr_part_valid(&mbr->partition_record[i])) { -- cgit v1.2.3 From 782c7f1bdb0a25e1851a47ff1aba9f71162c2f9d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 2 Sep 2023 09:35:21 +0200 Subject: part: rename disk_partition_type_uuid() Rename disk_partition_type_uuid to disk_partition_type_guid. Provide function descriptions for the getter and setter. Fixes: bcd645428c34 ("part: Add accessors for struct disk_partition type_uuid") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- disk/part_efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'disk') diff --git a/disk/part_efi.c b/disk/part_efi.c index 39382c5faee..b7aef3731b5 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -299,7 +299,7 @@ int part_get_info_efi(struct blk_desc *desc, int part, } if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, - (char *)disk_partition_type_uuid(info), + (char *)disk_partition_type_guid(info), UUID_STR_FORMAT_GUID); } -- cgit v1.2.3 From 1e94b46f73cedcebbff73799203f3266c5b28d90 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Sep 2023 18:21:46 -0600 Subject: common: Drop linux/printk.h from common header This old patch was marked as deferred. Bring it back to life, to continue towards the removal of common.h Move this out of the common header and include it only where needed. Signed-off-by: Simon Glass --- disk/part_efi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'disk') diff --git a/disk/part_efi.c b/disk/part_efi.c index b7aef3731b5..4ce9243ef25 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -29,6 +29,7 @@ #include #include #include +#include #include /* GUID for basic data partitons */ -- cgit v1.2.3