Restore and enable by default upgrade scripts
authorPiotr Dymacz <pepe2k@gmail.com>
Mon, 29 Aug 2016 11:35:07 +0000 (13:35 +0200)
committerPiotr Dymacz <pepe2k@gmail.com>
Mon, 29 Aug 2016 11:35:07 +0000 (13:35 +0200)
Include in environment new upgrade scripts as it's
easy and fast way for U-Boot/firmare upgrade using
TFTP server (should listen on 'serverip' address).

Use them under U-Boot command line with:
- run uboot_upg (for U-Boot image upgrade, file: u-boot.bin)
- run fw_upg (for firmware image upgrade, file: firmware.bin)

u-boot/Makefile
u-boot/common/env_common.c
u-boot/common/environment.c
u-boot/include/configs/ap121.h
u-boot/include/configs/ap143.h
u-boot/include/configs/db12x.h
u-boot/include/configs/qca9k_common.h
u-boot/include/upg_scripts.h [new file with mode: 0644]

index 96b008ac7c6a2c99a8f1e38d7fbb2a8d008c563e..0bf0072fc3475ac653992c672fe707b7265d967f 100644 (file)
@@ -169,6 +169,7 @@ define config_init
   $(if $(filter $(4),1),$(call define_add,CONFIG_GPIO_RESET_BTN_ACTIVE_LOW,1))
   $(if $(CONFIG_MAX_UBOOT_SIZE), \
     $(call define_add,CONFIG_MAX_UBOOT_SIZE,$(CONFIG_MAX_UBOOT_SIZE))
+    $(call define_add,CONFIG_MAX_UBOOT_SIZE_HEX,$(shell printf '0x%X' $(CONFIG_MAX_UBOOT_SIZE)))
   )
 
   $(if $(filter $(CONFIG_SKIP_LOWLEVEL_INIT),1), \
index f73fb320c9c5b7a73f6bb5e980cadc1738d01db2..8836feb1633de8709c133609bbd3bbef633df230 100644 (file)
@@ -27,6 +27,7 @@
 #include <common.h>
 #include <command.h>
 #include <environment.h>
+#include <upg_scripts.h>
 #include <linux/stddef.h>
 #include <malloc.h>
 #include <tinf.h>
@@ -35,7 +36,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #undef DEBUG_ENV
 
-#ifdef DEBUG_ENV
+#if defined(DEBUG_ENV)
        #define DEBUGF(fmt,args...) printf(fmt ,##args)
 #else
        #define DEBUGF(fmt,args...)
@@ -56,118 +57,128 @@ uchar (*env_get_char)(int) = env_get_char_init;
 #define MK_STR(x)      XMK_STR(x)
 
 uchar default_environment[] = {
-#ifdef CONFIG_BOOTARGS
-                                                               "bootargs=" CONFIG_BOOTARGS "\0"
+#if defined(CONFIG_BOOTARGS)
+       "bootargs=" CONFIG_BOOTARGS "\0"
 #endif
-#ifdef CONFIG_BOOTCOMMAND
-                                                               "bootcmd=" CONFIG_BOOTCOMMAND "\0"
+#if defined(CONFIG_BOOTCOMMAND)
+       "bootcmd=" CONFIG_BOOTCOMMAND "\0"
 #endif
-#ifdef CONFIG_RAMBOOTCOMMAND
-                                                               "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
+#if defined(CONFIG_RAMBOOTCOMMAND)
+       "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
 #endif
-#ifdef CONFIG_NFSBOOTCOMMAND
-                                                               "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
+#if defined(CONFIG_NFSBOOTCOMMAND)
+       "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
 #endif
 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
-                                                               "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
+       "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
 #endif
 #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
-                                                               "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
+       "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
 #endif
-#ifdef CONFIG_LOADS_ECHO
-                                                               "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
+#if defined(CONFIG_LOADS_ECHO)
+       "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
 #endif
-#ifdef CONFIG_ETHADDR
-                                                               "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
+#if defined(CONFIG_ETHADDR)
+       "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
 #endif
-#ifdef CONFIG_ETH1ADDR
-                                                               "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
+#if defined(CONFIG_ETH1ADDR)
+       "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
 #endif
-#ifdef CONFIG_ETH2ADDR
-                                                               "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
+#if defined(CONFIG_ETH2ADDR)
+       "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
 #endif
-#ifdef CONFIG_ETH3ADDR
-                                                               "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
+#if defined(CONFIG_ETH3ADDR)
+       "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
 #endif
-#ifdef CONFIG_IPADDR
-                                                               "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
+#if defined(CONFIG_IPADDR)
+       "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
 #endif
-#ifdef CONFIG_SERVERIP
-                                                               "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
+#if defined(CONFIG_SERVERIP)
+       "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
 #endif
-#ifdef CFG_AUTOLOAD
-                                                               "autoload=" CFG_AUTOLOAD "\0"
+#if defined(CFG_AUTOLOAD)
+       "autoload=" CFG_AUTOLOAD "\0"
 #endif
-#ifdef CONFIG_ROOTPATH
-                                                               "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
+#if defined(CONFIG_ROOTPATH)
+       "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
 #endif
-#ifdef CONFIG_GATEWAYIP
-                                                               "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
+#if defined(CONFIG_GATEWAYIP)
+       "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
 #endif
-#ifdef CONFIG_NETMASK
-                                                               "netmask=" MK_STR(CONFIG_NETMASK) "\0"
+#if defined(CONFIG_NETMASK)
+       "netmask=" MK_STR(CONFIG_NETMASK) "\0"
 #endif
-#ifdef CONFIG_HOSTNAME
-                                                               "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
+#if defined(CONFIG_HOSTNAME)
+       "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
 #endif
-#ifdef CONFIG_BOOTFILE
-                                                               "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
+#if defined(CONFIG_BOOTFILE)
+       "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
 #endif
-#ifdef CONFIG_LOADADDR
-                                                               "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
+#if defined(CONFIG_LOADADDR)
+       "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
 #endif
-#ifdef  CONFIG_CLOCKS_IN_MHZ
-                                                               "clocks_in_mhz=1\0"
+#if defined(CONFIG_CLOCKS_IN_MHZ)
+       "clocks_in_mhz=1\0"
 #endif
 #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
-                                                               "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
+       "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
 #endif
-#ifdef CONFIG_NETCONSOLE_PORT
-                                                               "ncport=" MK_STR(CONFIG_NETCONSOLE_PORT) "\0"
+#if defined(CONFIG_NETCONSOLE_PORT)
+       "ncport=" MK_STR(CONFIG_NETCONSOLE_PORT) "\0"
 #endif
-#ifdef  CONFIG_EXTRA_ENV_SETTINGS
-                                                               CONFIG_EXTRA_ENV_SETTINGS
+#if defined(CONFIG_EXTRA_ENV_SETTINGS)
+       CONFIG_EXTRA_ENV_SETTINGS
 #endif
-                                                               "\0" };
+#if defined(CONFIG_ENV_UPG_SCRIPTS_UBOOT)
+               CONFIG_ENV_UPG_SCRIPTS_UBOOT
+#endif
+#if defined(CONFIG_ENV_UPG_SCRIPTS_FW)
+               CONFIG_ENV_UPG_SCRIPTS_FW
+#endif
+       "\0"
+};
 
-#if defined(CFG_ENV_IS_IN_NAND)                /* Environment is in Nand Flash */
+/* Environment is in Nand Flash */
+#if defined(CFG_ENV_IS_IN_NAND)
 int default_environment_size = sizeof(default_environment);
 #endif
 
-void env_crc_update(void){
+void env_crc_update(void)
+{
        env_ptr->crc = tinf_crc32(env_ptr->data, ENV_SIZE);
 }
 
-static uchar env_get_char_init(int index){
+static uchar env_get_char_init(int index)
+{
        uchar c;
 
        /* if crc was bad, use the default environment */
-       if(gd->env_valid){
+       if (gd->env_valid)
                c = env_get_char_spec(index);
-       } else {
+       else
                c = default_environment[index];
-       }
 
-       return(c);
+       return c;
 }
 
-uchar env_get_char_memory(int index){
-       if(gd->env_valid){
-               return(*((uchar *)(gd->env_addr + index)));
-       } else {
-               return(default_environment[index]);
-       }
+uchar env_get_char_memory(int index)
+{
+       if (gd->env_valid)
+               return *((uchar *)(gd->env_addr + index));
+       else
+               return default_environment[index];
 }
 
-uchar *env_get_addr(int index){
-       if(gd->env_valid){
-               return(((uchar *)(gd->env_addr + index)));
-       } else {
-               return(&default_environment[index]);
-       }
+uchar *env_get_addr(int index)
+{
+       if (gd->env_valid)
+               return ((uchar *)(gd->env_addr + index));
+       else
+               return &default_environment[index];
 }
 
-void env_relocate(void){
+void env_relocate(void)
+{
        DEBUGF("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__, gd->reloc_off);
 
 #if defined(ENV_IS_EMBEDDED)
@@ -178,40 +189,38 @@ void env_relocate(void){
        env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off);
        DEBUGF("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
 #else
-       /*
-        * We must allocate a buffer for the environment
-        */
+       /* We must allocate a buffer for the environment */
        env_ptr = (env_t *)malloc(CFG_ENV_SIZE);
        DEBUGF("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
 #endif
 
-       /*
-        * After relocation to RAM, we can always use the "memory" functions
-        */
+       /* After relocation to RAM, we can always use the "memory" functions */
        env_get_char = env_get_char_memory;
 
-       if(gd->env_valid == 0){
-#if defined(CFG_ENV_IS_NOWHERE)        /* Environment not changable */
-               //puts("Using default environment\n\n");
-#else
+       if (gd->env_valid == 0) {
+#if !defined(CFG_ENV_IS_NOWHERE)
                puts("** Warning: bad env CRC, using default,\n"
                         "   use 'saveenv' to save it in FLASH\n\n");
 #endif
 
-               if(sizeof(default_environment) > ENV_SIZE){
-                       puts("## Error: default environment is too large\n");
+               if (sizeof(default_environment) > ENV_SIZE) {
+                       puts("## Error: default env is too big!\n");
                        return;
                }
 
                memset(env_ptr, 0, sizeof(env_t));
-               memcpy(env_ptr->data, default_environment, sizeof(default_environment));
-#ifdef CFG_REDUNDAND_ENVIRONMENT
+               memcpy(env_ptr->data, default_environment,
+                       sizeof(default_environment));
+
+#if defined(CFG_REDUNDAND_ENVIRONMENT)
                env_ptr->flags = 0xFF;
 #endif
+
                env_crc_update();
                gd->env_valid = 1;
        } else {
                env_relocate_spec();
        }
+
        gd->env_addr = (ulong)&(env_ptr->data);
 }
index 7e4060e8ac8df2d735418983c8cc541060d1d50a..899f86e1d08ffa54885d74312f950c9500955595 100644 (file)
  * MA 02111-1307 USA
  */
 
+/* Dirty trick to get only #defines */
 #ifndef __ASSEMBLY__
-#define        __ASSEMBLY__                    /* Dirty trick to get only #defines     */
+       #define __ASSEMBLY__
 #endif
-#define        __ASM_STUB_PROCESSOR_H__        /* don't include asm/processor.         */
+
+/* Don't include asm/processor */
+#define __ASM_STUB_PROCESSOR_H__
+
 #include <config.h>
-#undef __ASSEMBLY__
+
+#undef __ASSEMBLY__
 #include <environment.h>
+#include <upg_scripts.h>
 
 /*
  * Handle HOSTS that have prepended
  * crap on symbol names, not TARGETS.
  */
 #if defined(__APPLE__)
-/* Leading underscore on symbols */
-#  define SYM_CHAR "_"
-#else /* No leading character on symbols */
-#  define SYM_CHAR
+       /* Leading underscore on symbols */
+       #define SYM_CHAR "_"
+#else
+       /* No leading character on symbols */
+       #define SYM_CHAR
 #endif
 
 /*
  * a seperate section.  Note that ENV_CRC is only defined when building
  * U-Boot itself.
  */
-#if (defined(CONFIG_CMI)               || \
-     defined(CONFIG_FADS)              || \
-     defined(CONFIG_HYMOD)             || \
-     defined(CONFIG_ICU862)            || \
-     defined(CONFIG_R360MPI)   || \
-     defined(CONFIG_TQM8xxL)   || \
-     defined(CONFIG_RRVISION)  || \
-     defined(CONFIG_TRAB)      || \
-     defined(CONFIG_PPCHAMELEONEVB) )  && \
-     defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
+#if (defined(CONFIG_CMI)      ||\
+     defined(CONFIG_FADS)     ||\
+     defined(CONFIG_HYMOD)    ||\
+     defined(CONFIG_ICU862)   ||\
+     defined(CONFIG_R360MPI)  ||\
+     defined(CONFIG_TQM8xxL)  ||\
+     defined(CONFIG_RRVISION) ||\
+     defined(CONFIG_TRAB)     ||\
+     defined(CONFIG_PPCHAMELEONEVB) \
+    ) && defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
 
        /* XXX - This only works with GNU C */
        #define __PPCENV__ __attribute__ ((section(".ppcenv")))
  * computed CRC.  Otherwise define it as ~0.
  */
 #if !defined(ENV_CRC)
-#  define ENV_CRC      ~0
+       #define ENV_CRC ~0
 #endif
 
 env_t environment __PPCENV__ = {
        ENV_CRC,        /* CRC Sum */
-#ifdef CFG_REDUNDAND_ENVIRONMENT
+#if defined(CFG_REDUNDAND_ENVIRONMENT)
        1,              /* Flags: valid */
 #endif
        {
 #if defined(CONFIG_BOOTARGS)
-                                "bootargs="    CONFIG_BOOTARGS                         "\0"
+               "bootargs=" CONFIG_BOOTARGS "\0"
 #endif
 #if defined(CONFIG_BOOTCOMMAND)
-                                "bootcmd="             CONFIG_BOOTCOMMAND                      "\0"
+               "bootcmd=" CONFIG_BOOTCOMMAND "\0"
 #endif
 #if defined(CONFIG_RAMBOOTCOMMAND)
-                                "ramboot="             CONFIG_RAMBOOTCOMMAND           "\0"
+               "ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
 #endif
 #if defined(CONFIG_NFSBOOTCOMMAND)
-                                "nfsboot="             CONFIG_NFSBOOTCOMMAND           "\0"
+               "nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
 #endif
 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
-                                "bootdelay="   MK_STR(CONFIG_BOOTDELAY)        "\0"
+               "bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
 #endif
 #if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
-                                "baudrate="    MK_STR(CONFIG_BAUDRATE)         "\0"
+               "baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
 #endif
-#ifdef CONFIG_LOADS_ECHO
-                                "loads_echo="  MK_STR(CONFIG_LOADS_ECHO)       "\0"
+#if defined(CONFIG_LOADS_ECHO)
+               "loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
 #endif
-#ifdef CONFIG_ETHADDR
-                                "ethaddr="             MK_STR(CONFIG_ETHADDR)          "\0"
+#if defined(CONFIG_ETHADDR)
+               "ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
 #endif
-#ifdef CONFIG_ETH1ADDR
-                                "eth1addr="    MK_STR(CONFIG_ETH1ADDR)         "\0"
+#if defined(CONFIG_ETH1ADDR)
+               "eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
 #endif
-#ifdef CONFIG_ETH2ADDR
-                                "eth2addr="    MK_STR(CONFIG_ETH2ADDR)         "\0"
+#if defined(CONFIG_ETH2ADDR)
+               "eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
 #endif
-#ifdef CONFIG_ETH3ADDR
-                                "eth3addr="    MK_STR(CONFIG_ETH3ADDR)         "\0"
+#if defined(CONFIG_ETH3ADDR)
+               "eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
 #endif
-#ifdef CONFIG_ETHPRIME
-                                "ethprime="    CONFIG_ETHPRIME                         "\0"
+#if defined(CONFIG_ETHPRIME)
+               "ethprime=" CONFIG_ETHPRIME "\0"
 #endif
-#ifdef CONFIG_IPADDR
-                                "ipaddr="              MK_STR(CONFIG_IPADDR)           "\0"
+#if defined(CONFIG_IPADDR)
+               "ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
 #endif
-#ifdef CONFIG_SERVERIP
-                                "serverip="    MK_STR(CONFIG_SERVERIP)         "\0"
+#if defined(CONFIG_SERVERIP)
+               "serverip=" MK_STR(CONFIG_SERVERIP) "\0"
 #endif
-#ifdef CFG_AUTOLOAD
-                                "autoload="    CFG_AUTOLOAD                            "\0"
+#if defined(CFG_AUTOLOAD)
+               "autoload=" CFG_AUTOLOAD "\0"
 #endif
-#ifdef CONFIG_ROOTPATH
-                                "rootpath="    MK_STR(CONFIG_ROOTPATH)         "\0"
+#if defined(CONFIG_ROOTPATH)
+               "rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
 #endif
-#ifdef CONFIG_GATEWAYIP
-                                "gatewayip="   MK_STR(CONFIG_GATEWAYIP)        "\0"
+#if defined(CONFIG_GATEWAYIP)
+               "gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
 #endif
-#ifdef CONFIG_NETMASK
-                                "netmask="             MK_STR(CONFIG_NETMASK)          "\0"
+#if defined(CONFIG_NETMASK)
+               "netmask=" MK_STR(CONFIG_NETMASK) "\0"
 #endif
-#ifdef CONFIG_HOSTNAME
-                                "hostname="    MK_STR(CONFIG_HOSTNAME)         "\0"
+#if defined(CONFIG_HOSTNAME)
+               "hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
 #endif
-#ifdef CONFIG_BOOTFILE
-                                "bootfile="    MK_STR(CONFIG_BOOTFILE)         "\0"
+#if defined(CONFIG_BOOTFILE)
+               "bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
 #endif
-#ifdef CONFIG_LOADADDR
-                                "loadaddr="    MK_STR(CONFIG_LOADADDR)         "\0"
+#if defined(CONFIG_LOADADDR)
+               "loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
 #endif
-#ifdef CONFIG_NETCONSOLE_PORT
-                                "ncport="              MK_STR(CONFIG_NETCONSOLE_PORT)  "\0"
+#if defined(CONFIG_NETCONSOLE_PORT)
+               "ncport=" MK_STR(CONFIG_NETCONSOLE_PORT) "\0"
 #endif
-#ifdef CONFIG_CLOCKS_IN_MHZ
-                                "clocks_in_mhz=" "1"                                                   "\0"
+#if defined(CONFIG_CLOCKS_IN_MHZ)
+               "clocks_in_mhz=1\0"
 #endif
 #if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
-                                "pcidelay="    MK_STR(CONFIG_PCI_BOOTDELAY)    "\0"
+               "pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
 #endif
-#ifdef  CONFIG_EXTRA_ENV_SETTINGS
-                                CONFIG_EXTRA_ENV_SETTINGS
+#if defined(CONFIG_EXTRA_ENV_SETTINGS)
+               CONFIG_EXTRA_ENV_SETTINGS
 #endif
-       "\0"            /* Term. env_t.data with 2 NULs */
+#if defined(CONFIG_ENV_UPG_SCRIPTS_UBOOT)
+               CONFIG_ENV_UPG_SCRIPTS_UBOOT
+#endif
+#if defined(CONFIG_ENV_UPG_SCRIPTS_FW)
+               CONFIG_ENV_UPG_SCRIPTS_FW
+#endif
+       "\0"
        }
 };
-#ifdef CFG_ENV_ADDR_REDUND
+
+#if defined(CFG_ENV_ADDR_REDUND)
 env_t redundand_environment __PPCENV__ = {
-       0,              /* CRC Sum: invalid */
-       0,              /* Flags:   invalid */
+       0,      /* CRC Sum: invalid */
+       0,      /* Flags:   invalid */
        {
-       "\0"
+               "\0"
        }
 };
 #endif /* CFG_ENV_ADDR_REDUND */
@@ -203,13 +217,10 @@ env_t redundand_environment __PPCENV__ = {
  * in the image.  When this is used for
  * tools/envcrc, they are placed in the
  * .data/.sdata section.
- *
  */
 unsigned long env_size __PPCTEXT__ = sizeof(env_t);
 
-/*
- * Add in absolutes.
- */
+/* Add in absolutes */
 GEN_ABS(env_offset, CFG_ENV_OFFSET);
 
 #endif /* ENV_IS_EMBEDDED */
index 56bf89673e486a32c9da6a489b8a051ff341c250..a3571d9fe5b4c316b0a5e436f559ba4a5e9d0bf1 100644 (file)
 #if defined(CONFIG_FOR_DLINK_DIR505_A1)
        #define CFG_ENV_IS_NOWHERE      1
        #undef CFG_ENV_IS_IN_FLASH
+
        #undef CONFIG_CMD_DHCP
        #undef CONFIG_CMD_SNTP
        #undef CONFIG_CMD_IMI
        #undef CONFIG_CMD_LOADB
        #undef CONFIG_CMD_BUTTON
        #undef CONFIG_CMD_SLEEP
+
+       #undef CONFIG_UPG_SCRIPTS_UBOOT
+       #undef CONFIG_UPG_SCRIPTS_FW
 #endif
 
 /*
 
 #endif
 
+/*
+ * ==================================
+ * For upgrade scripts in environment
+ * ==================================
+ */
+#if !defined(CONFIG_FOR_BLACK_SWIFT_BOARD) &&\
+    !defined(CONFIG_FOR_DLINK_DIR505_A1)   &&\
+    !defined(CONFIG_FOR_DRAGINO_V2)        &&\
+    !defined(CONFIG_FOR_MESH_POTATO_V2)    &&\
+    !defined(CONFIG_FOR_8DEVICES_CARAMBOLA2)
+       #define CONFIG_UPG_SCRIPTS_UBOOT_SIZE_BCKP_HEX  0x20000
+#endif
+
 #endif /* _AP121_H */
index 411bb71dd4a132bb2947da5f66e0259d71774613..3315ad6a72d240c0eea92832320cb188137a75cd 100644 (file)
 
 #endif
 
+/*
+ * ==================================
+ * For upgrade scripts in environment
+ * ==================================
+ */
+#if !defined(CONFIG_FOR_WALLYS_DR531) &&\
+    !defined(CONFIG_FOR_ZBTLINK_ZBT_WE1526)
+       #define CONFIG_UPG_UBOOT_SIZE_BACKUP_HEX        0x20000
+#endif
+
+#if defined(CONFIG_FOR_ZBTLINK_ZBT_WE1526)
+       #define CONFIG_UPG_SCRIPTS_FW_ADDR_HEX  0x9F050000
+#endif
+
 /*
  * ===================
  * Other configuration
index f342def666c5d82d2d61c4d09aba7b4ff9783ec3..c95cdfa0460cd4dc2aa9680030e76cacd875e386 100644 (file)
 
 #endif
 
+/*
+ * ==================================
+ * For upgrade scripts in environment
+ * ==================================
+ */
+#define CONFIG_UPG_UBOOT_SIZE_BACKUP_HEX       0x20000
+
 /*
  * ===================
  * Other configuration
index 986c52ab599794ca329add18449aeed4bc9eb5e3..3a58a66b862566d8e04ffe6e1049c1eb9a6e53ac 100644 (file)
 #define CONFIG_CMD_BUTTON
 #define CONFIG_CMD_SLEEP
 
+/* Simple upgrade scripts in environment */
+#define CONFIG_UPG_SCRIPTS_UBOOT
+#define CONFIG_UPG_SCRIPTS_FW
+
 /* For HTTP based recovery */
 /* TODO: move it to httpd related header */
 #define WEBFAILSAFE_PROGRESS_START             0
diff --git a/u-boot/include/upg_scripts.h b/u-boot/include/upg_scripts.h
new file mode 100644 (file)
index 0000000..0ee3503
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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_name=firmware.bin\0" \
+               "fw_addr=" MK_STR(CONFIG_UPG_SCRIPTS_FW_ADDR_HEX) "\0" \
+               "fw_upg=" \
+                       "if ping $serverip; then " \
+                               "tftp $loadaddr $fw_name && " \
+                               "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_ */