Tom Rini | f739fcd | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 2 | /* |
Heinrich Schuchardt | e1fec15 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 3 | * EFI boot manager |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2017 Rob Clark |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 8 | #define LOG_CATEGORY LOGC_EFI |
| 9 | |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 10 | #include <common.h> |
| 11 | #include <charset.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 13 | #include <malloc.h> |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 14 | #include <efi_default_filename.h> |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 15 | #include <efi_loader.h> |
Heinrich Schuchardt | dda8c71 | 2020-06-24 19:09:18 +0200 | [diff] [blame] | 16 | #include <efi_variable.h> |
AKASHI Takahiro | 1a82b34 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 17 | #include <asm/unaligned.h> |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 18 | |
| 19 | static const struct efi_boot_services *bs; |
| 20 | static const struct efi_runtime_services *rs; |
| 21 | |
Masahisa Kojima | 87d7914 | 2022-09-12 17:33:50 +0900 | [diff] [blame^] | 22 | const efi_guid_t efi_guid_bootmenu_auto_generated = |
| 23 | EFICONFIG_AUTO_GENERATED_ENTRY_GUID; |
| 24 | |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 25 | /* |
| 26 | * bootmgr implements the logic of trying to find a payload to boot |
| 27 | * based on the BootOrder + BootXXXX variables, and then loading it. |
| 28 | * |
| 29 | * TODO detecting a special key held (f9?) and displaying a boot menu |
| 30 | * like you would get on a PC would be clever. |
| 31 | * |
| 32 | * TODO if we had a way to write and persist variables after the OS |
| 33 | * has started, we'd also want to check OsIndications to see if we |
| 34 | * should do normal or recovery boot. |
| 35 | */ |
| 36 | |
Heinrich Schuchardt | 1064d04 | 2020-08-07 17:47:13 +0200 | [diff] [blame] | 37 | /** |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 38 | * expand_media_path() - expand a device path for default file name |
| 39 | * @device_path: device path to check against |
| 40 | * |
| 41 | * If @device_path is a media or disk partition which houses a file |
| 42 | * system, this function returns a full device path which contains |
| 43 | * an architecture-specific default file name for removable media. |
| 44 | * |
| 45 | * Return: a newly allocated device path |
| 46 | */ |
| 47 | static |
| 48 | struct efi_device_path *expand_media_path(struct efi_device_path *device_path) |
| 49 | { |
Heinrich Schuchardt | 178667b | 2022-06-11 05:22:07 +0000 | [diff] [blame] | 50 | struct efi_device_path *dp, *rem, *full_path; |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 51 | efi_handle_t handle; |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 52 | |
| 53 | if (!device_path) |
| 54 | return NULL; |
| 55 | |
| 56 | /* |
| 57 | * If device_path is a (removable) media or partition which provides |
| 58 | * simple file system protocol, append a default file name to support |
| 59 | * booting from removable media. |
| 60 | */ |
| 61 | dp = device_path; |
Heinrich Schuchardt | 178667b | 2022-06-11 05:22:07 +0000 | [diff] [blame] | 62 | handle = efi_dp_find_obj(dp, &efi_simple_file_system_protocol_guid, |
| 63 | &rem); |
Heinrich Schuchardt | 72fa9cd | 2022-06-11 05:22:08 +0000 | [diff] [blame] | 64 | if (handle) { |
Heinrich Schuchardt | 178667b | 2022-06-11 05:22:07 +0000 | [diff] [blame] | 65 | if (rem->type == DEVICE_PATH_TYPE_END) { |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 66 | dp = efi_dp_from_file(NULL, 0, |
| 67 | "/EFI/BOOT/" BOOTEFI_NAME); |
| 68 | full_path = efi_dp_append(device_path, dp); |
| 69 | efi_free_pool(dp); |
| 70 | } else { |
| 71 | full_path = efi_dp_dup(device_path); |
| 72 | } |
| 73 | } else { |
| 74 | full_path = efi_dp_dup(device_path); |
| 75 | } |
| 76 | |
| 77 | return full_path; |
| 78 | } |
| 79 | |
| 80 | /** |
AKASHI Takahiro | 57ad624 | 2022-05-12 11:29:02 +0900 | [diff] [blame] | 81 | * try_load_from_file_path() - try to load a file |
| 82 | * |
| 83 | * Given a file media path iterate through a list of handles and try to |
| 84 | * to load the file from each of them until the first success. |
| 85 | * |
| 86 | * @fs_handles: array of handles with the simple file protocol |
| 87 | * @num: number of handles in fs_handles |
| 88 | * @fp: file path to open |
| 89 | * @handle: on return pointer to handle for loaded image |
| 90 | * @removable: if true only consider removable media, else only non-removable |
| 91 | */ |
| 92 | static efi_status_t try_load_from_file_path(efi_handle_t *fs_handles, |
| 93 | efi_uintn_t num, |
| 94 | struct efi_device_path *fp, |
| 95 | efi_handle_t *handle, |
| 96 | bool removable) |
| 97 | { |
| 98 | struct efi_handler *handler; |
| 99 | struct efi_device_path *dp; |
| 100 | int i; |
| 101 | efi_status_t ret; |
| 102 | |
| 103 | for (i = 0; i < num; i++) { |
| 104 | if (removable != efi_disk_is_removable(fs_handles[i])) |
| 105 | continue; |
| 106 | |
| 107 | ret = efi_search_protocol(fs_handles[i], &efi_guid_device_path, |
| 108 | &handler); |
| 109 | if (ret != EFI_SUCCESS) |
| 110 | continue; |
| 111 | |
| 112 | dp = handler->protocol_interface; |
| 113 | if (!dp) |
| 114 | continue; |
| 115 | |
| 116 | dp = efi_dp_append(dp, fp); |
| 117 | if (!dp) |
| 118 | continue; |
| 119 | |
| 120 | ret = EFI_CALL(efi_load_image(true, efi_root, dp, NULL, 0, |
| 121 | handle)); |
| 122 | efi_free_pool(dp); |
| 123 | if (ret == EFI_SUCCESS) |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | return EFI_NOT_FOUND; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * try_load_from_short_path |
| 132 | * @fp: file path |
| 133 | * @handle: pointer to handle for newly installed image |
| 134 | * |
| 135 | * Enumerate all the devices which support file system operations, |
| 136 | * prepend its media device path to the file path, @fp, and |
| 137 | * try to load the file. |
| 138 | * This function should be called when handling a short-form path |
| 139 | * which is starting with a file device path. |
| 140 | * |
| 141 | * Return: status code |
| 142 | */ |
| 143 | static efi_status_t try_load_from_short_path(struct efi_device_path *fp, |
| 144 | efi_handle_t *handle) |
| 145 | { |
| 146 | efi_handle_t *fs_handles; |
| 147 | efi_uintn_t num; |
| 148 | efi_status_t ret; |
| 149 | |
| 150 | ret = EFI_CALL(efi_locate_handle_buffer( |
| 151 | BY_PROTOCOL, |
| 152 | &efi_simple_file_system_protocol_guid, |
| 153 | NULL, |
| 154 | &num, &fs_handles)); |
| 155 | if (ret != EFI_SUCCESS) |
| 156 | return ret; |
| 157 | if (!num) |
| 158 | return EFI_NOT_FOUND; |
| 159 | |
| 160 | /* removable media first */ |
| 161 | ret = try_load_from_file_path(fs_handles, num, fp, handle, true); |
| 162 | if (ret == EFI_SUCCESS) |
| 163 | goto out; |
| 164 | |
| 165 | /* fixed media */ |
| 166 | ret = try_load_from_file_path(fs_handles, num, fp, handle, false); |
| 167 | if (ret == EFI_SUCCESS) |
| 168 | goto out; |
| 169 | |
| 170 | out: |
| 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | /** |
Heinrich Schuchardt | 15621aa | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 175 | * try_load_entry() - try to load image for boot option |
| 176 | * |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 177 | * Attempt to load load-option number 'n', returning device_path and file_path |
Heinrich Schuchardt | 15621aa | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 178 | * if successful. This checks that the EFI_LOAD_OPTION is active (enabled) |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 179 | * and that the specified file to boot exists. |
Heinrich Schuchardt | 15621aa | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 180 | * |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 181 | * @n: number of the boot option, e.g. 0x0a13 for Boot0A13 |
| 182 | * @handle: on return handle for the newly installed image |
| 183 | * @load_options: load options set on the loaded image protocol |
| 184 | * Return: status code |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 185 | */ |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 186 | static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, |
| 187 | void **load_options) |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 188 | { |
AKASHI Takahiro | 1a82b34 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 189 | struct efi_load_option lo; |
Heinrich Schuchardt | 4f41996 | 2022-04-25 23:35:01 +0200 | [diff] [blame] | 190 | u16 varname[9]; |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 191 | void *load_option; |
Heinrich Schuchardt | 45c66f9 | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 192 | efi_uintn_t size; |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 193 | efi_status_t ret; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 194 | |
Heinrich Schuchardt | 4f41996 | 2022-04-25 23:35:01 +0200 | [diff] [blame] | 195 | efi_create_indexed_name(varname, sizeof(varname), "Boot", n); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 196 | |
Ilias Apalodimas | f4dc1bc | 2021-03-27 10:56:07 +0200 | [diff] [blame] | 197 | load_option = efi_get_var(varname, &efi_global_variable_guid, &size); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 198 | if (!load_option) |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 199 | return EFI_LOAD_ERROR; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 200 | |
Heinrich Schuchardt | 0e69bcf | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 201 | ret = efi_deserialize_load_option(&lo, load_option, &size); |
| 202 | if (ret != EFI_SUCCESS) { |
| 203 | log_warning("Invalid load option for %ls\n", varname); |
| 204 | goto error; |
| 205 | } |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 206 | |
| 207 | if (lo.attributes & LOAD_OPTION_ACTIVE) { |
AKASHI Takahiro | 4e65ca0 | 2022-04-28 17:09:39 +0900 | [diff] [blame] | 208 | struct efi_device_path *file_path; |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 209 | u32 attributes; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 210 | |
Heinrich Schuchardt | 7ea79e5 | 2022-04-29 07:15:04 +0200 | [diff] [blame] | 211 | log_debug("trying to load \"%ls\" from %pD\n", lo.label, |
| 212 | lo.file_path); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 213 | |
AKASHI Takahiro | 57ad624 | 2022-05-12 11:29:02 +0900 | [diff] [blame] | 214 | if (EFI_DP_TYPE(lo.file_path, MEDIA_DEVICE, FILE_PATH)) { |
| 215 | /* file_path doesn't contain a device path */ |
| 216 | ret = try_load_from_short_path(lo.file_path, handle); |
| 217 | } else { |
| 218 | file_path = expand_media_path(lo.file_path); |
| 219 | ret = EFI_CALL(efi_load_image(true, efi_root, file_path, |
| 220 | NULL, 0, handle)); |
| 221 | efi_free_pool(file_path); |
| 222 | } |
AKASHI Takahiro | 94e6e55 | 2019-05-29 20:54:25 +0200 | [diff] [blame] | 223 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 224 | log_warning("Loading %ls '%ls' failed\n", |
| 225 | varname, lo.label); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 226 | goto error; |
AKASHI Takahiro | 94e6e55 | 2019-05-29 20:54:25 +0200 | [diff] [blame] | 227 | } |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 228 | |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 229 | attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 230 | EFI_VARIABLE_RUNTIME_ACCESS; |
Simon Glass | 156ccbc | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 231 | ret = efi_set_variable_int(u"BootCurrent", |
Heinrich Schuchardt | dda8c71 | 2020-06-24 19:09:18 +0200 | [diff] [blame] | 232 | &efi_global_variable_guid, |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 233 | attributes, sizeof(n), &n, false); |
Ilias Apalodimas | 53f6a5a | 2021-03-17 21:55:00 +0200 | [diff] [blame] | 234 | if (ret != EFI_SUCCESS) |
| 235 | goto unload; |
| 236 | /* try to register load file2 for initrd's */ |
| 237 | if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { |
| 238 | ret = efi_initrd_register(); |
| 239 | if (ret != EFI_SUCCESS) |
| 240 | goto unload; |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 241 | } |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 242 | |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 243 | log_info("Booting: %ls\n", lo.label); |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 244 | } else { |
| 245 | ret = EFI_LOAD_ERROR; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 248 | /* Set load options */ |
| 249 | if (size) { |
| 250 | *load_options = malloc(size); |
| 251 | if (!*load_options) { |
| 252 | ret = EFI_OUT_OF_RESOURCES; |
| 253 | goto error; |
| 254 | } |
| 255 | memcpy(*load_options, lo.optional_data, size); |
| 256 | ret = efi_set_load_options(*handle, size, *load_options); |
| 257 | } else { |
Heinrich Schuchardt | e434311 | 2020-12-27 15:46:00 +0100 | [diff] [blame] | 258 | *load_options = NULL; |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 261 | error: |
| 262 | free(load_option); |
| 263 | |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 264 | return ret; |
Ilias Apalodimas | 53f6a5a | 2021-03-17 21:55:00 +0200 | [diff] [blame] | 265 | |
| 266 | unload: |
| 267 | if (EFI_CALL(efi_unload_image(*handle)) != EFI_SUCCESS) |
| 268 | log_err("Unloading image failed\n"); |
| 269 | free(load_option); |
| 270 | |
| 271 | return ret; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Heinrich Schuchardt | 15621aa | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 274 | /** |
| 275 | * efi_bootmgr_load() - try to load from BootNext or BootOrder |
| 276 | * |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 277 | * Attempt to load from BootNext or in the order specified by BootOrder |
| 278 | * EFI variable, the available load-options, finding and returning |
| 279 | * the first one that can be loaded successfully. |
Heinrich Schuchardt | 15621aa | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 280 | * |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 281 | * @handle: on return handle for the newly installed image |
| 282 | * @load_options: load options set on the loaded image protocol |
| 283 | * Return: status code |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 284 | */ |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 285 | efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 286 | { |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 287 | u16 bootnext, *bootorder; |
Heinrich Schuchardt | 45c66f9 | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 288 | efi_uintn_t size; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 289 | int i, num; |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 290 | efi_status_t ret; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 291 | |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 292 | bs = systab.boottime; |
| 293 | rs = systab.runtime; |
| 294 | |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 295 | /* BootNext */ |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 296 | size = sizeof(bootnext); |
Simon Glass | 156ccbc | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 297 | ret = efi_get_variable_int(u"BootNext", |
Heinrich Schuchardt | dda8c71 | 2020-06-24 19:09:18 +0200 | [diff] [blame] | 298 | &efi_global_variable_guid, |
| 299 | NULL, &size, &bootnext, NULL); |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 300 | if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) { |
| 301 | /* BootNext does exist here */ |
| 302 | if (ret == EFI_BUFFER_TOO_SMALL || size != sizeof(u16)) |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 303 | log_err("BootNext must be 16-bit integer\n"); |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 304 | |
| 305 | /* delete BootNext */ |
Simon Glass | 156ccbc | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 306 | ret = efi_set_variable_int(u"BootNext", |
Heinrich Schuchardt | dda8c71 | 2020-06-24 19:09:18 +0200 | [diff] [blame] | 307 | &efi_global_variable_guid, |
| 308 | 0, 0, NULL, false); |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 309 | |
| 310 | /* load BootNext */ |
| 311 | if (ret == EFI_SUCCESS) { |
| 312 | if (size == sizeof(u16)) { |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 313 | ret = try_load_entry(bootnext, handle, |
| 314 | load_options); |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 315 | if (ret == EFI_SUCCESS) |
| 316 | return ret; |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 317 | log_warning( |
| 318 | "Loading from BootNext failed, falling back to BootOrder\n"); |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 319 | } |
| 320 | } else { |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 321 | log_err("Deleting BootNext failed\n"); |
AKASHI Takahiro | 37279ad | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | /* BootOrder */ |
Simon Glass | 156ccbc | 2022-01-23 12:55:12 -0700 | [diff] [blame] | 326 | bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); |
Heinrich Schuchardt | 33e4497 | 2019-02-24 04:44:48 +0100 | [diff] [blame] | 327 | if (!bootorder) { |
Heinrich Schuchardt | 7a373e5 | 2020-05-31 10:07:31 +0200 | [diff] [blame] | 328 | log_info("BootOrder not defined\n"); |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 329 | ret = EFI_NOT_FOUND; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 330 | goto error; |
Heinrich Schuchardt | 33e4497 | 2019-02-24 04:44:48 +0100 | [diff] [blame] | 331 | } |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 332 | |
| 333 | num = size / sizeof(uint16_t); |
| 334 | for (i = 0; i < num; i++) { |
Heinrich Schuchardt | 7ea79e5 | 2022-04-29 07:15:04 +0200 | [diff] [blame] | 335 | log_debug("trying to load Boot%04X\n", bootorder[i]); |
Heinrich Schuchardt | 0ad6400 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 336 | ret = try_load_entry(bootorder[i], handle, load_options); |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 337 | if (ret == EFI_SUCCESS) |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | |
| 341 | free(bootorder); |
| 342 | |
| 343 | error: |
AKASHI Takahiro | 6b95b38 | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 344 | return ret; |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 345 | } |