From c0a77a7301c52464404d96665f491f34803f46d4 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 6 Mar 2026 17:21:15 +0000 Subject: util/nvmutil: make the MAC shifting easier to read Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'util') 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 -- cgit v1.2.1