[bootloader] Small fixes

This commit is contained in:
Laury
2022-04-27 21:59:33 +02:00
parent 7f8e6a6b87
commit 7d61e236df
19 changed files with 112 additions and 129 deletions

View File

@@ -16,7 +16,6 @@
#include <ion/storage.h>
#include <ion/timing.h>
#include <ion/usb.h>
#include <ion/flash.h>
#include <ion/unicode/utf8_decoder.h>
#include <ion/unicode/utf8_helper.h>
#include <stdint.h>

View File

@@ -1,22 +0,0 @@
#ifndef ION_DEVICE_SHARED_FLASH_H
#define ION_DEVICE_SHARED_FLASH_H
#include <stddef.h>
#include <stdint.h>
namespace Ion {
namespace Device {
namespace Flash {
int TotalNumberOfSectors();
int SectorAtAddress(uint32_t address);
void MassErase();
void EraseSector(int i);
void WriteMemory(uint8_t * destination, uint8_t * source, size_t length);
}
}
}
#endif

View File

@@ -62,7 +62,7 @@ void SetInternalSectorProtection(int i, bool protect) {
InternalFlash::SetSectorProtection(i, protect);
}
void EnableInternalSessionLock() {
void LockInternalFlashForSession() {
InternalFlash::EnableSessionLock();
}

View File

@@ -1,5 +1,5 @@
#ifndef ION_DEVICE_SHARED_FLASH_H
#define ION_DEVICE_SHARED_FLASH_H
#ifndef ION_DEVICE_SHARED_FLASH_DRIVER_H
#define ION_DEVICE_SHARED_FLASH_DRIVER_H
#include <stddef.h>
#include <stdint.h>
@@ -18,7 +18,7 @@ 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 LockInternalFlashForSession(); // Will cause BUSERR when enabled
void EnableInternalFlashInterrupt();
void ClearInternalFlashErrors();
void LockSlotA();

View File

@@ -22,6 +22,7 @@ static inline void wait() {
static void open() {
// Unlock the Flash configuration register if needed
if (FLASH.CR()->getLOCK()) {
// https://www.numworks.com/resources/engineering/hardware/electrical/parts/stm32f730-arm-mcu-reference-manual-1b6e1356.pdf#page=82
FLASH.KEYR()->set(0x45670123);
FLASH.KEYR()->set(0xCDEF89AB);
}
@@ -33,6 +34,7 @@ static void open() {
static void open_protection() {
if (FLASH.OPTCR()->getLOCK()) {
// https://www.numworks.com/resources/engineering/hardware/electrical/parts/stm32f730-arm-mcu-reference-manual-1b6e1356.pdf#page=82
FLASH.OPTKEYR()->set(0x08192A3B);
FLASH.OPTKEYR()->set(0x4C5D6E7F);
}
@@ -347,8 +349,12 @@ 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
// https://www.numworks.com/resources/engineering/hardware/electrical/parts/stm32f730-arm-mcu-reference-manual-1b6e1356.pdf#page=82
// > "In the event of an unsuccessful unlock operation, this bit remains set until the next reset."
FLASH.OPTKEYR()->set(0x00000000);
FLASH.OPTKEYR()->set(0xFFFFFFFF);
// Now, a bus fault error is triggered
}
}