Skip to content

Conversation

@UncleGrumpy
Copy link
Collaborator

Changes include automatic detection of the beam application partition (default main.avm) to prevent overwriting the wrong flash sectors. This prevents overwriting Elixir library modules for Elixir supported builds, and assures that the application will be written to the same address that AtomVM will load and run. When flashing to a device with a custom partition table the app_partition parameter should be supplied if the app partition is not named main.avm.

Other changes include:

  • Device port is now auto discovered instead of hard coded
  • Improved error reporting
  • Stacktraces are only displayed in diagnostic mode
  • Dialyzer warnings for atomvm_rebar3_plugin esp32_flash provider fixed

@UncleGrumpy UncleGrumpy marked this pull request as draft July 29, 2025 02:22
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 3 times, most recently from 5685f2a to 91a5fc9 Compare August 2, 2025 05:59
@UncleGrumpy UncleGrumpy marked this pull request as ready for review August 2, 2025 06:00
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch from 91a5fc9 to 783d3ad Compare August 2, 2025 08:14
@UncleGrumpy UncleGrumpy requested review from bettio and pguyot October 21, 2025 14:12
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 2 times, most recently from 586a1ef to d334c12 Compare December 8, 2025 07:35
@UncleGrumpy UncleGrumpy requested review from pguyot and removed request for bettio and pguyot December 8, 2025 07:36
Copy link
Collaborator

@pguyot pguyot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Partial review)

@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 2 times, most recently from 3a391b9 to 4d4e57e Compare December 16, 2025 03:25
@UncleGrumpy UncleGrumpy requested a review from pguyot December 16, 2025 03:44
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 3 times, most recently from 9b7d519 to fe79208 Compare December 16, 2025 06:20
rebar_api:abort("Partition ~s not found!", [Partition]);
error:invalid_partition_table ->
rebar_api:abort(
"Error parsing partition table, possible line noise reading from device.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Port already open with minicom is more likely here than line noise ;-)

Copy link
Collaborator Author

@UncleGrumpy UncleGrumpy Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it were an open port to minicom that would have caused a rebar_api:abort/2 sooner, but I was not catching it there, and it would have fallen through to a more generic error.

I did rework error reporting a bit and centralized the error decoding to clean up the logic, and because so many of the errors can occur in multiple call locations.


%% @private
get_part_tempfile(State) ->
OutDir = filename:absname(rebar_dir:base_dir(State)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should call mktemp(1) here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. When I was first implementing this I intended to look into OTP methods for using temp files, but by the time I got the tricky bits working I forget to go back and address this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did use mktemp here, which prompted me to add atomvm_rebar3_plugin:external_command/3 for better re-usability (making the transition to replace use of os:cmd/1,2 with open_port/2 in other providers). I also added a temp logfile for esptool.py output. It turns out that the dumpfile created by mktemp causes esptool.py an error, so it needs to be deleted immediately, but the tempfile generated name is still used. Both the esptool.py output log and dumpfile are cleaned up before exiting successfully, but retained, and the full path to the logfile displayed if there is a failure.

{Tool, {exit_status, Status}} ->
error({"esptool.py failure", Status})
after 120000 ->
error("esptool.py failed (2 minute timeout exceeded)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool is not closed here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I did completely forget about that. Out of curiosity, how does the VM handle that close internally? Is a signal sent to the OS kill the external process?

@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 4 times, most recently from 885f434 to db356bd Compare December 22, 2025 23:47
@UncleGrumpy UncleGrumpy requested a review from pguyot December 22, 2025 23:53
Changes error reporting for the esp32_flash task to include stack trace when rebar3 is executed
with DIAGNOSTIC=1 or DEBUG=1.

Signed-off-by: Winford <winford@object.stream>
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 3 times, most recently from c9ad99f to 5cfb5c7 Compare December 23, 2025 01:15
@UncleGrumpy UncleGrumpy force-pushed the detect_esp32_offset branch 6 times, most recently from 3586f77 to dbbf440 Compare December 23, 2025 03:47
The `offset` for the beam application partition is now read from the partition table on the attached
esp32 device. When a custom partition table is used that does not use `main.avm` for the beam app
partition name the `app_partition` parameter should be used to specify the application partition
to be flashed. Valid application partition sub-types (the type is `data`) are `phy` or `0xAA`.

If the `offset` parameter is specified it will be used to verify that the offset address of the
application partition matched the expected value. This may be used to prevent flashing to a
standard build of AtomMV for application that require a custom partition table.

The `port` that the ESP32 is attached to is now auto discovered by default. When more than one
ESP32 device is plugged into USB the port should be specified to control which device is flashed.

Error reporting has been improved with descriptive error messages.

Dialyzer warnings for the esp32_flash task have been fixed when analyzing atomvm_rebar3_plugin.

Signed-off-by: Winford <winford@object.stream>
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