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