Flash Bootloader to ESP32 via JTAG [Solved]

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Flash Bootloader to ESP32 via JTAG [Solved]

Postby jubueche » Sat Jan 19, 2019 9:09 pm

Hello,

we are planning on buying the ESP32 for a product without a bootloader flashed and now we want to upload one via JTAG (Segger Jlink). Are there any resources someone could point us at that might help?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Flash Bootloader to ESP32 via JTAG

Postby ESP_igrr » Sun Jan 20, 2019 2:25 am

Writing to the flash chip using JTAG is described in https://docs.espressif.com/projects/esp ... -debugging for the (more common) case of writing the application. For the bootloader the command will be almost the same, except for the different .bin file and address.

Note that ESP32 also includes first stage bootloader, located in ROM. This bootloader can not be reprogrammed or erased, and allows for uploading to flash over UART.

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: Flash Bootloader to ESP32 via JTAG

Postby jubueche » Sun Jan 20, 2019 8:23 am

Hi,

What we did: Use build/bootloader/bootloader.bin and Flash it using the same command except with bootloader.bin at adress 0x1000.
After that when we tried flashing a normal file again, our system crashes.
Why is the bootloader in the build directory? It seems that it always should be the same..but given that it is in build maybe it isn’t?

Also does the completely naked Esp32 (no Wroom etc) come preflashed with the primary bootloader or even the second also?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Flash Bootloader to ESP32 via JTAG

Postby ESP_Sprite » Sun Jan 20, 2019 8:36 am

The (secondary) bootloader is not always the same for every project, as it can be configured to e.g. clear partitions when a GPIO is set to a certain level. For that reason, it's built alongside the project. And yes, the primary bootloader is in ROM, so every ESP32 ships with it and you cannot modify or remove it.

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: Flash Bootloader to ESP32 via JTAG

Postby jubueche » Sun Jan 20, 2019 9:08 am

Ok, that makes sense. This is the error log that we get:

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:6380
load:0x40078000,len:11152
load:0x40080400,len:6680
entry 0x40080764
I (56) boot: ESP-IDF v3.3-beta1-171-g577f8d852-dirty 2nd stage bootloader
I (56) boot: compile time 23:26:45
I (58) boot: Enabling RNG early entropy source...
I (64) boot: SPI Speed : 80MHz
I (68) boot: SPI Mode : DIO
I (72) boot: SPI Flash Size : 4MB
E (76) flash_parts: partition 0 invalid magic number 0x0
E (82) boot: Failed to verify partition table
E (87) boot: load partition table error!
ets Jun 8 2016 00:22:57


Maybe we have to clear the space reserved for the second-stage bootloader?
To your information, we previously flashed an application to address 0x1000 and it didn't work. We think the 1st bootloader is looking for a bootloader and the application just hasn't the format.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Flash Bootloader to ESP32 via JTAG

Postby ESP_Sprite » Sun Jan 20, 2019 9:16 am

No, that's actually the 2nd bootloader that loaded successfully, but couldn't find a valid partition table. It exits because it has no way to locate the user app. Sounds like you need to flash the partition table, and you should be good.

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: Flash Bootloader to ESP32 via JTAG

Postby jubueche » Sun Jan 20, 2019 9:27 am

After having flashed rthe second bootloader to 0x1000, we tried flashing a sketch to 0x10000 (ten thousand) and got this log from OpenOCD:

-f interface/jlink.cfg -f board/esp-wroom-32.cfg -c "program_esp32 app-template.bin 0x10000 verify exit"
Open On-Chip Debugger 0.10.0-dev (2018-11-05-04:03)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 2000 kHz
esp32 interrupt mask on
Info : No device selected, using first device.
Info : J-Link V10 compiled Oct 26 2018 12:04:17
Info : Hardware version: 10.10
Info : VTarget = 3.315 V
Info : clock speed 2000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : Target halted. PRO_CPU: PC=0x4000921A (active) APP_CPU: PC=0x00000000
Info : esp32: Debug controller 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Core 0 was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32: Debug controller 1 was reset (pwrstat=0x5F, after clear 0x5F).
Info : esp32: Core 1 was reset (pwrstat=0x5F, after clear 0x5F).
Info : Target halted. PRO_CPU: PC=0x5000004B (active) APP_CPU: PC=0x00000000
Info : esp32: Core 0 was reset (pwrstat=0x1F, after clear 0x0F).
Info : Target halted. PRO_CPU: PC=0x40000400 (active) APP_CPU: PC=0x40000400
** Programming Started **
auto erase enabled
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
Warn : Empty flash mapping!
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
Info : Auto-detected flash size 4096 KB
Info : Using flash size 4096 KB
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
wrote 151552 bytes from file app-template.bin in 6.266277s (23.618 KiB/s)
** Programming Finished **
** Verify Started **
Info : Target halted. PRO_CPU: PC=0x4009171A (active) APP_CPU: PC=0x40000400
read 149376 bytes from file app-template.bin and flash bank 0 at offset 0x00010000 in 2.371351s (61.516 KiB/s)
contents match
** Verified OK **
shutdown command invoked

Everything looks fine, except the warning Warn : Empty flash mapping!
What is this about?

When plugging in the USB again and executing make monitor, we see the warning from one post earlier about the magic partition number not being correct.

The interesting part is that when we flash it using Arduino, everything works fine again. I am assuming the arduino IDE flashes the appllication specific Bootloader.bin file also, right?

jubueche
Posts: 32
Joined: Sat Jan 19, 2019 4:03 pm

Re: Flash Bootloader to ESP32 via JTAG

Postby jubueche » Sun Jan 20, 2019 9:30 am

Sorry I did not see your reply before I posted. The partition table information is located at 0x8000, right?
Is there a .bin file in the build directory? And where should I flash it to?
I have found partitions_singleapp.bin in the build folder. Is that the one?

Am I understanding correctly that we are flashing the partition information?

[Update]: I saw that esptool allows you to flash the partition table using make partition_table-flash
[Update2]: We flashed to partitions_singleapp.bin file to 0x8000 and it worked! Thanks.
Help is much appreciated!

Who is online

Users browsing this forum: asargent, Gaston1980, Google [Bot] and 163 guests