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