Skip to content

Commit cb7d35d

Browse files
committed
Read magic bytes from ofw bl directly (flash)
1 parent 897d947 commit cb7d35d

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

sd-bootloader-ng/bootmanager/config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sGeneralSettings Config_generalSettings = {
88
60, //waitTimeoutInS
99
2100, //minBatteryLevel (Divide through around 700 to get voltage, so 3V should be save)
1010
0x0010014C, //ofwFixValue - Magic bytes from OFW BL
11+
"\0", //ofwFixFlash
1112
#ifdef NO_DEBUG_LOG
1213
false, //serialLog
1314
#else
@@ -113,6 +114,10 @@ static void jsmn_str(const char *value, size_t len, void *user_arg) {
113114
if (strcmp("general", jsonGroupName) == 0) {
114115
if (strcmp("activeImg", jsonValueName) == 0) {
115116
Config_generalSettings.activeImage = getImageNumber(value);
117+
} else if (strcmp("ofwFixFlash", jsonValueName) == 0) {
118+
uint8_t cpyLen = min(len, CONFIG_FLASH_PATH_MAX-1);
119+
strncpy(Config_generalSettings.ofwFixFlash, value, cpyLen);
120+
Config_generalSettings.ofwFixFlash[cpyLen] = '\0';
116121
}
117122
} else if (strncmp(jsonGroupName, "ofw", 3) == 0
118123
|| strncmp(jsonGroupName, "cfw", 3)

sd-bootloader-ng/bootmanager/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct sGeneralSettings
2424
uint16_t waitTimeoutInS;
2525
uint16_t minBatteryLevel;
2626
uint32_t ofwFixValue;
27+
char ofwFixFlash[CONFIG_FLASH_PATH_MAX];
2728
bool serialLog;
2829
uint8_t logLevel;
2930
bool logColor;

sd-bootloader-ng/bootmanager/main.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,47 @@ static bool prepareRun(sImageInfo* imageInfo, char* imagePath, uint32_t filesize
669669
if (strnlen(creationDate, 13) == 12 //latest format
670670
|| strnlen(creationDate, 29) == 28) //old format
671671
Logger_info(" creationDate=%s", creationDate);
672+
673+
if (Config_generalSettings.ofwFixFlash[0] != '\0') {
674+
SimpleLinkInit();
675+
_i32 fhandle;
676+
SlFsFileInfo_t pFsFileInfo;
677+
if (!sl_FsOpen(Config_generalSettings.ofwFixFlash, FS_MODE_OPEN_READ, NULL, &fhandle)) {
678+
if (!sl_FsGetInfo(Config_generalSettings.ofwFixFlash, 0, &pFsFileInfo)) {
679+
uint32_t numbers[2];
680+
uint32_t offset = 0;
681+
uint32_t readLen = 0;
682+
if (pFsFileInfo.FileLen == 4) { //File with magic bytes only
683+
offset = 0;
684+
readLen = 4;
685+
numbers[1] = 0xBEAC0005;
686+
Logger_debug("Read OfwFix from 4-byte file flash:%s", Config_generalSettings.ofwFixFlash);
687+
} else if (pFsFileInfo.FileLen == 20956) { //OFW BL
688+
offset = pFsFileInfo.FileLen - 8;
689+
readLen = 8;
690+
Logger_debug("Read OfwFix from ofw bl flash:%s", Config_generalSettings.ofwFixFlash);
691+
} else {
692+
Logger_debug("Invalid OfwFix file flash:%s with len=%i", Config_generalSettings.ofwFixFlash, pFsFileInfo.FileLen);
693+
readLen = 0;
694+
}
695+
696+
if (readLen > 0 && (readLen == sl_FsRead(fhandle, offset, numbers, readLen))) {
697+
sl_FsClose(fhandle, 0, 0, 0);
698+
if (numbers[1] == 0xBEAC0005) {
699+
Config_generalSettings.ofwFixValue = numbers[0];
700+
} else {
701+
Logger_error("Invalid OfwFix file flash:%s with wrong id=0x%08X instead of 0xBEAC0005", Config_generalSettings.ofwFixFlash, numbers[1]);
702+
}
703+
} else {
704+
Logger_debug("Could not get read OfwFix file flash:%s ", Config_generalSettings.ofwFixFlash);
705+
}
706+
} else {
707+
Logger_debug("Could not get size of OfwFix file flash:%s ", Config_generalSettings.ofwFixFlash);
708+
}
709+
} else {
710+
Logger_debug("Could not open OfwFix file flash:%s ", Config_generalSettings.ofwFixFlash);
711+
}
712+
}
672713

673714
Logger_debug("Apply OFW fix 0x%08X", Config_generalSettings.ofwFixValue);
674715
if (*pCheck1 == 0xBEAC0005 && *pCheck1 == *pCheck2) {

sd-bootloader-ng/bootmanager/sd/revvox/boot/ngCfg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"waitTimeoutInS": 60,
66
"_descMinBatteryLevel": "Divide through around 700 to get voltage",
77
"minBatteryLevel": 2100,
8-
"ofwFixValue": ["4C", "01", "10", "00"],
8+
"ofwFixFlash": "/sys/pre-img.bin",
99
"_descSerialLog": "Logging only works with the debug build!",
1010
"serialLog": false,
1111
"_descLogLevel": "0:Trace - 5:Fatal",

wiki/Bootloader.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The configuration for the bootloader is saved within [sd:/revvox/boot/ngCfg.json
4343
| waitTimeoutInS | Timeout in seconds for waitForPress if no earpress (hibernation) | 1-255 | 60 |
4444
| minBatteryLevel | Poweroff voltage to protect the battery. Divide through around 700 to get voltage (Standard 3V) | | 2100 |
4545
| ofwFixValue | Magic bytes to be placed into the OFW Image during boot (can be extracted from OFW BL data[-8:-4]) | hex array with 4 bytes | ["4C", "01", "10", "00"] |
46+
| ofwFixFlash| Magic bytes read from the ofw bootloader on flash | ex. /sys/pre-img.bin| |
4647
| serialLog | Enable log to UART (TX) @115200 baud. Only works for debug build! | true, false | true |
4748
| logLevel | Set Log level 0:Trace - 5:Fatal | 0-5 | DEBUG_LOG_LEVEL |
4849
| logColor | Enable colored log | true, false | false |

0 commit comments

Comments
 (0)