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

Reboot into UART download mode without external wiring or interaction #7854

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

twischer
Copy link
Contributor

@twischer twischer commented Jan 31, 2021

This patch introduces the new method Esp.reboot_uart_dwnld().
With this method the UART download mode can be selected by software only.

When the user calls this method the ESP8266 reboots into the UART
download mode. In this mode the user can use esptool.py to flash a new
firmware file.
This patch was tested with the following command:

$ esptool.py --before no_reset --after soft_reset \
    --chip esp8266 --port /dev/ttyUSB0 --baud 460800 \
    write_flash 0x0 ./firmware.bin

The implementation is based on the original implementation in the
boot ROM. Some parts of the original implementation can be found in
https://github.com/twischer/xtensa-subjects/tree/reversed/reversed

@earlephilhower
Copy link
Collaborator

This PR seems to include a bunch of NONOS binaries, too. Maybe they got pulled in by accident? Can you pull them out of the PR?

Also, can you explain why this would be useful? esptool is quite capable of resetting/uploading already w/o extra code in IRAM/etc., so I don't understand the rationale.

@twischer
Copy link
Contributor Author

twischer commented Feb 1, 2021

Hello @earlephilhower,

This PR seems to include a bunch of NONOS binaries, too. Maybe they got pulled in by accident? Can you pull them out of the PR?

This PR is not adding new binaries. It is only modifying them:

$ git show -- tools/sdk/lib/NONOSDK*
diff --git a/tools/sdk/lib/NONOSDK221/libmain.a b/tools/sdk/lib/NONOSDK221/libmain.a
index c0e70caf..f008bc9d 100644
Binary files a/tools/sdk/lib/NONOSDK221/libmain.a and b/tools/sdk/lib/NONOSDK221/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK22x_190313/libmain.a b/tools/sdk/lib/NONOSDK22x_190313/libmain.a
index a19b330c..66403108 100644
Binary files a/tools/sdk/lib/NONOSDK22x_190313/libmain.a and b/tools/sdk/lib/NONOSDK22x_190313/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK22x_190703/libmain.a b/tools/sdk/lib/NONOSDK22x_190703/libmain.a
index 1213ceb8..cd5fd1e8 100644
Binary files a/tools/sdk/lib/NONOSDK22x_190703/libmain.a and b/tools/sdk/lib/NONOSDK22x_190703/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK22x_191024/libmain.a b/tools/sdk/lib/NONOSDK22x_191024/libmain.a
index 58779578..cd01e1a3 100644
Binary files a/tools/sdk/lib/NONOSDK22x_191024/libmain.a and b/tools/sdk/lib/NONOSDK22x_191024/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK22x_191105/libmain.a b/tools/sdk/lib/NONOSDK22x_191105/libmain.a
index 2bc98579..0f66ab6b 100644
Binary files a/tools/sdk/lib/NONOSDK22x_191105/libmain.a and b/tools/sdk/lib/NONOSDK22x_191105/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK22x_191122/libmain.a b/tools/sdk/lib/NONOSDK22x_191122/libmain.a
index 77b7de1b..260be180 100644
Binary files a/tools/sdk/lib/NONOSDK22x_191122/libmain.a and b/tools/sdk/lib/NONOSDK22x_191122/libmain.a differ
diff --git a/tools/sdk/lib/NONOSDK3V0/libmain.a b/tools/sdk/lib/NONOSDK3V0/libmain.a
index e93201c5..c30cc88a 100644
Binary files a/tools/sdk/lib/NONOSDK3V0/libmain.a and b/tools/sdk/lib/NONOSDK3V0/libmain.a differ

I have changed https://github.com/esp8266/Arduino/blob/master/tools/sdk/lib/fix_sdk_libs.sh and therefore I have applied this modification already to the libraries. This modification is required because no symbol name is set for a function I need to call.

Also, can you explain why this would be useful?

I am interested in building a quite small and chip board which is water proofed. Therefore I do not want to have any additional connectors/wiring to the outside. The only connector attached is a USB plug for power supply. But I am also connecting the UART Tx and Rx line to D+ and D- of the USB plug. Therefore UART is accessible but there is no place for any additional wiring (connected to reset and GPIO2).

In the past also others were asking for such a solution:
https://www.esp8266.com/viewtopic.php?p=38310

@twischer twischer force-pushed the reboot_uart_download branch 3 times, most recently from ccd5dbe to af404b3 Compare February 3, 2021 20:18
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation in the PR.

Overall seems like a fine idea and useful in some circumstances, but a little polish would help make it maintainable later on.

cores/esp8266/esp8266_undocumented.h Outdated Show resolved Hide resolved
tools/sdk/ld/eagle.rom.addr.v6.ld Outdated Show resolved Hide resolved
tools/sdk/ld/eagle.rom.addr.v6.ld Outdated Show resolved Hide resolved
cores/esp8266/esp8266_undocumented.h Outdated Show resolved Hide resolved
cores/esp8266/reboot_uart_dwnld.cpp Outdated Show resolved Hide resolved
cores/esp8266/reboot_uart_dwnld.cpp Outdated Show resolved Hide resolved
cores/esp8266/Esp.cpp Outdated Show resolved Hide resolved
cores/esp8266/reboot_uart_dwnld.cpp Show resolved Hide resolved
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

Thanks for the add'l comments and cleanup. LGTM!

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

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

Thanks for the cleanup and add'l comments. LGTM!

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

LGTM.
Regular builds are unmodified according to a quick test when this new API is not used.

without any external wiring.

This patch introduces the new method
Esp.rebootIntoUartDownloadMode()

When the user calls this method the ESP8266 reboots into the UART
download mode. In this mode the user can use esptool.py to flash a new
firmware file. The following command was used to test it:
$ esptool.py --before no_reset --after soft_reset --chip esp8266 \
    --port /dev/ttyUSB0 --baud 460800 write_flash 0x0 firmware.bin

The implementation is based on the original implementation in the
boot ROM. Some parts of the original implementation can be found in
[1]. This patch is a squashed and simplified version of [2]. The non
squashed version might be helpful in case of debugging issues.

[1] https://github.com/twischer/xtensa-subjects/blob/master/reversed/bootrom.c
[2] https://github.com/twischer/Arduino/tree/reboot_uart_download_full

Signed-off-by: Timo Wischer <twischer@freenet.de>
@earlephilhower earlephilhower merged commit 83f5f29 into esp8266:master Feb 17, 2021
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.

3 participants