Skip to content

Commit

Permalink
[omega] 2.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
M4xi1m3 committed Apr 18, 2023
2 parents c9c563b + 58780ef commit 9629acf
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 105 deletions.
4 changes: 4 additions & 0 deletions apps/apps_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
* We do it before switching to USB application to redraw the battery
* pictogram. */
updateBatteryState();
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
//if in exam mode, do not switch to usb connected app
return true;
}
if (switchTo(usbConnectedAppSnapshot())) {
Ion::USB::DFU();
// Update LED when exiting DFU mode
Expand Down
32 changes: 15 additions & 17 deletions bootloader/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ __attribute__((noreturn)) void Boot::boot() {

__attribute__ ((noreturn)) void Boot::bootloader() {
for(;;) {
int modeFlash = 3;
// Draw the interfaces and infos
Bootloader::Interface::draw();
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");

Bootloader::Interface::draw(modeFlash);
bool abortUSB = false;
while (1) {
uint64_t scan = Ion::Keyboard::scan();
Expand All @@ -84,38 +83,37 @@ __attribute__ ((noreturn)) void Boot::bootloader() {
//allow to set bootmode with 1 and 2
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::One)) {
Bootloader::Boot::setMode(Bootloader::BootMode::SlotA);
Bootloader::Interface::draw();
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
Bootloader::Interface::draw(modeFlash);
Ion::Timing::msleep(100);
}
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Two)) {
Bootloader::Boot::setMode(Bootloader::BootMode::SlotB);
Bootloader::Interface::draw();
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
Bootloader::Interface::draw(modeFlash);
Ion::Timing::msleep(100);
}
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Plus)) {
modeFlash = modeFlash + 1;
if (modeFlash > 3) {
modeFlash = 1;
}
Ion::Timing::msleep(100);
Bootloader::Interface::draw(modeFlash);
}

if (Ion::USB::isPlugged() && !abortUSB) {
// Enable USB
Ion::USB::enable();

Bootloader::Interface::drawMessageBox("USB Enabled", "Press Back to disable USB");
// Launch the DFU stack, allowing to press Back to quit and reset
Ion::USB::DFU(true);
//wait for usb to be unplugged or back to be pressed
while (Ion::USB::isPlugged() && scan != Ion::Keyboard::State(Ion::Keyboard::Key::Back)) {
scan = Ion::Keyboard::scan();
Ion::Timing::msleep(100);
}
//cehck if usb is plugged
Ion::USB::DFU(true, modeFlash);
//check if usb is plugged
if (Ion::USB::isPlugged()) {
abortUSB = true;
}
// Disable USB
Ion::USB::disable();
Bootloader::Interface::draw();
Bootloader::Interface::drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");

Bootloader::Interface::draw(modeFlash);
}

//Prevent USB from launching after Back press
Expand Down
41 changes: 28 additions & 13 deletions bootloader/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ void Interface::drawImage(KDContext* ctx, const Image* image, int offset) {
ctx->fillRectWithPixels(bounds, pixelBuffer, nullptr);
}

void Interface::draw() {
void Interface::draw(int currentUSB) {
KDContext * ctx = KDIonContext::sharedContext();
ctx->fillRect(KDRect(0,0,320,240), KDColorBlack);
drawImage(ctx, ImageStore::Computer, 70);
drawImage(ctx, ImageStore::Cable, 172);

drawImage(ctx, ImageStore::Cable, 132);
drawMessageBox("Press (1)/(2) to select slot", "Press Power to reset");
ctx->drawString("Slot A:", KDPoint(0, 0), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString("Slot B:", KDPoint(0, 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString("Current:", KDPoint(0, 26), KDFont::SmallFont, KDColorWhite, KDColorBlack);
Expand Down Expand Up @@ -86,19 +86,34 @@ void Interface::draw() {
ctx->drawString(slot.userlandHeader()->version(), KDPoint(112, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
}
ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
} else {
if (slot.userland2Header()->isValid()) {
ctx->drawString("Epsilon", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString(slot.userland2Header()->version(), KDPoint(112, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
}
else {
ctx->drawString("Invalid", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
}
}
else {
if (slot.userland2Header()->isValid()) {
ctx->drawString("Epsilon", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString(slot.userland2Header()->version(), KDPoint(112, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
}
else {
ctx->drawString("Invalid", KDPoint(56, i * 13), KDFont::SmallFont, KDColorWhite, KDColorBlack);
}
}

}

char* USBFlashVerbose = "";
if (currentUSB == 1) {
USBFlashVerbose = "Slot A";
}
else if (currentUSB == 2) {
USBFlashVerbose = "Slot B";
}
else if (currentUSB == 3) {
USBFlashVerbose = "Slot A & B";
}
//add USBFlashVerbose to USBFlashVerboseStatus
ctx->drawString("USB Flash Mode: ", KDPoint(0, 180), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString(USBFlashVerbose, KDPoint(112, 180), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString("Press (+) to switch mode", KDPoint(0, 193), KDFont::SmallFont, KDColorWhite, KDColorBlack);
ctx->drawString("2.0.6", KDPoint(260, 180), KDFont::LargeFont, KDColorRed, KDColorBlack);
if (Bootloader::Slot::A().kernelHeader()->isValid()) {
const char* version = Bootloader::Slot::A().kernelHeader()->version();
bool isExam = Bootloader::ExamMode::SlotsExamMode::FetchSlotExamMode(version, "A") > 0;
Expand Down
2 changes: 1 addition & 1 deletion bootloader/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Interface {
static void drawImage(KDContext* ctx, const Image* image, int offset);

public:
static void draw();
static void draw(int currentUSB);
static void drawMessageBox(const char* line1, const char* line2);

};
Expand Down
84 changes: 46 additions & 38 deletions bootloader/slot_exam_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,48 @@ uint32_t SlotsExamMode::getSlotBEndExamAddress(int ExamVersion) {
}

uint8_t SlotsExamMode::FetchSlotExamMode(const char* version, const char* Slot) {
//get start and end from version and slot
uint32_t start = 0;
uint32_t end = 0;
if (Slot == "A") {
//if version under 16 get Old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotAStartExamAddress(0);
//get start and end from version and slot
uint32_t start = 0;
uint32_t end = 0;
if (Slot == "A") {
//if version under 16 get Old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
start = getSlotAStartExamAddress(0);
end = getSlotAEndExamAddress(0);
}
//else get new
else {
start = getSlotAStartExamAddress(1);
end = getSlotAEndExamAddress(1);
}
}
else if (Slot == "B") {
//if version under 16 get Old
if (version[0] < '1' || (version[0] == '1' && version[1] < '6')) {
}
//else get new
else {
start = getSlotAStartExamAddress(1);
end = getSlotAEndExamAddress(1);
}
}
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 {
start = getSlotBStartExamAddress(1);
end = getSlotBEndExamAddress(1);
}
}

if (strcmp("15.9.0", version) >= 0) {
return examFetch15(start, end);
} else if (strcmp("16.9.0", version) > 0) {
return examFetch16(start, end);
}
else if (strcmp("19.0.0", version) > 0) {
return examFetch1718(start, end);
}
//else get new
else {
return examFetch19(start, end);
start = getSlotBStartExamAddress(1);
end = getSlotBEndExamAddress(1);
}
}

if (strcmp("15.9.0", version) >= 0) {
return examFetch15(start, end);
}
else if (strcmp("16.9.0", version) > 0) {
return examFetch16(start, end);
}
else if (strcmp("19.0.0", version) > 0) {
return examFetch1718(start, end);
}
else {
return examFetch19(start, end);
}
}

uint8_t SlotsExamMode::examFetch15(uint32_t start, uint32_t end) {
uint32_t* persitence_start_32 = (uint32_t*)start;
uint32_t* persitence_end_32 = (uint32_t*)end;
Expand Down Expand Up @@ -186,11 +187,18 @@ uint8_t SlotsExamMode::examFetch19(uint32_t start, uint32_t end) {
uint16_t* start16 = (uint16_t*)start;
uint16_t* end16 = (uint16_t*)end;

while (start16 + 1 <= end16 && *start16 != 0xFFFF) {
start16++;
}

return *(start16 - 1) >> 8;
for (uint16_t* i = end16 - 2; i > start16; i--) {
if (*i != 0xFFFF) {
uint8_t highByte = *i >> 8;
uint8_t lowByte = *i & 0xFF;
if (highByte > lowByte) {
return highByte;
}
else {
return lowByte;
}
}
}
}


Expand Down
10 changes: 8 additions & 2 deletions bootloader/usb_desc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ namespace Ion {
namespace Device {
namespace USB {

const char* stringDescriptor() {
return "@Flash/0x90000000/08*004Kg,01*032Kg,63*064Kg,64*064Kg";
const char* stringDescriptor(int slot) {
if (slot == 1) {
return "@Flash/0x90000000/08*004Kg,01*032Kg,63*064Kg";
} else if (slot == 2) {
return "@Flash/0x90400000/64*064Kg";
} else if (slot == 3) {
return "@Flash/0x90000000/08*004Kg,01*032Kg,63*064Kg,64*064Kg";
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion build/config.mak
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEBUG ?= 0

HOME_DISPLAY_EXTERNALS ?= 1
EPSILON_VERSION ?= 15.5.0
OMEGA_VERSION ?= 2.0.5
OMEGA_VERSION ?= 2.0.6
# OMEGA_USERNAME ?= N/A
OMEGA_STATE ?= public
EPSILON_APPS ?= calculation rpn graph code statistics probability solver atomic sequence regression settings external
Expand Down
2 changes: 1 addition & 1 deletion ion/include/ion/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool isPlugged();
bool isEnumerated(); // Speed-enumerated, to be accurate
void clearEnumerationInterrupt();

void DFU(bool exitWithKeyboard = true);
void DFU(bool exitWithKeyboard = true, int slot = 3);
void enable();
void disable();

Expand Down
2 changes: 1 addition & 1 deletion ion/src/device/shared/drivers/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void initGPIO();
void shutdownGPIO();
void initOTG();
void shutdownOTG();
const char* stringDescriptor();
const char* stringDescriptor(int slot = 3);

}
}
Expand Down
2 changes: 1 addition & 1 deletion ion/src/device/shared/drivers/usb_desc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Ion {
namespace Device {
namespace USB {

const char* stringDescriptor() {
const char* stringDescriptor(int slot) {
return Config::InterfaceStringDescriptor;
}

Expand Down
4 changes: 2 additions & 2 deletions ion/src/device/shared/usb/calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Ion {
namespace Device {
namespace USB {

void Calculator::PollAndReset(bool exitWithKeyboard) {
void Calculator::PollAndReset(bool exitWithKeyboard, int slot) {
char serialNumber[Ion::Device::SerialNumber::Length+1];
Ion::Device::SerialNumber::copy(serialNumber);
Calculator c(serialNumber);
Calculator c(serialNumber, slot);

/* Leave DFU mode if the Back key is pressed, the calculator unplugged or the
* USB core soft-disconnected. */
Expand Down
6 changes: 3 additions & 3 deletions ion/src/device/shared/usb/calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace USB {

class Calculator : public Device {
public:
static void PollAndReset(bool exitWithKeyboard)
static void PollAndReset(bool exitWithKeyboard, int slot = 3)
__attribute__((section(".dfu_entry_point"))) // Needed to pinpoint this symbol in the linker script
__attribute__((used)) // Make sure this symbol is not discarded at link time
; // Return true if reset is needed
Calculator(const char * serialNumber) :
Calculator(const char * serialNumber, int slot = 3) :
Device(&m_dfuInterface),
m_deviceDescriptor(
0x0210, /* bcdUSB: USB Specification Number which the device complies
Expand Down Expand Up @@ -95,7 +95,7 @@ class Calculator : public Device {
m_manufacturerStringDescriptor("NumWorks"),
m_productStringDescriptor("NumWorks Calculator"),
m_serialNumberStringDescriptor(serialNumber),
m_interfaceStringDescriptor(stringDescriptor()),
m_interfaceStringDescriptor(stringDescriptor(slot)),
//m_interfaceStringDescriptor("@SRAM/0x20000000/01*256Ke"),
/* Switch to this descriptor to use dfu-util to write in the SRAM.
* FIXME Should be an alternate Interface. */
Expand Down
44 changes: 22 additions & 22 deletions ion/src/device/shared/usb/dfu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ void DFUInterface::StateData::push(Channel * c) const {
}

void DFUInterface::wholeDataReceivedCallback(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength) {
if (request->bRequest() == (uint8_t) DFURequest::Download) {
if (request->bRequest() == (uint8_t) DFURequest::Download) {
// Handle a download request
if (request->wValue() == 0) {
// The request is a special command
switch (transferBuffer[0]) {
case (uint8_t) DFUDownloadCommand::SetAddressPointer:
setAddressPointerCommand(request, transferBuffer, *transferBufferLength);
return;
case (uint8_t) DFUDownloadCommand::Erase:
eraseCommand(transferBuffer, *transferBufferLength);
return;
default:
m_state = State::dfuERROR;
m_status = Status::errSTALLEDPKT;
return;
}
}
if (request->wValue() == 0) {
// The request is a special command
switch (transferBuffer[0]) {
case (uint8_t)DFUDownloadCommand::SetAddressPointer:
setAddressPointerCommand(request, transferBuffer, *transferBufferLength);
return;
case (uint8_t)DFUDownloadCommand::Erase:
eraseCommand(transferBuffer, *transferBufferLength);
return;
default:
m_state = State::dfuERROR;
m_status = Status::errSTALLEDPKT;
return;
}
}
if (request->wValue() == 1) {
m_ep0->stallTransaction();
return;
}
if (request->wLength() > 0) {
// The request is a "real" download. Compute the writing address.
m_writeAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer;
// Store the received data until we copy it on the flash.
memcpy(m_largeBuffer, transferBuffer, *transferBufferLength);
m_largeBufferLength = *transferBufferLength;
m_state = State::dfuDNLOADSYNC;
// The request is a "real" download. Compute the writing address.
m_writeAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer;
// Store the received data until we copy it on the flash.
memcpy(m_largeBuffer, transferBuffer, *transferBufferLength);
m_largeBufferLength = *transferBufferLength;
m_state = State::dfuDNLOADSYNC;
}
}
}
Expand Down
Loading

0 comments on commit 9629acf

Please sign in to comment.