From b0a8cacd1dd11dbf6f8f7b46675d89e5b5b32920 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 30 Mar 2024 15:02:22 +0000 Subject: rolo: simplify parsing scramble header in load_firmware() The standard load_firmware() function is used on targets which use the "scramble -add" method for generating Rockbox binaries. While it tries to be a bit more generic and allows the CRC/data offsets to be placed anywhere in the file, there are no targets which actually need this flexibility, because they are all using plain old "scramble -add". So we can actually simplify load_firmware() and remove defines from the target headers. All the targets used CRC offset = 0 and data offset = 8, except for a few which I assume never supported ROLO or were never tested -- eg. samsungyh820: the CRC and data offsets cannot both be 0. The actual motivation for this is removing the calls to lseek(), which can help make bootloaders a tiny bit smaller, as lseek is typically not used anywhere else in bootloaders. Change-Id: Ic2d01e5b75a32e88363f085e3e839146a0710bf4 --- firmware/common/rb-loader.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'firmware/common/rb-loader.c') diff --git a/firmware/common/rb-loader.c b/firmware/common/rb-loader.c index 430ed6ec7b..0256f21884 100644 --- a/firmware/common/rb-loader.c +++ b/firmware/common/rb-loader.c @@ -58,16 +58,15 @@ static int load_firmware_filename(unsigned char* buf, goto end; } - lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); - - if (read(fd, &chksum, 4) < 4) + /* read 32-bit checksum followed by 4-byte model name, + * this is the "scramble -add" header written by tools/scramble */ + if (read(fd, buf, 8) < 8) { ret = EREAD_CHKSUM_FAILED; goto end; } - chksum = betoh32(chksum); /* Rockbox checksums are big-endian */ - lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET); + chksum = load_be32(buf); /* Rockbox checksums are big-endian */ if (read(fd, buf, len) < len) { -- cgit v1.2.3