mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion] Create method to lock PCB versions on old boards
This commit is contained in:
@@ -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
12
ion/include/ion/board.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef ION_BOARD_H
|
||||
#define ION_BOARD_H
|
||||
|
||||
namespace Ion {
|
||||
namespace Board {
|
||||
|
||||
void lockUnlockedPCBVersion();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -242,6 +242,8 @@ void writePCBVersion(PCBVersion) {}
|
||||
|
||||
void lockPCBVersion() {}
|
||||
|
||||
bool pcbVersionIsLocked() { return true; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
4
ion/src/shared/dummy/board.cpp
Normal file
4
ion/src/shared/dummy/board.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <ion/board.h>
|
||||
|
||||
void Ion::Board::lockUnlockedPCBVersion() {
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
ion_src += $(addprefix ion/src/shared/dummy/, \
|
||||
backlight.cpp \
|
||||
board.cpp \
|
||||
battery.cpp \
|
||||
display.cpp \
|
||||
exam_mode.cpp \
|
||||
|
||||
Reference in New Issue
Block a user