Skip to content

Commit a96f28b

Browse files
committed
[omega] 2.0.4
2 parents 7563e73 + 721df99 commit a96f28b

File tree

9 files changed

+276
-159
lines changed

9 files changed

+276
-159
lines changed

bootloader/boot.cpp

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,29 @@ __attribute__((noreturn)) void Boot::boot() {
3939
} else if (!Slot::A().kernelHeader()->isValid()) {
4040
// If slot A is invalid and B valid, boot B
4141
setMode(BootMode::SlotB);
42-
Slot::B().boot();
42+
Slot::B().boot("B");
4343
} else if (!Slot::B().kernelHeader()->isValid()) {
4444
// If slot B is invalid and A valid, boot A
4545
setMode(BootMode::SlotA);
46-
Slot::A().boot();
46+
Slot::A().boot("A");
4747
} else {
48-
49-
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(!Bootloader::Slot::A().userlandHeader()->isOmega());
50-
if (SlotAExamMode != Bootloader::ExamMode::ExamMode::Off && SlotAExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
51-
// We boot the slot in exam_mode
52-
Bootloader::Slot::A().boot();
53-
}
48+
const char* version = Bootloader::Slot::A().kernelHeader()->version();
49+
bool isExam = Bootloader::ExamMode::SlotsExamMode::FetchSlotExamMode(version, "A") > 0;
50+
if (isExam) {
51+
Bootloader::Slot::A().boot("A");
52+
}
5453

55-
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(!Bootloader::Slot::B().userlandHeader()->isOmega());
56-
if (SlotBExamMode != Bootloader::ExamMode::ExamMode::Off && SlotBExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
57-
// We boot the slot in exam_mode
58-
Bootloader::Slot::B().boot();
59-
}
54+
version = Bootloader::Slot::B().kernelHeader()->version();
55+
isExam = Bootloader::ExamMode::SlotsExamMode::FetchSlotExamMode(version, "B") > 0;
56+
if (isExam) {
57+
Bootloader::Slot::B().boot("B");
58+
}
6059

6160
// Both valid, boot the selected one
6261
if (mode() == BootMode::SlotA) {
63-
Slot::A().boot();
62+
Slot::A().boot("A");
6463
} else if (mode() == BootMode::SlotB) {
65-
Slot::B().boot();
64+
Slot::B().boot("B");
6665
}
6766
}
6867

@@ -74,21 +73,59 @@ __attribute__ ((noreturn)) void Boot::bootloader() {
7473
for(;;) {
7574
// Draw the interfaces and infos
7675
Bootloader::Interface::draw();
77-
78-
// Enable USB
79-
Ion::USB::enable();
80-
81-
// Wait for the device to be enumerated
82-
do {
83-
// If we pressed back while waiting, reset.
84-
uint64_t scan = Ion::Keyboard::scan();
85-
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Back)) {
86-
Ion::Device::Reset::core();
87-
}
88-
} while (!Ion::USB::isEnumerated());
89-
90-
// Launch the DFU stack, allowing to press Back to quit and reset
91-
Ion::USB::DFU(true);
76+
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
77+
78+
bool abortUSB = false;
79+
while (1) {
80+
uint64_t scan = Ion::Keyboard::scan();
81+
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::OnOff)) {
82+
Ion::Device::Reset::core();
83+
}
84+
//allow to set bootmode with 1 and 2
85+
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::One)) {
86+
Bootloader::Boot::setMode(Bootloader::BootMode::SlotA);
87+
Bootloader::Interface::draw();
88+
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
89+
Ion::Timing::msleep(100);
90+
}
91+
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Two)) {
92+
Bootloader::Boot::setMode(Bootloader::BootMode::SlotB);
93+
Bootloader::Interface::draw();
94+
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
95+
Ion::Timing::msleep(100);
96+
}
97+
98+
if (Ion::USB::isPlugged() && !abortUSB) {
99+
// Enable USB
100+
Ion::USB::enable();
101+
102+
Bootloader::Interface::drawMessageBox("USB Enabled", "Press Back to disable USB");
103+
// Launch the DFU stack, allowing to press Back to quit and reset
104+
Ion::USB::DFU(true);
105+
//wait for usb to be unplugged or back to be pressed
106+
while (Ion::USB::isPlugged() && scan != Ion::Keyboard::State(Ion::Keyboard::Key::Back)) {
107+
scan = Ion::Keyboard::scan();
108+
Ion::Timing::msleep(100);
109+
}
110+
//cehck if usb is plugged
111+
if (Ion::USB::isPlugged()) {
112+
abortUSB = true;
113+
}
114+
// Disable USB
115+
Ion::USB::disable();
116+
Bootloader::Interface::draw();
117+
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
118+
119+
}
120+
121+
//Prevent USB from launching after Back press
122+
if (!Ion::USB::isPlugged() && abortUSB) {
123+
abortUSB = false;
124+
}
125+
126+
Ion::Timing::msleep(100);
127+
128+
}
92129
}
93130
}
94131

bootloader/interface.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
namespace Bootloader {
1313

14+
void Interface::drawMessageBox(const char* line1, const char* line2) {
15+
KDContext* ctx = KDIonContext::sharedContext();
16+
//draw a red box at bottom of screen
17+
ctx->fillRect(KDRect(0, 210, 320, 32), KDColorRed);
18+
//get lenght of each line
19+
int line1Length = strlen(line1);
20+
int line2Length = strlen(line2);
21+
//draw the message
22+
ctx->drawString(line1, KDPoint(160-((line1Length*8)/2), 210), KDFont::SmallFont, KDColorWhite, KDColorRed);
23+
ctx->drawString(line2, KDPoint(160 - ((line2Length*8)/ 2), 228), KDFont::SmallFont, KDColorWhite, KDColorRed);
24+
25+
}
26+
1427
void Interface::drawImage(KDContext* ctx, const Image* image, int offset) {
1528
const uint8_t* data;
1629
size_t size;
@@ -74,23 +87,32 @@ void Interface::draw() {
7487
}
7588
ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
7689
} else {
77-
ctx->drawString("Invalid", KDPoint(56, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
90+
if (slot.userland2Header()->isValid()) {
91+
ctx->drawString("Epsilon", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
92+
ctx->drawString(slot.userland2Header()->version(), KDPoint(112, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
93+
ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
94+
}
95+
else {
96+
ctx->drawString("Invalid", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
97+
}
7898
}
7999

80100
}
81101

82102
if (Bootloader::Slot::A().kernelHeader()->isValid()) {
83-
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(!Bootloader::Slot::A().userlandHeader()->isOmega());
84-
if (SlotAExamMode != Bootloader::ExamMode::ExamMode::Off && SlotAExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
85-
ctx->drawString("E", KDPoint(238, 0), KDFont::SmallFont, KDColorWhite, KDColorBlack);
86-
}
103+
const char* version = Bootloader::Slot::A().kernelHeader()->version();
104+
bool isExam = Bootloader::ExamMode::SlotsExamMode::FetchSlotExamMode(version, "A") > 0;
105+
if (isExam) {
106+
ctx->drawString("E", KDPoint(238, 0), KDFont::SmallFont, KDColorWhite, KDColorBlack);
107+
}
87108
}
88109

89110
if (Bootloader::Slot::B().kernelHeader()->isValid()) {
90-
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(!Bootloader::Slot::B().userlandHeader()->isOmega());
91-
if (SlotBExamMode != Bootloader::ExamMode::ExamMode::Off && SlotBExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
92-
ctx->drawString("E", KDPoint(238, 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
93-
}
111+
const char* version = Bootloader::Slot::B().kernelHeader()->version();
112+
bool isExam = Bootloader::ExamMode::SlotsExamMode::FetchSlotExamMode(version, "B") > 0;
113+
if (isExam) {
114+
ctx->drawString("E", KDPoint(238, 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
115+
}
94116
}
95117

96118
}

bootloader/interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Interface {
1414

1515
public:
1616
static void draw();
17+
static void drawMessageBox(const char* line1, const char* line2);
1718

1819
};
1920

bootloader/slot.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <bootloader/slot.h>
22
#include <ion/src/device/shared/drivers/board.h>
3+
#include <ion/src/device/shared/drivers/external_flash.h>
4+
#include <bootloader/interface.h>
35

46
extern "C" void jump_to_firmware(const uint32_t* stackPtr, const void(*startPtr)(void));
57

@@ -21,7 +23,29 @@ const UserlandHeader* Slot::userlandHeader() const {
2123
return m_userlandHeader;
2224
}
2325

24-
[[ noreturn ]] void Slot::boot() const {
26+
const UserlandHeader* Slot::userland2Header() const {
27+
return m_userland2Header;
28+
}
29+
30+
[[ noreturn ]] void Slot::boot(const char* Slot) const {
31+
//protection mechanism against bootloader update introduced in E20
32+
//check if the slot use Userland2Header
33+
if (m_userland2Header->isValid()) {
34+
if (Slot == "A") {
35+
//check if 0x90010000 = 0xFFFFFFFF
36+
if (*(uint32_t*)0x90010000 != 0xFFFFFFFF) {
37+
Ion::Device::ExternalFlash::EraseSector(9);
38+
}
39+
}
40+
else if (Slot == "B") {
41+
//check if 0x90410000 = 0xFFFFFFFF
42+
if (*(uint32_t*)0x90410000 != 0xFFFFFFFF) {
43+
Ion::Device::ExternalFlash::EraseSector(73);
44+
}
45+
46+
}
47+
48+
}
2549
// Configure the MPU for the booted firmware
2650
Ion::Device::Board::bootloaderMPU();
2751

bootloader/slot.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ class Slot {
1414
public:
1515
Slot(uint32_t address) :
1616
m_kernelHeader(reinterpret_cast<KernelHeader*>(address)),
17-
m_userlandHeader(reinterpret_cast<UserlandHeader*>(address + 64 * 1024)) { }
17+
m_userlandHeader(reinterpret_cast<UserlandHeader*>(address + 64 * 1024)),
18+
m_userland2Header(reinterpret_cast<UserlandHeader*>(address + 128 * 1024)) { }
1819

1920
const KernelHeader* kernelHeader() const;
2021
const UserlandHeader* userlandHeader() const;
21-
[[ noreturn ]] void boot() const;
22+
const UserlandHeader* userland2Header() const;
23+
[[ noreturn ]] void boot(const char* Slot) const;
2224

2325
static const Slot A();
2426
static const Slot B();
2527

2628
private:
2729
const KernelHeader* m_kernelHeader;
2830
const UserlandHeader* m_userlandHeader;
31+
const UserlandHeader* m_userland2Header;
2932

3033
};
3134

0 commit comments

Comments
 (0)