Skip to content

Commit

Permalink
[bootloader] Fix exam mode with Epsilon 22
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaya-Cout committed Jan 17, 2024
1 parent f7a298a commit cb6fd76
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 28 deletions.
6 changes: 3 additions & 3 deletions bootloader/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ void Boot::patchKernel(const Slot & s) {
// data[origin_isr + sizeof(uint32_t) * 5 + 1] = ptr[1];
// data[origin_isr + sizeof(uint32_t) * 5 + 2] = ptr[2];
// data[origin_isr + sizeof(uint32_t) * 5 + 3] = ptr[3];

data[origin_isr + sizeof(uint32_t) * 7] = ptr[0]; // UsageFault
data[origin_isr + sizeof(uint32_t) * 7 + 1] = ptr[1];
data[origin_isr + sizeof(uint32_t) * 7 + 2] = ptr[2];
data[origin_isr + sizeof(uint32_t) * 7 + 3] = ptr[3];

// data[origin_isr + sizeof(uint32_t) * 4] = ptr[0];//hardfault
// data[origin_isr + sizeof(uint32_t) * 4 + 1] = ptr[1];
// data[origin_isr + sizeof(uint32_t) * 4 + 1] = ptr[1];
// data[origin_isr + sizeof(uint32_t) * 4 + 2] = ptr[2];
// data[origin_isr + sizeof(uint32_t) * 4 + 3] = ptr[3];

Expand All @@ -107,7 +107,7 @@ void Boot::bootSlot(Bootloader::Slot s) {
if (!s.userlandHeader()->isOmega() && !s.userlandHeader()->isUpsilon()) {
// We are trying to boot epsilon, so we check the version and show an advertisement if needed
const char * version = s.userlandHeader()->version();
const char * min = "21.3.1";
const char * min = "22.2.1";
int versionSum = Utility::versionSum(version, strlen(version));
int minimalVersionTrigger = Utility::versionSum(min, strlen(min));
if (versionSum >= minimalVersionTrigger) {
Expand Down
2 changes: 1 addition & 1 deletion bootloader/interface/static/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Messages {
constexpr static const char * aboutMessage4 = "and select the OS";
constexpr static const char * aboutMessage5 = "to boot.";

constexpr static const char * bootloaderVersion = "Version 1.0.8 - FREED0M.21.3";
constexpr static const char * bootloaderVersion = "Version 1.0.9 - FREED0M.22";

//USB NAMES
constexpr static const char * usbUpsilonBootloader = "NumWorks Calculator";
Expand Down
67 changes: 51 additions & 16 deletions bootloader/slots/slot_exam_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,33 @@ uint8_t SlotsExamMode::FetchSlotExamMode(const char * version, const char * Slot
start = getSlotAStartExamAddress(0);
end = getSlotAEndExamAddress(0);
}
// Else get new addresses
else {
// Else versions before 22
else if (version[0] == '2' && version[1] < '2') {
start = getSlotAStartExamAddress(1);
end = getSlotAEndExamAddress(1);
}
// Else Epsilon 22 +
else {
start = getSlotAStartExamAddress(2);
end = getSlotAEndExamAddress(2);
}
}
else if (Slot == "B") {
// If version under 16 get old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotBStartExamAddress(0);
end = getSlotBEndExamAddress(0);
}
// Else get new
else {
// Else versions before 22
else if (version[0] == '2' && version[1] < '2') {
start = getSlotBStartExamAddress(1);
end = getSlotBEndExamAddress(1);
}
// Else Epsilon 22 +
else {
start = getSlotBStartExamAddress(2);
end = getSlotBEndExamAddress(2);
}
} else if (Slot == "Khi") {
// We directly get the address of the Khi exam mode without checking the
// version, because on Khi, version is KhiCAS version, not the OS version
Expand Down Expand Up @@ -171,38 +181,63 @@ uint8_t SlotsExamMode::examFetch19(uint32_t start, uint32_t end) {

uint32_t SlotsExamMode::getSlotAStartExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotAExamModeBufferStartOldVersions;
return SlotAExamModeBufferStartBefore16;
}
else {
return SlotAExamModeBufferStartNewVersions;
if (ExamVersion == 1) {
return SlotAExamModeBufferStartEpsilon16;
}
if (ExamVersion == 2) {
return SlotAExamModeBufferStartEpsilon22;
}
assert(false);
// Should not happen
return SlotAExamModeBufferStartEpsilon22;
}

uint32_t SlotsExamMode::getSlotAEndExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotAExamModeBufferEndOldVersions;
return SlotAExamModeBufferEndBefore16;
}
if (ExamVersion == 1) {
return SlotAExamModeBufferEndEpsilon16;
}
else {
return SlotAExamModeBufferEndNewVersions;;
if (ExamVersion == 2) {
return SlotAExamModeBufferEndEpsilon22;
}
assert(false);
// Should not happen
return SlotAExamModeBufferEndEpsilon22;

}

uint32_t SlotsExamMode::getSlotBStartExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotBExamModeBufferStartOldVersions;
return SlotBExamModeBufferStartBeforeEpsilon16;
}
else {
return SlotBExamModeBufferStartNewVersions;
if (ExamVersion == 1) {
return SlotBExamModeBufferStartEpsilon16;
}
if (ExamVersion == 2) {
return SlotBExamModeBufferStartEpsilon22;
}
assert(false);
// Should not happen
return SlotBExamModeBufferStartEpsilon22;
}

uint32_t SlotsExamMode::getSlotBEndExamAddress(int ExamVersion) {
if (ExamVersion == 0) {
return SlotBExamModeBufferEndOldVersions;
return SlotBExamModeBufferEndBeforeEpsilon16;
}
if (ExamVersion == 1) {
return SlotBExamModeBufferEndEpsilon16;
}
else {
return SlotBExamModeBufferEndNewVersions;
if (ExamVersion == 2) {
return SlotBExamModeBufferEndEpsilon22;
}
assert(false);
// Should not happen
return SlotBExamModeBufferEndEpsilon22;
}

uint32_t SlotsExamMode::getSlotKhiStartExamAddress() {
Expand Down
22 changes: 14 additions & 8 deletions bootloader/slots/slot_exam_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ extern "C" {
namespace Bootloader {
namespace ExamMode {

static const uint32_t SlotAExamModeBufferStartOldVersions = 0x90001000;
static const uint32_t SlotAExamModeBufferEndOldVersions = 0x90003000;
static const uint32_t SlotAExamModeBufferStartBefore16 = 0x90001000;
static const uint32_t SlotAExamModeBufferEndBefore16 = 0x90003000;

static const uint32_t SlotAExamModeBufferStartNewVersions = 0x903f0000;
static const uint32_t SlotAExamModeBufferEndNewVersions = 0x90400000;
static const uint32_t SlotAExamModeBufferStartEpsilon16 = 0x903f0000;
static const uint32_t SlotAExamModeBufferEndEpsilon16 = 0x90400000;

static const uint32_t SlotBExamModeBufferStartOldVersions = 0x90401000;
static const uint32_t SlotBExamModeBufferEndOldVersions = 0x90403000;
static const uint32_t SlotAExamModeBufferStartEpsilon22 = 0x903f0400;
static const uint32_t SlotAExamModeBufferEndEpsilon22 = 0x90400000;

static const uint32_t SlotBExamModeBufferStartNewVersions = 0x907f0000;
static const uint32_t SlotBExamModeBufferEndNewVersions = 0x90800000;
static const uint32_t SlotBExamModeBufferStartBeforeEpsilon16 = 0x90401000;
static const uint32_t SlotBExamModeBufferEndBeforeEpsilon16 = 0x90403000;

static const uint32_t SlotBExamModeBufferStartEpsilon16 = 0x907f0000;
static const uint32_t SlotBExamModeBufferEndEpsilon16 = 0x90800000;

static const uint32_t SlotBExamModeBufferStartEpsilon22 = 0x907f0400;
static const uint32_t SlotBExamModeBufferEndEpsilon22 = 0x90800000;

static const uint32_t SlotKhiExamModeBufferStart = 0x90181000;
static const uint32_t SlotKhiExamModeBufferEnd = 0x90183000;
Expand Down

0 comments on commit cb6fd76

Please sign in to comment.