Skip to content
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

ESP32S2 self-update not working #134

Closed
T94T opened this issue Jul 21, 2021 · 12 comments
Closed

ESP32S2 self-update not working #134

T94T opened this issue Jul 21, 2021 · 12 comments

Comments

@T94T
Copy link

T94T commented Jul 21, 2021

We have two different self-update UF2 firmware files. But uploading one or another file does not work. The UF2 bootloader that was last burned via the idf.py tool is always active and cannot be overwritten.

@hathach
Copy link
Member

hathach commented Jul 21, 2021

can you provide more information on the issue:

  1. which board you are running
  2. step to reproduce
  3. all the version of firmware, software that are in used.

@T94T
Copy link
Author

T94T commented Jul 22, 2021

  1. ESP32-S2-Saola-1RI
    2./3. We are using latest 7b92803 and building with make BOARD=espressif_saola_1_wroom all self-update. The generated update-tinyuf2.uf2can be uploaded to the board but it does not take effect.

@hathach
Copy link
Member

hathach commented Jul 22, 2021

2.Step to reproduce: please provide your procedure detail, what have you done to test and how you verify that it does not take effect.

@T94T
Copy link
Author

T94T commented Jul 22, 2021

Just started all over again with following steps:

  • git clone --recurse-submodules https://github.com/adafruit/tinyuf2
  • install.sh
  • cd tinyuf2/ports/esp32s2
  • get_idf
  • idf.py -p /dev/ttyUSB0 -DBOARD=espressif_saola_1_wroom flash
    After this last step I have the UF2 bootloader correctly burned to the module.

Then I created the update-tinyuf2.uf2 for backup:

  • make BOARD=espressif_saola_1_wroom all self-update

To check wheter self-update works or not I created a new update-tinyuf2.uf2 file with UF2_VOLUME_LABEL changed from default "SAOLA1MBOOT" to "UPDATE".

  • make BOARD=espressif_saola_1_wroom clean
  • make BOARD=espressif_saola_1_wroom all self-update

And now it works as expected. After a self-update the MSD volume name is UPDATE. Also reverting back to the UF2_VOLUME_LABEL version works. Very strange. Must have messed up something with my previous installation.

@hathach
Copy link
Member

hathach commented Jul 22, 2021

update-uf2 is an actually an app like circuit python, it covert tinyuf2.bin to carray then erase and write once when updating. Maybe you modify but didn't recompile the tinyuf2 first (all target) and updater use the old bin file which make you think it does not do the work.

@T94T
Copy link
Author

T94T commented Jul 22, 2021

We now applied all the changes we made before. Unfortunately it still does not work. It gets confusing even more.

One bootloader is the original without changes. The second one should enter UF2 stage when hard resetting the board.

update-tinyuf2-factory.uf2

  • UF2_VOLUME_LABEL: FACTORY
  • tinyuf2 codebase without changes

update-tinyuf2-failover.uf2

  • UF2_VOLUME_LABEL: FOVER
  • tinyuf2 codebase with changes:
    added
if (reset_reason == POWERON_RESET) {
  boot_index = FACTORY_INDEX;
}

just after

RESET_REASON reset_reason = bootloader_common_get_reset_reason(0);

When uploading the update-tinyuf2-factory.uf2 or the update-tinyuf2-failover.uf2 the MSD volume name changes to FACTORY or FOVER as it should be.

BUT: The behaviour of the uploaded firmware does not take effect. The version that was last burned with the command idf.py -p /dev/ttyUSB0 -DBOARD=espressif_saola_1_wroom flash is always active.

@hathach
Copy link
Member

hathach commented Jul 22, 2021

Ok now I see what you mean (this is why asking for exact reproducible steps is needed), the changes you did isn't part of the tinyuf2, it is stage2 bootlaoder, tinyuf2 is actually factory app. Currently the updater only update tinyuf2 since I am not sure if it is safe and/or possible to update stage2 bootloader. I didn't say it is not possible, I just haven't tried it yet.

@T94T
Copy link
Author

T94T commented Jul 22, 2021

Thank you very much for investigating your time! Now some things become clear. Closing for now...

@T94T T94T closed this as completed Jul 22, 2021
@hathach
Copy link
Member

hathach commented Jul 22, 2021

If you still want to update the boot2 as well. You could open an issue for it, I will try to see if that is possible to do when having time

@hathach
Copy link
Member

hathach commented Jul 23, 2021

I tried to update the boot2 binary with update-uf2, there is a couple of issue

  1. There is a macro check to validate the address, though it is easily by passed by enabling unsafed write https://github.com/espressif/esp-idf/blob/master/components/spi_flash/esp_flash_api.c#L51
  2. There is some meta data required for boot2 bin
Invalid image block, can't boot.
ets_main.c 386 

Digging to esptool.py https://github.com/espressif/esptool/blob/master/esptool.py#L3488, look like it does some modification to bootlaoder image to add image size, flash mode, flash freq etc to the very frist 4 bytes (header). At this point, I don't think it is the worth effort to update it, since it seem rather unsafe. It is rather easy to flash boot2 update via rom bootloader. Boot2 won't change much anyway.

@T94T
Copy link
Author

T94T commented Jul 23, 2021

Thank you for digging even deeper. "unsafe" does not sound good. We are now flashing the boards directly with the upload tool. The failover bootloader we only need during the development phase. So it is not a big problem. Thank you very much again.

@hathach
Copy link
Member

hathach commented Jul 23, 2021

after giving a bit more thought, I think it is still worth updating, since ROM loader is there to unbrick. However, I don't quite feel comfortable following the esptool code, maybe if someone know where is the specs for the layout. We could get this done. I push my interim work to the branch here https://github.com/adafruit/tinyuf2/tree/esp32s2-update-boot2 . If anyone could help with meta data part, that would nail it.

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

No branches or pull requests

2 participants