diff options
author | Nam T. Nguyen <namnguyen@chromium.org> | 2015-01-21 11:18:32 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-22 21:14:26 +0000 |
commit | c67b061cb5cad74e67260a45f38cc03d2984b5d3 (patch) | |
tree | 2d74378207873be1c707d14684283109b755bda4 /cgpt | |
parent | 4e1a9569c352e90da32e3d7bff461c4197dfac67 (diff) | |
download | vboot-c67b061cb5cad74e67260a45f38cc03d2984b5d3.tar.gz |
cgpt_wrapper: Only write rw_gpt back if changed
We always wrote back the rw_gpt file to NOR flash. This operation is too
slow. This CL compares if the original file has been changed by cgpt.bin
before writing the file back to NOR.
BUG=None
BRANCH=None
TEST=/usr/bin/cgpt show /dev/mtd0 now does not write back to NOR
Change-Id: I4c63f0d4da72f3674e06a896fa329f5fc964a885
Reviewed-on: https://chromium-review.googlesource.com/242293
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Nam Nguyen <namnguyen@google.com>
Diffstat (limited to 'cgpt')
-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; } |