summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2018-07-15 23:23:42 +0200
committerRafał Miłecki <rafal@milecki.pl>2018-07-17 07:17:48 +0200
commit79c8f2f50bcb2991ba0165a67d8bf3187dbb5bf2 (patch)
tree95019377f41e737791516eda24a00e1dfcd51828
parent828eaeee2550c954ea98063e59e09980c1361de2 (diff)
downloadmtk-20170518-79c8f2f50bcb2991ba0165a67d8bf3187dbb5bf2.zip
mtk-20170518-79c8f2f50bcb2991ba0165a67d8bf3187dbb5bf2.tar.gz
mtk-20170518-79c8f2f50bcb2991ba0165a67d8bf3187dbb5bf2.tar.bz2
mtd: improve check for TRX header being already fixed
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> (cherry picked from commit 82498a7f7aa86ad0e93ef60d50dccaa0a9549e4c)
-rw-r--r--package/system/mtd/Makefile2
-rw-r--r--package/system/mtd/src/trx.c15
2 files changed, 9 insertions, 8 deletions
diff --git a/package/system/mtd/Makefile b/package/system/mtd/Makefile
index 5d1538e..c364876 100644
--- a/package/system/mtd/Makefile
+++ b/package/system/mtd/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=mtd
-PKG_RELEASE:=22$(if $(SDK),,.1)
+PKG_RELEASE:=23$(if $(SDK),,.1)
PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
STAMP_PREPARED := $(STAMP_PREPARED)_$(call confvar,CONFIG_MTD_REDBOOT_PARTS)
diff --git a/package/system/mtd/src/trx.c b/package/system/mtd/src/trx.c
index c1296a5..aaca232 100644
--- a/package/system/mtd/src/trx.c
+++ b/package/system/mtd/src/trx.c
@@ -207,13 +207,6 @@ mtd_fixtrx(const char *mtd, size_t offset, size_t data_size)
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");
@@ -243,6 +236,14 @@ mtd_fixtrx(const char *mtd, size_t offset, size_t data_size)
}
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));