Skip to content

Commit

Permalink
ESP32/kernel: use atomvm:get_entry_point/1
Browse files Browse the repository at this point in the history
Use atomvm:get_entry_point/1 for finding startup module instead of
relying on some static default.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Jul 3, 2023
1 parent 1c719bb commit 6cd8afc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libs/esp32kernel/esp32kernel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ loop() ->

boot() ->
BootPath = get_boot_path(),
atomvm:add_avm_pack_file(BootPath, []),
atomvm:add_avm_pack_file(BootPath, [{name, app}]),

StartModule = get_start_module(),
StartModule:start().
Expand All @@ -78,7 +78,15 @@ get_boot_path() ->
get_start_module() ->
case esp:nvs_get_binary(atomvm, start_module) of
undefined ->
main;
case atomvm:get_entry_point(app) of
undefined ->
main;
ModuleNameWithExt when is_binary(ModuleNameWithExt) ->
Len = byte_size(ModuleNameWithExt) - byte_size(<<".beam">>),
ModuleName = binary:part(ModuleNameWithExt, 0, Len),
erlang:display({going_to_boot, ModuleName}),
erlang:binary_to_atom(ModuleName, latin1)
end;
Module ->
erlang:binary_to_atom(Module, latin1)
end.
Expand Down

0 comments on commit 6cd8afc

Please sign in to comment.