Make TLS certificate storage PUYA compatible

This commit is contained in:
Theo Arends 2019-11-21 11:08:30 +01:00
parent 6706c89b66
commit f243b06726
1 changed files with 3 additions and 21 deletions

View File

@ -1134,7 +1134,9 @@ void CmndTlsKey(void) {
memcpy(spi_buffer + tls_obj_store_offset + entry->start, bin_buf, entry->len);
}
TlsWriteSpiBuffer(spi_buffer);
if (ESP.flashEraseSector(tls_spi_start_sector)) {
ESP.flashWrite(tls_spi_start_sector * SPI_FLASH_SEC_SIZE, (uint32_t*) spi_buffer, SPI_FLASH_SEC_SIZE);
}
free(spi_buffer);
free(bin_buf);
}
@ -1146,26 +1148,6 @@ void CmndTlsKey(void) {
}
}
extern "C" {
#include "spi_flash.h"
}
void TlsWriteSpiBuffer(uint8_t *buf) {
bool ret = false;
SpiFlashOpResult res;
noInterrupts();
res = spi_flash_erase_sector(tls_spi_start_sector);
if (SPI_FLASH_RESULT_OK == res) {
res = spi_flash_write(tls_spi_start_sector * SPI_FLASH_SEC_SIZE, (uint32_t*) buf, SPI_FLASH_SEC_SIZE);
if (SPI_FLASH_RESULT_OK == res) {
ret = true;
}
}
interrupts();
}
#ifdef DEBUG_DUMP_TLS
// Dump TLS Flash data - don't activate in production to protect your private keys
uint32_t bswap32(uint32_t x) {