Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * EFI application disk support |
| 3 | * |
| 4 | * Copyright (c) 2016 Alexander Graf |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 6dd9faf | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 10 | #include <blk.h> |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 12 | #include <efi_loader.h> |
| 13 | #include <inttypes.h> |
| 14 | #include <part.h> |
| 15 | #include <malloc.h> |
| 16 | |
| 17 | static const efi_guid_t efi_block_io_guid = BLOCK_IO_GUID; |
| 18 | |
| 19 | struct efi_disk_obj { |
| 20 | /* Generic EFI object parent class data */ |
| 21 | struct efi_object parent; |
| 22 | /* EFI Interface callback struct for block I/O */ |
| 23 | struct efi_block_io ops; |
| 24 | /* U-Boot ifname for block device */ |
| 25 | const char *ifname; |
| 26 | /* U-Boot dev_index for block device */ |
| 27 | int dev_index; |
| 28 | /* EFI Interface Media descriptor struct, referenced by ops */ |
| 29 | struct efi_block_io_media media; |
| 30 | /* EFI device path to this block device */ |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 31 | struct efi_device_path *dp; |
| 32 | /* partition # */ |
| 33 | unsigned int part; |
Rob Clark | 2a92080 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 34 | /* handle to filesys proto (for partition objects) */ |
| 35 | struct efi_simple_file_system_protocol *volume; |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 36 | /* Offset into disk for simple partitions */ |
| 37 | lbaint_t offset; |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 38 | /* Internal block device */ |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 39 | struct blk_desc *desc; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 42 | static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this, |
| 43 | char extended_verification) |
| 44 | { |
| 45 | EFI_ENTRY("%p, %x", this, extended_verification); |
| 46 | return EFI_EXIT(EFI_DEVICE_ERROR); |
| 47 | } |
| 48 | |
| 49 | enum efi_disk_direction { |
| 50 | EFI_DISK_READ, |
| 51 | EFI_DISK_WRITE, |
| 52 | }; |
| 53 | |
Heinrich Schuchardt | a80a232 | 2017-08-26 22:33:13 +0200 | [diff] [blame] | 54 | static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 55 | u32 media_id, u64 lba, unsigned long buffer_size, |
| 56 | void *buffer, enum efi_disk_direction direction) |
| 57 | { |
| 58 | struct efi_disk_obj *diskobj; |
| 59 | struct blk_desc *desc; |
| 60 | int blksz; |
| 61 | int blocks; |
| 62 | unsigned long n; |
| 63 | |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 64 | diskobj = container_of(this, struct efi_disk_obj, ops); |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 65 | desc = (struct blk_desc *) diskobj->desc; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 66 | blksz = desc->blksz; |
| 67 | blocks = buffer_size / blksz; |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 68 | lba += diskobj->offset; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 69 | |
Alexander Graf | edcef3b | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 70 | debug("EFI: %s:%d blocks=%x lba=%"PRIx64" blksz=%x dir=%d\n", __func__, |
| 71 | __LINE__, blocks, lba, blksz, direction); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 72 | |
| 73 | /* We only support full block access */ |
| 74 | if (buffer_size & (blksz - 1)) |
Rob Clark | 3304990 | 2017-07-25 20:28:29 -0400 | [diff] [blame] | 75 | return EFI_DEVICE_ERROR; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 76 | |
| 77 | if (direction == EFI_DISK_READ) |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 78 | n = blk_dread(desc, lba, blocks, buffer); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 79 | else |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 80 | n = blk_dwrite(desc, lba, blocks, buffer); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 81 | |
| 82 | /* We don't do interrupts, so check for timers cooperatively */ |
| 83 | efi_timer_check(); |
| 84 | |
Alexander Graf | edcef3b | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 85 | debug("EFI: %s:%d n=%lx blocks=%x\n", __func__, __LINE__, n, blocks); |
| 86 | |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 87 | if (n != blocks) |
Rob Clark | 3304990 | 2017-07-25 20:28:29 -0400 | [diff] [blame] | 88 | return EFI_DEVICE_ERROR; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 89 | |
Rob Clark | 3304990 | 2017-07-25 20:28:29 -0400 | [diff] [blame] | 90 | return EFI_SUCCESS; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Simon Glass | e275458 | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 93 | static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this, |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 94 | u32 media_id, u64 lba, unsigned long buffer_size, |
| 95 | void *buffer) |
| 96 | { |
Alexander Graf | 51735ae | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 97 | void *real_buffer = buffer; |
| 98 | efi_status_t r; |
| 99 | |
| 100 | #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER |
| 101 | if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) { |
| 102 | r = efi_disk_read_blocks(this, media_id, lba, |
| 103 | EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer); |
| 104 | if (r != EFI_SUCCESS) |
| 105 | return r; |
| 106 | return efi_disk_read_blocks(this, media_id, lba + |
| 107 | EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size, |
| 108 | buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE, |
| 109 | buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE); |
| 110 | } |
| 111 | |
| 112 | real_buffer = efi_bounce_buffer; |
| 113 | #endif |
| 114 | |
| 115 | EFI_ENTRY("%p, %x, %"PRIx64", %lx, %p", this, media_id, lba, |
| 116 | buffer_size, buffer); |
| 117 | |
| 118 | r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer, |
| 119 | EFI_DISK_READ); |
| 120 | |
| 121 | /* Copy from bounce buffer to real buffer if necessary */ |
| 122 | if ((r == EFI_SUCCESS) && (real_buffer != buffer)) |
| 123 | memcpy(buffer, real_buffer, buffer_size); |
| 124 | |
| 125 | return EFI_EXIT(r); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Simon Glass | e275458 | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 128 | static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this, |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 129 | u32 media_id, u64 lba, unsigned long buffer_size, |
| 130 | void *buffer) |
| 131 | { |
Alexander Graf | 51735ae | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 132 | void *real_buffer = buffer; |
| 133 | efi_status_t r; |
| 134 | |
| 135 | #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER |
| 136 | if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) { |
| 137 | r = efi_disk_write_blocks(this, media_id, lba, |
| 138 | EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer); |
| 139 | if (r != EFI_SUCCESS) |
| 140 | return r; |
| 141 | return efi_disk_write_blocks(this, media_id, lba + |
| 142 | EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size, |
| 143 | buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE, |
| 144 | buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE); |
| 145 | } |
| 146 | |
| 147 | real_buffer = efi_bounce_buffer; |
| 148 | #endif |
| 149 | |
| 150 | EFI_ENTRY("%p, %x, %"PRIx64", %lx, %p", this, media_id, lba, |
| 151 | buffer_size, buffer); |
| 152 | |
| 153 | /* Populate bounce buffer if necessary */ |
| 154 | if (real_buffer != buffer) |
| 155 | memcpy(real_buffer, buffer, buffer_size); |
| 156 | |
| 157 | r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer, |
| 158 | EFI_DISK_WRITE); |
| 159 | |
| 160 | return EFI_EXIT(r); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this) |
| 164 | { |
| 165 | /* We always write synchronously */ |
| 166 | EFI_ENTRY("%p", this); |
| 167 | return EFI_EXIT(EFI_SUCCESS); |
| 168 | } |
| 169 | |
| 170 | static const struct efi_block_io block_io_disk_template = { |
| 171 | .reset = &efi_disk_reset, |
| 172 | .read_blocks = &efi_disk_read_blocks, |
| 173 | .write_blocks = &efi_disk_write_blocks, |
| 174 | .flush_blocks = &efi_disk_flush_blocks, |
| 175 | }; |
| 176 | |
Rob Clark | 2a92080 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 177 | /* |
| 178 | * Find filesystem from a device-path. The passed in path 'p' probably |
| 179 | * contains one or more /File(name) nodes, so the comparison stops at |
| 180 | * the first /File() node, and returns the pointer to that via 'rp'. |
| 181 | * This is mostly intended to be a helper to map a device-path to an |
| 182 | * efi_file_handle object. |
| 183 | */ |
| 184 | struct efi_simple_file_system_protocol * |
| 185 | efi_fs_from_path(struct efi_device_path *fp) |
| 186 | { |
| 187 | struct efi_object *efiobj; |
| 188 | struct efi_disk_obj *diskobj; |
| 189 | |
| 190 | efiobj = efi_dp_find_obj(fp, NULL); |
| 191 | if (!efiobj) |
| 192 | return NULL; |
| 193 | |
| 194 | diskobj = container_of(efiobj, struct efi_disk_obj, parent); |
| 195 | |
| 196 | return diskobj->volume; |
| 197 | } |
| 198 | |
Heinrich Schuchardt | 93945f2 | 2017-10-26 19:25:46 +0200 | [diff] [blame^] | 199 | /* |
| 200 | * Create a device for a disk |
| 201 | * |
| 202 | * @name not used |
| 203 | * @if_typename interface name for block device |
| 204 | * @desc internal block device |
| 205 | * @dev_index device index for block device |
| 206 | * @offset offset into disk for simple partitions |
| 207 | */ |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 208 | static void efi_disk_add_dev(const char *name, |
| 209 | const char *if_typename, |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 210 | struct blk_desc *desc, |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 211 | int dev_index, |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 212 | lbaint_t offset, |
| 213 | unsigned int part) |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 214 | { |
| 215 | struct efi_disk_obj *diskobj; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 216 | |
Alexander Graf | 0812d1a | 2016-08-05 14:51:47 +0200 | [diff] [blame] | 217 | /* Don't add empty devices */ |
| 218 | if (!desc->lba) |
| 219 | return; |
| 220 | |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 221 | diskobj = calloc(1, sizeof(*diskobj)); |
Heinrich Schuchardt | 93945f2 | 2017-10-26 19:25:46 +0200 | [diff] [blame^] | 222 | if (!diskobj) { |
| 223 | printf("ERROR: Out of memory\n"); |
| 224 | return; |
| 225 | } |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 226 | |
| 227 | /* Fill in object data */ |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 228 | diskobj->dp = efi_dp_from_part(desc, part); |
| 229 | diskobj->part = part; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 230 | diskobj->parent.protocols[0].guid = &efi_block_io_guid; |
xypron.glpk@gmx.de | b5349f7 | 2017-07-11 22:06:14 +0200 | [diff] [blame] | 231 | diskobj->parent.protocols[0].protocol_interface = &diskobj->ops; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 232 | diskobj->parent.protocols[1].guid = &efi_guid_device_path; |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 233 | diskobj->parent.protocols[1].protocol_interface = diskobj->dp; |
Rob Clark | 2a92080 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 234 | if (part >= 1) { |
| 235 | diskobj->volume = efi_simple_file_system(desc, part, |
| 236 | diskobj->dp); |
| 237 | diskobj->parent.protocols[2].guid = |
| 238 | &efi_simple_file_system_protocol_guid; |
| 239 | diskobj->parent.protocols[2].protocol_interface = |
| 240 | diskobj->volume; |
| 241 | } |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 242 | diskobj->parent.handle = diskobj; |
| 243 | diskobj->ops = block_io_disk_template; |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 244 | diskobj->ifname = if_typename; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 245 | diskobj->dev_index = dev_index; |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 246 | diskobj->offset = offset; |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 247 | diskobj->desc = desc; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 248 | |
| 249 | /* Fill in EFI IO Media info (for read/write callbacks) */ |
| 250 | diskobj->media.removable_media = desc->removable; |
| 251 | diskobj->media.media_present = 1; |
| 252 | diskobj->media.block_size = desc->blksz; |
| 253 | diskobj->media.io_align = desc->blksz; |
Alexander Graf | 0812d1a | 2016-08-05 14:51:47 +0200 | [diff] [blame] | 254 | diskobj->media.last_block = desc->lba - offset; |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 255 | diskobj->ops.media = &diskobj->media; |
| 256 | |
Alexander Graf | 4a12a97 | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 257 | /* Hook up to the device list */ |
| 258 | list_add_tail(&diskobj->parent.link, &efi_obj_list); |
| 259 | } |
| 260 | |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 261 | static int efi_disk_create_eltorito(struct blk_desc *desc, |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 262 | const char *if_typename, |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 263 | int diskid, |
| 264 | const char *pdevname) |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 265 | { |
| 266 | int disks = 0; |
Patrick Delaunay | 1acc008 | 2017-01-27 11:00:38 +0100 | [diff] [blame] | 267 | #if CONFIG_IS_ENABLED(ISO_PARTITION) |
Alexander Graf | ecbe1a0 | 2016-04-11 16:16:20 +0200 | [diff] [blame] | 268 | char devname[32] = { 0 }; /* dp->str is u16[32] long */ |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 269 | disk_partition_t info; |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 270 | int part; |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 271 | |
| 272 | if (desc->part_type != PART_TYPE_ISO) |
| 273 | return 0; |
| 274 | |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 275 | /* and devices for each partition: */ |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 276 | for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { |
| 277 | if (part_get_info(desc, part, &info)) |
| 278 | continue; |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 279 | snprintf(devname, sizeof(devname), "%s:%d", pdevname, |
| 280 | part); |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 281 | efi_disk_add_dev(devname, if_typename, desc, diskid, |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 282 | info.start, part); |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 283 | disks++; |
| 284 | } |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 285 | |
| 286 | /* ... and add block device: */ |
| 287 | efi_disk_add_dev(devname, if_typename, desc, diskid, 0, 0); |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 288 | #endif |
| 289 | |
| 290 | return disks; |
| 291 | } |
| 292 | |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 293 | /* |
| 294 | * U-Boot doesn't have a list of all online disk devices. So when running our |
| 295 | * EFI payload, we scan through all of the potentially available ones and |
| 296 | * store them in our object pool. |
| 297 | * |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 298 | * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this. |
| 299 | * Consider converting the code to look up devices as needed. The EFI device |
| 300 | * could be a child of the UCLASS_BLK block device, perhaps. |
| 301 | * |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 302 | * This gets called from do_bootefi_exec(). |
| 303 | */ |
| 304 | int efi_disk_register(void) |
| 305 | { |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 306 | int disks = 0; |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 307 | #ifdef CONFIG_BLK |
| 308 | struct udevice *dev; |
| 309 | |
xypron.glpk@gmx.de | 70bfcdc | 2017-06-20 19:10:27 +0000 | [diff] [blame] | 310 | for (uclass_first_device_check(UCLASS_BLK, &dev); |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 311 | dev; |
xypron.glpk@gmx.de | 70bfcdc | 2017-06-20 19:10:27 +0000 | [diff] [blame] | 312 | uclass_next_device_check(&dev)) { |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 313 | struct blk_desc *desc = dev_get_uclass_platdata(dev); |
| 314 | const char *if_typename = dev->driver->name; |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 315 | disk_partition_t info; |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 316 | int part; |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 317 | |
| 318 | printf("Scanning disk %s...\n", dev->name); |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 319 | |
| 320 | /* add devices for each partition: */ |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 321 | for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { |
| 322 | if (part_get_info(desc, part, &info)) |
| 323 | continue; |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 324 | efi_disk_add_dev(dev->name, if_typename, desc, |
| 325 | desc->devnum, 0, part); |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* ... and add block device: */ |
| 329 | efi_disk_add_dev(dev->name, if_typename, desc, |
| 330 | desc->devnum, 0, 0); |
| 331 | |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 332 | disks++; |
| 333 | |
| 334 | /* |
| 335 | * El Torito images show up as block devices in an EFI world, |
| 336 | * so let's create them here |
| 337 | */ |
| 338 | disks += efi_disk_create_eltorito(desc, if_typename, |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 339 | desc->devnum, dev->name); |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 340 | } |
| 341 | #else |
| 342 | int i, if_type; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 343 | |
| 344 | /* Search for all available disk devices */ |
Simon Glass | 6dd9faf | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 345 | for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) { |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 346 | const struct blk_driver *cur_drvr; |
| 347 | const char *if_typename; |
| 348 | |
Simon Glass | 6dd9faf | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 349 | cur_drvr = blk_driver_lookup_type(if_type); |
| 350 | if (!cur_drvr) |
| 351 | continue; |
| 352 | |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 353 | if_typename = cur_drvr->if_typename; |
| 354 | printf("Scanning disks on %s...\n", if_typename); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 355 | for (i = 0; i < 4; i++) { |
| 356 | struct blk_desc *desc; |
Alexander Graf | ecbe1a0 | 2016-04-11 16:16:20 +0200 | [diff] [blame] | 357 | char devname[32] = { 0 }; /* dp->str is u16[32] long */ |
Rob Clark | 77511b3 | 2017-10-08 11:33:08 -0400 | [diff] [blame] | 358 | disk_partition_t info; |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 359 | int part; |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 360 | |
Simon Glass | 6dd9faf | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 361 | desc = blk_get_devnum_by_type(if_type, i); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 362 | if (!desc) |
| 363 | continue; |
| 364 | if (desc->type == DEV_TYPE_UNKNOWN) |
| 365 | continue; |
| 366 | |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 367 | snprintf(devname, sizeof(devname), "%s%d", |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 368 | if_typename, i); |
Rob Clark | 77511b3 | 2017-10-08 11:33:08 -0400 | [diff] [blame] | 369 | |
| 370 | /* add devices for each partition: */ |
Jonathan Gray | 16a73b2 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 371 | for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { |
| 372 | if (part_get_info(desc, part, &info)) |
| 373 | continue; |
Rob Clark | 77511b3 | 2017-10-08 11:33:08 -0400 | [diff] [blame] | 374 | efi_disk_add_dev(devname, if_typename, desc, |
| 375 | i, 0, part); |
Rob Clark | 77511b3 | 2017-10-08 11:33:08 -0400 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* ... and add block device: */ |
Rob Clark | 884bcf6 | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 379 | efi_disk_add_dev(devname, if_typename, desc, i, 0, 0); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 380 | disks++; |
Alexander Graf | 8c3df0b | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 381 | |
| 382 | /* |
| 383 | * El Torito images show up as block devices |
| 384 | * in an EFI world, so let's create them here |
| 385 | */ |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 386 | disks += efi_disk_create_eltorito(desc, if_typename, |
| 387 | i, devname); |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 388 | } |
| 389 | } |
Simon Glass | 487d756 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 390 | #endif |
Alexander Graf | 2a22d05 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 391 | printf("Found %d disks\n", disks); |
| 392 | |
| 393 | return 0; |
| 394 | } |