[ion] Create method to lock PCB versions on old boards

This commit is contained in:
Gabriel Ozouf
2021-03-31 13:19:46 +02:00
committed by Gabriel
parent 08f351fe31
commit bd0c7de2bf
9 changed files with 60 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
#include <ion/backlight.h>
#include <ion/battery.h>
#include <ion/board.h>
#include <ion/clipboard.h>
#include <ion/console.h>
#include <ion/display.h>

12
ion/include/ion/board.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef ION_BOARD_H
#define ION_BOARD_H
namespace Ion {
namespace Board {
void lockUnlockedPCBVersion();
}
}
#endif

View File

@@ -242,6 +242,8 @@ void writePCBVersion(PCBVersion) {}
void lockPCBVersion() {}
bool pcbVersionIsLocked() { return true; }
}
}
}

View File

@@ -385,7 +385,8 @@ PCBVersion pcbVersion() {
* way, flashing the PCB version can be done last. */
return PCB_LATEST;
#else
return readPCBVersionInMemory();
PCBVersion version = readPCBVersionInMemory();
return (version == alternateBlankVersion ? 0 : version);
#endif
}
@@ -405,6 +406,10 @@ void lockPCBVersion() {
InternalFlash::WriteMemory(destination, &zero, sizeof(zero));
}
bool pcbVersionIsLocked() {
return *reinterpret_cast<const uint8_t *>(InternalFlash::Config::OTPLocksAddress + pcbVersionOTPIndex) == 0;
}
}
}
}

View File

@@ -93,3 +93,26 @@ void setClockFrequency(Frequency f) {
}
}
}
namespace Ion {
namespace Board {
using namespace Device::Board;
void lockUnlockedPCBVersion() {
if (pcbVersionIsLocked()) {
return;
}
/* PCB version is unlocked : the device is a N0110 that has been
* produced prior to the pcb revision. */
PCBVersion version = pcbVersion();
if (version != 0) {
/* Some garbage has been written in OTP0. We overwrite it fully, which is
* interepreted as blank. */
writePCBVersion(alternateBlankVersion);
}
lockPCBVersion();
}
}
}

View File

@@ -26,11 +26,17 @@ void setStandardFrequency(Frequency f);
void setClockFrequency(Frequency f);
typedef uint32_t PCBVersion;
/* On N0110 released before the PCB revision, OTP0 is supposed to be blank and
* unlocked. However, such a device with something written in OTP0 will be
* unable to configure Vbus properly. In this case, and if OTP0 is still
* unlocked, we fully write OTP0 and treat it the same as fully blank. */
constexpr PCBVersion alternateBlankVersion = -1;
PCBVersion pcbVersion();
PCBVersion readPCBVersionInMemory();
void writePCBVersion(PCBVersion version);
void lockPCBVersion();
bool pcbVersionIsLocked();
}
}

View File

@@ -0,0 +1,4 @@
#include <ion/board.h>
void Ion::Board::lockUnlockedPCBVersion() {
}

View File

@@ -1,5 +1,6 @@
ion_src += $(addprefix ion/src/shared/dummy/, \
backlight.cpp \
board.cpp \
battery.cpp \
display.cpp \
exam_mode.cpp \