util/smmstoretool: allow for writing raw type variables from file

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 <krystian.hebel@3mdeb.com>
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
This commit is contained in:
Krystian Hebel
2025-07-11 20:17:45 +02:00
committed by Michał Żygowski
parent 66dfd8bc70
commit 353cf69892
2 changed files with 18 additions and 4 deletions
+17 -2
View File
@@ -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;
+1 -2
View File
@@ -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)