Skip to content

Commit

Permalink
Fix AWS exceptions and make flash location relative to flash size
Browse files Browse the repository at this point in the history
Fix AWS exceptions and make TLS flash location relative to flash size (#6179)
  • Loading branch information
arendst committed Aug 5, 2019
1 parent 93e2d76 commit 427c4ac
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions sonoff/xdrv_02_mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void MqttInit(void)
tlsClient = new BearSSL::WiFiClientSecure_light(1024,1024);

#ifdef USE_MQTT_AWS_IOT
snprintf(AWS_endpoint, sizeof(AWS_endpoint), PSTR("%s%s"), Settings.mqtt_user, Settings.mqtt_host);
snprintf_P(AWS_endpoint, sizeof(AWS_endpoint), PSTR("%s%s"), Settings.mqtt_user, Settings.mqtt_host);

loadTlsDir(); // load key and certificate data from Flash
tlsClient->setClientECCert(AWS_IoT_Client_Certificate,
Expand Down Expand Up @@ -973,9 +973,8 @@ void CmndSensorRetain(void)
\*********************************************************************************************/
#if defined(USE_MQTT_TLS) && defined(USE_MQTT_AWS_IOT)

const static uint8_t* tls_spi_start = (uint8_t*) 0x402FF000;
const static uint32_t tls_spi_start_write = 0x00FF000;
const static uint16_t tls_spi_start_sector = 0x00FF;
const static uint16_t tls_spi_start_sector = SPIFFS_END + 4; // 0xXXFF
const static uint8_t* tls_spi_start = (uint8_t*) ((tls_spi_start_sector * SPI_FLASH_SEC_SIZE) + 0x40200000); // 0x40XFF000
const static size_t tls_spi_len = 0x1000; // 4kb blocs
const static size_t tls_block_offset = 0x0400;
const static size_t tls_block_len = 0x0400; // 1kb
Expand Down Expand Up @@ -1144,11 +1143,11 @@ uint32_t bswap32(uint32_t x) {
((x >> 24) & 0x000000ff );
}
void CmndTlsDump(void) {
uint32_t start = 0x402FF400;
uint32_t end = 0x402FF7FF;
uint32_t start = (uint32_t)tls_spi_start + tls_block_offset;
uint32_t end = start + tls_block_len -1;
for (uint32_t pos = start; pos < end; pos += 0x10) {
uint32_t* values = (uint32_t*)(pos);
Serial.printf(PSTR("%08x: %08x %08x %08x %08x\n"), pos, bswap32(values[0]), bswap32(values[1]), bswap32(values[2]), bswap32(values[3]));
Serial.printf_P(PSTR("%08x: %08x %08x %08x %08x\n"), pos, bswap32(values[0]), bswap32(values[1]), bswap32(values[2]), bswap32(values[3]));
}
}
#endif // DEBUG_DUMP_TLS
Expand Down

2 comments on commit 427c4ac

@s-hadinger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Theo.

Just curious, why did you change printf’s to their _P variant? Is it for consistency? They are not using PMEM values here.

@arendst
Copy link
Owner Author

@arendst arendst commented on 427c4ac Aug 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PSTR(xx) means to access PMEM. Without _P I had execeptions 3 as it fails to access flash (at least with core 2.4.2, my one and only core ;-).

Please sign in to comment.