Bootloader pre-release

This commit is contained in:
devdl11
2022-04-25 18:22:19 +02:00
parent add333b920
commit 5ed8aef907
65 changed files with 1328 additions and 810 deletions

View File

@@ -45,6 +45,14 @@ SECTIONS {
_exam_mode_buffer_end = .;
} >INTERNAL_FLASH
.fake_isr_function : {
. = ALIGN(4);
_fake_isr_function_start = .;
KEEP(*(.fake_isr_function))
KEEP(*(.fake_isr_function.*))
_fake_isr_function_end = .;
}
.text : {
. = ALIGN(4);
*(.text)

View File

@@ -211,23 +211,14 @@ void DFUInterface::eraseMemoryIfNeeded() {
willErase();
Bootloader::ProtectionState * config = getDfuConfig();
Bootloader::ProtectionState config = getDfuConfig();
if (config != nullptr) {
// More simple to read
if ((0x08000000 <= m_eraseAddress && m_eraseAddress <= 0x08010000)&& !m_dfuData.isProtectedInternal()) {
Flash::EraseSector(m_erasePage);
} else if ((0x90000000 <= m_eraseAddress && m_eraseAddress <= 0x90800000)&& !m_dfuData.isProtectedExternal()) {
Flash::EraseSector(m_erasePage);
}
} else {
if (m_erasePage == Flash::TotalNumberOfSectors()) {
Flash::MassErase();
} else {
Flash::EraseSector(m_erasePage);
}
// More simple to read
if ((0x08000000 <= m_eraseAddress && m_eraseAddress <= 0x08010000)&& !m_dfuData.isProtectedInternal()) {
Flash::EraseSector(m_erasePage);
} else if ((0x90000000 <= m_eraseAddress && m_eraseAddress <= 0x90800000)&& !m_dfuData.isProtectedExternal()) {
Flash::EraseSector(m_erasePage);
}
/* Put an out of range value in m_erasePage to indicate that no erase is
* waiting. */
m_erasePage = -1;
@@ -242,15 +233,11 @@ void DFUInterface::writeOnMemory() {
memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength);
} else if (Flash::SectorAtAddress(m_writeAddress) >= 0) {
Bootloader::ProtectionState * config = getDfuConfig();
Bootloader::ProtectionState config = getDfuConfig();
if (config != nullptr) {
if (m_writeAddress >= 0x08000000 && m_writeAddress <= 0x08010000 && !m_dfuData.isProtectedInternal()) {
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
} else if (m_writeAddress >= 0x90000000 && m_writeAddress <= 0x90800000 && !m_dfuData.isProtectedExternal()) {
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
}
} else {
if (m_writeAddress >= 0x08000000 && m_writeAddress <= 0x08010000 && !m_dfuData.isProtectedInternal()) {
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
} else if (m_writeAddress >= 0x90000000 && m_writeAddress <= 0x90800000 && !m_dfuData.isProtectedExternal()) {
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
}
@@ -306,7 +293,7 @@ void DFUInterface::leaveDFUAndReset() {
}
void DFUInterface::copyDfuData() {
m_dfuData = Bootloader::ProtectionState(!m_dfuConfig->isProtectedInternal(), !m_dfuConfig->isProtectedExternal());
m_dfuData = Bootloader::ProtectionState(!m_dfuConfig.isProtectedInternal(), !m_dfuConfig.isProtectedExternal());
}
}

View File

@@ -30,7 +30,7 @@ public:
m_writeAddress(0),
m_bInterfaceAlternateSetting(bInterfaceAlternateSetting),
m_isErasingAndWriting(false),
m_dfuConfig(nullptr),
m_dfuConfig(),
m_eraseAddress(0),
m_dfuData()
{
@@ -40,8 +40,8 @@ public:
void wholeDataSentCallback(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength) override;
bool isErasingAndWriting() const { return m_isErasingAndWriting; }
void setDfuConfig(Bootloader::ProtectionState * data) { m_dfuConfig = data; copyDfuData(); }
Bootloader::ProtectionState * getDfuConfig() const { return m_dfuConfig; }
void setDfuConfig(Bootloader::ProtectionState data) { m_dfuConfig = data; copyDfuData(); }
Bootloader::ProtectionState getDfuConfig() const { return m_dfuConfig; }
protected:
void setActiveInterfaceAlternative(uint8_t interfaceAlternativeIndex) override {
@@ -180,7 +180,7 @@ private:
uint32_t m_writeAddress;
uint8_t m_bInterfaceAlternateSetting;
bool m_isErasingAndWriting;
Bootloader::ProtectionState * m_dfuConfig;
Bootloader::ProtectionState m_dfuConfig;
uint32_t m_eraseAddress;
Bootloader::ProtectionState m_dfuData;
};

View File

@@ -40,6 +40,7 @@ void writePCBVersion(PCBVersion version);
void lockPCBVersion();
bool pcbVersionIsLocked();
void jumpToInternalBootloader();
}
}
}

View File

@@ -62,6 +62,14 @@ void SetInternalSectorProtection(int i, bool protect) {
InternalFlash::SetSectorProtection(i, protect);
}
void EnableInternalSessionLock() {
InternalFlash::EnableSessionLock();
}
void EnableInternalFlashInterrupt() {
InternalFlash::EnableFlashInterrupt();
}
void LockSlotA() {
ExternalFlash::LockSlotA();
}

View File

@@ -18,6 +18,8 @@ void WriteMemory(uint8_t * destination, uint8_t * source, size_t length);
void DisableInternalProtection();
void EnableInternalProtection();
void SetInternalSectorProtection(int i, bool protect);
void EnableInternalSessionLock(); // Will cause BUSERR when enabled
void EnableInternalFlashInterrupt();
void LockSlotA();
void LockSlotB();

View File

@@ -344,6 +344,25 @@ void SetSectorProtection(int i, bool protect) {
}
}
void EnableSessionLock() {
if (FLASH.OPTCR()->getLOCK()) {
// writing bullshit to the lock register to lock it until next core reset
FLASH.OPTKEYR()->set(0x00000000);
FLASH.OPTKEYR()->set(0xFFFFFFFF);
}
}
void EnableFlashInterrupt() {
open();
FLASH.CR()->setERRIE(true);
wait();
FLASH.CR()->setEOPIE(true);
wait();
FLASH.CR()->setRDERRIE(true);
wait();
close();
}
}
}
}

View File

@@ -18,6 +18,8 @@ void WriteMemory(uint8_t * destination, uint8_t * source, size_t length);
void EnableProtection();
void DisableProtection();
void SetSectorProtection(int i, bool protect);
void EnableSessionLock();
void EnableFlashInterrupt();
/* The Device is powered by a 2.8V LDO. This allows us to perform writes to the
* Flash 32 bits at once. */

View File

@@ -45,6 +45,9 @@ public:
REGS_FIELD(SNB, uint8_t, 6, 3);
REGS_TYPE_FIELD(PSIZE, 9, 8);
REGS_BOOL_FIELD(STRT, 16);
REGS_BOOL_FIELD(EOPIE, 24);
REGS_BOOL_FIELD(ERRIE, 25);
REGS_BOOL_FIELD(RDERRIE, 26)
REGS_BOOL_FIELD(LOCK, 31);
};

View File

@@ -14,6 +14,12 @@ public:
public:
REGS_BOOL_FIELD(HSION, 0);
REGS_BOOL_FIELD(HSIRDY, 1);
REGS_BOOL_FIELD(HSITRIM1, 3);
REGS_BOOL_FIELD(HSITRIM2, 4);
REGS_BOOL_FIELD(HSITRIM3, 5);
REGS_BOOL_FIELD(HSITRIM4, 6);
REGS_BOOL_FIELD(HSITRIM5, 7);
REGS_BOOL_FIELD(HSICAL, 8);
REGS_BOOL_FIELD(HSEON, 16);
REGS_BOOL_FIELD_R(HSERDY, 17);
REGS_BOOL_FIELD(PLLON, 24);

View File

@@ -5,6 +5,8 @@
#include <regs/config/syscfg.h>
#include "gpio.h"
#define REGS_SYSCFG_CONFIG_F412 1
namespace Ion {
namespace Device {
namespace Regs {