summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-03 13:44:04 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-03 13:44:04 +0100
commit270693fc92e84b264c160b64e6c66ea4196760a7 (patch)
tree462ebd117d816ad1831b7586a647494e8d487a93 /util/nvmutil
parent46a9eea0f6d05761c38ab640b3919e8e1b6a3f70 (diff)
util/nvmutil: cleanup: move logic out of main()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 19b1d977..69cf929a 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -17,9 +17,6 @@ main(int argc, char *argv[])
err_if((errno = (!((part = PARTNUM[0] - '0') == 0 || part == 1))
|| PARTNUM[1] ? EINVAL : errno));
err_if((errno = (!cmd) ? EINVAL : errno));
-
- nf = ((cmd == cmd_swap) || (cmd == cmd_copy)) ? SIZE_4KB : nf;
- flags = (strcmp(COMMAND, "dump") == 0) ? O_RDONLY : flags;
openFiles(FILENAME);
readGbeFile(FILENAME);
@@ -34,7 +31,7 @@ void
openFiles(const char *path)
{
struct stat st;
- xopen(fd, path, flags);
+ xopen(fd, path, flags = (cmd == cmd_dump) ? O_RDONLY : flags);
if ((st.st_size != SIZE_8KB))
err(errno = ECANCELED, "File `%s` not 8KiB", path);
xopen(rfd, "/dev/urandom", O_RDONLY);
@@ -48,6 +45,7 @@ openFiles(const char *path)
void
readGbeFile(const char *path)
{
+ nf = ((cmd == cmd_swap) || (cmd == cmd_copy)) ? SIZE_4KB : nf;
skipread[part ^ 1] = (cmd == &cmd_copy) | (cmd == &cmd_setchecksum)
| (cmd == &cmd_brick);
gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB;