Tom Rini | 10e4779 | 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 | 1ed83ba | 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 | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 6 | * headers. Please think before adding more things. |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 7 | * Patches to remove things are welcome. |
Simon Glass | 1ed83ba | 2019-08-02 09:44:27 -0600 | [diff] [blame] | 8 | * |
Wolfgang Denk | f342f86 | 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 | bcbd521 | 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 | 66e8d44 | 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 | ad276f2 | 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 | cbf1a93 | 2016-04-04 04:07:33 -0500 | [diff] [blame] | 24 | #include <errno.h> |
Masahiro Yamada | a4f0b8e | 2016-12-28 00:36:00 +0900 | [diff] [blame] | 25 | #include <time.h> |
Wolfgang Denk | 0191e47 | 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 | 958f0f0 | 2017-09-16 14:10:45 +0900 | [diff] [blame] | 28 | #include <linux/bug.h> |
Masahiro Yamada | 29d2a62 | 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 | bf9c293 | 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 | a3f1634 | 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 | 5e882e9 | 2017-09-16 14:10:39 +0900 | [diff] [blame] | 36 | #include <stdio.h> |
Masahiro Yamada | bd42662 | 2014-11-07 03:03:28 +0900 | [diff] [blame] | 37 | #include <linux/kernel.h> |
Simon Glass | 7613579 | 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 | 6c48001 | 2014-02-26 17:03:19 -0800 | [diff] [blame] | 43 | #ifdef __LP64__ |
| 44 | #define CONFIG_SYS_SUPPORT_64BIT_DATA |
| 45 | #endif |
| 46 | |
Simon Glass | 9054a02 | 2017-12-04 13:48:20 -0700 | [diff] [blame] | 47 | #include <log.h> |
Simon Glass | 02aa9e6 | 2011-06-29 09:49:34 +0000 | [diff] [blame] | 48 | |
wdenk | 87249ba | 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 | a0a2b21 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 52 | /* startup functions, used in: |
| 53 | * common/board_f.c |
Patrick Delaunay | 98c8bbc | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 54 | * common/init/board_init.c |
Patrick Delaunay | b76e7cf | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 55 | * common/board_r.c |
Patrick Delaunay | b1d2344 | 2018-03-13 13:57:03 +0100 | [diff] [blame] | 56 | * common/board_info.c |
Patrick Delaunay | a0a2b21 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 57 | */ |
Patrick Delaunay | c6bfcd5 | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 58 | #include <init.h> |
| 59 | |
wdenk | 452cfd6 | 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 | 87249ba | 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 | 7da617c | 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 | b76e7cf | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 70 | int checkflash(void); |
| 71 | int checkdram(void); |
Masahiro Yamada | 43c0893 | 2014-02-05 11:28:25 +0900 | [diff] [blame] | 72 | extern u8 __dtb_dt_begin[]; /* embedded device tree blob */ |
Goldschmidt Simon | 5e7a1c2 | 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 | a0a2b21 | 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 | eacd14f | 2012-11-30 13:01:20 +0000 | [diff] [blame] | 76 | /** |
Ma Haijun | 6235824 | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 77 | * arch_fixup_fdt() - Write arch-specific information to fdt |
Simon Glass | 9ca3742 | 2013-05-08 08:06:01 +0000 | [diff] [blame] | 78 | * |
Ma Haijun | 6235824 | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 79 | * Defined in arch/$(ARCH)/lib/bootm-fdt.c |
Simon Glass | 9ca3742 | 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 | 6235824 | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 84 | int arch_fixup_fdt(void *blob); |
Simon Glass | 9ca3742 | 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 | 85c25df | 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 | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 92 | extern ulong load_addr; /* Default Load Address */ |
Simon Glass | 34f5229 | 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 | 0e3a593 | 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 | eee675f | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 105 | /* common/exports.c */ |
| 106 | void jumptable_init(void); |
| 107 | |
Mike Frysinger | a46fbba | 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 | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 111 | /* common/memsize.c */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 112 | long get_ram_size (long *, long); |
York Sun | 863e8d8 | 2014-02-11 11:57:26 -0800 | [diff] [blame] | 113 | phys_size_t get_effective_memsize(void); |
wdenk | 87249ba | 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 | 87249ba | 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 | 4e96ff8 | 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 | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR |
Heiko Schocher | 9bb0dd5 | 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 | 0383694 | 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 | 0383694 | 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 | a043661 | 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 | 9039c10 | 2013-04-11 09:35:43 +0000 | [diff] [blame] | 131 | #endif |
Simon Glass | 243182c | 2017-05-17 08:23:06 -0600 | [diff] [blame] | 132 | |
Diego Dorta | 206d580 | 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 | ec1c122 | 2014-09-01 13:50:48 +0200 | [diff] [blame] | 137 | void reset_misc (void); |
wdenk | 1e8d0c5 | 2005-04-03 17:23:39 +0000 | [diff] [blame] | 138 | void reset_cpu (ulong addr); |
Kim Phillips | dc0b59d | 2007-08-15 22:30:26 -0500 | [diff] [blame] | 139 | void ft_cpu_setup(void *blob, bd_t *bd); |
Kim Phillips | dc0b59d | 2007-08-15 22:30:26 -0500 | [diff] [blame] | 140 | void ft_pci_setup(void *blob, bd_t *bd); |
Kim Phillips | dc0b59d | 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 | 3ddce57 | 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 | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 147 | /* lib/uuid.c */ |
Przemyslaw Marczak | 0c81336 | 2014-04-02 10:20:03 +0200 | [diff] [blame] | 148 | #include <uuid.h> |
Jason Hobbs | 6e39cce | 2011-08-23 11:06:56 +0000 | [diff] [blame] | 149 | |
Peter Tyser | 685b7f5 | 2010-04-12 22:28:05 -0500 | [diff] [blame] | 150 | /* lib/vsprintf.c */ |
Simon Glass | f7ae6806 | 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 | 05a377b | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 153 | /* lib/net_utils.c */ |
| 154 | #include <net.h> |
Joe Hershberger | 05a377b | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 155 | |
Simon Glass | 8445d00 | 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 | 9fcee53 | 2017-01-02 11:48:30 +0000 | [diff] [blame] | 158 | #else /* __ASSEMBLY__ */ |
| 159 | |
Andre Przywara | 9fcee53 | 2017-01-02 11:48:30 +0000 | [diff] [blame] | 160 | #endif /* __ASSEMBLY__ */ |
Wolfgang Denk | 66e8d44 | 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 | f969a68 | 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 | 66e8d44 | 2009-07-24 00:17:48 +0200 | [diff] [blame] | 169 | #endif |
| 170 | |
Anton Staaf | 07a036a | 2011-09-02 13:45:28 +0000 | [diff] [blame] | 171 | #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1)) |
Andy Fleming | 2ef5ed0 | 2008-06-16 13:58:53 -0500 | [diff] [blame] | 172 | |
Anton Staaf | cda2e48 | 2011-10-17 16:46:13 -0700 | [diff] [blame] | 173 | /* |
Simon Glass | d61718b | 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 | 63f581f | 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 | 63b8f12 | 2011-07-08 10:44:25 +0000 | [diff] [blame] | 191 | /* Pull in stuff for the build system */ |
| 192 | #ifdef DO_DEPS_ONLY |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 193 | # include <env_internal.h> |
Mike Frysinger | 63b8f12 | 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_ */ |