util/nvmutil: even crazier code size reduction
parent
2ae9ff5446
commit
58e12063c7
|
@ -77,7 +77,7 @@ uint8_t big_endian;
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
size_t nr;
|
size_t nr = 128;
|
||||||
int fd, flags = O_RDWR;
|
int fd, flags = O_RDWR;
|
||||||
void (*cmd)(void) = NULL;
|
void (*cmd)(void) = NULL;
|
||||||
const char *strMac = NULL, *strRMac = "??:??:??:??:??:??";
|
const char *strMac = NULL, *strRMac = "??:??:??:??:??:??";
|
||||||
|
@ -101,45 +101,41 @@ main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
flags = O_RDONLY;
|
flags = O_RDONLY;
|
||||||
cmd = &cmd_dump;
|
cmd = &cmd_dump;
|
||||||
} else if (strcmp(COMMAND, "setmac") == 0)
|
} else if (strcmp(COMMAND, "setmac") == 0) {
|
||||||
strMac = (char *) strRMac; /* random mac address */
|
strMac = (char *) strRMac; /* random mac address */
|
||||||
else if (strcmp(COMMAND, "swap") == 0)
|
} else if (strcmp(COMMAND, "swap") == 0) {
|
||||||
cmd = &cmd_swap;
|
cmd = &cmd_swap;
|
||||||
|
nr = SIZE_4KB;
|
||||||
|
}
|
||||||
} else if (argc == 4) {
|
} else if (argc == 4) {
|
||||||
if (strcmp(COMMAND, "setmac") == 0)
|
if (strcmp(COMMAND, "setmac") == 0) {
|
||||||
strMac = MAC_ADDRESS; /* user-supplied mac address */
|
strMac = MAC_ADDRESS; /* user-supplied mac address */
|
||||||
else if ((!((part = PARTNUM[0] - '0') == 0 || part == 1))
|
} else if ((!((part = PARTNUM[0] - '0') == 0 || part == 1))
|
||||||
|| PARTNUM[1]) /* only allow '1' or '0' */
|
|| PARTNUM[1]) { /* only allow '1' or '0' */
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
else if (strcmp(COMMAND, "setchecksum") == 0)
|
} else if (strcmp(COMMAND, "setchecksum") == 0) {
|
||||||
cmd = &cmd_setchecksum;
|
cmd = &cmd_setchecksum;
|
||||||
else if (strcmp(COMMAND, "brick") == 0)
|
} else if (strcmp(COMMAND, "brick") == 0) {
|
||||||
cmd = &cmd_brick;
|
cmd = &cmd_brick;
|
||||||
else if (strcmp(COMMAND, "copy") == 0)
|
} else if (strcmp(COMMAND, "copy") == 0) {
|
||||||
cmd = &cmd_copy;
|
cmd = &cmd_copy;
|
||||||
|
nr = SIZE_4KB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strMac == NULL) && (cmd == NULL))
|
if ((strMac == NULL) && (cmd == NULL))
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
if (errno != 0)
|
|
||||||
err(errno, NULL);
|
|
||||||
|
|
||||||
nr = SIZE_4KB; /* copy/swap commands need everything to be read */
|
|
||||||
if ((cmd != &cmd_copy) && (cmd != &cmd_swap))
|
|
||||||
nr = 128; /* speedhack: read only the nvm part */
|
|
||||||
|
|
||||||
if ((cmd == &cmd_copy) || (cmd == &cmd_setchecksum) ||
|
|
||||||
(cmd == &cmd_brick))
|
|
||||||
skipread[part ^ 1] = 1; /* speedhack: don't read unused part */
|
|
||||||
|
|
||||||
|
if (errno == 0) {
|
||||||
|
skipread[part ^ 1] = (cmd == &cmd_copy) |
|
||||||
|
(cmd == &cmd_setchecksum) | (cmd == &cmd_brick);
|
||||||
readGbeFile(&fd, FILENAME, flags, nr);
|
readGbeFile(&fd, FILENAME, flags, nr);
|
||||||
|
|
||||||
if (strMac != NULL)
|
if (strMac != NULL)
|
||||||
cmd_setmac(strMac); /* nvm gbe.bin setmac */
|
cmd_setmac(strMac); /* nvm gbe.bin setmac */
|
||||||
else if (cmd != NULL)
|
else if (cmd != NULL)
|
||||||
(*cmd)(); /* all other commands except setmac */
|
(*cmd)(); /* all other commands except setmac */
|
||||||
|
|
||||||
writeGbeFile(&fd, FILENAME, nr);
|
writeGbeFile(&fd, FILENAME, nr);
|
||||||
|
}
|
||||||
|
|
||||||
if ((errno != 0) && (cmd != &cmd_dump))
|
if ((errno != 0) && (cmd != &cmd_dump))
|
||||||
err(errno, NULL);
|
err(errno, NULL);
|
||||||
|
|
Loading…
Reference in New Issue