blob: 13fcc1b471c52e9a09cb378c82825676624b142f [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Grafe83be452016-03-04 01:10:02 +01002/*
3 * EFI application disk support
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Grafe83be452016-03-04 01:10:02 +01006 */
7
8#include <common.h>
Simon Glasse3dfa912016-05-01 13:52:32 -06009#include <blk.h>
Simon Glass302d4f82016-05-14 14:03:05 -060010#include <dm.h>
Alexander Grafe83be452016-03-04 01:10:02 +010011#include <efi_loader.h>
Alexander Grafe83be452016-03-04 01:10:02 +010012#include <part.h>
13#include <malloc.h>
14
Heinrich Schuchardt405afb52018-01-19 20:24:45 +010015const efi_guid_t efi_block_io_guid = BLOCK_IO_GUID;
Alexander Grafe83be452016-03-04 01:10:02 +010016
17struct efi_disk_obj {
18 /* Generic EFI object parent class data */
19 struct efi_object parent;
20 /* EFI Interface callback struct for block I/O */
21 struct efi_block_io ops;
22 /* U-Boot ifname for block device */
23 const char *ifname;
24 /* U-Boot dev_index for block device */
25 int dev_index;
26 /* EFI Interface Media descriptor struct, referenced by ops */
27 struct efi_block_io_media media;
28 /* EFI device path to this block device */
Rob Clarka83272f2017-09-13 18:05:31 -040029 struct efi_device_path *dp;
30 /* partition # */
31 unsigned int part;
Rob Clark53142032017-09-13 18:05:34 -040032 /* handle to filesys proto (for partition objects) */
33 struct efi_simple_file_system_protocol *volume;
Alexander Grafeb8d82c2016-04-11 16:16:18 +020034 /* Offset into disk for simple partitions */
35 lbaint_t offset;
Alexander Graf34118e72016-08-05 14:49:53 +020036 /* Internal block device */
Rob Clarka83272f2017-09-13 18:05:31 -040037 struct blk_desc *desc;
Alexander Grafe83be452016-03-04 01:10:02 +010038};
39
Alexander Grafe83be452016-03-04 01:10:02 +010040static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this,
41 char extended_verification)
42{
43 EFI_ENTRY("%p, %x", this, extended_verification);
44 return EFI_EXIT(EFI_DEVICE_ERROR);
45}
46
47enum efi_disk_direction {
48 EFI_DISK_READ,
49 EFI_DISK_WRITE,
50};
51
Heinrich Schuchardt9ce06172017-08-26 22:33:13 +020052static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this,
Alexander Grafe83be452016-03-04 01:10:02 +010053 u32 media_id, u64 lba, unsigned long buffer_size,
54 void *buffer, enum efi_disk_direction direction)
55{
56 struct efi_disk_obj *diskobj;
57 struct blk_desc *desc;
58 int blksz;
59 int blocks;
60 unsigned long n;
61
Alexander Grafe83be452016-03-04 01:10:02 +010062 diskobj = container_of(this, struct efi_disk_obj, ops);
Alexander Graf34118e72016-08-05 14:49:53 +020063 desc = (struct blk_desc *) diskobj->desc;
Alexander Grafe83be452016-03-04 01:10:02 +010064 blksz = desc->blksz;
65 blocks = buffer_size / blksz;
Alexander Grafeb8d82c2016-04-11 16:16:18 +020066 lba += diskobj->offset;
Alexander Grafe83be452016-03-04 01:10:02 +010067
Masahiro Yamadac7570a32018-08-06 20:47:40 +090068 debug("EFI: %s:%d blocks=%x lba=%llx blksz=%x dir=%d\n", __func__,
Alexander Graf62a67482016-06-02 11:38:27 +020069 __LINE__, blocks, lba, blksz, direction);
Alexander Grafe83be452016-03-04 01:10:02 +010070
71 /* We only support full block access */
72 if (buffer_size & (blksz - 1))
Rob Clark99c43872017-07-25 20:28:29 -040073 return EFI_DEVICE_ERROR;
Alexander Grafe83be452016-03-04 01:10:02 +010074
75 if (direction == EFI_DISK_READ)
Simon Glass302d4f82016-05-14 14:03:05 -060076 n = blk_dread(desc, lba, blocks, buffer);
Alexander Grafe83be452016-03-04 01:10:02 +010077 else
Simon Glass302d4f82016-05-14 14:03:05 -060078 n = blk_dwrite(desc, lba, blocks, buffer);
Alexander Grafe83be452016-03-04 01:10:02 +010079
80 /* We don't do interrupts, so check for timers cooperatively */
81 efi_timer_check();
82
Alexander Graf62a67482016-06-02 11:38:27 +020083 debug("EFI: %s:%d n=%lx blocks=%x\n", __func__, __LINE__, n, blocks);
84
Alexander Grafe83be452016-03-04 01:10:02 +010085 if (n != blocks)
Rob Clark99c43872017-07-25 20:28:29 -040086 return EFI_DEVICE_ERROR;
Alexander Grafe83be452016-03-04 01:10:02 +010087
Rob Clark99c43872017-07-25 20:28:29 -040088 return EFI_SUCCESS;
Alexander Grafe83be452016-03-04 01:10:02 +010089}
90
Simon Glassc2194bf2016-09-25 15:27:32 -060091static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this,
Heinrich Schuchardt0844f792018-01-19 20:24:48 +010092 u32 media_id, u64 lba, efi_uintn_t buffer_size,
Alexander Grafe83be452016-03-04 01:10:02 +010093 void *buffer)
94{
Alexander Graf7c00a3c2016-05-11 18:25:48 +020095 void *real_buffer = buffer;
96 efi_status_t r;
97
98#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
99 if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) {
100 r = efi_disk_read_blocks(this, media_id, lba,
101 EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer);
102 if (r != EFI_SUCCESS)
103 return r;
104 return efi_disk_read_blocks(this, media_id, lba +
105 EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size,
106 buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE,
107 buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE);
108 }
109
110 real_buffer = efi_bounce_buffer;
111#endif
112
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900113 EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba,
Alexander Graf7c00a3c2016-05-11 18:25:48 +0200114 buffer_size, buffer);
115
116 r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer,
117 EFI_DISK_READ);
118
119 /* Copy from bounce buffer to real buffer if necessary */
120 if ((r == EFI_SUCCESS) && (real_buffer != buffer))
121 memcpy(buffer, real_buffer, buffer_size);
122
123 return EFI_EXIT(r);
Alexander Grafe83be452016-03-04 01:10:02 +0100124}
125
Simon Glassc2194bf2016-09-25 15:27:32 -0600126static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this,
Heinrich Schuchardt0844f792018-01-19 20:24:48 +0100127 u32 media_id, u64 lba, efi_uintn_t buffer_size,
Alexander Grafe83be452016-03-04 01:10:02 +0100128 void *buffer)
129{
Alexander Graf7c00a3c2016-05-11 18:25:48 +0200130 void *real_buffer = buffer;
131 efi_status_t r;
132
133#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
134 if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) {
135 r = efi_disk_write_blocks(this, media_id, lba,
136 EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer);
137 if (r != EFI_SUCCESS)
138 return r;
139 return efi_disk_write_blocks(this, media_id, lba +
140 EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size,
141 buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE,
142 buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE);
143 }
144
145 real_buffer = efi_bounce_buffer;
146#endif
147
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900148 EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba,
Alexander Graf7c00a3c2016-05-11 18:25:48 +0200149 buffer_size, buffer);
150
151 /* Populate bounce buffer if necessary */
152 if (real_buffer != buffer)
153 memcpy(real_buffer, buffer, buffer_size);
154
155 r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer,
156 EFI_DISK_WRITE);
157
158 return EFI_EXIT(r);
Alexander Grafe83be452016-03-04 01:10:02 +0100159}
160
161static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this)
162{
163 /* We always write synchronously */
164 EFI_ENTRY("%p", this);
165 return EFI_EXIT(EFI_SUCCESS);
166}
167
168static const struct efi_block_io block_io_disk_template = {
169 .reset = &efi_disk_reset,
170 .read_blocks = &efi_disk_read_blocks,
171 .write_blocks = &efi_disk_write_blocks,
172 .flush_blocks = &efi_disk_flush_blocks,
173};
174
Rob Clark53142032017-09-13 18:05:34 -0400175/*
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100176 * Get the simple file system protocol for a file device path.
177 *
178 * The full path provided is split into device part and into a file
179 * part. The device part is used to find the handle on which the
180 * simple file system protocol is installed.
181 *
182 * @full_path device path including device and file
183 * @return simple file system protocol
Rob Clark53142032017-09-13 18:05:34 -0400184 */
185struct efi_simple_file_system_protocol *
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100186efi_fs_from_path(struct efi_device_path *full_path)
Rob Clark53142032017-09-13 18:05:34 -0400187{
188 struct efi_object *efiobj;
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100189 struct efi_handler *handler;
190 struct efi_device_path *device_path;
191 struct efi_device_path *file_path;
192 efi_status_t ret;
Rob Clark53142032017-09-13 18:05:34 -0400193
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100194 /* Split the path into a device part and a file part */
195 ret = efi_dp_split_file_path(full_path, &device_path, &file_path);
196 if (ret != EFI_SUCCESS)
197 return NULL;
198 efi_free_pool(file_path);
199
200 /* Get the EFI object for the partition */
201 efiobj = efi_dp_find_obj(device_path, NULL);
202 efi_free_pool(device_path);
Rob Clark53142032017-09-13 18:05:34 -0400203 if (!efiobj)
204 return NULL;
205
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100206 /* Find the simple file system protocol */
207 ret = efi_search_protocol(efiobj, &efi_simple_file_system_protocol_guid,
208 &handler);
209 if (ret != EFI_SUCCESS)
210 return NULL;
Rob Clark53142032017-09-13 18:05:34 -0400211
Heinrich Schuchardt39578762018-01-19 20:24:39 +0100212 /* Return the simple file system protocol for the partition */
213 return handler->protocol_interface;
Rob Clark53142032017-09-13 18:05:34 -0400214}
215
Heinrich Schuchardt34f51832017-10-26 19:25:46 +0200216/*
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100217 * Create a handle for a partition or disk
Heinrich Schuchardt34f51832017-10-26 19:25:46 +0200218 *
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100219 * @parent parent handle
220 * @dp_parent parent device path
Heinrich Schuchardt34f51832017-10-26 19:25:46 +0200221 * @if_typename interface name for block device
222 * @desc internal block device
223 * @dev_index device index for block device
224 * @offset offset into disk for simple partitions
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100225 * @return disk object
Heinrich Schuchardt34f51832017-10-26 19:25:46 +0200226 */
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100227static efi_status_t efi_disk_add_dev(
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100228 efi_handle_t parent,
229 struct efi_device_path *dp_parent,
230 const char *if_typename,
231 struct blk_desc *desc,
232 int dev_index,
233 lbaint_t offset,
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100234 unsigned int part,
235 struct efi_disk_obj **disk)
Alexander Graf06fe57b2016-04-11 16:16:17 +0200236{
237 struct efi_disk_obj *diskobj;
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100238 efi_status_t ret;
Alexander Graf06fe57b2016-04-11 16:16:17 +0200239
Alexander Graf601db1f2016-08-05 14:51:47 +0200240 /* Don't add empty devices */
241 if (!desc->lba)
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100242 return EFI_NOT_READY;
Alexander Graf601db1f2016-08-05 14:51:47 +0200243
Rob Clarka83272f2017-09-13 18:05:31 -0400244 diskobj = calloc(1, sizeof(*diskobj));
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100245 if (!diskobj)
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100246 return EFI_OUT_OF_RESOURCES;
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100247
248 /* Hook up to the device list */
Heinrich Schuchardt967d7de2017-11-26 14:05:23 +0100249 efi_add_handle(&diskobj->parent);
Alexander Graf06fe57b2016-04-11 16:16:17 +0200250
251 /* Fill in object data */
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100252 if (part) {
253 struct efi_device_path *node = efi_dp_part_node(desc, part);
254
255 diskobj->dp = efi_dp_append_node(dp_parent, node);
256 efi_free_pool(node);
257 } else {
258 diskobj->dp = efi_dp_from_part(desc, part);
259 }
Rob Clarka83272f2017-09-13 18:05:31 -0400260 diskobj->part = part;
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100261 ret = efi_add_protocol(diskobj->parent.handle, &efi_block_io_guid,
262 &diskobj->ops);
263 if (ret != EFI_SUCCESS)
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100264 return ret;
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100265 ret = efi_add_protocol(diskobj->parent.handle, &efi_guid_device_path,
266 diskobj->dp);
267 if (ret != EFI_SUCCESS)
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100268 return ret;
Rob Clark53142032017-09-13 18:05:34 -0400269 if (part >= 1) {
270 diskobj->volume = efi_simple_file_system(desc, part,
271 diskobj->dp);
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100272 ret = efi_add_protocol(diskobj->parent.handle,
273 &efi_simple_file_system_protocol_guid,
Heinrich Schuchardtce721a82018-01-19 20:24:38 +0100274 diskobj->volume);
Heinrich Schuchardt9fb0f2f2017-11-26 14:05:12 +0100275 if (ret != EFI_SUCCESS)
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100276 return ret;
Rob Clark53142032017-09-13 18:05:34 -0400277 }
Alexander Graf06fe57b2016-04-11 16:16:17 +0200278 diskobj->ops = block_io_disk_template;
Simon Glass302d4f82016-05-14 14:03:05 -0600279 diskobj->ifname = if_typename;
Alexander Graf06fe57b2016-04-11 16:16:17 +0200280 diskobj->dev_index = dev_index;
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200281 diskobj->offset = offset;
Alexander Graf34118e72016-08-05 14:49:53 +0200282 diskobj->desc = desc;
Alexander Graf06fe57b2016-04-11 16:16:17 +0200283
284 /* Fill in EFI IO Media info (for read/write callbacks) */
285 diskobj->media.removable_media = desc->removable;
286 diskobj->media.media_present = 1;
287 diskobj->media.block_size = desc->blksz;
288 diskobj->media.io_align = desc->blksz;
Alexander Graf601db1f2016-08-05 14:51:47 +0200289 diskobj->media.last_block = desc->lba - offset;
Emmanuel Vadot5bf29642017-12-11 19:22:33 +0100290 if (part != 0)
291 diskobj->media.logical_partition = 1;
Alexander Graf06fe57b2016-04-11 16:16:17 +0200292 diskobj->ops.media = &diskobj->media;
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100293 if (disk)
294 *disk = diskobj;
295 return EFI_SUCCESS;
Alexander Graf06fe57b2016-04-11 16:16:17 +0200296}
297
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100298/*
299 * Create handles and protocols for the partitions of a block device
300 *
301 * @parent handle of the parent disk
302 * @blk_desc block device
303 * @if_typename interface type
304 * @diskid device number
305 * @pdevname device name
306 * @return number of partitions created
307 */
308int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
309 const char *if_typename, int diskid,
310 const char *pdevname)
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200311{
312 int disks = 0;
Alexander Graf3491ee72016-04-11 16:16:20 +0200313 char devname[32] = { 0 }; /* dp->str is u16[32] long */
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200314 disk_partition_t info;
Jonathan Grayd35cbd52017-10-10 13:55:26 +1100315 int part;
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100316 struct efi_device_path *dp = NULL;
317 efi_status_t ret;
318 struct efi_handler *handler;
319
320 /* Get the device path of the parent */
321 ret = efi_search_protocol(parent, &efi_guid_device_path, &handler);
322 if (ret == EFI_SUCCESS)
323 dp = handler->protocol_interface;
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200324
Alexander Graf83a83f22017-12-01 16:10:33 +0100325 /* Add devices for each partition */
Jonathan Grayd35cbd52017-10-10 13:55:26 +1100326 for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) {
327 if (part_get_info(desc, part, &info))
328 continue;
Alexander Graf34118e72016-08-05 14:49:53 +0200329 snprintf(devname, sizeof(devname), "%s:%d", pdevname,
330 part);
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100331 ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid,
332 info.start, part, NULL);
333 if (ret != EFI_SUCCESS) {
334 printf("Adding partition %s failed\n", pdevname);
335 continue;
336 }
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200337 disks++;
338 }
Rob Clarka83272f2017-09-13 18:05:31 -0400339
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200340 return disks;
341}
342
Alexander Grafe83be452016-03-04 01:10:02 +0100343/*
344 * U-Boot doesn't have a list of all online disk devices. So when running our
345 * EFI payload, we scan through all of the potentially available ones and
346 * store them in our object pool.
347 *
Simon Glass302d4f82016-05-14 14:03:05 -0600348 * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this.
349 * Consider converting the code to look up devices as needed. The EFI device
350 * could be a child of the UCLASS_BLK block device, perhaps.
351 *
Alexander Grafe83be452016-03-04 01:10:02 +0100352 * This gets called from do_bootefi_exec().
353 */
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100354efi_status_t efi_disk_register(void)
Alexander Grafe83be452016-03-04 01:10:02 +0100355{
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100356 struct efi_disk_obj *disk;
Alexander Grafe83be452016-03-04 01:10:02 +0100357 int disks = 0;
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100358 efi_status_t ret;
Simon Glass302d4f82016-05-14 14:03:05 -0600359#ifdef CONFIG_BLK
360 struct udevice *dev;
361
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100362 for (uclass_first_device_check(UCLASS_BLK, &dev); dev;
xypron.glpk@gmx.de308cd8e2017-06-20 19:10:27 +0000363 uclass_next_device_check(&dev)) {
Simon Glass302d4f82016-05-14 14:03:05 -0600364 struct blk_desc *desc = dev_get_uclass_platdata(dev);
Heinrich Schuchardt6a18bb32018-01-19 20:24:44 +0100365 const char *if_typename = blk_get_if_type_name(desc->if_type);
Simon Glass302d4f82016-05-14 14:03:05 -0600366
Alexander Graf83a83f22017-12-01 16:10:33 +0100367 /* Add block device for the full device */
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100368 printf("Scanning disk %s...\n", dev->name);
369 ret = efi_disk_add_dev(NULL, NULL, if_typename,
370 desc, desc->devnum, 0, 0, &disk);
371 if (ret == EFI_NOT_READY) {
372 printf("Disk %s not ready\n", dev->name);
373 continue;
374 }
375 if (ret) {
376 printf("ERROR: failure to add disk device %s, r = %lu\n",
377 dev->name, ret & ~EFI_ERROR_MASK);
378 return ret;
379 }
Simon Glass302d4f82016-05-14 14:03:05 -0600380 disks++;
381
Alexander Graf83a83f22017-12-01 16:10:33 +0100382 /* Partitions show up as block devices in EFI */
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100383 disks += efi_disk_create_partitions(
384 disk->parent.handle, desc, if_typename,
385 desc->devnum, dev->name);
Simon Glass302d4f82016-05-14 14:03:05 -0600386 }
387#else
388 int i, if_type;
Alexander Grafe83be452016-03-04 01:10:02 +0100389
390 /* Search for all available disk devices */
Simon Glasse3dfa912016-05-01 13:52:32 -0600391 for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) {
Simon Glass302d4f82016-05-14 14:03:05 -0600392 const struct blk_driver *cur_drvr;
393 const char *if_typename;
394
Simon Glasse3dfa912016-05-01 13:52:32 -0600395 cur_drvr = blk_driver_lookup_type(if_type);
396 if (!cur_drvr)
397 continue;
398
Simon Glass302d4f82016-05-14 14:03:05 -0600399 if_typename = cur_drvr->if_typename;
400 printf("Scanning disks on %s...\n", if_typename);
Alexander Grafe83be452016-03-04 01:10:02 +0100401 for (i = 0; i < 4; i++) {
402 struct blk_desc *desc;
Alexander Graf3491ee72016-04-11 16:16:20 +0200403 char devname[32] = { 0 }; /* dp->str is u16[32] long */
Alexander Grafe83be452016-03-04 01:10:02 +0100404
Simon Glasse3dfa912016-05-01 13:52:32 -0600405 desc = blk_get_devnum_by_type(if_type, i);
Alexander Grafe83be452016-03-04 01:10:02 +0100406 if (!desc)
407 continue;
408 if (desc->type == DEV_TYPE_UNKNOWN)
409 continue;
410
Alexander Grafe83be452016-03-04 01:10:02 +0100411 snprintf(devname, sizeof(devname), "%s%d",
Simon Glass302d4f82016-05-14 14:03:05 -0600412 if_typename, i);
Rob Clark1b2ccbb2017-10-08 11:33:08 -0400413
Alexander Graf83a83f22017-12-01 16:10:33 +0100414 /* Add block device for the full device */
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100415 ret = efi_disk_add_dev(NULL, NULL, if_typename, desc,
416 i, 0, 0, &disk);
417 if (ret == EFI_NOT_READY) {
418 printf("Disk %s not ready\n", devname);
419 continue;
420 }
421 if (ret) {
422 printf("ERROR: failure to add disk device %s, r = %lu\n",
423 devname, ret & ~EFI_ERROR_MASK);
424 return ret;
425 }
Alexander Grafe83be452016-03-04 01:10:02 +0100426 disks++;
Alexander Grafeb8d82c2016-04-11 16:16:18 +0200427
Alexander Graf83a83f22017-12-01 16:10:33 +0100428 /* Partitions show up as block devices in EFI */
Heinrich Schuchardt6f3de6b2018-01-19 20:24:47 +0100429 disks += efi_disk_create_partitions(
430 disk->parent.handle, desc,
431 if_typename, i, devname);
Alexander Grafe83be452016-03-04 01:10:02 +0100432 }
433 }
Simon Glass302d4f82016-05-14 14:03:05 -0600434#endif
Alexander Grafe83be452016-03-04 01:10:02 +0100435 printf("Found %d disks\n", disks);
436
Heinrich Schuchardtcde7a362018-02-09 20:55:47 +0100437 return EFI_SUCCESS;
Alexander Grafe83be452016-03-04 01:10:02 +0100438}