forked from espressif/esp-idf
feat(partitions): Adds new partition types and subtypes for bootloader and partition_table
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -29,6 +29,14 @@ extern "C" {
|
||||
#define PART_SUBTYPE_DATA_NVS_KEYS 0x04
|
||||
#define PART_SUBTYPE_DATA_EFUSE_EM 0x05
|
||||
|
||||
#define PART_TYPE_BOOTLOADER 0x02
|
||||
#define PART_SUBTYPE_BOOTLOADER_PRIMARY 0x00
|
||||
#define PART_SUBTYPE_BOOTLOADER_OTA 0x01
|
||||
|
||||
#define PART_TYPE_PARTITION_TABLE 0x03
|
||||
#define PART_SUBTYPE_PARTITION_TABLE_PRIMARY 0x00
|
||||
#define PART_SUBTYPE_PARTITION_TABLE_OTA 0x01
|
||||
|
||||
#define PART_TYPE_END 0xff
|
||||
#define PART_SUBTYPE_END 0xff
|
||||
|
||||
@@ -41,7 +49,11 @@ extern "C" {
|
||||
/* Pre-partition table fixed flash offsets */
|
||||
#define ESP_BOOTLOADER_DIGEST_OFFSET 0x0
|
||||
#define ESP_BOOTLOADER_OFFSET CONFIG_BOOTLOADER_OFFSET_IN_FLASH /* Offset of bootloader image. Has matching value in bootloader KConfig.projbuild file. */
|
||||
#define ESP_PRIMARY_BOOTLOADER_OFFSET CONFIG_BOOTLOADER_OFFSET_IN_FLASH /* Offset of Primary bootloader image. */
|
||||
#define ESP_PARTITION_TABLE_OFFSET CONFIG_PARTITION_TABLE_OFFSET /* Offset of partition table. Backwards-compatible name.*/
|
||||
#define ESP_PRIMARY_PARTITION_TABLE_OFFSET CONFIG_PARTITION_TABLE_OFFSET /* Offset of partition table. */
|
||||
#define ESP_PARTITION_TABLE_SIZE (0x1000) /* The partition table occupies 1 sector of flash (SPI_FLASH_SEC_SIZE) */
|
||||
#define ESP_BOOTLOADER_SIZE (ESP_PARTITION_TABLE_OFFSET - ESP_BOOTLOADER_OFFSET)
|
||||
|
||||
#define ESP_PARTITION_TABLE_MAX_LEN 0xC00 /* Maximum length of partition table data */
|
||||
#define ESP_PARTITION_TABLE_MAX_ENTRIES (ESP_PARTITION_TABLE_MAX_LEN / sizeof(esp_partition_info_t)) /* Maximum length of partition table data, including terminating entry */
|
||||
|
@@ -199,6 +199,26 @@ bool bootloader_utility_load_partition_table(bootloader_state_t *bs)
|
||||
break;
|
||||
}
|
||||
break; /* PARTITION_USAGE_DATA */
|
||||
case PART_TYPE_BOOTLOADER: /* Bootloader partition */
|
||||
switch (partition->subtype) {
|
||||
case PART_SUBTYPE_BOOTLOADER_PRIMARY:
|
||||
partition_usage = "primary bootloader";
|
||||
break;
|
||||
case PART_SUBTYPE_BOOTLOADER_OTA:
|
||||
partition_usage = "ota bootloader";
|
||||
break;
|
||||
}
|
||||
break; /* PART_TYPE_BOOTLOADER */
|
||||
case PART_TYPE_PARTITION_TABLE: /* Partition table partition */
|
||||
switch (partition->subtype) {
|
||||
case PART_SUBTYPE_PARTITION_TABLE_PRIMARY:
|
||||
partition_usage = "primary partition_table";
|
||||
break;
|
||||
case PART_SUBTYPE_PARTITION_TABLE_OTA:
|
||||
partition_usage = "ota partition_table";
|
||||
break;
|
||||
}
|
||||
break; /* PART_TYPE_PARTITION_TABLE */
|
||||
default: /* other partition type */
|
||||
break;
|
||||
}
|
||||
|
@@ -67,6 +67,12 @@ typedef enum {
|
||||
* @internal Keep this enum in sync with PartitionDefinition class gen_esp32part.py @endinternal
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY = 0x00, //!< Primary Bootloader
|
||||
ESP_PARTITION_SUBTYPE_BOOTLOADER_OTA = 0x01, //!< Temporary OTA storage for Bootloader, where the OTA uploads a new Bootloader image
|
||||
|
||||
ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY = 0x00, //!< Primary Partition table
|
||||
ESP_PARTITION_SUBTYPE_PARTITION_TABLE_OTA = 0x01, //!< Temporary OTA storage for Partition table, where the OTA uploads a new Partition table image
|
||||
|
||||
ESP_PARTITION_SUBTYPE_APP_FACTORY = 0x00, //!< Factory application partition
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN = 0x10, //!< Base for OTA partition subtypes
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_0 = ESP_PARTITION_SUBTYPE_APP_OTA_MIN + 0, //!< OTA partition 0
|
||||
|
@@ -67,6 +67,8 @@ const char *esp_partition_type_to_str(const uint32_t type)
|
||||
switch (type) {
|
||||
case PART_TYPE_APP: return "app";
|
||||
case PART_TYPE_DATA: return "data";
|
||||
case PART_TYPE_BOOTLOADER: return "bootloader";
|
||||
case PART_TYPE_PARTITION_TABLE: return "partition_table";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
@@ -74,6 +76,18 @@ const char *esp_partition_type_to_str(const uint32_t type)
|
||||
const char *esp_partition_subtype_to_str(const uint32_t type, const uint32_t subtype)
|
||||
{
|
||||
switch (type) {
|
||||
case PART_TYPE_BOOTLOADER:
|
||||
switch (subtype) {
|
||||
case PART_SUBTYPE_BOOTLOADER_PRIMARY: return "primary";
|
||||
case PART_SUBTYPE_BOOTLOADER_OTA: return "ota";
|
||||
default: return "unknown";
|
||||
}
|
||||
case PART_TYPE_PARTITION_TABLE:
|
||||
switch (subtype) {
|
||||
case PART_SUBTYPE_PARTITION_TABLE_PRIMARY: return "primary";
|
||||
case PART_SUBTYPE_PARTITION_TABLE_OTA: return "ota";
|
||||
default: return "unknown";
|
||||
}
|
||||
case PART_TYPE_APP:
|
||||
switch (subtype) {
|
||||
case PART_SUBTYPE_FACTORY: return "factory";
|
||||
|
@@ -7,11 +7,8 @@
|
||||
# See https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/partition-tables.html
|
||||
# for explanation of partition table structure and uses.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import binascii
|
||||
import errno
|
||||
@@ -36,8 +33,12 @@ __version__ = '1.3'
|
||||
|
||||
APP_TYPE = 0x00
|
||||
DATA_TYPE = 0x01
|
||||
BOOTLOADER_TYPE = 0x02
|
||||
PARTITION_TABLE_TYPE = 0x03
|
||||
|
||||
TYPES = {
|
||||
'bootloader': BOOTLOADER_TYPE,
|
||||
'partition_table': PARTITION_TABLE_TYPE,
|
||||
'app': APP_TYPE,
|
||||
'data': DATA_TYPE,
|
||||
}
|
||||
@@ -56,6 +57,14 @@ def get_ptype_as_int(ptype):
|
||||
|
||||
# Keep this map in sync with esp_partition_subtype_t enum in esp_partition.h
|
||||
SUBTYPES = {
|
||||
BOOTLOADER_TYPE: {
|
||||
# 'primary': 0x00, # The tool does not allow to define this partition yet.
|
||||
'ota': 0x01,
|
||||
},
|
||||
PARTITION_TABLE_TYPE: {
|
||||
# 'primary': 0x00, # The tool does not allow to define this partition yet.
|
||||
'ota': 0x01,
|
||||
},
|
||||
APP_TYPE: {
|
||||
'factory': 0x00,
|
||||
'test': 0x20,
|
||||
@@ -90,6 +99,8 @@ def get_subtype_as_int(ptype, subtype):
|
||||
ALIGNMENT = {
|
||||
APP_TYPE: 0x10000,
|
||||
DATA_TYPE: 0x1000,
|
||||
BOOTLOADER_TYPE: 0x1000,
|
||||
PARTITION_TABLE_TYPE: 0x1000,
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +121,7 @@ def get_alignment_size_for_type(ptype):
|
||||
else:
|
||||
# For no secure boot enabled case, app partition must be 4K aligned (min. flash erase size)
|
||||
return 0x1000
|
||||
# No specific size alignement requirement as such
|
||||
# No specific size alignment requirement as such
|
||||
return 0x1
|
||||
|
||||
|
||||
@@ -119,6 +130,10 @@ def get_partition_type(ptype):
|
||||
return APP_TYPE
|
||||
if ptype == 'data':
|
||||
return DATA_TYPE
|
||||
if ptype == 'bootloader':
|
||||
return BOOTLOADER_TYPE
|
||||
if ptype == 'partition_table':
|
||||
return PARTITION_TABLE_TYPE
|
||||
raise InputError('Invalid partition type')
|
||||
|
||||
|
||||
|
@@ -75,9 +75,13 @@ Name field can be any meaningful name. It is not significant to the {IDF_TARGET_
|
||||
Type Field
|
||||
~~~~~~~~~~
|
||||
|
||||
Partition type field can be specified as ``app`` (0x00) or ``data`` (0x01). Or it can be a number 0-254 (or as hex 0x00-0xFE). Types 0x00-0x3F are reserved for ESP-IDF core functions.
|
||||
Partition type field can be specified as a name or a number 0-254 (or as hex 0x00-0xFE). Types 0x00-0x3F are reserved for ESP-IDF core functions.
|
||||
|
||||
If your app needs to store data in a format not already supported by ESP-IDF, then please add a custom partition type value in the range 0x40-0xFE.
|
||||
- ``app`` (0x00),
|
||||
- ``data`` (0x01),
|
||||
- ``bootloader`` (0x02). By default, this partition is not included in any CSV partition table files because it is not required and does not impact the system's functionality. It is only useful for the bootloader OTA update. Even if this partition is not present in the CSV file, it is still possible to perform the OTA. Please note that if you specify this partition in the CSV file, its address and size must match Kconfigs,
|
||||
- ``partition_table`` (0x03),
|
||||
- 0x40-0xFE are reserved for **custom partition types**. If your app needs to store data in a format not already supported by ESP-IDF, then use a value from this range.
|
||||
|
||||
See :cpp:type:`esp_partition_type_t` for the enum definitions for ``app`` and ``data`` partitions.
|
||||
|
||||
@@ -105,6 +109,16 @@ See enum :cpp:type:`esp_partition_subtype_t` for the full list of subtypes defin
|
||||
- ``ota_0`` (0x10) ... ``ota_15`` (0x1F) are the OTA app slots. When :doc:`OTA <../api-reference/system/ota>` is in use, the OTA data partition configures which app slot the bootloader should boot. When using OTA, an application should have at least two OTA application slots (``ota_0`` & ``ota_1``). Refer to the :doc:`OTA documentation <../api-reference/system/ota>` for more details.
|
||||
- ``test`` (0x20) is a reserved subtype for factory test procedures. It will be used as the fallback boot partition if no other valid app partition is found. It is also possible to configure the bootloader to read a GPIO input during each boot, and boot this partition if the GPIO is held low, see :ref:`bootloader_boot_from_test_firmware`.
|
||||
|
||||
* When type is ``bootloader``, the SubType field can be specified as:
|
||||
|
||||
- ``primary`` (0x00). It is the so-called 2nd stage bootloader, which is placed at the {IDF_TARGET_CONFIG_BOOTLOADER_OFFSET_IN_FLASH} address in the flash. The ``gen_esp32part.py`` does not allow to have this partition in the CSV file for now.
|
||||
- ``ota`` (0x01). It is a temporary bootloader partition used by the bootloader OTA update functionality for downloading a new image.
|
||||
|
||||
* When type is ``partition_table``, the SubType field can be specified as:
|
||||
|
||||
- ``primary`` (0x00). It is the primary partition table, which is placed at the :ref:`CONFIG_PARTITION_TABLE_OFFSET` address in the flash. The ``gen_esp32part.py`` does not allow to have this partition in the CSV file for now.
|
||||
- ``ota`` (0x01). It is a temporary partition table partition used by the partition table OTA update functionality for downloading a new image.
|
||||
|
||||
* When type is ``data``, the subtype field can be specified as ``ota`` (0x00), ``phy`` (0x01), ``nvs`` (0x02), nvs_keys (0x04), or a range of other component-specific subtypes (see :cpp:type:`subtype enum <esp_partition_subtype_t>`).
|
||||
|
||||
- ``ota`` (0) is the :ref:`OTA data partition <ota_data_partition>` which stores information about the currently selected OTA app slot. This partition should be 0x2000 bytes in size. Refer to the :ref:`OTA documentation <ota_data_partition>` for more details.
|
||||
|
@@ -2,3 +2,4 @@
|
||||
# Turn verbose log on for bootloader
|
||||
#
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE=y
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0xF000
|
||||
|
Reference in New Issue
Block a user