Commit 487d756f78629f5e9465c7ace2c14ef51401bc3b

Authored by Simon Glass
1 parent 19d2e34237

dm: efi: Update for CONFIG_BLK

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>

Showing 2 changed files with 47 additions and 16 deletions Side-by-side Diff

include/efi_loader.h
... ... @@ -134,7 +134,7 @@
134 134 int efi_memory_init(void);
135 135  
136 136 /* Convert strings from normal C strings to uEFI strings */
137   -static inline void ascii2unicode(u16 *unicode, char *ascii)
  137 +static inline void ascii2unicode(u16 *unicode, const char *ascii)
138 138 {
139 139 while (*ascii)
140 140 *(unicode++) = *(ascii++);
lib/efi_loader/efi_disk.c
... ... @@ -8,6 +8,7 @@
8 8  
9 9 #include <common.h>
10 10 #include <blk.h>
  11 +#include <dm.h>
11 12 #include <efi_loader.h>
12 13 #include <inttypes.h>
13 14 #include <part.h>
14 15  
... ... @@ -96,9 +97,9 @@
96 97 return EFI_EXIT(EFI_DEVICE_ERROR);
97 98  
98 99 if (direction == EFI_DISK_READ)
99   - n = desc->block_read(desc, lba, blocks, buffer);
  100 + n = blk_dread(desc, lba, blocks, buffer);
100 101 else
101   - n = desc->block_write(desc, lba, blocks, buffer);
  102 + n = blk_dwrite(desc, lba, blocks, buffer);
102 103  
103 104 /* We don't do interrupts, so check for timers cooperatively */
104 105 efi_timer_check();
... ... @@ -142,8 +143,8 @@
142 143 .flush_blocks = &efi_disk_flush_blocks,
143 144 };
144 145  
145   -static void efi_disk_add_dev(char *name,
146   - const struct blk_driver *cur_drvr,
  146 +static void efi_disk_add_dev(const char *name,
  147 + const char *if_typename,
147 148 const struct blk_desc *desc,
148 149 int dev_index,
149 150 lbaint_t offset)
... ... @@ -161,7 +162,7 @@
161 162 diskobj->parent.protocols[1].open = efi_disk_open_dp;
162 163 diskobj->parent.handle = diskobj;
163 164 diskobj->ops = block_io_disk_template;
164   - diskobj->ifname = cur_drvr->if_typename;
  165 + diskobj->ifname = if_typename;
165 166 diskobj->dev_index = dev_index;
166 167 diskobj->offset = offset;
167 168  
... ... @@ -190,7 +191,7 @@
190 191 }
191 192  
192 193 static int efi_disk_create_eltorito(struct blk_desc *desc,
193   - const struct blk_driver *cur_drvr,
  194 + const char *if_typename,
194 195 int diskid)
195 196 {
196 197 int disks = 0;
... ... @@ -203,9 +204,10 @@
203 204 return 0;
204 205  
205 206 while (!part_get_info(desc, part, &info)) {
206   - snprintf(devname, sizeof(devname), "%s%d:%d",
207   - cur_drvr->if_typename, diskid, part);
208   - efi_disk_add_dev(devname, cur_drvr, desc, diskid, info.start);
  207 + snprintf(devname, sizeof(devname), "%s%d:%d", if_typename,
  208 + diskid, part);
  209 + efi_disk_add_dev(devname, if_typename, desc, diskid,
  210 + info.start);
209 211 part++;
210 212 disks++;
211 213 }
212 214  
213 215  
214 216  
215 217  
216 218  
... ... @@ -219,21 +221,49 @@
219 221 * EFI payload, we scan through all of the potentially available ones and
220 222 * store them in our object pool.
221 223 *
  224 + * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this.
  225 + * Consider converting the code to look up devices as needed. The EFI device
  226 + * could be a child of the UCLASS_BLK block device, perhaps.
  227 + *
222 228 * This gets called from do_bootefi_exec().
223 229 */
224 230 int efi_disk_register(void)
225 231 {
226   - const struct blk_driver *cur_drvr;
227   - int i, if_type;
228 232 int disks = 0;
  233 +#ifdef CONFIG_BLK
  234 + struct udevice *dev;
229 235  
  236 + for (uclass_first_device(UCLASS_BLK, &dev);
  237 + dev;
  238 + uclass_next_device(&dev)) {
  239 + struct blk_desc *desc = dev_get_uclass_platdata(dev);
  240 + const char *if_typename = dev->driver->name;
  241 +
  242 + printf("Scanning disk %s...\n", dev->name);
  243 + efi_disk_add_dev(dev->name, if_typename, desc, desc->devnum, 0);
  244 + disks++;
  245 +
  246 + /*
  247 + * El Torito images show up as block devices in an EFI world,
  248 + * so let's create them here
  249 + */
  250 + disks += efi_disk_create_eltorito(desc, if_typename,
  251 + desc->devnum);
  252 + }
  253 +#else
  254 + int i, if_type;
  255 +
230 256 /* Search for all available disk devices */
231 257 for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) {
  258 + const struct blk_driver *cur_drvr;
  259 + const char *if_typename;
  260 +
232 261 cur_drvr = blk_driver_lookup_type(if_type);
233 262 if (!cur_drvr)
234 263 continue;
235 264  
236   - printf("Scanning disks on %s...\n", cur_drvr->if_typename);
  265 + if_typename = cur_drvr->if_typename;
  266 + printf("Scanning disks on %s...\n", if_typename);
237 267 for (i = 0; i < 4; i++) {
238 268 struct blk_desc *desc;
239 269 char devname[32] = { 0 }; /* dp->str is u16[32] long */
240 270  
241 271  
... ... @@ -245,17 +275,18 @@
245 275 continue;
246 276  
247 277 snprintf(devname, sizeof(devname), "%s%d",
248   - cur_drvr->if_typename, i);
249   - efi_disk_add_dev(devname, cur_drvr, desc, i, 0);
  278 + if_typename, i);
  279 + efi_disk_add_dev(devname, if_typename, desc, i, 0);
250 280 disks++;
251 281  
252 282 /*
253 283 * El Torito images show up as block devices
254 284 * in an EFI world, so let's create them here
255 285 */
256   - disks += efi_disk_create_eltorito(desc, cur_drvr, i);
  286 + disks += efi_disk_create_eltorito(desc, if_typename, i);
257 287 }
258 288 }
  289 +#endif
259 290 printf("Found %d disks\n", disks);
260 291  
261 292 return 0;