aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorSergii Dmytruk <sergii.dmytruk@3mdeb.com>2024-05-22 20:41:02 +0300
committerFelix Held <felix-coreboot@felixheld.de>2024-06-14 14:19:46 +0000
commitd20cc994ba78fa3b40b09ca6b6e21688a850ef01 (patch)
tree61f2a65cc766d103b7f4a61fac19b5e86da1136c /util
parentdd6c3b4a61b3f93c391cc460c50dca37cb32f7f0 (diff)
util/smmstoretool: add uint64 data type
It's in particular useful for working with variables that contain 64-bit pointers, like CapsuleUpdateData* global variables defined by UEFI specification. Change-Id: I4b46b41cdc5f69d4ca189659bef1e44f64c0d554 Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/82611 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Diffstat (limited to 'util')
-rw-r--r--util/smmstoretool/data.c46
-rw-r--r--util/smmstoretool/data.h1
-rw-r--r--util/smmstoretool/main.c7
3 files changed, 41 insertions, 13 deletions
diff --git a/util/smmstoretool/data.c b/util/smmstoretool/data.c
index 778bf8a6cb..41d3b75aba 100644
--- a/util/smmstoretool/data.c
+++ b/util/smmstoretool/data.c
@@ -57,6 +57,16 @@ void print_data(const uint8_t data[], size_t data_size, enum data_type type)
if (data_size >= 4)
printf("%u\n", *(uint32_t *)data);
break;
+ case DATA_TYPE_UINT64:
+ if (data_size != 8) {
+ fprintf(stderr,
+ "warning: expected size of 8, got %zu\n",
+ data_size);
+ }
+
+ if (data_size >= 8)
+ printf("%llu\n", (unsigned long long)*(uint64_t *)data);
+ break;
case DATA_TYPE_ASCII:
for (size_t i = 0; i < data_size; ++i) {
char c = data[i];
@@ -78,20 +88,24 @@ void print_data(const uint8_t data[], size_t data_size, enum data_type type)
static uint64_t parse_uint(const char source[],
const char type[],
- unsigned long long max)
+ unsigned long long max,
+ bool *failed)
{
char *end;
unsigned long long uint = strtoull(source, &end, /*base=*/0);
if (*end != '\0') {
fprintf(stderr, "Trailing characters in \"%s\": %s\n",
source, end);
- return UINT64_MAX;
+ *failed = true;
+ return 0;
}
if (uint > max) {
fprintf(stderr, "Invalid %s value: %llu\n", type, uint);
- return UINT64_MAX;
+ *failed = true;
+ return 0;
}
+ *failed = false;
return uint;
}
@@ -100,7 +114,8 @@ void *make_data(const char source[], size_t *data_size, enum data_type type)
switch (type) {
void *data;
bool boolean;
- unsigned long long uint;
+ uint64_t uint;
+ bool failed;
case DATA_TYPE_BOOL:
if (str_eq(source, "true")) {
@@ -118,8 +133,8 @@ void *make_data(const char source[], size_t *data_size, enum data_type type)
*(uint8_t *)data = boolean;
return data;
case DATA_TYPE_UINT8:
- uint = parse_uint(source, "uint8", UINT8_MAX);
- if (uint == UINT64_MAX)
+ uint = parse_uint(source, "uint8", UINT8_MAX, &failed);
+ if (failed)
return NULL;
*data_size = 1;
@@ -127,8 +142,8 @@ void *make_data(const char source[], size_t *data_size, enum data_type type)
*(uint8_t *)data = uint;
return data;
case DATA_TYPE_UINT16:
- uint = parse_uint(source, "uint16", UINT16_MAX);
- if (uint == UINT64_MAX)
+ uint = parse_uint(source, "uint16", UINT16_MAX, &failed);
+ if (failed)
return NULL;
*data_size = 2;
@@ -136,14 +151,23 @@ void *make_data(const char source[], size_t *data_size, enum data_type type)
*(uint16_t *)data = uint;
return data;
case DATA_TYPE_UINT32:
- uint = parse_uint(source, "uint32", UINT32_MAX);
- if (uint == UINT64_MAX)
+ uint = parse_uint(source, "uint32", UINT32_MAX, &failed);
+ if (failed)
return NULL;
*data_size = 4;
data = xmalloc(*data_size);
*(uint32_t *)data = uint;
return data;
+ case DATA_TYPE_UINT64:
+ uint = parse_uint(source, "uint64", UINT64_MAX, &failed);
+ if (failed)
+ return NULL;
+
+ *data_size = 8;
+ data = xmalloc(*data_size);
+ *(uint64_t *)data = uint;
+ return data;
case DATA_TYPE_ASCII:
*data_size = strlen(source) + 1;
return strdup(source);
@@ -167,6 +191,8 @@ bool parse_data_type(const char str[], enum data_type *type)
*type = DATA_TYPE_UINT16;
else if (str_eq(str, "uint32"))
*type = DATA_TYPE_UINT32;
+ else if (str_eq(str, "uint64"))
+ *type = DATA_TYPE_UINT64;
else if (str_eq(str, "ascii"))
*type = DATA_TYPE_ASCII;
else if (str_eq(str, "unicode"))
diff --git a/util/smmstoretool/data.h b/util/smmstoretool/data.h
index 13bd7bc4f4..58e6c7d7a6 100644
--- a/util/smmstoretool/data.h
+++ b/util/smmstoretool/data.h
@@ -12,6 +12,7 @@ enum data_type {
DATA_TYPE_UINT8,
DATA_TYPE_UINT16,
DATA_TYPE_UINT32,
+ DATA_TYPE_UINT64,
DATA_TYPE_ASCII,
DATA_TYPE_UNICODE,
DATA_TYPE_RAW,
diff --git a/util/smmstoretool/main.c b/util/smmstoretool/main.c
index f5228d69e1..89d58d619a 100644
--- a/util/smmstoretool/main.c
+++ b/util/smmstoretool/main.c
@@ -122,9 +122,10 @@ static void print_types(FILE *f)
{
fprintf(f, "Types and their values:\n");
fprintf(f, " * bool (true, false)\n");
- fprintf(f, " * uint8 (0-255)\n");
- fprintf(f, " * uint16 (0-65535)\n");
- fprintf(f, " * uint32 (0-4294967295)\n");
+ fprintf(f, " * uint8 (0..255)\n");
+ fprintf(f, " * uint16 (0..65535)\n");
+ fprintf(f, " * uint32 (0..4294967295)\n");
+ fprintf(f, " * uint64 (0..2^64-1)\n");
fprintf(f, " * ascii (NUL-terminated)\n");
fprintf(f, " * unicode (widened and NUL-terminated)\n");
fprintf(f, " * raw (output only; raw bytes on output)\n");