From eaf95c13d52243439ea43327695b7612d2c39780 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Thu, 1 Sep 2016 01:36:59 +0200 Subject: [PATCH] Make web based recovery optional, as configurable httpd command --- u-boot/common/cmd_net.c | 2 ++ u-boot/include/configs/qca9k_common.h | 1 + u-boot/include/env_scripts.h | 26 +++++++++++++++++++------- u-boot/net/httpd.c | 3 +++ u-boot/net/net.c | 11 +++++++++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/u-boot/common/cmd_net.c b/u-boot/common/cmd_net.c index 9effeb0..a9d0cc1 100644 --- a/u-boot/common/cmd_net.c +++ b/u-boot/common/cmd_net.c @@ -33,10 +33,12 @@ extern int do_bootm(cmd_tbl_t *, int, int, char *[]); static int netboot_common(proto_t, cmd_tbl_t *, int, char *[]); +#if defined(CONFIG_CMD_HTTPD) int do_httpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ return NetLoopHttpd(); } U_BOOT_CMD(httpd, 1, 1, do_httpd, "start www server for firmware recovery\n", NULL); +#endif /* CONFIG_CMD_HTTPD */ int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ return netboot_common(TFTP, cmdtp, argc, argv); diff --git a/u-boot/include/configs/qca9k_common.h b/u-boot/include/configs/qca9k_common.h index 548e8ea..9fb2d32 100644 --- a/u-boot/include/configs/qca9k_common.h +++ b/u-boot/include/configs/qca9k_common.h @@ -107,6 +107,7 @@ #define CONFIG_CMD_ECHO #define CONFIG_CMD_ENV #define CONFIG_CMD_FLASH +#define CONFIG_CMD_HTTPD #define CONFIG_CMD_IMI #define CONFIG_CMD_ITEST #define CONFIG_CMD_LED diff --git a/u-boot/include/env_scripts.h b/u-boot/include/env_scripts.h index 0f32d3e..558d079 100644 --- a/u-boot/include/env_scripts.h +++ b/u-boot/include/env_scripts.h @@ -125,13 +125,30 @@ #error "Reset button definition is required for recovery" #endif + #if defined(CONFIG_CMD_HTTPD) + #define SCRIPT_HTTP_PART_1 \ + "echo - 3s for web based recovery;" + + #define SCRIPT_HTTP_PART_2 \ + "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 " + #else + #define SCRIPT_HTTP_PART_1 "" + #define SCRIPT_HTTP_PART_2 \ + "elif test $cnt -lt 5; then " + #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;" \ + SCRIPT_HTTP_PART_1 \ "echo - 5s for U-Boot console;" \ "echo - 7s for network console;" \ "echo;" \ @@ -155,12 +172,7 @@ "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 " \ + SCRIPT_HTTP_PART_2 \ "echo \\#\\# Error: button was not pressed long enough!;" \ "echo Continuing normal boot...;" \ "echo;" \ diff --git a/u-boot/net/httpd.c b/u-boot/net/httpd.c index ca174ca..6f9c4a2 100644 --- a/u-boot/net/httpd.c +++ b/u-boot/net/httpd.c @@ -8,6 +8,8 @@ #include #include #include + +#if defined(CONFIG_CMD_HTTPD) #include "httpd.h" #include "../httpd/uipopt.h" @@ -176,3 +178,4 @@ int do_http_progress(const int state){ return(0); } +#endif /* CONFIG_CMD_HTTPD */ diff --git a/u-boot/net/net.c b/u-boot/net/net.c index 2d2d224..4e30c8b 100644 --- a/u-boot/net/net.c +++ b/u-boot/net/net.c @@ -80,15 +80,19 @@ #include "tftp.h" #include "rarp.h" #include "nfs.h" +#if defined(CONFIG_CMD_HTTPD) #include "httpd.h" +#endif #if defined(CONFIG_CMD_SNTP) #include "sntp.h" #endif +#if defined(CONFIG_CMD_HTTPD) #include "../httpd/uipopt.h" #include "../httpd/uip.h" #include "../httpd/uip_arp.h" +#endif #if defined(CONFIG_CMD_NET) @@ -102,6 +106,7 @@ DECLARE_GLOBAL_DATA_PTR; #define ARP_TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) #endif +#if defined(CONFIG_CMD_HTTPD) unsigned char *webfailsafe_data_pointer = NULL; int webfailsafe_is_running = 0; int webfailsafe_ready_for_upgrade = 0; @@ -110,6 +115,7 @@ int webfailsafe_upgrade_type = WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE; void NetReceiveHttpd(volatile uchar * inpkt, int len); extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +#endif /** BOOTP EXTENTIONS **/ IPaddr_t NetOurSubnetMask = 0; /* Our subnet mask (0=unknown) */ @@ -757,10 +763,12 @@ void NetReceive(volatile uchar * inpkt, int len){ printf("Packet received\n"); #endif + #if defined(CONFIG_CMD_HTTPD) if(webfailsafe_is_running){ NetReceiveHttpd(inpkt, len); return; } + #endif NetRxPkt = inpkt; NetRxPktLen = len; @@ -1367,6 +1375,8 @@ ushort getenv_VLAN(char *var){ * HTTPD section */ +#if defined(CONFIG_CMD_HTTPD) + #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) void NetSendHttpd(void){ @@ -1589,3 +1599,4 @@ int NetLoopHttpd(void){ return(-1); } +#endif /* CONFIG_CMD_HTTPD */ -- 2.25.1