From f07cce51da8fce6094433eea344f8d00685a91ed Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Mon, 3 Jul 2023 19:52:16 +0200 Subject: [PATCH] ESP32/kernel: use atomvm:get_entry_point/1 Use atomvm:get_entry_point/1 for finding startup module instead of relying on some static default. Signed-off-by: Davide Bettio --- libs/esp32boot/esp32init.erl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/esp32boot/esp32init.erl b/libs/esp32boot/esp32init.erl index b365bc81c..3de2cba85 100644 --- a/libs/esp32boot/esp32init.erl +++ b/libs/esp32boot/esp32init.erl @@ -75,7 +75,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(). @@ -91,7 +91,14 @@ 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:binary_to_atom(ModuleName, latin1) + end; Module -> erlang:binary_to_atom(Module, latin1) end.