summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-09 21:59:34 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-09 22:18:51 +0000
commit1e45d19f5d2507fc6cfc01e98024fe55c5da060a (patch)
treecae39c933e437647e26ca7f3a362266ed3f32c9b /util
parent7d64b8ea8daec489dcf9dead62eab29758d42af4 (diff)
util/nvmutil: added a "cat" command
with this, you can read 16KB and 128KB files, and output them to stdout, but it outputs 8KB for example: ./nvmutil gbe128.bin > gbe8.bin now you have a 8KB file i could probably easily add cat16 and cat128 too. nvmutil reads two 4KB parts regardless of GbE file size (one from the first 4KB of each half of the file), so this was easy to implement. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 620fe00e..7cd300db 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -120,6 +120,7 @@ static void write_mac_part(size_t partnum);
static void cmd_helper_dump(void);
static void print_mac_from_nvm(size_t partnum);
static void hexdump(size_t partnum);
+static void cmd_helper_cat(void);
static void write_gbe_file(void);
static void override_part_modified(void);
static void set_checksum(size_t part);
@@ -236,6 +237,7 @@ enum {
CMD_SETMAC,
CMD_SWAP,
CMD_COPY,
+ CMD_CAT
};
/*
@@ -316,6 +318,12 @@ static const struct commands command[] = {
ARG_PART,
CHECKSUM_READ, SKIP_CHECKSUM_WRITE,
GBE_PART_SIZE },
+
+ { CMD_CAT, "cat", cmd_helper_cat, ARGC_3,
+ NO_INVERT, SET_MOD_OFF,
+ ARG_NOPART,
+ SKIP_CHECKSUM_READ, SKIP_CHECKSUM_WRITE,
+ GBE_PART_SIZE },
};
#define MAX_CMD_LEN 50
@@ -694,9 +702,6 @@ read_gbe_file_part(size_t p)
if (rc != (ssize_t)gbe_rw_size)
err(ECANCELED, "%s: Partial read from p%zu", fname, p);
-
- printf("%s: Read %zu bytes from p%zu\n",
- fname, gbe_rw_size, p);
}
static ssize_t
@@ -1084,6 +1089,19 @@ hexdump(size_t partnum)
}
static void
+cmd_helper_cat(void)
+{
+ size_t wc = 0;
+ ssize_t w;
+
+ fflush(NULL);
+
+ for (wc = 0; wc < sizeof(buf); wc += w)
+ if ((w = write(STDOUT_FILENO, buf + wc, sizeof(buf) - wc)) < 1)
+ err(EIO, "%s: stdout", fname);
+}
+
+static void
write_gbe_file(void)
{
size_t p;