Bootloader
Bootloader
=====================
:link_to_translation:`zh_CN:[中文]`
Bootloader compatibility
-------------------------
The bootloader does not support booting apps from older versions of ESP-IDF. When
updating ESP-IDF manually on an existing product that might need to downgrade the
app to an older version, keep using the older ESP-IDF bootloader binary as well.
.. note::
.. only:: esp32
Bootloaders built from very old versions of ESP-IDF (before ESP-IDF V2.1)
perform less hardware configuration than newer versions. When using a bootloader
from these early ESP-IDF versions and building a new app, enable the config
option :ref:`CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS`.
Bootloaders built from versions of ESP-IDF before V3.1 do not support MD5
checksums in the partition table binary. When using a bootloader from these ESP-IDF
versions and building a new app, enable the config
option :ref:`CONFIG_ESP32_COMPATIBLE_PRE_V3_1_BOOTLOADERS`.
The :first stage bootloader in ROM reads the second stage bootloader header from
flash and uses these settings to load it. However, at this time the system clock
speed is lower than configured and not all flash modes are supported. When the
second stage bootloader then runs and re-configures the flash, it reads values from
the currently selected app binary header not the bootloader header. This allows an
OTA update to change the SPI flash settings in use.
.. only:: esp32
Bootloaders prior to ESP-IDF V4.0 used the bootloader's own header to configure
the SPI flash, meaning these values could not be changed in an update. To maintain
compatibility with older bootloaders, the app re-initializes the flash settings
during app startup using the configuration found in the app header.
FACTORY reset
---------------------------
The user can write a basic working firmware and load it into the factory partition.
Next, update the firmware via OTA (over the air). The updated firmware will be
loaded into an OTA app partition slot and the OTA data partition is updated to boot
from this partition.
If you want to be able to roll back to the factory firmware and clear the settings,
then you need to set :ref:`CONFIG_BOOTLOADER_FACTORY_RESET`.
The factory reset mechanism allows to reset the device to factory settings:
Partition table.::
.. _bootloader_boot_from_test_firmware:
Customer bootloader
---------------------
The current bootloader implementation allows the customer to override it. To do
this, you must copy the folder `/esp-idf/components/bootloader` and then edit
`/your_project/components/bootloader/subproject/main/bootloader_main.c`.
In the bootloader space, you can not use the drivers and functions from other
components. If necessary, then the required functionality should be placed in the
folder bootloader (note that this will increase its size).
It is necessary to monitor its size because there can be overlays in memory with a
partition table leading to damage. At the moment the bootloader is limited to the
partition table from the address `0x8000`.