Skip to content

Commit

Permalink
[ion/device] Adapt behaviour in factory
Browse files Browse the repository at this point in the history
When flashing fo the first time, we need Epsilon to know the PCB version
before the OTP are flashed. We also need the to prevent Epsilon from
writing the OTP outside of the factory.
  • Loading branch information
GabrielNumworks committed Apr 16, 2021
1 parent 00b7443 commit cbb435d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ion/src/device/bench/command/pcb_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ void PCBVersion(const char * input) {
return;
}

/* When running the bench for a diagnostic, we must absolutely not write the
* OTP, as N0110 built prior to the PCB revision would still have their OTP
* blank and unlocked. */
#if IN_FACTORY
Board::writePCBVersion(PCB_LATEST);
if (Board::readPCBVersion() != PCB_LATEST) {
/* Read directly from memory, as when IN_FACTORY is true, the method
* readPCBVersion always returns PCB_LATEST. */
if (Board::readPCBVersionInMemory() != PCB_LATEST) {
reply(sKO);
return;
}
#endif
reply(sOK);
}

Expand Down
4 changes: 4 additions & 0 deletions ion/src/device/n0100/drivers/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ PCBVersion readPCBVersion() {
return PCB_LATEST;
}

PCBVersion readPCBVersionInMemory() {
return PCB_LATEST;
}

void writePCBVersion(PCBVersion) {}

}
Expand Down
13 changes: 11 additions & 2 deletions ion/src/device/n0110/drivers/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,17 @@ constexpr int pcbVersionOTPIndex = 0;
* version number. This way, devices with blank OTP are considered version 0. */

PCBVersion readPCBVersion() {
/* FIXME: When flashing for the first time after assembling the device, this
* should return PCB_LATEST. */
#if IN_FACTORY
/* When flashing for the first time, we want all systems that depend on the
* PCB version to function correctly before flashing the PCB version. This
* way, flashing the PCB version can be done last. */
return PCB_LATEST;
#else
return readPCBVersionInMemory();
#endif
}

PCBVersion readPCBVersionInMemory() {
return ~*reinterpret_cast<const PCBVersion *>(InternalFlash::Config::OTPAddresses[pcbVersionOTPIndex]);
}

Expand Down
1 change: 1 addition & 0 deletions ion/src/device/shared/drivers/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void setClockFrequency(Frequency f);
typedef uint32_t PCBVersion;

PCBVersion readPCBVersion();
PCBVersion readPCBVersionInMemory();
void writePCBVersion(PCBVersion version);

}
Expand Down

0 comments on commit cbb435d

Please sign in to comment.