Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 2 | /* |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 3 | * EFI boot manager |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2017 Rob Clark |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <charset.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 11 | #include <malloc.h> |
| 12 | #include <efi_loader.h> |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 13 | #include <asm/unaligned.h> |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 14 | |
| 15 | static const struct efi_boot_services *bs; |
| 16 | static const struct efi_runtime_services *rs; |
| 17 | |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 18 | /* |
| 19 | * bootmgr implements the logic of trying to find a payload to boot |
| 20 | * based on the BootOrder + BootXXXX variables, and then loading it. |
| 21 | * |
| 22 | * TODO detecting a special key held (f9?) and displaying a boot menu |
| 23 | * like you would get on a PC would be clever. |
| 24 | * |
| 25 | * TODO if we had a way to write and persist variables after the OS |
| 26 | * has started, we'd also want to check OsIndications to see if we |
| 27 | * should do normal or recovery boot. |
| 28 | */ |
| 29 | |
| 30 | |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 31 | /** |
| 32 | * efi_deserialize_load_option() - parse serialized data |
| 33 | * |
| 34 | * Parse serialized data describing a load option and transform it to the |
| 35 | * efi_load_option structure. |
| 36 | * |
| 37 | * @lo: pointer to target |
| 38 | * @data: serialized data |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 39 | * @size: size of the load option, on return size of the optional data |
| 40 | * Return: status code |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 41 | */ |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 42 | efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data, |
| 43 | efi_uintn_t *size) |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 44 | { |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 45 | efi_uintn_t len; |
| 46 | |
| 47 | len = sizeof(u32); |
| 48 | if (*size < len + 2 * sizeof(u16)) |
| 49 | return EFI_INVALID_PARAMETER; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 50 | lo->attributes = get_unaligned_le32(data); |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 51 | data += len; |
| 52 | *size -= len; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 53 | |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 54 | len = sizeof(u16); |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 55 | lo->file_path_length = get_unaligned_le16(data); |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 56 | data += len; |
| 57 | *size -= len; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 58 | |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 59 | lo->label = (u16 *)data; |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 60 | len = u16_strnlen(lo->label, *size / sizeof(u16) - 1); |
| 61 | if (lo->label[len]) |
| 62 | return EFI_INVALID_PARAMETER; |
| 63 | len = (len + 1) * sizeof(u16); |
| 64 | if (*size < len) |
| 65 | return EFI_INVALID_PARAMETER; |
| 66 | data += len; |
| 67 | *size -= len; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 68 | |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 69 | len = lo->file_path_length; |
| 70 | if (*size < len) |
| 71 | return EFI_INVALID_PARAMETER; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 72 | lo->file_path = (struct efi_device_path *)data; |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 73 | /* |
| 74 | * TODO: validate device path. There should be an end node within |
| 75 | * the indicated file_path_length. |
| 76 | */ |
| 77 | data += len; |
| 78 | *size -= len; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 79 | |
| 80 | lo->optional_data = data; |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 81 | |
| 82 | return EFI_SUCCESS; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 85 | /** |
| 86 | * efi_serialize_load_option() - serialize load option |
| 87 | * |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 88 | * Serialize efi_load_option structure into byte stream for BootXXXX. |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 89 | * |
| 90 | * @data: buffer for serialized data |
| 91 | * @lo: load option |
| 92 | * Return: size of allocated buffer |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 93 | */ |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 94 | unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 95 | { |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 96 | unsigned long label_len; |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 97 | unsigned long size; |
| 98 | u8 *p; |
| 99 | |
| 100 | label_len = (u16_strlen(lo->label) + 1) * sizeof(u16); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 101 | |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 102 | /* total size */ |
| 103 | size = sizeof(lo->attributes); |
| 104 | size += sizeof(lo->file_path_length); |
| 105 | size += label_len; |
| 106 | size += lo->file_path_length; |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 107 | if (lo->optional_data) |
| 108 | size += (utf8_utf16_strlen((const char *)lo->optional_data) |
| 109 | + 1) * sizeof(u16); |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 110 | p = malloc(size); |
| 111 | if (!p) |
| 112 | return 0; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 113 | |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 114 | /* copy data */ |
| 115 | *data = p; |
| 116 | memcpy(p, &lo->attributes, sizeof(lo->attributes)); |
| 117 | p += sizeof(lo->attributes); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 118 | |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 119 | memcpy(p, &lo->file_path_length, sizeof(lo->file_path_length)); |
| 120 | p += sizeof(lo->file_path_length); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 121 | |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 122 | memcpy(p, lo->label, label_len); |
| 123 | p += label_len; |
| 124 | |
| 125 | memcpy(p, lo->file_path, lo->file_path_length); |
| 126 | p += lo->file_path_length; |
| 127 | |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 128 | if (lo->optional_data) { |
| 129 | utf8_utf16_strcpy((u16 **)&p, (const char *)lo->optional_data); |
| 130 | p += sizeof(u16); /* size of trailing \0 */ |
| 131 | } |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 132 | return size; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 135 | /** |
| 136 | * get_var() - get UEFI variable |
| 137 | * |
| 138 | * It is the caller's duty to free the returned buffer. |
| 139 | * |
| 140 | * @name: name of variable |
| 141 | * @vendor: vendor GUID of variable |
| 142 | * @size: size of allocated buffer |
| 143 | * Return: buffer with variable data or NULL |
| 144 | */ |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 145 | static void *get_var(u16 *name, const efi_guid_t *vendor, |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 146 | efi_uintn_t *size) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 147 | { |
| 148 | efi_guid_t *v = (efi_guid_t *)vendor; |
| 149 | efi_status_t ret; |
| 150 | void *buf = NULL; |
| 151 | |
| 152 | *size = 0; |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 153 | EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf)); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 154 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 155 | buf = malloc(*size); |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 156 | EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf)); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | if (ret != EFI_SUCCESS) { |
| 160 | free(buf); |
| 161 | *size = 0; |
| 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | return buf; |
| 166 | } |
| 167 | |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 168 | /** |
| 169 | * try_load_entry() - try to load image for boot option |
| 170 | * |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 171 | * Attempt to load load-option number 'n', returning device_path and file_path |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 172 | * if successful. This checks that the EFI_LOAD_OPTION is active (enabled) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 173 | * and that the specified file to boot exists. |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 174 | * |
| 175 | * @n: number of the boot option, e.g. 0x0a13 for Boot0A13 |
| 176 | * @handle: on return handle for the newly installed image |
| 177 | * Return: status code |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 178 | */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 179 | static efi_status_t try_load_entry(u16 n, efi_handle_t *handle) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 180 | { |
AKASHI Takahiro | bd23774 | 2018-11-05 18:06:41 +0900 | [diff] [blame] | 181 | struct efi_load_option lo; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 182 | u16 varname[] = L"Boot0000"; |
| 183 | u16 hexmap[] = L"0123456789ABCDEF"; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 184 | void *load_option; |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 185 | efi_uintn_t size; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 186 | efi_status_t ret; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 187 | |
| 188 | varname[4] = hexmap[(n & 0xf000) >> 12]; |
| 189 | varname[5] = hexmap[(n & 0x0f00) >> 8]; |
| 190 | varname[6] = hexmap[(n & 0x00f0) >> 4]; |
| 191 | varname[7] = hexmap[(n & 0x000f) >> 0]; |
| 192 | |
| 193 | load_option = get_var(varname, &efi_global_variable_guid, &size); |
| 194 | if (!load_option) |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 195 | return EFI_LOAD_ERROR; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 196 | |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 197 | ret = efi_deserialize_load_option(&lo, load_option, &size); |
| 198 | if (ret != EFI_SUCCESS) { |
| 199 | log_warning("Invalid load option for %ls\n", varname); |
| 200 | goto error; |
| 201 | } |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 202 | |
| 203 | if (lo.attributes & LOAD_OPTION_ACTIVE) { |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 204 | u32 attributes; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 205 | |
Heinrich Schuchardt | 253aa64 | 2018-01-26 07:20:54 +0100 | [diff] [blame] | 206 | debug("%s: trying to load \"%ls\" from %pD\n", |
| 207 | __func__, lo.label, lo.file_path); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 208 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 209 | ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, |
| 210 | NULL, 0, handle)); |
AKASHI Takahiro | 15db9ce | 2019-05-29 20:54:25 +0200 | [diff] [blame] | 211 | if (ret != EFI_SUCCESS) { |
| 212 | printf("Loading from Boot%04X '%ls' failed\n", n, |
| 213 | lo.label); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 214 | goto error; |
AKASHI Takahiro | 15db9ce | 2019-05-29 20:54:25 +0200 | [diff] [blame] | 215 | } |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 216 | |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 217 | attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 218 | EFI_VARIABLE_RUNTIME_ACCESS; |
| 219 | size = sizeof(n); |
| 220 | ret = EFI_CALL(efi_set_variable( |
| 221 | L"BootCurrent", |
| 222 | (efi_guid_t *)&efi_global_variable_guid, |
| 223 | attributes, size, &n)); |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 224 | if (ret != EFI_SUCCESS) { |
| 225 | if (EFI_CALL(efi_unload_image(*handle)) |
| 226 | != EFI_SUCCESS) |
| 227 | printf("Unloading image failed\n"); |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 228 | goto error; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 229 | } |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 230 | |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 231 | printf("Booting: %ls\n", lo.label); |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 232 | } else { |
| 233 | ret = EFI_LOAD_ERROR; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | error: |
| 237 | free(load_option); |
| 238 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 239 | return ret; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 242 | /** |
| 243 | * efi_bootmgr_load() - try to load from BootNext or BootOrder |
| 244 | * |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 245 | * Attempt to load from BootNext or in the order specified by BootOrder |
| 246 | * EFI variable, the available load-options, finding and returning |
| 247 | * the first one that can be loaded successfully. |
Heinrich Schuchardt | e612ba6 | 2019-07-14 13:20:28 +0200 | [diff] [blame] | 248 | * |
| 249 | * @handle: on return handle for the newly installed image |
| 250 | * Return: status code |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 251 | */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 252 | efi_status_t efi_bootmgr_load(efi_handle_t *handle) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 253 | { |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 254 | u16 bootnext, *bootorder; |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 255 | efi_uintn_t size; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 256 | int i, num; |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 257 | efi_status_t ret; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 258 | |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 259 | bs = systab.boottime; |
| 260 | rs = systab.runtime; |
| 261 | |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 262 | /* BootNext */ |
| 263 | bootnext = 0; |
| 264 | size = sizeof(bootnext); |
| 265 | ret = EFI_CALL(efi_get_variable(L"BootNext", |
| 266 | (efi_guid_t *)&efi_global_variable_guid, |
| 267 | NULL, &size, &bootnext)); |
| 268 | if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) { |
| 269 | /* BootNext does exist here */ |
| 270 | if (ret == EFI_BUFFER_TOO_SMALL || size != sizeof(u16)) |
| 271 | printf("BootNext must be 16-bit integer\n"); |
| 272 | |
| 273 | /* delete BootNext */ |
| 274 | ret = EFI_CALL(efi_set_variable( |
| 275 | L"BootNext", |
| 276 | (efi_guid_t *)&efi_global_variable_guid, |
AKASHI Takahiro | fd93b31 | 2019-06-04 15:52:09 +0900 | [diff] [blame] | 277 | EFI_VARIABLE_NON_VOLATILE, 0, |
| 278 | &bootnext)); |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 279 | |
| 280 | /* load BootNext */ |
| 281 | if (ret == EFI_SUCCESS) { |
| 282 | if (size == sizeof(u16)) { |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 283 | ret = try_load_entry(bootnext, handle); |
| 284 | if (ret == EFI_SUCCESS) |
| 285 | return ret; |
AKASHI Takahiro | 15db9ce | 2019-05-29 20:54:25 +0200 | [diff] [blame] | 286 | printf("Loading from BootNext failed, falling back to BootOrder\n"); |
AKASHI Takahiro | e6577f9 | 2019-03-20 09:07:55 +0900 | [diff] [blame] | 287 | } |
| 288 | } else { |
| 289 | printf("Deleting BootNext failed\n"); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /* BootOrder */ |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 294 | bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); |
Heinrich Schuchardt | 3d2257f | 2019-02-24 04:44:48 +0100 | [diff] [blame] | 295 | if (!bootorder) { |
| 296 | printf("BootOrder not defined\n"); |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 297 | ret = EFI_NOT_FOUND; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 298 | goto error; |
Heinrich Schuchardt | 3d2257f | 2019-02-24 04:44:48 +0100 | [diff] [blame] | 299 | } |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 300 | |
| 301 | num = size / sizeof(uint16_t); |
| 302 | for (i = 0; i < num; i++) { |
| 303 | debug("%s: trying to load Boot%04X\n", __func__, bootorder[i]); |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 304 | ret = try_load_entry(bootorder[i], handle); |
| 305 | if (ret == EFI_SUCCESS) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 306 | break; |
| 307 | } |
| 308 | |
| 309 | free(bootorder); |
| 310 | |
| 311 | error: |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 312 | return ret; |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 313 | } |