Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 2 | /* |
Simon Glass | ec1fa18 | 2019-08-02 09:44:27 -0600 | [diff] [blame] | 3 | * Common header file for U-Boot |
| 4 | * |
| 5 | * This file still includes quite a bit of stuff that should be in separate |
Simon Glass | 288b29e | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 6 | * headers. Please think before adding more things. |
Simon Glass | 1045315 | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 7 | * Patches to remove things are welcome. |
Simon Glass | ec1fa18 | 2019-08-02 09:44:27 -0600 | [diff] [blame] | 8 | * |
Wolfgang Denk | 3b74e7e | 2009-05-16 10:47:45 +0200 | [diff] [blame] | 9 | * (C) Copyright 2000-2009 |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 10 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef __COMMON_H_ |
Wolfgang Denk | d0b8fee | 2012-01-06 07:36:44 +0100 | [diff] [blame] | 14 | #define __COMMON_H_ 1 |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 15 | |
Wolfgang Denk | fcd3c87 | 2009-07-24 00:17:48 +0200 | [diff] [blame] | 16 | #ifndef __ASSEMBLY__ /* put C only stuff in this section */ |
| 17 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 18 | typedef unsigned char uchar; |
| 19 | typedef volatile unsigned long vu_long; |
wdenk | 180d3f7 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 20 | typedef volatile unsigned short vu_short; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 21 | typedef volatile unsigned char vu_char; |
| 22 | |
| 23 | #include <config.h> |
Joe Hershberger | 2307ea4 | 2016-04-04 04:07:33 -0500 | [diff] [blame] | 24 | #include <errno.h> |
Masahiro Yamada | a7b8176 | 2016-12-28 00:36:00 +0900 | [diff] [blame] | 25 | #include <time.h> |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 26 | #include <asm-offsets.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 27 | #include <linux/bitops.h> |
Masahiro Yamada | 0a70fb4 | 2017-09-16 14:10:45 +0900 | [diff] [blame] | 28 | #include <linux/bug.h> |
Masahiro Yamada | 5bc516e | 2016-12-28 00:35:59 +0900 | [diff] [blame] | 29 | #include <linux/delay.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 30 | #include <linux/types.h> |
Masahiro Yamada | b44b302 | 2017-09-16 14:10:40 +0900 | [diff] [blame] | 31 | #include <linux/printk.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 32 | #include <linux/string.h> |
Marek Vasut | 9aed508 | 2012-09-27 17:08:15 +0200 | [diff] [blame] | 33 | #include <linux/stringify.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 34 | #include <asm/ptrace.h> |
| 35 | #include <stdarg.h> |
Masahiro Yamada | 7fea7b1 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 36 | #include <stdio.h> |
Masahiro Yamada | cba1da4 | 2014-11-07 03:03:28 +0900 | [diff] [blame] | 37 | #include <linux/kernel.h> |
Simon Glass | 8504315 | 2017-05-17 08:23:05 -0600 | [diff] [blame] | 38 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 39 | #include <part.h> |
| 40 | #include <flash.h> |
| 41 | #include <image.h> |
| 42 | |
York Sun | 4d1fd7f | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 43 | #ifdef __LP64__ |
| 44 | #define CONFIG_SYS_SUPPORT_64BIT_DATA |
| 45 | #endif |
| 46 | |
Simon Glass | 0e98b0a | 2017-12-04 13:48:20 -0700 | [diff] [blame] | 47 | #include <log.h> |
Simon Glass | 21726a7 | 2011-06-29 09:49:34 +0000 | [diff] [blame] | 48 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 49 | #include <asm/u-boot.h> /* boot information for Linux kernel */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 50 | #include <asm/global_data.h> /* global data used for startup functions */ |
| 51 | |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 52 | /* startup functions, used in: |
| 53 | * common/board_f.c |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 54 | * common/init/board_init.c |
Patrick Delaunay | e2c219c | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 55 | * common/board_r.c |
Patrick Delaunay | fc22ee2 | 2018-03-13 13:57:03 +0100 | [diff] [blame] | 56 | * common/board_info.c |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 57 | */ |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 58 | #include <init.h> |
| 59 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 60 | /* |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 61 | * Function Prototypes |
| 62 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 63 | void hang (void) __attribute__ ((noreturn)); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 64 | |
Simon Glass | 2ea09c8 | 2015-04-28 20:25:07 -0600 | [diff] [blame] | 65 | #include <display_options.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 66 | |
| 67 | /* common/main.c */ |
| 68 | void main_loop (void); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 69 | |
Patrick Delaunay | e2c219c | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 70 | int checkflash(void); |
| 71 | int checkdram(void); |
Masahiro Yamada | 6ab6b2a | 2014-02-05 11:28:25 +0900 | [diff] [blame] | 72 | extern u8 __dtb_dt_begin[]; /* embedded device tree blob */ |
Goldschmidt Simon | 9bd76b8 | 2017-11-21 12:29:56 +0000 | [diff] [blame] | 73 | extern u8 __dtb_dt_spl_begin[]; /* embedded device tree blob for SPL/TPL */ |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 74 | int mdm_init(void); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 75 | |
Simon Glass | 15a33e4 | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 76 | /** |
Ma Haijun | e29607e | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 77 | * arch_fixup_fdt() - Write arch-specific information to fdt |
Simon Glass | 13d0698 | 2013-05-08 08:06:01 +0000 | [diff] [blame] | 78 | * |
Ma Haijun | e29607e | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 79 | * Defined in arch/$(ARCH)/lib/bootm-fdt.c |
Simon Glass | 13d0698 | 2013-05-08 08:06:01 +0000 | [diff] [blame] | 80 | * |
| 81 | * @blob: FDT blob to write to |
| 82 | * @return 0 if ok, or -ve FDT_ERR_... on failure |
| 83 | */ |
Ma Haijun | e29607e | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 84 | int arch_fixup_fdt(void *blob); |
Simon Glass | 13d0698 | 2013-05-08 08:06:01 +0000 | [diff] [blame] | 85 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 86 | /* common/flash.c */ |
| 87 | void flash_perror (int); |
| 88 | |
Wolfgang Denk | 74de7ae | 2009-04-01 23:34:12 +0200 | [diff] [blame] | 89 | /* common/cmd_source.c */ |
| 90 | int source (ulong addr, const char *fit_uname); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 91 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 92 | extern ulong load_addr; /* Default Load Address */ |
Simon Glass | 1aec244 | 2011-10-21 18:51:38 +0000 | [diff] [blame] | 93 | extern ulong save_addr; /* Default Save Address */ |
| 94 | extern ulong save_size; /* Default Save Size */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 95 | |
Jason Hobbs | 06283a6 | 2011-08-31 10:37:30 -0500 | [diff] [blame] | 96 | /* common/cmd_net.c */ |
| 97 | int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 98 | |
Rob Herring | 669df7e | 2012-05-25 10:47:39 +0000 | [diff] [blame] | 99 | /* common/cmd_fat.c */ |
| 100 | int do_fat_fsload(cmd_tbl_t *, int, int, char * const []); |
| 101 | |
| 102 | /* common/cmd_ext2.c */ |
| 103 | int do_ext2load(cmd_tbl_t *, int, int, char * const []); |
| 104 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 105 | /* common/exports.c */ |
| 106 | void jumptable_init(void); |
| 107 | |
Mike Frysinger | ecb1dc8 | 2009-05-20 04:35:14 -0400 | [diff] [blame] | 108 | /* common/kallsysm.c */ |
| 109 | const char *symbol_lookup(unsigned long addr, unsigned long *caddr); |
| 110 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 111 | /* common/memsize.c */ |
Albert ARIBAUD | a55d23c | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 112 | long get_ram_size (long *, long); |
York Sun | e386616 | 2014-02-11 11:57:26 -0800 | [diff] [blame] | 113 | phys_size_t get_effective_memsize(void); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 114 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 115 | /* $(BOARD)/$(BOARD).c */ |
| 116 | void reset_phy (void); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 117 | void fdc_hw_init (void); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 118 | |
Adam Ford | f1b1f77 | 2018-04-15 13:51:26 -0400 | [diff] [blame] | 119 | #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR |
Heiko Schocher | 548738b | 2010-01-07 08:55:40 +0100 | [diff] [blame] | 121 | #endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 122 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | #if defined(CONFIG_SYS_DRAM_TEST) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 124 | int testdram(void); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | #endif /* CONFIG_SYS_DRAM_TEST */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 126 | |
Benoît Thébaudeau | 5c6db12 | 2013-04-11 09:35:53 +0000 | [diff] [blame] | 127 | #if defined(CONFIG_ARM) |
| 128 | void relocate_code(ulong); |
| 129 | #else |
| 130 | void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn)); |
Benoît Thébaudeau | 959eaa7 | 2013-04-11 09:35:43 +0000 | [diff] [blame] | 131 | #endif |
Simon Glass | 6e2941d | 2017-05-17 08:23:06 -0600 | [diff] [blame] | 132 | |
Diego Dorta | 026d795 | 2017-10-05 09:13:38 -0300 | [diff] [blame] | 133 | void s_init(void); |
| 134 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 135 | void upmconfig (unsigned int, unsigned int *, unsigned int); |
| 136 | ulong get_tbclk (void); |
Przemyslaw Marczak | 1fb4dab | 2014-09-01 13:50:48 +0200 | [diff] [blame] | 137 | void reset_misc (void); |
wdenk | 3ec924a | 2005-04-03 17:23:39 +0000 | [diff] [blame] | 138 | void reset_cpu (ulong addr); |
Kim Phillips | 6a16e0d | 2007-08-15 22:30:26 -0500 | [diff] [blame] | 139 | void ft_cpu_setup(void *blob, bd_t *bd); |
Kim Phillips | 6a16e0d | 2007-08-15 22:30:26 -0500 | [diff] [blame] | 140 | void ft_pci_setup(void *blob, bd_t *bd); |
Kim Phillips | 6a16e0d | 2007-08-15 22:30:26 -0500 | [diff] [blame] | 141 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 142 | /* $(CPU)/speed.c */ |
| 143 | int get_clocks (void); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 144 | ulong get_bus_freq (ulong); |
Stefan Roese | 550650d | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 145 | int get_serial_clock(void); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 146 | |
Jason Hobbs | e11938e | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 147 | /* lib/uuid.c */ |
Przemyslaw Marczak | d718ded | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 148 | #include <uuid.h> |
Jason Hobbs | e11938e | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 149 | |
Peter Tyser | 78acc47 | 2010-04-12 22:28:05 -0500 | [diff] [blame] | 150 | /* lib/vsprintf.c */ |
Simon Glass | 9785c90 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 151 | #include <vsprintf.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 152 | |
Joe Hershberger | 4ef8d53 | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 153 | /* lib/net_utils.c */ |
| 154 | #include <net.h> |
Joe Hershberger | 4ef8d53 | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 155 | |
Simon Glass | 097e178 | 2012-01-14 15:24:44 +0000 | [diff] [blame] | 156 | #include <bootstage.h> |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 157 | |
Andre Przywara | 2a6713b | 2017-01-02 11:48:30 +0000 | [diff] [blame] | 158 | #else /* __ASSEMBLY__ */ |
| 159 | |
Andre Przywara | 2a6713b | 2017-01-02 11:48:30 +0000 | [diff] [blame] | 160 | #endif /* __ASSEMBLY__ */ |
Wolfgang Denk | fcd3c87 | 2009-07-24 00:17:48 +0200 | [diff] [blame] | 161 | |
| 162 | /* Put only stuff here that the assembler can digest */ |
| 163 | |
| 164 | #ifdef CONFIG_POST |
| 165 | #define CONFIG_HAS_POST |
Michael Zaidman | 800eb09 | 2010-09-20 08:51:53 +0200 | [diff] [blame] | 166 | #ifndef CONFIG_POST_ALT_LIST |
| 167 | #define CONFIG_POST_STD_LIST |
| 168 | #endif |
Wolfgang Denk | fcd3c87 | 2009-07-24 00:17:48 +0200 | [diff] [blame] | 169 | #endif |
| 170 | |
Anton Staaf | 155cfb5 | 2011-09-02 13:45:28 +0000 | [diff] [blame] | 171 | #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1)) |
Andy Fleming | 4b03ac8 | 2008-06-16 13:58:53 -0500 | [diff] [blame] | 172 | |
Anton Staaf | 1e41f5a | 2011-10-17 16:46:13 -0700 | [diff] [blame] | 173 | /* |
Simon Glass | c9689ca | 2015-06-23 15:38:31 -0600 | [diff] [blame] | 174 | * check_member() - Check the offset of a structure member |
| 175 | * |
| 176 | * @structure: Name of structure (e.g. global_data) |
| 177 | * @member: Name of member (e.g. baudrate) |
| 178 | * @offset: Expected offset in bytes |
| 179 | */ |
| 180 | #define check_member(structure, member, offset) _Static_assert( \ |
| 181 | offsetof(struct structure, member) == offset, \ |
| 182 | "`struct " #structure "` offset for `" #member "` is not " #offset) |
| 183 | |
Simon Glass | 476476e | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 184 | /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */ |
| 185 | #ifdef CONFIG_EFI_STUB |
| 186 | #define ll_boot_init() false |
| 187 | #else |
| 188 | #define ll_boot_init() true |
| 189 | #endif |
| 190 | |
Mike Frysinger | c3eb3fe | 2011-07-08 10:44:25 +0000 | [diff] [blame] | 191 | /* Pull in stuff for the build system */ |
| 192 | #ifdef DO_DEPS_ONLY |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 193 | # include <env_internal.h> |
Mike Frysinger | c3eb3fe | 2011-07-08 10:44:25 +0000 | [diff] [blame] | 194 | #endif |
| 195 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 196 | #endif /* __COMMON_H_ */ |