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