diff options
-rw-r--r-- | cgpt/cgpt_wrapper.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cgpt/cgpt_wrapper.c b/cgpt/cgpt_wrapper.c index 6750d8d8..577b2766 100644 --- a/cgpt/cgpt_wrapper.c +++ b/cgpt/cgpt_wrapper.c @@ -22,6 +22,7 @@ #include "cgpt.h" #include "cgpt_nor.h" +#include "cryptolib.h" // Check if cmdline |argv| has "-D". "-D" signifies that GPT structs are stored // off device, and hence we should not wrap around cgpt. @@ -64,6 +65,8 @@ static const char *find_mtd_device(int argc, const char *const argv[]) { static int wrap_cgpt(int argc, const char *const argv[], const char *mtd_device) { + uint8_t *original_hash = NULL; + uint8_t *modified_hash = NULL; int ret = 0; // Create a temp dir to work in. @@ -76,6 +79,7 @@ static int wrap_cgpt(int argc, if (snprintf(rw_gpt_path, sizeof(rw_gpt_path), "%s/rw_gpt", temp_dir) < 0) { goto cleanup; } + original_hash = DigestFile(rw_gpt_path, SHA1_DIGEST_ALGORITHM); // Obtain the MTD size. ret++; @@ -120,11 +124,17 @@ static int wrap_cgpt(int argc, // Write back "rw_gpt" to NOR flash in two chunks. ret++; - if (WriteNorFlash(temp_dir) == 0) { - ret = 0; + modified_hash = DigestFile(rw_gpt_path, SHA1_DIGEST_ALGORITHM); + if (original_hash != NULL && modified_hash != NULL && + memcmp(original_hash, modified_hash, SHA1_DIGEST_SIZE) != 0) { + if (WriteNorFlash(temp_dir) == 0) { + ret = 0; + } } cleanup: + free(original_hash); + free(modified_hash); RemoveDir(temp_dir); return ret; } |