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