Skip to content

Commit d62451a

Browse files
committed
ESP32/init: use atomvm:get_start_beam/1
Use atomvm:get_start_beam/1 for finding startup module instead of relying on some static default. Signed-off-by: Davide Bettio <[email protected]>
1 parent 097f8c9 commit d62451a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libs/esp32boot/esp32init.erl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ loop() ->
7474

7575
boot() ->
7676
BootPath = get_boot_path(),
77-
atomvm:add_avm_pack_file(BootPath, []),
77+
atomvm:add_avm_pack_file(BootPath, [{name, app}]),
7878

7979
StartModule = get_start_module(),
8080
StartModule:start().
@@ -90,7 +90,14 @@ get_boot_path() ->
9090
get_start_module() ->
9191
case esp:nvs_get_binary(atomvm, start_module) of
9292
undefined ->
93-
main;
93+
case atomvm:get_start_beam(app) of
94+
error ->
95+
main;
96+
{ok, ModuleNameWithExt} when is_binary(ModuleNameWithExt) ->
97+
Len = byte_size(ModuleNameWithExt) - byte_size(<<".beam">>),
98+
ModuleName = binary:part(ModuleNameWithExt, 0, Len),
99+
erlang:binary_to_atom(ModuleName, latin1)
100+
end;
94101
Module ->
95102
erlang:binary_to_atom(Module, latin1)
96103
end.

0 commit comments

Comments
 (0)