diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-02-23 11:13:09 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-02-23 11:13:09 +0000 |
| commit | 50de561ac4837edfa81abd36df0bae2ecb62bc20 (patch) | |
| tree | b0c5c2bfd0faa1211028d68aff29c1990e11bcd2 | |
| parent | 061e6048a864cb1dd6d80052e54b0794af61e6ba (diff) | |
nvmutil: explain a few parts in nvmalloc
the current code is optimised for speed, but it's a bit
esoteric, so make it easier to understand.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 99900878..360febca 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -197,19 +197,24 @@ openFiles(const char *path) void nvmalloc(void) { + /* same operations need the full block, others only 128 bytes */ if ((cmd == cmd_swap) || (cmd == cmd_copy)) nf = SIZE_4KB; else nf = NVM_SIZE; + /* only read the part specified, for copy/setchecksum/brick */ if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick)) do_read[part ^ 1] = 0; + /* only allocate one block if only one part being read */ char *buf = malloc(nf << (do_read[0] & do_read[1])); if (buf == NULL) err(errno, NULL); gbe[0] = (size_t) buf; + + /* speedhack: for cmd copy, both pointers are set the same */ gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1])); } |
