Skip to content

Commit 89d821c

Browse files
committed
Update build scripts to support the requirements for ESP32-S3
1 parent 700b9b9 commit 89d821c

27 files changed

+628
-7536
lines changed

Diff for: CMakeLists.txt

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,31 @@ endif()
99
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
1010
project(arduino-lib-builder)
1111

12+
idf_build_get_property(elf EXECUTABLE GENERATOR_EXPRESSION)
13+
1214
add_custom_command(
1315
OUTPUT "idf_libs"
14-
COMMAND ${CMAKE_SOURCE_DIR}/tools/prepare-libs.sh ${IDF_TARGET}
15-
DEPENDS gen_project_binary bootloader partition_table
16+
COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-libs.sh ${IDF_TARGET} "${CONFIG_ESPTOOLPY_OCT_FLASH}" "${CONFIG_SPIRAM_MODE_OCT}"
17+
DEPENDS ${elf}
18+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
19+
VERBATIM
20+
)
21+
add_custom_target(idf-libs DEPENDS "idf_libs")
22+
23+
add_custom_command(
24+
OUTPUT "copy_bootloader"
25+
COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-bootloader.sh ${IDF_TARGET} "${CONFIG_LIB_BUILDER_FLASHMODE}" "${CONFIG_LIB_BUILDER_FLASHFREQ}"
26+
DEPENDS bootloader
27+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
28+
VERBATIM
29+
)
30+
add_custom_target(copy-bootloader DEPENDS "copy_bootloader")
31+
32+
add_custom_command(
33+
OUTPUT "mem_variant"
34+
COMMAND ${CMAKE_SOURCE_DIR}/tools/copy-mem-variant.sh ${IDF_TARGET} "${CONFIG_ESPTOOLPY_OCT_FLASH}" "${CONFIG_SPIRAM_MODE_OCT}"
35+
DEPENDS ${elf}
1636
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1737
VERBATIM
1838
)
19-
add_custom_target(idf-libs ALL DEPENDS "idf_libs")
39+
add_custom_target(mem-variant DEPENDS "mem_variant")

Diff for: build.sh

+154-31
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,173 @@
11
#!/bin/bash
22

33
if ! [ -x "$(command -v python)" ]; then
4-
echo "ERROR: python is not installed! Please install python first."
5-
exit 1
4+
echo "ERROR: python is not installed! Please install python first."
5+
exit 1
66
fi
77

88
if ! [ -x "$(command -v git)" ]; then
9-
echo "ERROR: git is not installed! Please install git first."
10-
exit 1
9+
echo "ERROR: git is not installed! Please install git first."
10+
exit 1
1111
fi
1212

13-
mkdir -p dist
13+
TARGET="all"
14+
BUILD_TYPE="all"
15+
SKIP_ENV=0
16+
COPY_OUT=0
17+
DEPLOY_OUT=0
1418

15-
# update components from git
16-
./tools/update-components.sh
17-
if [ $? -ne 0 ]; then exit 1; fi
19+
function print_help() {
20+
echo "Usage: build.sh [-s] [-A arduino_branch] [-I idf_branch] [-i idf_commit] [-a path] [-t <target>] [-b <build|menuconfig|idf_libs|copy_bootloader|mem_variant>] [config ...]"
21+
echo " -s Skip installing/updating of ESP-IDF and all components"
22+
echo " -A Set which branch of arduino-esp32 to be used for compilation"
23+
echo " -I Set which branch of ESP-IDF to be used for compilation"
24+
echo " -i Set which commit of ESP-IDF to be used for compilation"
25+
echo " -d Deploy the build to github arduino-esp32"
26+
echo " -a Set the arduino-esp32 folder to copy the result to. ex. '$HOME/Arduino/hardware/espressif/esp32'"
27+
echo " -t Set the build target(chip). ex. 'esp32s3'"
28+
echo " -b Set the build type. ex. 'build' to build the project and prepare for uploading to a board"
29+
echo " ... Specify additional configs to be applied. ex. 'qio 80m' to compile for QIO Flash@80MHz. Requires -b"
30+
exit 1
31+
}
1832

19-
# install esp-idf and gcc toolchain
20-
source ./tools/install-esp-idf.sh
21-
if [ $? -ne 0 ]; then exit 1; fi
33+
while getopts ":A:I:i:a:t:b:sd" opt; do
34+
case ${opt} in
35+
s )
36+
SKIP_ENV=1
37+
;;
38+
d )
39+
DEPLOY_OUT=1
40+
;;
41+
a )
42+
export ESP32_ARDUINO="$OPTARG"
43+
COPY_OUT=1
44+
;;
45+
A )
46+
export AR_BRANCH="$OPTARG"
47+
;;
48+
I )
49+
export IDF_BRANCH="$OPTARG"
50+
;;
51+
i )
52+
export IDF_COMMIT="$OPTARG"
53+
;;
54+
t )
55+
TARGET=$OPTARG
56+
;;
57+
b )
58+
b=$OPTARG
59+
if [ "$b" != "build" ] &&
60+
[ "$b" != "menuconfig" ] &&
61+
[ "$b" != "idf_libs" ] &&
62+
[ "$b" != "copy_bootloader" ] &&
63+
[ "$b" != "mem_variant" ]; then
64+
print_help
65+
fi
66+
BUILD_TYPE="$b"
67+
;;
68+
\? )
69+
echo "Invalid option: -$OPTARG" 1>&2
70+
print_help
71+
;;
72+
: )
73+
echo "Invalid option: -$OPTARG requires an argument" 1>&2
74+
print_help
75+
;;
76+
esac
77+
done
78+
shift $((OPTIND -1))
79+
CONFIGS=$@
80+
81+
if [ $SKIP_ENV -eq 0 ]; then
82+
echo "* Installing/Updating ESP-IDF and all components..."
83+
# update components from git
84+
./tools/update-components.sh
85+
if [ $? -ne 0 ]; then exit 1; fi
86+
87+
# install esp-idf and gcc toolchain
88+
source ./tools/install-esp-idf.sh
89+
if [ $? -ne 0 ]; then exit 1; fi
90+
else
91+
source ./tools/config.sh
92+
fi
2293

23-
if [ -z $TARGETS ]; then
24-
TARGETS="esp32s3 esp32c3 esp32s2 esp32"
94+
if [ "$BUILD_TYPE" != "all" ]; then
95+
if [ "$TARGET" = "all" ]; then
96+
echo "ERROR: You need to specify target for non-default builds"
97+
print_help
98+
fi
99+
configs="configs/defconfig.common;configs/defconfig.$TARGET"
100+
for conf in $CONFIGS; do
101+
configs="$configs;configs/defconfig.$conf"
102+
done
103+
echo "idf.py -DIDF_TARGET=\"$TARGET\" -DSDKCONFIG_DEFAULTS=\"$configs\" $BUILD_TYPE"
104+
rm -rf build sdkconfig
105+
idf.py -DIDF_TARGET="$TARGET" -DSDKCONFIG_DEFAULTS="$configs" $BUILD_TYPE
106+
if [ $? -ne 0 ]; then exit 1; fi
107+
exit 0
25108
fi
26109

110+
rm -rf build sdkconfig out
111+
27112
echo $(git -C $AR_COMPS/arduino describe --all --long) > version.txt
28113

29-
rm -rf out build sdkconfig sdkconfig.old
30-
31-
for target in $TARGETS; do
32-
# configure the build for the target
33-
rm -rf build sdkconfig sdkconfig.old
34-
cp "sdkconfig.$target" sdkconfig
35-
# uncomment next line to access menuconfig
36-
# idf.py menuconfig
37-
# build and prepare libs
38-
idf.py build
39-
if [ $? -ne 0 ]; then exit 1; fi
40-
cp sdkconfig "sdkconfig.$target"
41-
# build bootloaders
42-
./tools/build-bootloaders.sh
43-
if [ $? -ne 0 ]; then exit 1; fi
114+
for target_json in `jq -c '.targets[]' configs/builds.json`; do
115+
target=$(echo "$target_json" | jq -c '.target' | tr -d '"')
116+
117+
if [ "$TARGET" != "all" ] && [ "$TARGET" != "$target" ]; then
118+
echo "* Skipping Target: $target"
119+
continue
120+
fi
121+
122+
echo "* Target: $target"
123+
main_configs="configs/defconfig.common;configs/defconfig.$target"
124+
125+
# Build IDF Libs
126+
idf_libs_configs="$main_configs"
127+
for defconf in `echo "$target_json" | jq -c '.idf_libs[]' | tr -d '"'`; do
128+
idf_libs_configs="$idf_libs_configs;configs/defconfig.$defconf"
129+
done
130+
echo "* Build IDF-Libs: $idf_libs_configs"
131+
rm -rf build sdkconfig
132+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$idf_libs_configs" idf_libs
133+
if [ $? -ne 0 ]; then exit 1; fi
134+
135+
# Build Bootloaders
136+
for boot_conf in `echo "$target_json" | jq -c '.bootloaders[]'`; do
137+
bootloader_configs="$main_configs"
138+
for defconf in `echo "$boot_conf" | jq -c '.[]' | tr -d '"'`; do
139+
bootloader_configs="$bootloader_configs;configs/defconfig.$defconf"
140+
done
141+
echo "* Build BootLoader: $bootloader_configs"
142+
rm -rf build sdkconfig
143+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$bootloader_configs" copy_bootloader
144+
if [ $? -ne 0 ]; then exit 1; fi
145+
done
146+
147+
# Build Memory Variants
148+
for mem_conf in `echo "$target_json" | jq -c '.mem_variants[]'`; do
149+
mem_configs="$main_configs"
150+
for defconf in `echo "$mem_conf" | jq -c '.[]' | tr -d '"'`; do
151+
mem_configs="$mem_configs;configs/defconfig.$defconf"
152+
done
153+
echo "* Build Memory Variant: $mem_configs"
154+
rm -rf build sdkconfig
155+
idf.py -DIDF_TARGET="$target" -DSDKCONFIG_DEFAULTS="$mem_configs" mem_variant
156+
if [ $? -ne 0 ]; then exit 1; fi
157+
done
44158
done
45159

46160
# archive the build
47-
./tools/archive-build.sh
48-
if [ $? -ne 0 ]; then exit 1; fi
161+
if [ "$TARGET" = "all" ] && [ "$BUILD_TYPE" = "all" ]; then
162+
./tools/archive-build.sh
163+
if [ $? -ne 0 ]; then exit 1; fi
164+
fi
49165

50-
#./tools/copy-to-arduino.sh
166+
# copy everything to arduino-esp32 installation
167+
if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then
168+
./tools/copy-to-arduino.sh
169+
fi
170+
171+
if [ $DEPLOY_OUT -eq 1 ]; then
172+
./tools/push-to-arduino.sh
173+
fi

Diff for: configs/builds.json

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"mem_variants_files":[
3+
{
4+
"file":"libbootloader_support.a",
5+
"src":"build/esp-idf/bootloader_support/libbootloader_support.a",
6+
"out":"lib/libbootloader_support.a"
7+
},
8+
{
9+
"file":"libesp_hw_support.a",
10+
"src":"build/esp-idf/esp_hw_support/libesp_hw_support.a",
11+
"out":"lib/libesp_hw_support.a"
12+
},
13+
{
14+
"file":"libspi_flash.a",
15+
"src":"build/esp-idf/spi_flash/libspi_flash.a",
16+
"out":"lib/libspi_flash.a"
17+
},
18+
{
19+
"file":"libfreertos.a",
20+
"src":"build/esp-idf/freertos/libfreertos.a",
21+
"out":"lib/libfreertos.a"
22+
},
23+
{
24+
"file":"libesp_system.a",
25+
"src":"build/esp-idf/esp_system/libesp_system.a",
26+
"out":"lib/libesp_system.a"
27+
},
28+
{
29+
"file":"sections.ld",
30+
"src":"build/esp-idf/esp_system/ld/sections.ld",
31+
"out":"ld/sections.ld"
32+
}
33+
],
34+
"targets":[
35+
{
36+
"target": "esp32s3",
37+
"idf_libs":["qio","80m"],
38+
"bootloaders":[
39+
["qio","120m"],
40+
["qio","80m"],
41+
["dio","80m"],
42+
["opi_flash","opi_ram","80m"]
43+
],
44+
"mem_variants":[
45+
["opi_ram","80m"],
46+
["opi_flash","opi_ram","80m"]
47+
]
48+
},
49+
{
50+
"target": "esp32s2",
51+
"idf_libs":["qio","80m"],
52+
"bootloaders":[
53+
["qio","80m"],
54+
["qout","80m"],
55+
["dio","80m"],
56+
["dout","80m"],
57+
["qio","40m"],
58+
["qout","40m"],
59+
["dio","40m"],
60+
["dout","40m"]
61+
],
62+
"mem_variants":[]
63+
},
64+
{
65+
"target": "esp32c3",
66+
"idf_libs":["qio","80m"],
67+
"bootloaders":[
68+
["qio","80m"],
69+
["qout","80m"],
70+
["dio","80m"],
71+
["dout","80m"],
72+
["qio","40m"],
73+
["qout","40m"],
74+
["dio","40m"],
75+
["dout","40m"]
76+
],
77+
"mem_variants":[]
78+
},
79+
{
80+
"target": "esp32",
81+
"idf_libs":["dio","40m"],
82+
"bootloaders":[
83+
["qio","80m"],
84+
["qout","80m"],
85+
["dio","80m"],
86+
["dout","80m"],
87+
["qio","40m"],
88+
["qout","40m"],
89+
["dio","40m"],
90+
["dout","40m"]
91+
],
92+
"mem_variants":[]
93+
}
94+
]
95+
}

Diff for: configs/defconfig.120m

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ESPTOOLPY_FLASHFREQ_120M=y
2+
CONFIG_SPIRAM_SPEED_120M=y

Diff for: configs/defconfig.40m

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
2+
CONFIG_SPIRAM_SPEED_40M=y

Diff for: configs/defconfig.80m

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
2+
CONFIG_SPIRAM_SPEED_80M=y

Diff for: configs/defconfig.common

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_AUTOSTART_ARDUINO=y
2+
CONFIG_ARDUINO_UDP_RUN_CORE0=y

Diff for: configs/defconfig.dio

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y

Diff for: configs/defconfig.dout

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y

0 commit comments

Comments
 (0)