util/nvmutil: Make the GbE checksum a define

This makes the code easier to understand.

All 2-byte words, stored in little endian order within
the 128-byte GbE NVM area, must add up to 0xBABA.

If it doesn't, then software is supposed to reject that
GbE config. The nvmutil software works on that basis.

Signed-off-by: Leah Rowe <leah@libreboot.org>
master
Leah Rowe 2025-01-03 01:36:20 +00:00
parent 874317c4e5
commit 033e4cd9d5
1 changed files with 3 additions and 2 deletions

View File

@ -24,6 +24,7 @@ uint8_t hextonum(char chs), rhex(void);
#define MAC_ADDRESS argv[3]
#define PARTN argv[3]
#define SIZE_4KB 0x1000
#define NVM_CHECKSUM 0xbaba
uint16_t buf16[SIZE_4KB], mac[3] = {0, 0, 0};
uint8_t *buf = (uint8_t *) &buf16;
@ -235,7 +236,7 @@ cmd_setchecksum(void)
uint16_t val16 = 0;
for (int c = 0; c < 0x3F; c++)
val16 += word(c, part);
setWord(0x3F, part, 0xBABA - val16);
setWord(0x3F, part, NVM_CHECKSUM - val16);
}
void
@ -258,7 +259,7 @@ goodChecksum(int partnum)
uint16_t total = 0;
for(int w = 0; w <= 0x3F; w++)
total += word(w, partnum);
if (total == 0xBABA)
if (total == NVM_CHECKSUM)
return 1;
fprintf(stderr, "WARNING: BAD checksum in part %d\n", partnum);
return (errno = ECANCELED) & 0;