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

Function partitioned_file_create

util/cbfstool/partitioned_file.c:103–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103partitioned_file_t *partitioned_file_create(const char *filename,
104 struct buffer *flashmap)
105{
106 assert(filename);
107 assert(flashmap);
108 assert(flashmap->data);
109
110 if (fmap_find((const uint8_t *)flashmap->data, flashmap->size) != 0) {
111 ERROR("Attempted to create a partitioned image out of something that isn't an FMAP\n");
112 return NULL;
113 }
114 struct fmap *bootstrap_fmap = (struct fmap *)flashmap->data;
115
116 const struct fmap_area *fmap_area =
117 fmap_find_area(bootstrap_fmap, SECTION_NAME_FMAP);
118 if (!fmap_area) {
119 ERROR("Provided FMAP missing '%s' region\n", SECTION_NAME_FMAP);
120 return NULL;
121 }
122
123 if (count_selected_fmap_entries(bootstrap_fmap,
124 partitioned_file_fmap_select_children_of, fmap_area)) {
125 ERROR("Provided FMAP's '%s' region contains other regions\n",
126 SECTION_NAME_FMAP);
127 return NULL;
128 }
129
130 int fmap_len = fmap_size(bootstrap_fmap);
131 if (fmap_len < 0) {
132 ERROR("Unable to determine size of provided FMAP\n");
133 return NULL;
134 }
135 assert((size_t)fmap_len <= flashmap->size);
136 if ((uint32_t)fmap_len > fmap_area->size) {
137 ERROR("Provided FMAP's '%s' region needs to be at least %d bytes\n",
138 SECTION_NAME_FMAP, fmap_len);
139 return NULL;
140 }
141
142 partitioned_file_t *file = partitioned_file_create_flat(filename,
143 bootstrap_fmap->size);
144 if (!file)
145 return NULL;
146
147 struct buffer fmap_region;
148 buffer_splice(&fmap_region, &file->buffer, fmap_area->offset, fmap_area->size);
149 memcpy(fmap_region.data, bootstrap_fmap, fmap_len);
150 if (!partitioned_file_write_region(file, &fmap_region)) {
151 partitioned_file_close(file);
152 return NULL;
153 }
154 file->fmap = (struct fmap *)(file->buffer.data + fmap_area->offset);
155
156 return file;
157}
158
159partitioned_file_t *partitioned_file_reopen(const char *filename,
160 bool write_access)

Callers 1

mainFunction · 0.85

Calls 9

fmap_findFunction · 0.85
fmap_sizeFunction · 0.85
buffer_spliceFunction · 0.85
partitioned_file_closeFunction · 0.85
fmap_find_areaFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected