mirror of
https://github.com/liberatedsystems/RNode_Firmware_CE.git
synced 2025-07-23 06:41:05 -04:00
Fix for FW hashe not being calculated correctly on NRF52
This commit is contained in:
parent
c88fe0ed33
commit
d69c1552e2
6 changed files with 3728 additions and 82 deletions
36
Utilities.h
36
Utilities.h
|
@ -27,9 +27,11 @@
|
|||
#include <InternalFileSystem.h>
|
||||
using namespace Adafruit_LittleFS_Namespace;
|
||||
#define EEPROM_FILE "eeprom"
|
||||
#define FW_LENGTH_FILE "fw_length"
|
||||
bool file_exists = false;
|
||||
int written_bytes = 4;
|
||||
File file(InternalFS);
|
||||
File eeprom_file(InternalFS);
|
||||
File fw_length_file(InternalFS);
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -1159,21 +1161,21 @@ void promisc_disable() {
|
|||
bool eeprom_begin() {
|
||||
InternalFS.begin();
|
||||
|
||||
file.open(EEPROM_FILE, FILE_O_READ);
|
||||
eeprom_file.open(EEPROM_FILE, FILE_O_READ);
|
||||
|
||||
// if file doesn't exist
|
||||
if (!file) {
|
||||
if (file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
||||
if (!eeprom_file) {
|
||||
if (eeprom_file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
||||
// initialise the file with empty content
|
||||
uint8_t empty_content[EEPROM_SIZE] = {0};
|
||||
file.write(empty_content, EEPROM_SIZE);
|
||||
eeprom_file.write(empty_content, EEPROM_SIZE);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
eeprom_file.close();
|
||||
eeprom_file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1181,8 +1183,8 @@ void promisc_disable() {
|
|||
uint8_t eeprom_read(uint32_t mapped_addr) {
|
||||
uint8_t byte;
|
||||
void* byte_ptr = &byte;
|
||||
file.seek(mapped_addr);
|
||||
file.read(byte_ptr, 1);
|
||||
eeprom_file.seek(mapped_addr);
|
||||
eeprom_file.read(byte_ptr, 1);
|
||||
return byte;
|
||||
}
|
||||
#endif
|
||||
|
@ -1243,8 +1245,8 @@ void kiss_dump_eeprom() {
|
|||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||
void eeprom_flush() {
|
||||
// sync file contents to flash
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
eeprom_file.close();
|
||||
eeprom_file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
written_bytes = 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1260,11 +1262,11 @@ void eeprom_update(int mapped_addr, uint8_t byte) {
|
|||
// each time is really slow, but this is also suboptimal
|
||||
uint8_t read_byte;
|
||||
void* read_byte_ptr = &read_byte;
|
||||
file.seek(mapped_addr);
|
||||
file.read(read_byte_ptr, 1);
|
||||
file.seek(mapped_addr);
|
||||
eeprom_file.seek(mapped_addr);
|
||||
eeprom_file.read(read_byte_ptr, 1);
|
||||
eeprom_file.seek(mapped_addr);
|
||||
if (read_byte != byte) {
|
||||
file.write(byte);
|
||||
eeprom_file.write(byte);
|
||||
}
|
||||
written_bytes++;
|
||||
|
||||
|
@ -1274,8 +1276,8 @@ void eeprom_update(int mapped_addr, uint8_t byte) {
|
|||
}
|
||||
|
||||
if (written_bytes >= 4) {
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
eeprom_file.close();
|
||||
eeprom_file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
written_bytes = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue