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

Function cbfstool_convert_fsp

util/cbfstool/cbfstool.c:1145–1206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1143}
1144
1145static int cbfstool_convert_fsp(struct buffer *buffer,
1146 uint32_t *offset, struct cbfs_file *header)
1147{
1148 uint32_t address;
1149 struct buffer fsp;
1150
1151 /*
1152 * There are 4 different cases here:
1153 *
1154 * 1. --xip and --base-address: we need to place the binary at the given base address
1155 * in the CBFS image and relocate it to that address. *offset was already filled in,
1156 * but we need to convert it to the host address space for relocation.
1157 *
1158 * 2. --xip but no --base-address: we implicitly force a 4K minimum alignment so that
1159 * relocation can occur. Call do_cbfs_locate() here to find an appropriate *offset.
1160 * This also needs to be converted to the host address space for relocation.
1161 *
1162 * 3. No --xip but a --base-address: special case where --base-address does not have its
1163 * normal meaning, instead we use it as the relocation target address. We explicitly
1164 * reset *offset to 0 so that the file will be placed wherever it fits in CBFS.
1165 *
1166 * 4. No --xip and no --base-address: this means that the FSP was pre-linked and should
1167 * not be relocated. Just chain directly to convert_raw() for compression.
1168 */
1169
1170 if (param.stage_xip) {
1171 if (!param.baseaddress_assigned) {
1172 param.alignment = 4*1024;
1173 if (do_cbfs_locate(offset, buffer_size(buffer)))
1174 return -1;
1175 }
1176 assert(!IS_HOST_SPACE_ADDRESS(*offset));
1177 address = convert_addr_space(param.image_region, *offset);
1178 } else {
1179 if (param.baseaddress_assigned == 0) {
1180 INFO("Honoring pre-linked FSP module, no relocation.\n");
1181 return cbfstool_convert_raw(buffer, offset, header);
1182 } else {
1183 address = param.baseaddress;
1184 *offset = 0;
1185 }
1186 }
1187
1188 /* Create a copy of the buffer to attempt relocation. */
1189 if (buffer_create(&fsp, buffer_size(buffer), "fsp"))
1190 return -1;
1191
1192 memcpy(buffer_get(&fsp), buffer_get(buffer), buffer_size(buffer));
1193
1194 /* Replace the buffer contents w/ the relocated ones on success. */
1195 if (fsp_component_relocate(address, buffer_get(&fsp), buffer_size(&fsp))
1196 > 0) {
1197 buffer_delete(buffer);
1198 buffer_clone(buffer, &fsp);
1199 } else {
1200 buffer_delete(&fsp);
1201 WARN("Invalid FSP variant.\n");
1202 }

Callers

nothing calls this directly

Calls 10

do_cbfs_locateFunction · 0.85
buffer_sizeFunction · 0.85
convert_addr_spaceFunction · 0.85
cbfstool_convert_rawFunction · 0.85
buffer_createFunction · 0.85
buffer_getFunction · 0.85
fsp_component_relocateFunction · 0.85
buffer_deleteFunction · 0.85
buffer_cloneFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected