]> git.sur5r.net Git - u-boot/commitdiff
dm: efi: Update for CONFIG_BLK
authorSimon Glass <sjg@chromium.org>
Sat, 14 May 2016 20:03:05 +0000 (14:03 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 27 May 2016 16:23:09 +0000 (10:23 -0600)
This code does not currently build with driver model enabled for block
devices. Update it to correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alexander Graf <agraf@suse.de>
include/efi_loader.h
lib/efi_loader/efi_disk.c

index 88b8149b147585aeca9ef07bcdf02cc3356b7b95..44a950f4842e590ccf1af1d9ae0c4816c6073755 100644 (file)
@@ -134,7 +134,7 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
 int efi_memory_init(void);
 
 /* Convert strings from normal C strings to uEFI strings */
-static inline void ascii2unicode(u16 *unicode, char *ascii)
+static inline void ascii2unicode(u16 *unicode, const char *ascii)
 {
        while (*ascii)
                *(unicode++) = *(ascii++);
index 075fd3401450d41320353d2db42ad9fdb03ccc59..3095bcfa2bfd2fd8552f20a99ef65135c8bb3247 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <common.h>
 #include <blk.h>
+#include <dm.h>
 #include <efi_loader.h>
 #include <inttypes.h>
 #include <part.h>
@@ -96,9 +97,9 @@ static efi_status_t EFIAPI efi_disk_rw_blocks(struct efi_block_io *this,
                return EFI_EXIT(EFI_DEVICE_ERROR);
 
        if (direction == EFI_DISK_READ)
-               n = desc->block_read(desc, lba, blocks, buffer);
+               n = blk_dread(desc, lba, blocks, buffer);
        else
-               n = desc->block_write(desc, lba, blocks, buffer);
+               n = blk_dwrite(desc, lba, blocks, buffer);
 
        /* We don't do interrupts, so check for timers cooperatively */
        efi_timer_check();
@@ -142,8 +143,8 @@ static const struct efi_block_io block_io_disk_template = {
        .flush_blocks = &efi_disk_flush_blocks,
 };
 
-static void efi_disk_add_dev(char *name,
-                            const struct blk_driver *cur_drvr,
+static void efi_disk_add_dev(const char *name,
+                            const char *if_typename,
                             const struct blk_desc *desc,
                             int dev_index,
                             lbaint_t offset)
@@ -161,7 +162,7 @@ static void efi_disk_add_dev(char *name,
        diskobj->parent.protocols[1].open = efi_disk_open_dp;
        diskobj->parent.handle = diskobj;
        diskobj->ops = block_io_disk_template;
-       diskobj->ifname = cur_drvr->if_typename;
+       diskobj->ifname = if_typename;
        diskobj->dev_index = dev_index;
        diskobj->offset = offset;
 
@@ -190,7 +191,7 @@ static void efi_disk_add_dev(char *name,
 }
 
 static int efi_disk_create_eltorito(struct blk_desc *desc,
-                                   const struct blk_driver *cur_drvr,
+                                   const char *if_typename,
                                    int diskid)
 {
        int disks = 0;
@@ -203,9 +204,10 @@ static int efi_disk_create_eltorito(struct blk_desc *desc,
                return 0;
 
        while (!part_get_info(desc, part, &info)) {
-               snprintf(devname, sizeof(devname), "%s%d:%d",
-                        cur_drvr->if_typename, diskid, part);
-               efi_disk_add_dev(devname, cur_drvr, desc, diskid, info.start);
+               snprintf(devname, sizeof(devname), "%s%d:%d", if_typename,
+                        diskid, part);
+               efi_disk_add_dev(devname, if_typename, desc, diskid,
+                                info.start);
                part++;
                disks++;
        }
@@ -219,21 +221,49 @@ static int efi_disk_create_eltorito(struct blk_desc *desc,
  * EFI payload, we scan through all of the potentially available ones and
  * store them in our object pool.
  *
+ * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this.
+ * Consider converting the code to look up devices as needed. The EFI device
+ * could be a child of the UCLASS_BLK block device, perhaps.
+ *
  * This gets called from do_bootefi_exec().
  */
 int efi_disk_register(void)
 {
-       const struct blk_driver *cur_drvr;
-       int i, if_type;
        int disks = 0;
+#ifdef CONFIG_BLK
+       struct udevice *dev;
+
+       for (uclass_first_device(UCLASS_BLK, &dev);
+            dev;
+            uclass_next_device(&dev)) {
+               struct blk_desc *desc = dev_get_uclass_platdata(dev);
+               const char *if_typename = dev->driver->name;
+
+               printf("Scanning disk %s...\n", dev->name);
+               efi_disk_add_dev(dev->name, if_typename, desc, desc->devnum, 0);
+               disks++;
+
+               /*
+               * El Torito images show up as block devices in an EFI world,
+               * so let's create them here
+               */
+               disks += efi_disk_create_eltorito(desc, if_typename,
+                                                 desc->devnum);
+       }
+#else
+       int i, if_type;
 
        /* Search for all available disk devices */
        for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) {
+               const struct blk_driver *cur_drvr;
+               const char *if_typename;
+
                cur_drvr = blk_driver_lookup_type(if_type);
                if (!cur_drvr)
                        continue;
 
-               printf("Scanning disks on %s...\n", cur_drvr->if_typename);
+               if_typename = cur_drvr->if_typename;
+               printf("Scanning disks on %s...\n", if_typename);
                for (i = 0; i < 4; i++) {
                        struct blk_desc *desc;
                        char devname[32] = { 0 }; /* dp->str is u16[32] long */
@@ -245,17 +275,18 @@ int efi_disk_register(void)
                                continue;
 
                        snprintf(devname, sizeof(devname), "%s%d",
-                                cur_drvr->if_typename, i);
-                       efi_disk_add_dev(devname, cur_drvr, desc, i, 0);
+                                if_typename, i);
+                       efi_disk_add_dev(devname, if_typename, desc, i, 0);
                        disks++;
 
                        /*
                         * El Torito images show up as block devices
                         * in an EFI world, so let's create them here
                         */
-                       disks += efi_disk_create_eltorito(desc, cur_drvr, i);
+                       disks += efi_disk_create_eltorito(desc, if_typename, i);
                }
        }
+#endif
        printf("Found %d disks\n", disks);
 
        return 0;