From eaad16edad243dc7ca9e66bd88ea106e83c7f105 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 26 Nov 2022 23:25:23 +0000 Subject: util/nvmutil: cmd setchecksum in own function --- util/nvmutil/nvmutil.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 67ae77f4..7ea39537 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -41,6 +41,7 @@ void cmd(const char *command); void cmd_dump(void); void showmac(int partnum); void hexdump(int partnum); +void cmd_setchecksum(void); int validChecksum(int partnum); uint16_t word(int pos16, int partnum); void setWord(int pos16, int partnum, uint16_t val); @@ -236,16 +237,12 @@ invalid_mac_address: void cmd(const char *command) { - int c, part0, part1; - uint16_t val16; + int part0, part1; if (strcmp(command, "dump") == 0) { cmd_dump(); } else if (strcmp(command, "setchecksum") == 0) { - val16 = 0; - for (c = 0; c < 0x3F; c++) - val16 += word(c, part); - setWord(0x3F, part, 0xBABA - val16); + cmd_setchecksum(); } else if (strcmp(command, "brick") == 0) { if (validChecksum(part)) setWord(0x3F, part, (word(0x3F, part)) ^ 0xFF); @@ -325,6 +322,16 @@ hexdump(int partnum) } } +void +cmd_setchecksum(void) +{ + int c; + uint16_t val16 = 0; + for (c = 0; c < 0x3F; c++) + val16 += word(c, part); + setWord(0x3F, part, 0xBABA - val16); +} + int validChecksum(int partnum) { -- cgit v1.2.1