struct efi_device_path *dp;
/* partition # */
unsigned int part;
+ /* handle to filesys proto (for partition objects) */
+ struct efi_simple_file_system_protocol *volume;
/* Offset into disk for simple partitions */
lbaint_t offset;
/* Internal block device */
.flush_blocks = &efi_disk_flush_blocks,
};
+/*
+ * Find filesystem from a device-path. The passed in path 'p' probably
+ * contains one or more /File(name) nodes, so the comparison stops at
+ * the first /File() node, and returns the pointer to that via 'rp'.
+ * This is mostly intended to be a helper to map a device-path to an
+ * efi_file_handle object.
+ */
+struct efi_simple_file_system_protocol *
+efi_fs_from_path(struct efi_device_path *fp)
+{
+ struct efi_object *efiobj;
+ struct efi_disk_obj *diskobj;
+
+ efiobj = efi_dp_find_obj(fp, NULL);
+ if (!efiobj)
+ return NULL;
+
+ diskobj = container_of(efiobj, struct efi_disk_obj, parent);
+
+ return diskobj->volume;
+}
+
+/*
+ * Create a device for a disk
+ *
+ * @name not used
+ * @if_typename interface name for block device
+ * @desc internal block device
+ * @dev_index device index for block device
+ * @offset offset into disk for simple partitions
+ */
static void efi_disk_add_dev(const char *name,
const char *if_typename,
struct blk_desc *desc,
unsigned int part)
{
struct efi_disk_obj *diskobj;
+ efi_status_t ret;
/* Don't add empty devices */
if (!desc->lba)
return;
diskobj = calloc(1, sizeof(*diskobj));
+ if (!diskobj)
+ goto out_of_memory;
+
+ /* Hook up to the device list */
+ list_add_tail(&diskobj->parent.link, &efi_obj_list);
/* Fill in object data */
diskobj->dp = efi_dp_from_part(desc, part);
diskobj->part = part;
- diskobj->parent.protocols[0].guid = &efi_block_io_guid;
- diskobj->parent.protocols[0].protocol_interface = &diskobj->ops;
- diskobj->parent.protocols[1].guid = &efi_guid_device_path;
- diskobj->parent.protocols[1].protocol_interface = diskobj->dp;
diskobj->parent.handle = diskobj;
+ ret = efi_add_protocol(diskobj->parent.handle, &efi_block_io_guid,
+ &diskobj->ops);
+ if (ret != EFI_SUCCESS)
+ goto out_of_memory;
+ ret = efi_add_protocol(diskobj->parent.handle, &efi_guid_device_path,
+ diskobj->dp);
+ if (ret != EFI_SUCCESS)
+ goto out_of_memory;
+ if (part >= 1) {
+ diskobj->volume = efi_simple_file_system(desc, part,
+ diskobj->dp);
+ ret = efi_add_protocol(diskobj->parent.handle,
+ &efi_simple_file_system_protocol_guid,
+ &diskobj->volume);
+ if (ret != EFI_SUCCESS)
+ goto out_of_memory;
+ }
diskobj->ops = block_io_disk_template;
diskobj->ifname = if_typename;
diskobj->dev_index = dev_index;
diskobj->media.io_align = desc->blksz;
diskobj->media.last_block = desc->lba - offset;
diskobj->ops.media = &diskobj->media;
-
- /* Hook up to the device list */
- list_add_tail(&diskobj->parent.link, &efi_obj_list);
+ return;
+out_of_memory:
+ printf("ERROR: Out of memory\n");
}
static int efi_disk_create_eltorito(struct blk_desc *desc,
#if CONFIG_IS_ENABLED(ISO_PARTITION)
char devname[32] = { 0 }; /* dp->str is u16[32] long */
disk_partition_t info;
- int part = 1;
+ int part;
if (desc->part_type != PART_TYPE_ISO)
return 0;
/* and devices for each partition: */
- while (!part_get_info(desc, part, &info)) {
+ for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
+ if (part_get_info(desc, part, &info))
+ continue;
snprintf(devname, sizeof(devname), "%s:%d", pdevname,
part);
efi_disk_add_dev(devname, if_typename, desc, diskid,
info.start, part);
- part++;
disks++;
}
struct blk_desc *desc = dev_get_uclass_platdata(dev);
const char *if_typename = dev->driver->name;
disk_partition_t info;
- int part = 1;
+ int part;
printf("Scanning disk %s...\n", dev->name);
/* add devices for each partition: */
- while (!part_get_info(desc, part, &info)) {
+ 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);
- part++;
}
/* ... and add block device: */
for (i = 0; i < 4; i++) {
struct blk_desc *desc;
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);
if (!desc)
snprintf(devname, sizeof(devname), "%s%d",
if_typename, i);
+
+ /* add devices for each partition: */
+ 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);
disks++;