From 6cd8afca9ded5b5020a5fd151ad02cdd79a5a4da 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/esp32kernel/esp32kernel.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libs/esp32kernel/esp32kernel.erl b/libs/esp32kernel/esp32kernel.erl index 85fc2414d..88f92c3ad 100644 --- a/libs/esp32kernel/esp32kernel.erl +++ b/libs/esp32kernel/esp32kernel.erl @@ -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(). @@ -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.