Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Jeroen Hofstee | 39e1230 | 2014-07-13 22:57:58 +0200 | [diff] [blame] | 9 | #include <autoboot.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 10 | #include <bootretry.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 11 | #include <cli.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 12 | #include <console.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 13 | #include <fdtdec.h> |
| 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> |
Gokul Sriram Palanisamy | e1b9106 | 2017-12-20 17:57:24 +0530 | [diff] [blame] | 17 | #include <asm/arch-qca-common/qca_common.h> |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Gitanjali Krishna | 9af31fe | 2019-06-10 14:50:33 -0700 | [diff] [blame] | 21 | extern int do_dumpqca_minimal_data(const char *offset); |
| 22 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 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 | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 31 | /* Stored value of bootdelay, used by autoboot_command() */ |
| 32 | static int stored_bootdelay; |
| 33 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 34 | extern void check_serial_console(void); |
| 35 | extern void check_for_enable_usb_passthrough(void); |
| 36 | extern void print_menu_selections(void); |
| 37 | extern void process_menu_selection(int); |
| 38 | #if defined(CONFIG_DEBUG_ENABLE) |
| 39 | extern int process_debug_package(void); |
| 40 | #endif |
| 41 | extern void check_factory_reset(void); |
| 42 | extern void usb_passthrough(void); |
| 43 | |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 44 | #if defined(CONFIG_AUTOBOOT_KEYED) |
| 45 | #if defined(CONFIG_AUTOBOOT_STOP_STR_SHA256) |
| 46 | |
| 47 | /* |
| 48 | * Use a "constant-length" time compare function for this |
| 49 | * hash compare: |
| 50 | * |
| 51 | * https://crackstation.net/hashing-security.htm |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 52 | */ |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 53 | static int slow_equals(u8 *a, u8 *b, int len) |
| 54 | { |
| 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 | |
| 64 | static int passwd_abort(uint64_t etime) |
| 65 | { |
| 66 | const char *sha_env_str = getenv("bootstopkeysha256"); |
| 67 | u8 sha_env[SHA256_SUM_LEN]; |
| 68 | u8 sha[SHA256_SUM_LEN]; |
| 69 | char presskey[MAX_DELAY_STOP_STR]; |
| 70 | const char *algo_name = "sha256"; |
| 71 | u_int presskey_len = 0; |
| 72 | int abort = 0; |
| 73 | int size; |
| 74 | int ret; |
| 75 | |
| 76 | if (sha_env_str == NULL) |
| 77 | sha_env_str = CONFIG_AUTOBOOT_STOP_STR_SHA256; |
| 78 | |
| 79 | /* |
| 80 | * Generate the binary value from the environment hash value |
| 81 | * so that we can compare this value with the computed hash |
| 82 | * from the user input |
| 83 | */ |
| 84 | ret = hash_parse_string(algo_name, sha_env_str, sha_env); |
| 85 | if (ret) { |
| 86 | printf("Hash %s not supported!\n", algo_name); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * We don't know how long the stop-string is, so we need to |
| 92 | * generate the sha256 hash upon each input character and |
| 93 | * compare the value with the one saved in the environment |
| 94 | */ |
| 95 | do { |
| 96 | if (tstc()) { |
| 97 | /* Check for input string overflow */ |
| 98 | if (presskey_len >= MAX_DELAY_STOP_STR) |
| 99 | return 0; |
| 100 | |
| 101 | presskey[presskey_len++] = getc(); |
| 102 | |
| 103 | /* Calculate sha256 upon each new char */ |
| 104 | hash_block(algo_name, (const void *)presskey, |
| 105 | presskey_len, sha, &size); |
| 106 | |
| 107 | /* And check if sha matches saved value in env */ |
| 108 | if (slow_equals(sha, sha_env, SHA256_SUM_LEN)) |
| 109 | abort = 1; |
| 110 | } |
| 111 | } while (!abort && get_ticks() <= etime); |
| 112 | |
| 113 | return abort; |
| 114 | } |
| 115 | #else |
| 116 | static int passwd_abort(uint64_t etime) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 117 | { |
| 118 | int abort = 0; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 119 | struct { |
| 120 | char *str; |
| 121 | u_int len; |
| 122 | int retry; |
| 123 | } |
| 124 | delaykey[] = { |
Jeroen Hofstee | 9e546ee | 2014-06-16 00:17:33 +0200 | [diff] [blame] | 125 | { .str = getenv("bootdelaykey"), .retry = 1 }, |
Jeroen Hofstee | 9e546ee | 2014-06-16 00:17:33 +0200 | [diff] [blame] | 126 | { .str = getenv("bootstopkey"), .retry = 0 }, |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | char presskey[MAX_DELAY_STOP_STR]; |
| 130 | u_int presskey_len = 0; |
| 131 | u_int presskey_max = 0; |
| 132 | u_int i; |
| 133 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 134 | # ifdef CONFIG_AUTOBOOT_DELAY_STR |
| 135 | if (delaykey[0].str == NULL) |
| 136 | delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR; |
| 137 | # endif |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 138 | # ifdef CONFIG_AUTOBOOT_STOP_STR |
Stefan Roese | 2d908fa | 2015-05-18 14:08:22 +0200 | [diff] [blame] | 139 | if (delaykey[1].str == NULL) |
| 140 | delaykey[1].str = CONFIG_AUTOBOOT_STOP_STR; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 141 | # endif |
| 142 | |
| 143 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i++) { |
| 144 | delaykey[i].len = delaykey[i].str == NULL ? |
| 145 | 0 : strlen(delaykey[i].str); |
| 146 | delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ? |
| 147 | MAX_DELAY_STOP_STR : delaykey[i].len; |
| 148 | |
| 149 | presskey_max = presskey_max > delaykey[i].len ? |
| 150 | presskey_max : delaykey[i].len; |
| 151 | |
| 152 | debug_bootkeys("%s key:<%s>\n", |
| 153 | delaykey[i].retry ? "delay" : "stop", |
| 154 | delaykey[i].str ? delaykey[i].str : "NULL"); |
| 155 | } |
| 156 | |
| 157 | /* In order to keep up with incoming data, check timeout only |
| 158 | * when catch up. |
| 159 | */ |
| 160 | do { |
| 161 | if (tstc()) { |
| 162 | if (presskey_len < presskey_max) { |
| 163 | presskey[presskey_len++] = getc(); |
| 164 | } else { |
| 165 | for (i = 0; i < presskey_max - 1; i++) |
| 166 | presskey[i] = presskey[i + 1]; |
| 167 | |
| 168 | presskey[i] = getc(); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i++) { |
| 173 | if (delaykey[i].len > 0 && |
| 174 | presskey_len >= delaykey[i].len && |
| 175 | memcmp(presskey + presskey_len - |
| 176 | delaykey[i].len, delaykey[i].str, |
| 177 | delaykey[i].len) == 0) { |
| 178 | debug_bootkeys("got %skey\n", |
| 179 | delaykey[i].retry ? "delay" : |
| 180 | "stop"); |
| 181 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 182 | /* don't retry auto boot */ |
| 183 | if (!delaykey[i].retry) |
| 184 | bootretry_dont_retry(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 185 | abort = 1; |
| 186 | } |
| 187 | } |
| 188 | } while (!abort && get_ticks() <= etime); |
| 189 | |
Stefan Roese | 8f0b1e2 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 190 | return abort; |
| 191 | } |
| 192 | #endif |
| 193 | |
| 194 | /*************************************************************************** |
| 195 | * Watch for 'delay' seconds for autoboot stop or autoboot delay string. |
| 196 | * returns: 0 - no key string, allow autoboot 1 - got key string, abort |
| 197 | */ |
| 198 | static int abortboot_keyed(int bootdelay) |
| 199 | { |
| 200 | int abort; |
| 201 | uint64_t etime = endtick(bootdelay); |
| 202 | |
| 203 | #ifndef CONFIG_ZERO_BOOTDELAY_CHECK |
| 204 | if (bootdelay == 0) |
| 205 | return 0; |
| 206 | #endif |
| 207 | |
| 208 | # ifdef CONFIG_AUTOBOOT_PROMPT |
| 209 | /* |
| 210 | * CONFIG_AUTOBOOT_PROMPT includes the %d for all boards. |
| 211 | * To print the bootdelay value upon bootup. |
| 212 | */ |
| 213 | printf(CONFIG_AUTOBOOT_PROMPT, bootdelay); |
| 214 | # endif |
| 215 | |
| 216 | abort = passwd_abort(etime); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 217 | if (!abort) |
| 218 | debug_bootkeys("key timeout\n"); |
| 219 | |
| 220 | #ifdef CONFIG_SILENT_CONSOLE |
| 221 | if (abort) |
| 222 | gd->flags &= ~GD_FLG_SILENT; |
| 223 | #endif |
| 224 | |
| 225 | return abort; |
| 226 | } |
| 227 | |
| 228 | # else /* !defined(CONFIG_AUTOBOOT_KEYED) */ |
| 229 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 230 | static int menukey = 0; |
| 231 | |
| 232 | /* Check if we've got CPConfig in the environment. If not, add it and save the environment */ |
| 233 | void fixup_environment(void) |
| 234 | { |
| 235 | char * s = getenv("CPConfig"); |
| 236 | if (s == NULL) { |
| 237 | printf("Found unsaved environment...\n"); |
| 238 | setenv("CPConfig", "yes"); |
| 239 | saveenv(); |
| 240 | } |
| 241 | } |
| 242 | int validateUserSelection(unsigned char c){ |
| 243 | char valid_min = '1'; |
| 244 | char valid_max = '9' ; |
| 245 | if (c >= valid_min && c <= valid_max){ |
| 246 | return 0; |
| 247 | } |
| 248 | return 1; |
| 249 | } |
| 250 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 251 | |
| 252 | static int abortboot_normal(int bootdelay) |
| 253 | { |
| 254 | int abort = 0; |
| 255 | unsigned long ts; |
| 256 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 257 | fixup_environment(); |
| 258 | |
| 259 | #if defined(CONFIG_DEBUG_ENABLE) |
| 260 | if (process_debug_package() == 0) { |
| 261 | printf("Successfully validated the debug enable package.\n"); |
| 262 | } else { |
| 263 | printf("Debug package not found or otherwise invalid\n"); |
| 264 | } |
| 265 | #endif |
| 266 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 267 | #ifdef CONFIG_MENUPROMPT |
| 268 | printf(CONFIG_MENUPROMPT); |
| 269 | #else |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 270 | /* check_serial_console(); */ |
| 271 | print_menu_selections(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 272 | if (bootdelay >= 0) |
| 273 | printf("Hit any key to stop autoboot: %2d ", bootdelay); |
| 274 | #endif |
| 275 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 276 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 277 | #if defined CONFIG_ZERO_BOOTDELAY_CHECK |
| 278 | /* |
| 279 | * Check if key already pressed |
| 280 | * Don't check if bootdelay < 0 |
| 281 | */ |
| 282 | if (bootdelay >= 0) { |
| 283 | if (tstc()) { /* we got a key press */ |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 284 | menukey = getc(); /* consume input */ |
| 285 | if (!validateUserSelection(menukey)){ |
| 286 | puts ("\b\b\b 0"); |
| 287 | abort = 1; /* don't auto boot */ |
| 288 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | #endif |
| 292 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 293 | check_factory_reset(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 294 | while ((bootdelay > 0) && (!abort)) { |
| 295 | --bootdelay; |
| 296 | /* delay 1000 ms */ |
| 297 | ts = get_timer(0); |
| 298 | do { |
| 299 | if (tstc()) { /* we got a key press */ |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 300 | menukey = getc(); |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 301 | printf("You pressed %c\n", (char) menukey); |
| 302 | if (!validateUserSelection((char)menukey)){ |
| 303 | abort = 1; /* don't auto boot */ |
| 304 | bootdelay = 0; /* no more delay */ |
| 305 | break; |
| 306 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 307 | } |
| 308 | udelay(10000); |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 309 | check_factory_reset(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 310 | } while (!abort && get_timer(ts) < 1000); |
| 311 | |
| 312 | printf("\b\b\b%2d ", bootdelay); |
| 313 | } |
| 314 | |
| 315 | putc('\n'); |
| 316 | |
| 317 | #ifdef CONFIG_SILENT_CONSOLE |
| 318 | if (abort) |
| 319 | gd->flags &= ~GD_FLG_SILENT; |
| 320 | #endif |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 321 | if (abort) |
| 322 | process_menu_selection(menukey); |
| 323 | else |
| 324 | process_menu_selection('3'); |
| 325 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 326 | return abort; |
| 327 | } |
| 328 | # endif /* CONFIG_AUTOBOOT_KEYED */ |
| 329 | |
| 330 | static int abortboot(int bootdelay) |
| 331 | { |
| 332 | #ifdef CONFIG_AUTOBOOT_KEYED |
| 333 | return abortboot_keyed(bootdelay); |
| 334 | #else |
| 335 | return abortboot_normal(bootdelay); |
| 336 | #endif |
| 337 | } |
| 338 | |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 339 | static void process_fdt_options(const void *blob) |
| 340 | { |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 341 | #if defined(CONFIG_OF_CONTROL) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 342 | ulong addr; |
| 343 | |
| 344 | /* Add an env variable to point to a kernel payload, if available */ |
| 345 | addr = fdtdec_get_config_int(gd->fdt_blob, "kernel-offset", 0); |
| 346 | if (addr) |
| 347 | setenv_addr("kernaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr)); |
| 348 | |
| 349 | /* Add an env variable to point to a root disk, if available */ |
| 350 | addr = fdtdec_get_config_int(gd->fdt_blob, "rootdisk-offset", 0); |
| 351 | if (addr) |
| 352 | setenv_addr("rootaddr", (void *)(CONFIG_SYS_TEXT_BASE + addr)); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 353 | #endif /* CONFIG_OF_CONTROL */ |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 354 | } |
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 | const char *bootdelay_process(void) |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 357 | { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 358 | char *s; |
| 359 | int bootdelay; |
| 360 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 361 | unsigned long bootcount = 0; |
| 362 | unsigned long bootlimit = 0; |
| 363 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
| 364 | |
| 365 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 366 | bootcount = bootcount_load(); |
| 367 | bootcount++; |
| 368 | bootcount_store(bootcount); |
| 369 | setenv_ulong("bootcount", bootcount); |
| 370 | bootlimit = getenv_ulong("bootlimit", 10, 0); |
| 371 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
| 372 | |
| 373 | s = getenv("bootdelay"); |
| 374 | bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY; |
| 375 | |
| 376 | #ifdef CONFIG_OF_CONTROL |
| 377 | bootdelay = fdtdec_get_config_int(gd->fdt_blob, "bootdelay", |
| 378 | bootdelay); |
| 379 | #endif |
| 380 | |
| 381 | debug("### main_loop entered: bootdelay=%d\n\n", bootdelay); |
| 382 | |
| 383 | #if defined(CONFIG_MENU_SHOW) |
| 384 | bootdelay = menu_show(bootdelay); |
| 385 | #endif |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 386 | bootretry_init_cmd_timeout(); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 387 | |
| 388 | #ifdef CONFIG_POST |
| 389 | if (gd->flags & GD_FLG_POSTFAIL) { |
| 390 | s = getenv("failbootcmd"); |
| 391 | } else |
| 392 | #endif /* CONFIG_POST */ |
| 393 | #ifdef CONFIG_BOOTCOUNT_LIMIT |
| 394 | if (bootlimit && (bootcount > bootlimit)) { |
| 395 | printf("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n", |
| 396 | (unsigned)bootlimit); |
| 397 | s = getenv("altbootcmd"); |
| 398 | } else |
| 399 | #endif /* CONFIG_BOOTCOUNT_LIMIT */ |
| 400 | s = getenv("bootcmd"); |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 401 | |
| 402 | process_fdt_options(gd->fdt_blob); |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 403 | stored_bootdelay = bootdelay; |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 404 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 405 | return s; |
| 406 | } |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 407 | |
Gokul Sriram Palanisamy | e1b9106 | 2017-12-20 17:57:24 +0530 | [diff] [blame] | 408 | __weak int apps_iscrashed(void) |
| 409 | { |
| 410 | return 0; |
| 411 | } |
| 412 | |
speriaka | 98e4409 | 2019-08-27 11:27:13 +0530 | [diff] [blame] | 413 | __weak int apps_iscrashed_crashdump_disabled(void) |
| 414 | { |
| 415 | return 0; |
| 416 | } |
| 417 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 418 | __weak void check_reset_button(void) |
| 419 | { |
| 420 | printf("This is where the reset button check would be running, if it were complete\n"); |
| 421 | return; |
| 422 | } |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 423 | void autoboot_command(const char *s) |
| 424 | { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 425 | debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>"); |
| 426 | |
Kyle Swenson | 3c6e30f | 2021-03-29 09:52:45 -0600 | [diff] [blame] | 427 | char * skip = NULL; |
| 428 | skip = getenv("skip_usb_passthrough"); |
| 429 | if (!(skip != NULL && strcmp(skip, "yes") == 0)) { |
| 430 | printf("Doing usbpassthrough, since skip_usb_passthrough isn't set to yes\n"); |
| 431 | usb_passthrough(); |
| 432 | } |
| 433 | |
Gokul Sriram Palanisamy | e1b9106 | 2017-12-20 17:57:24 +0530 | [diff] [blame] | 434 | #ifdef CONFIG_QCA_APPSBL_DLOAD |
| 435 | /* |
| 436 | * If kernel has crashed in previous boot, |
| 437 | * jump to crash dump collection. |
| 438 | */ |
| 439 | if (apps_iscrashed()) { |
| 440 | printf("Crashdump magic found, initializing dump activity..\n"); |
Gokul Sriram Palanisamy | ebfe553 | 2018-01-29 13:18:16 +0530 | [diff] [blame] | 441 | s = getenv("dump_to_flash"); |
Venkat Raju Sana | d0efe15 | 2019-07-22 20:31:38 -0700 | [diff] [blame] | 442 | if (!s) { |
Venkat Raju Sana | 2e7684f | 2019-03-11 19:29:46 -0700 | [diff] [blame] | 443 | s = getenv("dump_minimal"); |
Venkat Raju Sana | d0efe15 | 2019-07-22 20:31:38 -0700 | [diff] [blame] | 444 | if (s) { |
| 445 | if (strncmp(s, "1", sizeof("1"))) { |
| 446 | printf("\nError: Invalid variable dump_minimal \n"); |
| 447 | reset_board(); |
| 448 | } |
| 449 | } |
| 450 | } |
Sandhya | 0b984e9 | 2019-06-26 10:24:59 +0530 | [diff] [blame] | 451 | if (s) { |
Venkat Raju Sana | d0efe15 | 2019-07-22 20:31:38 -0700 | [diff] [blame] | 452 | do_dumpqca_minimal_data(s); |
Antony Arun T | 6cc115d | 2019-07-19 16:13:50 +0530 | [diff] [blame] | 453 | reset_board(); |
Sandhya | 0b984e9 | 2019-06-26 10:24:59 +0530 | [diff] [blame] | 454 | } |
Gokul Sriram Palanisamy | ebfe553 | 2018-01-29 13:18:16 +0530 | [diff] [blame] | 455 | else |
Venkat Raju Sana | 2e7684f | 2019-03-11 19:29:46 -0700 | [diff] [blame] | 456 | dump_func(FULL_DUMP); |
Gokul Sriram Palanisamy | e1b9106 | 2017-12-20 17:57:24 +0530 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | #endif |
| 460 | |
speriaka | 98e4409 | 2019-08-27 11:27:13 +0530 | [diff] [blame] | 461 | if (apps_iscrashed_crashdump_disabled()) { |
| 462 | printf("Crashdump disabled, resetting the board..\n"); |
| 463 | reset_board(); |
| 464 | } |
| 465 | |
Simon Glass | affb215 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 466 | if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) { |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 467 | #if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC) |
| 468 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
| 469 | #endif |
| 470 | |
| 471 | run_command_list(s, -1, 0); |
| 472 | |
| 473 | #if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC) |
| 474 | disable_ctrlc(prev); /* restore Control C checking */ |
| 475 | #endif |
| 476 | } |
| 477 | |
| 478 | #ifdef CONFIG_MENUKEY |
| 479 | if (menukey == CONFIG_MENUKEY) { |
| 480 | s = getenv("menucmd"); |
| 481 | if (s) |
| 482 | run_command_list(s, -1, 0); |
| 483 | } |
| 484 | #endif /* CONFIG_MENUKEY */ |
Gokul Sriram Palanisamy | a23d322 | 2017-12-21 11:50:24 +0530 | [diff] [blame] | 485 | |
| 486 | #ifdef CONFIG_IPQ_ETH_INIT_DEFER |
| 487 | puts("\nNet: "); |
| 488 | eth_initialize(); |
| 489 | #endif |
Simon Glass | 66ded17 | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 490 | } |