mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[Reviews] Code correction and improvement
This commit is contained in:
@@ -12,6 +12,7 @@ bootloader_src += $(addprefix bootloader/,\
|
||||
recovery.cpp \
|
||||
usb_data.cpp \
|
||||
itoa.cpp \
|
||||
utility.cpp \
|
||||
)
|
||||
|
||||
bootloader_images = $(addprefix bootloader/, \
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <bootloader/recovery.h>
|
||||
#include <bootloader/usb_data.h>
|
||||
#include <ion/src/device/shared/drivers/flash.h>
|
||||
#include <bootloader/utility.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -25,14 +26,8 @@ void Boot::bootSlot(Bootloader::Slot s) {
|
||||
// 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";
|
||||
int vsum = 0;
|
||||
for (int i = 0; i < strlen(version); i++) {
|
||||
vsum += version[i] * (100-i*15);
|
||||
}
|
||||
int minsum = 0;
|
||||
for (int i = 0; i < strlen(min); i++) {
|
||||
minsum += min[i] * (100-i*15);
|
||||
}
|
||||
int vsum = Bootloader::Utility::versionSum(version, strlen(version));
|
||||
int minsum = Bootloader::Utility::versionSum(min, strlen(min));
|
||||
if (vsum >= minsum) {
|
||||
Interface::drawEpsilonAdvertisement();
|
||||
uint64_t scan = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <bootloader/itoa.h>
|
||||
#include <bootloader/utility.h>
|
||||
|
||||
// https://www.techiedelight.com/implement-itoa-function-in-c/
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <bootloader/kernel_header.h>
|
||||
#include <bootloader/utility.h>
|
||||
|
||||
namespace Bootloader {
|
||||
|
||||
@@ -22,16 +23,10 @@ const void(*KernelHeader::startPointer() const)() {
|
||||
return m_startPointer;
|
||||
}
|
||||
|
||||
const bool KernelHeader::isNewVersion() const {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
sum += m_version[i] * (5 - i);
|
||||
}
|
||||
const bool KernelHeader::isAboveVersion16 () const {
|
||||
int sum = Bootloader::Utility::versionSum(m_version, 2);
|
||||
char newVersion[] = "16";
|
||||
int min = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
min += newVersion[i] * (5 - i);
|
||||
}
|
||||
int min = Bootloader::Utility::versionSum(newVersion, 2);
|
||||
return sum >= min;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
const char * version() const;
|
||||
const char * patchLevel() const;
|
||||
const bool isValid() const;
|
||||
const bool isNewVersion() const;
|
||||
const bool isAboveVersion16() const;
|
||||
|
||||
const uint32_t* stackPointer() const;
|
||||
const void(*startPointer() const)();
|
||||
|
||||
@@ -20,7 +20,7 @@ __attribute__ ((noreturn)) void ion_main(int argc, const char * const argv[]) {
|
||||
bool isSlotA = Bootloader::Slot::A().kernelHeader()->isValid();
|
||||
|
||||
if (isSlotA) {
|
||||
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(Bootloader::Slot::A().kernelHeader()->isNewVersion());
|
||||
Bootloader::ExamMode::ExamMode SlotAExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotAExamMode(Bootloader::Slot::A().kernelHeader()->isAboveVersion16());
|
||||
if (SlotAExamMode != Bootloader::ExamMode::ExamMode::Off && SlotAExamMode != Bootloader::ExamMode::ExamMode::Unknown) {
|
||||
// We boot the slot in exam_mode
|
||||
Bootloader::Slot::A().boot();
|
||||
@@ -30,7 +30,7 @@ __attribute__ ((noreturn)) void ion_main(int argc, const char * const argv[]) {
|
||||
bool isSlotB = Bootloader::Slot::B().kernelHeader()->isValid();
|
||||
|
||||
if (isSlotB) {
|
||||
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(Bootloader::Slot::B().kernelHeader()->isNewVersion());
|
||||
Bootloader::ExamMode::ExamMode SlotBExamMode = (Bootloader::ExamMode::ExamMode)Bootloader::ExamMode::SlotsExamMode::FetchSlotBExamMode(Bootloader::Slot::B().kernelHeader()->isAboveVersion16());
|
||||
if (SlotBExamMode != Bootloader::ExamMode::ExamMode::Off && SlotBExamMode != Bootloader::ExamMode::ExamMode::Unknown && isSlotB) {
|
||||
// We boot the slot in exam_mode
|
||||
Bootloader::Slot::B().boot();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <bootloader/usb_data.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <bootloader/itoa.h>
|
||||
#include <bootloader/utility.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <bootloader/messages.h>
|
||||
@@ -27,13 +27,13 @@ const char * Bootloader::USBData::buildStringDescriptor(StringHeader header, uin
|
||||
}
|
||||
|
||||
const Bootloader::USBData Bootloader::USBData::DEFAULT() {
|
||||
return USBData("@Flash/0x90000000/08*004Kg,01*032Kg,63*064Kg,64*064Kg", Messages::upsilonBootloader, DFUData());
|
||||
return USBData("@Flash/0x90000000/08*004Kg,01*032Kg,63*064Kg,64*064Kg", Messages::upsilonBootloader, ProtectionState());
|
||||
}
|
||||
|
||||
const Bootloader::USBData Bootloader::USBData::BOOTLOADER_UPDATE() {
|
||||
return USBData("@Flash/0x08000000/04*016Kg", Messages::bootloaderUpdate, DFUData(true, false));
|
||||
return USBData("@Flash/0x08000000/04*016Kg", Messages::bootloaderUpdate, ProtectionState(true, false));
|
||||
}
|
||||
|
||||
Bootloader::USBData Bootloader::USBData::Recovery(uint32_t startAddress, uint32_t size) {
|
||||
return USBData(buildStringDescriptor(StringHeader::SRAM(), startAddress, size), Messages::upsilonRecovery, DFUData(false, false));
|
||||
return USBData(buildStringDescriptor(StringHeader::SRAM(), startAddress, size), Messages::upsilonRecovery, ProtectionState(false, false));
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
namespace Bootloader {
|
||||
|
||||
class DFUData {
|
||||
class ProtectionState {
|
||||
public:
|
||||
DFUData(bool unlockInternal = false, bool unlockExternal = true) : m_protectInternal(!unlockInternal), m_protectExternal(!unlockExternal) {};
|
||||
ProtectionState(bool unlockInternal = false, bool unlockExternal = true) : m_protectInternal(!unlockInternal), m_protectExternal(!unlockExternal) {};
|
||||
|
||||
bool isProtectedInternal() const { return m_protectInternal; }
|
||||
bool isProtectedExternal() const { return m_protectExternal; }
|
||||
@@ -33,11 +33,11 @@ class USBData {
|
||||
const char * m_string;
|
||||
};
|
||||
|
||||
USBData(const char * desc, const char * name, DFUData data = DFUData()) : m_stringDescriptor(desc), m_name(name), m_data(&data) {};
|
||||
USBData(const char * desc, const char * name, ProtectionState data = ProtectionState()) : m_stringDescriptor(desc), m_name(name), m_data(&data) {};
|
||||
|
||||
const char * stringDescriptor() const { return m_stringDescriptor; }
|
||||
const char * getName() const { return m_name; }
|
||||
DFUData * getData() const { return m_data; }
|
||||
ProtectionState * getData() const { return m_data; }
|
||||
|
||||
static const char * buildStringDescriptor(StringHeader header, uint32_t startAddress, uint32_t size);
|
||||
|
||||
@@ -48,7 +48,7 @@ class USBData {
|
||||
private:
|
||||
const char * m_stringDescriptor;
|
||||
const char * m_name;
|
||||
DFUData * m_data;
|
||||
ProtectionState * m_data;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ const bool UserlandHeader::isValid() const {
|
||||
}
|
||||
|
||||
const bool UserlandHeader::isOmega() const {
|
||||
return m_ohm_header == OmegaMagic && m_ohm_footer == OmegaMagic;
|
||||
return m_omegaMagicHeader == OmegaMagic && m_omegaMagicFooter == OmegaMagic;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const char * UserlandHeader::omegaVersion() const {
|
||||
}
|
||||
|
||||
const bool UserlandHeader::isUpsilon() const {
|
||||
return m_ups_header == UpsilonMagic && m_ups_footer == UpsilonMagic;
|
||||
return m_upsilonMagicHeader == UpsilonMagic && m_upsilonMagicHeader == UpsilonMagic;
|
||||
}
|
||||
|
||||
const char * UserlandHeader::upsilonVersion() const {
|
||||
|
||||
@@ -34,14 +34,14 @@ private:
|
||||
uint32_t m_externalAppsRAMStart;
|
||||
uint32_t m_externalAppsRAMEnd;
|
||||
uint32_t m_footer;
|
||||
uint32_t m_ohm_header;
|
||||
uint32_t m_omegaMagicHeader;
|
||||
const char m_omegaVersion[16];
|
||||
const volatile char m_username[16];
|
||||
uint32_t m_ohm_footer;
|
||||
uint32_t m_ups_header;
|
||||
uint32_t m_omegaMagicFooter;
|
||||
uint32_t m_upsilonMagicHeader;
|
||||
const char m_UpsilonVersion[16];
|
||||
uint32_t m_osType;
|
||||
uint32_t m_ups_footer;
|
||||
uint32_t m_upsilonMagicFooter;
|
||||
};
|
||||
|
||||
extern const UserlandHeader* s_userlandHeaderA;
|
||||
|
||||
10
bootloader/utility.cpp
Normal file
10
bootloader/utility.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <bootloader/utility.h>
|
||||
#include <string.h>
|
||||
|
||||
int Bootloader::Utility::versionSum(const char * version, int length) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
sum += version[i] * (strlen(version) * 100 - i * 10);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace Bootloader {
|
||||
class Utility {
|
||||
public:
|
||||
static char * itoa(int value, char * result, int base);
|
||||
static int versionSum(const char * version, int length);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _BOOTLOADER_ITOA_H_
|
||||
#endif
|
||||
Reference in New Issue
Block a user