From 0d62e6a7338d8f25727f56ca14236954fc8f2cef Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 10 Jul 2007 17:53:54 +0200 Subject: UBI-utils: add compare feature This is a new feature for pfiflash, called "--compare". It allows the user to simulate a pfiflash session without actually changing the flash content. If the flash content is equal to the data in the pfif file, pfiflash returns zero. A positive value is returned when the flash content differs from the pfi file, which indicates that an update is necessary. This feature is useful when a controller mounts an NFS share during boot and has to determine if a pfi file stored on this share contains a code update. Modified PDD values are also registered by the compare feature. Signed-off-by: Alexander Schmidt --- ubi-utils/src/bootenv.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'ubi-utils/src/bootenv.c') diff --git a/ubi-utils/src/bootenv.c b/ubi-utils/src/bootenv.c index ed15dc7..561d473 100644 --- a/ubi-utils/src/bootenv.c +++ b/ubi-utils/src/bootenv.c @@ -479,6 +479,54 @@ bootenv_write(FILE* fp, bootenv_t env) return bootenv_write_crc(fp, env, NULL); } +int +bootenv_compare(bootenv_t first, bootenv_t second) +{ + int rc; + size_t written_first, written_second; + char *buf_first, *buf_second; + + if (first == NULL || second == NULL) + return -EINVAL; + + buf_first = malloc(BOOTENV_MAXSIZE); + if (!buf_first) + return -ENOMEM; + buf_second = malloc(BOOTENV_MAXSIZE); + if (!buf_second) { + rc = -ENOMEM; + goto err; + } + + rc = fill_output_buffer(first, buf_first, BOOTENV_MAXSIZE, + &written_first); + if (rc < 0) + goto err; + rc = fill_output_buffer(second, buf_second, BOOTENV_MAXSIZE, + &written_second); + if (rc < 0) + goto err; + + if (written_first != written_second) { + rc = 1; + goto err; + } + + rc = memcmp(buf_first, buf_second, written_first); + if (rc != 0) { + rc = 2; + goto err; + } + +err: + if (buf_first) + free(buf_first); + if (buf_second) + free(buf_second); + + return rc; +} + int bootenv_size(bootenv_t env, size_t *size) { -- cgit v1.2.3