diff options
author | Sergii Dmytruk <sergii.dmytruk@3mdeb.com> | 2023-11-17 19:31:20 +0200 |
---|---|---|
committer | Martin L Roth <gaumless@gmail.com> | 2024-03-09 23:22:55 +0000 |
commit | 04bd9651435843ce4b03c9717f2965fe344fe5cc (patch) | |
tree | 0193502b26818c738206a60862c689485d533a50 /util/smmstoretool/storage.c | |
parent | 7a51acfbe91c7f9d01837103341526abb6ea46f4 (diff) |
util: add smmstoretool for editing SMMSTORE
Offline SMMSTORE variable modification tool. Can be used to
pre-configure ROM image or debug EFI state stored in a dump.
Change-Id: I6c1c06f1d0c39c13b5be76a3070f09b715aca6e0
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79080
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Diffstat (limited to 'util/smmstoretool/storage.c')
-rw-r--r-- | util/smmstoretool/storage.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/util/smmstoretool/storage.c b/util/smmstoretool/storage.c new file mode 100644 index 0000000000..abc6840b67 --- /dev/null +++ b/util/smmstoretool/storage.c @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "storage.h" + +#include <assert.h> +#include <stdio.h> + +#include "fv.h" +#include "utils.h" + +bool storage_open(const char store_file[], struct storage_t *storage, bool rw) +{ + storage->rw = rw; + + storage->file = map_file(store_file, rw); + if (storage->file.start == NULL) { + fprintf(stderr, "Failed to load smm-store-file \"%s\"\n", + store_file); + return false; + } + + bool auth_vars; + if (!fv_parse(storage->file, &storage->store_area, &auth_vars)) { + if (!rw) { + fprintf(stderr, + "Failed to find variable store in \"%s\"\n", + store_file); + goto error; + } + + if (!fv_init(storage->file)) { + fprintf(stderr, + "Failed to create variable store in \"%s\"\n", + store_file); + goto error; + } + + if (!fv_parse(storage->file, &storage->store_area, &auth_vars)) { + fprintf(stderr, + "Failed to parse newly formatted store in \"%s\"\n", + store_file); + goto error; + } + + fprintf(stderr, + "Successfully created variable store in \"%s\"\n", + store_file); + } + + storage->vs = vs_load(storage->store_area, auth_vars); + return true; + +error: + unmap_file(storage->file); + return false; +} + +bool storage_write_back(struct storage_t *storage) +{ + assert(storage->rw && "Only RW storage can be updated."); + + bool success = vs_store(&storage->vs, storage->store_area); + if (!success) + fprintf(stderr, "Failed to update variable store\n"); + storage_drop(storage); + return success; +} + +void storage_drop(struct storage_t *storage) +{ + unmap_file(storage->file); + vs_free(&storage->vs); +} |