From 353cf69892f81da054b52810db32ee3fcdda351e Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Fri, 11 Jul 2025 20:17:45 +0200 Subject: [PATCH] util/smmstoretool: allow for writing raw type variables from file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some variables can't be described using any of the predefined types. Allow passing their values from a file. Upstream-Status: Pending Change-Id: Idb03e8dbdbdd446cc16cae584640cf1641ecc2c1 Signed-off-by: Krystian Hebel Signed-off-by: Michał Żygowski --- util/smmstoretool/data.c | 19 +++++++++++++++++-- util/smmstoretool/main.c | 3 +-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/util/smmstoretool/data.c b/util/smmstoretool/data.c index 5eca5f6a81..42931be2cb 100644 --- a/util/smmstoretool/data.c +++ b/util/smmstoretool/data.c @@ -120,6 +120,7 @@ void *make_data(const char source[], size_t *data_size, enum data_type type) uint64_t uint; struct mem_range_t file; bool failed; + FILE *f; case DATA_TYPE_BOOL: if (str_eq(source, "true")) { @@ -188,8 +189,22 @@ void *make_data(const char source[], size_t *data_size, enum data_type type) unmap_file(file); return data; case DATA_TYPE_RAW: - fprintf(stderr, "Raw data type is output only\n"); - return NULL; + f = fopen(source, "rb"); + if (!f) { + perror(source); + return NULL; + } + fseek(f, 0, SEEK_END); + *data_size = ftell(f); + fseek(f, 0, SEEK_SET); + data = xmalloc(*data_size); + if (fread(data, 1, *data_size, f) != *data_size) { + fprintf(stderr, "Error reading data from '%s', aborting\n", source); + free(data); + data = NULL; + } + fclose(f); + return data; } return NULL; diff --git a/util/smmstoretool/main.c b/util/smmstoretool/main.c index 7a5de9b9ce..673620cbe2 100644 --- a/util/smmstoretool/main.c +++ b/util/smmstoretool/main.c @@ -128,8 +128,7 @@ static void print_types(FILE *f) fprintf(f, " * uint64 (0..2^64-1)\n"); fprintf(f, " * ascii (NUL-terminated)\n"); fprintf(f, " * unicode (widened and NUL-terminated)\n"); - fprintf(f, " * file (input only; file contents as variable)\n"); - fprintf(f, " * raw (output only; raw bytes on output)\n"); + fprintf(f, " * raw (file name on input; raw bytes on output)\n"); } static void help_set(FILE *f, const struct subcommand_t *info)