feat(bootloader): Support v2 firmware updates to v3 by OTA

This commit is contained in:
Dong Heng
2018-11-09 19:54:17 +08:00
parent ef79175caf
commit 11db1b0daf
18 changed files with 752 additions and 15 deletions

View File

@ -213,6 +213,28 @@ config CRYSTAL_USED_40MHZ
bool "40MHz"
endchoice
config ESP8266_OTA_FROM_OLD
bool "(**Expected**)ESP8266 update from old SDK by OTA"
default n
depends on TARGET_PLATFORM_ESP8266
select ESP8266_BOOT_COPY_APP
help
The function is not released.
Enable this option, script will generate the complete firmware for both old RTOS SDK(before V3.0)
and NonOS SDK to update to v3 by OTA.
The old RTOS SDK(before V3.0) or NonOS SDK can download the firmware to its partition and run it as it self's application.
config ESP8266_BOOT_COPY_APP
bool "(**Expected**)Boot copy app"
default n
help
The function is not released.
Enable this option, when it is that "OTA1" application is to run after update by OTA,
bootloader will copy "OTA1" application to "OTA0" partition and run "OTA0".
endmenu
menu WIFI

View File

@ -89,10 +89,22 @@ OTA_BIN := ./build/$(PROJECT_NAME).ota.bin
OTA1_BIN := ./build/$(PROJECT_NAME).app1.bin
OTA2_BIN := ./build/$(PROJECT_NAME).app2.bin
OTA_V2_TO_V3_BIN := ./build/$(PROJECT_NAME).v2_to_v3.ota.bin
CONFIG_APP2_OFFSET ?= $(CONFIG_APP1_OFFSET)
CONFIG_APP2_SIZE ?= $(CONFIG_APP1_SIZE)
OTA1_OFFSET := CONFIG_APP1_OFFSET
ifdef CONFIG_ESP8266_BOOT_COPY_APP
OTA2_LINK_OFFSET := $(CONFIG_APP1_OFFSET)
else
OTA2_LINK_OFFSET := $(CONFIG_APP2_OFFSET)
endif
$(OTA2_BIN): all_binaries
ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB")
@rm -f ./build/esp8266/esp8266_out.ld
@make APP_OFFSET=$(CONFIG_APP2_OFFSET) APP_SIZE=$(CONFIG_APP2_SIZE) CFLAGS= CXXFLAGS=
@make APP_OFFSET=$(OTA2_LINK_OFFSET) APP_SIZE=$(CONFIG_APP2_SIZE) CFLAGS= CXXFLAGS=
endif
@cp $(RAW_BIN) $(OTA2_BIN)
@echo [GEN] $(OTA2_BIN)
@ -113,9 +125,22 @@ endif
@cp $(OTA1_BIN) $(RAW_BIN)
@echo [GEN] $(OTA_BIN)
ifdef CONFIG_ESP8266_OTA_FROM_OLD
$(OTA_V2_TO_V3_BIN): $(OTA_BIN)
@cp $(RAW_BIN) $(RAW_BIN).tmp.bak
@cp $(OTA1_BIN) $(RAW_BIN)
@python $(IDF_PATH)/tools/pack_fw.py --output $(OTA_V2_TO_V3_BIN) pack3 $(ESPTOOL_ALL_FLASH_ARGS)
@cp $(RAW_BIN).tmp.bak $(RAW_BIN)
@echo [GEN] $(OTA_V2_TO_V3_BIN)
endif
ifdef CONFIG_ESP8266_OTA_FROM_OLD
ota: $(OTA_V2_TO_V3_BIN)
else
ota: $(OTA_BIN)
endif
ota-clean:
@rm -f $(OTA_BIN) $(OTA1_BIN) $(OTA2_BIN)
@rm -f $(OTA_BIN) $(OTA1_BIN) $(OTA2_BIN) $(OTA_V2_TO_V3_BIN)
clean: ota-clean

View File

@ -140,6 +140,12 @@
#define WDT_CTL_EN_LSB 0
#define WDT_FEED_VALUE 0x73
#define WDT_REG_READ(_reg) REG_READ(PERIPHS_WDT_BASEADDR + _reg)
#define WDT_REG_WRITE(_reg, _val) REG_WRITE(PERIPHS_WDT_BASEADDR + _reg, _val)
#define CLEAR_WDT_REG_MASK(_reg, _mask) WDT_REG_WRITE(_reg, WDT_REG_READ(_reg) & (~_mask))
#define WDT_FEED() WDT_REG_WRITE(WDT_RST_ADDRESS, WDT_FEED_VALUE)
//}}
//RTC reg {{

View File

@ -33,6 +33,10 @@ int SPI_write_status(esp_spi_flash_chip_t *chip, uint32_t status);
int SPI_read_status(esp_spi_flash_chip_t *chip, uint32_t *status);
int Enable_QMode(esp_spi_flash_chip_t *chip);
int SPIWrite(uint32_t addr, const uint8_t *src, uint32_t size);
int SPIRead(uint32_t addr, void *dst, uint32_t size);
int SPIEraseSector(uint32_t sector_num);
void Cache_Read_Disable();
void Cache_Read_Enable(uint8_t map, uint8_t p, uint8_t v);

View File

@ -263,6 +263,14 @@ extern "C" {
#define PERIPHS_SPI_FLASH_USRREG (0x60000200 + 0x1c)
#define CACHE_MAP_1M_HIGH BIT25
#define CACHE_MAP_2M BIT24
#define CACHE_MAP_SEGMENT_S 16
#define CACHE_MAP_SEGMENT_MASK 0x3
#define CACHE_BASE_ADDR 0x40200000
#define CACHE_2M_SIZE 0x00200000
#define CACHE_1M_SIZE 0x00100000
#ifdef __cplusplus
}
#endif

View File

@ -21,11 +21,6 @@
#include "portmacro.h"
#include "esp8266/eagle_soc.h"
#define WDT_REG_READ(_reg) REG_READ(PERIPHS_WDT_BASEADDR + _reg)
#define WDT_REG_WRITE(_reg, _val) REG_WRITE(PERIPHS_WDT_BASEADDR + _reg, _val)
#define CLEAR_WDT_REG_MASK(_reg, _mask) WDT_REG_WRITE(_reg, WDT_REG_READ(_reg) & (~_mask))
#define WDT_FEED() WDT_REG_WRITE(WDT_RST_ADDRESS, WDT_FEED_VALUE)
static const char *TAG = "wdt";
#ifdef CONFIG_TASK_WDT_PANIC