@@ -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
0 commit comments