mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-13 06:49:52 +02:00
util/nvmutil: make swap() easier to understand
the swap function reverses the byte order in memory, of a loaded GbE after after reading it, or before writing it. this is required (as detected) on big-endian CPUs, because GbE files store bytes in little-endian order. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -540,8 +540,15 @@ swap(int partnum)
|
||||
int e = 1;
|
||||
uint8_t *n = buf + (SIZE_4KB * partnum);
|
||||
|
||||
for (w = NVM_SIZE * ((uint8_t *) &e)[0], x = 1;
|
||||
w < NVM_SIZE; w += 2, x += 2) {
|
||||
if (((uint8_t *) &e)[0] == 1)
|
||||
return; /* Little-endian host CPU; no swap needed. */
|
||||
|
||||
/*
|
||||
* The host CPU stores bytes in big-endian order.
|
||||
* GbE files store bytes in little-endian order.
|
||||
* We will therefore reverse the order in memory:
|
||||
*/
|
||||
for (w = 0, x = 1; w < NVM_SIZE; w += 2, x += 2) {
|
||||
uint8_t chg = n[w];
|
||||
n[w] = n[x];
|
||||
n[x] = chg;
|
||||
|
||||
Reference in New Issue
Block a user