blob: 2c10171359cf36b3baa0e015643459e14038e2d1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Patrick Delaunaydafa84d2018-03-09 18:28:12 +01002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * Copy the startup prototype, previously defined in common.h
7 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunaydafa84d2018-03-09 18:28:12 +01008 */
9
10#ifndef __INIT_H_
11#define __INIT_H_ 1
12
13#ifndef __ASSEMBLY__ /* put C only stuff in this section */
14
Simon Glass401d1c42020-10-30 21:38:53 -060015#include <linux/types.h>
16
Simon Glass90794862021-12-29 11:57:43 -070017/*
18 * In case of the EFI app the UEFI firmware provides the low-level
19 * initialisation.
20 */
21#ifdef CONFIG_EFI
Simon Glass35a3f872019-12-28 10:44:56 -070022#define ll_boot_init() false
23#else
Simon Glass401d1c42020-10-30 21:38:53 -060024#include <asm/global_data.h>
25
Simon Glassba974a02020-04-26 09:12:57 -060026#define ll_boot_init() (!(gd->flags & GD_FLG_SKIP_LL_INIT))
Simon Glass35a3f872019-12-28 10:44:56 -070027#endif
28
Patrick Delaunaydafa84d2018-03-09 18:28:12 +010029/*
30 * Function Prototypes
31 */
32
33/* common/board_f.c */
Patrick Delaunayd6f87712018-03-13 13:57:00 +010034void board_init_f(ulong dummy);
Patrick Delaunaydafa84d2018-03-09 18:28:12 +010035
36/**
37 * arch_cpu_init() - basic cpu-dependent setup for an architecture
38 *
39 * This is called after early malloc is available. It should handle any
40 * CPU- or SoC- specific init needed to continue the init sequence. See
41 * board_f.c for where it is called. If this is not provided, a default
42 * version (which does nothing) will be used.
43 *
Mario Sixdc145a72018-08-06 10:23:40 +020044 * Return: 0 on success, otherwise error
Patrick Delaunaydafa84d2018-03-09 18:28:12 +010045 */
46int arch_cpu_init(void);
47
48/**
49 * mach_cpu_init() - SoC/machine dependent CPU setup
50 *
51 * This is called after arch_cpu_init(). It should handle any
52 * SoC or machine specific init needed to continue the init sequence. See
53 * board_f.c for where it is called. If this is not provided, a default
54 * version (which does nothing) will be used.
55 *
Mario Sixdc145a72018-08-06 10:23:40 +020056 * Return: 0 on success, otherwise error
Patrick Delaunaydafa84d2018-03-09 18:28:12 +010057 */
58int mach_cpu_init(void);
59
Patrick Delaunayd6f87712018-03-13 13:57:00 +010060/**
Simon Glassfe08d392019-12-06 21:42:20 -070061 * arch_fsp_init() - perform post-relocation firmware support package init
62 *
63 * Where U-Boot relies on binary blobs to handle part of the system init, this
64 * function can be used to set up the blobs. This is used on some Intel
65 * platforms.
66 *
67 * Return: 0
68 */
69int arch_fsp_init_r(void);
70
Patrick Delaunayd6f87712018-03-13 13:57:00 +010071int dram_init(void);
72
73/**
74 * dram_init_banksize() - Set up DRAM bank sizes
75 *
76 * This can be implemented by boards to set up the DRAM bank information in
77 * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
78 * is called.
79 *
80 * If this is not provided, a default implementation will try to set up a
81 * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
Tom Riniaa6e94d2022-11-16 13:10:37 -050082 * CFG_SYS_SDRAM_BASE are set. The bank will have a start address of
83 * CFG_SYS_SDRAM_BASE and the size will be determined by a call to
Patrick Delaunayd6f87712018-03-13 13:57:00 +010084 * get_effective_memsize().
85 *
Mario Sixdc145a72018-08-06 10:23:40 +020086 * Return: 0 if OK, -ve on error
Patrick Delaunayd6f87712018-03-13 13:57:00 +010087 */
88int dram_init_banksize(void);
89
Simon Glass9b4a2052019-12-28 10:45:05 -070090long get_ram_size(long *base, long size);
91phys_size_t get_effective_memsize(void);
92
Simon Glass49acd562019-12-28 10:45:06 -070093int testdram(void);
94
Patrick Delaunayd6f87712018-03-13 13:57:00 +010095/**
Ovidiu Panaitd63fc992022-09-13 21:31:28 +030096 * arch_setup_dest_addr() - Fix up initial reloc address
97 *
98 * This is called in generic board init sequence in common/board_f.c at the end
99 * of the setup_dest_addr() initcall. Each architecture could provide this
100 * function to make adjustments to the initial reloc address.
101 *
102 * If an implementation is not provided, it will just be a nop stub.
103 *
104 * Return: 0 if OK
105 */
106int arch_setup_dest_addr(void);
107
108/**
Mario Sixdc145a72018-08-06 10:23:40 +0200109 * arch_reserve_stacks() - Reserve all necessary stacks
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100110 *
111 * This is used in generic board init sequence in common/board_f.c. Each
112 * architecture could provide this function to tailor the required stacks.
113 *
114 * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
115 * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
116 * require only this can leave it untouched.
117 *
118 * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
119 * positions of the stack. The stack pointer(s) will be set to this later.
120 * gd->irq_sp is only required, if the architecture needs it.
121 *
Mario Sixdc145a72018-08-06 10:23:40 +0200122 * Return: 0 if no error
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100123 */
124int arch_reserve_stacks(void);
125
Patrick Delaunayb8aa55c2018-03-13 13:57:04 +0100126/**
Ovidiu Panait79926e42020-03-29 20:57:41 +0300127 * arch_reserve_mmu() - Reserve memory for MMU TLB table
128 *
129 * Architecture-specific routine for reserving memory for the MMU TLB table.
130 * This is used in generic board init sequence in common/board_f.c.
131 *
132 * If an implementation is not provided, it will just be a nop stub.
133 *
134 * Return: 0 if OK
135 */
136int arch_reserve_mmu(void);
137
138/**
Ovidiu Panait81e7cb12020-07-24 14:12:15 +0300139 * arch_setup_bdinfo() - Architecture dependent boardinfo setup
140 *
141 * Architecture-specific routine for populating various boardinfo fields of
142 * gd->bd. It is called during the generic board init sequence.
143 *
144 * If an implementation is not provided, it will just be a nop stub.
145 *
146 * Return: 0 if OK
147 */
148int arch_setup_bdinfo(void);
149
150/**
Ovidiu Panaitba743102020-07-24 14:12:14 +0300151 * setup_bdinfo() - Generic boardinfo setup
152 *
153 * Routine for populating various generic boardinfo fields of
154 * gd->bd. It is called during the generic board init sequence.
155 *
156 * Return: 0 if OK
157 */
158int setup_bdinfo(void);
159
Dzmitry Sankouski12a3e1a2022-02-22 21:49:52 +0300160#if defined(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
161defined(CONFIG_SAVE_PREV_BL_FDT_ADDR)
162/**
163 * save_prev_bl_data - Save prev bl data in env vars.
164 *
165 * When u-boot is chain-loaded, save previous bootloader data,
166 * like initramfs address to environment variables.
167 *
168 * Return: 0 if ok; -ENODATA on error
169 */
170int save_prev_bl_data(void);
Caleb Connollyca84ba62024-02-26 17:26:05 +0000171
172/**
173 * get_prev_bl_fdt_addr - When u-boot is chainloaded, get the address
174 * of the FDT passed by the previous bootloader.
175 *
176 * Return: the address of the FDT passed by the previous bootloader
177 * or 0 if not found.
178 */
179phys_addr_t get_prev_bl_fdt_addr(void);
180#else
181#define get_prev_bl_fdt_addr() 0LLU
Dzmitry Sankouski12a3e1a2022-02-22 21:49:52 +0300182#endif
183
Ovidiu Panaitba743102020-07-24 14:12:14 +0300184/**
Ovidiu Panaitfb504b22020-11-28 10:43:09 +0200185 * cpu_secondary_init_r() - CPU-specific secondary initialization
186 *
187 * After non-volatile devices, environment and cpu code are setup, have
188 * another round to deal with any initialization that might require
189 * full access to the environment or loading of some image (firmware)
190 * from a non-volatile device.
191 *
192 * It is called during the generic post-relocation init sequence.
193 *
194 * Return: 0 if OK
195 */
196int cpu_secondary_init_r(void);
197
198/**
Ovidiu Panaitc343e8c2020-11-28 10:43:11 +0200199 * pci_ep_init() - Initialize pci endpoint devices
200 *
201 * It is called during the generic post-relocation init sequence.
202 *
203 * Return: 0 if OK
204 */
205int pci_ep_init(void);
206
207/**
Ovidiu Panaitb9f6d0f2020-11-28 10:43:12 +0200208 * pci_init() - Enumerate pci devices
209 *
210 * It is called during the generic post-relocation init sequence to enumerate
211 * pci buses. This is needed, for instance, in the case of DM PCI-based
212 * Ethernet devices, which will not be detected without having the enumeration
213 * performed earlier.
214 *
215 * Return: 0 if OK
216 */
217int pci_init(void);
218
219/**
Patrick Delaunayb8aa55c2018-03-13 13:57:04 +0100220 * init_cache_f_r() - Turn on the cache in preparation for relocation
221 *
Mario Sixdc145a72018-08-06 10:23:40 +0200222 * Return: 0 if OK, -ve on error
Patrick Delaunayb8aa55c2018-03-13 13:57:04 +0100223 */
224int init_cache_f_r(void);
225
Mario Six5d6c61a2018-08-06 10:23:41 +0200226#if !CONFIG_IS_ENABLED(CPU)
227/**
228 * print_cpuinfo() - Display information about the CPU
229 *
230 * Return: 0 if OK, -ve on error
231 */
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100232int print_cpuinfo(void);
Mario Six5d6c61a2018-08-06 10:23:41 +0200233#endif
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100234int timer_init(void);
Mario Sixdc145a72018-08-06 10:23:40 +0200235
Patrick Delaunayd6f87712018-03-13 13:57:00 +0100236#if defined(CONFIG_DTB_RESELECT)
237int embedded_dtb_select(void);
238#endif
239
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100240/* common/init/board_init.c */
241extern ulong monitor_flash_len;
242
243/**
244 * ulong board_init_f_alloc_reserve - allocate reserved area
Mario Sixdc145a72018-08-06 10:23:40 +0200245 * @top: top of the reserve area, growing down.
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100246 *
247 * This function is called by each architecture very early in the start-up
248 * code to allow the C runtime to reserve space on the stack for writable
249 * 'globals' such as GD and the malloc arena.
250 *
Mario Sixdc145a72018-08-06 10:23:40 +0200251 * Return: bottom of reserved area
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100252 */
253ulong board_init_f_alloc_reserve(ulong top);
254
255/**
256 * board_init_f_init_reserve - initialize the reserved area(s)
Mario Sixdc145a72018-08-06 10:23:40 +0200257 * @base: top from which reservation was done
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100258 *
259 * This function is called once the C runtime has allocated the reserved
260 * area on the stack. It must initialize the GD at the base of that area.
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100261 */
262void board_init_f_init_reserve(ulong base);
263
Simon Glass67c4e9f2019-11-14 12:57:45 -0700264struct global_data;
265
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100266/**
267 * arch_setup_gd() - Set up the global_data pointer
Mario Sixdc145a72018-08-06 10:23:40 +0200268 * @gd_ptr: Pointer to global data
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100269 *
270 * This pointer is special in some architectures and cannot easily be assigned
271 * to. For example on x86 it is implemented by adding a specific record to its
272 * Global Descriptor Table! So we we provide a function to carry out this task.
273 * For most architectures this can simply be:
274 *
275 * gd = gd_ptr;
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100276 */
Simon Glass67c4e9f2019-11-14 12:57:45 -0700277void arch_setup_gd(struct global_data *gd_ptr);
Patrick Delaunay11f86cb2018-03-13 13:57:01 +0100278
Patrick Delaunaydafa84d2018-03-09 18:28:12 +0100279/* common/board_r.c */
Simon Glass67c4e9f2019-11-14 12:57:45 -0700280void board_init_r(struct global_data *id, ulong dest_addr)
281 __attribute__ ((noreturn));
Patrick Delaunaye2c219c2018-03-13 13:57:02 +0100282
283int cpu_init_r(void);
Patrick Delaunaye2c219c2018-03-13 13:57:02 +0100284int mac_read_from_eeprom(void);
Artur Rojekcd3dbb52023-10-18 16:00:56 +0200285
286/**
287 * serial_read_from_eeprom - read the serial number from EEPROM
288 *
289 * This function reads the serial number from the EEPROM and sets the
290 * appropriate environment variable.
291 *
292 * The environment variable is only set if it has not been set
293 * already. This ensures that any user-saved variables are never
294 * overwritten.
295 *
296 * This function must be called after relocation.
297 */
298int serial_read_from_eeprom(int devnum);
Patrick Delaunaye2c219c2018-03-13 13:57:02 +0100299int set_cpu_clk_info(void);
300int update_flash_size(int flash_size);
301int arch_early_init_r(void);
Patrick Delaunaye2c219c2018-03-13 13:57:02 +0100302int misc_init_r(void);
Patrick Delaunaye2c219c2018-03-13 13:57:02 +0100303
Patrick Delaunayfc22ee22018-03-13 13:57:03 +0100304/* common/board_info.c */
305int checkboard(void);
Simon Glassef211ab2023-11-12 19:58:21 -0700306
307/**
308 * show_board_info() - Show board information
309 *
310 * Check sysinfo for board information. Failing that if the root node of the DTB
311 * has a "model" property, show it.
312 *
313 * Then call checkboard().
314 *
315 * Return 0 if OK, -ve on error
316 */
Patrick Delaunayfc22ee22018-03-13 13:57:03 +0100317int show_board_info(void);
Patrick Delaunaydafa84d2018-03-09 18:28:12 +0100318
Simon Glass67c4e9f2019-11-14 12:57:45 -0700319/**
Heinrich Schuchardt289bd722023-08-14 08:44:26 +0200320 * board_get_usable_ram_top() - get uppermost address for U-Boot relocation
Simon Glass67c4e9f2019-11-14 12:57:45 -0700321 *
Heinrich Schuchardt289bd722023-08-14 08:44:26 +0200322 * Some systems have reserved memory areas in high memory. By implementing this
323 * function boards can indicate the highest address value to be used when
324 * relocating U-Boot. The returned address is exclusive (i.e. 1 byte above the
325 * last usable address).
Simon Glass67c4e9f2019-11-14 12:57:45 -0700326 *
Heinrich Schuchardt289bd722023-08-14 08:44:26 +0200327 * Due to overflow on systems with 32bit phys_addr_t a value 0 is used instead
328 * of 4GiB.
329 *
330 * @total_size: monitor length in bytes (size of U-Boot code)
331 * Return: uppermost address for U-Boot relocation
Simon Glass67c4e9f2019-11-14 12:57:45 -0700332 */
Heinrich Schuchardtd768dd82023-08-12 20:16:58 +0200333phys_addr_t board_get_usable_ram_top(phys_size_t total_size);
Simon Glass67c4e9f2019-11-14 12:57:45 -0700334
Simon Glass52559322019-11-14 12:57:46 -0700335int board_early_init_f(void);
336
337/* manipulate the U-Boot fdt before its relocation */
338int board_fix_fdt(void *rw_fdt_blob);
339int board_late_init(void);
340int board_postclk_init(void); /* after clocks/timebase, before env/serial */
341int board_early_init_r(void);
342
Ovidiu Panait130845b2020-11-28 10:43:18 +0200343/**
344 * arch_initr_trap() - Init traps
345 *
346 * Arch specific routine for initializing traps. It is called during the
347 * generic board init sequence, after relocation.
348 *
349 * Return: 0 if OK
350 */
351int arch_initr_trap(void);
Simon Glassd67bdaa2019-11-14 12:57:48 -0700352
Simon Glass6b8d3ce2019-12-28 10:44:39 -0700353/**
Ovidiu Panait2fd81be2022-01-01 19:13:29 +0200354 * init_addr_map()
355 *
356 * Initialize non-identity virtual-physical memory mappings for 32bit CPUs.
357 * It is called during the generic board init sequence, after relocation.
358 *
359 * Return: 0 if OK
360 */
361int init_addr_map(void);
362
363/**
Simon Glass6b8d3ce2019-12-28 10:44:39 -0700364 * main_loop() - Enter the main loop of U-Boot
365 *
366 * This normally runs the command line.
367 */
368void main_loop(void);
369
Simon Glass94133872019-12-28 10:44:45 -0700370#if defined(CONFIG_ARM)
371void relocate_code(ulong addr_moni);
372#else
373void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
374 ulong relocaddr)
375 __attribute__ ((noreturn));
376#endif
377
Simon Glass655f17f2020-05-10 14:16:55 -0600378/* Print a numeric value (for use in arch_print_bdinfo()) */
Bin Meng98592c72021-01-31 20:36:05 +0800379void bdinfo_print_num_l(const char *name, ulong value);
380void bdinfo_print_num_ll(const char *name, unsigned long long value);
Simon Glass655f17f2020-05-10 14:16:55 -0600381
Simon Glass40b8afe2023-03-10 12:47:14 -0800382/* Print a string value (for use in arch_print_bdinfo()) */
383void bdinfo_print_str(const char *name, const char *str);
384
Simon Glass655f17f2020-05-10 14:16:55 -0600385/* Print a clock speed in MHz */
386void bdinfo_print_mhz(const char *name, unsigned long hz);
387
Ovidiu Panaitae90d162022-08-29 20:02:04 +0300388/**
389 * bdinfo_print_size - print size variables in bdinfo format
390 * @name: string to print before the size
391 * @size: size to print
392 *
393 * Helper function for displaying size variables as properly formatted bdinfo
394 * entries. The size is printed as "xxx Bytes", "xxx KiB", "xxx MiB",
395 * "xxx GiB", etc. as needed;
396 *
397 * For use in arch_print_bdinfo().
398 */
399void bdinfo_print_size(const char *name, uint64_t size);
400
Simon Glass59b0d7d2020-05-10 14:16:56 -0600401/* Show arch-specific information for the 'bd' command */
402void arch_print_bdinfo(void);
403
Tom Rini03de3052024-05-20 13:35:03 -0600404struct cmd_tbl;
405
Andy Shevchenko4b325312021-11-08 21:03:38 +0300406int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
407
Patrick Delaunaydafa84d2018-03-09 18:28:12 +0100408#endif /* __ASSEMBLY__ */
409/* Put only stuff here that the assembler can digest */
410
411#endif /* __INIT_H_ */