summaryrefslogtreecommitdiff
path: root/util/nvmutil/nvmutil.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-03 12:36:54 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-03 12:40:50 +0000
commit98bc523274c8343f91e8657b1d85653944094f09 (patch)
tree439e45f6649491e63b3e99bfcbb97128353efd85 /util/nvmutil/nvmutil.c
parent6770fa8ef2f3365ddd11729e13e5db2d4c775e57 (diff)
util/nvmutil: re-introduce do_read in readGbe
lots of block devices use 4KB block size. it makes sense to have this optimisation here. i previously removed it, along with the one that only reads the NVM area - that one is still gone, because it was largely pointless. because of this modification returning, i also re-introduced the check in setWord against nvmPartModified - otherwise, for example, running cmd brick 0 would brick part 0 but then write all zeroes to part 1. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
-rw-r--r--util/nvmutil/nvmutil.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 68363bc8..b569e341 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -43,6 +43,7 @@ uint8_t buf[SIZE_8KB];
uint16_t mac[3] = {0, 0, 0};
size_t partsize;
int flags, rfd, fd, part, e = 1;
+int nvmPartModified[2] = {0, 0};
const char *strMac = NULL, *strRMac = "xx:xx:xx:xx:xx:xx", *fname = "";
@@ -184,8 +185,13 @@ xopen(int *f, const char *l, int p, struct stat *st)
void
readGbe(void)
{
+ int do_read[2] = {1, 1};
+ if ((cmd == cmd_copy) || (cmd == cmd_brick) || (cmd == cmd_setchecksum))
+ do_read[part ^ 1] = 0;
+
for (int p = 0; p < 2; p++)
- readGbe_part(p);
+ if (do_read[p])
+ readGbe_part(p);
}
void
@@ -415,6 +421,7 @@ void
setWord(int pos16, int p, uint16_t val16)
{
check_bounds(pos16, p);
+ nvmPartModified[p] = 1;
((uint16_t *) (buf + (SIZE_4KB * p)))[pos16] = val16;
}
@@ -432,7 +439,8 @@ writeGbe(void)
{
if (flags != O_RDONLY)
for (int p = 0; p < 2; p++)
- writeGbe_part(p);
+ if (nvmPartModified[p])
+ writeGbe_part(p);
err_if(close(fd) == -1);
}