util/nvmutil: cmd setchecksum in own function

fsdg20230625
Leah Rowe 2022-11-26 23:25:23 +00:00
parent cea1beeac5
commit eaad16edad
1 changed files with 13 additions and 6 deletions

View File

@ -41,6 +41,7 @@ void cmd(const char *command);
void cmd_dump(void); void cmd_dump(void);
void showmac(int partnum); void showmac(int partnum);
void hexdump(int partnum); void hexdump(int partnum);
void cmd_setchecksum(void);
int validChecksum(int partnum); int validChecksum(int partnum);
uint16_t word(int pos16, 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 val);
@ -236,16 +237,12 @@ invalid_mac_address:
void void
cmd(const char *command) cmd(const char *command)
{ {
int c, part0, part1; int part0, part1;
uint16_t val16;
if (strcmp(command, "dump") == 0) { if (strcmp(command, "dump") == 0) {
cmd_dump(); cmd_dump();
} else if (strcmp(command, "setchecksum") == 0) { } else if (strcmp(command, "setchecksum") == 0) {
val16 = 0; cmd_setchecksum();
for (c = 0; c < 0x3F; c++)
val16 += word(c, part);
setWord(0x3F, part, 0xBABA - val16);
} else if (strcmp(command, "brick") == 0) { } else if (strcmp(command, "brick") == 0) {
if (validChecksum(part)) if (validChecksum(part))
setWord(0x3F, part, (word(0x3F, part)) ^ 0xFF); 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 int
validChecksum(int partnum) validChecksum(int partnum)
{ {