Skip to content

Commit

Permalink
Partition check
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Kennard committed Oct 28, 2019
1 parent 8cb58af commit 23b7c24
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
menu "RevK"

config REVK_PARTITION_CHECK
bool "Check and update partition table"
default y
help
Enable automatic checking of partition table, and update if necessary

config REVK_APPNAME
string "Override app name"
default ""
Expand Down
2 changes: 2 additions & 0 deletions component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

COMPONENT_EMBED_FILES := ../build/partitions_4m.bin

1 change: 1 addition & 0 deletions partitions_2ota.csv → partitions_4m.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ phy_init, data, phy, 0xf000, 0x1000,
ota_0, 0, ota_0, , 0x1f0000,
ota_1, 0, ota_1, , 0x1f0000,
nvs, data, nvs, , 0xC000,
nvs_key, data, nvs_keys,, 0x1000,
27 changes: 27 additions & 0 deletions revk.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,33 @@ task (void *pvParameters)
void
revk_init (app_command_t * app_command_cb)
{ // Start the revk task, use __FILE__ and __DATE__ and __TIME__ to set task name and version ID
#ifdef CONFIG_REVK_PARTITION_CHECK
extern const uint8_t part_start[] asm ("_binary_partitions_4m_bin_start");
extern const uint8_t part_end[] asm ("_binary_partitions_4m_bin_end");
// Check and update partition table - expects some code to stay where it can run, i.e. 0x10000, but may clear all settings
if ((part_end - part_start) > SPI_FLASH_SEC_SIZE)
{
ESP_LOGE (TAG, "Block size error (%d>%d)", part_end - part_start, SPI_FLASH_SEC_SIZE);
return;
}
esp_err_t e;
uint8_t *mem = malloc (SPI_FLASH_SEC_SIZE);
if (!mem)
{
ESP_LOGE (TAG, "Malloc fail: %d", SPI_FLASH_SEC_SIZE);
return;
}
ESP_ERROR_CHECK (spi_flash_read (CONFIG_PARTITION_TABLE_OFFSET, mem, SPI_FLASH_SEC_SIZE));
if (memcmp (mem, part_start, part_end - part_start))
{
memset (mem, 0, SPI_FLASH_SEC_SIZE);
memcpy (mem, part_start, part_end - part_start);
ESP_ERROR_CHECK (spi_flash_erase_range (CONFIG_PARTITION_TABLE_OFFSET, SPI_FLASH_SEC_SIZE));
ESP_ERROR_CHECK (spi_flash_write (CONFIG_PARTITION_TABLE_OFFSET, mem, SPI_FLASH_SEC_SIZE));
esp_restart ();
}
free (mem);
#endif
nvs_flash_init ();
const esp_app_desc_t *app = esp_ota_get_app_description ();
ESP_ERROR_CHECK (nvs_open (TAG, NVS_READWRITE, &nvs)); // RevK settings
Expand Down

0 comments on commit 23b7c24

Please sign in to comment.