Skip to content

Commit

Permalink
Add support to boot.avm partition
Browse files Browse the repository at this point in the history
Try to boot boot.avm partition first, which will take care of
application loading.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Jul 9, 2023
1 parent 4fb9613 commit 24f8e20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/platforms/esp32/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ void app_main()

spi_flash_mmap_handle_t handle;
int size;
const void *main_avm = esp32_sys_mmap_partition("main.avm", &handle, &size);
const void *startup_avm = esp32_sys_mmap_partition("boot.avm", &handle, &size);
if (IS_NULL_PTR(startup_avm)) {
ESP_LOGI(TAG, "Trying deprecated main.avm partition.");
startup_avm = esp32_sys_mmap_partition("main.avm", &handle, &size);
}

uint32_t startup_beam_size;
const void *startup_beam;
Expand All @@ -76,12 +80,12 @@ void app_main()
port_driver_init_all(glb);
nif_collection_init_all(glb);

if (!avmpack_is_valid(main_avm, size)) {
ESP_LOGE(TAG, "Invalid main.avm packbeam. size=%u", size);
if (!avmpack_is_valid(startup_avm, size)) {
ESP_LOGE(TAG, "Invalid startup avmpack. size=%u", size);
AVM_ABORT();
}
if (!avmpack_find_section_by_flag(main_avm, BEAM_START_FLAG, &startup_beam, &startup_beam_size, &startup_module_name)) {
ESP_LOGE(TAG, "Error: Failed to locate start module in main.avm packbeam. (Did you flash a library by mistake?)");
if (!avmpack_find_section_by_flag(startup_avm, BEAM_START_FLAG, &startup_beam, &startup_beam_size, &startup_module_name)) {
ESP_LOGE(TAG, "Error: Failed to locate start module in startup partition. (Did you flash a library by mistake?)");
AVM_ABORT();
}
ESP_LOGI(TAG, "Found startup beam %s", startup_module_name);
Expand All @@ -92,7 +96,7 @@ void app_main()
}
avmpack_data_init(&avmpack_data->base, &const_avm_pack_info);
avmpack_data->base.in_use = true;
avmpack_data->base.data = main_avm;
avmpack_data->base.data = startup_avm;
synclist_append(&glb->avmpack_data, &avmpack_data->base.avmpack_head);

const void *lib_avm = esp32_sys_mmap_partition("lib.avm", &handle, &size);
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 0x1C0000,
lib.avm, data, phy, 0x1D0000, 0x40000,
boot.avm, data, phy, 0x1D0000, 0x40000,
main.avm, data, phy, 0x210000, 0x100000

0 comments on commit 24f8e20

Please sign in to comment.