-
Notifications
You must be signed in to change notification settings - Fork 5
Enhancements for the esp32_flash task #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
5685f2a to
91a5fc9
Compare
91a5fc9 to
783d3ad
Compare
586a1ef to
d334c12
Compare
pguyot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Partial review)
src/atomvm_esp32_flash_provider.erl
Outdated
| auto -> | ||
| read_flash_offset(EspTool, Port, Partition, State); | ||
| Val -> | ||
| Offset0 = read_flash_offset(EspTool, Port, Partition, State), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicer transition behaviour would be to check that offset matches the beginning of any partition (main.avm or named otherwise).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Now if the given offset does not match the expected partition name a warning will be issued, but as long as it is a data partition of a valid subtype (any subtype not specifically reserved for other purposes - i.e. cordump, nvs, nsv_keys, fat, etc) the partition will be used.
src/esp_part_dump.erl
Outdated
| "0xc00", | ||
| TempFile | ||
| ]), | ||
| os:cmd(Cmd), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os:cmd doesn't return the status. We may want to use the good old open_port({spawn_executable, Esptool}).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this file and the esp32_flash provider to use open_port/2, this had the added benefit of faster flash operations and quieter output.
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>
3a391b9 to
4d4e57e
Compare
11dfd1c to
9b7d519
Compare
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>
9b7d519 to
fe79208
Compare
| I. | ||
| -spec integer_from_string(S :: list() | integer()) -> Value :: integer(). | ||
| integer_from_string("auto") -> | ||
| -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have this function return integer() | auto instead of using -1 as a magic number.
| TempFile = get_part_tempfile(State), | ||
| Address = | ||
| case Offset of | ||
| -1 -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want auto here.
| 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.", |
There was a problem hiding this comment.
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 ;-)
| end; | ||
| Val -> | ||
| Offset0 = read_flash_offset(EspTool, Port, Partition, TempFile), | ||
| case Val =:= Offset0 of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case Offset0 of or if Val =:= Offset0 look more Erlang to me.
| end, | ||
| Cmd = lists:join(" ", [ | ||
| EspTool, | ||
| [ProjectAppAVM | _] = [get_avm_file(ProjectApp) || ProjectApp <- ProjectApps], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using side effects from get_avm_file/1 here or could you just process the first ProjectApps (with hd(ProjectApps))?
| while [ "${#}" -gt 0 ]; do | ||
| case ${1} in | ||
| read_flash ) shift | ||
| if [ "${1}" = "0x8000" ] && [ "${2}" = "0xC00" ] || [ "${2}" = "0xc00" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if [ "${1}" = "0x8000" ] && [ "${2}" = "0xC00" ] || [ "${2}" = "0xc00" ]; then | |
| if [ "${1}" = "0x8000" ] && { [ "${2}" = "0xC00" ] || [ "${2}" = "0xc00" ]; }; then |
| I; | ||
| integer_from_string(S) when is_list(S) -> | ||
| S0 = string:trim(S), | ||
| case lists:prefix("0x", S0) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use string:prefix/2 or lists:sublist(S0, 2) instead of lists:subtract(S0, "0x")
|
|
||
| -spec lookup_partition_by_name(Name :: string(), Partitions :: binary()) -> | ||
| Offset :: non_neg_integer(). | ||
| lookup_partition_by_name(Name, Partitions) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lookup_partition_by_name/2 and lookup_partition_by_offset should have the same signature (return error tuple or raise).
|
|
||
| %% @private | ||
| get_part_tempfile(State) -> | ||
| OutDir = filename:absname(rebar_dir:base_dir(State)), |
There was a problem hiding this comment.
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
| {Tool, {exit_status, Status}} -> | ||
| error({"esptool.py failure", Status}) | ||
| after 120000 -> | ||
| error("esptool.py failed (2 minute timeout exceeded)") |
There was a problem hiding this comment.
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.
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 theapp_partitionparameter should be supplied if the app partition is not namedmain.avm.Other changes include: