First of all lengths should be compared after checking all blocks for
being good/bad. It's because requested length may differ from a final
one if there were some bad blocks.
Secondly it makes sense to also compare crc32 since we already have a
new one calculated.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=mtd
-PKG_RELEASE:=22
+PKG_RELEASE:=23
PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
exit(1);
}
- if (trx->len == STORE32_LE(data_size + TRX_CRC32_DATA_OFFSET)) {
- if (quiet < 2)
- fprintf(stderr, "Header already fixed, exiting\n");
- close(fd);
- return 0;
- }
-
buf = malloc(data_size);
if (!buf) {
perror("malloc");
}
data_size = to - buf;
+ if (trx->len == STORE32_LE(data_size + TRX_CRC32_DATA_OFFSET) &&
+ trx->crc32 == STORE32_LE(crc32buf(buf, data_size))) {
+ if (quiet < 2)
+ fprintf(stderr, "Header already fixed, exiting\n");
+ close(fd);
+ return 0;
+ }
+
trx->len = STORE32_LE(data_size + offsetof(struct trx_header, flag_version));
trx->crc32 = STORE32_LE(crc32buf(buf, data_size));