Skip to content

Commit 17ecd4d

Browse files
committed
Streamline ESP32 image creation
Modifies the ESP32 build configuration and mkimage tool to automatically detect the image flavor based on the partition table used. By checking the offset of the application partition the correct flavor of language support is used when creating images. Adds a config option to configure an Elixir supported build by using `idf.py fullclean reconfigure -DAVM_ELIXIR_BOOT="y"` (sdkconfig must be deleted first). Signed-off-by: Winford <[email protected]>
1 parent 444b166 commit 17ecd4d

File tree

10 files changed

+64
-15
lines changed

10 files changed

+64
-15
lines changed

.github/workflows/esp32-mkimage.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ jobs:
148148
then
149149
./mkimage.sh
150150
else
151-
FLAVOR_SUFFIX=$(echo "${{ matrix.flavor }}" | sed 's/-//g')
152-
BOOT_FILE="../../../../build/libs/esp32boot/${FLAVOR_SUFFIX}_esp32boot.avm"
153-
./mkimage.sh --boot "$BOOT_FILE"
151+
./mkimage.sh
154152
mv atomvm-${{ matrix.soc }}.img atomvm-${{ matrix.soc }}${{ matrix.flavor }}.img
155153
fi
156154
ls -l *.img

src/platforms/esp32/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2017-2025 Davide Bettio <[email protected]>
2+
# Copyright 2025 Winford (Uncle Grumpy) <[email protected]>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
5+
6+
sdkconfig.defaults

src/platforms/esp32/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ endif()
5151
# On Esp32, select is run in a loop in a dedicated task
5252
set(AVM_SELECT_IN_TASK ON)
5353

54+
## Configure partiton table based on boot flavor
55+
if (${AVM_ELIXIR_BOOT} MATCHES "ON|On|on|Y|y|YES|Yes|yes")
56+
set(AVM_PARTITION_TABLE_FILENAME "partitions-elixir.csv")
57+
else()
58+
set(AVM_PARTITION_TABLE_FILENAME "partitions.csv")
59+
endif()
60+
61+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sdkconfig.defaults.in ${CMAKE_CURRENT_SOURCE_DIR}/sdkconfig.defaults @ONLY)
62+
5463
project(atomvm-esp32)
5564

5665
# esp-idf does not use compile_feature but instead sets version in
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2025 Winford (Uncle Grumpy) <[email protected]>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
#
20+
21+
partition_table_get_partition_info(app_offset "--partition-name main.avm" "offset")
22+
if ("${app_offset}" STREQUAL "0x210000")
23+
set(BOOT_LIBS "esp32boot.avm")
24+
elseif ("${app_offset}" STREQUAL "0x250000")
25+
set(BOOT_LIBS "elixir_esp32boot.avm")
26+
else()
27+
message(FATAL_ERROR "Unable to determine esp32boot flavor from offset: ${app_offset}")
28+
endif()
29+

src/platforms/esp32/sdkconfig.defaults

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_PARTITION_TABLE_CUSTOM=y
2+
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
3+
CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
4+
CONFIG_LWIP_IPV6=n
5+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="@AVM_PARTITION_TABLE_FILENAME@"
6+
CONFIG_PARTITION_TABLE_FILENAME="@AVM_PARTITION_TABLE_FILENAME@"

src/platforms/esp32/tools/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cmake_minimum_required (VERSION 3.13)
2222
project (ReleaseEsp32)
2323
include(../../../../version.cmake)
2424
include(../../../../CMakeModules/GetVersion.cmake)
25+
include(../GetBootAVM.cmake)
2526

2627
## Build image tools for target chip
2728

@@ -45,6 +46,13 @@ elseif(${CONFIG_IDF_TARGET} STREQUAL "esp32p4")
4546
set(BOOTLOADER_OFFSET "0x2000")
4647
endif()
4748

49+
if (NOT EXISTS ../../../../build/libs/esp32boot/${BOOT_LIBS})
50+
message(WARNING "A generic_unix build must be done first in the top level AtomVM/build directory! \n\
51+
Consult https://doc.atomvm.org/main/build-instructions.html for build instructions.")
52+
endif()
53+
54+
set(ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../")
55+
4856
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mkimage.config.in ${CMAKE_BINARY_DIR}/mkimage.config)
4957

5058
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../../../tools/dev/flash.sh ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/flash.sh COPYONLY)
@@ -64,7 +72,3 @@ file(COPY ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/flash.sh
6472
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
6573
)
6674

67-
if (NOT EXISTS ../../../../build/libs/esp32boot/${BOOT_LIBS})
68-
message(WARNING "A generic_unix build must be done first in the top level AtomVM/build directory! \n\
69-
Consult https://doc.atomvm.org/main/build-instructions.html for build instructions.")
70-
endif()

src/platforms/esp32/tools/mkimage.config.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
#{
3434
name => "AtomVM Virtual Machine",
3535
offset => "0x10000",
36-
path => ["${BUILD_DIR}/atomvm-esp32.bin", "${ROOT_DIR}/src/platforms/esp32/build/atomvvm-esp32.bin"]
36+
path => ["${BUILD_DIR}/atomvm-esp32.bin", "${ROOT_DIR}/src/platforms/esp32/build/atomvm-esp32.bin"]
3737
},
3838
#{
3939
name => "AtomVM Boot and Core BEAM Library",
4040
offset => "0x1D0000",
41-
path => ["$[BOOT_FILE]"]
41+
path => ["${ROOT_DIR}/build/libs/esp32boot/${BOOT_LIBS}"]
4242
}
4343
]
4444
}.

src/platforms/esp32/tools/mkimage.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ do_main(Argv) ->
4343
try
4444
Config = load_config(maps:get(config, Opts, "mkimage.config")),
4545
BuildDir = get_build_dir(Opts, RootDir),
46-
BootFile = BuildDir ++ "/libs/esp32boot/esp32boot.avm",
46+
BootFile = maps:get(boot, Opts, BuildDir ++ "/libs/esp32boot/esp32boot.avm"),
4747
mkimage(
4848
RootDir,
4949
BuildDir,

src/platforms/esp32/tools/mkimage.sh.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ escript "@CMAKE_BINARY_DIR@/mkimage.erl" \
2323
--root_dir "@CMAKE_BINARY_DIR@/../../../.." \
2424
--config "@CMAKE_BINARY_DIR@/mkimage.config" \
2525
--out "@CMAKE_BINARY_DIR@/atomvm-@[email protected]" \
26+
--boot "@CMAKE_BINARY_DIR@/../../../../build/libs/esp32boot/@BOOT_LIBS@"
2627
"$@"
2728

2829
echo "============================================="
2930

3031
echo ""
31-
echo "AtomVM @CONFIG_IDF_TARGET@ version @ATOMVM_VERSION@ image written to:"
32+
echo "AtomVM @CONFIG_IDF_TARGET@ version @ATOMVM_VERSION@ image with @BOOT_LIBS@ libraries written to:"
3233
echo "@CMAKE_BINARY_DIR@/atomvm-@[email protected]"

0 commit comments

Comments
 (0)