config_common:
@ >include/config.h
@$(call include_add,soc/soc_list.h)
- @$(call define_add,CONFIG_MAX_BUTTON_PRESSING,10)
- @$(call define_add,CONFIG_DELAY_TO_AUTORUN_HTTPD,3)
- @$(call define_add,CONFIG_DELAY_TO_AUTORUN_CONSOLE,5)
- @$(call define_add,CONFIG_DELAY_TO_AUTORUN_NETCONSOLE,7)
ar933x_common: unconfig config_common
@$(call define_add,CFG_AG7240_NMACS,2)
#include <common.h>
#include <command.h>
#include <environment.h>
-#include <upg_scripts.h>
+#include <env_scripts.h>
#include <linux/stddef.h>
#include <malloc.h>
#include <tinf.h>
#endif
#if defined(CONFIG_ENV_UPG_SCRIPTS_FW)
CONFIG_ENV_UPG_SCRIPTS_FW
+#endif
+#if defined(CONFIG_ENV_BTN_RECOVERY_SCRIPT)
+ CONFIG_ENV_BTN_RECOVERY_SCRIPT
#endif
"\0"
};
#undef __ASSEMBLY__
#include <environment.h>
-#include <upg_scripts.h>
+#include <env_scripts.h>
/*
* Handle HOSTS that have prepended
#endif
#if defined(CONFIG_ENV_UPG_SCRIPTS_FW)
CONFIG_ENV_UPG_SCRIPTS_FW
+#endif
+#if defined(CONFIG_ENV_BTN_RECOVERY_SCRIPT)
+ CONFIG_ENV_BTN_RECOVERY_SCRIPT
#endif
"\0"
}
DECLARE_GLOBAL_DATA_PTR;
#endif
-extern void all_led_on(void);
-extern void all_led_off(void);
-extern int NetLoopHttpd(void);
-
-#define MAX_DELAY_STOP_STR 32
-
static char *delete_char(char *buffer, char *p, int *colp, int *np, int plen);
static int parse_line(char *, char *[]);
-#if defined(CONFIG_BOOTDELAY) &&\
- (CONFIG_BOOTDELAY >= 0)
-static int abortboot(int);
-#endif
-
char console_buffer[CFG_CBSIZE]; /* console I/O buffer */
static char erase_seq[] = "\b \b"; /* erase sequence */
static char tab_seq[] = " "; /* used to expand TABs */
}
#endif /* CONFIG_BOOTDELAY && CONFIG_BOOTDELAY >= 0 */
+/*
+ * =========
+ * Main loop
+ * =========
+ */
void main_loop(void)
{
- int counter = 0;
+ char *bootcmd;
+
+#if defined(CONFIG_BTN_RECOVERY_SCRIPT)
+ int stop_boot;
+ char *c;
+#endif
#ifndef CFG_HUSH_PARSER
static char lastcommand[CFG_CBSIZE] = { 0, };
u_boot_hush_start();
#endif
-#if defined(CONFIG_BOOTDELAY) &&\
- (CONFIG_BOOTDELAY >= 0)
- /* Get boot delay (seconds) */
- s = getenv("bootdelay");
- bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
-
/* Get boot command */
- s = getenv("bootcmd");
-
- #if !defined(CONFIG_BOOTCOMMAND)
- #error "CONFIG_BOOTCOMMAND not defined!"
- #endif
+ bootcmd = getenv("bootcmd");
- if (!s)
+#if defined(CONFIG_BOOTCOMMAND)
+ if (!bootcmd)
setenv("bootcmd", CONFIG_BOOTCOMMAND);
- s = getenv("bootcmd");
+ bootcmd = getenv("bootcmd");
+#endif
- /*
- * Are we going to run web failsafe mode,
- * U-Boot console, U-Boot netconsole
- * or just boot command?
- */
+/* Recovery mode before normal boot */
+#if defined(CONFIG_BTN_RECOVERY_SCRIPT)
if (reset_button_status()) {
- #if defined(CONFIG_SILENT_CONSOLE)
+ #if defined(CONFIG_SILENT_CONSOLE)
if (gd->flags & GD_FLG_SILENT) {
/* Restore serial console */
console_assign(stdout, "serial");
/* Enable normal console output */
gd->flags &= ~(GD_FLG_SILENT);
- #endif
- /* Wait 0,5s */
- milisecdelay(500);
-
- printf("Press reset button for at least:\n"
- "- %d sec. to run web failsafe mode\n"
- "- %d sec. to run U-Boot console\n"
- "- %d sec. to run U-Boot netconsole\n\n",
- CONFIG_DELAY_TO_AUTORUN_HTTPD,
- CONFIG_DELAY_TO_AUTORUN_CONSOLE,
- CONFIG_DELAY_TO_AUTORUN_NETCONSOLE);
-
- printf("Reset button is pressed for: %2d ", counter);
-
- while (reset_button_status()) {
- /* LED ON and wait 0,15s */
- all_led_on();
- milisecdelay(150);
+ #endif
- /* LED OFF and wait 0,85s */
- all_led_off();
- milisecdelay(850);
+ run_command("run recovery", 0);
- counter++;
+ /* Should we stop booting after recovery mode? */
+ c = getenv("stop_boot");
+ stop_boot = c ? (int)simple_strtol(c, NULL, 10) : 0;
- /* How long the button is pressed? */
- printf("\b\b\b%2d ", counter);
-
- if (!reset_button_status())
- break;
-
- if (counter >= CONFIG_MAX_BUTTON_PRESSING)
- break;
- }
-
- all_led_off();
-
- if (counter > 0) {
- /* Run web failsafe mode */
- if (counter >= CONFIG_DELAY_TO_AUTORUN_HTTPD &&
- counter < CONFIG_DELAY_TO_AUTORUN_CONSOLE) {
- printf("\n\nButton was pressed for %d sec...\n"
- "HTTP server is starting for firmware update...\n\n",
- counter);
-
- NetLoopHttpd();
- bootdelay = -1;
- } else if (counter >= CONFIG_DELAY_TO_AUTORUN_CONSOLE &&
- counter < CONFIG_DELAY_TO_AUTORUN_NETCONSOLE) {
- printf("\n\nButton was pressed for %d sec...\n"
- "Starting U-Boot console...\n\n",
- counter);
-
- bootdelay = -1;
- } else if (counter >= CONFIG_DELAY_TO_AUTORUN_NETCONSOLE) {
- printf("\n\nButton was pressed for %d sec...\n"
- "Starting U-Boot netconsole...\n\n",
- counter);
-
- bootdelay = -1;
- run_command("startnc", 0);
- } else {
- printf("\n\n## Error: button wasn't pressed long enough!\n"
- "Continuing normal boot...\n\n");
- }
+ if (stop_boot)
+ bootcmd = NULL;
+ }
+#endif /* CONFIG_RECOVERY_MODE */
- } else {
- printf("\n\n## Error: button wasn't pressed long enough!\n"
- "Continuing normal boot...\n\n");
- }
+#if defined(CONFIG_BOOTDELAY) &&\
+ (CONFIG_BOOTDELAY >= 0)
+ /* Get boot delay (seconds) */
+ s = getenv("bootdelay");
+ bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
+ if (bootdelay >= 0 && bootcmd && !abortboot(bootdelay)) {
+ /* Try to boot */
+ #ifndef CFG_HUSH_PARSER
+ run_command(bootcmd, 0);
+ #else
+ parse_string_outer(bootcmd, FLAG_PARSE_SEMICOLON |
+ FLAG_EXIT_FROM_LOOP);
+ #endif
}
-
- if (bootdelay >= 0 && s && !abortboot(bootdelay)) {
+#else
+ if (bootcmd) {
/* Try to boot */
#ifndef CFG_HUSH_PARSER
- run_command(s, 0);
+ run_command(bootcmd, 0);
#else
- parse_string_outer(s, FLAG_PARSE_SEMICOLON |
- FLAG_EXIT_FROM_LOOP);
+ parse_string_outer(bootcmd, FLAG_PARSE_SEMICOLON |
+ FLAG_EXIT_FROM_LOOP);
#endif
- /* Something went wrong! */
- printf("\n## Error: failed to execute 'bootcmd'!\n"
- "HTTP server is starting for firmware update...\n\n");
-
- NetLoopHttpd();
}
#endif /* CONFIG_BOOTDELAY && CONFIG_BOOTDELAY >= 0 */
if (argc < 2) {
print_cmd_help(cmdtp);
- return(1);
+ return 1;
}
for (i=1; i<argc; ++i) {
#define CONFIG_UPG_SCRIPTS_UBOOT
#define CONFIG_UPG_SCRIPTS_FW
+/* Recovery script with button */
+#define CONFIG_BTN_RECOVERY_SCRIPT
+
/* For HTTP based recovery */
/* TODO: move it to httpd related header */
#define WEBFAILSAFE_PROGRESS_START 0
--- /dev/null
+/*
+ * Upgrade and recovery helper environment scripts
+ *
+ * Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _ENV_SCRIPTS_H_
+#define _ENV_SCRIPTS_H_
+
+/*
+ * U-Boot upgrade
+ */
+#if defined(CONFIG_UPG_SCRIPTS_UBOOT) &&\
+ defined(CONFIG_MAX_UBOOT_SIZE_HEX)
+
+ /* Backup size: use image limit size by default */
+ #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX)
+ #define CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX \
+ CONFIG_MAX_UBOOT_SIZE_HEX
+ #endif
+
+ /* Target address: use CFG_FLASH_BASE by default */
+ #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX)
+ #define CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX \
+ CFG_FLASH_BASE
+ #endif
+
+ /* Limit size: use image limit size by default */
+ #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
+ #define CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX \
+ CONFIG_MAX_UBOOT_SIZE_HEX
+ #endif
+
+ /* Small check */
+ #if (CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX < \
+ CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
+ #error "U-Boot backup size must be >= U-Boot image size"
+ #endif
+
+ /* Include backup stage only if needed */
+ #if (CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX == \
+ CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
+ #define CONFIG_ENV_UPG_SCRIPTS_UBOOT \
+ "uboot_name=u-boot.bin\0" \
+ "uboot_addr=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX) "\0" \
+ "uboot_size=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX) "\0" \
+ "uboot_upg=" \
+ "if ping $serverip; then " \
+ "tftp $loadaddr $uboot_name && " \
+ "if itest.l $filesize <= $uboot_size; then " \
+ "erase $uboot_addr +$uboot_size && " \
+ "cp.b $loadaddr $uboot_addr $uboot_size && " \
+ "echo DONE! U-Boot upgraded!; " \
+ "else " \
+ "echo ERROR! File is too big!; " \
+ "fi; " \
+ "else " \
+ "echo ERROR! $serverip is not reachable!; " \
+ "fi\0"
+ #else
+ #define CONFIG_ENV_UPG_SCRIPTS_UBOOT \
+ "uboot_name=u-boot.bin\0" \
+ "uboot_addr=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX) "\0" \
+ "uboot_size=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX) "\0" \
+ "uboot_bckp=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX) "\0" \
+ "uboot_upg=" \
+ "if ping $serverip; then " \
+ "mw.b $loadaddr 0xFF $uboot_bckp && " \
+ "cp.b $uboot_addr $loadaddr $uboot_bckp && " \
+ "tftp $loadaddr $uboot_name && " \
+ "if itest.l $filesize <= $uboot_size; then " \
+ "erase $uboot_addr +$uboot_bckp && " \
+ "cp.b $loadaddr $uboot_addr $uboot_bckp && " \
+ "echo DONE! U-Boot upgraded!; " \
+ "else " \
+ "echo ERROR! File is too big!; " \
+ "fi; " \
+ "else " \
+ "echo ERROR! $serverip is not reachable!; " \
+ "fi\0"
+ #endif
+
+#endif /* CONFIG_UPG_SCRIPTS_UBOOT && CONFIG_MAX_UBOOT_SIZE_HEX */
+
+/*
+ * Firmware upgrade
+ */
+#if defined(CONFIG_UPG_SCRIPTS_FW)
+
+ /* Target address: use CFG_LOAD_ADDR by default */
+ #if !defined(CONFIG_UPG_SCRIPTS_FW_ADDR_HEX)
+ #define CONFIG_UPG_SCRIPTS_FW_ADDR_HEX \
+ CFG_LOAD_ADDR
+ #endif
+
+ #define CONFIG_ENV_UPG_SCRIPTS_FW \
+ "fw_addr=" MK_STR(CONFIG_UPG_SCRIPTS_FW_ADDR_HEX) "\0" \
+ "fw_upg=" \
+ "if ping $serverip; then " \
+ "tftp $loadaddr $bootfile && " \
+ "erase $fw_addr +$filesize && " \
+ "cp.b $loadaddr $fw_addr $filesize && " \
+ "echo DONE! Firmware upgraded!; " \
+ "else " \
+ "echo ERROR! $serverip is not reachable!; " \
+ "fi\0"
+
+#endif /* CONFIG_UPG_SCRIPTS_FW */
+
+/*
+ * Recovery
+ */
+#if defined(CONFIG_BTN_RECOVERY_SCRIPT)
+
+ #if !defined(CONFIG_CMD_BUTTON) ||\
+ !defined(CONFIG_CMD_SLEEP) ||\
+ !defined(CONFIG_CMD_LED) ||\
+ !defined(CONFIG_CMD_SETEXPR)
+ #error "Commands setexpr, sleep, button and led{on, off} are required for recovery"
+ #endif
+
+ #if !defined(CONFIG_GPIO_RESET_BTN)
+ #error "Reset button definition is required for recovery"
+ #endif
+
+ #define CONFIG_ENV_BTN_RECOVERY_SCRIPT \
+ "recovery=" \
+ "if button; then " \
+ "sleep 600;" \
+ "setenv cnt 0;" \
+ "echo Keep button pressed for at least:;" \
+ "echo - 3s for web based recovery;" \
+ "echo - 5s for U-Boot console;" \
+ "echo - 7s for network console;" \
+ "echo;" \
+ "while button; do " \
+ "ledon;" \
+ "sleep 300;" \
+ "echo . \'\\\\c\';" \
+ "sleep 300;" \
+ "ledoff;" \
+ "sleep 600;" \
+ "setexpr cnt $cnt + 1;" \
+ "done;" \
+ "echo $cnt seconds;" \
+ "echo;" \
+ "if test $cnt -ge 7; then " \
+ "echo Starting network console...;" \
+ "setenv stop_boot 1;" \
+ "echo;" \
+ "startnc;" \
+ "elif test $cnt -ge 5; then " \
+ "echo Starting U-Boot console...;" \
+ "setenv stop_boot 1;" \
+ "echo;" \
+ "elif test $cnt -ge 3; then " \
+ "echo HTTP server is starting for firmware update...;" \
+ "setenv stop_boot 1;" \
+ "echo;" \
+ "httpd;" \
+ "elif test $cnt -lt 3; then " \
+ "echo \\#\\# Error: button was not pressed long enough!;" \
+ "echo Continuing normal boot...;" \
+ "echo;" \
+ "fi;"\
+ "fi\0"
+
+#endif /* CONFIG_BTN_RECOVERY_SCRIPT */
+
+#endif /* _ENV_SCRIPTS_H_ */
+++ /dev/null
-/*
- * Upgrade helper environment scripts
- *
- * Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
- *
- * SPDX-License-Identifier: GPL-2.0
- */
-
-#ifndef _UPG_SCRIPTS_H_
-#define _UPG_SCRIPTS_H_
-
-/*
- * U-Boot upgrade
- */
-#if defined(CONFIG_UPG_SCRIPTS_UBOOT) &&\
- defined(CONFIG_MAX_UBOOT_SIZE_HEX)
-
- /* Backup size: use image limit size by default */
- #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX)
- #define CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX \
- CONFIG_MAX_UBOOT_SIZE_HEX
- #endif
-
- /* Target address: use CFG_FLASH_BASE by default */
- #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX)
- #define CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX \
- CFG_FLASH_BASE
- #endif
-
- /* Limit size: use image limit size by default */
- #if !defined(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
- #define CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX \
- CONFIG_MAX_UBOOT_SIZE_HEX
- #endif
-
- /* Small check */
- #if (CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX < \
- CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
- #error "U-Boot backup size must be >= U-Boot image size"
- #endif
-
- /* Include backup stage only if needed */
- #if (CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX == \
- CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX)
- #define CONFIG_ENV_UPG_SCRIPTS_UBOOT \
- "uboot_name=u-boot.bin\0" \
- "uboot_addr=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX) "\0" \
- "uboot_size=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX) "\0" \
- "uboot_upg=" \
- "if ping $serverip; then " \
- "tftp $loadaddr $uboot_name && " \
- "if itest.l $filesize <= $uboot_size; then " \
- "erase $uboot_addr +$uboot_size && " \
- "cp.b $loadaddr $uboot_addr $uboot_size && " \
- "echo DONE! U-Boot upgraded!; " \
- "else " \
- "echo ERROR! File is too big!; " \
- "fi; " \
- "else " \
- "echo ERROR! $serverip is not reachable!; " \
- "fi\0"
- #else
- #define CONFIG_ENV_UPG_SCRIPTS_UBOOT \
- "uboot_name=u-boot.bin\0" \
- "uboot_addr=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_ADDR_HEX) "\0" \
- "uboot_size=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_HEX) "\0" \
- "uboot_bckp=" MK_STR(CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX) "\0" \
- "uboot_upg=" \
- "if ping $serverip; then " \
- "mw.b $loadaddr 0xFF $uboot_bckp && " \
- "cp.b $uboot_addr $loadaddr $uboot_bckp && " \
- "tftp $loadaddr $uboot_name && " \
- "if itest.l $filesize <= $uboot_size; then " \
- "erase $uboot_addr +$uboot_bckp && " \
- "cp.b $loadaddr $uboot_addr $uboot_bckp && " \
- "echo DONE! U-Boot upgraded!; " \
- "else " \
- "echo ERROR! File is too big!; " \
- "fi; " \
- "else " \
- "echo ERROR! $serverip is not reachable!; " \
- "fi\0"
- #endif
-
-#endif /* CONFIG_UPG_SCRIPTS_UBOOT && CONFIG_MAX_UBOOT_SIZE_HEX */
-
-/*
- * Firmware upgrade
- */
-#if defined(CONFIG_UPG_SCRIPTS_FW)
-
- /* Target address: use CFG_LOAD_ADDR by default */
- #if !defined(CONFIG_UPG_SCRIPTS_FW_ADDR_HEX)
- #define CONFIG_UPG_SCRIPTS_FW_ADDR_HEX \
- CFG_LOAD_ADDR
- #endif
-
- #define CONFIG_ENV_UPG_SCRIPTS_FW \
- "fw_addr=" MK_STR(CONFIG_UPG_SCRIPTS_FW_ADDR_HEX) "\0" \
- "fw_upg=" \
- "if ping $serverip; then " \
- "tftp $loadaddr $bootfile && " \
- "erase $fw_addr +$filesize && " \
- "cp.b $loadaddr $fw_addr $filesize && " \
- "echo DONE! Firmware upgraded!; " \
- "else " \
- "echo ERROR! $serverip is not reachable!; " \
- "fi\0"
-
-#endif /* CONFIG_UPG_SCRIPTS_FW */
-
-#endif /* _UPG_SCRIPTS_H_ */