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