mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-18 14:12:44 +02:00
util/nvmutil: simplify writeGbeFile()
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+6
-11
@@ -83,7 +83,7 @@ readGbeFile(const char *path)
|
|||||||
if (skipread[p])
|
if (skipread[p])
|
||||||
continue;
|
continue;
|
||||||
xpread(fd, (uint8_t *) gbe[p], nf, p << 12, path);
|
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)
|
if (gbeFileModified)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
for (int p = 0; p < 2; p++) {
|
for (int x = gbe[0] > gbe[1] ? 1 : 0, p = 0; p < 2; p++, x ^= 1) {
|
||||||
if (gbe[0] > gbe[1])
|
if (!nvmPartModified[x])
|
||||||
p ^= 1; /* speedhack: write sequentially on-disk */
|
continue;
|
||||||
if (!nvmPartModified[p])
|
handle_endianness(x);
|
||||||
goto next_part;
|
xpwrite(fd, (uint8_t *) gbe[x], nf, x << 12, filename);
|
||||||
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 */
|
|
||||||
}
|
}
|
||||||
xclose(fd, filename);
|
xclose(fd, filename);
|
||||||
xpledge("stdio", NULL);
|
xpledge("stdio", NULL);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ int big_endian;
|
|||||||
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
|
if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
|
||||||
if (fstat(f, &st) == -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 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 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)
|
#define xclose(f, l) if (close(f) == -1) err(ERR(), "%s", l)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user