mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-21 19:26:22 +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;
|
int e = 1;
|
||||||
uint8_t *n = buf + (SIZE_4KB * partnum);
|
uint8_t *n = buf + (SIZE_4KB * partnum);
|
||||||
|
|
||||||
for (w = NVM_SIZE * ((uint8_t *) &e)[0], x = 1;
|
if (((uint8_t *) &e)[0] == 1)
|
||||||
w < NVM_SIZE; w += 2, x += 2) {
|
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];
|
uint8_t chg = n[w];
|
||||||
n[w] = n[x];
|
n[w] = n[x];
|
||||||
n[x] = chg;
|
n[x] = chg;
|
||||||
|
|||||||
Reference in New Issue
Block a user