diff options
Diffstat (limited to 'disk')
| -rw-r--r-- | disk/disk-uclass.c | 265 | ||||
| -rw-r--r-- | disk/part.c | 226 | ||||
| -rw-r--r-- | disk/part_amiga.c | 34 | ||||
| -rw-r--r-- | disk/part_dos.c | 95 | ||||
| -rw-r--r-- | disk/part_efi.c | 282 | ||||
| -rw-r--r-- | disk/part_iso.c | 52 | ||||
| -rw-r--r-- | disk/part_mac.c | 59 |
7 files changed, 469 insertions, 544 deletions
diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index d32747e2242..efe4bf1f949 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -17,227 +17,110 @@ #include <dm/device-internal.h> #include <dm/lists.h> -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; -} - -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) +/** + * 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) { - struct udevice *parent; - struct disk_part *part; - const struct blk_ops *ops; + struct disk_part *part = dev_get_uclass_plat(dev); - parent = dev_get_parent(dev); - ops = blk_get_ops(parent); - if (!ops->write) + if (device_get_uclass_id(dev) != UCLASS_PARTITION) return -ENOSYS; - part = dev_get_uclass_plat(dev); if (start >= part->gpt_part_info.size) - return 0; + return -E2BIG; if ((start + blkcnt) > part->gpt_part_info.size) - blkcnt = part->gpt_part_info.size - start; - start += part->gpt_part_info.start; + return -ERANGE; - return ops->write(parent, start, blkcnt, buffer); + return 0; } -static ulong part_blk_erase(struct udevice *dev, lbaint_t start, - lbaint_t blkcnt) +/** + * 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 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; + struct disk_part *part = dev_get_uclass_plat(dev); - 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); + return start + part->gpt_part_info.start; } -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 */ -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 + * + * @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; + int ret = disk_blk_part_validate(dev, start, blkcnt); - ops = blk_get_ops(dev); - if (!ops->read) - return -ENOSYS; + if (ret) + return ret; - 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; - } - - 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), disk_blk_part_offset(dev, start), + blkcnt, buffer); } +/** + * disk_blk_write() - Write to a block device + * + * @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 + */ 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) - return -ENOSYS; + int ret = disk_blk_part_validate(dev, start, blkcnt); - blkcache_invalidate(desc->uclass_id, desc->devnum); + if (ret) + return ret; - return ops->write(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 (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) { - struct blk_desc *desc; - const struct blk_ops *ops; - - desc = dev_get_blk(dev); - if (!desc) - return -ENOSYS; + int ret = disk_blk_part_validate(dev, start, blkcnt); - ops = blk_get_ops(dev); - if (!ops->erase) - return -ENOSYS; - - blkcache_invalidate(desc->uclass_id, desc->devnum); + if (ret) + return ret; - return ops->erase(dev, start, blkcnt); + return blk_erase(dev_get_parent(dev), disk_blk_part_offset(dev, start), + blkcnt); } UCLASS_DRIVER(partition) = { @@ -245,3 +128,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, +}; diff --git a/disk/part.c b/disk/part.c index eec02f58988..72241b7b232 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,25 +48,41 @@ 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) +/** + * 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 = 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 */ @@ -83,27 +105,37 @@ 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 *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 +172,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 +198,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 +232,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 +254,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 +262,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 +305,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,50 +341,46 @@ 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; if (blk_enabled()) { -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) /* The common case is no UUID support */ - info->uuid[0] = 0; -#endif -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0] = 0; -#endif + disk_partition_clr_uuid(info); + disk_partition_clr_type_guid(info); 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 +388,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,33 +397,29 @@ 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"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif -#ifdef CONFIG_PARTITION_TYPE_GUID - info->type_guid[0] = 0; -#endif + disk_partition_clr_uuid(info); + disk_partition_clr_type_guid(info); return 0; } 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 +455,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 +468,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 +480,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 +493,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 +552,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 +584,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 +604,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 +624,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 +636,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 +680,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 +690,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 +708,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 +728,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 +761,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 +776,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 +823,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) 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<limit; i++) { - ulong res = blk_dread(dev_desc, i, 1, (ulong *)block_buffer); + ulong res = blk_dread(desc, i, 1, (ulong *)block_buffer); if (res == 1) { struct rigid_disk_block *trdb = (struct rigid_disk_block *)block_buffer; @@ -165,7 +165,7 @@ struct rigid_disk_block *get_rdisk(struct blk_desc *dev_desc) * Ridgid disk block */ -struct bootcode_block *get_bootcode(struct blk_desc *dev_desc) +struct bootcode_block *get_bootcode(struct blk_desc *desc) { int i; int limit; @@ -181,7 +181,7 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc) for (i = 0; i < limit; i++) { - ulong res = blk_dread(dev_desc, i, 1, (ulong *)block_buffer); + ulong res = blk_dread(desc, i, 1, (ulong *)block_buffer); if (res == 1) { struct bootcode_block *boot = (struct bootcode_block *)block_buffer; @@ -206,17 +206,17 @@ struct bootcode_block *get_bootcode(struct blk_desc *dev_desc) * Test if the given partition has an Amiga partition table/Rigid * Disk block */ -static int part_test_amiga(struct blk_desc *dev_desc) +static int part_test_amiga(struct blk_desc *desc) { struct rigid_disk_block *rdb; struct bootcode_block *bootcode; PRINTF("part_test_amiga: Testing for an Amiga RDB partition\n"); - rdb = get_rdisk(dev_desc); + rdb = get_rdisk(desc); if (rdb) { - bootcode = get_bootcode(dev_desc); + bootcode = get_bootcode(desc); if (bootcode) PRINTF("part_test_amiga: bootable Amiga disk\n"); else @@ -235,7 +235,7 @@ static int part_test_amiga(struct blk_desc *dev_desc) /* * Find partition number partnum on the given drive. */ -static struct partition_block *find_partition(struct blk_desc *dev_desc, +static struct partition_block *find_partition(struct blk_desc *desc, int partnum) { struct rigid_disk_block *rdb; @@ -243,7 +243,7 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc, u32 block; PRINTF("Trying to find partition block %d\n", partnum); - rdb = get_rdisk(dev_desc); + rdb = get_rdisk(desc); if (!rdb) { PRINTF("find_partition: no rdb found\n"); @@ -257,7 +257,7 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc, while (block != 0xFFFFFFFF) { - ulong res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer); + ulong res = blk_dread(desc, block, 1, (ulong *)block_buffer); if (res == 1) { p = (struct partition_block *)block_buffer; @@ -289,10 +289,10 @@ static struct partition_block *find_partition(struct blk_desc *dev_desc, /* * Get info about a partition */ -static int part_get_info_amiga(struct blk_desc *dev_desc, int part, - struct disk_partition *info) +static int part_get_info_amiga(struct blk_desc *desc, int part, + struct disk_partition *info) { - struct partition_block *p = find_partition(dev_desc, part-1); + struct partition_block *p = find_partition(desc, part - 1); struct amiga_part_geometry *g; u32 disk_type; @@ -317,7 +317,7 @@ static int part_get_info_amiga(struct blk_desc *dev_desc, int part, return 0; } -static void part_print_amiga(struct blk_desc *dev_desc) +static void part_print_amiga(struct blk_desc *desc) { struct rigid_disk_block *rdb; struct bootcode_block *boot; @@ -325,7 +325,7 @@ static void part_print_amiga(struct blk_desc *dev_desc) u32 block; int i = 1; - rdb = get_rdisk(dev_desc); + rdb = get_rdisk(desc); if (!rdb) { PRINTF("part_print_amiga: no rdb found\n"); @@ -353,7 +353,7 @@ static void part_print_amiga(struct blk_desc *dev_desc) PRINTF("Trying to load block #0x%X\n", block); - res = blk_dread(dev_desc, block, 1, (ulong *)block_buffer); + res = blk_dread(desc, block, 1, (ulong *)block_buffer); if (res == 1) { p = (struct partition_block *)block_buffer; @@ -370,7 +370,7 @@ static void part_print_amiga(struct blk_desc *dev_desc) } else block = 0xFFFFFFFF; } - boot = get_bootcode(dev_desc); + boot = get_bootcode(desc); if (boot) { printf("Disk is bootable\n"); diff --git a/disk/part_dos.c b/disk/part_dos.c index 56e61884def..33374384373 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,14 +200,15 @@ 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; + int i, ret; int dos_type; /* set a maximum recursion level */ @@ -218,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 || @@ -231,10 +231,12 @@ static int part_get_info_extended(struct blk_desc *dev_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) + return ret; /* Print all primary/logical partitions */ pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); @@ -247,18 +249,24 @@ 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); - 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"); 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; } @@ -277,7 +285,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); } @@ -288,29 +296,30 @@ 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; + info->size = desc->lba; + 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) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); return 0; } 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) @@ -490,20 +499,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; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 80a44dc9f07..4ce9243ef25 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 <common.h> #include <blk.h> #include <log.h> @@ -26,6 +29,7 @@ #include <dm/ofnode.h> #include <linux/compiler.h> #include <linux/ctype.h> +#include <linux/printk.h> #include <u-boot/crc.h> /* GUID for basic data partitons */ @@ -51,12 +55,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 +199,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 +217,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 +259,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 +272,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,20 +287,22 @@ 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])); 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 -#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 (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); + } + if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { + uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, + (char *)disk_partition_type_guid(info), + UUID_STR_FORMAT_GUID); + } log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start, info->size, info->name); @@ -306,12 +312,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 +326,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 +354,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 +387,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 +408,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) { @@ -416,10 +421,7 @@ int gpt_fill_pte(struct blk_desc *dev_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; @@ -430,7 +432,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 */ @@ -488,16 +490,19 @@ int gpt_fill_pte(struct blk_desc *dev_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; - 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; + 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; + } } -#endif /* partition attributes */ memset(&gpt_e[i].attributes, 0, @@ -527,7 +532,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 +548,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 +561,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 +578,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 +602,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 +618,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 +628,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 +669,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 +689,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 +703,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 +712,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 +721,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 +745,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 +765,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 +789,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 +798,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 +867,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 +895,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 +919,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 +927,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 +938,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 +946,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; } @@ -978,17 +980,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])) { @@ -1008,25 +1016,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 +1045,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 +1083,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 +1108,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 +1138,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 +1149,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; 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;i<lastsect;i++) { PRINTF("Reading block %d\n", i); - if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1) + if (iso_dread(desc, i, 1, (ulong *)tmpbuf) != 1) return -1; if(ppr->desctype==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) = { 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; |
