mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-13 17:00:19 +00:00
Add MG_OTA_{ROLLBACK,STATE_SET,STATE_GET}
This commit is contained in:
1 parent
a6452f5311
commit
67f249c58a
16 files changed
+345
-131
No files matched your search
+7
-7
@@ -112,6 +112,7 @@ MG_IRAM static bool mg_stm32h7_erase(void *addr) {
|
||||
MG_REG(bank + FLASH_CR) |= (sector & 7U) << 8U; // Sector to erase
|
||||
MG_REG(bank + FLASH_CR) |= MG_BIT(2); // Sector erase bit
|
||||
MG_REG(bank + FLASH_CR) |= MG_BIT(7); // Start erasing
|
||||
flash_wait(bank);
|
||||
ok = !flash_is_err(bank);
|
||||
MG_DEBUG(("Erase sector %lu @ %p %s. CR %#lx SR %#lx", sector, addr,
|
||||
ok ? "ok" : "fail", MG_REG(bank + FLASH_CR),
|
||||
@@ -127,9 +128,7 @@ MG_IRAM static bool mg_stm32h7_swap(void) {
|
||||
uint32_t desired = flash_bank_is_swapped(bank) ? 0 : MG_BIT(31);
|
||||
flash_unlock();
|
||||
flash_clear_err(bank);
|
||||
// printf("OPTSR_PRG 1 %#lx\n", FLASH->OPTSR_PRG);
|
||||
MG_SET_BITS(MG_REG(bank + FLASH_OPTSR_PRG), MG_BIT(31), desired);
|
||||
// printf("OPTSR_PRG 2 %#lx\n", FLASH->OPTSR_PRG);
|
||||
MG_REG(bank + FLASH_OPTCR) |= MG_BIT(1); // OPTSTART
|
||||
while ((MG_REG(bank + FLASH_OPTSR_CUR) & MG_BIT(31)) != desired) (void) 0;
|
||||
return true;
|
||||
@@ -162,7 +161,7 @@ MG_IRAM static bool mg_stm32h7_write(void *addr, const void *buf, size_t len) {
|
||||
if (flash_is_err(bank)) ok = false;
|
||||
}
|
||||
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
|
||||
MG_DEBUG(("Flash write %lu bytes @ %p: %s. CR %#lx SR %#lx", len, dst,
|
||||
MG_DEBUG(("Flash write %lu bytes @ %p: %s. CR %#lx SR %#lx", len, addr,
|
||||
ok ? "ok" : "fail", MG_REG(bank + FLASH_CR),
|
||||
MG_REG(bank + FLASH_SR)));
|
||||
MG_REG(bank + FLASH_CR) &= ~MG_BIT(1); // Clear programming flag
|
||||
@@ -175,7 +174,7 @@ MG_IRAM static void single_bank_swap(char *p1, char *p2, size_t s, size_t ss) {
|
||||
for (size_t ofs = 0; ofs < s; ofs += ss) {
|
||||
mg_stm32h7_write(p1 + ofs, p2 + ofs, ss);
|
||||
}
|
||||
*(volatile unsigned long *) 0xe000ed0c = 0x5fa0004;
|
||||
*(volatile uint32_t *) 0xe000ed0cU = 0x5fa0004U; // NVIC_SystemReset()
|
||||
}
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
@@ -185,8 +184,8 @@ bool mg_ota_begin(size_t new_firmware_size) {
|
||||
s_mg_flash_stm32h7.size /= 2;
|
||||
}
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
*((uint32_t *) 0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *) 0xE000ED94) == 0 ? "ok" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h7);
|
||||
}
|
||||
@@ -199,7 +198,7 @@ bool mg_ota_end(void) {
|
||||
if (mg_ota_flash_end(&s_mg_flash_stm32h7)) {
|
||||
if (is_dualbank()) {
|
||||
// Bank swap is deferred until reset, been executing in flash, reset
|
||||
*(volatile unsigned long *) 0xe000ed0c = 0x5fa0004;
|
||||
*(volatile uint32_t *) 0xe000ed0cU = 0x5fa0004U; // NVIC_SystemReset()
|
||||
} else {
|
||||
// Swap partitions. Pray power does not go away
|
||||
MG_INFO(("Swapping partitions, size %u (%u sectors)",
|
||||
@@ -217,5 +216,6 @@ bool mg_ota_end(void) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct mg_flash *mg_flash = &s_mg_flash_stm32h7;
|
||||
#endif
|
||||
Reference in new issue
Block a user