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