Skip to content

Commit

Permalink
[FL-3761, FL-3869] Backports for 0.64 branch (flipperdevices#3771)
Browse files Browse the repository at this point in the history
* scripts: update.py: [FL-3761] guaranteed length for CRC fields in manifest
* Updater: fix inability to update with bigger updater.bin (flipperdevices#3676)

Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
hedger and skotopes authored Jul 15, 2024
1 parent 7063023 commit fc1ab34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions firmware/targets/f7/Src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ static bool flipper_update_load_stage(const string_t work_dir, UpdateManifest* m
string_clear(loader_img_path);

void* img = malloc(stat.fsize);
uint32_t bytes_read = 0;
uint32_t read_total = 0;
uint16_t read_current = 0;
const uint16_t MAX_READ = 0xFFFF;

uint32_t crc = 0;
do {
uint16_t size_read = 0;
if(f_read(&file, img + bytes_read, MAX_READ, &size_read) != FR_OK) {
if(f_read(&file, img + read_total, MAX_READ, &read_current) != FR_OK) { //-V769
break;
}
crc = crc32_calc_buffer(crc, img + bytes_read, size_read);
bytes_read += size_read;
} while(bytes_read == MAX_READ);
crc = crc32_calc_buffer(crc, img + read_total, read_current);
read_total += read_current;
} while(read_current == MAX_READ);

do {
if((bytes_read != stat.fsize) || (crc != manifest->staged_loader_crc)) {
if((read_total != stat.fsize) || (crc != manifest->staged_loader_crc)) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def bytes2ffhex(value: bytes):
@staticmethod
def int2ffhex(value: int, n_hex_syms=8):
if value:
n_hex_syms = math.ceil(math.ceil(math.log2(value)) / 8) * 2
n_hex_syms = max(math.ceil(math.ceil(math.log2(value)) / 8) * 2, n_hex_syms)
fmtstr = f"%0{n_hex_syms}X"
hexstr = fmtstr % value
return " ".join(list(Main.batch(hexstr, 2))[::-1])
Expand Down

0 comments on commit fc1ab34

Please sign in to comment.