diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-02-23 13:41:37 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-02-23 13:42:27 +0000 |
| commit | e1d8773c5453084bd7016c070a0bbf3b9d043f6d (patch) | |
| tree | 84100ddcfdc52d070c9a4930b9a4d195019025a9 /util | |
| parent | 261c41a3c382aeb7a9a14850150418960b072747 (diff) | |
nvmutil: split pwrite handling from writeGbe
handle it in a separate function, for clarity.
the main function just checks each part whether it
changed, and then passes control to writeGbe_part.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 4720095c..ee86de14 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -18,7 +18,7 @@ void cmd_setchecksum(void), cmd_brick(void), swap(int partnum), writeGbe(void), cmd_dump(void), cmd_setmac(void), nvmalloc(void), readGbe(void), checkdir(const char *path), macf(int partnum), hexdump(int partnum), parseMacString(const char *strMac, uint16_t *mac), cmd_swap(void), - openFiles(const char *path), cmd_copy(void); + openFiles(const char *path), cmd_copy(void), writeGbe_part(int); int goodChecksum(int partnum); uint8_t hextonum(char chs), rhex(void); @@ -421,19 +421,22 @@ void writeGbe(void) { for (int p = 0; p < 2; p++) { - if ((!nvmPartChanged[p]) || (flags == O_RDONLY)) - continue; - - swap(p); /* swap bytes on big-endian host CPUs */ - if(pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize) != nf) - err(ERR(), "Couldn't write %ld bytes to '%s' part '%d'", - nf, filename, p); + if ((nvmPartChanged[p]) && (flags != O_RDONLY)) + writeGbe_part(p); } - err_if(close(fd) == -1); } void +writeGbe_part(int p) +{ + swap(p); /* swap bytes on big-endian host CPUs */ + if(pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize) != nf) + err(ERR(), "Can't write %ld b to '%s' p%d", nf, filename, p); + +} + +void swap(int partnum) { uint8_t *n = (uint8_t *) gbe[partnum]; |
