Skip to content

Commit f5b82c5

Browse files
committed
Merge branch 'bugfix/esptool_elf2image_flashmode' into 'master'
esptool_py: pass flash mode/frequency/size to elf2image See merge request espressif/esp-idf!7440
2 parents 37edc8f + cbb6bec commit f5b82c5

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

components/esptool_py/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@ if(NOT BOOTLOADER_BUILD)
2222

2323
# Generate flasher_args.json for tools that need it. The variables below are used
2424
# in configuring the template flasher_args.json.in.
25-
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
26-
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
27-
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
28-
29-
set(ESPTOOLPY_FLASH_OPTIONS
30-
--flash_mode ${ESPFLASHMODE}
31-
--flash_freq ${ESPFLASHFREQ}
32-
--flash_size ${ESPFLASHSIZE}
33-
)
25+
# Some of the variables (flash mode, size, frequency) are already set in project_include.cmake.
3426

3527
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
3628
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")

components/esptool_py/project_include.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ set(ESPTOOLPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip ${
88
set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
99
set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py")
1010

11+
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
12+
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
13+
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
14+
15+
set(ESPTOOLPY_FLASH_OPTIONS
16+
--flash_mode ${ESPFLASHMODE}
17+
--flash_freq ${ESPFLASHFREQ}
18+
--flash_size ${ESPFLASHSIZE}
19+
)
20+
1121
if(NOT BOOTLOADER_BUILD)
1222
set(esptool_elf2image_args --elf-sha256-offset 0xb0)
1323
endif()
@@ -128,12 +138,9 @@ else()
128138
list(APPEND esptool_flash_main_args "--after=${CONFIG_ESPTOOLPY_AFTER}")
129139
endif()
130140

131-
set(esptool_flash_sub_args "--flash_mode=${CONFIG_ESPTOOLPY_FLASHMODE}"
132-
"--flash_freq=${CONFIG_ESPTOOLPY_FLASHFREQ}"
133-
"--flash_size=${CONFIG_ESPTOOLPY_FLASHSIZE}")
134141

135142
idf_component_set_property(esptool_py FLASH_ARGS "${esptool_flash_main_args}")
136-
idf_component_set_property(esptool_py FLASH_SUB_ARGS "${esptool_flash_sub_args}")
143+
idf_component_set_property(esptool_py FLASH_SUB_ARGS "${ESPTOOLPY_FLASH_OPTIONS}")
137144

138145
function(esptool_py_flash_target_image target_name image_name offset image)
139146
idf_build_get_property(build_dir BUILD_DIR)

tools/ci/test_build_system.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,25 @@ function run_tests()
288288
( make 2>&1 | grep "does not fit in configured flash size 1MB" ) || failure "Build didn't fail with expected flash size failure message"
289289
mv sdkconfig.bak sdkconfig
290290

291+
print_status "Flash size is correctly set in the bootloader image header"
292+
# Build with the default 2MB setting
293+
rm sdkconfig
294+
make defconfig && make bootloader || failure "Failed to build bootloader"
295+
bin_header_match build/bootloader/bootloader.bin "0210"
296+
# Change to 4MB
297+
echo "CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y" > sdkconfig
298+
make defconfig && make bootloader || failure "Failed to build bootloader"
299+
bin_header_match build/bootloader/bootloader.bin "0220"
300+
# Change to QIO, bootloader should still be DIO (will change to QIO in 2nd stage bootloader)
301+
echo "CONFIG_FLASHMODE_QIO=y" > sdkconfig
302+
make defconfig && make bootloader || failure "Failed to build bootloader"
303+
bin_header_match build/bootloader/bootloader.bin "0210"
304+
# Change to 80 MHz
305+
echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" > sdkconfig
306+
make defconfig && make bootloader || failure "Failed to build bootloader"
307+
bin_header_match build/bootloader/bootloader.bin "021f"
308+
rm sdkconfig
309+
291310
print_status "sdkconfig should have contents of all files: sdkconfig, sdkconfig.defaults, sdkconfig.defaults.IDF_TARGET"
292311
make clean > /dev/null;
293312
rm -f sdkconfig.defaults;
@@ -491,5 +510,17 @@ function clean_build_dir()
491510
rm -rf --preserve-root ${BUILD}/*
492511
}
493512

513+
# check the bytes 3-4 of the binary image header. e.g.:
514+
# bin_header_match app.bin 0210
515+
function bin_header_match()
516+
{
517+
expected=$2
518+
filename=$1
519+
actual=$(xxd -s 2 -l 2 -ps $1)
520+
if [ ! "$expected" = "$actual" ]; then
521+
failure "Incorrect binary image header, expected $expected got $actual"
522+
fi
523+
}
524+
494525
cd ${TESTDIR}
495526
run_tests

tools/ci/test_build_system_cmake.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,31 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
595595
rm idf_project.yml
596596
git checkout main/main.c
597597

598+
print_status "Build fails if partitions don't fit in flash"
599+
sed -i.bak "s/CONFIG_ESPTOOLPY_FLASHSIZE.\+//" sdkconfig # remove all flashsize config
600+
echo "CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y" >> sdkconfig # introduce undersize flash
601+
( 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"
602+
mv sdkconfig.bak sdkconfig
603+
604+
print_status "Flash size is correctly set in the bootloader image header"
605+
# Build with the default 2MB setting
606+
rm sdkconfig
607+
idf.py bootloader || failure "Failed to build bootloader"
608+
bin_header_match build/bootloader/bootloader.bin "0210"
609+
# Change to 4MB
610+
echo "CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y" > sdkconfig
611+
idf.py bootloader || failure "Failed to build bootloader"
612+
bin_header_match build/bootloader/bootloader.bin "0220"
613+
# Change to QIO, bootloader should still be DIO (will change to QIO in 2nd stage bootloader)
614+
echo "CONFIG_FLASHMODE_QIO=y" > sdkconfig
615+
idf.py bootloader || failure "Failed to build bootloader"
616+
bin_header_match build/bootloader/bootloader.bin "0210"
617+
# Change to 80 MHz
618+
echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" > sdkconfig
619+
idf.py bootloader || failure "Failed to build bootloader"
620+
bin_header_match build/bootloader/bootloader.bin "021f"
621+
rm sdkconfig
622+
598623
print_status "All tests completed"
599624
if [ -n "${FAILURES}" ]; then
600625
echo "Some failures were detected:"
@@ -722,5 +747,17 @@ function clean_build_dir()
722747
rm -rf $PRESERVE_ROOT_ARG ${BUILD}/* ${BUILD}/.*
723748
}
724749

750+
# check the bytes 3-4 of the binary image header. e.g.:
751+
# bin_header_match app.bin 0210
752+
function bin_header_match()
753+
{
754+
expected=$2
755+
filename=$1
756+
actual=$(xxd -s 2 -l 2 -ps $1)
757+
if [ ! "$expected" = "$actual" ]; then
758+
failure "Incorrect binary image header, expected $expected got $actual"
759+
fi
760+
}
761+
725762
cd ${TESTDIR}
726763
run_tests

0 commit comments

Comments
 (0)