Skip to content

Commit a0955e7

Browse files
robclarkJosephChen2017
authored andcommitted
UPSTREAM: efi_loader: use proper device-paths for partitions
Also, create disk objects for the disk itself, in addition to the partitions. (UEFI terminology is a bit confusing, a "disk" object is really a partition.) This helps grub properly identify the boot device since it is trying to match up partition "disk" object with it's parent device. Now instead of seeing devices like: /File([email protected])/EndEntire /File(usb_mass_storage.lun0)/EndEntire You see: /ACPI(133741d0,0)/UnknownMessaging(1d)/EndEntire /ACPI(133741d0,0)/UnknownMessaging(1d)/HD(0,800,64000,dd904a8c00000000,1,1)/EndEntire /ACPI(133741d0,0)/UnknownMessaging(1d)/HD(1,64800,200000,dd904a8c00000000,1,1)/EndEntire /ACPI(133741d0,0)/UnknownMessaging(1d)/HD(2,264800,19a000,dd904a8c00000000,1,1)/EndEntire /ACPI(133741d0,0)/USB(0,0)/USB(0,0)/USB(0,0)/EndEntire /ACPI(133741d0,0)/USB(0,0)/USB(0,0)/USB(0,0)/HD(0,800,60000,38ca680200000000,1,1)/EndEntire /ACPI(133741d0,0)/USB(0,0)/USB(0,0)/USB(0,0)/HD(1,61000,155000,38ca680200000000,1,1)/EndEntire /ACPI(133741d0,0)/USB(0,0)/USB(0,0)/USB(0,0)/HD(2,20fa800,1bbf8800,38ca680200000000,1,1)/EndEntire /ACPI(133741d0,0)/USB(0,0)/USB(0,0)/USB(0,0)/HD(3,1b6800,1f44000,38ca680200000000,1,1)/EndEntire This is on a board with single USB disk and single sd-card. The UnknownMessaging(1d) node in the device-path is the MMC device, but grub_efi_print_device_path() hasn't been updated yet for some of the newer device-path sub-types. This patch is inspired by a patch originally from Peter Jones, but re-worked to use efi_device_path, so it doesn't much resemble the original. Signed-off-by: Rob Clark <[email protected]> [agraf: s/unsigned/unsigned int/] Signed-off-by: Alexander Graf <[email protected]> (cherry picked from commit 884bcf6) Change-Id: I8d891a25dd321b718b0429d8b8a895cc4490f272 Signed-off-by: Jeffy Chen <[email protected]>
1 parent 1fa8dee commit a0955e7

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

lib/efi_loader/efi_disk.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ struct efi_disk_obj {
2828
/* EFI Interface Media descriptor struct, referenced by ops */
2929
struct efi_block_io_media media;
3030
/* EFI device path to this block device */
31-
struct efi_device_path_file_path *dp;
31+
struct efi_device_path *dp;
32+
/* partition # */
33+
unsigned int part;
3234
/* Offset into disk for simple partitions */
3335
lbaint_t offset;
3436
/* Internal block device */
35-
const struct blk_desc *desc;
37+
struct blk_desc *desc;
3638
};
3739

3840
static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this,
@@ -172,26 +174,26 @@ static const struct efi_block_io block_io_disk_template = {
172174

173175
static void efi_disk_add_dev(const char *name,
174176
const char *if_typename,
175-
const struct blk_desc *desc,
177+
struct blk_desc *desc,
176178
int dev_index,
177-
lbaint_t offset)
179+
lbaint_t offset,
180+
unsigned int part)
178181
{
179182
struct efi_disk_obj *diskobj;
180-
struct efi_device_path_file_path *dp;
181-
int objlen = sizeof(*diskobj) + (sizeof(*dp) * 2);
182183

183184
/* Don't add empty devices */
184185
if (!desc->lba)
185186
return;
186187

187-
diskobj = calloc(1, objlen);
188+
diskobj = calloc(1, sizeof(*diskobj));
188189

189190
/* Fill in object data */
190-
dp = (void *)&diskobj[1];
191+
diskobj->dp = efi_dp_from_part(desc, part);
192+
diskobj->part = part;
191193
diskobj->parent.protocols[0].guid = &efi_block_io_guid;
192194
diskobj->parent.protocols[0].protocol_interface = &diskobj->ops;
193195
diskobj->parent.protocols[1].guid = &efi_guid_device_path;
194-
diskobj->parent.protocols[1].protocol_interface = dp;
196+
diskobj->parent.protocols[1].protocol_interface = diskobj->dp;
195197
diskobj->parent.handle = diskobj;
196198
diskobj->ops = block_io_disk_template;
197199
diskobj->ifname = if_typename;
@@ -207,17 +209,6 @@ static void efi_disk_add_dev(const char *name,
207209
diskobj->media.last_block = desc->lba - offset;
208210
diskobj->ops.media = &diskobj->media;
209211

210-
/* Fill in device path */
211-
diskobj->dp = dp;
212-
dp[0].dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
213-
dp[0].dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
214-
dp[0].dp.length = sizeof(*dp);
215-
ascii2unicode(dp[0].str, name);
216-
217-
dp[1].dp.type = DEVICE_PATH_TYPE_END;
218-
dp[1].dp.sub_type = DEVICE_PATH_SUB_TYPE_END;
219-
dp[1].dp.length = sizeof(*dp);
220-
221212
/* Hook up to the device list */
222213
list_add_tail(&diskobj->parent.link, &efi_obj_list);
223214
}
@@ -236,14 +227,18 @@ static int efi_disk_create_eltorito(struct blk_desc *desc,
236227
if (desc->part_type != PART_TYPE_ISO)
237228
return 0;
238229

230+
/* and devices for each partition: */
239231
while (!part_get_info(desc, part, &info)) {
240232
snprintf(devname, sizeof(devname), "%s:%d", pdevname,
241233
part);
242234
efi_disk_add_dev(devname, if_typename, desc, diskid,
243-
info.start);
235+
info.start, part);
244236
part++;
245237
disks++;
246238
}
239+
240+
/* ... and add block device: */
241+
efi_disk_add_dev(devname, if_typename, desc, diskid, 0, 0);
247242
#endif
248243

249244
return disks;
@@ -271,9 +266,22 @@ int efi_disk_register(void)
271266
uclass_next_device_check(&dev)) {
272267
struct blk_desc *desc = dev_get_uclass_platdata(dev);
273268
const char *if_typename = dev->driver->name;
269+
disk_partition_t info;
270+
int part = 1;
274271

275272
printf("Scanning disk %s...\n", dev->name);
276-
efi_disk_add_dev(dev->name, if_typename, desc, desc->devnum, 0);
273+
274+
/* add devices for each partition: */
275+
while (!part_get_info(desc, part, &info)) {
276+
efi_disk_add_dev(dev->name, if_typename, desc,
277+
desc->devnum, 0, part);
278+
part++;
279+
}
280+
281+
/* ... and add block device: */
282+
efi_disk_add_dev(dev->name, if_typename, desc,
283+
desc->devnum, 0, 0);
284+
277285
disks++;
278286

279287
/*
@@ -309,7 +317,7 @@ int efi_disk_register(void)
309317

310318
snprintf(devname, sizeof(devname), "%s%d",
311319
if_typename, i);
312-
efi_disk_add_dev(devname, if_typename, desc, i, 0);
320+
efi_disk_add_dev(devname, if_typename, desc, i, 0, 0);
313321
disks++;
314322

315323
/*

0 commit comments

Comments
 (0)