partition.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdbool.h>
4 
5 #define ESP_PARTITION_MAGIC 0x50AA
6 #define PARTITION_TYPE_APP 0x00
7 #define PARTITION_APP_SUBTYPE_FACTORY 0x00 // Corresponds to Slot #0
8 #define PARTITION_APP_SUBTYPE_OTA0 0x10 // Also corresponds to Slot #0
9 #define PARTITION_TYPE_DATA 0x01
10 #define PARTITION_DATA_SUBTYPE_SYSPARAM 0x40 // SDK system parameters
11 #define ESP_PARTITION_TABLE_MAX_LEN 0x0C00
12 
18  uint8_t type;
19  uint8_t subtype;
20  uint32_t offset;
21  uint32_t size;
22  char name[16];
23  uint32_t flags;
24 };
25 
26 // Read ROM locations from partition table. Return true if config changed
27 static bool scan_partitions(rboot_config* romconf)
28 {
29  bool config_changed = false;
30  uint8_t rom_count = 0;
31  struct esp_partition_info_t info;
32  uint32_t offset;
33  for(offset = 0; offset < ESP_PARTITION_TABLE_MAX_LEN; offset += sizeof(info)) {
34  info.magic = 0;
35  SPIRead(PARTITION_TABLE_OFFSET + offset, &info, sizeof(info));
36  if(info.magic != ESP_PARTITION_MAGIC) {
37  break;
38  }
39  if(info.type != PARTITION_TYPE_APP) {
40  continue;
41  }
42  unsigned index;
44  index = 0;
45  } else {
46  index = info.subtype - PARTITION_APP_SUBTYPE_OTA0;
47  if(index >= MAX_ROMS) {
48  continue;
49  }
50  }
51  echof("Found '%s' @ 0x%08x, size 0x%08x, subtype 0x%02X\r\n", info.name, info.offset, info.size, info.subtype);
52  if(romconf->roms[index] != info.offset) {
53  romconf->roms[index] = info.offset;
54  config_changed = true;
55  }
56  if(index >= rom_count) {
57  rom_count = index + 1;
58  }
59  }
60  if(romconf->count != rom_count) {
61  config_changed = true;
62  romconf->count = rom_count;
63  }
64  return config_changed;
65 }
66 
67 #if defined(BOOT_GPIO_ENABLED) || defined(BOOT_GPIO_SKIP_ENABLED)
68 
69 // Supports MODE_GPIO_ERASES_SDKCONFIG setting
70 static void erase_sdk_config()
71 {
72  echof("Erasing SDK config partition.\r\n");
73 
74  bool config_changed = false;
75  uint8_t rom_count = 0;
76  struct esp_partition_info_t info;
77  uint32_t offset;
78  for(offset = 0; offset < ESP_PARTITION_TABLE_MAX_LEN; offset += sizeof(info)) {
79  info.magic = 0;
80  if(SPIRead(PARTITION_TABLE_OFFSET + offset, &info, sizeof(info)) != 0) {
81  break;
82  }
83  if(info.magic != ESP_PARTITION_MAGIC) {
84  break;
85  }
87  continue;
88  }
89  uint32_t sector = info.offset / SECTOR_SIZE;
90  uint8_t sector_count = info.size / SECTOR_SIZE;
91  while(sector_count-- != 0) {
92  SPIEraseSector(sector++);
93  }
94  }
95 }
96 
97 #endif
uint8_t subtype
Sub-type for partition (interpretation dependent upon type)
Definition: partition.h:19
#define MAX_ROMS
Definition: rboot.h:92
#define PARTITION_TYPE_DATA
Definition: partition.h:9
#define ESP_PARTITION_TABLE_MAX_LEN
Definition: partition.h:11
#define ESP_PARTITION_MAGIC
Definition: partition.h:5
Structure containing rBoot configuration.
Definition: rboot.h:105
uint32_t roms[MAX_ROMS]
Flash addresses of each ROM.
Definition: rboot.h:113
uint32_t SPIEraseSector(int)
uint8_t count
Quantity of ROMs available to boot.
Definition: rboot.h:111
#define PARTITION_TYPE_APP
Definition: partition.h:6
char name[16]
Unique identifer for entry.
Definition: partition.h:22
#define PARTITION_APP_SUBTYPE_OTA0
Definition: partition.h:8
uint32_t offset
Start offset.
Definition: partition.h:20
#define SECTOR_SIZE
Definition: rboot.h:69
uint8_t type
Main type of partition.
Definition: partition.h:18
Internal structure describing the binary layout of a partition table entry.
Definition: partition.h:16
uint16_t magic
Fixed value to identify valid entry, appears as 0xFFFF at end of table.
Definition: partition.h:17
static bool scan_partitions(rboot_config *romconf)
Definition: partition.h:27
uint32_t size
Size of partition in bytes.
Definition: partition.h:21
uint32_t SPIRead(uint32_t addr, void *outptr, uint32_t len)
#define PARTITION_DATA_SUBTYPE_SYSPARAM
Definition: partition.h:10
#define PARTITION_APP_SUBTYPE_FACTORY
Definition: partition.h:7
uint32_t flags
Various option flags.
Definition: partition.h:23