• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <cbfs.h>
5 #include <cbmem.h>
6 #include <commonlib/fsp.h>
7 #include <fsp/util.h>
8 
fsp_relocate(struct prog * fsp_relocd)9 int fsp_relocate(struct prog *fsp_relocd)
10 {
11 	void *fih;
12 	ssize_t fih_offset;
13 	size_t size;
14 
15 	void *new_loc = cbfs_cbmem_alloc(prog_name(fsp_relocd),
16 					 CBMEM_ID_REFCODE, &size);
17 	if (new_loc == NULL) {
18 		printk(BIOS_ERR, "Unable to load FSP into memory.\n");
19 		return -1;
20 	}
21 
22 	fih_offset = fsp1_1_relocate((uintptr_t)new_loc, new_loc, size);
23 
24 	if (fih_offset <= 0) {
25 		printk(BIOS_ERR, "FSP relocation failure.\n");
26 		return -1;
27 	}
28 
29 	fih = (void *)((uint8_t *)new_loc + fih_offset);
30 
31 	prog_set_area(fsp_relocd, new_loc, size);
32 	prog_set_entry(fsp_relocd, fih, NULL);
33 
34 	return 0;
35 }
36