Skip to content

Commit

Permalink
OTA check
Browse files Browse the repository at this point in the history
  • Loading branch information
revk committed Aug 16, 2023
1 parent 9dd57c9 commit 1d7d47a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions partitions_4m.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RevK, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xd000, 0x2000,
phy_init, data, phy, 0xf000, 0x1000,
ota_0, 0, ota_0, 0x10000, 0x1f0000,
ota_1, 0, ota_1, , 0x1f0000,
nvs, data, nvs, 0x3F0000,0xF000,
ota_0, 0, ota_0, 0x10000, 0x1f0000,
ota_1, 0, ota_1, 0x200000,0x1f0000,
nvs, data, nvs, 0x3F0000,0xf000,
nvs_key, data, nvs_keys,0x3FF000,0x1000,
26 changes: 19 additions & 7 deletions revk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1449,11 +1449,11 @@ task (void *pvParameters)
char col = 0;
if (lit)
col = *c++; // Sequences the colours set for the on state
gpio_set_level (blink[0] & IO_MASK, (col == 'R' || col == 'Y' || col == 'M' || col == 'W') ^ ((blink[0] & IO_INV) ? 1 : 0)); // Red LED
gpio_set_level (blink[1] & IO_MASK, (col == 'G' || col == 'Y' || col == 'C' || col == 'W') ^ ((blink[1] & IO_INV) ? 1 : 0)); // Green LED
gpio_set_level (blink[2] & IO_MASK, (col == 'B' || col == 'C' || col == 'M' || col == 'W') ^ ((blink[2] & IO_INV) ? 1 : 0)); // Blue LED
gpio_set_level (blink[0] & IO_MASK, (col == 'R' || col == 'Y' || col == 'M' || col == 'W') ^ ((blink[0] & IO_INV) ? 1 : 0)); // Red LED
gpio_set_level (blink[1] & IO_MASK, (col == 'G' || col == 'Y' || col == 'C' || col == 'W') ^ ((blink[1] & IO_INV) ? 1 : 0)); // Green LED
gpio_set_level (blink[2] & IO_MASK, (col == 'B' || col == 'C' || col == 'M' || col == 'W') ^ ((blink[2] & IO_INV) ? 1 : 0)); // Blue LED
} else
gpio_set_level (blink[0] & IO_MASK, lit ^ ((blink[0] & IO_INV) ? 1 : 0)); // Single LED
gpio_set_level (blink[0] & IO_MASK, lit ^ ((blink[0] & IO_INV) ? 1 : 0)); // Single LED
}
}
}
Expand Down Expand Up @@ -1736,8 +1736,20 @@ revk_boot (app_callback_t * app_callback_cb)
{
REVK_ERR_CHECK (esp_flash_read (NULL, mem, CONFIG_PARTITION_TABLE_OFFSET, secsize));
if (memcmp (mem, part_start, part_end - part_start))
{
if (strchr (ota_partition->label, '0'))
{ // Different partition table
// Only update partition if we are running at an address that is valid in new partition table.
uint8_t *p = part_start;
while (p < part_end)
{
if (p[0] == 0xAA && !strncmp (p + 12, "ota", 3))
{
uint32_t a = (p[4] | (p[5] << 8) | (p[6] << 16) | (p[7] << 24));
if (a == ota_partition->address)
break;
}
p += 32;
}
if (p < part_end)
{
#ifndef CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED
#error Set CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED to allow CONFIG_REVK_PARTITION_CHECK
Expand All @@ -1749,7 +1761,7 @@ revk_boot (app_callback_t * app_callback_cb)
REVK_ERR_CHECK (esp_flash_write (NULL, mem, CONFIG_PARTITION_TABLE_OFFSET, secsize));
esp_restart ();
} else
ESP_LOGE (TAG, "Not updating partition as not on ota 0 (%s)", ota_partition->label);
ESP_LOGE (TAG, "Not updating partition as no ota at %lX", ota_partition->address);
} else
{
ESP_LOGI (TAG, "Partition table at %X as expected (%s)", CONFIG_PARTITION_TABLE_OFFSET, table);
Expand Down

0 comments on commit 1d7d47a

Please sign in to comment.