Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application disk support |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | e3dfa91 | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 9 | #include <blk.h> |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 11 | #include <efi_loader.h> |
AKASHI Takahiro | 120a01a | 2019-10-07 14:59:38 +0900 | [diff] [blame] | 12 | #include <fs.h> |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 13 | #include <part.h> |
| 14 | #include <malloc.h> |
| 15 | |
Heinrich Schuchardt | a993173 | 2020-03-19 15:16:31 +0100 | [diff] [blame] | 16 | struct efi_system_partition efi_system_partition; |
| 17 | |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 18 | const efi_guid_t efi_block_io_guid = EFI_BLOCK_IO_PROTOCOL_GUID; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 19 | |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 20 | /** |
| 21 | * struct efi_disk_obj - EFI disk object |
| 22 | * |
| 23 | * @header: EFI object header |
| 24 | * @ops: EFI disk I/O protocol interface |
| 25 | * @ifname: interface name for block device |
| 26 | * @dev_index: device index of block device |
| 27 | * @media: block I/O media information |
| 28 | * @dp: device path to the block device |
| 29 | * @part: partition |
| 30 | * @volume: simple file system protocol of the partition |
| 31 | * @offset: offset into disk for simple partition |
| 32 | * @desc: internal block device descriptor |
| 33 | */ |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 34 | struct efi_disk_obj { |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 35 | struct efi_object header; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 36 | struct efi_block_io ops; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 37 | const char *ifname; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 38 | int dev_index; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 39 | struct efi_block_io_media media; |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 40 | struct efi_device_path *dp; |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 41 | unsigned int part; |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 42 | struct efi_simple_file_system_protocol *volume; |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 43 | lbaint_t offset; |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 44 | struct blk_desc *desc; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Heinrich Schuchardt | 670198c | 2019-09-05 20:13:46 +0200 | [diff] [blame] | 47 | /** |
| 48 | * efi_disk_reset() - reset block device |
| 49 | * |
| 50 | * This function implements the Reset service of the EFI_BLOCK_IO_PROTOCOL. |
| 51 | * |
| 52 | * As U-Boot's block devices do not have a reset function simply return |
| 53 | * EFI_SUCCESS. |
| 54 | * |
| 55 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 56 | * details. |
| 57 | * |
| 58 | * @this: pointer to the BLOCK_IO_PROTOCOL |
| 59 | * @extended_verification: extended verification |
| 60 | * Return: status code |
| 61 | */ |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 62 | static efi_status_t EFIAPI efi_disk_reset(struct efi_block_io *this, |
| 63 | char extended_verification) |
| 64 | { |
| 65 | EFI_ENTRY("%p, %x", this, extended_verification); |
Heinrich Schuchardt | 670198c | 2019-09-05 20:13:46 +0200 | [diff] [blame] | 66 | return EFI_EXIT(EFI_SUCCESS); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | enum efi_disk_direction { |
| 70 | EFI_DISK_READ, |
| 71 | EFI_DISK_WRITE, |
| 72 | }; |
| 73 | |
Heinrich Schuchardt | 9ce0617 | 2017-08-26 22:33:13 +0200 | [diff] [blame] | 74 | static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 75 | u32 media_id, u64 lba, unsigned long buffer_size, |
| 76 | void *buffer, enum efi_disk_direction direction) |
| 77 | { |
| 78 | struct efi_disk_obj *diskobj; |
| 79 | struct blk_desc *desc; |
| 80 | int blksz; |
| 81 | int blocks; |
| 82 | unsigned long n; |
| 83 | |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 84 | diskobj = container_of(this, struct efi_disk_obj, ops); |
Alexander Graf | 34118e7 | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 85 | desc = (struct blk_desc *) diskobj->desc; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 86 | blksz = desc->blksz; |
| 87 | blocks = buffer_size / blksz; |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 88 | lba += diskobj->offset; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 89 | |
Heinrich Schuchardt | ee6ef8b | 2019-09-05 19:43:17 +0200 | [diff] [blame] | 90 | EFI_PRINT("blocks=%x lba=%llx blksz=%x dir=%d\n", |
| 91 | blocks, lba, blksz, direction); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 92 | |
| 93 | /* We only support full block access */ |
| 94 | if (buffer_size & (blksz - 1)) |
Heinrich Schuchardt | 3592252 | 2019-09-05 19:31:23 +0200 | [diff] [blame] | 95 | return EFI_BAD_BUFFER_SIZE; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 96 | |
| 97 | if (direction == EFI_DISK_READ) |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 98 | n = blk_dread(desc, lba, blocks, buffer); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 99 | else |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 100 | n = blk_dwrite(desc, lba, blocks, buffer); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 101 | |
| 102 | /* We don't do interrupts, so check for timers cooperatively */ |
| 103 | efi_timer_check(); |
| 104 | |
Heinrich Schuchardt | ee6ef8b | 2019-09-05 19:43:17 +0200 | [diff] [blame] | 105 | EFI_PRINT("n=%lx blocks=%x\n", n, blocks); |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 106 | |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 107 | if (n != blocks) |
Rob Clark | 99c4387 | 2017-07-25 20:28:29 -0400 | [diff] [blame] | 108 | return EFI_DEVICE_ERROR; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 109 | |
Rob Clark | 99c4387 | 2017-07-25 20:28:29 -0400 | [diff] [blame] | 110 | return EFI_SUCCESS; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 113 | /** |
| 114 | * efi_disk_read_blocks() - reads blocks from device |
| 115 | * |
| 116 | * This function implements the ReadBlocks service of the EFI_BLOCK_IO_PROTOCOL. |
| 117 | * |
| 118 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 119 | * details. |
| 120 | * |
| 121 | * @this: pointer to the BLOCK_IO_PROTOCOL |
| 122 | * @media_id: id of the medium to be read from |
| 123 | * @lba: starting logical block for reading |
| 124 | * @buffer_size: size of the read buffer |
| 125 | * @buffer: pointer to the destination buffer |
| 126 | * Return: status code |
| 127 | */ |
Simon Glass | c2194bf | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 128 | static efi_status_t EFIAPI efi_disk_read_blocks(struct efi_block_io *this, |
Heinrich Schuchardt | 0844f79 | 2018-01-19 20:24:48 +0100 | [diff] [blame] | 129 | u32 media_id, u64 lba, efi_uintn_t buffer_size, |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 130 | void *buffer) |
| 131 | { |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 132 | void *real_buffer = buffer; |
| 133 | efi_status_t r; |
| 134 | |
Heinrich Schuchardt | 3592252 | 2019-09-05 19:31:23 +0200 | [diff] [blame] | 135 | if (!this) |
| 136 | return EFI_INVALID_PARAMETER; |
| 137 | /* TODO: check for media changes */ |
| 138 | if (media_id != this->media->media_id) |
| 139 | return EFI_MEDIA_CHANGED; |
| 140 | if (!this->media->media_present) |
| 141 | return EFI_NO_MEDIA; |
| 142 | /* media->io_align is a power of 2 */ |
| 143 | if ((uintptr_t)buffer & (this->media->io_align - 1)) |
| 144 | return EFI_INVALID_PARAMETER; |
| 145 | if (lba * this->media->block_size + buffer_size > |
| 146 | this->media->last_block * this->media->block_size) |
| 147 | return EFI_INVALID_PARAMETER; |
| 148 | |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 149 | #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER |
| 150 | if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) { |
| 151 | r = efi_disk_read_blocks(this, media_id, lba, |
| 152 | EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer); |
| 153 | if (r != EFI_SUCCESS) |
| 154 | return r; |
| 155 | return efi_disk_read_blocks(this, media_id, lba + |
| 156 | EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size, |
| 157 | buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE, |
| 158 | buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE); |
| 159 | } |
| 160 | |
| 161 | real_buffer = efi_bounce_buffer; |
| 162 | #endif |
| 163 | |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 164 | EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba, |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 165 | buffer_size, buffer); |
| 166 | |
| 167 | r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer, |
| 168 | EFI_DISK_READ); |
| 169 | |
| 170 | /* Copy from bounce buffer to real buffer if necessary */ |
| 171 | if ((r == EFI_SUCCESS) && (real_buffer != buffer)) |
| 172 | memcpy(buffer, real_buffer, buffer_size); |
| 173 | |
| 174 | return EFI_EXIT(r); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 177 | /** |
| 178 | * efi_disk_write_blocks() - writes blocks to device |
| 179 | * |
| 180 | * This function implements the WriteBlocks service of the |
| 181 | * EFI_BLOCK_IO_PROTOCOL. |
| 182 | * |
| 183 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 184 | * details. |
| 185 | * |
| 186 | * @this: pointer to the BLOCK_IO_PROTOCOL |
| 187 | * @media_id: id of the medium to be written to |
| 188 | * @lba: starting logical block for writing |
| 189 | * @buffer_size: size of the write buffer |
| 190 | * @buffer: pointer to the source buffer |
| 191 | * Return: status code |
| 192 | */ |
Simon Glass | c2194bf | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 193 | static efi_status_t EFIAPI efi_disk_write_blocks(struct efi_block_io *this, |
Heinrich Schuchardt | 0844f79 | 2018-01-19 20:24:48 +0100 | [diff] [blame] | 194 | u32 media_id, u64 lba, efi_uintn_t buffer_size, |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 195 | void *buffer) |
| 196 | { |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 197 | void *real_buffer = buffer; |
| 198 | efi_status_t r; |
| 199 | |
Heinrich Schuchardt | 3592252 | 2019-09-05 19:31:23 +0200 | [diff] [blame] | 200 | if (!this) |
| 201 | return EFI_INVALID_PARAMETER; |
| 202 | if (this->media->read_only) |
| 203 | return EFI_WRITE_PROTECTED; |
| 204 | /* TODO: check for media changes */ |
| 205 | if (media_id != this->media->media_id) |
| 206 | return EFI_MEDIA_CHANGED; |
| 207 | if (!this->media->media_present) |
| 208 | return EFI_NO_MEDIA; |
| 209 | /* media->io_align is a power of 2 */ |
| 210 | if ((uintptr_t)buffer & (this->media->io_align - 1)) |
| 211 | return EFI_INVALID_PARAMETER; |
| 212 | if (lba * this->media->block_size + buffer_size > |
| 213 | this->media->last_block * this->media->block_size) |
| 214 | return EFI_INVALID_PARAMETER; |
| 215 | |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 216 | #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER |
| 217 | if (buffer_size > EFI_LOADER_BOUNCE_BUFFER_SIZE) { |
| 218 | r = efi_disk_write_blocks(this, media_id, lba, |
| 219 | EFI_LOADER_BOUNCE_BUFFER_SIZE, buffer); |
| 220 | if (r != EFI_SUCCESS) |
| 221 | return r; |
| 222 | return efi_disk_write_blocks(this, media_id, lba + |
| 223 | EFI_LOADER_BOUNCE_BUFFER_SIZE / this->media->block_size, |
| 224 | buffer_size - EFI_LOADER_BOUNCE_BUFFER_SIZE, |
| 225 | buffer + EFI_LOADER_BOUNCE_BUFFER_SIZE); |
| 226 | } |
| 227 | |
| 228 | real_buffer = efi_bounce_buffer; |
| 229 | #endif |
| 230 | |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 231 | EFI_ENTRY("%p, %x, %llx, %zx, %p", this, media_id, lba, |
Alexander Graf | 7c00a3c | 2016-05-11 18:25:48 +0200 | [diff] [blame] | 232 | buffer_size, buffer); |
| 233 | |
| 234 | /* Populate bounce buffer if necessary */ |
| 235 | if (real_buffer != buffer) |
| 236 | memcpy(real_buffer, buffer, buffer_size); |
| 237 | |
| 238 | r = efi_disk_rw_blocks(this, media_id, lba, buffer_size, real_buffer, |
| 239 | EFI_DISK_WRITE); |
| 240 | |
| 241 | return EFI_EXIT(r); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 244 | /** |
| 245 | * efi_disk_flush_blocks() - flushes modified data to the device |
| 246 | * |
| 247 | * This function implements the FlushBlocks service of the |
| 248 | * EFI_BLOCK_IO_PROTOCOL. |
| 249 | * |
| 250 | * As we always write synchronously nothing is done here. |
| 251 | * |
| 252 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 253 | * details. |
| 254 | * |
| 255 | * @this: pointer to the BLOCK_IO_PROTOCOL |
| 256 | * Return: status code |
| 257 | */ |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 258 | static efi_status_t EFIAPI efi_disk_flush_blocks(struct efi_block_io *this) |
| 259 | { |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 260 | EFI_ENTRY("%p", this); |
| 261 | return EFI_EXIT(EFI_SUCCESS); |
| 262 | } |
| 263 | |
| 264 | static const struct efi_block_io block_io_disk_template = { |
| 265 | .reset = &efi_disk_reset, |
| 266 | .read_blocks = &efi_disk_read_blocks, |
| 267 | .write_blocks = &efi_disk_write_blocks, |
| 268 | .flush_blocks = &efi_disk_flush_blocks, |
| 269 | }; |
| 270 | |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 271 | /** |
| 272 | * efi_fs_from_path() - retrieve simple file system protocol |
| 273 | * |
| 274 | * Gets the simple file system protocol for a file device path. |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 275 | * |
| 276 | * The full path provided is split into device part and into a file |
| 277 | * part. The device part is used to find the handle on which the |
| 278 | * simple file system protocol is installed. |
| 279 | * |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 280 | * @full_path: device path including device and file |
| 281 | * Return: simple file system protocol |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 282 | */ |
| 283 | struct efi_simple_file_system_protocol * |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 284 | efi_fs_from_path(struct efi_device_path *full_path) |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 285 | { |
| 286 | struct efi_object *efiobj; |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 287 | struct efi_handler *handler; |
| 288 | struct efi_device_path *device_path; |
| 289 | struct efi_device_path *file_path; |
| 290 | efi_status_t ret; |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 291 | |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 292 | /* Split the path into a device part and a file part */ |
| 293 | ret = efi_dp_split_file_path(full_path, &device_path, &file_path); |
| 294 | if (ret != EFI_SUCCESS) |
| 295 | return NULL; |
| 296 | efi_free_pool(file_path); |
| 297 | |
| 298 | /* Get the EFI object for the partition */ |
| 299 | efiobj = efi_dp_find_obj(device_path, NULL); |
| 300 | efi_free_pool(device_path); |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 301 | if (!efiobj) |
| 302 | return NULL; |
| 303 | |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 304 | /* Find the simple file system protocol */ |
| 305 | ret = efi_search_protocol(efiobj, &efi_simple_file_system_protocol_guid, |
| 306 | &handler); |
| 307 | if (ret != EFI_SUCCESS) |
| 308 | return NULL; |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 309 | |
Heinrich Schuchardt | 3957876 | 2018-01-19 20:24:39 +0100 | [diff] [blame] | 310 | /* Return the simple file system protocol for the partition */ |
| 311 | return handler->protocol_interface; |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 312 | } |
| 313 | |
AKASHI Takahiro | 120a01a | 2019-10-07 14:59:38 +0900 | [diff] [blame] | 314 | /** |
| 315 | * efi_fs_exists() - check if a partition bears a file system |
| 316 | * |
| 317 | * @desc: block device descriptor |
| 318 | * @part: partition number |
| 319 | * Return: 1 if a file system exists on the partition |
| 320 | * 0 otherwise |
| 321 | */ |
| 322 | static int efi_fs_exists(struct blk_desc *desc, int part) |
| 323 | { |
| 324 | if (fs_set_blk_dev_with_part(desc, part)) |
| 325 | return 0; |
| 326 | |
| 327 | if (fs_get_type() == FS_TYPE_ANY) |
| 328 | return 0; |
| 329 | |
| 330 | fs_close(); |
| 331 | |
| 332 | return 1; |
| 333 | } |
| 334 | |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 335 | /** |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 336 | * efi_disk_add_dev() - create a handle for a partition or disk |
Heinrich Schuchardt | 34f5183 | 2017-10-26 19:25:46 +0200 | [diff] [blame] | 337 | * |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 338 | * @parent: parent handle |
| 339 | * @dp_parent: parent device path |
| 340 | * @if_typename: interface name for block device |
| 341 | * @desc: internal block device |
| 342 | * @dev_index: device index for block device |
| 343 | * @offset: offset into disk for simple partitions |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 344 | * @part: partition |
| 345 | * @disk: pointer to receive the created handle |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 346 | * Return: disk object |
Heinrich Schuchardt | 34f5183 | 2017-10-26 19:25:46 +0200 | [diff] [blame] | 347 | */ |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 348 | static efi_status_t efi_disk_add_dev( |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 349 | efi_handle_t parent, |
| 350 | struct efi_device_path *dp_parent, |
| 351 | const char *if_typename, |
| 352 | struct blk_desc *desc, |
| 353 | int dev_index, |
| 354 | lbaint_t offset, |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 355 | unsigned int part, |
| 356 | struct efi_disk_obj **disk) |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 357 | { |
| 358 | struct efi_disk_obj *diskobj; |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 359 | efi_status_t ret; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 360 | |
Alexander Graf | 601db1f | 2016-08-05 14:51:47 +0200 | [diff] [blame] | 361 | /* Don't add empty devices */ |
| 362 | if (!desc->lba) |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 363 | return EFI_NOT_READY; |
Alexander Graf | 601db1f | 2016-08-05 14:51:47 +0200 | [diff] [blame] | 364 | |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 365 | diskobj = calloc(1, sizeof(*diskobj)); |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 366 | if (!diskobj) |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 367 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 368 | |
| 369 | /* Hook up to the device list */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 370 | efi_add_handle(&diskobj->header); |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 371 | |
| 372 | /* Fill in object data */ |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 373 | if (part) { |
| 374 | struct efi_device_path *node = efi_dp_part_node(desc, part); |
| 375 | |
| 376 | diskobj->dp = efi_dp_append_node(dp_parent, node); |
| 377 | efi_free_pool(node); |
| 378 | } else { |
| 379 | diskobj->dp = efi_dp_from_part(desc, part); |
| 380 | } |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 381 | diskobj->part = part; |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 382 | ret = efi_add_protocol(&diskobj->header, &efi_block_io_guid, |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 383 | &diskobj->ops); |
| 384 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 385 | return ret; |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 386 | ret = efi_add_protocol(&diskobj->header, &efi_guid_device_path, |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 387 | diskobj->dp); |
| 388 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 389 | return ret; |
AKASHI Takahiro | 356ef90 | 2019-10-07 14:59:39 +0900 | [diff] [blame] | 390 | /* partitions or whole disk without partitions */ |
| 391 | if ((part || desc->part_type == PART_TYPE_UNKNOWN) && |
| 392 | efi_fs_exists(desc, part)) { |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 393 | diskobj->volume = efi_simple_file_system(desc, part, |
| 394 | diskobj->dp); |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 395 | ret = efi_add_protocol(&diskobj->header, |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 396 | &efi_simple_file_system_protocol_guid, |
Heinrich Schuchardt | ce721a8 | 2018-01-19 20:24:38 +0100 | [diff] [blame] | 397 | diskobj->volume); |
Heinrich Schuchardt | 9fb0f2f | 2017-11-26 14:05:12 +0100 | [diff] [blame] | 398 | if (ret != EFI_SUCCESS) |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 399 | return ret; |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 400 | } |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 401 | diskobj->ops = block_io_disk_template; |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 402 | diskobj->ifname = if_typename; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 403 | diskobj->dev_index = dev_index; |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 404 | diskobj->offset = offset; |
Alexander Graf | 34118e7 | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 405 | diskobj->desc = desc; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 406 | |
| 407 | /* Fill in EFI IO Media info (for read/write callbacks) */ |
| 408 | diskobj->media.removable_media = desc->removable; |
| 409 | diskobj->media.media_present = 1; |
Heinrich Schuchardt | 3592252 | 2019-09-05 19:31:23 +0200 | [diff] [blame] | 410 | /* |
| 411 | * MediaID is just an arbitrary counter. |
| 412 | * We have to change it if the medium is removed or changed. |
| 413 | */ |
| 414 | diskobj->media.media_id = 1; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 415 | diskobj->media.block_size = desc->blksz; |
| 416 | diskobj->media.io_align = desc->blksz; |
Alexander Graf | 601db1f | 2016-08-05 14:51:47 +0200 | [diff] [blame] | 417 | diskobj->media.last_block = desc->lba - offset; |
Heinrich Schuchardt | af8c5b6 | 2020-03-19 15:45:52 +0100 | [diff] [blame] | 418 | if (part) |
Emmanuel Vadot | 5bf2964 | 2017-12-11 19:22:33 +0100 | [diff] [blame] | 419 | diskobj->media.logical_partition = 1; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 420 | diskobj->ops.media = &diskobj->media; |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 421 | if (disk) |
| 422 | *disk = diskobj; |
Heinrich Schuchardt | a993173 | 2020-03-19 15:16:31 +0100 | [diff] [blame] | 423 | |
| 424 | /* Store first EFI system partition */ |
| 425 | if (part && !efi_system_partition.if_type) { |
| 426 | int r; |
| 427 | disk_partition_t info; |
| 428 | |
| 429 | r = part_get_info(desc, part, &info); |
| 430 | if (r) |
| 431 | return EFI_DEVICE_ERROR; |
| 432 | if (info.bootable & PART_EFI_SYSTEM_PARTITION) { |
| 433 | efi_system_partition.if_type = desc->if_type; |
| 434 | efi_system_partition.devnum = desc->devnum; |
| 435 | efi_system_partition.part = part; |
| 436 | EFI_PRINT("EFI system partition: %s %d:%d\n", |
| 437 | blk_get_if_type_name(desc->if_type), |
| 438 | desc->devnum, part); |
| 439 | } |
| 440 | } |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 441 | return EFI_SUCCESS; |
Alexander Graf | 06fe57b | 2016-04-11 16:16:17 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 444 | /** |
| 445 | * efi_disk_create_partitions() - create handles and protocols for partitions |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 446 | * |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 447 | * Create handles and protocols for the partitions of a block device. |
| 448 | * |
| 449 | * @parent: handle of the parent disk |
Heinrich Schuchardt | 76f5789 | 2020-04-10 17:10:34 +0200 | [diff] [blame] | 450 | * @desc: block device |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 451 | * @if_typename: interface type |
| 452 | * @diskid: device number |
| 453 | * @pdevname: device name |
| 454 | * Return: number of partitions created |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 455 | */ |
| 456 | int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, |
| 457 | const char *if_typename, int diskid, |
| 458 | const char *pdevname) |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 459 | { |
| 460 | int disks = 0; |
Alexander Graf | 3491ee7 | 2016-04-11 16:16:20 +0200 | [diff] [blame] | 461 | char devname[32] = { 0 }; /* dp->str is u16[32] long */ |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 462 | disk_partition_t info; |
Jonathan Gray | d35cbd5 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 463 | int part; |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 464 | struct efi_device_path *dp = NULL; |
| 465 | efi_status_t ret; |
| 466 | struct efi_handler *handler; |
| 467 | |
| 468 | /* Get the device path of the parent */ |
| 469 | ret = efi_search_protocol(parent, &efi_guid_device_path, &handler); |
| 470 | if (ret == EFI_SUCCESS) |
| 471 | dp = handler->protocol_interface; |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 472 | |
Alexander Graf | 83a83f2 | 2017-12-01 16:10:33 +0100 | [diff] [blame] | 473 | /* Add devices for each partition */ |
Jonathan Gray | d35cbd5 | 2017-10-10 13:55:26 +1100 | [diff] [blame] | 474 | for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { |
| 475 | if (part_get_info(desc, part, &info)) |
| 476 | continue; |
Alexander Graf | 34118e7 | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 477 | snprintf(devname, sizeof(devname), "%s:%d", pdevname, |
| 478 | part); |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 479 | ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid, |
| 480 | info.start, part, NULL); |
| 481 | if (ret != EFI_SUCCESS) { |
| 482 | printf("Adding partition %s failed\n", pdevname); |
| 483 | continue; |
| 484 | } |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 485 | disks++; |
| 486 | } |
Rob Clark | a83272f | 2017-09-13 18:05:31 -0400 | [diff] [blame] | 487 | |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 488 | return disks; |
| 489 | } |
| 490 | |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 491 | /** |
| 492 | * efi_disk_register() - register block devices |
| 493 | * |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 494 | * U-Boot doesn't have a list of all online disk devices. So when running our |
| 495 | * EFI payload, we scan through all of the potentially available ones and |
| 496 | * store them in our object pool. |
| 497 | * |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 498 | * This function is called in efi_init_obj_list(). |
| 499 | * |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 500 | * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this. |
| 501 | * Consider converting the code to look up devices as needed. The EFI device |
| 502 | * could be a child of the UCLASS_BLK block device, perhaps. |
| 503 | * |
Heinrich Schuchardt | 6203606 | 2020-03-19 13:49:34 +0100 | [diff] [blame] | 504 | * Return: status code |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 505 | */ |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 506 | efi_status_t efi_disk_register(void) |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 507 | { |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 508 | struct efi_disk_obj *disk; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 509 | int disks = 0; |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 510 | efi_status_t ret; |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 511 | #ifdef CONFIG_BLK |
| 512 | struct udevice *dev; |
| 513 | |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 514 | for (uclass_first_device_check(UCLASS_BLK, &dev); dev; |
xypron.glpk@gmx.de | 308cd8e | 2017-06-20 19:10:27 +0000 | [diff] [blame] | 515 | uclass_next_device_check(&dev)) { |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 516 | struct blk_desc *desc = dev_get_uclass_platdata(dev); |
Heinrich Schuchardt | 6a18bb3 | 2018-01-19 20:24:44 +0100 | [diff] [blame] | 517 | const char *if_typename = blk_get_if_type_name(desc->if_type); |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 518 | |
Alexander Graf | 83a83f2 | 2017-12-01 16:10:33 +0100 | [diff] [blame] | 519 | /* Add block device for the full device */ |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 520 | printf("Scanning disk %s...\n", dev->name); |
| 521 | ret = efi_disk_add_dev(NULL, NULL, if_typename, |
| 522 | desc, desc->devnum, 0, 0, &disk); |
| 523 | if (ret == EFI_NOT_READY) { |
| 524 | printf("Disk %s not ready\n", dev->name); |
| 525 | continue; |
| 526 | } |
| 527 | if (ret) { |
| 528 | printf("ERROR: failure to add disk device %s, r = %lu\n", |
| 529 | dev->name, ret & ~EFI_ERROR_MASK); |
| 530 | return ret; |
| 531 | } |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 532 | disks++; |
| 533 | |
Alexander Graf | 83a83f2 | 2017-12-01 16:10:33 +0100 | [diff] [blame] | 534 | /* Partitions show up as block devices in EFI */ |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 535 | disks += efi_disk_create_partitions( |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 536 | &disk->header, desc, if_typename, |
Heinrich Schuchardt | 6f3de6b | 2018-01-19 20:24:47 +0100 | [diff] [blame] | 537 | desc->devnum, dev->name); |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 538 | } |
| 539 | #else |
| 540 | int i, if_type; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 541 | |
| 542 | /* Search for all available disk devices */ |
Simon Glass | e3dfa91 | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 543 | for (if_type = 0; if_type < IF_TYPE_COUNT; if_type++) { |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 544 | const struct blk_driver *cur_drvr; |
| 545 | const char *if_typename; |
| 546 | |
Simon Glass | e3dfa91 | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 547 | cur_drvr = blk_driver_lookup_type(if_type); |
| 548 | if (!cur_drvr) |
| 549 | continue; |
| 550 | |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 551 | if_typename = cur_drvr->if_typename; |
| 552 | printf("Scanning disks on %s...\n", if_typename); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 553 | for (i = 0; i < 4; i++) { |
| 554 | struct blk_desc *desc; |
Alexander Graf | 3491ee7 | 2016-04-11 16:16:20 +0200 | [diff] [blame] | 555 | char devname[32] = { 0 }; /* dp->str is u16[32] long */ |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 556 | |
Simon Glass | e3dfa91 | 2016-05-01 13:52:32 -0600 | [diff] [blame] | 557 | desc = blk_get_devnum_by_type(if_type, i); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 558 | if (!desc) |
| 559 | continue; |
| 560 | if (desc->type == DEV_TYPE_UNKNOWN) |
| 561 | continue; |
| 562 | |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 563 | snprintf(devname, sizeof(devname), "%s%d", |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 564 | if_typename, i); |
Rob Clark | 1b2ccbb | 2017-10-08 11:33:08 -0400 | [diff] [blame] | 565 | |
Alexander Graf | 83a83f2 | 2017-12-01 16:10:33 +0100 | [diff] [blame] | 566 | /* Add block device for the full device */ |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 567 | ret = efi_disk_add_dev(NULL, NULL, if_typename, desc, |
| 568 | i, 0, 0, &disk); |
| 569 | if (ret == EFI_NOT_READY) { |
| 570 | printf("Disk %s not ready\n", devname); |
| 571 | continue; |
| 572 | } |
| 573 | if (ret) { |
| 574 | printf("ERROR: failure to add disk device %s, r = %lu\n", |
| 575 | devname, ret & ~EFI_ERROR_MASK); |
| 576 | return ret; |
| 577 | } |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 578 | disks++; |
Alexander Graf | eb8d82c | 2016-04-11 16:16:18 +0200 | [diff] [blame] | 579 | |
Alexander Graf | 83a83f2 | 2017-12-01 16:10:33 +0100 | [diff] [blame] | 580 | /* Partitions show up as block devices in EFI */ |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 581 | disks += efi_disk_create_partitions |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 582 | (&disk->header, desc, |
Heinrich Schuchardt | adb50d0 | 2018-09-26 05:27:55 +0200 | [diff] [blame] | 583 | if_typename, i, devname); |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 584 | } |
| 585 | } |
Simon Glass | 302d4f8 | 2016-05-14 14:03:05 -0600 | [diff] [blame] | 586 | #endif |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 587 | printf("Found %d disks\n", disks); |
| 588 | |
Heinrich Schuchardt | cde7a36 | 2018-02-09 20:55:47 +0100 | [diff] [blame] | 589 | return EFI_SUCCESS; |
Alexander Graf | e83be45 | 2016-03-04 01:10:02 +0100 | [diff] [blame] | 590 | } |
AKASHI Takahiro | 911df64 | 2020-04-27 18:48:20 +0900 | [diff] [blame] | 591 | |
| 592 | /** |
| 593 | * efi_disk_is_system_part() - check if handle refers to an EFI system partition |
| 594 | * |
| 595 | * @handle: handle of partition |
| 596 | * |
| 597 | * Return: true if handle refers to an EFI system partition |
| 598 | */ |
| 599 | bool efi_disk_is_system_part(efi_handle_t handle) |
| 600 | { |
| 601 | struct efi_handler *handler; |
| 602 | struct efi_disk_obj *diskobj; |
| 603 | disk_partition_t info; |
| 604 | efi_status_t ret; |
| 605 | int r; |
| 606 | |
| 607 | /* check if this is a block device */ |
| 608 | ret = efi_search_protocol(handle, &efi_block_io_guid, &handler); |
| 609 | if (ret != EFI_SUCCESS) |
| 610 | return false; |
| 611 | |
| 612 | diskobj = container_of(handle, struct efi_disk_obj, header); |
| 613 | |
| 614 | r = part_get_info(diskobj->desc, diskobj->part, &info); |
| 615 | if (r) |
| 616 | return false; |
| 617 | |
| 618 | return !!(info.bootable & PART_EFI_SYSTEM_PARTITION); |
| 619 | } |