From 98bc523274c8343f91e8657b1d85653944094f09 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 3 Mar 2026 12:36:54 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'util/nvmutil/nvmutil.c') 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); } -- cgit v1.2.1