Skip to content

Commit 903e798

Browse files
committed
Add esp32boot library to idf.py flash target
Adds the esp32boot library flavor (determined from partition table) to the idf.py flash job, allowing developers to simply skip running mkimage.sh and flashimage.sh from the build directory to flash all of the necessary partitions for a complete install to their device. Signed-off-by: Winford <[email protected]>
1 parent 26acd80 commit 903e798

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6767
- ESP32 cmake build options are now also exposed in `idf.py menuconfig`.
6868
- ESP32 Elixir support is determined automatically from the offset of `boot.avm` in the partiton
6969
table.
70+
- ESP32 ports now flash a complete working image using the `idf.py flash` task.
7071

7172
### Fixed
7273

doc/src/build-instructions.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ Tests for the following libraries are supported:
207207

208208
Building AtomVM for ESP32 must be done on either a Linux or MacOS build machine.
209209

210-
In order to build a complete AtomVM image for ESP32, you will also need to build AtomVM for the Generic UNIX platform (typically, the same build machine you are suing to build AtomVM for ESP32).
210+
In order to build a complete AtomVM image for ESP32, you will also need to build AtomVM for the Generic UNIX platform (typically, the same build machine you are suing to build AtomVM for ESP32). This is expected to
211+
be done before building an ESP32 port, since the BEAM libraries packed into the esp32boot.avm (or
212+
elixir_esp32boot.avm for Elixir supported builds) are created at the same time as the atomvmlib.avm
213+
libraries as part of the generic UNIX build.
211214

212215
### ESP32 Build Requirements
213216

@@ -272,19 +275,34 @@ You can now build AtomVM using the build command:
272275
$ idf.py build
273276
```
274277
275-
This command, once completed, will create the Espressif bootloader, partition table, and AtomVM binary. The last line of the output should read something like the following:
278+
This command, once completed, will create the Espressif bootloader, partition table, and AtomVM binary. The last line of the output should read something like the following example:
276279
277-
Project build complete. To flash, run this command:
278-
~/.espressif/python_env/idf5.1_py3.11_env/bin/python ~/esp/esp-idf-v5.1/components
279-
/esptool_py/esptool/esptool.py -p (PORT) -b 921600 --before default_reset
280-
--after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size detect
281-
--flash_freq 40m 0x1000 build/bootloader/bootloader.bin 0x8000
282-
build/partition_table/partition-table.bin 0x10000 build/atomvm-esp32.bin
283-
or run 'idf.py -p (PORT) flash'
280+
```
281+
Project build complete. To flash, run:
282+
idf.py flash
283+
or
284+
idf.py -p PORT flash
285+
or
286+
python -m esptool --chip esp32 -b 921600 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/atomvm-esp32.bin 0x1d0000 ../../../build/libs/esp32boot/esp32boot.avm
287+
or from the "/home/joe/AtomVM/src/platforms/esp32/build" directory
288+
python -m esptool --chip esp32 -b 921600 --before default_reset --after hard_reset write_flash "@flash_args"
289+
```
284290
285-
At this point, you can run `idf.py flash` to upload the 3 binaries up to your ESP32 device, and in some development scenarios, this is a preferable shortcut.
291+
```{important}
292+
When using the `@flash_args` method be sure to execute from
293+
<path-to-your-cloned-AtomVM>/src/platforms/esp32/build.
294+
```
286295
287-
However, first, we will build a single binary image file containing all of the above 3 binaries, as well as the AtomVM core libraries. See [Building a Release Image](#building-a-release-image), below. But first, it is helpful to understand a bit about how the AtomVM partitioning scheme works, on the ESP32.
296+
At this point, you can run `idf.py flash` and have a complete working image. In some development
297+
scenarios is may be helpful to use `idf.py app-flash` (to only flash a new AtomVM binary to the
298+
`factory` partition) to avoid re-flashing the entire image if no changes were made to the Erlang or
299+
Elixir libraries, and the partition table has not been altered. If you have made changes to the
300+
sdkconfig file (using `idf.py menuconfig` or by other means) it may be necessary to also update the
301+
bootloader using `idf.py bootlader-flash`. As with most other `idf.py` commands these may be
302+
combined (for example: `idf.py bootlader-flash app-flash`). For more information about these
303+
partitions and the flash partitions layout see [Flash Layout](#flash-layout) below.
304+
305+
To build a single binary image file see [Building a Release Image](#building-a-release-image), below.
288306
289307
### Running tests for ESP32
290308
@@ -417,18 +435,18 @@ The flash layout is roughly as follows (not to scale):
417435
| partition table | 3KB |
418436
+-----------------+ |
419437
| | |
420-
| NVS | 24KB |
438+
| nvs | 24KB |
421439
| | |
422440
+-----------------+ |
423441
| PHY_INIT | 4KB |
424442
+-----------------+ | AtomVM
425443
| | | binary
426444
| | | image
427-
| | |
428445
| AtomVM | |
429-
| Virtual | 1.75MB |
430-
| Machine | |
446+
| Virtual | |
447+
| Machine | 1.75MB |
431448
| | |
449+
| (factory) | |
432450
| | |
433451
+-----------------+ |
434452
| boot.avm | 256-512KB v
@@ -474,7 +492,7 @@ and `boot.avm` partitions.
474492
475493
### Building a Release Image
476494
477-
The `<atomvm-source-tree-root>/tools/release/esp32` directory contains the `mkimage.sh` script that can be used to create a single AtomVM image file, which can be distributed as a release, allowing application developers to develop AtomVM applications without having to build AtomVM from scratch.
495+
The `<atomvm-source-tree-root>/src/platforms/esp32/build` directory contains the `mkimage.sh` script that can be used to create a single AtomVM image file, which can be distributed as a release, allowing application developers to develop AtomVM applications without having to build AtomVM from scratch.
478496
479497
```{attention}
480498
Before running the `mkimage.sh` script, you must have a complete build of both the esp32 project, as well as a full

src/platforms/esp32/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ option(AVM_VERBOSE_ABORT "Print module and line number on VM abort" OFF)
8383
option(AVM_CREATE_STACKTRACES "Create stacktraces" ON)
8484

8585
add_subdirectory(tools)
86+
87+
include(GetBootAVM.cmake)
88+
message(NOTICE "-- Configuring atomvmlib esp32boot flavor: ${BOOT_LIBS}")
89+
if (NOT ("${BOOT_LIBS}" STREQUAL "NONE"))
90+
set(BOOT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../build/libs/esp32boot/${BOOT_LIBS}")
91+
if (NOT EXISTS "${BOOT_LIB_PATH}")
92+
message(ERROR "A generic_unix build must be done first in the top level AtomVM/build directory! \n\
93+
Consult https://doc.atomvm.org/main/build-instructions.html for build instructions.")
94+
endif()
95+
partition_table_get_partition_info(lib_offset "--partition-name boot.avm" "offset")
96+
esptool_py_flash_target_image(flash boot.avm "${lib_offset}" "${BOOT_LIB_PATH}")
97+
endif()

src/platforms/esp32/GetBootAVM.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#
2020

2121
partition_table_get_partition_info(app_offset "--partition-name main.avm" "offset")
22-
set(AVM_APP_OFFSET "${app_offset}")
2322
if ("${app_offset}" STREQUAL "0x210000")
2423
set(BOOT_LIBS "esp32boot.avm")
2524
elseif ("${app_offset}" STREQUAL "0x250000")

src/platforms/esp32/components/libatomvm/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ target_link_libraries(${COMPONENT_LIB}
3535
INTERFACE libAtomVM "-u platform_nifs_get_nif" "-u platform_defaultatoms_init")
3636

3737
target_compile_features(${COMPONENT_LIB} INTERFACE c_std_11)
38+
39+
include(../../GetBootAVM.cmake)
40+
partition_table_get_partition_info(boot_offset "--partition-name boot.avm" "offset")

0 commit comments

Comments
 (0)