diff options
author | Leah Rowe <leah@libreboot.org> | 2025-01-27 18:40:44 +0000 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-01-27 18:40:44 +0000 |
commit | 3bb7520f6d921bb71fa8206387a52cef405a788c (patch) | |
tree | 46591c243def71e2e21296f2476c3baa9b94c6c2 | |
parent | d94b274fd9f4e7a4ef71e25832ab7baedf10bd50 (diff) |
util/nvmutil: do setmac if only filename given
./nvm gbe.bin
with this patch, the above example does the same as:
./nvm gbe.bin setmac
now you can simply specify the gbe file, and it will
randomise the mac address within it, and update the
nvm checksum word.
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r-- | util/nvmutil/nvmutil.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 16841427..6da8e64c 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -78,10 +78,12 @@ main(int argc, char *argv[]) err_if(pledge("stdio rpath wpath unveil", NULL) == -1); #endif - if (argc < 3) { /* TODO: manpage! */ + if (argc < 2) { /* TODO: manpage! */ fprintf(stderr, "Modify Intel GbE NVM images e.g. set MAC\n"); fprintf(stderr, "USAGE:\n"); fprintf(stderr, " %s FILE dump\n", argv[0]); + fprintf(stderr, " %s FILE\n # does same as setmac without arg", + argv[0]); fprintf(stderr, " %s FILE setmac [MAC]\n", argv[0]); fprintf(stderr, " %s FILE swap\n", argv[0]); fprintf(stderr, " %s FILE copy 0|1\n", argv[0]); @@ -92,14 +94,16 @@ main(int argc, char *argv[]) filename = argv[1]; - if (strcmp(COMMAND, "dump") == 0) { - flags = O_RDONLY; /* write not needed for dump cmd */ + flags = O_RDWR; + + if (argc > 2) { + if (strcmp(COMMAND, "dump") == 0) { + flags = O_RDONLY; /* write not needed for dump cmd */ #ifdef __OpenBSD__ - /* writes not needed for the dump command */ - err_if(pledge("stdio rpath unveil", NULL) == -1); + /* writes not needed for the dump command */ + err_if(pledge("stdio rpath unveil", NULL) == -1); #endif - } else { - flags = O_RDWR; + } } /* check for dir first, to prevent unveil from @@ -129,14 +133,19 @@ main(int argc, char *argv[]) err_if(pledge("stdio", NULL) == -1); #endif - for (int i = 0; (i < 6) && (cmd == NULL); i++) { - if (strcmp(COMMAND, op[i].str) != 0) - continue; - if (argc >= op[i].args) { - cmd = op[i].cmd; - break; + if (argc > 2) { + for (int i = 0; (i < 6) && (cmd == NULL); i++) { + if (strcmp(COMMAND, op[i].str) != 0) + continue; + if (argc >= op[i].args) { + cmd = op[i].cmd; + break; + } + err(errno = EINVAL, "Too few args on command '%s'", + op[i].str); } - err(errno = EINVAL, "Too few args on command '%s'", op[i].str); + } else { + cmd = cmd_setmac; } if (cmd == cmd_setmac) { |