Skip to content

Commit

Permalink
ESP32: update mkimage tool in order to support different boot.avm par…
Browse files Browse the repository at this point in the history
…titions

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>
  • Loading branch information
bettio committed Sep 14, 2024
1 parent 07e5896 commit 2c757e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/esp32-mkimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ jobs:
- name: "Create a ${{ matrix.soc }}${{ matrix.flavor }} image"
working-directory: ./src/platforms/esp32/build
run: |
./mkimage.sh
if [ ! -z "${{ matrix.flavor }}" ]
if [ -z "${{ matrix.flavor }}" ]
then
./mkimage.sh
else
FLAVOR_SUFFIX=$(echo "${{ matrix.flavor }}" | sed 's/-//g')
BOOT_FILE="build/libs/esp32boot/${FLAVOR_SUFFIX}_esp32boot.avm"
./mkimage.sh --boot="$BOOT_FILE"
mv ./src/platforms/esp32/build/atomvm-${{ matrix.soc }}.img \
./src/platforms/esp32/build/atomvm-${{ matrix.soc }}${{ matrix.flavor }}.img
fi
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/tools/mkimage.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#{
name => "AtomVM Boot and Core BEAM Library",
offset => "0x1D0000",
path => ["${BUILD_DIR}/../../../../build/libs/esp32boot/esp32boot.avm"]
path => ["$[BOOT_FILE]"]
}
]
}.
15 changes: 11 additions & 4 deletions src/platforms/esp32/tools/mkimage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ do_main(Argv) ->
RootDir ->
try
Config = load_config(maps:get(config, Opts, "mkimage.config")),
BuildDir = get_build_dir(Opts, RootDir),
BootFile = BuildDir ++ "/libs/esp32boot/esp32boot.avm",
mkimage(
RootDir,
get_build_dir(Opts, RootDir),
BuildDir,
maps:get(boot, Opts, BootFile),
maps:get(out, Opts, "atomvm.img"),
maps:get(segments, Config)
),
Expand All @@ -65,6 +68,8 @@ parse_args(Argv) ->
%% @private
parse_args([], {Opts, Args}) ->
{Opts, lists:reverse(Args)};
parse_args(["--boot", Path | T], {Opts, Args}) ->
parse_args(T, {Opts#{boot => Path}, Args});
parse_args(["--out", Path | T], {Opts, Args}) ->
parse_args(T, {Opts#{out => Path}, Args});
parse_args(["--root_dir", Path | T], {Opts, Args}) ->
Expand Down Expand Up @@ -92,6 +97,7 @@ print_help() ->
"The following options are supported:"
"~n"
" * --root_dir <path> Path to the root directory of the AtomVM git checkout~n"
" * --boot <path> Path to a esp32boot.avm file~n"
" * --build_dir <path> Path to the AtomVM build directory (defaults to root_dir/build, if unspecifeid)~n"
" * --out <path> Output path for AtomVM image file~n"
" * --config <path> Path to mkimage configuration file~n"
Expand Down Expand Up @@ -124,7 +130,7 @@ get_build_dir(Opts, RootDir) ->
end.

%% @private
mkimage(RootDir, BuildDir, OutputFile, Segments) ->
mkimage(RootDir, BuildDir, BootFile, OutputFile, Segments) ->
io:format("Writing output to ~s~n", [OutputFile]),
io:format("=============================================~n"),
case file:open(OutputFile, [write, binary]) of
Expand Down Expand Up @@ -156,7 +162,7 @@ mkimage(RootDir, BuildDir, OutputFile, Segments) ->
end
end,
SegmentPaths = [
replace("BUILD_DIR", BuildDir, replace("ROOT_DIR", RootDir, SegmentPath))
replace("BUILD_DIR", BuildDir, replace("BOOT_FILE", BootFile, replace("ROOT_DIR", RootDir, SegmentPath)))
|| SegmentPath <- maps:get(path, Segment)
],
case try_read(SegmentPaths) of
Expand Down Expand Up @@ -200,4 +206,5 @@ from_hex([$0, $x | Bits]) ->

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

0 comments on commit 2c757e4

Please sign in to comment.