summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-01-27 20:13:15 +0000
committerLeah Rowe <leah@libreboot.org>2023-01-27 20:13:15 +0000
commit0f4852450caaee38ccfde2dc1727b0c6cf5f9fbd (patch)
treecfce1fe02df40cd521016119c216906aa940aca5 /util
parentb1186968e83d4b21875d9949b28a2d3e7b281b64 (diff)
util/nvmutil: use gbe[] in word() and setword()
this will make the code more flexible, if (when) i add changes that allow multiple commands to be used in a single run, on any given number of files
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index c8bd829f..bc5859f4 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -46,7 +46,7 @@ void cmd_swap(void);
void cmd_copy(void);
int validChecksum(int partnum);
uint16_t word(int pos16, int partnum);
-void setWord(int pos16, int partnum, uint16_t val);
+void setWord(int pos16, int partnum, uint16_t val16);
void byteswap(uint8_t *byte);
void writeGbeFile(int *fd, const char *filename);
@@ -403,19 +403,21 @@ validChecksum(int partnum)
uint16_t
word(int pos16, int partnum)
{
- uint16_t val16 = ((uint16_t *) buf)[pos16 + (partnum << 11)];
- if (!little_endian)
- byteswap((uint8_t *) &val16);
-
- return val16;
+ uint8_t *nbuf = (uint8_t *) gbe[partnum];
+ uint16_t pos8 = pos16 << 1;
+ uint16_t val16 = nbuf[pos8 + 1];
+ val16 <<= 8;
+ return val16 |= nbuf[pos8];
}
void
-setWord(int pos16, int partnum, uint16_t val)
+setWord(int pos16, int partnum, uint16_t val16)
{
- ((uint16_t *) buf)[pos16 + (partnum << 11)] = val;
- if (!little_endian)
- byteswap(buf + (pos16 << 1) + (partnum << 12));
+ uint8_t *nbuf = (uint8_t *) gbe[partnum];
+ uint8_t val8[2] = {(uint8_t) (val16 & 0xff), (uint8_t) (val16 >> 8)};
+ uint16_t pos8 = pos16 << 1;
+ nbuf[pos8] = val8[0];
+ nbuf[pos8 + 1] = val8[1];
gbeFileModified = 1;
nvmPartModified[partnum] = 1;