77# the host's make system.
88# ###################################################################################################
99
10+ # TODO 2026 have esp tools run from both the venv and then sometimes also directly. This is just a mess of course.
11+ # We should check for a python venv and use this preferentially as teh esp tool path and if it's not there we can fall back
12+ # to the host pythoin environment (assuming this has been setu) and use the tools in the ert-build-support.
13+
1014set -e
1115
1216# If this is called as a docker command we wont have the exported environment variables, so read them from the paramaters
@@ -54,19 +58,37 @@ export EHS_ROOT=`pwd` # assuming we're in the ehs project root
5458pushd ${EHS_ROOT} /..
5559export REPOSITORY_ROOT=` pwd`
5660popd
57- # Check if we are alr
61+
62+ # Note we can use the ates esptool for all versions of esp,buyt allowing for an override
63+ if [ " ${EHS_ESPTOOL_VERSION_OVERRIDE} " = " 5.1.0" ] ; then
64+ # These are probably not necessary for any IDF version, but is not supported in 4.4.1.
65+ EXTRA_ESPTOOL_ARGS=" -min-rev-full 0 --max-rev-full 9999 "
66+ export TOOLCHAIN_VERSION=" xtensa-esp32-elf-5.1.0"
67+ else
68+ # default for anything else
69+ EXTRA_ESPTOOL_ARGS=
70+ export TOOLCHAIN_VERSION=" xtensa-esp32-elf-4.4.1"
71+ fi
72+
73+ # These tools haven't changed, so we can just use the 4.4.4 for all versions of IDF apparently
74+
75+ export TEMP_PWD=${PWD}
76+ INX_HOST_ARCH=$( uname -m)
77+ TOOLCHAIN_PATH=" ${TEMP_PWD} /../ert-build-support/toolchains/${INX_HOST_ARCH} /${TOOLCHAIN_VERSION} "
78+
79+ export IDF_PYTHON_ENV_BASE=" ../../TARGET_TREES/esp32_venv/"
80+ export IDF_ESPTOOL_BASE=" ${TOOLCHAIN_PATH} /${TOOLCHAIN_FLASHING_VERSION} /tools"
81+
82+ # Check if we are in docker sowe don't try to install IDF's grim python tools again
5883if [ -f /.dockerenv ]; then
5984 echo " Already running in Docker continuing"
6085 export PATH=" /opt/python_env/bin:$PATH "
6186else
62- # todo Do we need to do this really?
63- # Presumably this is attempting to create the python environment on the host?
87+ # If for some reason we don't have a python venv environment we can try and run the host
88+ # TODO see above note on this being an agregation of of mind-farts.
89+
6490 # The following would be better picked from config.mk rather than hardwired, but would need to passed in for Docker builds.
6591
66- export TOOLCHAIN_VERSION=" xtensa-esp32-elf-4.4.4"
67- export TEMP_PWD=${PWD}
68- INX_HOST_ARCH=$( uname -m)
69- TOOLCHAIN_PATH=" ${TEMP_PWD} /../ert-build-support/toolchains/${INX_HOST_ARCH} /${TOOLCHAIN_VERSION} "
7092 _PATH=" ${TOOLCHAIN_PATH} /bin"
7193
7294 # # Create python virtual environment, install requirements and export it to PATH
7698 # todo-we should consider if we need a nother temporary directory for tools that are built per host machine (TARHGET_TREES is not very descriptive)
7799 # Note there is also a venv that might be built into /opt/python_env - this is typically only generated for workstaions that flash devices.
78100
79- export IDF_PYTHON_ENV_BASE=" ../../TARGET_TREES/esp32_venv/"
80101 python3 -m venv ${IDF_PYTHON_ENV_BASE} > /dev/null
81102 export IDF_PYTHON_ENV_PATH=" ${IDF_PYTHON_ENV_BASE} /bin"
82-
103+
83104 # Set path to the python and toolchain.
84105 _PATH=" ${TOOLCHAIN_PATH} /bin"
85- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin"
106+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin"
86107 _PATH=" ${_PATH: +${_PATH} : }${IDF_PYTHON_ENV_PATH} "
87- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /esptool_py/esptool"
88- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /espcoredump"
89- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /partition_table"
90- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /app_update"
91- _PATH=" ${_PATH: +${_PATH} : }${TOOLCHAIN_PATH} / ${TOOLCHAIN_FLASHING_VERSION} /tools /additional_tools"
108+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /esptool_py/esptool"
109+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /espcoredump"
110+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /partition_table"
111+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /app_update"
112+ _PATH=" ${_PATH: +${_PATH} : }${IDF_ESPTOOL_BASE} /additional_tools"
92113 export PATH=" ${_PATH}${PATH: +: ${PATH} } "
93114 # Start the python virutal environment.
94115 sudo python3 -m venv /opt/python_env
@@ -108,25 +129,24 @@ echo "### Building .bin file for esp32 from .elf file "
108129echo " Location of the elf file:"
109130echo " ehs_esp32s3_freertos-xtensa-base.elf # or use this: $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.exe"
110131echo " ---------------------------------------------------------------------------------------------------------------------------"
111- # what was this?? e --flash_mode "dio" --flash_freq "40m" --flash_size "4MB" --elf-sha256-offset 0xb0 ehs_esp32s3_freertos-xtensor-base.elf -o $PWD/../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/ehs.bin
112- # Older toolchains don't support all arguements
113- if [ " ${TOOLCHAIN_NAME} " = " xtensa-esp32-elf-4.4.1" ] ; then
114- EXTRA_ESPTOOL_ARGS=
115- else
116- EXTRA_ESPTOOL_ARGS=-min-rev-full 0 --max-rev-full 9999
117- fi
118132
119- # if python3 ../ert-contrib-middleware/contrib/esp-idf/${CONTRIB_MIDDLWARE_FLASHINGTOOLS_VERSION}/components/esptool_py/esptool/esptool.py --chip esp32 elf2imag
120133
121- if python3 ../ert-contrib-middleware/contrib/esp-idf/${CONTRIB_MIDDLWARE_FLASHINGTOOLS_VERSION} /components/esptool_py/esptool/esptool.py --chip esp32s3 elf2image ${EXTRA_ESPTOOL_ARGS} -ff 80m -fm qio -fs 8MB -o $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.bin $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.exe
134+
135+ # Building the bootable binary from ehs.exe elf file
136+
137+ if python3 ${IDF_ESPTOOL_BASE} /esptool_py/esptool/esptool.py --chip esp32s3 elf2image ${EXTRA_ESPTOOL_ARGS} -ff 80m -fm qio -fs 8MB -o $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.bin $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.exe
122138then
123139 echo " ### Copied ehs.bin file generated in $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/"
124140else
125- echo " !!! ERROR: COULD NOT GENERATE ehs.bin !!!"
141+ echo " !!! ERROR: COULD NOT GENERATE ehs.bin !!!"
142+ exit 1
126143fi
144+
127145echo " 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
146+ echo " Building the full flashable image from bootloader.bin, partition_table and any other partitions (file sytems and OTA etc)"
128147ls -l " $PWD /../ert-contrib-middleware/target_libs/${COMPONENT_BASE_TECHNOLOGIES} /build/lib/"
129148echo " 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
149+
130150if test -f " $PWD /../ert-contrib-middleware/target_libs/${COMPONENT_BASE_TECHNOLOGIES} /build/lib/bootloader.bin"
131151then
132152 echo " ### Copied the pre build bootloader binary (bootloader.bin) into TARGET_TREES ###"
135155 echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
136156 echo " !!! ERROR: COuld not find bootloader.bin in $PWD /../ert-contrib-middleware/target_libs/${COMPONENT_BASE_TECHNOLOGIES} /build/lib/bootloader.bin !!!"
137157 echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
138- exit
158+ exit 1
139159fi
140160
141161# previously know as? "$PWD/../ert-contrib-middleware/contrib/esp-idf/esp-idf-4.4.1/build/partitions.bin"
147167 echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
148168 echo " !!! ERROR: COuld not find partition table (partition-table.bin)) in $PWD /../ert-contrib-middleware/target_libs/${COMPONENT_BASE_TECHNOLOGIES} /build/lib/ !!!"
149169 echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
150- exit
170+ exit 1
151171fi
152172
153173# Convert the application folder to binary image
165185fi
166186done
167187
168- /opt/python_env/bin/littlefs-python create -v --block-size 4096 --fs-size 1572864 --name-max 64 --image $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/data.bin $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /data_partition/
188+ # TODO See comments in head of this document, why we are using the venv scripts here
189+ # todo Presumably we wantthe hardwired sies etc in here to be paramterised so they can be set for speciic platform builds
190+ /opt/python_env/bin/littlefs-python create -v --block-size 4096 --fs-size 1572864 --name-max 64 --image $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/data.bin $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /data_partition/ || exit
169191
170192# Lets build the binary (todo2023 - we should do this in a packer target in the future?? )
171193echo " Converting the elf file to binary image.... (This is usually done by make targetenv_esp32s3)"
172194# python3 ../ert-contrib-middleware/contrib/esp-idf/CONTRIB_MIDDLWARE_FLASHINGTOOLS_VERSION/components/esptool_py/esptool/esptool.py --chip esp32s3 merge_bin -o $PWD/../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/ehs.img --flash_mode dio --flash_size 8MB 0x0 $PWD/../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/bootloader.bin 0x9000 ../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/partition-table.bin 0x10000 $PWD/../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/ehs.bin 0x410000 $PWD/../TARGET_TREES/ehs_env-$SPECIFIC_TARGET/bin/data.bin
173- python3 ../ert-contrib-middleware/contrib/esp-idf/ ${CONTRIB_MIDDLWARE_FLASHINGTOOLS_VERSION} /components/ esptool_py/esptool/esptool.py --chip esp32s3 merge_bin -o $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.img --flash_mode dio --flash_size 8MB 0x0 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/bootloader.bin 0x9000 ../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/partition-table.bin 0x20000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.bin 0x67c000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/data.bin 0x5ff000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/app_data.bin
195+ python3 ${IDF_ESPTOOL_BASE} / esptool_py/esptool/esptool.py --chip esp32s3 merge_bin -o $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.img --flash_mode dio --flash_size 8MB 0x0 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/bootloader.bin 0x9000 ../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/partition-table.bin 0x20000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/ehs.bin 0x67c000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/data.bin 0x5ff000 $PWD /../TARGET_TREES/ehs_env-$SPECIFIC_TARGET /bin/app_data.bin || exit 1
174196
175197echo " ---------------------------------------------------------------------------------------------------------------------------"
176198echo " All Done!"
0 commit comments