feat(partition_table): Update partition table script and OTA example

1. APP binary supports 4KB align instead of 64KB align

2. Add options to sdkconfig.defaults:
2.1. using 1MB flash
2.2. use custom partition table "partitions_two_ota.1MB.mini.csv"
2.3. custom partition table base address is 0x4000

3. "make ota flash" using APP1_OFFSET as app downloading address
This commit is contained in:
Dong Heng
2018-12-25 15:53:42 +08:00
parent 5bd4b2e075
commit 3d63a6ca52
11 changed files with 138 additions and 39 deletions

View File

@ -1,9 +1,5 @@
menu "ESP8266-specific" menu "ESP8266-specific"
config APP_OFFSET
hex
default 0x1000
choice NEWLIB_STDOUT_LINE_ENDING choice NEWLIB_STDOUT_LINE_ENDING
prompt "Line ending for UART output" prompt "Line ending for UART output"
default NEWLIB_STDOUT_LINE_ENDING_CRLF default NEWLIB_STDOUT_LINE_ENDING_CRLF

View File

@ -84,16 +84,6 @@ endif
.PHONY: ota ota-clean .PHONY: ota ota-clean
ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB")
APP1_OFFSET ?= 0x10000
APP1_SIZE ?= 0x70000
APP2_OFFSET ?= 0x80000
APP2_SIZE ?= 0x70000
else
APP1_OFFSET ?= CONFIG_APP_OFFSET
APP1_SIZE ?= 0x100000
endif
RAW_BIN := ./build/$(PROJECT_NAME).bin RAW_BIN := ./build/$(PROJECT_NAME).bin
OTA_BIN := ./build/$(PROJECT_NAME).ota.bin OTA_BIN := ./build/$(PROJECT_NAME).ota.bin
OTA1_BIN := ./build/$(PROJECT_NAME).app1.bin OTA1_BIN := ./build/$(PROJECT_NAME).app1.bin
@ -102,7 +92,7 @@ OTA2_BIN := ./build/$(PROJECT_NAME).app2.bin
$(OTA2_BIN): all_binaries $(OTA2_BIN): all_binaries
ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB") ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB")
@rm -f ./build/esp8266/esp8266_out.ld @rm -f ./build/esp8266/esp8266_out.ld
@make APP_OFFSET=$(APP2_OFFSET) APP_SIZE=$(APP2_SIZE) CFLAGS= CXXFLAGS= @make APP_OFFSET=$(CONFIG_APP2_OFFSET) APP_SIZE=$(CONFIG_APP2_SIZE) CFLAGS= CXXFLAGS=
endif endif
@cp $(RAW_BIN) $(OTA2_BIN) @cp $(RAW_BIN) $(OTA2_BIN)
@echo [GEN] $(OTA2_BIN) @echo [GEN] $(OTA2_BIN)
@ -111,7 +101,7 @@ $(OTA1_BIN): all_binaries
ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB") ifeq ($(CONFIG_ESPTOOLPY_FLASHSIZE), "1MB")
@rm -f ./build/esp8266/esp8266_out.ld @rm -f ./build/esp8266/esp8266_out.ld
endif endif
@make APP_OFFSET=$(APP1_OFFSET) APP_SIZE=$(APP1_SIZE) CFLAGS= CXXFLAGS= @make APP_OFFSET=$(CONFIG_APP1_OFFSET) APP_SIZE=$(CONFIG_APP1_SIZE) CFLAGS= CXXFLAGS=
@cp $(RAW_BIN) $(OTA1_BIN) @cp $(RAW_BIN) $(OTA1_BIN)
@echo [GEN] $(OTA1_BIN) @echo [GEN] $(OTA1_BIN)

View File

@ -41,8 +41,6 @@ COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES) $(addprefix ld/,$(LINKER_SCRIPTS))
# saves us from having to add the target to a Makefile.projbuild # saves us from having to add the target to a Makefile.projbuild
$(COMPONENT_LIBRARY): esp8266_out.ld esp8266_common_out.ld $(COMPONENT_LIBRARY): esp8266_out.ld esp8266_common_out.ld
APP_OFFSET ?= $(CONFIG_APP_OFFSET)
APP_SIZE ?= 0x100000
OUTLD_CFLAGS := -DAPP_OFFSET=$(APP_OFFSET) -DAPP_SIZE=$(APP_SIZE) OUTLD_CFLAGS := -DAPP_OFFSET=$(APP_OFFSET) -DAPP_SIZE=$(APP_SIZE)
esp8266_out.ld: $(COMPONENT_PATH)/ld/esp8266.ld ../include/sdkconfig.h esp8266_out.ld: $(COMPONENT_PATH)/ld/esp8266.ld ../include/sdkconfig.h

View File

@ -50,7 +50,7 @@ endif
ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS) ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN) ESPTOOL_ALL_FLASH_ARGS += $(APP_OFFSET) $(APP_BIN)
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
ifndef IS_BOOTLOADER_BUILD ifndef IS_BOOTLOADER_BUILD
@ -71,15 +71,15 @@ ifdef IS_BOOTLOADER_BUILD
endif endif
flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash)
@echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(CONFIG_APP_OFFSET))..." @echo "Flashing binaries to serial port $(ESPPORT) (app at offset $(APP_OFFSET))..."
ifdef CONFIG_SECURE_BOOT_ENABLED ifdef CONFIG_SECURE_BOOT_ENABLED
@echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)" @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
endif endif
$(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS) $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash)
@echo "Flashing app to serial port $(ESPPORT), offset $(CONFIG_APP_OFFSET)..." @echo "Flashing app to serial port $(ESPPORT), offset $(APP_OFFSET)..."
$(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
# Submodules normally added in component.mk, but can be added # Submodules normally added in component.mk, but can be added
# at the project level as long as qualified path # at the project level as long as qualified path

View File

@ -27,13 +27,6 @@ config PARTITION_TABLE_CUSTOM_FILENAME
Name of the custom partition CSV filename. This path is evaluated Name of the custom partition CSV filename. This path is evaluated
relative to the project root directory. relative to the project root directory.
config PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET
hex "Factory app partition offset" if PARTITION_TABLE_CUSTOM
default 0x10000
help
If using a custom partition table, specify the offset in the flash
where 'make flash' should write the built app.
config PARTITION_TABLE_OFFSET config PARTITION_TABLE_OFFSET
hex "Partition table offset address at flash" hex "Partition table offset address at flash"
default 0x8000 default 0x8000
@ -58,17 +51,56 @@ config PARTITION_TABLE_FILENAME
default partitions_two_ota_coredump.csv if PARTITION_TABLE_TWO_OTA && ESP32_ENABLE_COREDUMP_TO_FLASH default partitions_two_ota_coredump.csv if PARTITION_TABLE_TWO_OTA && ESP32_ENABLE_COREDUMP_TO_FLASH
default PARTITION_TABLE_CUSTOM_FILENAME if PARTITION_TABLE_CUSTOM default PARTITION_TABLE_CUSTOM_FILENAME if PARTITION_TABLE_CUSTOM
config APP_OFFSET
hex
default PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET if PARTITION_TABLE_CUSTOM
default 0x10000 # this is the factory app offset used by the default tables
config PHY_DATA_OFFSET config PHY_DATA_OFFSET
depends on ESP_PHY_INIT_DATA_IN_PARTITION depends on ESP_PHY_INIT_DATA_IN_PARTITION
hex hex
default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM
default 0xf000 # this is the factory app offset used by the default tables default 0xf000 # this is the factory app offset used by the default tables
config APP2_SUPPORT
depends on ESPTOOLPY_FLASHSIZE_1MB && (PARTITION_TABLE_TWO_OTA || PARTITION_TABLE_CUSTOM)
bool "Support to setup partition parameter of APP2" if PARTITION_TABLE_CUSTOM
default y
help
Enable this option, if you want to have APP1 & APP2 in 1MB SPI Flash.
config APP1_OFFSET
hex "APP1 partition offset" if PARTITION_TABLE_CUSTOM
default 0x10000
help
If using a custom partition table, specify the offset in the flash
where the APP1 located.
It should be same as the value in the custom partition table CSV.
config APP1_SIZE
hex "APP1 partition size(by bytes)" if PARTITION_TABLE_CUSTOM
default 0x70000 if APP2_SUPPORT
default 0xF0000
help
APP1 partition size by bytes.
It should be same as the value in the custom partition table CSV.
config APP2_OFFSET
depends on APP2_SUPPORT
hex "APP2 partition offset" if PARTITION_TABLE_CUSTOM
default 0x80000
help
If using a custom partition table, specify the offset in the flash
where the APP2 located.
It should be same as the value in the custom partition table CSV.
config APP2_SIZE
depends on APP2_SUPPORT
hex "APP2 partition size(by bytes)" if PARTITION_TABLE_CUSTOM
default 0x70000
help
APP2 partition size by bytes.
It should be same as the value in the custom partition table CSV.
endmenu endmenu

View File

@ -45,6 +45,11 @@ $(PARTITION_TABLE_BIN_UNSIGNED): $(PARTITION_TABLE_CSV_PATH) $(SDKCONFIG_MAKEFIL
all_binaries: $(PARTITION_TABLE_BIN) all_binaries: $(PARTITION_TABLE_BIN)
APP_OFFSET ?= $(CONFIG_APP1_OFFSET)
APP_SIZE ?= $(CONFIG_APP1_SIZE)
export APP_OFFSET APP_SIZE
PARTITION_TABLE_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN) PARTITION_TABLE_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN)
ESPTOOL_ALL_FLASH_ARGS += $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN) ESPTOOL_ALL_FLASH_ARGS += $(PARTITION_TABLE_OFFSET) $(PARTITION_TABLE_BIN)

View File

@ -163,7 +163,7 @@ class PartitionDefinition(object):
MAGIC_BYTES = b"\xAA\x50" MAGIC_BYTES = b"\xAA\x50"
ALIGNMENT = { ALIGNMENT = {
APP_TYPE : 0x10000, APP_TYPE : 0x1000,
DATA_TYPE : 0x04, DATA_TYPE : 0x04,
} }

View File

@ -16,6 +16,65 @@ In this example, the ESP8266 has 2 images in flash: OTA_0, OTA_1. Each of these
Flashing the example over serial with "make flash" updates the OTA_0 app image. On first boot, the bootloader loads this OTA_0 app image which then performs an OTA update (triggered in the example code). The update downloads a new image from an http server and saves it into the OTA_1 partition. At this point the example code updates the ota_data partition to indicate the new app partition, and reboots. The bootloader reads ota_data, determines the new OTA image has been selected, and runs it. Flashing the example over serial with "make flash" updates the OTA_0 app image. On first boot, the bootloader loads this OTA_0 app image which then performs an OTA update (triggered in the example code). The update downloads a new image from an http server and saves it into the OTA_1 partition. At this point the example code updates the ota_data partition to indicate the new app partition, and reboots. The bootloader reads ota_data, determines the new OTA image has been selected, and runs it.
# Custom partition configuration
If customers want to use their own partition tables with specific partition location. Please see following steps:
## Step 1: Create partition file
Create a partition managment file with "cvs" formate, please refer to "doc/en/api-guides/partition-tables.rst"
## Step 2: Select custom partition mode
1. Select custom partition tables at "menuconfig":
```
Partition Table --->
Partition Table (XXXXXX) --->
(X) Custom partition table CSV
```
2. Configurate custom partition location at:
```
(XXXXXX)Custom partition CSV file
```
Note: System will add the absolute path of the project to the head of the "Custom partition CSV file" automatically when compling.
3. Configurate patition table location if necessary:
```
(XXXXXX)Partition table offset address at flash
```
## Step 3: Configurate application location:
Configurate application location at "mennuconfig" like following base on partition table file.
If you select 1MB flash, application location configuration menu is like following:
```
Partition Table --->
[*] Support to setup partition parameter of APP2
(0x5000) App1 offset address
(0x7B000) App1 size by bytes
(0x85000) App2 offset address
(0x7b000) App2 size by bytes
```
If you select 2MB flash and above size, application location configuration menu is like following:
```
Partition Table --->
(0x10000) APP1 partition offset
(0xF0000) APP1 partition size(by bytes)
```
Note: The firmware location information must be same as partition table file. **make ota flash** will only download the app1 at **APP1 partition offset**.
# Workflow # Workflow
The OTA_workflow.png diagram demonstrates the overall workflow: The OTA_workflow.png diagram demonstrates the overall workflow:
@ -84,6 +143,8 @@ Serial flasher config --->
(X) 1 MB (X) 1 MB
``` ```
Configurate the application location information and it must be same as the OTA example's information, how to do refer to **Step 3: Configurate application location** of **Custom partition configuration**.
Save your changes, and type `make` to build the example. Save your changes, and type `make` to build the example.
## Step 4: Flash OTA Example ## Step 4: Flash OTA Example

View File

@ -0,0 +1,9 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
# Bootloader is at 0x0000 - 0x4000, total 16KB
# Partition table is at 0x4000 - 0x5000, total 4KB
phy_init, data, phy, 0x5000, 0x1000
ota_0, 0, ota_0, 0x6000, 0x7A000
nvs, data, nvs, 0x80000, 0x4000
otadata, data, ota, 0x84000, 0x2000
ota_1, 0, ota_1, 0x86000, 0x7A000
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
3 # Bootloader is at 0x0000 - 0x4000, total 16KB
4 # Partition table is at 0x4000 - 0x5000, total 4KB
5 phy_init, data, phy, 0x5000, 0x1000
6 ota_0, 0, ota_0, 0x6000, 0x7A000
7 nvs, data, nvs, 0x80000, 0x4000
8 otadata, data, ota, 0x84000, 0x2000
9 ota_1, 0, ota_1, 0x86000, 0x7A000

View File

@ -1,4 +1,12 @@
# Default sdkconfig parameters to use the ESP8266 OTA # Default sdkconfig parameters to use the ESP8266 OTA
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
CONFIG_PARTITION_TABLE_TWO_OTA=y
CONFIG_LWIP_SOCKET_MULTITHREAD= CONFIG_LWIP_SOCKET_MULTITHREAD=
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_two_ota.1MB.mini.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x4000
CONFIG_APP1_OFFSET=0x6000
CONFIG_APP1_SIZE=0x7A000
CONFIG_APP2_OFFSET=0x86000
CONFIG_APP2_SIZE=0x7A000

View File

@ -410,10 +410,10 @@ ifeq ("$(CONFIG_SECURE_BOOT_ENABLED)$(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)"
@echo "App built but not signed. Signing step via espsecure.py:" @echo "App built but not signed. Signing step via espsecure.py:"
@echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)" @echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)"
@echo "Then flash app command is:" @echo "Then flash app command is:"
@echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) @echo $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
else else
@echo "App built. Default flash app command is:" @echo "App built. Default flash app command is:"
@echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) @echo $(ESPTOOLPY_WRITE_FLASH) $(APP_OFFSET) $(APP_BIN)
endif endif
all_binaries: $(APP_BIN) all_binaries: $(APP_BIN)