Merge branch 'bugfix/esptool_elf2image_flashmode' into 'master'

esptool_py: pass flash mode/frequency/size to elf2image

See merge request espressif/esp-idf!7440
This commit is contained in:
Angus Gratton 2020-01-28 14:22:35 +08:00
commit f5b82c5b1f
4 changed files with 80 additions and 13 deletions

View file

@ -22,15 +22,7 @@ if(NOT BOOTLOADER_BUILD)
# Generate flasher_args.json for tools that need it. The variables below are used
# in configuring the template flasher_args.json.in.
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY_FLASH_OPTIONS
--flash_mode ${ESPFLASHMODE}
--flash_freq ${ESPFLASHFREQ}
--flash_size ${ESPFLASHSIZE}
)
# Some of the variables (flash mode, size, frequency) are already set in project_include.cmake.
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")

View file

@ -8,6 +8,16 @@ set(ESPTOOLPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip ${
set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py")
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY_FLASH_OPTIONS
--flash_mode ${ESPFLASHMODE}
--flash_freq ${ESPFLASHFREQ}
--flash_size ${ESPFLASHSIZE}
)
if(NOT BOOTLOADER_BUILD)
set(esptool_elf2image_args --elf-sha256-offset 0xb0)
endif()
@ -128,12 +138,9 @@ else()
list(APPEND esptool_flash_main_args "--after=${CONFIG_ESPTOOLPY_AFTER}")
endif()
set(esptool_flash_sub_args "--flash_mode=${CONFIG_ESPTOOLPY_FLASHMODE}"
"--flash_freq=${CONFIG_ESPTOOLPY_FLASHFREQ}"
"--flash_size=${CONFIG_ESPTOOLPY_FLASHSIZE}")
idf_component_set_property(esptool_py FLASH_ARGS "${esptool_flash_main_args}")
idf_component_set_property(esptool_py FLASH_SUB_ARGS "${esptool_flash_sub_args}")
idf_component_set_property(esptool_py FLASH_SUB_ARGS "${ESPTOOLPY_FLASH_OPTIONS}")
function(esptool_py_flash_target_image target_name image_name offset image)
idf_build_get_property(build_dir BUILD_DIR)

View file

@ -288,6 +288,25 @@ function run_tests()
( make 2>&1 | grep "does not fit in configured flash size 1MB" ) || failure "Build didn't fail with expected flash size failure message"
mv sdkconfig.bak sdkconfig
print_status "Flash size is correctly set in the bootloader image header"
# Build with the default 2MB setting
rm sdkconfig
make defconfig && make bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0210"
# Change to 4MB
echo "CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y" > sdkconfig
make defconfig && make bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0220"
# Change to QIO, bootloader should still be DIO (will change to QIO in 2nd stage bootloader)
echo "CONFIG_FLASHMODE_QIO=y" > sdkconfig
make defconfig && make bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0210"
# Change to 80 MHz
echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" > sdkconfig
make defconfig && make bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "021f"
rm sdkconfig
print_status "sdkconfig should have contents of all files: sdkconfig, sdkconfig.defaults, sdkconfig.defaults.IDF_TARGET"
make clean > /dev/null;
rm -f sdkconfig.defaults;
@ -491,5 +510,17 @@ function clean_build_dir()
rm -rf --preserve-root ${BUILD}/*
}
# check the bytes 3-4 of the binary image header. e.g.:
# bin_header_match app.bin 0210
function bin_header_match()
{
expected=$2
filename=$1
actual=$(xxd -s 2 -l 2 -ps $1)
if [ ! "$expected" = "$actual" ]; then
failure "Incorrect binary image header, expected $expected got $actual"
fi
}
cd ${TESTDIR}
run_tests

View file

@ -595,6 +595,31 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
rm idf_project.yml
git checkout main/main.c
print_status "Build fails if partitions don't fit in flash"
sed -i.bak "s/CONFIG_ESPTOOLPY_FLASHSIZE.\+//" sdkconfig # remove all flashsize config
echo "CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y" >> sdkconfig # introduce undersize flash
( idf.py build 2>&1 | grep "does not fit in configured flash size 1MB" ) || failure "Build didn't fail with expected flash size failure message"
mv sdkconfig.bak sdkconfig
print_status "Flash size is correctly set in the bootloader image header"
# Build with the default 2MB setting
rm sdkconfig
idf.py bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0210"
# Change to 4MB
echo "CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y" > sdkconfig
idf.py bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0220"
# Change to QIO, bootloader should still be DIO (will change to QIO in 2nd stage bootloader)
echo "CONFIG_FLASHMODE_QIO=y" > sdkconfig
idf.py bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "0210"
# Change to 80 MHz
echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" > sdkconfig
idf.py bootloader || failure "Failed to build bootloader"
bin_header_match build/bootloader/bootloader.bin "021f"
rm sdkconfig
print_status "All tests completed"
if [ -n "${FAILURES}" ]; then
echo "Some failures were detected:"
@ -722,5 +747,17 @@ function clean_build_dir()
rm -rf $PRESERVE_ROOT_ARG ${BUILD}/* ${BUILD}/.*
}
# check the bytes 3-4 of the binary image header. e.g.:
# bin_header_match app.bin 0210
function bin_header_match()
{
expected=$2
filename=$1
actual=$(xxd -s 2 -l 2 -ps $1)
if [ ! "$expected" = "$actual" ]; then
failure "Incorrect binary image header, expected $expected got $actual"
fi
}
cd ${TESTDIR}
run_tests