Skip to content

Commit

Permalink
Merge pull request #981 from pennam/opta-secure
Browse files Browse the repository at this point in the history
Opta secure QSPI simplify code avoid breaking QSPIFBlockDevice
  • Loading branch information
pennam authored Oct 28, 2024
2 parents aacd17c + 4ad1efd commit 3947c86
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions variants/OPTA/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,28 @@ static bool has_otp_info = false;

bool getSecureFlashData() {
static OptaBoardInfo info;
uint8_t temp_buf[sizeof(OptaBoardInfo) + 1];
int ret = 0;
static SecureQSPIFBlockDevice secure_root;
secure_root.init();
// read secure sector 2 ( address 1 << 13 )
ret = secure_root.readSecure(temp_buf, (1 << 13), sizeof(temp_buf));
char temp_buf[sizeof(OptaBoardInfo) + 1];
int ret = QSPI_STATUS_OK;
mbed::QSPI _qspi(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_0);
auto rxlen = sizeof(temp_buf);
ret = _qspi.read(0x48, -1, 1 << 13, temp_buf, &rxlen);
memcpy(&info, &temp_buf[1], sizeof(OptaBoardInfo));
if (info.magic == OTP_QSPI_MAGIC) {
_boardInfo = (uint8_t*)&info;
has_otp_info = true;
}
secure_root.deinit();
return ret == 0;
return ret == QSPI_STATUS_OK;
}

class SecureQSPIReader {
public:
SecureQSPIReader() {
getSecureFlashData();
}
};

SecureQSPIReader __reader __attribute__ ((init_priority (101)));

uint8_t* boardInfo() {
return _boardInfo;
}
Expand Down

0 comments on commit 3947c86

Please sign in to comment.