Skip to content

Commit

Permalink
[bootloader] Fix exam mode with Epsilon 19 and add support for Epsilo…
Browse files Browse the repository at this point in the history
…n 20 (UpsilonNumworks#302)

* [bootloader] Fix exam mode on Epsilon 19

* [bootloader] Fix comment indentation

* [bootloader] Restore comment indentation (even if GitHub tell that it isn't indented properly)

* [bootloader] Turn tabulations into spaces

* [bootloader] Mark Epsilon 19 as "safe to boot"

* [bootloader] Fix Epsilon 20 boot

* [bootloader] Chang version to 1.0.2
  • Loading branch information
Yaya-Cout authored Dec 3, 2022
1 parent 08eb1ae commit 851ec2a
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ epsilon.map
.gradle
.idea/
.vs
.cache/
compile_commands.json
2 changes: 1 addition & 1 deletion bootloader/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "18.2.4";
const char * min = "20.0.0";
int versionSum = Utility::versionSum(version, strlen(version));
int minimalVersionTrigger = Utility::versionSum(min, strlen(min));
if (versionSum >= minimalVersionTrigger) {
Expand Down
4 changes: 2 additions & 2 deletions bootloader/interface/static/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Messages {
constexpr static const char * epsilonWarningTitle = "Epsilon Slot";

constexpr static const char * epsilonWarningMessage1 = "!! WARNING !! ";
constexpr static const char * epsilonWarningMessage2 = "This version of epsilon";
constexpr static const char * epsilonWarningMessage2 = "This version of Epsilon";
constexpr static const char * epsilonWarningMessage3 = "can lock the calculator.";
constexpr static const char * epsilonWarningMessage4 = "Proceed the boot ?";
constexpr static const char * epsilonWarningMessage5 = "EXE - Yes";
Expand All @@ -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.1 - FREED0M.19";
constexpr static const char * bootloaderVersion = "Version 1.0.2 - FREED0M.20";

//USB NAMES
constexpr static const char * usbUpsilonBootloader = "Upsilon Bootloader";
Expand Down
11 changes: 5 additions & 6 deletions bootloader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@ __attribute__ ((noreturn)) void ion_main(int argc, const char * const argv[]) {
bool isSlotA = Bootloader::Slot::isFullyValid(Bootloader::Slot::A());

if (isSlotA) {
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(!Bootloader::Slot::A().userlandHeader()->isOmega());
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(Bootloader::Slot::A().userlandHeader()->version());
if (SlotAExamMode != Bootloader::ExamMode::ExamMode::Off && SlotAExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
// We boot the slot in exam_mode
Bootloader::Slot::A().boot();
}
}
}

bool isSlotB = Bootloader::Slot::isFullyValid(Bootloader::Slot::B());

if (isSlotB) {
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(!Bootloader::Slot::B().userlandHeader()->isOmega());
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(Bootloader::Slot::B().userlandHeader()->version());
if (SlotBExamMode != Bootloader::ExamMode::ExamMode::Off && SlotBExamMode != Bootloader::ExamMode::ExamMode::Unknown && isSlotB) {
// We boot the slot in exam_mode
Bootloader::Slot::B().boot();
}

}

// I have no idea if this will work, but if Pariss did a good job, it should
// I have no idea if this will work, but if Parisse did a good job, it should

bool isKhiSlot = Bootloader::Slot::isFullyValid(Bootloader::Slot::Khi());

if (isKhiSlot) {
Bootloader::ExamMode::ExamMode KhiExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotKhiExamMode();
Bootloader::ExamMode::ExamMode KhiExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotKhiExamMode(Bootloader::Slot::Khi().userlandHeader()->version());
if (KhiExamMode != Bootloader::ExamMode::ExamMode::Off && KhiExamMode != Bootloader::ExamMode::ExamMode::Unknown && isKhiSlot) {
// We boot the slot in exam_mode
Bootloader::Slot::Khi().boot();
Expand Down
27 changes: 26 additions & 1 deletion bootloader/slots/slot.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <bootloader/slots/slot.h>
#include <ion/src/device/shared/drivers/board.h>
#include <ion/src/device/shared/drivers/flash.h>
#include <ion/src/device/shared/drivers/external_flash.h>
#include <bootloader/boot.h>

extern "C" void jump_to_firmware(const uint32_t* stackPtr, const void(*startPtr)(void));
Expand All @@ -24,7 +25,13 @@ const KernelHeader* Slot::kernelHeader() const {
}

const UserlandHeader* Slot::userlandHeader() const {
return m_userlandHeader;
if (m_userlandHeader->isValid()) {
return m_userlandHeader;
} else if (m_userland2Header->isValid()) {
return m_userland2Header;
} else {
return m_userlandHeader;
}
}

[[ noreturn ]] void Slot::boot() const {
Expand All @@ -37,6 +44,24 @@ const UserlandHeader* Slot::userlandHeader() const {
Ion::Device::Flash::LockSlotA();
}

// Erase the bootloader integrated in slots in Epsilon 20
if (m_userland2Header->isValid()) {
if (m_address == 0x90000000) {
// Check if bootloader is present in slot A
if (*(uint32_t*)0x90010000 != 0xFFFFFFFF) {
// Erase bootloader in slot A
Ion::Device::ExternalFlash::EraseSector(9);
}
}
else if (m_address == 0x90400000) {
// Check if bootloader is present in slot B
if (*(uint32_t*)0x90410000 != 0xFFFFFFFF) {
// Erase bootloader in slot B
Ion::Device::ExternalFlash::EraseSector(73);
}
}
}

// Configure the MPU for the booted firmware
Ion::Device::Board::bootloaderMPU();

Expand Down
4 changes: 3 additions & 1 deletion bootloader/slots/slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Slot {
Slot(uint32_t address) :
m_kernelHeader(reinterpret_cast<KernelHeader*>(address)),
m_userlandHeader(reinterpret_cast<UserlandHeader*>(address + 64 * 1024)),
m_address(address) { }
m_userland2Header(reinterpret_cast<UserlandHeader*>(address + 128 * 1024)),
m_address(address) {}

const KernelHeader* kernelHeader() const;
const UserlandHeader* userlandHeader() const;
Expand All @@ -32,6 +33,7 @@ class Slot {
private:
const KernelHeader* m_kernelHeader;
const UserlandHeader* m_userlandHeader;
const UserlandHeader* m_userland2Header;
const uint32_t m_address;

};
Expand Down
Loading

0 comments on commit 851ec2a

Please sign in to comment.