From: Piotr Dymacz Date: Mon, 29 Aug 2016 11:35:07 +0000 (+0200) Subject: Restore and enable by default upgrade scripts X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=55469d891f05e95ca4c6eac02843438654a2b7da;p=oweals%2Fu-boot_mod.git Restore and enable by default upgrade scripts 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) --- diff --git a/u-boot/Makefile b/u-boot/Makefile index 96b008a..0bf0072 100644 --- a/u-boot/Makefile +++ b/u-boot/Makefile @@ -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), \ diff --git a/u-boot/common/env_common.c b/u-boot/common/env_common.c index f73fb32..8836feb 100644 --- a/u-boot/common/env_common.c +++ b/u-boot/common/env_common.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -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); } diff --git a/u-boot/common/environment.c b/u-boot/common/environment.c index 7e4060e..899f86e 100644 --- a/u-boot/common/environment.c +++ b/u-boot/common/environment.c @@ -21,23 +21,30 @@ * 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 -#undef __ASSEMBLY__ + +#undef __ASSEMBLY__ #include +#include /* * 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 /* @@ -51,16 +58,16 @@ * 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"))) @@ -100,99 +107,106 @@ * 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 */ diff --git a/u-boot/include/configs/ap121.h b/u-boot/include/configs/ap121.h index 56bf896..a3571d9 100644 --- a/u-boot/include/configs/ap121.h +++ b/u-boot/include/configs/ap121.h @@ -352,6 +352,7 @@ #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 @@ -359,6 +360,9 @@ #undef CONFIG_CMD_LOADB #undef CONFIG_CMD_BUTTON #undef CONFIG_CMD_SLEEP + + #undef CONFIG_UPG_SCRIPTS_UBOOT + #undef CONFIG_UPG_SCRIPTS_FW #endif /* @@ -420,4 +424,17 @@ #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 */ diff --git a/u-boot/include/configs/ap143.h b/u-boot/include/configs/ap143.h index 411bb71..3315ad6 100644 --- a/u-boot/include/configs/ap143.h +++ b/u-boot/include/configs/ap143.h @@ -213,6 +213,20 @@ #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 diff --git a/u-boot/include/configs/db12x.h b/u-boot/include/configs/db12x.h index f342def..c95cdfa 100644 --- a/u-boot/include/configs/db12x.h +++ b/u-boot/include/configs/db12x.h @@ -157,6 +157,13 @@ #endif +/* + * ================================== + * For upgrade scripts in environment + * ================================== + */ +#define CONFIG_UPG_UBOOT_SIZE_BACKUP_HEX 0x20000 + /* * =================== * Other configuration diff --git a/u-boot/include/configs/qca9k_common.h b/u-boot/include/configs/qca9k_common.h index 986c52a..3a58a66 100644 --- a/u-boot/include/configs/qca9k_common.h +++ b/u-boot/include/configs/qca9k_common.h @@ -117,6 +117,10 @@ #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 index 0000000..0ee3503 --- /dev/null +++ b/u-boot/include/upg_scripts.h @@ -0,0 +1,113 @@ +/* + * Upgrade helper environment scripts + * + * Copyright (C) 2016 Piotr Dymacz + * + * 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_ */