mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 18:55:24 +00:00
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>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
4e1a9569c3
commit
c67b061cb5
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user