ESP32 Software

From ElectroDragon Wiki
Revision as of 16:39, 11 October 2019 by Chao (talk | contribs) (→‎Flashing)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Partition tables

0x1000: bootloader.bin -> https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/bootloader.html
0x4000: partitions_singleapp.bin -> partitions table

Config Menuconfig

The simplest way to use the partition table is to open the project configuration menu (idf.py menuconfig) and choose one of the simple predefined partition tables under CONFIG_PARTITION_TABLE_TYPE: “Single factory app, no OTA” “Factory app, two OTA definitions” In both cases the factory app is flashed at offset 0x10000. If you execute idf.py partition_table then it will print a summary of the partition table.

Built-in Partition Tables

Here is the summary printed for the “Single factory app, no OTA” configuration:

# Espressif ESP32 Partition Table
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,

At a 0x10000 (64KB) offset in the flash is the app labelled “factory”. The bootloader will run this app by default.

There are also two data regions defined in the partition table for storing NVS library partition and PHY init data.

Here is the summary printed for the “Factory app, two OTA definitions” configuration:

# Espressif ESP32 Partition Table 
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  0,    0,       0x10000, 1M,
ota_0,    0,    ota_0,  0x110000, 1M,
ota_1,    0,    ota_1,  0x210000, 1M,

There are now three app partition definitions. The type of the factory app (at 0x10000) and the next two “OTA” apps are all set to “app”, but their subtypes are different.

There is also a new “otadata” slot, which holds the data for OTA updates. The bootloader consults this data in order to know which app to execute. If “ota data” is empty, it will execute the factory app.

Understanding the Partitions, Bootloader, OTA0/1, etc

  • Below is the example for AT application
  • Clean up all flash, get serial output
rst:0x10 (RTCWDT_RTC_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371 
  • Load bootloader to flash 0x1000 and so far we still don't have the partitions table:
�[0;32mI (56) boot: ESP-IDF v3.2-127-gddbce78 2nd stage bootloader�[0m 
�[0;32mI (56) boot: compile time 12:07:35�[0m
�[0;32mI (57) boot: Enabling RNG early entropy source...�[0m
�[0;32mI (63) boot: SPI Speed      : 40MHz�[0m
�[0;32mI (67) boot: SPI Mode       : DIO�[0m
�[0;32mI (71) boot: SPI Flash Size : 4MB�[0m
�[0;32mI (75) boot: Partition Table:�[0m
�[0;32mI (78) boot: ## Label            Usage          Type ST Offset   Length�[0m
�[0;32mI (86) boot: End of partition table�[0m
�[0;31mE (90) boot: No bootable app partitions in the partition table�[0m
  • Load the partitions Table to 0x8000 (old bootloader use is 0x4000):
�[0;32mI (56) boot: ESP-IDF v3.2-127-gddbce78 2nd stage bootloader�[0m
�[0;32mI (56) boot: compile time 12:07:35�[0m
�[0;32mI (57) boot: Enabling RNG early entropy source...�[0m
�[0;32mI (63) boot: SPI Speed      : 40MHz�[0m
�[0;32mI (67) boot: SPI Mode       : DIO�[0m
�[0;32mI (71) boot: SPI Flash Size : 4MB�[0m
�[0;32mI (75) boot: Partition Table:�[0m
�[0;32mI (78) boot: ## Label            Usage          Type ST Offset   Length�[0m
�[0;32mI (86) boot:  0 phy_init         RF data          01 01 0000f000 00001000�[0m
�[0;32mI (93) boot:  1 otadata          OTA data         01 00 00010000 00002000�[0m
�[0;32mI (101) boot:  2 nvs              WiFi data        01 02 00012000 0000e000�[0m
�[0;32mI (108) boot:  3 at_customize     unknown          40 00 00020000 000e0000�[0m
�[0;32mI (116) boot:  4 ota_0            OTA app          00 10 00100000 00180000�[0m
�[0;32mI (123) boot:  5 ota_1            OTA app          00 11 00280000 00180000�[0m
�[0;32mI (131) boot: End of partition table�[0m
�[0;31mE (135) boot: ota data partition invalid and no factory, will try all partitions�[0m
�[0;31mE (143) esp_image: image at 0x100000 has invalid magic byte�[0m
�[0;33mW (149) esp_image: image at 0x100000 has invalid SPI mode 128�[0m
�[0;33mW (156) esp_image: image at 0x100000 has invalid SPI size 7�[0m
�[0;31mE (162) boot: OTA app partition slot 0 is not bootable�[0m
�[0;31mE (168) esp_image: image at 0x280000 has invalid magic byte�[0m
�[0;33mW (174) esp_image: image at 0x280000 has invalid SPI mode 255�[0m
�[0;33mW (181) esp_image: image at 0x280000 has invalid SPI size 15�[0m 
�[0;31mE (187) boot: OTA app partition slot 1 is not bootable�[0m
�[0;31mE (193) boot: No bootable app partitions in the partition table�[0m
  • load main AT bin file
�[0;32mI (553) esp_image: segment 5: paddr=0x0022435c vaddr=0x4008a79c size=0x0c9ec ( 51692) load�[0m
�[0;32mI (575) esp_image: segment 6: paddr=0x00230d50 vaddr=0x400c0000 size=0x00064 (   100) load�[0m
�[0;32mI (588) boot: Loaded app from partition at offset 0x100000�[0m
�[0;32mI (589) boot: Disabling RNG early entropy source...�[0m
factory_parameter partition missed
1.2.0
factory_parameter partition missed
  • It's still missing the at customized, load this file at_customized.bin to 0x20000, and all working
�[0;32mI (553) esp_image: segment 5: paddr=0x0022435c vaddr=0x4008a79c size=0x0c9ec ( 51692) load�[0m
�[0;32mI (575) esp_image: segment 6: paddr=0x00230d50 vaddr=0x400c0000 size=0x00064 (   100) load�[0m
�[0;32mI (588) boot: Loaded app from partition at offset 0x100000�[0m
�[0;32mI (589) boot: Disabling RNG early entropy source...�[0m
1.2.0

Flashing

Pre-setup

Example Flash AT Application

  • Flash each partitions, please check partitions details above
  • Download ESP32 AT BIN from here