Skip to content

Commit 5fc54c9

Browse files
committed
ESP32: update mkimage tool in order to support different boot.avm partitions
Add support for `--boot` option so a different esp32boot.avm file (e.g. the one with Elixir support) can be used. Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent 112945b commit 5fc54c9

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.github/workflows/esp32-mkimage.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ jobs:
135135
- name: "Create a ${{ matrix.soc }}${{ matrix.flavor }} image"
136136
working-directory: ./src/platforms/esp32/build
137137
run: |
138-
./mkimage.sh
139-
if [ ! -z "${{ matrix.flavor }}" ]
138+
if [ -z "${{ matrix.flavor }}" ]
140139
then
140+
./mkimage.sh
141+
else
142+
FLAVOR_SUFFIX=$(echo "${{ matrix.flavor }}" | sed 's/-//g')
143+
BOOT_FILE="build/libs/esp32boot/${FLAVOR_SUFFIX}_esp32boot.avm"
144+
./mkimage.sh --boot="$BOOT_FILE"
141145
mv atomvm-${{ matrix.soc }}.img atomvm-${{ matrix.soc }}${{ matrix.flavor }}.img
142146
fi
143147
ls -l *.img

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- ESP32: add a new Elixir release "flavor" with a bigger boot.avm partition that has room for
1212
Elixir standard library modules
13+
- ESP32: `--boot` option to mkimage.sh tool
1314

1415
### Changed
1516

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#{
3939
name => "AtomVM Boot and Core BEAM Library",
4040
offset => "0x1D0000",
41-
path => ["${BUILD_DIR}/../../../../build/libs/esp32boot/esp32boot.avm"]
41+
path => ["$[BOOT_FILE]"]
4242
}
4343
]
4444
}.

src/platforms/esp32/tools/mkimage.erl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ do_main(Argv) ->
4242
RootDir ->
4343
try
4444
Config = load_config(maps:get(config, Opts, "mkimage.config")),
45+
BuildDir = get_build_dir(Opts, RootDir),
46+
BootFile = BuildDir ++ "/libs/esp32boot/esp32boot.avm",
4547
mkimage(
4648
RootDir,
47-
get_build_dir(Opts, RootDir),
49+
BuildDir,
50+
maps:get(boot, Opts, BootFile),
4851
maps:get(out, Opts, "atomvm.img"),
4952
maps:get(segments, Config)
5053
),
@@ -65,6 +68,8 @@ parse_args(Argv) ->
6568
%% @private
6669
parse_args([], {Opts, Args}) ->
6770
{Opts, lists:reverse(Args)};
71+
parse_args(["--boot", Path | T], {Opts, Args}) ->
72+
parse_args(T, {Opts#{boot => Path}, Args});
6873
parse_args(["--out", Path | T], {Opts, Args}) ->
6974
parse_args(T, {Opts#{out => Path}, Args});
7075
parse_args(["--root_dir", Path | T], {Opts, Args}) ->
@@ -92,6 +97,7 @@ print_help() ->
9297
"The following options are supported:"
9398
"~n"
9499
" * --root_dir <path> Path to the root directory of the AtomVM git checkout~n"
100+
" * --boot <path> Path to a esp32boot.avm file~n"
95101
" * --build_dir <path> Path to the AtomVM build directory (defaults to root_dir/build, if unspecifeid)~n"
96102
" * --out <path> Output path for AtomVM image file~n"
97103
" * --config <path> Path to mkimage configuration file~n"
@@ -124,7 +130,7 @@ get_build_dir(Opts, RootDir) ->
124130
end.
125131

126132
%% @private
127-
mkimage(RootDir, BuildDir, OutputFile, Segments) ->
133+
mkimage(RootDir, BuildDir, BootFile, OutputFile, Segments) ->
128134
io:format("Writing output to ~s~n", [OutputFile]),
129135
io:format("=============================================~n"),
130136
case file:open(OutputFile, [write, binary]) of
@@ -156,7 +162,7 @@ mkimage(RootDir, BuildDir, OutputFile, Segments) ->
156162
end
157163
end,
158164
SegmentPaths = [
159-
replace("BUILD_DIR", BuildDir, replace("ROOT_DIR", RootDir, SegmentPath))
165+
replace("BUILD_DIR", BuildDir, replace("BOOT_FILE", BootFile, replace("ROOT_DIR", RootDir, SegmentPath)))
160166
|| SegmentPath <- maps:get(path, Segment)
161167
],
162168
case try_read(SegmentPaths) of
@@ -200,4 +206,5 @@ from_hex([$0, $x | Bits]) ->
200206

201207
%% @private
202208
replace(VariableName, Value, String) ->
203-
string:replace(String, io_lib:format("${~s}", [VariableName]), Value).
209+
string:replace(String, io_lib:format("${~s}", [VariableName]), Value),
210+
string:replace(String, io_lib:format("$[~s]", [VariableName]), Value).

0 commit comments

Comments
 (0)