Skip to content

Flash the main.avm partition found on the board - #86

Open
bettio wants to merge 8 commits into
atomvm:mainfrom
bettio:flash-partition
Open

bettio wants to merge 8 commits into
atomvm:mainfrom
bettio:flash-partition

Conversation

@bettio

@bettio bettio commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

mix atomvm.esp32.flash wrote the application at 0x250000 unless told
otherwise, while the main.avm partition is elsewhere on older
Erlang-only images and on JIT builds. The task now reads the partition
table of the board and writes to its main.avm partition, as AtomVM finds
it, so no offset belongs in mix.exs any more; esp32_flash_offset and
--flash_offset still pin an address. An application bigger than its
partition is refused, with a hint at mix atomvm.esp32.expand.

Other partitions are named with esp32_partition in mix.exs or with
--partition, for custom layouts and A/B partitioning, several at once
when they all receive the same application. Both esptool paths read the
table, through Pythonx and through an external esptool.py, whose exit
status now fails the task. The moduledocs follow the keys renamed by
#35, and a mix.exs still setting flash_offset gets a warning.

The moduledocs of both flash tasks still named flash_offset, the mix.exs
key they no longer read.

Signed-off-by: Davide Bettio <davide@uninstall.it>
The key was renamed to esp32_flash_offset and stm32_flash_offset, and a
project still setting flash_offset gets the default without a word.

Signed-off-by: Davide Bettio <davide@uninstall.it>
flash_pythonx/1 selected the device when no --port was given, for this
task only: install passes the port it selected. Move the selection and
the check that AtomVM is installed into the task, which then knows the
port before calling esptool.

Signed-off-by: Davide Bettio <davide@uninstall.it>
A partition looked up by name and data type, the way AtomVM finds its
boot.avm and main.avm partitions, whatever the subtype.

Signed-off-by: Davide Bettio <davide@uninstall.it>
The exit status of esptool.py was dropped, so the task exited 0 after a
failed write. The Pythonx path already exits 1.

Signed-off-by: Davide Bettio <davide@uninstall.it>
The application was written at 0x250000 unless told otherwise, while the
main.avm partition is elsewhere on older Erlang-only images and on JIT
builds, and the flash offset was part of every mix.exs. Read the
partition table of the board and write to its main.avm partition, as
AtomVM finds it: by name and data type. esp32_flash_offset and
--flash_offset pin an address and skip the read.

--flash_offset now refuses anything but a hexadecimal address: 0x
crashed, 0x25zz became 0x25, and 250000 was ignored.

Signed-off-by: Davide Bettio <davide@uninstall.it>
The partition table gives the size of main.avm along with its offset, so
an image that does not fit is reported before anything is written, with
a hint at mix atomvm.esp32.expand.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Custom layouts and A/B partitioning put the application elsewhere than
main.avm. esp32_partition in mix.exs names the partition to write to,
--partition overrides it, and several names get the same image in one
esptool call. A partition and an address given together are refused.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@petermm

petermm commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

there is some blocker surrounding the esptool.py path using auto and multiple esp devices connected - on pythonx we pin the device, so we are sure we read from same device that we write to - the esptool.py doesn't pin the port, so in theory we could read a partition map from device A, and the write to device B.. most likely only in theory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants