diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-06 17:21:15 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-06 17:22:31 +0000 |
| commit | c0a77a7301c52464404d96665f491f34803f46d4 (patch) | |
| tree | fd5109aa0d783fda40adbe3ae54bf254b764219f /util/nvmutil | |
| parent | 596643a0d5cfd4c5ed236a04dd0e95aacd910d78 (diff) | |
util/nvmutil: make the MAC shifting easier to read
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 3c8eeed4..8529f5c5 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -414,9 +414,20 @@ set_mac_nib(int mac_pos, int nib) (mac[mac_pos + nib] == 'X'))) /* random */ h = (h & 0xE) | 2; /* local, unicast */ - /* Store the new nibble as part of the new MAC address */ - macbuf[byte >> 1] |= (uint16_t)h << - (((byte & 1) << 3) + (4 * (nib ^ 1))); + /* + * The word is stored big-endian in the file. + * Logically in C, it is stored little-endian, + * because of how we load in read_gbe(), so + * we store the MAC address in reverse order + * per 2-byte word (there are 3 of these). + */ + int shift = (byte & 1) << 3; /* left or right byte? */ + shift |= (nib ^ 1) << 2; /* left or right nib? */ + + /* + * Now we can shift properly, OR'ing the result: + */ + macbuf[byte >> 1] |= (uint16_t)h << shift; } static uint8_t |
