blob: ecbadaae75cfb609f3dc8ddf50bd7648d04d201a [file] [log] [blame]
Simon Glass466c7852019-12-06 21:42:18 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 Google LLC
4 */
5
Simon Glass466c7852019-12-06 21:42:18 -07006#include <binman.h>
7#include <binman_sym.h>
Simon Glass1ea97892020-05-10 11:40:00 -06008#include <bootstage.h>
Simon Glass466c7852019-12-06 21:42:18 -07009#include <cbfs.h>
10#include <dm.h>
Simon Glassfc557362022-03-04 08:43:05 -070011#include <event.h>
Simon Glass466c7852019-12-06 21:42:18 -070012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass466c7852019-12-06 21:42:18 -070014#include <spi.h>
15#include <spl.h>
16#include <spi_flash.h>
17#include <asm/intel_pinctrl.h>
18#include <dm/uclass-internal.h>
19#include <asm/fsp2/fsp_internal.h>
20
Simon Glassb8357c12023-08-21 21:16:56 -060021int fsp_setup_pinctrl(void)
Simon Glass466c7852019-12-06 21:42:18 -070022{
23 struct udevice *dev;
24 ofnode node;
25 int ret;
26
27 /* Make sure pads are set up early in U-Boot */
Simon Glassd89c4a32020-04-26 09:12:53 -060028 if (!ll_boot_init() || spl_phase() != PHASE_BOARD_F)
Simon Glass466c7852019-12-06 21:42:18 -070029 return 0;
30
31 /* Probe all pinctrl devices to set up the pads */
32 ret = uclass_first_device_err(UCLASS_PINCTRL, &dev);
33 if (ret)
34 return log_msg_ret("no fsp pinctrl", ret);
35 node = ofnode_path("fsp");
36 if (!ofnode_valid(node))
37 return log_msg_ret("no fsp params", -EINVAL);
38 ret = pinctrl_config_pads_for_node(dev, node);
39 if (ret)
40 return log_msg_ret("pad config", ret);
41
42 return ret;
43}
Simon Glassb8357c12023-08-21 21:16:56 -060044EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, fsp_setup_pinctrl);
Simon Glass466c7852019-12-06 21:42:18 -070045
46#if !defined(CONFIG_TPL_BUILD)
47binman_sym_declare(ulong, intel_fsp_m, image_pos);
48binman_sym_declare(ulong, intel_fsp_m, size);
49
50/**
51 * get_cbfs_fsp() - Obtain the FSP by looking up in CBFS
52 *
53 * This looks up an FSP in a CBFS. It is used mostly for testing, when booting
54 * U-Boot from a hybrid image containing coreboot as the first-stage bootloader.
55 *
56 * The typical use for this feature is when building a Chrome OS image which
57 * includes coreboot in it. By adding U-Boot into the 'COREBOOT' CBFS as well,
58 * it is possible to make coreboot chain-load U-Boot. Thus the initial stages of
59 * the SoC init can be done by coreboot and the later stages by U-Boot. This is
60 * a convenient way to start the porting work. The jump to U-Boot can then be
61 * moved progressively earlier and earlier, until U-Boot takes over all the init
62 * and you have a native port.
63 *
64 * This function looks up a CBFS at a known location and reads the FSP-M from it
65 * so that U-Boot can init the memory.
66 *
67 * This function is not used in the normal boot but is kept here for future
68 * development.
69 *
70 * @type; Type to look up (only FSP_M supported at present)
71 * @map_base: Base memory address for mapped SPI
72 * @entry: Returns an entry containing the position of the FSP image
73 */
74static int get_cbfs_fsp(enum fsp_type_t type, ulong map_base,
75 struct binman_entry *entry)
76{
77 /*
78 * Use a hard-coded position of CBFS in the ROM for now. It would be
79 * possible to read the position using the FMAP in the ROM, but since
80 * this code is only used for development, it doesn't seem worth it.
81 * Use the 'cbfstool <image> layout' command to get these values, e.g.:
82 * 'COREBOOT' (CBFS, size 1814528, offset 2117632).
83 */
84 ulong cbfs_base = 0x205000;
Simon Glass466c7852019-12-06 21:42:18 -070085 struct cbfs_priv *cbfs;
86 int ret;
87
Simon Glass94649092021-03-15 18:00:12 +130088 ret = cbfs_init_mem(map_base + cbfs_base, CBFS_SIZE_UNKNOWN, true,
89 &cbfs);
Simon Glass466c7852019-12-06 21:42:18 -070090 if (ret)
91 return ret;
92 if (!ret) {
93 const struct cbfs_cachenode *node;
94
95 node = cbfs_find_file(cbfs, "fspm.bin");
96 if (!node)
97 return log_msg_ret("fspm node", -ENOENT);
98
99 entry->image_pos = (ulong)node->data;
100 entry->size = node->data_length;
101 }
102
103 return 0;
104}
105
106int fsp_locate_fsp(enum fsp_type_t type, struct binman_entry *entry,
107 bool use_spi_flash, struct udevice **devp,
108 struct fsp_header **hdrp, ulong *rom_offsetp)
109{
110 ulong mask = CONFIG_ROM_SIZE - 1;
111 struct udevice *dev;
112 ulong rom_offset = 0;
113 uint map_size;
114 ulong map_base;
115 uint offset;
116 int ret;
117
118 /*
119 * Find the devices but don't probe them, since we don't want to
120 * auto-config PCI before silicon init runs
121 */
122 ret = uclass_find_first_device(UCLASS_NORTHBRIDGE, &dev);
123 if (ret)
124 return log_msg_ret("Cannot get northbridge", ret);
125 if (!use_spi_flash) {
126 struct udevice *sf;
127
128 /* Just use the SPI driver to get the memory map */
129 ret = uclass_find_first_device(UCLASS_SPI_FLASH, &sf);
130 if (ret)
131 return log_msg_ret("Cannot get SPI flash", ret);
132 ret = dm_spi_get_mmap(sf, &map_base, &map_size, &offset);
133 if (ret)
134 return log_msg_ret("Could not get flash mmap", ret);
135 }
136
137 if (spl_phase() >= PHASE_BOARD_F) {
138 if (type != FSP_S)
139 return -EPROTONOSUPPORT;
140 ret = binman_entry_find("intel-fsp-s", entry);
141 if (ret)
142 return log_msg_ret("binman entry", ret);
143 if (!use_spi_flash)
144 rom_offset = (map_base & mask) - CONFIG_ROM_SIZE;
145 } else {
146 ret = -ENOENT;
147 if (false)
148 /*
149 * Support using a hybrid image build by coreboot. See
150 * the function comments for details
151 */
152 ret = get_cbfs_fsp(type, map_base, entry);
153 if (ret) {
154 ulong mask = CONFIG_ROM_SIZE - 1;
155
156 if (type != FSP_M)
157 return -EPROTONOSUPPORT;
158 entry->image_pos = binman_sym(ulong, intel_fsp_m,
159 image_pos);
160 entry->size = binman_sym(ulong, intel_fsp_m, size);
161 if (entry->image_pos != BINMAN_SYM_MISSING) {
162 ret = 0;
163 if (use_spi_flash)
164 entry->image_pos &= mask;
165 else
166 entry->image_pos += (map_base & mask);
167 } else {
168 ret = -ENOENT;
169 }
170 }
171 }
172 if (ret)
173 return log_msg_ret("Cannot find FSP", ret);
174 entry->image_pos += rom_offset;
175
176 /*
177 * Account for the time taken to read memory-mapped SPI flash since in
178 * this case we don't use the SPI driver and BOOTSTAGE_ID_ACCUM_SPI.
179 */
180 if (!use_spi_flash)
181 bootstage_start(BOOTSTAGE_ID_ACCUM_MMAP_SPI, "mmap_spi");
182 ret = fsp_get_header(entry->image_pos, entry->size, use_spi_flash,
183 hdrp);
184 if (!use_spi_flash)
185 bootstage_accum(BOOTSTAGE_ID_ACCUM_MMAP_SPI);
186 if (ret)
187 return log_msg_ret("fsp_get_header", ret);
188 *devp = dev;
189 if (rom_offsetp)
190 *rom_offsetp = rom_offset;
191
192 return 0;
193}
194#endif