summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-02 11:52:49 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-02 11:52:49 +0100
commitc9fdfce34ecae22873293fe6747db6c746a27309 (patch)
tree7678a64ff2978e65444b557f03504bf7e5fdcf24 /util/nvmutil
parentbdccd7cb0c632a07e6d9feea4964ebbc18a48cd3 (diff)
util/nvmutil: simplify writeGbeFile()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c17
-rw-r--r--util/nvmutil/nvmutil.h2
2 files changed, 7 insertions, 12 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d9b79e61..26593137 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -83,7 +83,7 @@ readGbeFile(const char *path)
if (skipread[p])
continue;
xpread(fd, (uint8_t *) gbe[p], nf, p << 12, path);
- handle_endianness();
+ handle_endianness(p);
}
}
@@ -256,16 +256,11 @@ writeGbeFile(const char *filename)
{
if (gbeFileModified)
errno = 0;
- for (int p = 0; p < 2; p++) {
- if (gbe[0] > gbe[1])
- p ^= 1; /* speedhack: write sequentially on-disk */
- if (!nvmPartModified[p])
- goto next_part;
- handle_endianness();
- xpwrite(fd, (uint8_t *) gbe[p], nf, p << 12, filename);
-next_part:
- if (gbe[0] > gbe[1])
- p ^= 1; /* speedhack: write sequentially on-disk */
+ for (int x = gbe[0] > gbe[1] ? 1 : 0, p = 0; p < 2; p++, x ^= 1) {
+ if (!nvmPartModified[x])
+ continue;
+ handle_endianness(x);
+ xpwrite(fd, (uint8_t *) gbe[x], nf, x << 12, filename);
}
xclose(fd, filename);
xpledge("stdio", NULL);
diff --git a/util/nvmutil/nvmutil.h b/util/nvmutil/nvmutil.h
index 18255c3e..d69977d8 100644
--- a/util/nvmutil/nvmutil.h
+++ b/util/nvmutil/nvmutil.h
@@ -56,7 +56,7 @@ int big_endian;
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
if (fstat(f, &st) == -1) err(ERR(), "%s", l)
#define xpread(f, b, n, o, l) if (pread(f, b, n, o) == -1) err(ERR(), "%s", l)
-#define handle_endianness() if (big_endian) xorswap_buf(p)
+#define handle_endianness(r) if (big_endian) xorswap_buf(r)
#define xpwrite(f, b, n, o, l) if (pwrite(f, b, n, o) == -1) err(ERR(), "%s", l)
#define xclose(f, l) if (close(f) == -1) err(ERR(), "%s", l)