Skip to content

Commit

Permalink
Fix esp8266 bootloader building and add diagnostic tools (#2734)
Browse files Browse the repository at this point in the history
This PR focuses on an issue discovered in #2727 when attempting to update the esp8266 boot partition from code during a firmware update.
It was discovered that doing this renders the device unbootable because the boot sector header information is incorrect.

This is because the required `SPI_SIZE`, `SPI_MODE` and `SPI_FREQ` values were never passed to the rboot makefile when building.
When flashing the boot partition normally, these parameters get passed to esptool, which modifies the provided boot image.
I wasn't aware until now that it did this!

**Build rboot as variant**

The solution to the main problem is to build rboot as a variant - see https://sming.readthedocs.io/en/latest/_inc/Sming/building.html#library-variants.

The location of the bootloader firmware (in `out/Esp8266/debug/firmware/rboot.bin`) is unchanged,
but is overwritten by the appropriate variant after every build.

This should ensure consistency with selected settings.

**Remove RBOOT_INTEGRATION**

As we've forked rboot some time ago this isn't necessary, so we can simplify the code a bit.

**Update esptool to v4.6.2 (from v4.4)**

Version 4.7 has issues with earlier python versions and breaks with IDF 4.4/4.3.

**Add `bootinfo` build target**

Adds `make bootinfo` for esp architectures which shows details of the boot partition,
including header fields so we can check it's correct.

**Add `esptool` build target**

Makes for easier access to esptool.
  • Loading branch information
mikee47 authored Mar 18, 2024
1 parent 1054a0c commit b9029a2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
8 changes: 8 additions & 0 deletions Sming/Arch/Esp32/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ endif

$(TARGET_BIN): $(TARGET_OUT)
$(Q) $(ESPTOOL_CMDLINE) elf2image --min-rev $(CHIP_REV_MIN) --elf-sha256-offset 0xb0 $(ESPTOOL_EXTRA_ARGS) $(flashimageoptions) -o $@ $<


##@Flashing

.PHONY: bootinfo
bootinfo: $(FLASH_BOOT_LOADER) ##Show bootloader information
$(info $(FLASH_BOOT_LOADER):)
$(Q) $(ESPTOOL_CMDLINE) image_info -v2 $(FLASH_BOOT_LOADER)
8 changes: 8 additions & 0 deletions Sming/Components/esptool/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ endef
define EraseFlash
$(call ESPTOOL_EXECUTE,erase_flash)
endef


##@Flashing

.PHONY: esptool
esptool: ##Pass options to esptool, e.g. `make esptool -- --help` or `make esptool image_info`
$(Q) $(ESPTOOL_CMDLINE) $(filter-out $@,$(MAKECMDGOALS))

2 changes: 1 addition & 1 deletion Sming/Components/esptool/esptool
Submodule esptool updated 182 files
44 changes: 33 additions & 11 deletions Sming/Components/rboot/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ endif

# => APP

# Build bootloader variant based on these variable values
RBOOT_VARS := \
PARTITION_TABLE_OFFSET \
RBOOT_RTC_ENABLED \
RBOOT_GPIO_ENABLED \
RBOOT_GPIO_SKIP_ENABLED \
RBOOT_SILENT \
SPI_SPEED \
SPI_MODE \
SPI_SIZE

# rBoot options
CONFIG_VARS += RBOOT_RTC_ENABLED RBOOT_GPIO_ENABLED RBOOT_GPIO_SKIP_ENABLED
RBOOT_RTC_ENABLED ?= 0
Expand Down Expand Up @@ -102,12 +113,6 @@ RBOOT_ROM_1_BIN := $(FW_BASE)/$(RBOOT_ROM_1).bin


COMPONENT_APPCODE := rboot/appcode
APP_CFLAGS += -DRBOOT_INTEGRATION

# these are exported for use by the rBoot Makefile
export RBOOT_BUILD_BASE := $(abspath $(COMPONENT_BUILD_DIR))
export RBOOT_FW_BASE := $(abspath $(FW_BASE))
export ESPTOOL2

# multiple roms per 1mb block?
ifeq ($(RBOOT_TWO_ROMS),1)
Expand Down Expand Up @@ -143,12 +148,20 @@ ifdef RBOOT_EMULATION
FLASH_BOOT_CHUNKS = 0x00000=$(BLANK_BIN)
FLASH_RBOOT_ERASE_CONFIG_CHUNKS := 0x01000=$(BLANK_BIN)
else
export RBOOT_ROM0_ADDR
export RBOOT_ROM1_ADDR
export ESPTOOL2
export $(RBOOT_VARS)
RBOOT_VARSTR := $(foreach v,$(RBOOT_VARS),$v=$($v))
RBOOT_HASH := $(call CalculateVariantHash,RBOOT_VARSTR)
export RBOOT_BUILD_BASE := $(COMPONENT_BUILD_BASE)/$(RBOOT_HASH)
RBOOT_VAR_BIN := $(RBOOT_BUILD_BASE)/rboot.bin
RBOOT_BIN := $(FW_BASE)/rboot.bin
CUSTOM_TARGETS += $(RBOOT_BIN)
$(RBOOT_BIN):
$(Q) $(MAKE) -C $(RBOOT_DIR)/rboot PARTITION_TABLE_OFFSET=$(PARTITION_TABLE_OFFSET) $(RBOOT_CFLAGS)
CUSTOM_TARGETS += build_rboot
$(RBOOT_VAR_BIN): $(ESPTOOL2)
$(Q) $(MAKE) -C $(RBOOT_DIR)/rboot $(RBOOT_CFLAGS)

.PHONY: build_rboot
build_rboot: $(RBOOT_VAR_BIN)
cp $(RBOOT_VAR_BIN) $(RBOOT_BIN)

EXTRA_LDFLAGS := -u Cache_Read_Enable_New

Expand Down Expand Up @@ -207,4 +220,13 @@ $(RBOOT_ROM_1_BIN): $(TARGET_OUT_1)

endif


##@Flashing

.PHONY: bootinfo
bootinfo: ##Show bootloader information
$(info $(RBOOT_BIN):)
$(Q) $(ESPTOOL_CMDLINE) image_info -v2 $(RBOOT_BIN)


endif # RBOOT_EMULATION
13 changes: 0 additions & 13 deletions Sming/Components/rboot/include/rboot-integration.h

This file was deleted.

2 changes: 1 addition & 1 deletion Sming/Components/rboot/rboot
Submodule rboot updated 5 files
+2 −27 Makefile
+0 −10 README.rst
+5 −4 appcode/rboot-api.c
+0 −4 rboot-stage2a.c
+0 −4 rboot.h

0 comments on commit b9029a2

Please sign in to comment.