From 0f4852450caaee38ccfde2dc1727b0c6cf5f9fbd Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 27 Jan 2023 20:13:15 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'util/nvmutil') 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; -- cgit v1.2.1