From 1e45d19f5d2507fc6cfc01e98024fe55c5da060a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 9 Mar 2026 21:59:34 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 24 +++++++++++++++++++++--- 1 file 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 @@ -1083,6 +1088,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) { -- cgit v1.2.1