ESP32: Partition Table の確認方法

## Partition Table を確認するプログラム

Linux の場合、Partition Table の定義は次のフォルダーにあります。

```text
$HOME/.arduino15/packages/esp32/hardware/esp32/3.1.3/tools/partitions
```

Arduino IDE で Partition Table は　次で切り替えます。

ツール -> Partition Scheme
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/adb5f12d-535a-4924-b449-89e853f7bb91.png)


```text:partition01.ino
#include "esp_partition.h"

void setup() {
	Serial.begin(115200);
	Serial.println("*** setup *** aaa ***");
	delay(2000);
	Serial.println("*** setup *** bbb ***");
	delay(2000);
	Serial.println("*** setup *** ccc ***");
	delay(2000);

	Serial.println("Partition Table:");
	Serial.println("====================");

    // すべてのパーティションを取得
    esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);

    while (it != NULL) {
        const esp_partition_t *partition = esp_partition_get(it);
        Serial.printf("Name: %s, Type: 0x%X, SubType: 0x%X, Address: 0x%X, Size: %d KB\n",
                      partition->label, partition->type, partition->subtype, partition->address, partition->size / 1024);
        it = esp_partition_next(it);
    }
    esp_partition_iterator_release(it);

	delay(2000);
	Serial.println("*** setup *** end ***");
}

void loop() {
}
```

## Default 4MB with spiffs が選ばれた時

```csv:tools/partitions/default.csv
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x140000,
app1,     app,  ota_1,   0x150000,0x140000,
spiffs,   data, spiffs,  0x290000,0x160000,
coredump, data, coredump,0x3F0000,0x10000,
```

実行結果

```text
Partition Table:
====================
Name: app0, Type: 0x0, SubType: 0x10, Address: 0x10000, Size: 1280 KB
Name: app1, Type: 0x0, SubType: 0x11, Address: 0x150000, Size: 1280 KB
```

## Minimal が選ばれた時

```csv:tools/partitions/minimal.csv
 Name,   Type, SubType, Offset,   Size, Flags
nvs,      data, nvs,     0x9000,   0x5000,
otadata,  data, ota,     0xe000,   0x2000,
app0,     app,  ota_0,   0x10000,  0x140000,
spiffs,   data, spiffs,  0x150000, 0xA0000,
coredump, data, coredump,0x1F0000, 0x10000,
```

実行結果

```text
Partition Table:
====================
Name: app0, Type: 0x0, SubType: 0x10, Address: 0x10000, Size: 1280 KB
```

## Huge App が選ばれた時

```csv:tools/partitions/huge_app.csv
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x300000,
spiffs,   data, spiffs,  0x310000,0xE0000,
coredump, data, coredump,0x3F0000,0x10000,
```

実行結果

```text
Partition Table:
====================
Name: app0, Type: 0x0, SubType: 0x10, Address: 0x10000, Size: 3072 KB
```

## NO OTA (2MB APP / 2MB SPIFFS) が選ばれた時

```csv:tools/partitions/no_ota.csv
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x200000,
spiffs,   data, spiffs,  0x210000,0x1E0000,
coredump, data, coredump,0x3F0000,0x10000,
```

実行結果

```text
Partition Table:
====================
Name: app0, Type: 0x0, SubType: 0x10, Address: 0x10000, Size: 2048 KB
```