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