Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 2 | /* |
Pali Rohár | 10a953d | 2020-04-01 00:35:08 +0200 | [diff] [blame] | 3 | * (C) Copyright 2011-2013 Pali Rohár <pali@kernel.org> |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 6 | #include <charset.h> |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 7 | #include <cli.h> |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 8 | #include <command.h> |
| 9 | #include <ansi.h> |
Masahisa Kojima | 767a9e6 | 2022-09-12 17:33:54 +0900 | [diff] [blame] | 10 | #include <efi_config.h> |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 11 | #include <efi_variable.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 14 | #include <menu.h> |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 15 | #include <watchdog.h> |
| 16 | #include <malloc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 18 | #include <linux/string.h> |
| 19 | |
| 20 | /* maximum bootmenu entries */ |
| 21 | #define MAX_COUNT 99 |
| 22 | |
| 23 | /* maximal size of bootmenu env |
| 24 | * 9 = strlen("bootmenu_") |
| 25 | * 2 = strlen(MAX_COUNT) |
| 26 | * 1 = NULL term |
| 27 | */ |
| 28 | #define MAX_ENV_SIZE (9 + 2 + 1) |
| 29 | |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 30 | enum bootmenu_ret { |
| 31 | BOOTMENU_RET_SUCCESS = 0, |
| 32 | BOOTMENU_RET_FAIL, |
| 33 | BOOTMENU_RET_QUIT, |
| 34 | BOOTMENU_RET_UPDATED, |
| 35 | }; |
| 36 | |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 37 | enum boot_type { |
| 38 | BOOTMENU_TYPE_NONE = 0, |
| 39 | BOOTMENU_TYPE_BOOTMENU, |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 40 | BOOTMENU_TYPE_UEFI_BOOT_OPTION, |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 41 | }; |
| 42 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 43 | struct bootmenu_entry { |
| 44 | unsigned short int num; /* unique number 0 .. MAX_COUNT */ |
| 45 | char key[3]; /* key identifier of number */ |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 46 | char *title; /* title of entry */ |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 47 | char *command; /* hush command of entry */ |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 48 | enum boot_type type; /* boot type of entry */ |
| 49 | u16 bootorder; /* order for each boot type */ |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 50 | struct bootmenu_data *menu; /* this bootmenu */ |
| 51 | struct bootmenu_entry *next; /* next menu entry (num+1) */ |
| 52 | }; |
| 53 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 54 | static char *bootmenu_getoption(unsigned short int n) |
| 55 | { |
Lan Yixun (dlan) | 981c7e0 | 2013-06-27 18:58:53 +0800 | [diff] [blame] | 56 | char name[MAX_ENV_SIZE]; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 57 | |
| 58 | if (n > MAX_COUNT) |
| 59 | return NULL; |
| 60 | |
Lan Yixun (dlan) | 981c7e0 | 2013-06-27 18:58:53 +0800 | [diff] [blame] | 61 | sprintf(name, "bootmenu_%d", n); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 62 | return env_get(name); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static void bootmenu_print_entry(void *data) |
| 66 | { |
| 67 | struct bootmenu_entry *entry = data; |
| 68 | int reverse = (entry->menu->active == entry->num); |
| 69 | |
| 70 | /* |
| 71 | * Move cursor to line where the entry will be drown (entry->num) |
| 72 | * First 3 lines contain bootmenu header + 1 empty line |
| 73 | */ |
Heinrich Schuchardt | d7dc877 | 2022-05-01 23:17:18 +0200 | [diff] [blame] | 74 | printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 75 | |
| 76 | if (reverse) |
| 77 | puts(ANSI_COLOR_REVERSE); |
| 78 | |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 79 | printf("%s", entry->title); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 80 | |
| 81 | if (reverse) |
| 82 | puts(ANSI_COLOR_RESET); |
| 83 | } |
| 84 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 85 | static char *bootmenu_choice_entry(void *data) |
| 86 | { |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 87 | struct cli_ch_state s_cch, *cch = &s_cch; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 88 | struct bootmenu_data *menu = data; |
| 89 | struct bootmenu_entry *iter; |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 90 | enum bootmenu_key key = BKEY_NONE; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 91 | int i; |
| 92 | |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 93 | cli_ch_init(cch); |
| 94 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 95 | while (1) { |
| 96 | if (menu->delay >= 0) { |
| 97 | /* Autoboot was not stopped */ |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 98 | key = bootmenu_autoboot_loop(menu, cch); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 99 | } else { |
| 100 | /* Some key was pressed, so autoboot was stopped */ |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 101 | key = bootmenu_loop(menu, cch); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | switch (key) { |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 105 | case BKEY_UP: |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 106 | menu->last_active = menu->active; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 107 | if (menu->active > 0) |
| 108 | --menu->active; |
| 109 | /* no menu key selected, regenerate menu */ |
| 110 | return NULL; |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 111 | case BKEY_DOWN: |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 112 | menu->last_active = menu->active; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 113 | if (menu->active < menu->count - 1) |
| 114 | ++menu->active; |
| 115 | /* no menu key selected, regenerate menu */ |
| 116 | return NULL; |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 117 | case BKEY_SHORTCUT: |
| 118 | /* invalid shortcut, regenerate menu */ |
| 119 | if (cch->shortcut_key >= menu->count - 1) |
| 120 | return NULL; |
| 121 | /* shortcut_key value for Exit is is -1 */ |
| 122 | menu->active = cch->shortcut_key < 0 ? menu->count - 1 : |
| 123 | cch->shortcut_key; |
| 124 | fallthrough; |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 125 | case BKEY_SELECT: |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 126 | iter = menu->first; |
| 127 | for (i = 0; i < menu->active; ++i) |
| 128 | iter = iter->next; |
| 129 | return iter->key; |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 130 | case BKEY_QUIT: |
Svyatoslav Ryhel | 08f67c4 | 2024-01-17 12:55:46 +0200 | [diff] [blame] | 131 | /* Quit by choosing the last entry */ |
Pali Rohár | 3c0629b | 2020-12-27 01:04:38 +0100 | [diff] [blame] | 132 | iter = menu->first; |
| 133 | while (iter->next) |
| 134 | iter = iter->next; |
| 135 | return iter->key; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 136 | default: |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* never happens */ |
| 142 | debug("bootmenu: this should not happen"); |
| 143 | return NULL; |
| 144 | } |
| 145 | |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 146 | static bool bootmenu_need_reprint(void *data) |
| 147 | { |
| 148 | struct bootmenu_data *menu = data; |
| 149 | bool need_reprint; |
| 150 | |
| 151 | need_reprint = menu->last_active != menu->active; |
| 152 | menu->last_active = menu->active; |
| 153 | |
| 154 | return need_reprint; |
| 155 | } |
| 156 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 157 | static void bootmenu_destroy(struct bootmenu_data *menu) |
| 158 | { |
| 159 | struct bootmenu_entry *iter = menu->first; |
| 160 | struct bootmenu_entry *next; |
| 161 | |
| 162 | while (iter) { |
| 163 | next = iter->next; |
| 164 | free(iter->title); |
| 165 | free(iter->command); |
| 166 | free(iter); |
| 167 | iter = next; |
| 168 | } |
| 169 | free(menu); |
| 170 | } |
| 171 | |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 172 | static char bootmenu_entry_shortcut_key(int index) |
| 173 | { |
| 174 | switch (index) { |
| 175 | /* 1-9 shortcut key (0 reserved) */ |
| 176 | case 0 ... 8: |
| 177 | return '1' + index; |
| 178 | /* a-z shortcut key */ |
| 179 | case 9 ... 34: |
| 180 | return 'a' + index - 9; |
| 181 | /* We support shortcut for up to 34 options (0 reserved) */ |
| 182 | default: |
| 183 | return -ENOENT; |
| 184 | } |
| 185 | } |
| 186 | |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 187 | /** |
| 188 | * prepare_bootmenu_entry() - generate the bootmenu_xx entries |
| 189 | * |
| 190 | * This function read the "bootmenu_x" U-Boot environment variable |
| 191 | * and generate the bootmenu entries. |
| 192 | * |
| 193 | * @menu: pointer to the bootmenu structure |
| 194 | * @current: pointer to the last bootmenu entry list |
| 195 | * @index: pointer to the index of the last bootmenu entry, |
| 196 | * the number of bootmenu entry is added by this function |
| 197 | * Return: 1 on success, negative value on error |
| 198 | */ |
| 199 | static int prepare_bootmenu_entry(struct bootmenu_data *menu, |
| 200 | struct bootmenu_entry **current, |
| 201 | unsigned short int *index) |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 202 | { |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 203 | char *sep; |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 204 | const char *option; |
| 205 | unsigned short int i = *index; |
| 206 | struct bootmenu_entry *entry = NULL; |
| 207 | struct bootmenu_entry *iter = *current; |
Frank Wunderlich | 6a3578e | 2018-10-05 11:41:59 +0200 | [diff] [blame] | 208 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 209 | while ((option = bootmenu_getoption(i))) { |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 210 | char shortcut_key; |
| 211 | int len; |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 212 | |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 213 | /* bootmenu_[num] format is "[title]=[commands]" */ |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 214 | sep = strchr(option, '='); |
| 215 | if (!sep) { |
| 216 | printf("Invalid bootmenu entry: %s\n", option); |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | entry = malloc(sizeof(struct bootmenu_entry)); |
| 221 | if (!entry) |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 222 | return -ENOMEM; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 223 | |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 224 | /* Add shotcut key option: %c. %s\0 */ |
| 225 | len = sep - option + 4; |
| 226 | |
| 227 | entry->title = malloc(len); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 228 | if (!entry->title) { |
| 229 | free(entry); |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 230 | return -ENOMEM; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 231 | } |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 232 | |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 233 | shortcut_key = bootmenu_entry_shortcut_key(i); |
| 234 | /* Use emtpy space if entry doesn't support shortcut key */ |
| 235 | snprintf(entry->title, len, "%c%c %s", |
| 236 | shortcut_key > 0 ? shortcut_key : ' ', |
| 237 | shortcut_key > 0 ? '.' : ' ', |
| 238 | option); |
| 239 | |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 240 | entry->command = strdup(sep + 1); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 241 | if (!entry->command) { |
| 242 | free(entry->title); |
| 243 | free(entry); |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 244 | return -ENOMEM; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 245 | } |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 246 | |
| 247 | sprintf(entry->key, "%d", i); |
| 248 | |
| 249 | entry->num = i; |
| 250 | entry->menu = menu; |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 251 | entry->type = BOOTMENU_TYPE_BOOTMENU; |
| 252 | entry->bootorder = i; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 253 | entry->next = NULL; |
| 254 | |
| 255 | if (!iter) |
| 256 | menu->first = entry; |
| 257 | else |
| 258 | iter->next = entry; |
| 259 | |
| 260 | iter = entry; |
| 261 | ++i; |
| 262 | |
| 263 | if (i == MAX_COUNT - 1) |
| 264 | break; |
| 265 | } |
| 266 | |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 267 | *index = i; |
| 268 | *current = iter; |
| 269 | |
| 270 | return 1; |
| 271 | } |
| 272 | |
Simon Glass | 315367a | 2023-02-05 15:36:28 -0700 | [diff] [blame] | 273 | #if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) && (IS_ENABLED(CONFIG_CMD_EFICONFIG)) |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 274 | /** |
| 275 | * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries |
| 276 | * |
Heinrich Schuchardt | 2013f90 | 2024-11-23 10:04:03 +0100 | [diff] [blame] | 277 | * This function reads the "BootOrder" UEFI variable |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 278 | * and generate the bootmenu entries in the order of "BootOrder". |
| 279 | * |
| 280 | * @menu: pointer to the bootmenu structure |
| 281 | * @current: pointer to the last bootmenu entry list |
| 282 | * @index: pointer to the index of the last bootmenu entry, |
| 283 | * the number of uefi entry is added by this function |
| 284 | * Return: 1 on success, negative value on error |
| 285 | */ |
| 286 | static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, |
| 287 | struct bootmenu_entry **current, |
| 288 | unsigned short int *index) |
| 289 | { |
| 290 | u16 *bootorder; |
| 291 | efi_status_t ret; |
| 292 | unsigned short j; |
| 293 | efi_uintn_t num, size; |
| 294 | void *load_option; |
| 295 | struct efi_load_option lo; |
| 296 | u16 varname[] = u"Boot####"; |
| 297 | unsigned short int i = *index; |
| 298 | struct bootmenu_entry *entry = NULL; |
| 299 | struct bootmenu_entry *iter = *current; |
| 300 | |
| 301 | bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); |
| 302 | if (!bootorder) |
| 303 | return -ENOENT; |
| 304 | |
| 305 | num = size / sizeof(u16); |
| 306 | for (j = 0; j < num; j++) { |
| 307 | entry = malloc(sizeof(struct bootmenu_entry)); |
| 308 | if (!entry) |
| 309 | return -ENOMEM; |
| 310 | |
| 311 | efi_create_indexed_name(varname, sizeof(varname), |
| 312 | "Boot", bootorder[j]); |
| 313 | load_option = efi_get_var(varname, &efi_global_variable_guid, &size); |
| 314 | if (!load_option) |
| 315 | continue; |
| 316 | |
| 317 | ret = efi_deserialize_load_option(&lo, load_option, &size); |
| 318 | if (ret != EFI_SUCCESS) { |
| 319 | log_warning("Invalid load option for %ls\n", varname); |
| 320 | free(load_option); |
| 321 | free(entry); |
| 322 | continue; |
| 323 | } |
| 324 | |
| 325 | if (lo.attributes & LOAD_OPTION_ACTIVE) { |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 326 | char *buf; |
| 327 | |
| 328 | buf = calloc(1, utf16_utf8_strlen(lo.label) + 1); |
| 329 | if (!buf) { |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 330 | free(load_option); |
| 331 | free(entry); |
| 332 | free(bootorder); |
| 333 | return -ENOMEM; |
| 334 | } |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 335 | entry->title = buf; |
| 336 | utf16_utf8_strncpy(&buf, lo.label, u16_strlen(lo.label)); |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 337 | entry->command = strdup("bootefi bootmgr"); |
| 338 | sprintf(entry->key, "%d", i); |
| 339 | entry->num = i; |
| 340 | entry->menu = menu; |
| 341 | entry->type = BOOTMENU_TYPE_UEFI_BOOT_OPTION; |
| 342 | entry->bootorder = bootorder[j]; |
| 343 | entry->next = NULL; |
| 344 | |
| 345 | if (!iter) |
| 346 | menu->first = entry; |
| 347 | else |
| 348 | iter->next = entry; |
| 349 | |
| 350 | iter = entry; |
| 351 | i++; |
| 352 | } |
| 353 | |
| 354 | free(load_option); |
| 355 | |
| 356 | if (i == MAX_COUNT - 1) |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | free(bootorder); |
| 361 | *index = i; |
| 362 | *current = iter; |
| 363 | |
| 364 | return 1; |
| 365 | } |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 366 | #endif |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 367 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 368 | /** |
| 369 | * bootmenu_create() - create boot menu entries |
| 370 | * |
| 371 | * @uefi: consider UEFI boot options |
| 372 | * @delay: autostart delay in seconds |
| 373 | */ |
| 374 | static struct bootmenu_data *bootmenu_create(int uefi, int delay) |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 375 | { |
| 376 | int ret; |
| 377 | unsigned short int i = 0; |
| 378 | struct bootmenu_data *menu; |
| 379 | struct bootmenu_entry *iter = NULL; |
| 380 | struct bootmenu_entry *entry; |
| 381 | char *default_str; |
| 382 | |
| 383 | menu = malloc(sizeof(struct bootmenu_data)); |
| 384 | if (!menu) |
| 385 | return NULL; |
| 386 | |
| 387 | menu->delay = delay; |
| 388 | menu->active = 0; |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 389 | menu->last_active = -1; |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 390 | menu->first = NULL; |
| 391 | |
| 392 | default_str = env_get("bootmenu_default"); |
| 393 | if (default_str) |
| 394 | menu->active = (int)simple_strtol(default_str, NULL, 10); |
| 395 | |
| 396 | ret = prepare_bootmenu_entry(menu, &iter, &i); |
| 397 | if (ret < 0) |
| 398 | goto cleanup; |
| 399 | |
Simon Glass | 315367a | 2023-02-05 15:36:28 -0700 | [diff] [blame] | 400 | #if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) && (IS_ENABLED(CONFIG_CMD_EFICONFIG)) |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 401 | if (uefi && i < MAX_COUNT - 1) { |
Masahisa Kojima | 767a9e6 | 2022-09-12 17:33:54 +0900 | [diff] [blame] | 402 | efi_status_t efi_ret; |
| 403 | |
| 404 | /* |
| 405 | * UEFI specification requires booting from removal media using |
| 406 | * a architecture-specific default image name such as BOOTAA64.EFI. |
| 407 | */ |
Raymond Mao | 70a76c5 | 2023-06-19 14:22:58 -0700 | [diff] [blame] | 408 | efi_ret = efi_bootmgr_update_media_device_boot_option(); |
Raymond Mao | a35784d | 2023-06-19 14:22:59 -0700 | [diff] [blame] | 409 | if (efi_ret != EFI_SUCCESS) |
Masahisa Kojima | 767a9e6 | 2022-09-12 17:33:54 +0900 | [diff] [blame] | 410 | goto cleanup; |
| 411 | |
| 412 | ret = prepare_uefi_bootorder_entry(menu, &iter, &i); |
| 413 | if (ret < 0 && ret != -ENOENT) |
| 414 | goto cleanup; |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 415 | } |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 416 | #endif |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 417 | |
Svyatoslav Ryhel | 08f67c4 | 2024-01-17 12:55:46 +0200 | [diff] [blame] | 418 | /* Add Exit entry at the end */ |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 419 | if (i <= MAX_COUNT - 1) { |
| 420 | entry = malloc(sizeof(struct bootmenu_entry)); |
| 421 | if (!entry) |
| 422 | goto cleanup; |
| 423 | |
Svyatoslav Ryhel | 08f67c4 | 2024-01-17 12:55:46 +0200 | [diff] [blame] | 424 | /* Add Quit entry if exiting bootmenu is disabled */ |
Masahisa Kojima | 97cbcc4 | 2022-05-26 19:09:38 +0900 | [diff] [blame] | 425 | if (!IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE)) |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 426 | entry->title = strdup("0. Exit"); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 427 | else |
Christian Marangi | b357fc6 | 2025-05-25 15:43:58 +0200 | [diff] [blame] | 428 | entry->title = strdup("0. Quit"); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 429 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 430 | if (!entry->title) { |
| 431 | free(entry); |
| 432 | goto cleanup; |
| 433 | } |
| 434 | |
| 435 | entry->command = strdup(""); |
| 436 | if (!entry->command) { |
| 437 | free(entry->title); |
| 438 | free(entry); |
| 439 | goto cleanup; |
| 440 | } |
| 441 | |
| 442 | sprintf(entry->key, "%d", i); |
| 443 | |
| 444 | entry->num = i; |
| 445 | entry->menu = menu; |
Masahisa Kojima | 015405a | 2022-04-28 17:09:41 +0900 | [diff] [blame] | 446 | entry->type = BOOTMENU_TYPE_NONE; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 447 | entry->next = NULL; |
| 448 | |
| 449 | if (!iter) |
| 450 | menu->first = entry; |
| 451 | else |
| 452 | iter->next = entry; |
| 453 | |
| 454 | iter = entry; |
| 455 | ++i; |
| 456 | } |
| 457 | |
| 458 | menu->count = i; |
Frank Wunderlich | 4931d96 | 2018-12-03 11:23:41 +0100 | [diff] [blame] | 459 | |
| 460 | if ((menu->active >= menu->count)||(menu->active < 0)) { //ensure active menuitem is inside menu |
| 461 | printf("active menuitem (%d) is outside menu (0..%d)\n",menu->active,menu->count-1); |
| 462 | menu->active=0; |
| 463 | } |
| 464 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 465 | return menu; |
| 466 | |
| 467 | cleanup: |
| 468 | bootmenu_destroy(menu); |
| 469 | return NULL; |
| 470 | } |
| 471 | |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 472 | static void menu_display_statusline(struct menu *m) |
| 473 | { |
| 474 | struct bootmenu_entry *entry; |
| 475 | struct bootmenu_data *menu; |
| 476 | |
| 477 | if (menu_default_choice(m, (void *)&entry) < 0) |
| 478 | return; |
| 479 | |
| 480 | menu = entry->menu; |
| 481 | |
| 482 | printf(ANSI_CURSOR_POSITION, 1, 1); |
| 483 | puts(ANSI_CLEAR_LINE); |
Heinrich Schuchardt | d7dc877 | 2022-05-01 23:17:18 +0200 | [diff] [blame] | 484 | printf(ANSI_CURSOR_POSITION, 2, 3); |
| 485 | puts("*** U-Boot Boot Menu ***"); |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 486 | puts(ANSI_CLEAR_LINE_TO_END); |
| 487 | printf(ANSI_CURSOR_POSITION, 3, 1); |
| 488 | puts(ANSI_CLEAR_LINE); |
| 489 | |
| 490 | /* First 3 lines are bootmenu header + 2 empty lines between entries */ |
| 491 | printf(ANSI_CURSOR_POSITION, menu->count + 5, 1); |
| 492 | puts(ANSI_CLEAR_LINE); |
Heinrich Schuchardt | d7dc877 | 2022-05-01 23:17:18 +0200 | [diff] [blame] | 493 | printf(ANSI_CURSOR_POSITION, menu->count + 6, 3); |
Masahisa Kojima | 3a9eb07 | 2023-02-02 18:24:43 +0900 | [diff] [blame] | 494 | puts("Press UP/DOWN to move, ENTER to select, ESC to quit"); |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 495 | puts(ANSI_CLEAR_LINE_TO_END); |
| 496 | printf(ANSI_CURSOR_POSITION, menu->count + 7, 1); |
| 497 | puts(ANSI_CLEAR_LINE); |
| 498 | } |
| 499 | |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 500 | static void handle_uefi_bootnext(void) |
| 501 | { |
| 502 | u16 bootnext; |
| 503 | efi_status_t ret; |
| 504 | efi_uintn_t size; |
| 505 | |
| 506 | /* Initialize EFI drivers */ |
| 507 | ret = efi_init_obj_list(); |
| 508 | if (ret != EFI_SUCCESS) { |
| 509 | log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", |
| 510 | ret & ~EFI_ERROR_MASK); |
| 511 | |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | /* If UEFI BootNext variable is set, boot the BootNext load option */ |
| 516 | size = sizeof(u16); |
| 517 | ret = efi_get_variable_int(u"BootNext", |
| 518 | &efi_global_variable_guid, |
| 519 | NULL, &size, &bootnext, NULL); |
| 520 | if (ret == EFI_SUCCESS) |
| 521 | /* BootNext does exist here, try to boot */ |
| 522 | run_command("bootefi bootmgr", 0); |
| 523 | } |
| 524 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 525 | /** |
| 526 | * bootmenu_show - display boot menu |
| 527 | * |
| 528 | * @uefi: generated entries for UEFI boot options |
| 529 | * @delay: autoboot delay in seconds |
| 530 | */ |
| 531 | static enum bootmenu_ret bootmenu_show(int uefi, int delay) |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 532 | { |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 533 | int cmd_ret; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 534 | int init = 0; |
| 535 | void *choice = NULL; |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 536 | char *title = NULL; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 537 | char *command = NULL; |
| 538 | struct menu *menu; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 539 | struct bootmenu_entry *iter; |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 540 | int ret = BOOTMENU_RET_SUCCESS; |
| 541 | struct bootmenu_data *bootmenu; |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 542 | efi_status_t efi_ret = EFI_SUCCESS; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 543 | char *option, *sep; |
| 544 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 545 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && uefi) |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 546 | handle_uefi_bootnext(); |
| 547 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 548 | /* If delay is 0 do not create menu, just run first entry */ |
| 549 | if (delay == 0) { |
| 550 | option = bootmenu_getoption(0); |
| 551 | if (!option) { |
| 552 | puts("bootmenu option 0 was not found\n"); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 553 | return BOOTMENU_RET_FAIL; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 554 | } |
| 555 | sep = strchr(option, '='); |
| 556 | if (!sep) { |
| 557 | puts("bootmenu option 0 is invalid\n"); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 558 | return BOOTMENU_RET_FAIL; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 559 | } |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 560 | cmd_ret = run_command(sep + 1, 0); |
| 561 | return (cmd_ret == CMD_RET_SUCCESS ? BOOTMENU_RET_SUCCESS : BOOTMENU_RET_FAIL); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 564 | bootmenu = bootmenu_create(uefi, delay); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 565 | if (!bootmenu) |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 566 | return BOOTMENU_RET_FAIL; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 567 | |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 568 | menu = menu_create(NULL, bootmenu->delay, 1, menu_display_statusline, |
| 569 | bootmenu_print_entry, bootmenu_choice_entry, |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 570 | bootmenu_need_reprint, bootmenu); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 571 | if (!menu) { |
| 572 | bootmenu_destroy(bootmenu); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 573 | return BOOTMENU_RET_FAIL; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | for (iter = bootmenu->first; iter; iter = iter->next) { |
Masahisa Kojima | acc969e | 2022-03-24 22:54:33 +0900 | [diff] [blame] | 577 | if (menu_item_add(menu, iter->key, iter) != 1) |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 578 | goto cleanup; |
| 579 | } |
| 580 | |
| 581 | /* Default menu entry is always first */ |
| 582 | menu_default_set(menu, "0"); |
| 583 | |
| 584 | puts(ANSI_CURSOR_HIDE); |
| 585 | puts(ANSI_CLEAR_CONSOLE); |
| 586 | printf(ANSI_CURSOR_POSITION, 1, 1); |
| 587 | |
| 588 | init = 1; |
| 589 | |
Masahisa Kojima | acc969e | 2022-03-24 22:54:33 +0900 | [diff] [blame] | 590 | if (menu_get_choice(menu, &choice) == 1) { |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 591 | iter = choice; |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 592 | title = strdup(iter->title); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 593 | command = strdup(iter->command); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 594 | |
Svyatoslav Ryhel | 08f67c4 | 2024-01-17 12:55:46 +0200 | [diff] [blame] | 595 | /* last entry exits bootmenu */ |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 596 | if (iter->num == iter->menu->count - 1) { |
| 597 | ret = BOOTMENU_RET_QUIT; |
| 598 | goto cleanup; |
| 599 | } |
| 600 | } else { |
| 601 | goto cleanup; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 604 | /* |
| 605 | * If the selected entry is UEFI BOOT####, set the BootNext variable. |
| 606 | * Then uefi bootmgr is invoked by the preset command in iter->command. |
| 607 | */ |
| 608 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { |
| 609 | if (iter->type == BOOTMENU_TYPE_UEFI_BOOT_OPTION) { |
| 610 | /* |
| 611 | * UEFI specification requires BootNext variable needs non-volatile |
| 612 | * attribute, but this BootNext is only used inside of U-Boot and |
| 613 | * removed by efi bootmgr once BootNext is processed. |
| 614 | * So this BootNext can be volatile. |
| 615 | */ |
| 616 | efi_ret = efi_set_variable_int(u"BootNext", &efi_global_variable_guid, |
| 617 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 618 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 619 | sizeof(u16), &iter->bootorder, false); |
| 620 | if (efi_ret != EFI_SUCCESS) |
| 621 | goto cleanup; |
| 622 | } |
| 623 | } |
| 624 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 625 | cleanup: |
| 626 | menu_destroy(menu); |
| 627 | bootmenu_destroy(bootmenu); |
| 628 | |
| 629 | if (init) { |
| 630 | puts(ANSI_CURSOR_SHOW); |
| 631 | puts(ANSI_CLEAR_CONSOLE); |
| 632 | printf(ANSI_CURSOR_POSITION, 1, 1); |
| 633 | } |
| 634 | |
| 635 | if (title && command) { |
Masahisa Kojima | 1baf964 | 2022-05-29 10:52:43 +0900 | [diff] [blame] | 636 | debug("Starting entry '%s'\n", title); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 637 | free(title); |
Masahisa Kojima | f90c7b2 | 2022-04-28 17:09:42 +0900 | [diff] [blame] | 638 | if (efi_ret == EFI_SUCCESS) |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 639 | cmd_ret = run_command(command, 0); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 640 | free(command); |
| 641 | } |
| 642 | |
Tom Rini | e510a3f | 2022-12-04 10:13:33 -0500 | [diff] [blame] | 643 | #ifdef CFG_POSTBOOTMENU |
| 644 | run_command(CFG_POSTBOOTMENU, 0); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 645 | #endif |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 646 | |
| 647 | if (efi_ret != EFI_SUCCESS || cmd_ret != CMD_RET_SUCCESS) |
| 648 | ret = BOOTMENU_RET_FAIL; |
| 649 | |
| 650 | return ret; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Simon Glass | ec5f71a | 2019-07-20 20:51:24 -0600 | [diff] [blame] | 653 | #ifdef CONFIG_AUTOBOOT_MENU_SHOW |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 654 | int menu_show(int bootdelay) |
| 655 | { |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 656 | int ret; |
| 657 | |
| 658 | while (1) { |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 659 | ret = bootmenu_show(1, bootdelay); |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 660 | bootdelay = -1; |
| 661 | if (ret == BOOTMENU_RET_UPDATED) |
| 662 | continue; |
| 663 | |
Masahisa Kojima | 97cbcc4 | 2022-05-26 19:09:38 +0900 | [diff] [blame] | 664 | if (IS_ENABLED(CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE)) { |
Masahisa Kojima | 43d0ab2 | 2022-04-28 17:09:44 +0900 | [diff] [blame] | 665 | if (ret == BOOTMENU_RET_QUIT) { |
| 666 | /* default boot process */ |
| 667 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) |
| 668 | run_command("bootefi bootmgr", 0); |
| 669 | |
| 670 | run_command("run bootcmd", 0); |
| 671 | } |
| 672 | } else { |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 677 | return -1; /* -1 - abort boot and run monitor code */ |
| 678 | } |
| 679 | #endif |
| 680 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 681 | int do_bootmenu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 682 | { |
| 683 | char *delay_str = NULL; |
| 684 | int delay = 10; |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 685 | int uefi = 0; |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 686 | |
| 687 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
| 688 | delay = CONFIG_BOOTDELAY; |
| 689 | #endif |
| 690 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 691 | if (argc >= 2) { |
| 692 | if (!strcmp("-e", argv[1])) { |
| 693 | uefi = 1; |
| 694 | --argc; |
| 695 | ++argv; |
| 696 | } |
| 697 | } |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 698 | if (argc >= 2) |
| 699 | delay_str = argv[1]; |
| 700 | |
| 701 | if (!delay_str) |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 702 | delay_str = env_get("bootmenu_delay"); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 703 | |
| 704 | if (delay_str) |
| 705 | delay = (int)simple_strtol(delay_str, NULL, 10); |
| 706 | |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 707 | bootmenu_show(uefi, delay); |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | U_BOOT_CMD( |
| 712 | bootmenu, 2, 1, do_bootmenu, |
| 713 | "ANSI terminal bootmenu", |
Heinrich Schuchardt | 0259d41 | 2024-11-27 08:06:30 +0100 | [diff] [blame] | 714 | "[-e] [delay]\n" |
| 715 | "-e - show UEFI entries\n" |
| 716 | "delay - show ANSI terminal bootmenu with autoboot delay" |
Pali Rohár | ac91b47 | 2013-03-23 14:53:08 +0000 | [diff] [blame] | 717 | ); |