Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Jeroen Hofstee | 39e1230 | 2014-07-13 22:57:58 +0200 | [diff] [blame] | 8 | #include <autoboot.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 9 | #include <bootretry.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 10 | #include <cli.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 11 | #include <console.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 12 | #include <fdtdec.h> |
Simon Glass | e8c7805 | 2019-07-20 20:51:16 -0600 | [diff] [blame] | 13 | #include <hash.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 14 | #include <menu.h> |
| 15 | #include <post.h> |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 16 | #include <u-boot/sha256.h> |
Lukasz Majewski | bc8c440 | 2018-05-02 16:10:53 +0200 | [diff] [blame] | 17 | #include <bootcount.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | #define MAX_DELAY_STOP_STR 32 |
| 22 | |
| 23 | #ifndef DEBUG_BOOTKEYS |
| 24 | #define DEBUG_BOOTKEYS 0 |
| 25 | #endif |
| 26 | #define debug_bootkeys(fmt, args...) \ |
| 27 | debug_cond(DEBUG_BOOTKEYS, fmt, ##args) |
| 28 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 29 | /* Stored value of bootdelay, used by autoboot_command() */ |
| 30 | static int stored_bootdelay; |
| 31 | |
Simon Glass | 0c4bd31 | 2019-07-20 20:51:15 -0600 | [diff] [blame] | 32 | #ifdef CONFIG_AUTOBOOT_ENCRYPTION |
| 33 | #define AUTOBOOT_STOP_STR_SHA256 CONFIG_AUTOBOOT_STOP_STR_SHA256 |
| 34 | #else |
| 35 | #define AUTOBOOT_STOP_STR_SHA256 "" |
| 36 | #endif |
| 37 | |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 38 | /* |
| 39 | * Use a "constant-length" time compare function for this |
| 40 | * hash compare: |
| 41 | * |
| 42 | * https://crackstation.net/hashing-security.htm |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 43 | */ |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 44 | static int slow_equals(u8 *a, u8 *b, int len) |
| 45 | { |
| 46 | int diff = 0; |
| 47 | int i; |
| 48 | |
| 49 | for (i = 0; i < len; i++) |
| 50 | diff |= a[i] ^ b[i]; |
| 51 | |
| 52 | return diff == 0; |
| 53 | } |
| 54 | |
Simon Glass | 88fa4be | 2019-07-20 20:51:17 -0600 | [diff] [blame] | 55 | /** |
| 56 | * passwd_abort_sha256() - check for a hashed key sequence to abort booting |
| 57 | * |
| 58 | * This checks for the user entering a SHA256 hash within a given time. |
| 59 | * |
| 60 | * @etime: Timeout value ticks (stop when get_ticks() reachs this) |
| 61 | * @return 0 if autoboot should continue, 1 if it should stop |
| 62 | */ |
Simon Glass | e8c7805 | 2019-07-20 20:51:16 -0600 | [diff] [blame] | 63 | static int passwd_abort_sha256(uint64_t etime) |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 64 | { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 65 | const char *sha_env_str = env_get("bootstopkeysha256"); |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 66 | u8 sha_env[SHA256_SUM_LEN]; |
| 67 | u8 sha[SHA256_SUM_LEN]; |
| 68 | char presskey[MAX_DELAY_STOP_STR]; |
| 69 | const char *algo_name = "sha256"; |
| 70 | u_int presskey_len = 0; |
| 71 | int abort = 0; |
Martin Etnestad | 2d06fd8 | 2018-01-12 09:04:38 +0100 | [diff] [blame] | 72 | int size = sizeof(sha); |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 73 | int ret; |
| 74 | |
| 75 | if (sha_env_str == NULL) |
Simon Glass | 0c4bd31 | 2019-07-20 20:51:15 -0600 | [diff] [blame] | 76 | sha_env_str = AUTOBOOT_STOP_STR_SHA256; |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Generate the binary value from the environment hash value |
| 80 | * so that we can compare this value with the computed hash |
| 81 | * from the user input |
| 82 | */ |
| 83 | ret = hash_parse_string(algo_name, sha_env_str, sha_env); |
| 84 | if (ret) { |
| 85 | printf("Hash %s not supported!\n", algo_name); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * We don't know how long the stop-string is, so we need to |
| 91 | * generate the sha256 hash upon each input character and |
| 92 | * compare the value with the one saved in the environment |
| 93 | */ |
| 94 | do { |
| 95 | if (tstc()) { |
| 96 | /* Check for input string overflow */ |
| 97 | if (presskey_len >= MAX_DELAY_STOP_STR) |
| 98 | return 0; |
| 99 | |
| 100 | presskey[presskey_len++] = getc(); |
| 101 | |
| 102 | /* Calculate sha256 upon each new char */ |
| 103 | hash_block(algo_name, (const void *)presskey, |
| 104 | presskey_len, sha, &size); |
| 105 | |
| 106 | /* And check if sha matches saved value in env */ |
| 107 | if (slow_equals(sha, sha_env, SHA256_SUM_LEN)) |
| 108 | abort = 1; |
| 109 | } |
| 110 | } while (!abort && get_ticks() <= etime); |
| 111 | |
| 112 | return abort; |
| 113 | } |
Simon Glass | e8c7805 | 2019-07-20 20:51:16 -0600 | [diff] [blame] | 114 | |
Simon Glass | 88fa4be | 2019-07-20 20:51:17 -0600 | [diff] [blame] | 115 | /** |
| 116 | * passwd_abort_key() - check for a key sequence to aborted booting |
| 117 | * |
| 118 | * This checks for the user entering a string within a given time. |
| 119 | * |
| 120 | * @etime: Timeout value ticks (stop when get_ticks() reachs this) |
| 121 | * @return 0 if autoboot should continue, 1 if it should stop |
| 122 | */ |
Simon Glass | e8c7805 | 2019-07-20 20:51:16 -0600 | [diff] [blame] | 123 | static int passwd_abort_key(uint64_t etime) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 124 | { |
| 125 | int abort = 0; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 126 | struct { |
| 127 | char *str; |
| 128 | u_int len; |
| 129 | int retry; |
| 130 | } |
| 131 | delaykey[] = { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 132 | { .str = env_get("bootdelaykey"), .retry = 1 }, |
| 133 | { .str = env_get("bootstopkey"), .retry = 0 }, |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | char presskey[MAX_DELAY_STOP_STR]; |
| 137 | u_int presskey_len = 0; |
| 138 | u_int presskey_max = 0; |
| 139 | u_int i; |
| 140 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 141 | # ifdef CONFIG_AUTOBOOT_DELAY_STR |
| 142 | if (delaykey[0].str == NULL) |
| 143 | delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR; |
| 144 | # endif |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 145 | # ifdef CONFIG_AUTOBOOT_STOP_STR |
Stefan Roese | 2d908fa | 2015-05-18 14:08:22 +0200 | [diff] [blame] | 146 | if (delaykey[1].str == NULL) |
| 147 | delaykey[1].str = CONFIG_AUTOBOOT_STOP_STR; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 148 | # endif |
| 149 | |
| 150 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i++) { |
| 151 | delaykey[i].len = delaykey[i].str == NULL ? |
| 152 | 0 : strlen(delaykey[i].str); |
| 153 | delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ? |
| 154 | MAX_DELAY_STOP_STR : delaykey[i].len; |
| 155 | |
| 156 | presskey_max = presskey_max > delaykey[i].len ? |
| 157 | presskey_max : delaykey[i].len; |
| 158 | |
| 159 | debug_bootkeys("%s key:<%s>\n", |
| 160 | delaykey[i].retry ? "delay" : "stop", |
| 161 | delaykey[i].str ? delaykey[i].str : "NULL"); |
| 162 | } |
| 163 | |
| 164 | /* In order to keep up with incoming data, check timeout only |
| 165 | * when catch up. |
| 166 | */ |
| 167 | do { |
| 168 | if (tstc()) { |
| 169 | if (presskey_len < presskey_max) { |
| 170 | presskey[presskey_len++] = getc(); |
| 171 | } else { |
| 172 | for (i = 0; i < presskey_max - 1; i++) |
| 173 | presskey[i] = presskey[i + 1]; |
| 174 | |
| 175 | presskey[i] = getc(); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i++) { |
| 180 | if (delaykey[i].len > 0 && |
| 181 | presskey_len >= delaykey[i].len && |
| 182 | memcmp(presskey + presskey_len - |
| 183 | delaykey[i].len, delaykey[i].str, |
| 184 | delaykey[i].len) == 0) { |
| 185 | debug_bootkeys("got %skey\n", |
| 186 | delaykey[i].retry ? "delay" : |
| 187 | "stop"); |
| 188 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 189 | /* don't retry auto boot */ |
| 190 | if (!delaykey[i].retry) |
| 191 | bootretry_dont_retry(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 192 | abort = 1; |
| 193 | } |
| 194 | } |
| 195 | } while (!abort && get_ticks() <= etime); |
| 196 | |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 197 | return abort; |
| 198 | } |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 199 | |
| 200 | /*************************************************************************** |
| 201 | * Watch for 'delay' seconds for autoboot stop or autoboot delay string. |
| 202 | * returns: 0 - no key string, allow autoboot 1 - got key string, abort |
| 203 | */ |
Simon Glass | e79e4b2 | 2019-07-20 20:51:19 -0600 | [diff] [blame] | 204 | static int abortboot_key_sequence(int bootdelay) |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 205 | { |
| 206 | int abort; |
| 207 | uint64_t etime = endtick(bootdelay); |
| 208 | |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 209 | # ifdef CONFIG_AUTOBOOT_PROMPT |
| 210 | /* |
| 211 | * CONFIG_AUTOBOOT_PROMPT includes the %d for all boards. |
| 212 | * To print the bootdelay value upon bootup. |
| 213 | */ |
| 214 | printf(CONFIG_AUTOBOOT_PROMPT, bootdelay); |
| 215 | # endif |
| 216 | |
Simon Glass | e8c7805 | 2019-07-20 20:51:16 -0600 | [diff] [blame] | 217 | if (IS_ENABLED(CONFIG_AUTOBOOT_ENCRYPTION)) |
| 218 | abort = passwd_abort_sha256(etime); |
| 219 | else |
| 220 | abort = passwd_abort_key(etime); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 221 | if (!abort) |
| 222 | debug_bootkeys("key timeout\n"); |
| 223 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 224 | return abort; |
| 225 | } |
| 226 | |
Simon Glass | 8fc31e2 | 2019-07-20 20:51:21 -0600 | [diff] [blame] | 227 | #ifdef CONFIG_USE_AUTOBOOT_MENUKEY |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 228 | static int menukey; |
| 229 | #endif |
| 230 | |
Simon Glass | e79e4b2 | 2019-07-20 20:51:19 -0600 | [diff] [blame] | 231 | static int abortboot_single_key(int bootdelay) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 232 | { |
| 233 | int abort = 0; |
| 234 | unsigned long ts; |
| 235 | |
Masahiro Yamada | 4632739 | 2016-06-27 16:23:04 +0900 | [diff] [blame] | 236 | printf("Hit any key to stop autoboot: %2d ", bootdelay); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 237 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 238 | /* |
| 239 | * Check if key already pressed |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 240 | */ |
Masahiro Yamada | 4632739 | 2016-06-27 16:23:04 +0900 | [diff] [blame] | 241 | if (tstc()) { /* we got a key press */ |
| 242 | (void) getc(); /* consume input */ |
| 243 | puts("\b\b\b 0"); |
| 244 | abort = 1; /* don't auto boot */ |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 245 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 246 | |
| 247 | while ((bootdelay > 0) && (!abort)) { |
| 248 | --bootdelay; |
| 249 | /* delay 1000 ms */ |
| 250 | ts = get_timer(0); |
| 251 | do { |
| 252 | if (tstc()) { /* we got a key press */ |
| 253 | abort = 1; /* don't auto boot */ |
| 254 | bootdelay = 0; /* no more delay */ |
Simon Glass | 8fc31e2 | 2019-07-20 20:51:21 -0600 | [diff] [blame] | 255 | # ifdef CONFIG_USE_AUTOBOOT_MENUKEY |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 256 | menukey = getc(); |
| 257 | # else |
| 258 | (void) getc(); /* consume input */ |
| 259 | # endif |
| 260 | break; |
| 261 | } |
| 262 | udelay(10000); |
| 263 | } while (!abort && get_timer(ts) < 1000); |
| 264 | |
| 265 | printf("\b\b\b%2d ", bootdelay); |
| 266 | } |
| 267 | |
| 268 | putc('\n'); |
| 269 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 270 | return abort; |
| 271 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 272 | |
| 273 | static int abortboot(int bootdelay) |
| 274 | { |
Masahiro Yamada | 4632739 | 2016-06-27 16:23:04 +0900 | [diff] [blame] | 275 | int abort = 0; |
Masahiro Yamada | 09b9d9e | 2016-06-27 16:23:03 +0900 | [diff] [blame] | 276 | |
Simon Glass | e79e4b2 | 2019-07-20 20:51:19 -0600 | [diff] [blame] | 277 | if (bootdelay >= 0) { |
| 278 | if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED)) |
| 279 | abort = abortboot_key_sequence(bootdelay); |
| 280 | else |
| 281 | abort = abortboot_single_key(bootdelay); |
| 282 | } |
Masahiro Yamada | 09b9d9e | 2016-06-27 16:23:03 +0900 | [diff] [blame] | 283 | |
Simon Glass | 42b4d14 | 2019-07-20 20:51:18 -0600 | [diff] [blame] | 284 | if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && abort) |
Masahiro Yamada | 09b9d9e | 2016-06-27 16:23:03 +0900 | [diff] [blame] | 285 | gd->flags &= ~GD_FLG_SILENT; |
Masahiro Yamada | 09b9d9e | 2016-06-27 16:23:03 +0900 | [diff] [blame] | 286 | |
| 287 | return abort; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 288 | } |
| 289 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 290 | static void process_fdt_options(const void *blob) |
| 291 | { |
Stefan Roese | 9f73690 | 2016-01-28 17:34:40 +0100 | [diff] [blame] | 292 | #if defined(CONFIG_OF_CONTROL) && defined(CONFIG_SYS_TEXT_BASE) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 293 | ulong addr; |
| 294 | |
| 295 | /* Add an env variable to point to a kernel payload, if available */ |
| 296 | addr = fdtdec_get_config_int(gd->fdt_blob, "kernel-offset", 0); |
| 297 | if (addr) |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 298 | env_set_addr("kernaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr)); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 299 | |
| 300 | /* Add an env variable to point to a root disk, if available */ |
| 301 | addr = fdtdec_get_config_int(gd->fdt_blob, "rootdisk-offset", 0); |
| 302 | if (addr) |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 303 | env_set_addr("rootaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr)); |
Stefan Roese | 9f73690 | 2016-01-28 17:34:40 +0100 | [diff] [blame] | 304 | #endif /* CONFIG_OF_CONTROL && CONFIG_SYS_TEXT_BASE */ |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 305 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 306 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 307 | const char *bootdelay_process(void) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 308 | { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 309 | char *s; |
| 310 | int bootdelay; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 311 | |
Lukasz Majewski | bc8c440 | 2018-05-02 16:10:53 +0200 | [diff] [blame] | 312 | bootcount_inc(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 313 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 314 | s = env_get("bootdelay"); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 315 | bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; |
| 316 | |
| 317 | #ifdef CONFIG_OF_CONTROL |
| 318 | bootdelay = fdtdec_get_config_int(gd->fdt_blob, "bootdelay", |
| 319 | bootdelay); |
| 320 | #endif |
| 321 | |
| 322 | debug("### main_loop entered: bootdelay=%d\n\n", bootdelay); |
| 323 | |
| 324 | #if defined(CONFIG_MENU_SHOW) |
| 325 | bootdelay = menu_show(bootdelay); |
| 326 | #endif |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 327 | bootretry_init_cmd_timeout(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 328 | |
| 329 | #ifdef CONFIG_POST |
| 330 | if (gd->flags & GD_FLG_POSTFAIL) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 331 | s = env_get("failbootcmd"); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 332 | } else |
| 333 | #endif /* CONFIG_POST */ |
Lukasz Majewski | bc8c440 | 2018-05-02 16:10:53 +0200 | [diff] [blame] | 334 | if (bootcount_error()) |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 335 | s = env_get("altbootcmd"); |
Lukasz Majewski | bc8c440 | 2018-05-02 16:10:53 +0200 | [diff] [blame] | 336 | else |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 337 | s = env_get("bootcmd"); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 338 | |
| 339 | process_fdt_options(gd->fdt_blob); |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 340 | stored_bootdelay = bootdelay; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 341 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 342 | return s; |
| 343 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 344 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 345 | void autoboot_command(const char *s) |
| 346 | { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 347 | debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>"); |
| 348 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 349 | if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 350 | #if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC) |
| 351 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
| 352 | #endif |
| 353 | |
| 354 | run_command_list(s, -1, 0); |
| 355 | |
| 356 | #if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC) |
| 357 | disable_ctrlc(prev); /* restore Control C checking */ |
| 358 | #endif |
| 359 | } |
| 360 | |
Simon Glass | 8fc31e2 | 2019-07-20 20:51:21 -0600 | [diff] [blame] | 361 | #ifdef CONFIG_USE_AUTOBOOT_MENUKEY |
| 362 | if (menukey == CONFIG_AUTOBOOT_MENUKEY) { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 363 | s = env_get("menucmd"); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 364 | if (s) |
| 365 | run_command_list(s, -1, 0); |
| 366 | } |
Simon Glass | 8fc31e2 | 2019-07-20 20:51:21 -0600 | [diff] [blame] | 367 | #endif /* CONFIG_USE_AUTOBOOT_MENUKEY */ |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 368 | } |