MCPcopy Create free account
hub / github.com/coreboot/coreboot / storage_open

Function storage_open

util/smmstoretool/storage.c:14–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "utils.h"
13
14bool storage_open(const char store_file[], struct storage_t *storage, bool rw)
15{
16 storage->rw = rw;
17
18 storage->file = map_file(store_file, rw);
19 if (storage->file.start == NULL) {
20 fprintf(stderr, "Failed to load smm-store-file \"%s\"\n",
21 store_file);
22 return false;
23 }
24
25 /* If we won't find FMAP with SMMSTORE, use the whole file, but fail if
26 * FMAP is there without SMMSTORE. */
27 storage->region = storage->file;
28
29 long fmap_offset = fmap_find(storage->file.start, storage->file.length);
30 if (fmap_offset >= 0) {
31 struct fmap *fmap = (void *)(storage->file.start + fmap_offset);
32 const struct fmap_area *area = fmap_find_area(fmap, "SMMSTORE");
33 if (area == NULL) {
34 fprintf(stderr,
35 "Found FMAP without SMMSTORE in \"%s\"\n",
36 store_file);
37 return false;
38 }
39
40 storage->region.start += area->offset;
41 storage->region.length = area->size;
42 }
43
44 bool is_auth_var_store;
45 if (!fv_parse(storage->region, &storage->store_area, &is_auth_var_store)) {
46 if (!rw) {
47 fprintf(stderr,
48 "Failed to find variable store in \"%s\"\n",
49 store_file);
50 goto error;
51 }
52
53 fprintf(stderr,
54 "\nThe variable store has not been found in the ROM image\n"
55 "and is about to be initialized. This situation is normal\n"
56 "for a release image, as the variable store is usually\n"
57 "initialized on the first boot of the platform.\n\n");
58
59 if (!fv_init(storage->region)) {
60 fprintf(stderr,
61 "Failed to create variable store in \"%s\"\n",
62 store_file);
63 goto error;
64 }
65
66 if (!fv_parse(storage->region, &storage->store_area, &is_auth_var_store)) {
67 fprintf(stderr,
68 "Failed to parse newly formatted store in \"%s\"\n",
69 store_file);
70 goto error;
71 }

Callers 4

process_setFunction · 0.85
process_listFunction · 0.85
process_getFunction · 0.85
process_removeFunction · 0.85

Calls 8

fprintfFunction · 0.85
fmap_findFunction · 0.85
fv_parseFunction · 0.85
fv_initFunction · 0.85
vs_loadFunction · 0.85
map_fileFunction · 0.70
unmap_fileFunction · 0.70
fmap_find_areaFunction · 0.50

Tested by

no test coverage detected