From 616fe4500c610cad71814068030376fa245fe72c 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/esp32kernel/esp32kernel.erl b/libs/esp32kernel/esp32kernel.erl index 6187cedd1..f8086ead8 100644 --- a/libs/esp32kernel/esp32kernel.erl +++ b/libs/esp32kernel/esp32kernel.erl @@ -71,7 +71,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(). @@ -87,7 +87,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.