AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * UEFI Shell-like command |
| 4 | * |
| 5 | * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited |
| 6 | */ |
| 7 | |
| 8 | #include <charset.h> |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
Heinrich Schuchardt | 2c1e224 | 2020-12-13 10:30:24 +0100 | [diff] [blame] | 11 | #include <efi_dt_fixup.h> |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 12 | #include <efi_load_initrd.h> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 13 | #include <efi_loader.h> |
Heinrich Schuchardt | 50adeff | 2020-09-27 14:50:25 +0200 | [diff] [blame] | 14 | #include <efi_rng.h> |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 15 | #include <efi_variable.h> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 16 | #include <exports.h> |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 17 | #include <hexdump.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 18 | #include <log.h> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 19 | #include <malloc.h> |
Heinrich Schuchardt | fec10a4 | 2020-03-14 08:44:07 +0100 | [diff] [blame] | 20 | #include <mapmem.h> |
Heinrich Schuchardt | 2639762 | 2021-02-02 17:53:14 +0100 | [diff] [blame] | 21 | #include <part.h> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 22 | #include <search.h> |
| 23 | #include <linux/ctype.h> |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 24 | #include <linux/err.h> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 25 | |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 26 | #define BS systab.boottime |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 27 | #define RT systab.runtime |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 28 | |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 29 | #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT |
| 30 | /** |
| 31 | * do_efi_capsule_update() - process a capsule update |
| 32 | * |
| 33 | * @cmdtp: Command table |
| 34 | * @flag: Command flag |
| 35 | * @argc: Number of arguments |
| 36 | * @argv: Argument array |
| 37 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 38 | * |
| 39 | * Implement efidebug "capsule update" sub-command. |
| 40 | * process a capsule update. |
| 41 | * |
| 42 | * efidebug capsule update [-v] <capsule address> |
| 43 | */ |
| 44 | static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag, |
| 45 | int argc, char * const argv[]) |
| 46 | { |
| 47 | struct efi_capsule_header *capsule; |
| 48 | int verbose = 0; |
| 49 | char *endp; |
| 50 | efi_status_t ret; |
| 51 | |
| 52 | if (argc != 2 && argc != 3) |
| 53 | return CMD_RET_USAGE; |
| 54 | |
| 55 | if (argc == 3) { |
| 56 | if (strcmp(argv[1], "-v")) |
| 57 | return CMD_RET_USAGE; |
| 58 | |
| 59 | verbose = 1; |
| 60 | argc--; |
| 61 | argv++; |
| 62 | } |
| 63 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 64 | capsule = (typeof(capsule))hextoul(argv[1], &endp); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 65 | if (endp == argv[1]) { |
| 66 | printf("Invalid address: %s", argv[1]); |
| 67 | return CMD_RET_FAILURE; |
| 68 | } |
| 69 | |
| 70 | if (verbose) { |
| 71 | printf("Capsule guid: %pUl\n", &capsule->capsule_guid); |
| 72 | printf("Capsule flags: 0x%x\n", capsule->flags); |
| 73 | printf("Capsule header size: 0x%x\n", capsule->header_size); |
| 74 | printf("Capsule image size: 0x%x\n", |
| 75 | capsule->capsule_image_size); |
| 76 | } |
| 77 | |
Simon Glass | 83698b2 | 2021-02-07 14:27:02 -0700 | [diff] [blame] | 78 | ret = EFI_CALL(RT->update_capsule(&capsule, 1, 0)); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 79 | if (ret) { |
| 80 | printf("Cannot handle a capsule at %p", capsule); |
| 81 | return CMD_RET_FAILURE; |
| 82 | } |
| 83 | |
| 84 | return CMD_RET_SUCCESS; |
| 85 | } |
| 86 | |
Sughosh Ganu | e6f9efc | 2020-12-30 19:27:11 +0530 | [diff] [blame] | 87 | static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag, |
| 88 | int argc, char * const argv[]) |
| 89 | { |
| 90 | efi_status_t ret; |
| 91 | |
| 92 | ret = efi_launch_capsules(); |
| 93 | |
| 94 | return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE; |
| 95 | } |
| 96 | |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 97 | /** |
| 98 | * do_efi_capsule_show() - show capsule information |
| 99 | * |
| 100 | * @cmdtp: Command table |
| 101 | * @flag: Command flag |
| 102 | * @argc: Number of arguments |
| 103 | * @argv: Argument array |
| 104 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 105 | * |
| 106 | * Implement efidebug "capsule show" sub-command. |
| 107 | * show capsule information. |
| 108 | * |
| 109 | * efidebug capsule show <capsule address> |
| 110 | */ |
| 111 | static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag, |
| 112 | int argc, char * const argv[]) |
| 113 | { |
| 114 | struct efi_capsule_header *capsule; |
| 115 | char *endp; |
| 116 | |
| 117 | if (argc != 2) |
| 118 | return CMD_RET_USAGE; |
| 119 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 120 | capsule = (typeof(capsule))hextoul(argv[1], &endp); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 121 | if (endp == argv[1]) { |
| 122 | printf("Invalid address: %s", argv[1]); |
| 123 | return CMD_RET_FAILURE; |
| 124 | } |
| 125 | |
| 126 | printf("Capsule guid: %pUl\n", &capsule->capsule_guid); |
| 127 | printf("Capsule flags: 0x%x\n", capsule->flags); |
| 128 | printf("Capsule header size: 0x%x\n", capsule->header_size); |
| 129 | printf("Capsule image size: 0x%x\n", |
| 130 | capsule->capsule_image_size); |
| 131 | |
| 132 | return CMD_RET_SUCCESS; |
| 133 | } |
| 134 | |
Jose Marinho | b027e79 | 2021-03-11 13:18:51 +0000 | [diff] [blame] | 135 | #ifdef CONFIG_EFI_ESRT |
| 136 | |
| 137 | #define EFI_ESRT_FW_TYPE_NUM 4 |
| 138 | char *efi_fw_type_str[EFI_ESRT_FW_TYPE_NUM] = {"unknown", "system FW", "device FW", |
| 139 | "UEFI driver"}; |
| 140 | |
| 141 | #define EFI_ESRT_UPDATE_STATUS_NUM 9 |
| 142 | char *efi_update_status_str[EFI_ESRT_UPDATE_STATUS_NUM] = {"success", "unsuccessful", |
| 143 | "insufficient resources", "incorrect version", "invalid format", |
| 144 | "auth error", "power event (AC)", "power event (batt)", |
| 145 | "unsatisfied dependencies"}; |
| 146 | |
| 147 | #define EFI_FW_TYPE_STR_GET(idx) (\ |
| 148 | EFI_ESRT_FW_TYPE_NUM > (idx) ? efi_fw_type_str[(idx)] : "error"\ |
| 149 | ) |
| 150 | |
| 151 | #define EFI_FW_STATUS_STR_GET(idx) (\ |
| 152 | EFI_ESRT_UPDATE_STATUS_NUM > (idx) ? efi_update_status_str[(idx)] : "error"\ |
| 153 | ) |
| 154 | |
| 155 | /** |
| 156 | * do_efi_capsule_esrt() - manage UEFI capsules |
| 157 | * |
| 158 | * @cmdtp: Command table |
| 159 | * @flag: Command flag |
| 160 | * @argc: Number of arguments |
| 161 | * @argv: Argument array |
| 162 | * Return: CMD_RET_SUCCESS on success, |
| 163 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 164 | * |
| 165 | * Implement efidebug "capsule esrt" sub-command. |
| 166 | * The prints the current ESRT table. |
| 167 | * |
| 168 | * efidebug capsule esrt |
| 169 | */ |
| 170 | static int do_efi_capsule_esrt(struct cmd_tbl *cmdtp, int flag, |
| 171 | int argc, char * const argv[]) |
| 172 | { |
| 173 | struct efi_system_resource_table *esrt = NULL; |
| 174 | |
| 175 | if (argc != 1) |
| 176 | return CMD_RET_USAGE; |
| 177 | |
| 178 | for (int idx = 0; idx < systab.nr_tables; idx++) |
| 179 | if (!guidcmp(&efi_esrt_guid, &systab.tables[idx].guid)) |
| 180 | esrt = (struct efi_system_resource_table *)systab.tables[idx].table; |
| 181 | |
| 182 | if (!esrt) { |
| 183 | log_info("ESRT: table not present\n"); |
| 184 | return CMD_RET_SUCCESS; |
| 185 | } |
| 186 | |
| 187 | printf("========================================\n"); |
| 188 | printf("ESRT: fw_resource_count=%d\n", esrt->fw_resource_count); |
| 189 | printf("ESRT: fw_resource_count_max=%d\n", esrt->fw_resource_count_max); |
| 190 | printf("ESRT: fw_resource_version=%lld\n", esrt->fw_resource_version); |
| 191 | |
| 192 | for (int idx = 0; idx < esrt->fw_resource_count; idx++) { |
| 193 | printf("[entry %d]==============================\n", idx); |
| 194 | printf("ESRT: fw_class=%pUL\n", &esrt->entries[idx].fw_class); |
| 195 | printf("ESRT: fw_type=%s\n", EFI_FW_TYPE_STR_GET(esrt->entries[idx].fw_type)); |
| 196 | printf("ESRT: fw_version=%d\n", esrt->entries[idx].fw_version); |
| 197 | printf("ESRT: lowest_supported_fw_version=%d\n", |
| 198 | esrt->entries[idx].lowest_supported_fw_version); |
| 199 | printf("ESRT: capsule_flags=%d\n", |
| 200 | esrt->entries[idx].capsule_flags); |
| 201 | printf("ESRT: last_attempt_version=%d\n", |
| 202 | esrt->entries[idx].last_attempt_version); |
| 203 | printf("ESRT: last_attempt_status=%s\n", |
| 204 | EFI_FW_STATUS_STR_GET(esrt->entries[idx].last_attempt_status)); |
| 205 | } |
| 206 | printf("========================================\n"); |
| 207 | |
| 208 | return CMD_RET_SUCCESS; |
| 209 | } |
| 210 | #endif /* CONFIG_EFI_ESRT */ |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 211 | /** |
| 212 | * do_efi_capsule_res() - show a capsule update result |
| 213 | * |
| 214 | * @cmdtp: Command table |
| 215 | * @flag: Command flag |
| 216 | * @argc: Number of arguments |
| 217 | * @argv: Argument array |
| 218 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 219 | * |
| 220 | * Implement efidebug "capsule result" sub-command. |
| 221 | * show a capsule update result. |
| 222 | * If result number is not specified, CapsuleLast will be shown. |
| 223 | * |
| 224 | * efidebug capsule result [<capsule result number>] |
| 225 | */ |
| 226 | static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag, |
| 227 | int argc, char * const argv[]) |
| 228 | { |
| 229 | int capsule_id; |
| 230 | char *endp; |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 231 | u16 var_name16[12]; |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 232 | efi_guid_t guid; |
| 233 | struct efi_capsule_result_variable_header *result = NULL; |
| 234 | efi_uintn_t size; |
| 235 | efi_status_t ret; |
| 236 | |
| 237 | if (argc != 1 && argc != 2) |
| 238 | return CMD_RET_USAGE; |
| 239 | |
| 240 | guid = efi_guid_capsule_report; |
| 241 | if (argc == 1) { |
| 242 | size = sizeof(var_name16); |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 243 | ret = efi_get_variable_int(L"CapsuleLast", &guid, NULL, |
| 244 | &size, var_name16, NULL); |
| 245 | |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 246 | if (ret != EFI_SUCCESS) { |
| 247 | if (ret == EFI_NOT_FOUND) |
| 248 | printf("CapsuleLast doesn't exist\n"); |
| 249 | else |
| 250 | printf("Failed to get CapsuleLast\n"); |
| 251 | |
| 252 | return CMD_RET_FAILURE; |
| 253 | } |
| 254 | printf("CapsuleLast is %ls\n", var_name16); |
| 255 | } else { |
| 256 | argc--; |
| 257 | argv++; |
| 258 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 259 | capsule_id = hextoul(argv[0], &endp); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 260 | if (capsule_id < 0 || capsule_id > 0xffff) |
| 261 | return CMD_RET_USAGE; |
| 262 | |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 263 | efi_create_indexed_name(var_name16, sizeof(var_name16), |
| 264 | "Capsule", capsule_id); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | size = 0; |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 268 | ret = efi_get_variable_int(var_name16, &guid, NULL, &size, NULL, NULL); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 269 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 270 | result = malloc(size); |
AKASHI Takahiro | 1af1673 | 2021-01-22 10:42:48 +0900 | [diff] [blame] | 271 | if (!result) |
| 272 | return CMD_RET_FAILURE; |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 273 | ret = efi_get_variable_int(var_name16, &guid, NULL, &size, |
| 274 | result, NULL); |
AKASHI Takahiro | 1af1673 | 2021-01-22 10:42:48 +0900 | [diff] [blame] | 275 | } |
| 276 | if (ret != EFI_SUCCESS) { |
| 277 | free(result); |
| 278 | printf("Failed to get %ls\n", var_name16); |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 279 | |
AKASHI Takahiro | 1af1673 | 2021-01-22 10:42:48 +0900 | [diff] [blame] | 280 | return CMD_RET_FAILURE; |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | printf("Result total size: 0x%x\n", result->variable_total_size); |
| 284 | printf("Capsule guid: %pUl\n", &result->capsule_guid); |
| 285 | printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n", |
| 286 | result->capsule_processed.year, result->capsule_processed.month, |
| 287 | result->capsule_processed.day, result->capsule_processed.hour, |
| 288 | result->capsule_processed.minute, |
| 289 | result->capsule_processed.second); |
| 290 | printf("Capsule status: 0x%lx\n", result->capsule_status); |
| 291 | |
| 292 | free(result); |
| 293 | |
| 294 | return CMD_RET_SUCCESS; |
| 295 | } |
| 296 | |
| 297 | static struct cmd_tbl cmd_efidebug_capsule_sub[] = { |
| 298 | U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update, |
| 299 | "", ""), |
| 300 | U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show, |
| 301 | "", ""), |
Jose Marinho | b027e79 | 2021-03-11 13:18:51 +0000 | [diff] [blame] | 302 | #ifdef CONFIG_EFI_ESRT |
| 303 | U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt, |
| 304 | "", ""), |
| 305 | #endif |
Sughosh Ganu | e6f9efc | 2020-12-30 19:27:11 +0530 | [diff] [blame] | 306 | U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update, |
| 307 | "", ""), |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 308 | U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res, |
| 309 | "", ""), |
| 310 | }; |
| 311 | |
| 312 | /** |
| 313 | * do_efi_capsule() - manage UEFI capsules |
| 314 | * |
| 315 | * @cmdtp: Command table |
| 316 | * @flag: Command flag |
| 317 | * @argc: Number of arguments |
| 318 | * @argv: Argument array |
| 319 | * Return: CMD_RET_SUCCESS on success, |
| 320 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 321 | * |
| 322 | * Implement efidebug "capsule" sub-command. |
| 323 | */ |
| 324 | static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag, |
| 325 | int argc, char * const argv[]) |
| 326 | { |
| 327 | struct cmd_tbl *cp; |
| 328 | |
| 329 | if (argc < 2) |
| 330 | return CMD_RET_USAGE; |
| 331 | |
| 332 | argc--; argv++; |
| 333 | |
| 334 | cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub, |
| 335 | ARRAY_SIZE(cmd_efidebug_capsule_sub)); |
| 336 | if (!cp) |
| 337 | return CMD_RET_USAGE; |
| 338 | |
| 339 | return cp->cmd(cmdtp, flag, argc, argv); |
| 340 | } |
| 341 | #endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */ |
| 342 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 343 | /** |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 344 | * efi_get_device_path_text() - get device path text |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 345 | * |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 346 | * Return the text representation of the device path of a handle. |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 347 | * |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 348 | * @handle: handle of UEFI device |
| 349 | * Return: |
| 350 | * Pointer to the device path text or NULL. |
| 351 | * The caller is responsible for calling FreePool(). |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 352 | */ |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 353 | static u16 *efi_get_device_path_text(efi_handle_t handle) |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 354 | { |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 355 | struct efi_handler *handler; |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 356 | efi_status_t ret; |
| 357 | |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 358 | ret = efi_search_protocol(handle, &efi_guid_device_path, &handler); |
| 359 | if (ret == EFI_SUCCESS && handler->protocol_interface) { |
| 360 | struct efi_device_path *dp = handler->protocol_interface; |
| 361 | |
| 362 | return efi_dp_str(dp); |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 363 | } else { |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 364 | return NULL; |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | #define EFI_HANDLE_WIDTH ((int)sizeof(efi_handle_t) * 2) |
| 369 | |
| 370 | static const char spc[] = " "; |
| 371 | static const char sep[] = "================"; |
| 372 | |
| 373 | /** |
| 374 | * do_efi_show_devices() - show UEFI devices |
| 375 | * |
| 376 | * @cmdtp: Command table |
| 377 | * @flag: Command flag |
| 378 | * @argc: Number of arguments |
| 379 | * @argv: Argument array |
| 380 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 381 | * |
| 382 | * Implement efidebug "devices" sub-command. |
| 383 | * Show all UEFI devices and their information. |
| 384 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 385 | static int do_efi_show_devices(struct cmd_tbl *cmdtp, int flag, |
| 386 | int argc, char *const argv[]) |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 387 | { |
| 388 | efi_handle_t *handles; |
| 389 | efi_uintn_t num, i; |
| 390 | u16 *dev_path_text; |
| 391 | efi_status_t ret; |
| 392 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 393 | ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL, |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 394 | &num, &handles)); |
| 395 | if (ret != EFI_SUCCESS) |
| 396 | return CMD_RET_FAILURE; |
| 397 | |
| 398 | if (!num) |
| 399 | return CMD_RET_SUCCESS; |
| 400 | |
| 401 | printf("Device%.*s Device Path\n", EFI_HANDLE_WIDTH - 6, spc); |
| 402 | printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep); |
| 403 | for (i = 0; i < num; i++) { |
Heinrich Schuchardt | 749cafb | 2021-04-02 11:30:02 +0200 | [diff] [blame] | 404 | dev_path_text = efi_get_device_path_text(handles[i]); |
| 405 | if (dev_path_text) { |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 406 | printf("%p %ls\n", handles[i], dev_path_text); |
| 407 | efi_free_pool(dev_path_text); |
| 408 | } |
| 409 | } |
| 410 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 411 | efi_free_pool(handles); |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 412 | |
| 413 | return CMD_RET_SUCCESS; |
| 414 | } |
| 415 | |
| 416 | /** |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 417 | * efi_get_driver_handle_info() - get information of UEFI driver |
| 418 | * |
| 419 | * @handle: Handle of UEFI device |
| 420 | * @driver_name: Driver name |
| 421 | * @image_path: Pointer to text of device path |
| 422 | * Return: 0 on success, -1 on failure |
| 423 | * |
| 424 | * Currently return no useful information as all UEFI drivers are |
| 425 | * built-in.. |
| 426 | */ |
| 427 | static int efi_get_driver_handle_info(efi_handle_t handle, u16 **driver_name, |
| 428 | u16 **image_path) |
| 429 | { |
| 430 | struct efi_handler *handler; |
| 431 | struct efi_loaded_image *image; |
| 432 | efi_status_t ret; |
| 433 | |
| 434 | /* |
| 435 | * driver name |
| 436 | * TODO: support EFI_COMPONENT_NAME2_PROTOCOL |
| 437 | */ |
| 438 | *driver_name = NULL; |
| 439 | |
| 440 | /* image name */ |
| 441 | ret = efi_search_protocol(handle, &efi_guid_loaded_image, &handler); |
| 442 | if (ret != EFI_SUCCESS) { |
| 443 | *image_path = NULL; |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | image = handler->protocol_interface; |
| 448 | *image_path = efi_dp_str(image->file_path); |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * do_efi_show_drivers() - show UEFI drivers |
| 455 | * |
| 456 | * @cmdtp: Command table |
| 457 | * @flag: Command flag |
| 458 | * @argc: Number of arguments |
| 459 | * @argv: Argument array |
| 460 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 461 | * |
| 462 | * Implement efidebug "drivers" sub-command. |
| 463 | * Show all UEFI drivers and their information. |
| 464 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 465 | static int do_efi_show_drivers(struct cmd_tbl *cmdtp, int flag, |
| 466 | int argc, char *const argv[]) |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 467 | { |
| 468 | efi_handle_t *handles; |
| 469 | efi_uintn_t num, i; |
| 470 | u16 *driver_name, *image_path_text; |
| 471 | efi_status_t ret; |
| 472 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 473 | ret = EFI_CALL(efi_locate_handle_buffer( |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 474 | BY_PROTOCOL, &efi_guid_driver_binding_protocol, |
| 475 | NULL, &num, &handles)); |
| 476 | if (ret != EFI_SUCCESS) |
| 477 | return CMD_RET_FAILURE; |
| 478 | |
| 479 | if (!num) |
| 480 | return CMD_RET_SUCCESS; |
| 481 | |
| 482 | printf("Driver%.*s Name Image Path\n", |
| 483 | EFI_HANDLE_WIDTH - 6, spc); |
| 484 | printf("%.*s ==================== ====================\n", |
| 485 | EFI_HANDLE_WIDTH, sep); |
| 486 | for (i = 0; i < num; i++) { |
| 487 | if (!efi_get_driver_handle_info(handles[i], &driver_name, |
| 488 | &image_path_text)) { |
| 489 | if (image_path_text) |
| 490 | printf("%p %-20ls %ls\n", handles[i], |
| 491 | driver_name, image_path_text); |
| 492 | else |
| 493 | printf("%p %-20ls <built-in>\n", |
| 494 | handles[i], driver_name); |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 495 | efi_free_pool(driver_name); |
| 496 | efi_free_pool(image_path_text); |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 500 | efi_free_pool(handles); |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 501 | |
| 502 | return CMD_RET_SUCCESS; |
| 503 | } |
| 504 | |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 505 | static const struct { |
| 506 | const char *text; |
| 507 | const efi_guid_t guid; |
| 508 | } guid_list[] = { |
| 509 | { |
| 510 | "Device Path", |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 511 | EFI_DEVICE_PATH_PROTOCOL_GUID, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 512 | }, |
| 513 | { |
| 514 | "Device Path To Text", |
| 515 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID, |
| 516 | }, |
| 517 | { |
| 518 | "Device Path Utilities", |
| 519 | EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID, |
| 520 | }, |
| 521 | { |
| 522 | "Unicode Collation 2", |
| 523 | EFI_UNICODE_COLLATION_PROTOCOL2_GUID, |
| 524 | }, |
| 525 | { |
| 526 | "Driver Binding", |
| 527 | EFI_DRIVER_BINDING_PROTOCOL_GUID, |
| 528 | }, |
| 529 | { |
| 530 | "Simple Text Input", |
| 531 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID, |
| 532 | }, |
| 533 | { |
| 534 | "Simple Text Input Ex", |
| 535 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID, |
| 536 | }, |
| 537 | { |
| 538 | "Simple Text Output", |
| 539 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID, |
| 540 | }, |
| 541 | { |
| 542 | "Block IO", |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 543 | EFI_BLOCK_IO_PROTOCOL_GUID, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 544 | }, |
| 545 | { |
| 546 | "Simple File System", |
| 547 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, |
| 548 | }, |
| 549 | { |
| 550 | "Loaded Image", |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 551 | EFI_LOADED_IMAGE_PROTOCOL_GUID, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 552 | }, |
| 553 | { |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 554 | "Graphics Output", |
| 555 | EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 556 | }, |
Heinrich Schuchardt | ae77690 | 2019-04-20 07:57:28 +0200 | [diff] [blame] | 557 | { |
| 558 | "HII String", |
| 559 | EFI_HII_STRING_PROTOCOL_GUID, |
| 560 | }, |
| 561 | { |
| 562 | "HII Database", |
| 563 | EFI_HII_DATABASE_PROTOCOL_GUID, |
| 564 | }, |
| 565 | { |
| 566 | "HII Config Routing", |
| 567 | EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID, |
| 568 | }, |
| 569 | { |
Ilias Apalodimas | 3510ba7 | 2020-02-21 09:55:45 +0200 | [diff] [blame] | 570 | "Load File2", |
| 571 | EFI_LOAD_FILE2_PROTOCOL_GUID, |
| 572 | }, |
| 573 | { |
Heinrich Schuchardt | 50adeff | 2020-09-27 14:50:25 +0200 | [diff] [blame] | 574 | "Random Number Generator", |
| 575 | EFI_RNG_PROTOCOL_GUID, |
| 576 | }, |
| 577 | { |
Heinrich Schuchardt | ae77690 | 2019-04-20 07:57:28 +0200 | [diff] [blame] | 578 | "Simple Network", |
| 579 | EFI_SIMPLE_NETWORK_PROTOCOL_GUID, |
| 580 | }, |
| 581 | { |
| 582 | "PXE Base Code", |
| 583 | EFI_PXE_BASE_CODE_PROTOCOL_GUID, |
| 584 | }, |
Heinrich Schuchardt | 2c1e224 | 2020-12-13 10:30:24 +0100 | [diff] [blame] | 585 | { |
| 586 | "Device-Tree Fixup", |
| 587 | EFI_DT_FIXUP_PROTOCOL_GUID, |
| 588 | }, |
Heinrich Schuchardt | 2639762 | 2021-02-02 17:53:14 +0100 | [diff] [blame] | 589 | { |
| 590 | "System Partition", |
| 591 | PARTITION_SYSTEM_GUID |
| 592 | }, |
Heinrich Schuchardt | c244416 | 2021-02-26 17:57:47 +0100 | [diff] [blame] | 593 | { |
| 594 | "Firmware Management", |
| 595 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID |
| 596 | }, |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 597 | /* Configuration table GUIDs */ |
| 598 | { |
| 599 | "ACPI table", |
| 600 | EFI_ACPI_TABLE_GUID, |
| 601 | }, |
| 602 | { |
Jose Marinho | ebb61ee | 2021-03-02 17:26:38 +0000 | [diff] [blame] | 603 | "EFI System Resource Table", |
| 604 | EFI_SYSTEM_RESOURCE_TABLE_GUID, |
| 605 | }, |
| 606 | { |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 607 | "device tree", |
| 608 | EFI_FDT_GUID, |
| 609 | }, |
| 610 | { |
| 611 | "SMBIOS table", |
| 612 | SMBIOS_TABLE_GUID, |
| 613 | }, |
Heinrich Schuchardt | 956eff3 | 2020-02-19 20:48:49 +0100 | [diff] [blame] | 614 | { |
| 615 | "Runtime properties", |
| 616 | EFI_RT_PROPERTIES_TABLE_GUID, |
| 617 | }, |
Ilias Apalodimas | a51fb1c | 2020-11-30 11:47:41 +0200 | [diff] [blame] | 618 | { |
| 619 | "TCG2 Final Events Table", |
| 620 | EFI_TCG2_FINAL_EVENTS_TABLE_GUID, |
| 621 | }, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | /** |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 625 | * get_guid_text - get string of GUID |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 626 | * |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 627 | * Return description of GUID. |
| 628 | * |
| 629 | * @guid: GUID |
| 630 | * Return: description of GUID or NULL |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 631 | */ |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 632 | static const char *get_guid_text(const void *guid) |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 633 | { |
| 634 | int i; |
| 635 | |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 636 | for (i = 0; i < ARRAY_SIZE(guid_list); i++) { |
| 637 | /* |
| 638 | * As guidcmp uses memcmp() we can safely accept unaligned |
| 639 | * GUIDs. |
| 640 | */ |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 641 | if (!guidcmp(&guid_list[i].guid, guid)) |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 642 | return guid_list[i].text; |
| 643 | } |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 644 | |
Heinrich Schuchardt | c6fc502 | 2020-01-07 06:02:33 +0100 | [diff] [blame] | 645 | return NULL; |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /** |
| 649 | * do_efi_show_handles() - show UEFI handles |
| 650 | * |
| 651 | * @cmdtp: Command table |
| 652 | * @flag: Command flag |
| 653 | * @argc: Number of arguments |
| 654 | * @argv: Argument array |
| 655 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 656 | * |
| 657 | * Implement efidebug "dh" sub-command. |
| 658 | * Show all UEFI handles and their information, currently all protocols |
| 659 | * added to handle. |
| 660 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 661 | static int do_efi_show_handles(struct cmd_tbl *cmdtp, int flag, |
| 662 | int argc, char *const argv[]) |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 663 | { |
| 664 | efi_handle_t *handles; |
| 665 | efi_guid_t **guid; |
| 666 | efi_uintn_t num, count, i, j; |
| 667 | const char *guid_text; |
| 668 | efi_status_t ret; |
| 669 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 670 | ret = EFI_CALL(efi_locate_handle_buffer(ALL_HANDLES, NULL, NULL, |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 671 | &num, &handles)); |
| 672 | if (ret != EFI_SUCCESS) |
| 673 | return CMD_RET_FAILURE; |
| 674 | |
| 675 | if (!num) |
| 676 | return CMD_RET_SUCCESS; |
| 677 | |
| 678 | printf("Handle%.*s Protocols\n", EFI_HANDLE_WIDTH - 6, spc); |
| 679 | printf("%.*s ====================\n", EFI_HANDLE_WIDTH, sep); |
| 680 | for (i = 0; i < num; i++) { |
| 681 | printf("%p", handles[i]); |
| 682 | ret = EFI_CALL(BS->protocols_per_handle(handles[i], &guid, |
| 683 | &count)); |
| 684 | if (ret || !count) { |
| 685 | putc('\n'); |
| 686 | continue; |
| 687 | } |
| 688 | |
| 689 | for (j = 0; j < count; j++) { |
| 690 | if (j) |
| 691 | printf(", "); |
| 692 | else |
| 693 | putc(' '); |
| 694 | |
| 695 | guid_text = get_guid_text(guid[j]); |
| 696 | if (guid_text) |
| 697 | puts(guid_text); |
| 698 | else |
| 699 | printf("%pUl", guid[j]); |
| 700 | } |
| 701 | putc('\n'); |
| 702 | } |
| 703 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 704 | efi_free_pool(handles); |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 705 | |
| 706 | return CMD_RET_SUCCESS; |
| 707 | } |
| 708 | |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 709 | /** |
AKASHI Takahiro | 71ab1bf | 2019-02-25 15:54:42 +0900 | [diff] [blame] | 710 | * do_efi_show_images() - show UEFI images |
| 711 | * |
| 712 | * @cmdtp: Command table |
| 713 | * @flag: Command flag |
| 714 | * @argc: Number of arguments |
| 715 | * @argv: Argument array |
| 716 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 717 | * |
| 718 | * Implement efidebug "images" sub-command. |
| 719 | * Show all UEFI loaded images and their information. |
| 720 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 721 | static int do_efi_show_images(struct cmd_tbl *cmdtp, int flag, |
| 722 | int argc, char *const argv[]) |
AKASHI Takahiro | 71ab1bf | 2019-02-25 15:54:42 +0900 | [diff] [blame] | 723 | { |
| 724 | efi_print_image_infos(NULL); |
| 725 | |
| 726 | return CMD_RET_SUCCESS; |
| 727 | } |
| 728 | |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 729 | static const char * const efi_mem_type_string[] = { |
| 730 | [EFI_RESERVED_MEMORY_TYPE] = "RESERVED", |
| 731 | [EFI_LOADER_CODE] = "LOADER CODE", |
| 732 | [EFI_LOADER_DATA] = "LOADER DATA", |
| 733 | [EFI_BOOT_SERVICES_CODE] = "BOOT CODE", |
| 734 | [EFI_BOOT_SERVICES_DATA] = "BOOT DATA", |
| 735 | [EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE", |
| 736 | [EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA", |
| 737 | [EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL", |
| 738 | [EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM", |
| 739 | [EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM", |
| 740 | [EFI_ACPI_MEMORY_NVS] = "ACPI NVS", |
| 741 | [EFI_MMAP_IO] = "IO", |
| 742 | [EFI_MMAP_IO_PORT] = "IO PORT", |
| 743 | [EFI_PAL_CODE] = "PAL", |
Heinrich Schuchardt | 45176e8 | 2020-04-29 20:21:39 +0200 | [diff] [blame] | 744 | [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT", |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 745 | }; |
| 746 | |
| 747 | static const struct efi_mem_attrs { |
| 748 | const u64 bit; |
| 749 | const char *text; |
| 750 | } efi_mem_attrs[] = { |
| 751 | {EFI_MEMORY_UC, "UC"}, |
| 752 | {EFI_MEMORY_UC, "UC"}, |
| 753 | {EFI_MEMORY_WC, "WC"}, |
| 754 | {EFI_MEMORY_WT, "WT"}, |
| 755 | {EFI_MEMORY_WB, "WB"}, |
| 756 | {EFI_MEMORY_UCE, "UCE"}, |
| 757 | {EFI_MEMORY_WP, "WP"}, |
| 758 | {EFI_MEMORY_RP, "RP"}, |
| 759 | {EFI_MEMORY_XP, "WP"}, |
| 760 | {EFI_MEMORY_NV, "NV"}, |
| 761 | {EFI_MEMORY_MORE_RELIABLE, "REL"}, |
| 762 | {EFI_MEMORY_RO, "RO"}, |
Heinrich Schuchardt | e76f0e4 | 2020-05-19 07:20:46 +0200 | [diff] [blame] | 763 | {EFI_MEMORY_SP, "SP"}, |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 764 | {EFI_MEMORY_RUNTIME, "RT"}, |
| 765 | }; |
| 766 | |
| 767 | /** |
| 768 | * print_memory_attributes() - print memory map attributes |
Heinrich Schuchardt | b1d6543 | 2019-07-14 14:00:41 +0200 | [diff] [blame] | 769 | * |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 770 | * @attributes: Attribute value |
| 771 | * |
| 772 | * Print memory map attributes |
| 773 | */ |
| 774 | static void print_memory_attributes(u64 attributes) |
| 775 | { |
| 776 | int sep, i; |
| 777 | |
| 778 | for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++) |
| 779 | if (attributes & efi_mem_attrs[i].bit) { |
| 780 | if (sep) { |
| 781 | putc('|'); |
| 782 | } else { |
| 783 | putc(' '); |
| 784 | sep = 1; |
| 785 | } |
| 786 | puts(efi_mem_attrs[i].text); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2) |
| 791 | |
| 792 | /** |
| 793 | * do_efi_show_memmap() - show UEFI memory map |
| 794 | * |
| 795 | * @cmdtp: Command table |
| 796 | * @flag: Command flag |
| 797 | * @argc: Number of arguments |
| 798 | * @argv: Argument array |
| 799 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 800 | * |
| 801 | * Implement efidebug "memmap" sub-command. |
| 802 | * Show UEFI memory map. |
| 803 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 804 | static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, |
| 805 | int argc, char *const argv[]) |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 806 | { |
| 807 | struct efi_mem_desc *memmap = NULL, *map; |
| 808 | efi_uintn_t map_size = 0; |
| 809 | const char *type; |
| 810 | int i; |
| 811 | efi_status_t ret; |
| 812 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 813 | ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 814 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 815 | map_size += sizeof(struct efi_mem_desc); /* for my own */ |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 816 | ret = efi_allocate_pool(EFI_LOADER_DATA, map_size, |
| 817 | (void *)&memmap); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 818 | if (ret != EFI_SUCCESS) |
| 819 | return CMD_RET_FAILURE; |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 820 | ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 821 | } |
| 822 | if (ret != EFI_SUCCESS) { |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 823 | efi_free_pool(memmap); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 824 | return CMD_RET_FAILURE; |
| 825 | } |
| 826 | |
| 827 | printf("Type Start%.*s End%.*s Attributes\n", |
| 828 | EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); |
| 829 | printf("================ %.*s %.*s ==========\n", |
| 830 | EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep); |
AKASHI Takahiro | ac0abe2 | 2020-05-08 14:50:18 +0900 | [diff] [blame] | 831 | /* |
| 832 | * Coverity check: dereferencing null pointer "map." |
| 833 | * This is a false positive as memmap will always be |
| 834 | * populated by allocate_pool() above. |
| 835 | */ |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 836 | for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) { |
Heinrich Schuchardt | 45176e8 | 2020-04-29 20:21:39 +0200 | [diff] [blame] | 837 | if (map->type < ARRAY_SIZE(efi_mem_type_string)) |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 838 | type = efi_mem_type_string[map->type]; |
| 839 | else |
| 840 | type = "(unknown)"; |
| 841 | |
| 842 | printf("%-16s %.*llx-%.*llx", type, |
| 843 | EFI_PHYS_ADDR_WIDTH, |
Heinrich Schuchardt | 9d4c788 | 2020-03-27 04:33:17 +0000 | [diff] [blame] | 844 | (u64)map_to_sysmem((void *)(uintptr_t) |
| 845 | map->physical_start), |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 846 | EFI_PHYS_ADDR_WIDTH, |
Heinrich Schuchardt | 9d4c788 | 2020-03-27 04:33:17 +0000 | [diff] [blame] | 847 | (u64)map_to_sysmem((void *)(uintptr_t) |
| 848 | (map->physical_start + |
| 849 | map->num_pages * EFI_PAGE_SIZE))); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 850 | |
| 851 | print_memory_attributes(map->attribute); |
| 852 | putc('\n'); |
| 853 | } |
| 854 | |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 855 | efi_free_pool(memmap); |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 856 | |
| 857 | return CMD_RET_SUCCESS; |
| 858 | } |
| 859 | |
AKASHI Takahiro | 71ab1bf | 2019-02-25 15:54:42 +0900 | [diff] [blame] | 860 | /** |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 861 | * do_efi_show_tables() - show UEFI configuration tables |
| 862 | * |
| 863 | * @cmdtp: Command table |
| 864 | * @flag: Command flag |
| 865 | * @argc: Number of arguments |
| 866 | * @argv: Argument array |
| 867 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 868 | * |
| 869 | * Implement efidebug "tables" sub-command. |
| 870 | * Show UEFI configuration tables. |
| 871 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 872 | static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, |
| 873 | int argc, char *const argv[]) |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 874 | { |
| 875 | efi_uintn_t i; |
| 876 | const char *guid_str; |
| 877 | |
| 878 | for (i = 0; i < systab.nr_tables; ++i) { |
| 879 | guid_str = get_guid_text(&systab.tables[i].guid); |
| 880 | if (!guid_str) |
| 881 | guid_str = ""; |
| 882 | printf("%pUl %s\n", &systab.tables[i].guid, guid_str); |
| 883 | } |
| 884 | |
| 885 | return CMD_RET_SUCCESS; |
| 886 | } |
| 887 | |
| 888 | /** |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 889 | * create_initrd_dp() - Create a special device for our Boot### option |
| 890 | * |
| 891 | * @dev: Device |
| 892 | * @part: Disk partition |
| 893 | * @file: Filename |
| 894 | * Return: Pointer to the device path or ERR_PTR |
| 895 | * |
| 896 | */ |
| 897 | static |
| 898 | struct efi_device_path *create_initrd_dp(const char *dev, const char *part, |
| 899 | const char *file) |
| 900 | |
| 901 | { |
| 902 | struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL; |
| 903 | struct efi_device_path *initrd_dp = NULL; |
| 904 | efi_status_t ret; |
| 905 | const struct efi_initrd_dp id_dp = { |
| 906 | .vendor = { |
| 907 | { |
| 908 | DEVICE_PATH_TYPE_MEDIA_DEVICE, |
| 909 | DEVICE_PATH_SUB_TYPE_VENDOR_PATH, |
| 910 | sizeof(id_dp.vendor), |
| 911 | }, |
| 912 | EFI_INITRD_MEDIA_GUID, |
| 913 | }, |
| 914 | .end = { |
| 915 | DEVICE_PATH_TYPE_END, |
| 916 | DEVICE_PATH_SUB_TYPE_END, |
| 917 | sizeof(id_dp.end), |
| 918 | } |
| 919 | }; |
| 920 | |
| 921 | ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp); |
| 922 | if (ret != EFI_SUCCESS) { |
| 923 | printf("Cannot create device path for \"%s %s\"\n", part, file); |
| 924 | goto out; |
| 925 | } |
| 926 | |
| 927 | initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp, |
| 928 | tmp_fp); |
| 929 | |
| 930 | out: |
| 931 | efi_free_pool(tmp_dp); |
| 932 | efi_free_pool(tmp_fp); |
| 933 | return initrd_dp; |
| 934 | } |
| 935 | |
| 936 | /** |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 937 | * do_efi_boot_add() - set UEFI load option |
| 938 | * |
| 939 | * @cmdtp: Command table |
| 940 | * @flag: Command flag |
| 941 | * @argc: Number of arguments |
| 942 | * @argv: Argument array |
| 943 | * Return: CMD_RET_SUCCESS on success, |
| 944 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 945 | * |
Heinrich Schuchardt | b1d6543 | 2019-07-14 14:00:41 +0200 | [diff] [blame] | 946 | * Implement efidebug "boot add" sub-command. Create or change UEFI load option. |
| 947 | * |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 948 | * efidebug boot add -b <id> <label> <interface> <devnum>[:<part>] <file> |
| 949 | * -i <file> <interface2> <devnum2>[:<part>] <initrd> |
| 950 | * -s '<options>' |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 951 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 952 | static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, |
| 953 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 954 | { |
| 955 | int id; |
| 956 | char *endp; |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 957 | u16 var_name16[9]; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 958 | efi_guid_t guid; |
| 959 | size_t label_len, label_len16; |
| 960 | u16 *label; |
| 961 | struct efi_device_path *device_path = NULL, *file_path = NULL; |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 962 | struct efi_device_path *final_fp = NULL; |
| 963 | struct efi_device_path *initrd_dp = NULL; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 964 | struct efi_load_option lo; |
| 965 | void *data = NULL; |
| 966 | efi_uintn_t size; |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 967 | efi_uintn_t fp_size = 0; |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 968 | efi_status_t ret; |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 969 | int r = CMD_RET_SUCCESS; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 970 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 971 | guid = efi_global_variable_guid; |
| 972 | |
| 973 | /* attributes */ |
| 974 | lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */ |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 975 | lo.optional_data = NULL; |
| 976 | lo.label = NULL; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 977 | |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 978 | argc--; |
| 979 | argv++; /* 'add' */ |
| 980 | for (; argc > 0; argc--, argv++) { |
| 981 | if (!strcmp(argv[0], "-b")) { |
| 982 | if (argc < 5 || lo.label) { |
| 983 | r = CMD_RET_USAGE; |
| 984 | goto out; |
| 985 | } |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 986 | id = (int)hextoul(argv[1], &endp); |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 987 | if (*endp != '\0' || id > 0xffff) |
| 988 | return CMD_RET_USAGE; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 989 | |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 990 | efi_create_indexed_name(var_name16, sizeof(var_name16), |
| 991 | "Boot", id); |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 992 | |
| 993 | /* label */ |
| 994 | label_len = strlen(argv[2]); |
| 995 | label_len16 = utf8_utf16_strnlen(argv[2], label_len); |
| 996 | label = malloc((label_len16 + 1) * sizeof(u16)); |
| 997 | if (!label) |
| 998 | return CMD_RET_FAILURE; |
| 999 | lo.label = label; /* label will be changed below */ |
| 1000 | utf8_utf16_strncpy(&label, argv[2], label_len); |
| 1001 | |
| 1002 | /* file path */ |
| 1003 | ret = efi_dp_from_name(argv[3], argv[4], argv[5], |
| 1004 | &device_path, &file_path); |
| 1005 | if (ret != EFI_SUCCESS) { |
| 1006 | printf("Cannot create device path for \"%s %s\"\n", |
| 1007 | argv[3], argv[4]); |
| 1008 | r = CMD_RET_FAILURE; |
| 1009 | goto out; |
| 1010 | } |
| 1011 | fp_size += efi_dp_size(file_path) + |
| 1012 | sizeof(struct efi_device_path); |
| 1013 | argc -= 5; |
| 1014 | argv += 5; |
| 1015 | } else if (!strcmp(argv[0], "-i")) { |
| 1016 | if (argc < 3 || initrd_dp) { |
| 1017 | r = CMD_RET_USAGE; |
| 1018 | goto out; |
| 1019 | } |
| 1020 | |
| 1021 | initrd_dp = create_initrd_dp(argv[1], argv[2], argv[3]); |
| 1022 | if (!initrd_dp) { |
| 1023 | printf("Cannot add an initrd\n"); |
| 1024 | r = CMD_RET_FAILURE; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | argc -= 3; |
| 1028 | argv += 3; |
| 1029 | fp_size += efi_dp_size(initrd_dp) + |
| 1030 | sizeof(struct efi_device_path); |
| 1031 | } else if (!strcmp(argv[0], "-s")) { |
| 1032 | if (argc < 1 || lo.optional_data) { |
| 1033 | r = CMD_RET_USAGE; |
| 1034 | goto out; |
| 1035 | } |
| 1036 | lo.optional_data = (const u8 *)argv[1]; |
| 1037 | argc -= 1; |
| 1038 | argv += 1; |
| 1039 | } else { |
| 1040 | r = CMD_RET_USAGE; |
| 1041 | goto out; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | if (!file_path) { |
| 1046 | printf("Missing binary\n"); |
| 1047 | r = CMD_RET_USAGE; |
| 1048 | goto out; |
| 1049 | } |
| 1050 | |
| 1051 | final_fp = efi_dp_concat(file_path, initrd_dp); |
| 1052 | if (!final_fp) { |
| 1053 | printf("Cannot create final device path\n"); |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1054 | r = CMD_RET_FAILURE; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1055 | goto out; |
| 1056 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1057 | |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1058 | lo.file_path = final_fp; |
| 1059 | lo.file_path_length = fp_size; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1060 | |
| 1061 | size = efi_serialize_load_option(&lo, (u8 **)&data); |
| 1062 | if (!size) { |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1063 | r = CMD_RET_FAILURE; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1064 | goto out; |
| 1065 | } |
| 1066 | |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1067 | ret = efi_set_variable_int(var_name16, &guid, |
| 1068 | EFI_VARIABLE_NON_VOLATILE | |
| 1069 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 1070 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 1071 | size, data, false); |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 1072 | if (ret != EFI_SUCCESS) { |
| 1073 | printf("Cannot set %ls\n", var_name16); |
| 1074 | r = CMD_RET_FAILURE; |
| 1075 | } |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1076 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1077 | out: |
| 1078 | free(data); |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1079 | efi_free_pool(final_fp); |
| 1080 | efi_free_pool(initrd_dp); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1081 | efi_free_pool(device_path); |
| 1082 | efi_free_pool(file_path); |
| 1083 | free(lo.label); |
| 1084 | |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1085 | return r; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | /** |
| 1089 | * do_efi_boot_rm() - delete UEFI load options |
| 1090 | * |
| 1091 | * @cmdtp: Command table |
| 1092 | * @flag: Command flag |
| 1093 | * @argc: Number of arguments |
| 1094 | * @argv: Argument array |
| 1095 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 1096 | * |
| 1097 | * Implement efidebug "boot rm" sub-command. |
| 1098 | * Delete UEFI load options. |
Heinrich Schuchardt | b1d6543 | 2019-07-14 14:00:41 +0200 | [diff] [blame] | 1099 | * |
| 1100 | * efidebug boot rm <id> ... |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1101 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1102 | static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag, |
| 1103 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1104 | { |
| 1105 | efi_guid_t guid; |
| 1106 | int id, i; |
| 1107 | char *endp; |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1108 | u16 var_name16[9]; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1109 | efi_status_t ret; |
| 1110 | |
| 1111 | if (argc == 1) |
| 1112 | return CMD_RET_USAGE; |
| 1113 | |
| 1114 | guid = efi_global_variable_guid; |
| 1115 | for (i = 1; i < argc; i++, argv++) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 1116 | id = (int)hextoul(argv[1], &endp); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1117 | if (*endp != '\0' || id > 0xffff) |
| 1118 | return CMD_RET_FAILURE; |
| 1119 | |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1120 | efi_create_indexed_name(var_name16, sizeof(var_name16), |
| 1121 | "Boot", id); |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1122 | ret = efi_set_variable_int(var_name16, &guid, 0, 0, NULL, |
| 1123 | false); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1124 | if (ret) { |
Heinrich Schuchardt | 3be0bda | 2020-03-02 20:13:10 +0100 | [diff] [blame] | 1125 | printf("Cannot remove %ls\n", var_name16); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1126 | return CMD_RET_FAILURE; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | return CMD_RET_SUCCESS; |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * show_efi_boot_opt_data() - dump UEFI load option |
| 1135 | * |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1136 | * @varname16: variable name |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 1137 | * @data: value of UEFI load option variable |
| 1138 | * @size: size of the boot option |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1139 | * |
| 1140 | * Decode the value of UEFI load option variable and print information. |
| 1141 | */ |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1142 | static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1143 | { |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1144 | struct efi_device_path *initrd_path = NULL; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1145 | struct efi_load_option lo; |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1146 | efi_status_t ret; |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1147 | const efi_guid_t lf2_initrd_guid = EFI_INITRD_MEDIA_GUID; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1148 | |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1149 | ret = efi_deserialize_load_option(&lo, data, size); |
| 1150 | if (ret != EFI_SUCCESS) { |
| 1151 | printf("%ls: invalid load option\n", varname16); |
| 1152 | return; |
| 1153 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1154 | |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1155 | printf("%ls:\nattributes: %c%c%c (0x%08x)\n", |
| 1156 | varname16, |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1157 | /* ACTIVE */ |
| 1158 | lo.attributes & LOAD_OPTION_ACTIVE ? 'A' : '-', |
| 1159 | /* FORCE RECONNECT */ |
| 1160 | lo.attributes & LOAD_OPTION_FORCE_RECONNECT ? 'R' : '-', |
| 1161 | /* HIDDEN */ |
| 1162 | lo.attributes & LOAD_OPTION_HIDDEN ? 'H' : '-', |
| 1163 | lo.attributes); |
Heinrich Schuchardt | e6720b9 | 2021-05-24 10:35:25 +0200 | [diff] [blame] | 1164 | printf(" label: %ls\n", lo.label); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1165 | |
Heinrich Schuchardt | ca44a5d | 2021-10-15 01:47:40 +0200 | [diff] [blame] | 1166 | printf(" file_path: %pD\n", lo.file_path); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1167 | |
Heinrich Schuchardt | 9530652 | 2021-10-15 02:03:55 +0200 | [diff] [blame^] | 1168 | initrd_path = efi_dp_from_lo(&lo, &lf2_initrd_guid); |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1169 | if (initrd_path) { |
Heinrich Schuchardt | ca44a5d | 2021-10-15 01:47:40 +0200 | [diff] [blame] | 1170 | printf(" initrd_path: %pD\n", initrd_path); |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1171 | efi_free_pool(initrd_path); |
| 1172 | } |
| 1173 | |
Heinrich Schuchardt | 9df002e | 2019-04-29 13:51:45 +0200 | [diff] [blame] | 1174 | printf(" data:\n"); |
| 1175 | print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1176 | lo.optional_data, *size, true); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * show_efi_boot_opt() - dump UEFI load option |
| 1181 | * |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1182 | * @varname16: variable name |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1183 | * |
| 1184 | * Dump information defined by UEFI load option. |
| 1185 | */ |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1186 | static void show_efi_boot_opt(u16 *varname16) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1187 | { |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1188 | void *data; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1189 | efi_uintn_t size; |
AKASHI Takahiro | dab93f4 | 2019-11-26 10:11:22 +0900 | [diff] [blame] | 1190 | efi_status_t ret; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1191 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1192 | size = 0; |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1193 | ret = EFI_CALL(efi_get_variable(varname16, &efi_global_variable_guid, |
| 1194 | NULL, &size, NULL)); |
AKASHI Takahiro | dab93f4 | 2019-11-26 10:11:22 +0900 | [diff] [blame] | 1195 | if (ret == EFI_BUFFER_TOO_SMALL) { |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1196 | data = malloc(size); |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1197 | if (!data) { |
| 1198 | printf("ERROR: Out of memory\n"); |
| 1199 | return; |
| 1200 | } |
| 1201 | ret = EFI_CALL(efi_get_variable(varname16, |
| 1202 | &efi_global_variable_guid, |
| 1203 | NULL, &size, data)); |
| 1204 | if (ret == EFI_SUCCESS) |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1205 | show_efi_boot_opt_data(varname16, data, &size); |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1206 | free(data); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1207 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1208 | } |
| 1209 | |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1210 | static int u16_tohex(u16 c) |
| 1211 | { |
| 1212 | if (c >= '0' && c <= '9') |
| 1213 | return c - '0'; |
| 1214 | if (c >= 'A' && c <= 'F') |
| 1215 | return c - 'A' + 10; |
| 1216 | |
| 1217 | /* not hexadecimal */ |
| 1218 | return -1; |
| 1219 | } |
| 1220 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1221 | /** |
| 1222 | * show_efi_boot_dump() - dump all UEFI load options |
| 1223 | * |
| 1224 | * @cmdtp: Command table |
| 1225 | * @flag: Command flag |
| 1226 | * @argc: Number of arguments |
| 1227 | * @argv: Argument array |
| 1228 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 1229 | * |
| 1230 | * Implement efidebug "boot dump" sub-command. |
| 1231 | * Dump information of all UEFI load options defined. |
Heinrich Schuchardt | 2171509 | 2019-07-25 20:52:23 +0200 | [diff] [blame] | 1232 | * |
| 1233 | * efidebug boot dump |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1234 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1235 | static int do_efi_boot_dump(struct cmd_tbl *cmdtp, int flag, |
| 1236 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1237 | { |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1238 | u16 *var_name16, *p; |
| 1239 | efi_uintn_t buf_size, size; |
| 1240 | efi_guid_t guid; |
| 1241 | int id, i, digit; |
| 1242 | efi_status_t ret; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1243 | |
| 1244 | if (argc > 1) |
| 1245 | return CMD_RET_USAGE; |
| 1246 | |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1247 | buf_size = 128; |
| 1248 | var_name16 = malloc(buf_size); |
| 1249 | if (!var_name16) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1250 | return CMD_RET_FAILURE; |
| 1251 | |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1252 | var_name16[0] = 0; |
| 1253 | for (;;) { |
| 1254 | size = buf_size; |
| 1255 | ret = EFI_CALL(efi_get_next_variable_name(&size, var_name16, |
| 1256 | &guid)); |
| 1257 | if (ret == EFI_NOT_FOUND) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1258 | break; |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1259 | if (ret == EFI_BUFFER_TOO_SMALL) { |
| 1260 | buf_size = size; |
| 1261 | p = realloc(var_name16, buf_size); |
| 1262 | if (!p) { |
| 1263 | free(var_name16); |
| 1264 | return CMD_RET_FAILURE; |
| 1265 | } |
| 1266 | var_name16 = p; |
| 1267 | ret = EFI_CALL(efi_get_next_variable_name(&size, |
| 1268 | var_name16, |
| 1269 | &guid)); |
| 1270 | } |
| 1271 | if (ret != EFI_SUCCESS) { |
| 1272 | free(var_name16); |
| 1273 | return CMD_RET_FAILURE; |
| 1274 | } |
| 1275 | |
| 1276 | if (memcmp(var_name16, L"Boot", 8)) |
| 1277 | continue; |
| 1278 | |
| 1279 | for (id = 0, i = 0; i < 4; i++) { |
| 1280 | digit = u16_tohex(var_name16[4 + i]); |
| 1281 | if (digit < 0) |
| 1282 | break; |
| 1283 | id = (id << 4) + digit; |
| 1284 | } |
| 1285 | if (i == 4 && !var_name16[8]) |
Heinrich Schuchardt | 8d8be69 | 2020-04-29 19:20:35 +0200 | [diff] [blame] | 1286 | show_efi_boot_opt(var_name16); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1287 | } |
AKASHI Takahiro | 016bfcd | 2019-04-26 09:44:18 +0900 | [diff] [blame] | 1288 | |
| 1289 | free(var_name16); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1290 | |
| 1291 | return CMD_RET_SUCCESS; |
| 1292 | } |
| 1293 | |
| 1294 | /** |
| 1295 | * show_efi_boot_order() - show order of UEFI load options |
| 1296 | * |
| 1297 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 1298 | * |
| 1299 | * Show order of UEFI load options defined by BootOrder variable. |
| 1300 | */ |
| 1301 | static int show_efi_boot_order(void) |
| 1302 | { |
Heinrich Schuchardt | 98fc615 | 2020-04-29 21:15:08 +0200 | [diff] [blame] | 1303 | u16 *bootorder; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1304 | efi_uintn_t size; |
| 1305 | int num, i; |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1306 | u16 var_name16[9]; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1307 | void *data; |
| 1308 | struct efi_load_option lo; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1309 | efi_status_t ret; |
| 1310 | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1311 | size = 0; |
Heinrich Schuchardt | 982c7d9 | 2020-05-02 16:08:37 +0200 | [diff] [blame] | 1312 | ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid, |
Heinrich Schuchardt | 98fc615 | 2020-04-29 21:15:08 +0200 | [diff] [blame] | 1313 | NULL, &size, NULL)); |
| 1314 | if (ret != EFI_BUFFER_TOO_SMALL) { |
| 1315 | if (ret == EFI_NOT_FOUND) { |
| 1316 | printf("BootOrder not defined\n"); |
| 1317 | return CMD_RET_SUCCESS; |
| 1318 | } else { |
| 1319 | return CMD_RET_FAILURE; |
| 1320 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1321 | } |
Heinrich Schuchardt | 98fc615 | 2020-04-29 21:15:08 +0200 | [diff] [blame] | 1322 | bootorder = malloc(size); |
| 1323 | if (!bootorder) { |
| 1324 | printf("ERROR: Out of memory\n"); |
| 1325 | return CMD_RET_FAILURE; |
| 1326 | } |
| 1327 | ret = EFI_CALL(efi_get_variable(L"BootOrder", &efi_global_variable_guid, |
| 1328 | NULL, &size, bootorder)); |
| 1329 | if (ret != EFI_SUCCESS) { |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1330 | ret = CMD_RET_FAILURE; |
| 1331 | goto out; |
| 1332 | } |
| 1333 | |
| 1334 | num = size / sizeof(u16); |
| 1335 | for (i = 0; i < num; i++) { |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1336 | efi_create_indexed_name(var_name16, sizeof(var_name16), |
Heinrich Schuchardt | 205bc3f | 2021-06-12 00:01:44 +0200 | [diff] [blame] | 1337 | "Boot", bootorder[i]); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1338 | |
| 1339 | size = 0; |
Heinrich Schuchardt | 98fc615 | 2020-04-29 21:15:08 +0200 | [diff] [blame] | 1340 | ret = EFI_CALL(efi_get_variable(var_name16, |
| 1341 | &efi_global_variable_guid, NULL, |
| 1342 | &size, NULL)); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1343 | if (ret != EFI_BUFFER_TOO_SMALL) { |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1344 | printf("%2d: %ls: (not defined)\n", i + 1, var_name16); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1345 | continue; |
| 1346 | } |
| 1347 | |
| 1348 | data = malloc(size); |
| 1349 | if (!data) { |
| 1350 | ret = CMD_RET_FAILURE; |
| 1351 | goto out; |
| 1352 | } |
Heinrich Schuchardt | 98fc615 | 2020-04-29 21:15:08 +0200 | [diff] [blame] | 1353 | ret = EFI_CALL(efi_get_variable(var_name16, |
| 1354 | &efi_global_variable_guid, NULL, |
| 1355 | &size, data)); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1356 | if (ret != EFI_SUCCESS) { |
| 1357 | free(data); |
| 1358 | ret = CMD_RET_FAILURE; |
| 1359 | goto out; |
| 1360 | } |
| 1361 | |
Heinrich Schuchardt | 7ca84f8 | 2020-05-31 22:46:09 +0200 | [diff] [blame] | 1362 | ret = efi_deserialize_load_option(&lo, data, &size); |
| 1363 | if (ret != EFI_SUCCESS) { |
| 1364 | printf("%ls: invalid load option\n", var_name16); |
| 1365 | ret = CMD_RET_FAILURE; |
| 1366 | goto out; |
| 1367 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1368 | |
Heinrich Schuchardt | 9a5e74e | 2021-05-24 10:57:03 +0200 | [diff] [blame] | 1369 | printf("%2d: %ls: %ls\n", i + 1, var_name16, lo.label); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1370 | |
| 1371 | free(data); |
| 1372 | } |
| 1373 | out: |
| 1374 | free(bootorder); |
| 1375 | |
| 1376 | return ret; |
| 1377 | } |
| 1378 | |
| 1379 | /** |
| 1380 | * do_efi_boot_next() - manage UEFI BootNext variable |
| 1381 | * |
| 1382 | * @cmdtp: Command table |
| 1383 | * @flag: Command flag |
| 1384 | * @argc: Number of arguments |
| 1385 | * @argv: Argument array |
| 1386 | * Return: CMD_RET_SUCCESS on success, |
| 1387 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 1388 | * |
| 1389 | * Implement efidebug "boot next" sub-command. |
| 1390 | * Set BootNext variable. |
Heinrich Schuchardt | b1d6543 | 2019-07-14 14:00:41 +0200 | [diff] [blame] | 1391 | * |
| 1392 | * efidebug boot next <id> |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1393 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1394 | static int do_efi_boot_next(struct cmd_tbl *cmdtp, int flag, |
| 1395 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1396 | { |
| 1397 | u16 bootnext; |
| 1398 | efi_uintn_t size; |
| 1399 | char *endp; |
| 1400 | efi_guid_t guid; |
| 1401 | efi_status_t ret; |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 1402 | int r = CMD_RET_SUCCESS; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1403 | |
| 1404 | if (argc != 2) |
| 1405 | return CMD_RET_USAGE; |
| 1406 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 1407 | bootnext = (u16)hextoul(argv[1], &endp); |
Heinrich Schuchardt | 90c9d04 | 2020-05-09 17:59:19 +0200 | [diff] [blame] | 1408 | if (*endp) { |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1409 | printf("invalid value: %s\n", argv[1]); |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1410 | r = CMD_RET_FAILURE; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1411 | goto out; |
| 1412 | } |
| 1413 | |
| 1414 | guid = efi_global_variable_guid; |
| 1415 | size = sizeof(u16); |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1416 | ret = efi_set_variable_int(L"BootNext", &guid, |
AKASHI Takahiro | c1f3ebc | 2019-06-04 15:52:10 +0900 | [diff] [blame] | 1417 | EFI_VARIABLE_NON_VOLATILE | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1418 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 1419 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1420 | size, &bootnext, false); |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 1421 | if (ret != EFI_SUCCESS) { |
| 1422 | printf("Cannot set BootNext\n"); |
| 1423 | r = CMD_RET_FAILURE; |
| 1424 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1425 | out: |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1426 | return r; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * do_efi_boot_order() - manage UEFI BootOrder variable |
| 1431 | * |
| 1432 | * @cmdtp: Command table |
| 1433 | * @flag: Command flag |
| 1434 | * @argc: Number of arguments |
| 1435 | * @argv: Argument array |
| 1436 | * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure |
| 1437 | * |
| 1438 | * Implement efidebug "boot order" sub-command. |
| 1439 | * Show order of UEFI load options, or change it in BootOrder variable. |
Heinrich Schuchardt | b1d6543 | 2019-07-14 14:00:41 +0200 | [diff] [blame] | 1440 | * |
| 1441 | * efidebug boot order [<id> ...] |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1442 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1443 | static int do_efi_boot_order(struct cmd_tbl *cmdtp, int flag, |
| 1444 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1445 | { |
| 1446 | u16 *bootorder = NULL; |
| 1447 | efi_uintn_t size; |
| 1448 | int id, i; |
| 1449 | char *endp; |
| 1450 | efi_guid_t guid; |
| 1451 | efi_status_t ret; |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 1452 | int r = CMD_RET_SUCCESS; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1453 | |
| 1454 | if (argc == 1) |
| 1455 | return show_efi_boot_order(); |
| 1456 | |
| 1457 | argc--; |
| 1458 | argv++; |
| 1459 | |
| 1460 | size = argc * sizeof(u16); |
| 1461 | bootorder = malloc(size); |
| 1462 | if (!bootorder) |
| 1463 | return CMD_RET_FAILURE; |
| 1464 | |
| 1465 | for (i = 0; i < argc; i++) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 1466 | id = (int)hextoul(argv[i], &endp); |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1467 | if (*endp != '\0' || id > 0xffff) { |
| 1468 | printf("invalid value: %s\n", argv[i]); |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1469 | r = CMD_RET_FAILURE; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1470 | goto out; |
| 1471 | } |
| 1472 | |
| 1473 | bootorder[i] = (u16)id; |
| 1474 | } |
| 1475 | |
| 1476 | guid = efi_global_variable_guid; |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1477 | ret = efi_set_variable_int(L"BootOrder", &guid, |
AKASHI Takahiro | c1f3ebc | 2019-06-04 15:52:10 +0900 | [diff] [blame] | 1478 | EFI_VARIABLE_NON_VOLATILE | |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1479 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 1480 | EFI_VARIABLE_RUNTIME_ACCESS, |
Heinrich Schuchardt | e8324f5 | 2021-05-24 11:10:59 +0200 | [diff] [blame] | 1481 | size, bootorder, true); |
Heinrich Schuchardt | 99a21fc | 2019-06-20 12:59:45 +0200 | [diff] [blame] | 1482 | if (ret != EFI_SUCCESS) { |
| 1483 | printf("Cannot set BootOrder\n"); |
| 1484 | r = CMD_RET_FAILURE; |
| 1485 | } |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1486 | out: |
| 1487 | free(bootorder); |
| 1488 | |
Heinrich Schuchardt | 8bdd149 | 2019-06-20 12:48:04 +0200 | [diff] [blame] | 1489 | return r; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1490 | } |
| 1491 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1492 | static struct cmd_tbl cmd_efidebug_boot_sub[] = { |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1493 | U_BOOT_CMD_MKENT(add, CONFIG_SYS_MAXARGS, 1, do_efi_boot_add, "", ""), |
| 1494 | U_BOOT_CMD_MKENT(rm, CONFIG_SYS_MAXARGS, 1, do_efi_boot_rm, "", ""), |
| 1495 | U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_efi_boot_dump, "", ""), |
| 1496 | U_BOOT_CMD_MKENT(next, CONFIG_SYS_MAXARGS, 1, do_efi_boot_next, "", ""), |
| 1497 | U_BOOT_CMD_MKENT(order, CONFIG_SYS_MAXARGS, 1, do_efi_boot_order, |
| 1498 | "", ""), |
| 1499 | }; |
| 1500 | |
| 1501 | /** |
| 1502 | * do_efi_boot_opt() - manage UEFI load options |
| 1503 | * |
| 1504 | * @cmdtp: Command table |
| 1505 | * @flag: Command flag |
| 1506 | * @argc: Number of arguments |
| 1507 | * @argv: Argument array |
| 1508 | * Return: CMD_RET_SUCCESS on success, |
| 1509 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 1510 | * |
| 1511 | * Implement efidebug "boot" sub-command. |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1512 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1513 | static int do_efi_boot_opt(struct cmd_tbl *cmdtp, int flag, |
| 1514 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1515 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1516 | struct cmd_tbl *cp; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1517 | |
| 1518 | if (argc < 2) |
| 1519 | return CMD_RET_USAGE; |
| 1520 | |
| 1521 | argc--; argv++; |
| 1522 | |
| 1523 | cp = find_cmd_tbl(argv[0], cmd_efidebug_boot_sub, |
| 1524 | ARRAY_SIZE(cmd_efidebug_boot_sub)); |
| 1525 | if (!cp) |
| 1526 | return CMD_RET_USAGE; |
| 1527 | |
| 1528 | return cp->cmd(cmdtp, flag, argc, argv); |
| 1529 | } |
| 1530 | |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1531 | /** |
| 1532 | * do_efi_test_bootmgr() - run simple bootmgr for test |
| 1533 | * |
| 1534 | * @cmdtp: Command table |
| 1535 | * @flag: Command flag |
| 1536 | * @argc: Number of arguments |
| 1537 | * @argv: Argument array |
| 1538 | * Return: CMD_RET_SUCCESS on success, |
| 1539 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 1540 | * |
| 1541 | * Implement efidebug "test bootmgr" sub-command. |
| 1542 | * Run simple bootmgr for test. |
| 1543 | * |
| 1544 | * efidebug test bootmgr |
| 1545 | */ |
Heinrich Schuchardt | b2625e8 | 2021-01-15 19:02:50 +0100 | [diff] [blame] | 1546 | static __maybe_unused int do_efi_test_bootmgr(struct cmd_tbl *cmdtp, int flag, |
| 1547 | int argc, char * const argv[]) |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1548 | { |
| 1549 | efi_handle_t image; |
| 1550 | efi_uintn_t exit_data_size = 0; |
| 1551 | u16 *exit_data = NULL; |
| 1552 | efi_status_t ret; |
Heinrich Schuchardt | e6ed835 | 2020-08-11 18:20:50 +0200 | [diff] [blame] | 1553 | void *load_options = NULL; |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1554 | |
Heinrich Schuchardt | a7647a7 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 1555 | ret = efi_bootmgr_load(&image, &load_options); |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1556 | printf("efi_bootmgr_load() returned: %ld\n", ret & ~EFI_ERROR_MASK); |
| 1557 | |
| 1558 | /* We call efi_start_image() even if error for test purpose. */ |
| 1559 | ret = EFI_CALL(efi_start_image(image, &exit_data_size, &exit_data)); |
| 1560 | printf("efi_start_image() returned: %ld\n", ret & ~EFI_ERROR_MASK); |
| 1561 | if (ret && exit_data) |
| 1562 | efi_free_pool(exit_data); |
| 1563 | |
| 1564 | efi_restore_gd(); |
| 1565 | |
Heinrich Schuchardt | a7647a7 | 2020-08-07 17:49:39 +0200 | [diff] [blame] | 1566 | free(load_options); |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1567 | return CMD_RET_SUCCESS; |
| 1568 | } |
| 1569 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1570 | static struct cmd_tbl cmd_efidebug_test_sub[] = { |
Heinrich Schuchardt | b2625e8 | 2021-01-15 19:02:50 +0100 | [diff] [blame] | 1571 | #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1572 | U_BOOT_CMD_MKENT(bootmgr, CONFIG_SYS_MAXARGS, 1, do_efi_test_bootmgr, |
| 1573 | "", ""), |
Heinrich Schuchardt | b2625e8 | 2021-01-15 19:02:50 +0100 | [diff] [blame] | 1574 | #endif |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1575 | }; |
| 1576 | |
| 1577 | /** |
| 1578 | * do_efi_test() - manage UEFI load options |
| 1579 | * |
| 1580 | * @cmdtp: Command table |
| 1581 | * @flag: Command flag |
| 1582 | * @argc: Number of arguments |
| 1583 | * @argv: Argument array |
| 1584 | * Return: CMD_RET_SUCCESS on success, |
| 1585 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 1586 | * |
| 1587 | * Implement efidebug "test" sub-command. |
| 1588 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1589 | static int do_efi_test(struct cmd_tbl *cmdtp, int flag, |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1590 | int argc, char * const argv[]) |
| 1591 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1592 | struct cmd_tbl *cp; |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1593 | |
| 1594 | if (argc < 2) |
| 1595 | return CMD_RET_USAGE; |
| 1596 | |
| 1597 | argc--; argv++; |
| 1598 | |
| 1599 | cp = find_cmd_tbl(argv[0], cmd_efidebug_test_sub, |
| 1600 | ARRAY_SIZE(cmd_efidebug_test_sub)); |
| 1601 | if (!cp) |
| 1602 | return CMD_RET_USAGE; |
| 1603 | |
| 1604 | return cp->cmd(cmdtp, flag, argc, argv); |
| 1605 | } |
| 1606 | |
Ilias Apalodimas | f500940 | 2020-05-17 22:25:45 +0300 | [diff] [blame] | 1607 | /** |
| 1608 | * do_efi_query_info() - QueryVariableInfo EFI service |
| 1609 | * |
| 1610 | * @cmdtp: Command table |
| 1611 | * @flag: Command flag |
| 1612 | * @argc: Number of arguments |
| 1613 | * @argv: Argument array |
| 1614 | * Return: CMD_RET_SUCCESS on success, |
| 1615 | * CMD_RET_USAGE or CMD_RET_FAILURE on failure |
| 1616 | * |
| 1617 | * Implement efidebug "test" sub-command. |
| 1618 | */ |
| 1619 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1620 | static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag, |
Ilias Apalodimas | f500940 | 2020-05-17 22:25:45 +0300 | [diff] [blame] | 1621 | int argc, char * const argv[]) |
| 1622 | { |
| 1623 | efi_status_t ret; |
| 1624 | u32 attr = 0; |
| 1625 | u64 max_variable_storage_size; |
| 1626 | u64 remain_variable_storage_size; |
| 1627 | u64 max_variable_size; |
| 1628 | int i; |
| 1629 | |
| 1630 | for (i = 1; i < argc; i++) { |
| 1631 | if (!strcmp(argv[i], "-bs")) |
| 1632 | attr |= EFI_VARIABLE_BOOTSERVICE_ACCESS; |
| 1633 | else if (!strcmp(argv[i], "-rt")) |
| 1634 | attr |= EFI_VARIABLE_RUNTIME_ACCESS; |
| 1635 | else if (!strcmp(argv[i], "-nv")) |
| 1636 | attr |= EFI_VARIABLE_NON_VOLATILE; |
| 1637 | else if (!strcmp(argv[i], "-at")) |
| 1638 | attr |= |
| 1639 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; |
| 1640 | } |
| 1641 | |
| 1642 | ret = EFI_CALL(efi_query_variable_info(attr, |
| 1643 | &max_variable_storage_size, |
| 1644 | &remain_variable_storage_size, |
| 1645 | &max_variable_size)); |
| 1646 | if (ret != EFI_SUCCESS) { |
| 1647 | printf("Error: Cannot query UEFI variables, r = %lu\n", |
| 1648 | ret & ~EFI_ERROR_MASK); |
| 1649 | return CMD_RET_FAILURE; |
| 1650 | } |
| 1651 | |
| 1652 | printf("Max storage size %llu\n", max_variable_storage_size); |
| 1653 | printf("Remaining storage size %llu\n", remain_variable_storage_size); |
| 1654 | printf("Max variable size %llu\n", max_variable_size); |
| 1655 | |
| 1656 | return CMD_RET_SUCCESS; |
| 1657 | } |
| 1658 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1659 | static struct cmd_tbl cmd_efidebug_sub[] = { |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1660 | U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""), |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 1661 | #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT |
| 1662 | U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule, |
| 1663 | "", ""), |
| 1664 | #endif |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 1665 | U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices, |
| 1666 | "", ""), |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 1667 | U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers, |
| 1668 | "", ""), |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 1669 | U_BOOT_CMD_MKENT(dh, CONFIG_SYS_MAXARGS, 1, do_efi_show_handles, |
| 1670 | "", ""), |
AKASHI Takahiro | 71ab1bf | 2019-02-25 15:54:42 +0900 | [diff] [blame] | 1671 | U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1, do_efi_show_images, |
| 1672 | "", ""), |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 1673 | U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1, do_efi_show_memmap, |
| 1674 | "", ""), |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 1675 | U_BOOT_CMD_MKENT(tables, CONFIG_SYS_MAXARGS, 1, do_efi_show_tables, |
| 1676 | "", ""), |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1677 | U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_efi_test, |
| 1678 | "", ""), |
Ilias Apalodimas | f500940 | 2020-05-17 22:25:45 +0300 | [diff] [blame] | 1679 | U_BOOT_CMD_MKENT(query, CONFIG_SYS_MAXARGS, 1, do_efi_query_info, |
| 1680 | "", ""), |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1681 | }; |
| 1682 | |
| 1683 | /** |
| 1684 | * do_efidebug() - display and configure UEFI environment |
| 1685 | * |
| 1686 | * @cmdtp: Command table |
| 1687 | * @flag: Command flag |
| 1688 | * @argc: Number of arguments |
| 1689 | * @argv: Argument array |
| 1690 | * Return: CMD_RET_SUCCESS on success, |
| 1691 | * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure |
| 1692 | * |
| 1693 | * Implement efidebug command which allows us to display and |
| 1694 | * configure UEFI environment. |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1695 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1696 | static int do_efidebug(struct cmd_tbl *cmdtp, int flag, |
| 1697 | int argc, char *const argv[]) |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1698 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1699 | struct cmd_tbl *cp; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1700 | efi_status_t r; |
| 1701 | |
| 1702 | if (argc < 2) |
| 1703 | return CMD_RET_USAGE; |
| 1704 | |
| 1705 | argc--; argv++; |
| 1706 | |
| 1707 | /* Initialize UEFI drivers */ |
| 1708 | r = efi_init_obj_list(); |
| 1709 | if (r != EFI_SUCCESS) { |
| 1710 | printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", |
| 1711 | r & ~EFI_ERROR_MASK); |
| 1712 | return CMD_RET_FAILURE; |
| 1713 | } |
| 1714 | |
| 1715 | cp = find_cmd_tbl(argv[0], cmd_efidebug_sub, |
| 1716 | ARRAY_SIZE(cmd_efidebug_sub)); |
| 1717 | if (!cp) |
| 1718 | return CMD_RET_USAGE; |
| 1719 | |
| 1720 | return cp->cmd(cmdtp, flag, argc, argv); |
| 1721 | } |
| 1722 | |
| 1723 | #ifdef CONFIG_SYS_LONGHELP |
| 1724 | static char efidebug_help_text[] = |
| 1725 | " - UEFI Shell-like interface to configure UEFI environment\n" |
| 1726 | "\n" |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1727 | "efidebug boot add " |
| 1728 | "-b <bootid> <label> <interface> <devnum>[:<part>] <file path> " |
| 1729 | "-i <interface> <devnum>[:<part>] <initrd file path> " |
| 1730 | "-s '<optional data>'\n" |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1731 | " - set UEFI BootXXXX variable\n" |
| 1732 | " <load options> will be passed to UEFI application\n" |
| 1733 | "efidebug boot rm <bootid#1> [<bootid#2> [<bootid#3> [...]]]\n" |
| 1734 | " - delete UEFI BootXXXX variables\n" |
| 1735 | "efidebug boot dump\n" |
| 1736 | " - dump all UEFI BootXXXX variables\n" |
| 1737 | "efidebug boot next <bootid>\n" |
| 1738 | " - set UEFI BootNext variable\n" |
| 1739 | "efidebug boot order [<bootid#1> [<bootid#2> [<bootid#3> [...]]]]\n" |
| 1740 | " - set/show UEFI boot order\n" |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 1741 | "\n" |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 1742 | #ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT |
| 1743 | "efidebug capsule update [-v] <capsule address>\n" |
| 1744 | " - process a capsule\n" |
Sughosh Ganu | e6f9efc | 2020-12-30 19:27:11 +0530 | [diff] [blame] | 1745 | "efidebug capsule disk-update\n" |
| 1746 | " - update a capsule from disk\n" |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 1747 | "efidebug capsule show <capsule address>\n" |
| 1748 | " - show capsule information\n" |
| 1749 | "efidebug capsule result [<capsule result var>]\n" |
| 1750 | " - show a capsule update result\n" |
Jose Marinho | b027e79 | 2021-03-11 13:18:51 +0000 | [diff] [blame] | 1751 | #ifdef CONFIG_EFI_ESRT |
| 1752 | "efidebug capsule esrt\n" |
| 1753 | " - print the ESRT\n" |
| 1754 | #endif |
AKASHI Takahiro | 38833c8 | 2020-11-17 09:28:01 +0900 | [diff] [blame] | 1755 | "\n" |
| 1756 | #endif |
AKASHI Takahiro | e32788a | 2019-02-25 15:54:39 +0900 | [diff] [blame] | 1757 | "efidebug devices\n" |
Heinrich Schuchardt | c414d88 | 2020-01-07 07:48:15 +0100 | [diff] [blame] | 1758 | " - show UEFI devices\n" |
AKASHI Takahiro | 185716a | 2019-02-25 15:54:40 +0900 | [diff] [blame] | 1759 | "efidebug drivers\n" |
Heinrich Schuchardt | c414d88 | 2020-01-07 07:48:15 +0100 | [diff] [blame] | 1760 | " - show UEFI drivers\n" |
AKASHI Takahiro | 02e8ca6 | 2019-02-25 15:54:41 +0900 | [diff] [blame] | 1761 | "efidebug dh\n" |
Heinrich Schuchardt | c414d88 | 2020-01-07 07:48:15 +0100 | [diff] [blame] | 1762 | " - show UEFI handles\n" |
AKASHI Takahiro | 71ab1bf | 2019-02-25 15:54:42 +0900 | [diff] [blame] | 1763 | "efidebug images\n" |
AKASHI Takahiro | 32979d8 | 2019-02-25 15:54:43 +0900 | [diff] [blame] | 1764 | " - show loaded images\n" |
| 1765 | "efidebug memmap\n" |
Heinrich Schuchardt | c414d88 | 2020-01-07 07:48:15 +0100 | [diff] [blame] | 1766 | " - show UEFI memory map\n" |
Heinrich Schuchardt | 75844e5 | 2020-01-07 05:57:47 +0100 | [diff] [blame] | 1767 | "efidebug tables\n" |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1768 | " - show UEFI configuration tables\n" |
Heinrich Schuchardt | b2625e8 | 2021-01-15 19:02:50 +0100 | [diff] [blame] | 1769 | #ifdef CONFIG_CMD_BOOTEFI_BOOTMGR |
AKASHI Takahiro | 36bba2c | 2020-04-14 11:51:48 +0900 | [diff] [blame] | 1770 | "efidebug test bootmgr\n" |
Ilias Apalodimas | f500940 | 2020-05-17 22:25:45 +0300 | [diff] [blame] | 1771 | " - run simple bootmgr for test\n" |
Heinrich Schuchardt | b2625e8 | 2021-01-15 19:02:50 +0100 | [diff] [blame] | 1772 | #endif |
Ilias Apalodimas | f500940 | 2020-05-17 22:25:45 +0300 | [diff] [blame] | 1773 | "efidebug query [-nv][-bs][-rt][-at]\n" |
| 1774 | " - show size of UEFI variables store\n"; |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1775 | #endif |
| 1776 | |
| 1777 | U_BOOT_CMD( |
Ilias Apalodimas | 773c090 | 2021-03-17 21:55:01 +0200 | [diff] [blame] | 1778 | efidebug, CONFIG_SYS_MAXARGS, 0, do_efidebug, |
AKASHI Takahiro | e7c0883 | 2019-02-25 15:54:38 +0900 | [diff] [blame] | 1779 | "Configure UEFI environment", |
| 1780 | efidebug_help_text |
| 1781 | ); |