summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2022-11-26 11:02:28 +0000
committerLeah Rowe <leah@libreboot.org>2022-11-26 11:03:04 +0000
commit0bbd4f1f262ed6b8eba131b62c941a6b2400763f (patch)
tree44bbee9608ea21c146a8cb914a94e45660def68e /util/nvmutil
parentb0f9f47e9a395ef6d67ca062b02e6d36c48eaffb (diff)
util/nvmutil: write gbe files in a function
in any C program, main() should not contain detailed logic. ideally, the main() function should only be a skeleton, showing the overall logic flow of the program. split writing gbe files into a separate function, to satisfy this criteria.
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index b3c9031b..f9e56090 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -42,6 +42,7 @@ int validChecksum(int partnum);
uint16_t word(int pos16, int partnum);
void setWord(int pos16, int partnum, uint16_t val);
void byteswap(uint8_t *byte);
+void writeGbeFile(int *fd, const char *filename);
#define FILENAME argv[1]
#define COMMAND argv[2]
@@ -60,7 +61,7 @@ uint8_t little_endian;
int
main(int argc, char *argv[])
{
- int fd, partnum;
+ int fd;
int flags = O_RDWR;
char *strMac = NULL;
char *strRMac = "??:??:??:??:??:??";
@@ -104,23 +105,8 @@ main(int argc, char *argv[])
else
cmd(COMMAND);
- if (gbeFileModified) {
- errno = 0;
- if (pwrite(fd, gbe, SIZE_8KB, 0) == SIZE_8KB)
- close(fd);
- if (errno == 0) {
- for (partnum = 0; partnum < 2; partnum++) {
- if (nvmPartModified[partnum])
- printf("Part %d modified\n",
- partnum);
- else
- fprintf (stderr, "Part %d NOT "
- "modified\n", partnum);
- }
- printf("File `%s` successfully "
- "modified\n", FILENAME);
- }
- }
+ if (gbeFileModified)
+ writeGbeFile(&fd, FILENAME);
}
nvmutil_exit:
@@ -132,6 +118,26 @@ nvmutil_exit:
return errno;
}
+void
+writeGbeFile(int *fd, const char *filename)
+{
+ int partnum;
+ errno = 0;
+
+ if (pwrite((*fd), gbe, SIZE_8KB, 0) == SIZE_8KB)
+ close((*fd));
+ if (errno == 0) {
+ for (partnum = 0; partnum < 2; partnum++) {
+ if (nvmPartModified[partnum])
+ printf("Part %d modified\n", partnum);
+ else
+ fprintf (stderr,
+ "Part %d NOT modified\n", partnum);
+ }
+ printf("File `%s` successfully modified\n", filename);
+ }
+}
+
ssize_t
readFromFile(int *fd, uint8_t *buf, const char *path, int flags, size_t size)
{