summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-01-29 03:41:55 +0000
committerLeah Rowe <leah@libreboot.org>2025-01-29 03:41:55 +0000
commitb1d8975959dc942bb8691253f3599e4ac99932eb (patch)
tree69683ab392ab850fab17db858fec42229e0fd7fe
parent6821659bcb205c0c1fc796fd7a9543f42b7bacc7 (diff)
util/nvmutil: Only read up to 4KB on larger gbe
On the 16KB and 128KB files, we still only need to operate on 4KB at the start of each block, where the block size is larger than 4KB. The reason we deal with the entire 4KB block is because the nvm words (in the 128 byte section) can define an extended nvm area anywhere after 128 bytes, within the 128 byte block. We could systematically read where that is being handled, and handle it; we could then allocate less memory, and read/write fewer bytes, but many block devices like SSDs and flash drives have at least a 4KB erase block anyway, so it's kinda pointless. saving memory would be nice, but I don't really want to bloat the code. This is a nice easy optimisation, to avoid wasting an additional 8KB of memory when handling 16KB files, and additional 120KB if handling 128KB files, since nf is what determines how much memory will be allocated. the alternative would be to use an mmap, and then we could reasonably handle the idea above for only writing, surgically, what we need: nvm words and extended nvm words. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--config/ifd/xx30/gbebin8192 -> 8192 bytes
-rw-r--r--util/nvmutil/nvmutil.c4
2 files changed, 3 insertions, 1 deletions
diff --git a/config/ifd/xx30/gbe b/config/ifd/xx30/gbe
index 0c9dfa1d..a4758cba 100644
--- a/config/ifd/xx30/gbe
+++ b/config/ifd/xx30/gbe
Binary files differ
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index dacfeaaf..5ee990f2 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -29,6 +29,7 @@ uint8_t hextonum(char chs), rhex(void);
#define NVM_CHECKSUM_WORD 0x3F /* checksum word position */
#define NVM_SIZE 128 /* Area containing NVM words */
+#define SIZE_4KB 0x1000
#define SIZE_8KB 0x2000
#define SIZE_16KB 0x4000
#define SIZE_128KB 0x20000
@@ -211,7 +212,8 @@ void
readGbe(void)
{
if ((cmd == cmd_swap) || (cmd == cmd_copy))
- nf = partsize; /* read/write the entire block */
+ nf = SIZE_4KB; /* read/write the entire block */
+ /* only need to do 4KB even on larger gbe files */
else
nf = NVM_SIZE; /* only read/write the nvm part of the block */