From 8dea350a625c8d8d9fc0835664b50c1e90ca6fd8 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 17 Jan 2023 10:23:21 +0000 Subject: util/nvmutil: only write parts that are modified Old behaviour: always write both gbe sections. New behaviour: only write back what was changed. --- util/nvmutil/nvmutil.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 33f23899..4acef2fa 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -439,21 +439,22 @@ writeGbeFile(int *fd, const char *filename) int partnum; errno = 0; - if (pwrite((*fd), (uint8_t *) gbe[0], SIZE_4KB, 0) != SIZE_4KB) - err(errno, "%s", filename); - if (pwrite((*fd), (uint8_t *) gbe[1], SIZE_4KB, SIZE_4KB) != SIZE_4KB) - err(errno, "%s", filename); - if (close((*fd))) - err(errno, "%s", filename); - if (errno != 0) - err(errno, "%s", filename); - for (partnum = 0; partnum < 2; partnum++) { - if (nvmPartModified[partnum]) + if (nvmPartModified[partnum]) { printf("Part %d modified\n", partnum); - else + } else { fprintf (stderr, "Part %d NOT modified\n", partnum); + continue; + } + if (pwrite((*fd), (uint8_t *) gbe[partnum], SIZE_4KB, + partnum << 12) != SIZE_4KB) + err(errno, "%s", filename); } - printf("File `%s` successfully modified\n", filename); + if (close((*fd))) + err(errno, "%s", filename); + if (errno != 0) + err(errno, "%s", filename); + + printf("File `%s` successfully re-written.\n", filename); } -- cgit v1.2.1