efi_loader: Fix partition offsets

Commit 884bcf6f65 (efi_loader: use proper device-paths for partitions) tried
to introduce the el torito scheme to all partition table types: Spawn
individual disk objects for each partition on a disk.

Unfortunately, that code ended up creating partitions with offset=0 which meant
that anyone accessing these objects gets data from the raw block device instead
of the partition.

Furthermore, all the el torito logic to spawn devices for partitions was
duplicated. So let's merge the two code paths and give partition disk objects
good offsets to work from, so that payloads can actually make use of them.

Fixes: 884bcf6f65 (efi_loader: use proper device-paths for partitions)
Reported-by: Yousaf Kaukab <yousaf.kaukab@suse.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Alexander Graf 2017-12-01 16:10:33 +01:00
parent 1a0b4d22a9
commit c034b7fd41

View file

@ -264,21 +264,17 @@ out_of_memory:
printf("ERROR: Out of memory\n"); printf("ERROR: Out of memory\n");
} }
static int efi_disk_create_eltorito(struct blk_desc *desc, static int efi_disk_create_partitions(struct blk_desc *desc,
const char *if_typename, const char *if_typename,
int diskid, int diskid,
const char *pdevname) const char *pdevname)
{ {
int disks = 0; int disks = 0;
#if CONFIG_IS_ENABLED(ISO_PARTITION)
char devname[32] = { 0 }; /* dp->str is u16[32] long */ char devname[32] = { 0 }; /* dp->str is u16[32] long */
disk_partition_t info; disk_partition_t info;
int part; int part;
if (desc->part_type != PART_TYPE_ISO) /* Add devices for each partition */
return 0;
/* and devices for each partition: */
for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
if (part_get_info(desc, part, &info)) if (part_get_info(desc, part, &info))
continue; continue;
@ -289,10 +285,6 @@ static int efi_disk_create_eltorito(struct blk_desc *desc,
disks++; disks++;
} }
/* ... and add block device: */
efi_disk_add_dev(devname, if_typename, desc, diskid, 0, 0);
#endif
return disks; return disks;
} }
@ -318,31 +310,18 @@ int efi_disk_register(void)
uclass_next_device_check(&dev)) { uclass_next_device_check(&dev)) {
struct blk_desc *desc = dev_get_uclass_platdata(dev); struct blk_desc *desc = dev_get_uclass_platdata(dev);
const char *if_typename = dev->driver->name; const char *if_typename = dev->driver->name;
disk_partition_t info;
int part;
printf("Scanning disk %s...\n", dev->name); printf("Scanning disk %s...\n", dev->name);
/* add devices for each partition: */ /* Add block device for the full device */
for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
if (part_get_info(desc, part, &info))
continue;
efi_disk_add_dev(dev->name, if_typename, desc,
desc->devnum, 0, part);
}
/* ... and add block device: */
efi_disk_add_dev(dev->name, if_typename, desc, efi_disk_add_dev(dev->name, if_typename, desc,
desc->devnum, 0, 0); desc->devnum, 0, 0);
disks++; disks++;
/* /* Partitions show up as block devices in EFI */
* El Torito images show up as block devices in an EFI world, disks += efi_disk_create_partitions(desc, if_typename,
* so let's create them here desc->devnum, dev->name);
*/
disks += efi_disk_create_eltorito(desc, if_typename,
desc->devnum, dev->name);
} }
#else #else
int i, if_type; int i, if_type;
@ -361,8 +340,6 @@ int efi_disk_register(void)
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
struct blk_desc *desc; struct blk_desc *desc;
char devname[32] = { 0 }; /* dp->str is u16[32] long */ char devname[32] = { 0 }; /* dp->str is u16[32] long */
disk_partition_t info;
int part;
desc = blk_get_devnum_by_type(if_type, i); desc = blk_get_devnum_by_type(if_type, i);
if (!desc) if (!desc)
@ -373,24 +350,13 @@ int efi_disk_register(void)
snprintf(devname, sizeof(devname), "%s%d", snprintf(devname, sizeof(devname), "%s%d",
if_typename, i); if_typename, i);
/* add devices for each partition: */ /* Add block device for the full device */
for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
if (part_get_info(desc, part, &info))
continue;
efi_disk_add_dev(devname, if_typename, desc,
i, 0, part);
}
/* ... and add block device: */
efi_disk_add_dev(devname, if_typename, desc, i, 0, 0); efi_disk_add_dev(devname, if_typename, desc, i, 0, 0);
disks++; disks++;
/* /* Partitions show up as block devices in EFI */
* El Torito images show up as block devices disks += efi_disk_create_partitions(desc, if_typename,
* in an EFI world, so let's create them here i, devname);
*/
disks += efi_disk_create_eltorito(desc, if_typename,
i, devname);
} }
} }
#endif #endif