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