Boot esp8266 app firmware from custom address

aboutesp
Posts: 5
Joined: Mon Oct 09, 2023 7:32 am

Boot esp8266 app firmware from custom address

Postby aboutesp » Mon Oct 09, 2023 10:58 am

Hello Forum!

In general, I would like to make app firmware rollback mechanism for OTA updates for esp8266.
Right now, I am trying to load app firmware from custom address.

1) Updated eboot bootloader to load app firmware from 0x00080000 addr

2) Built two apps with different debug output strings ("Hello, Loop 111!" and "Hello, Loop 222!").
Uploaded two apps to flash, first app to 0x0 addr, second app to 0x00080000 addr
Second app loads and works as expected.

3) Made more changes between apps.
Added additional output string to second app. ("Additional string that will break app!")
Second app does not works correctly.
There is garbage in output.

Why does loading the second app have such dependencies on the first app?
How to broke these dependence and load second different app?

Any suggestions are greatly appreciated! Thank you!

aboutesp
Posts: 5
Joined: Mon Oct 09, 2023 7:32 am

Re: Boot esp8266 app firmware from custom address

Postby aboutesp » Mon Oct 09, 2023 6:24 pm

This post with commands for step 1) of first post

Update eboot bootloader to load app from 0x00080000

Code: Select all

user@localhost:~/esp8266/bootloaders/eboot$ git diff
diff --git a/bootloaders/eboot/eboot.c b/bootloaders/eboot/eboot.c
index c3d0c278..ab3ff25c 100644
--- a/bootloaders/eboot/eboot.c
+++ b/bootloaders/eboot/eboot.c
@@ -301,6 +301,7 @@ int main()
 
     if (cmd.action == ACTION_LOAD_APP) {
         ets_printf("ld\n");
+        cmd.args[0] = 0x00080000;
         res = load_app_from_flash_raw(cmd.args[0]);
         // We will get to this only on load fail
         ets_printf("e:%d\n", res);
diff --git a/bootloaders/eboot/eboot.elf b/bootloaders/eboot/eboot.elf
index 0e679ff4..69985ff5 100755
Build custom eboot.elf

Code: Select all

user@localhost:~/esp8266/bootloaders/eboot$ make
Replace eboot.elf for sketch builds

Code: Select all

user@localhost:~/esp8266/bootloaders/eboot$ cp eboot.elf $HOME/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/bootloaders/eboot/

aboutesp
Posts: 5
Joined: Mon Oct 09, 2023 7:32 am

Re: Boot esp8266 app firmware from custom address

Postby aboutesp » Mon Oct 09, 2023 6:31 pm

First app firmware for 0x0 address

Application for 0x0 address

Code: Select all

user@localhost:~/esketch$ cat esketch.ino 
void setup() {
  Serial.begin(38400);
  Serial.println("Hello, Setup!");
}
void loop() {
  Serial.println("Hello, Loop 111!");
  delay(1000);
}
Build application for 0x0 with custom eboot loader

Code: Select all

user@localhost:~/esketch$ ~/arduino-cli/bin/arduino-cli compile --log --verbose --output-dir ./build --fqbn esp8266:esp8266:nodemcuv2 .
Write application to 0x0

Code: Select all

user@localhost:~/esketch$ $HOME/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x0 ./build/esketch.ino.bin

aboutesp
Posts: 5
Joined: Mon Oct 09, 2023 7:32 am

Re: Boot esp8266 app firmware from custom address

Postby aboutesp » Mon Oct 09, 2023 6:34 pm

Second app firmware for 0x0008000 address

Application for 0x00080000 address

Code: Select all

user@localhost:~/esketch$ cat esketch.ino 
void setup() {
  Serial.begin(38400);
  Serial.println("Hello, Setup!");
}
void loop() {
  Serial.println("Hello, Loop 222!");
  delay(1000);
}
Build application for 0x00080000 with custom eboot loader

Code: Select all

user@localhost:~/esketch$ ~/arduino-cli/bin/arduino-cli compile --log --verbose --output-dir ./build --fqbn esp8266:esp8266:nodemcuv2 .
Write application to 0x00080000

Code: Select all

user@localhost:~/esketch$ $HOME/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x00080000 ./build/esketch.ino.bin
Output

Code: Select all

21:32:36.975 -> �怢B��G�!�F!ĮC�))Hello, Setup!
21:32:36.975 -> Hello, Loop 222!
21:32:37.972 -> Hello, Loop 222!
21:32:38.968 -> Hello, Loop 222!

aboutesp
Posts: 5
Joined: Mon Oct 09, 2023 7:32 am

Re: Boot esp8266 app firmware from custom address

Postby aboutesp » Mon Oct 09, 2023 6:45 pm

Second app firmware for 0x0008000 address with additional output string

Application for 0x00080000 address with additional output string

Code: Select all

user@localhost:~/esketch$ cat esketch.ino 
void setup() {
  Serial.begin(38400);
  Serial.println("Hello, Setup!");
}
void loop() {
  Serial.println("Hello, Loop 222!");
  Serial.println("Additional string that will break app!");
  delay(1000);
}
Build application for 0x00080000 with custom eboot loader

Code: Select all

user@localhost:~/esketch$ ~/arduino-cli/bin/arduino-cli compile --log --verbose --output-dir ./build --fqbn esp8266:esp8266:nodemcuv2 .
Write application to 0x00080000

Code: Select all

user@localhost:~/esketch$ $HOME/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/esptool/esptool.py --port /dev/ttyUSB0 write_flash 0x00080000 ./build/esketch.ino.bin
Output is garbage

Code: Select all

21:43:47.653 -> L��g
21:43:47.653 -> J�J�Ʌ��叽ʑ�@�V(�E#��r�H�X̄ֈ����F�V(�)����ĤC��n�œ���M���E���A�B̝�3����D��b�HJ
21:43:47.717 -> 긞���JJJ	s)�����3�V3(�������(�����vV8ߟ��p's!���3��Ɔ����!�))))$6������ʉ��(����@'b��k�Ḟ=�(J�ʈ��ʊ����3�(�����3�F+(������������L'b7
21:43:47.749 -> �懆�D#�(���1���JJJJ	3�(�����3�V#(�������)))(&����#rC�'3�(���3��Ą����!��JJJJ	s)���������(����B!����č�t$�}�(j�€��ʊ����#�(�����1�B))JJ����������L'b7

Who is online

Users browsing this forum: No registered users and 6 guests