Commit 068feb9b86d991283c43b56e36094f4e6f484d04

Authored by Rick Chen
Committed by Tom Rini
1 parent c7d7e80acd

riscv: Modify generic codes to support RISC-V

Support common commands bdinfo and image format,
also modify common generic flow for RISC-V.

Signed-off-by: Rick Chen <rick@andestech.com>
Signed-off-by: Rick Chen <rickchen36@gmail.com>
Signed-off-by: Greentime Hu <green.hu@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 6 changed files with 29 additions and 3 deletions Inline Diff

1 config CREATE_ARCH_SYMLINK 1 config CREATE_ARCH_SYMLINK
2 bool 2 bool
3 3
4 config HAVE_ARCH_IOREMAP 4 config HAVE_ARCH_IOREMAP
5 bool 5 bool
6 6
7 choice 7 choice
8 prompt "Architecture select" 8 prompt "Architecture select"
9 default SANDBOX 9 default SANDBOX
10 10
11 config ARC 11 config ARC
12 bool "ARC architecture" 12 bool "ARC architecture"
13 select HAVE_PRIVATE_LIBGCC 13 select HAVE_PRIVATE_LIBGCC
14 select SUPPORT_OF_CONTROL 14 select SUPPORT_OF_CONTROL
15 select ARCH_EARLY_INIT_R 15 select ARCH_EARLY_INIT_R
16 select CLK 16 select CLK
17 select TIMER 17 select TIMER
18 select ARC_TIMER 18 select ARC_TIMER
19 19
20 config ARM 20 config ARM
21 bool "ARM architecture" 21 bool "ARM architecture"
22 select CREATE_ARCH_SYMLINK 22 select CREATE_ARCH_SYMLINK
23 select HAVE_PRIVATE_LIBGCC if !ARM64 23 select HAVE_PRIVATE_LIBGCC if !ARM64
24 select SUPPORT_OF_CONTROL 24 select SUPPORT_OF_CONTROL
25 25
26 config M68K 26 config M68K
27 bool "M68000 architecture" 27 bool "M68000 architecture"
28 select HAVE_PRIVATE_LIBGCC 28 select HAVE_PRIVATE_LIBGCC
29 29
30 config MICROBLAZE 30 config MICROBLAZE
31 bool "MicroBlaze architecture" 31 bool "MicroBlaze architecture"
32 select SUPPORT_OF_CONTROL 32 select SUPPORT_OF_CONTROL
33 imply CMD_IRQ 33 imply CMD_IRQ
34 34
35 config MIPS 35 config MIPS
36 bool "MIPS architecture" 36 bool "MIPS architecture"
37 select HAVE_ARCH_IOREMAP 37 select HAVE_ARCH_IOREMAP
38 select HAVE_PRIVATE_LIBGCC 38 select HAVE_PRIVATE_LIBGCC
39 select SUPPORT_OF_CONTROL 39 select SUPPORT_OF_CONTROL
40 40
41 config NDS32 41 config NDS32
42 bool "NDS32 architecture" 42 bool "NDS32 architecture"
43 select SUPPORT_OF_CONTROL 43 select SUPPORT_OF_CONTROL
44 44
45 config NIOS2 45 config NIOS2
46 bool "Nios II architecture" 46 bool "Nios II architecture"
47 select SUPPORT_OF_CONTROL 47 select SUPPORT_OF_CONTROL
48 select OF_CONTROL 48 select OF_CONTROL
49 select DM 49 select DM
50 select CPU 50 select CPU
51 51
52 config PPC 52 config PPC
53 bool "PowerPC architecture" 53 bool "PowerPC architecture"
54 select HAVE_PRIVATE_LIBGCC 54 select HAVE_PRIVATE_LIBGCC
55 select SUPPORT_OF_CONTROL 55 select SUPPORT_OF_CONTROL
56 56
57 config RISCV
58 bool "riscv architecture"
59 select SUPPORT_OF_CONTROL
60
57 config SANDBOX 61 config SANDBOX
58 bool "Sandbox" 62 bool "Sandbox"
59 select BOARD_LATE_INIT 63 select BOARD_LATE_INIT
60 select SUPPORT_OF_CONTROL 64 select SUPPORT_OF_CONTROL
61 select DM 65 select DM
62 select DM_KEYBOARD 66 select DM_KEYBOARD
63 select DM_SPI_FLASH 67 select DM_SPI_FLASH
64 select DM_SERIAL 68 select DM_SERIAL
65 select DM_I2C 69 select DM_I2C
66 select DM_SPI 70 select DM_SPI
67 select DM_GPIO 71 select DM_GPIO
68 select DM_MMC 72 select DM_MMC
69 select LZO 73 select LZO
70 imply CMD_GETTIME 74 imply CMD_GETTIME
71 imply CMD_HASH 75 imply CMD_HASH
72 imply CMD_IO 76 imply CMD_IO
73 imply CMD_IOTRACE 77 imply CMD_IOTRACE
74 imply CMD_LZMADEC 78 imply CMD_LZMADEC
75 imply CRC32_VERIFY 79 imply CRC32_VERIFY
76 imply FAT_WRITE 80 imply FAT_WRITE
77 imply HASH_VERIFY 81 imply HASH_VERIFY
78 imply LZMA 82 imply LZMA
79 imply SCSI 83 imply SCSI
80 imply CMD_SATA 84 imply CMD_SATA
81 imply CMD_SF_TEST 85 imply CMD_SF_TEST
82 86
83 config SH 87 config SH
84 bool "SuperH architecture" 88 bool "SuperH architecture"
85 select HAVE_PRIVATE_LIBGCC 89 select HAVE_PRIVATE_LIBGCC
86 90
87 config X86 91 config X86
88 bool "x86 architecture" 92 bool "x86 architecture"
89 select CREATE_ARCH_SYMLINK 93 select CREATE_ARCH_SYMLINK
90 select HAVE_PRIVATE_LIBGCC 94 select HAVE_PRIVATE_LIBGCC
91 select USE_PRIVATE_LIBGCC 95 select USE_PRIVATE_LIBGCC
92 select SUPPORT_OF_CONTROL 96 select SUPPORT_OF_CONTROL
93 select OF_CONTROL 97 select OF_CONTROL
94 select DM 98 select DM
95 select DM_PCI 99 select DM_PCI
96 select PCI 100 select PCI
97 select TIMER 101 select TIMER
98 select X86_TSC_TIMER 102 select X86_TSC_TIMER
99 imply BLK 103 imply BLK
100 imply DM_ETH 104 imply DM_ETH
101 imply DM_GPIO 105 imply DM_GPIO
102 imply DM_KEYBOARD 106 imply DM_KEYBOARD
103 imply DM_MMC 107 imply DM_MMC
104 imply DM_RTC 108 imply DM_RTC
105 imply DM_SERIAL 109 imply DM_SERIAL
106 imply DM_SCSI 110 imply DM_SCSI
107 imply DM_SPI 111 imply DM_SPI
108 imply DM_SPI_FLASH 112 imply DM_SPI_FLASH
109 imply DM_USB 113 imply DM_USB
110 imply DM_VIDEO 114 imply DM_VIDEO
111 imply CMD_FPGA_LOADMK 115 imply CMD_FPGA_LOADMK
112 imply CMD_GETTIME 116 imply CMD_GETTIME
113 imply CMD_IO 117 imply CMD_IO
114 imply CMD_IRQ 118 imply CMD_IRQ
115 imply CMD_PCI 119 imply CMD_PCI
116 imply CMD_SF_TEST 120 imply CMD_SF_TEST
117 imply CMD_ZBOOT 121 imply CMD_ZBOOT
118 imply USB_HOST_ETHER 122 imply USB_HOST_ETHER
119 imply USB_ETHER_ASIX 123 imply USB_ETHER_ASIX
120 imply USB_ETHER_SMSC95XX 124 imply USB_ETHER_SMSC95XX
121 125
122 config XTENSA 126 config XTENSA
123 bool "Xtensa architecture" 127 bool "Xtensa architecture"
124 select CREATE_ARCH_SYMLINK 128 select CREATE_ARCH_SYMLINK
125 select SUPPORT_OF_CONTROL 129 select SUPPORT_OF_CONTROL
126 130
127 endchoice 131 endchoice
128 132
129 config SYS_ARCH 133 config SYS_ARCH
130 string 134 string
131 help 135 help
132 This option should contain the architecture name to build the 136 This option should contain the architecture name to build the
133 appropriate arch/<CONFIG_SYS_ARCH> directory. 137 appropriate arch/<CONFIG_SYS_ARCH> directory.
134 All the architectures should specify this option correctly. 138 All the architectures should specify this option correctly.
135 139
136 config SYS_CPU 140 config SYS_CPU
137 string 141 string
138 help 142 help
139 This option should contain the CPU name to build the correct 143 This option should contain the CPU name to build the correct
140 arch/<CONFIG_SYS_ARCH>/cpu/<CONFIG_SYS_CPU> directory. 144 arch/<CONFIG_SYS_ARCH>/cpu/<CONFIG_SYS_CPU> directory.
141 145
142 This is optional. For those targets without the CPU directory, 146 This is optional. For those targets without the CPU directory,
143 leave this option empty. 147 leave this option empty.
144 148
145 config SYS_SOC 149 config SYS_SOC
146 string 150 string
147 help 151 help
148 This option should contain the SoC name to build the directory 152 This option should contain the SoC name to build the directory
149 arch/<CONFIG_SYS_ARCH>/cpu/<CONFIG_SYS_CPU>/<CONFIG_SYS_SOC>. 153 arch/<CONFIG_SYS_ARCH>/cpu/<CONFIG_SYS_CPU>/<CONFIG_SYS_SOC>.
150 154
151 This is optional. For those targets without the SoC directory, 155 This is optional. For those targets without the SoC directory,
152 leave this option empty. 156 leave this option empty.
153 157
154 config SYS_VENDOR 158 config SYS_VENDOR
155 string 159 string
156 help 160 help
157 This option should contain the vendor name of the target board. 161 This option should contain the vendor name of the target board.
158 If it is set and 162 If it is set and
159 board/<CONFIG_SYS_VENDOR>/common/Makefile exists, the vendor common 163 board/<CONFIG_SYS_VENDOR>/common/Makefile exists, the vendor common
160 directory is compiled. 164 directory is compiled.
161 If CONFIG_SYS_BOARD is also set, the sources under 165 If CONFIG_SYS_BOARD is also set, the sources under
162 board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD> directory are compiled. 166 board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD> directory are compiled.
163 167
164 This is optional. For those targets without the vendor directory, 168 This is optional. For those targets without the vendor directory,
165 leave this option empty. 169 leave this option empty.
166 170
167 config SYS_BOARD 171 config SYS_BOARD
168 string 172 string
169 help 173 help
170 This option should contain the name of the target board. 174 This option should contain the name of the target board.
171 If it is set, either board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD> 175 If it is set, either board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD>
172 or board/<CONFIG_SYS_BOARD> directory is compiled depending on 176 or board/<CONFIG_SYS_BOARD> directory is compiled depending on
173 whether CONFIG_SYS_VENDOR is set or not. 177 whether CONFIG_SYS_VENDOR is set or not.
174 178
175 This is optional. For those targets without the board directory, 179 This is optional. For those targets without the board directory,
176 leave this option empty. 180 leave this option empty.
177 181
178 config SYS_CONFIG_NAME 182 config SYS_CONFIG_NAME
179 string 183 string
180 help 184 help
181 This option should contain the base name of board header file. 185 This option should contain the base name of board header file.
182 The header file include/configs/<CONFIG_SYS_CONFIG_NAME>.h 186 The header file include/configs/<CONFIG_SYS_CONFIG_NAME>.h
183 should be included from include/config.h. 187 should be included from include/config.h.
184 188
185 source "arch/arc/Kconfig" 189 source "arch/arc/Kconfig"
186 source "arch/arm/Kconfig" 190 source "arch/arm/Kconfig"
187 source "arch/m68k/Kconfig" 191 source "arch/m68k/Kconfig"
188 source "arch/microblaze/Kconfig" 192 source "arch/microblaze/Kconfig"
189 source "arch/mips/Kconfig" 193 source "arch/mips/Kconfig"
190 source "arch/nds32/Kconfig" 194 source "arch/nds32/Kconfig"
191 source "arch/nios2/Kconfig" 195 source "arch/nios2/Kconfig"
192 source "arch/powerpc/Kconfig" 196 source "arch/powerpc/Kconfig"
193 source "arch/sandbox/Kconfig" 197 source "arch/sandbox/Kconfig"
194 source "arch/sh/Kconfig" 198 source "arch/sh/Kconfig"
195 source "arch/x86/Kconfig" 199 source "arch/x86/Kconfig"
196 source "arch/xtensa/Kconfig" 200 source "arch/xtensa/Kconfig"
201 source "arch/riscv/Kconfig"
197 202
1 /* 1 /*
2 * (C) Copyright 2003 2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * 4 *
5 * SPDX-License-Identifier: GPL-2.0+ 5 * SPDX-License-Identifier: GPL-2.0+
6 */ 6 */
7 7
8 /* 8 /*
9 * Boot support 9 * Boot support
10 */ 10 */
11 #include <common.h> 11 #include <common.h>
12 #include <command.h> 12 #include <command.h>
13 #include <linux/compiler.h> 13 #include <linux/compiler.h>
14 14
15 DECLARE_GLOBAL_DATA_PTR; 15 DECLARE_GLOBAL_DATA_PTR;
16 16
17 __maybe_unused 17 __maybe_unused
18 static void print_num(const char *name, ulong value) 18 static void print_num(const char *name, ulong value)
19 { 19 {
20 printf("%-12s= 0x%08lX\n", name, value); 20 printf("%-12s= 0x%08lX\n", name, value);
21 } 21 }
22 22
23 __maybe_unused 23 __maybe_unused
24 static void print_eth(int idx) 24 static void print_eth(int idx)
25 { 25 {
26 char name[10], *val; 26 char name[10], *val;
27 if (idx) 27 if (idx)
28 sprintf(name, "eth%iaddr", idx); 28 sprintf(name, "eth%iaddr", idx);
29 else 29 else
30 strcpy(name, "ethaddr"); 30 strcpy(name, "ethaddr");
31 val = env_get(name); 31 val = env_get(name);
32 if (!val) 32 if (!val)
33 val = "(not set)"; 33 val = "(not set)";
34 printf("%-12s= %s\n", name, val); 34 printf("%-12s= %s\n", name, val);
35 } 35 }
36 36
37 #ifndef CONFIG_DM_ETH 37 #ifndef CONFIG_DM_ETH
38 __maybe_unused 38 __maybe_unused
39 static void print_eths(void) 39 static void print_eths(void)
40 { 40 {
41 struct eth_device *dev; 41 struct eth_device *dev;
42 int i = 0; 42 int i = 0;
43 43
44 do { 44 do {
45 dev = eth_get_dev_by_index(i); 45 dev = eth_get_dev_by_index(i);
46 if (dev) { 46 if (dev) {
47 printf("eth%dname = %s\n", i, dev->name); 47 printf("eth%dname = %s\n", i, dev->name);
48 print_eth(i); 48 print_eth(i);
49 i++; 49 i++;
50 } 50 }
51 } while (dev); 51 } while (dev);
52 52
53 printf("current eth = %s\n", eth_get_name()); 53 printf("current eth = %s\n", eth_get_name());
54 printf("ip_addr = %s\n", env_get("ipaddr")); 54 printf("ip_addr = %s\n", env_get("ipaddr"));
55 } 55 }
56 #endif 56 #endif
57 57
58 __maybe_unused 58 __maybe_unused
59 static void print_lnum(const char *name, unsigned long long value) 59 static void print_lnum(const char *name, unsigned long long value)
60 { 60 {
61 printf("%-12s= 0x%.8llX\n", name, value); 61 printf("%-12s= 0x%.8llX\n", name, value);
62 } 62 }
63 63
64 __maybe_unused 64 __maybe_unused
65 static void print_mhz(const char *name, unsigned long hz) 65 static void print_mhz(const char *name, unsigned long hz)
66 { 66 {
67 char buf[32]; 67 char buf[32];
68 68
69 printf("%-12s= %6s MHz\n", name, strmhz(buf, hz)); 69 printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
70 } 70 }
71 71
72 72
73 static inline void print_bi_boot_params(const bd_t *bd) 73 static inline void print_bi_boot_params(const bd_t *bd)
74 { 74 {
75 print_num("boot_params", (ulong)bd->bi_boot_params); 75 print_num("boot_params", (ulong)bd->bi_boot_params);
76 } 76 }
77 77
78 static inline void print_bi_mem(const bd_t *bd) 78 static inline void print_bi_mem(const bd_t *bd)
79 { 79 {
80 #if defined(CONFIG_SH) 80 #if defined(CONFIG_SH)
81 print_num("mem start ", (ulong)bd->bi_memstart); 81 print_num("mem start ", (ulong)bd->bi_memstart);
82 print_lnum("mem size ", (u64)bd->bi_memsize); 82 print_lnum("mem size ", (u64)bd->bi_memsize);
83 #elif defined(CONFIG_ARC) 83 #elif defined(CONFIG_ARC)
84 print_num("mem start", (ulong)bd->bi_memstart); 84 print_num("mem start", (ulong)bd->bi_memstart);
85 print_lnum("mem size", (u64)bd->bi_memsize); 85 print_lnum("mem size", (u64)bd->bi_memsize);
86 #else 86 #else
87 print_num("memstart", (ulong)bd->bi_memstart); 87 print_num("memstart", (ulong)bd->bi_memstart);
88 print_lnum("memsize", (u64)bd->bi_memsize); 88 print_lnum("memsize", (u64)bd->bi_memsize);
89 #endif 89 #endif
90 } 90 }
91 91
92 static inline void print_bi_dram(const bd_t *bd) 92 static inline void print_bi_dram(const bd_t *bd)
93 { 93 {
94 #ifdef CONFIG_NR_DRAM_BANKS 94 #ifdef CONFIG_NR_DRAM_BANKS
95 int i; 95 int i;
96 96
97 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { 97 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
98 if (bd->bi_dram[i].size) { 98 if (bd->bi_dram[i].size) {
99 print_num("DRAM bank", i); 99 print_num("DRAM bank", i);
100 print_num("-> start", bd->bi_dram[i].start); 100 print_num("-> start", bd->bi_dram[i].start);
101 print_num("-> size", bd->bi_dram[i].size); 101 print_num("-> size", bd->bi_dram[i].size);
102 } 102 }
103 } 103 }
104 #endif 104 #endif
105 } 105 }
106 106
107 static inline void print_bi_flash(const bd_t *bd) 107 static inline void print_bi_flash(const bd_t *bd)
108 { 108 {
109 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH) 109 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH)
110 print_num("flash start ", (ulong)bd->bi_flashstart); 110 print_num("flash start ", (ulong)bd->bi_flashstart);
111 print_num("flash size ", (ulong)bd->bi_flashsize); 111 print_num("flash size ", (ulong)bd->bi_flashsize);
112 print_num("flash offset ", (ulong)bd->bi_flashoffset); 112 print_num("flash offset ", (ulong)bd->bi_flashoffset);
113 113
114 #elif defined(CONFIG_NIOS2) 114 #elif defined(CONFIG_NIOS2)
115 print_num("flash start", (ulong)bd->bi_flashstart); 115 print_num("flash start", (ulong)bd->bi_flashstart);
116 print_num("flash size", (ulong)bd->bi_flashsize); 116 print_num("flash size", (ulong)bd->bi_flashsize);
117 print_num("flash offset", (ulong)bd->bi_flashoffset); 117 print_num("flash offset", (ulong)bd->bi_flashoffset);
118 #else 118 #else
119 print_num("flashstart", (ulong)bd->bi_flashstart); 119 print_num("flashstart", (ulong)bd->bi_flashstart);
120 print_num("flashsize", (ulong)bd->bi_flashsize); 120 print_num("flashsize", (ulong)bd->bi_flashsize);
121 print_num("flashoffset", (ulong)bd->bi_flashoffset); 121 print_num("flashoffset", (ulong)bd->bi_flashoffset);
122 #endif 122 #endif
123 } 123 }
124 124
125 static inline void print_eth_ip_addr(void) 125 static inline void print_eth_ip_addr(void)
126 { 126 {
127 #if defined(CONFIG_CMD_NET) 127 #if defined(CONFIG_CMD_NET)
128 print_eth(0); 128 print_eth(0);
129 #if defined(CONFIG_HAS_ETH1) 129 #if defined(CONFIG_HAS_ETH1)
130 print_eth(1); 130 print_eth(1);
131 #endif 131 #endif
132 #if defined(CONFIG_HAS_ETH2) 132 #if defined(CONFIG_HAS_ETH2)
133 print_eth(2); 133 print_eth(2);
134 #endif 134 #endif
135 #if defined(CONFIG_HAS_ETH3) 135 #if defined(CONFIG_HAS_ETH3)
136 print_eth(3); 136 print_eth(3);
137 #endif 137 #endif
138 #if defined(CONFIG_HAS_ETH4) 138 #if defined(CONFIG_HAS_ETH4)
139 print_eth(4); 139 print_eth(4);
140 #endif 140 #endif
141 #if defined(CONFIG_HAS_ETH5) 141 #if defined(CONFIG_HAS_ETH5)
142 print_eth(5); 142 print_eth(5);
143 #endif 143 #endif
144 printf("IP addr = %s\n", env_get("ipaddr")); 144 printf("IP addr = %s\n", env_get("ipaddr"));
145 #endif 145 #endif
146 } 146 }
147 147
148 static inline void print_baudrate(void) 148 static inline void print_baudrate(void)
149 { 149 {
150 #if defined(CONFIG_PPC) 150 #if defined(CONFIG_PPC)
151 printf("baudrate = %6u bps\n", gd->baudrate); 151 printf("baudrate = %6u bps\n", gd->baudrate);
152 #else 152 #else
153 printf("baudrate = %u bps\n", gd->baudrate); 153 printf("baudrate = %u bps\n", gd->baudrate);
154 #endif 154 #endif
155 } 155 }
156 156
157 static inline void __maybe_unused print_std_bdinfo(const bd_t *bd) 157 static inline void __maybe_unused print_std_bdinfo(const bd_t *bd)
158 { 158 {
159 print_bi_boot_params(bd); 159 print_bi_boot_params(bd);
160 print_bi_mem(bd); 160 print_bi_mem(bd);
161 print_bi_flash(bd); 161 print_bi_flash(bd);
162 print_eth_ip_addr(); 162 print_eth_ip_addr();
163 print_baudrate(); 163 print_baudrate();
164 } 164 }
165 165
166 #if defined(CONFIG_PPC) 166 #if defined(CONFIG_PPC)
167 void __weak board_detail(void) 167 void __weak board_detail(void)
168 { 168 {
169 /* Please define board_detail() for your platform */ 169 /* Please define board_detail() for your platform */
170 } 170 }
171 171
172 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 172 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
173 { 173 {
174 bd_t *bd = gd->bd; 174 bd_t *bd = gd->bd;
175 175
176 #ifdef DEBUG 176 #ifdef DEBUG
177 print_num("bd address", (ulong)bd); 177 print_num("bd address", (ulong)bd);
178 #endif 178 #endif
179 print_bi_mem(bd); 179 print_bi_mem(bd);
180 print_bi_flash(bd); 180 print_bi_flash(bd);
181 print_num("sramstart", bd->bi_sramstart); 181 print_num("sramstart", bd->bi_sramstart);
182 print_num("sramsize", bd->bi_sramsize); 182 print_num("sramsize", bd->bi_sramsize);
183 #if defined(CONFIG_8xx) || defined(CONFIG_E500) 183 #if defined(CONFIG_8xx) || defined(CONFIG_E500)
184 print_num("immr_base", bd->bi_immr_base); 184 print_num("immr_base", bd->bi_immr_base);
185 #endif 185 #endif
186 print_num("bootflags", bd->bi_bootflags); 186 print_num("bootflags", bd->bi_bootflags);
187 #if defined(CONFIG_CPM2) 187 #if defined(CONFIG_CPM2)
188 print_mhz("vco", bd->bi_vco); 188 print_mhz("vco", bd->bi_vco);
189 print_mhz("sccfreq", bd->bi_sccfreq); 189 print_mhz("sccfreq", bd->bi_sccfreq);
190 print_mhz("brgfreq", bd->bi_brgfreq); 190 print_mhz("brgfreq", bd->bi_brgfreq);
191 #endif 191 #endif
192 print_mhz("intfreq", bd->bi_intfreq); 192 print_mhz("intfreq", bd->bi_intfreq);
193 #if defined(CONFIG_CPM2) 193 #if defined(CONFIG_CPM2)
194 print_mhz("cpmfreq", bd->bi_cpmfreq); 194 print_mhz("cpmfreq", bd->bi_cpmfreq);
195 #endif 195 #endif
196 print_mhz("busfreq", bd->bi_busfreq); 196 print_mhz("busfreq", bd->bi_busfreq);
197 197
198 #ifdef CONFIG_ENABLE_36BIT_PHYS 198 #ifdef CONFIG_ENABLE_36BIT_PHYS
199 #ifdef CONFIG_PHYS_64BIT 199 #ifdef CONFIG_PHYS_64BIT
200 puts("addressing = 36-bit\n"); 200 puts("addressing = 36-bit\n");
201 #else 201 #else
202 puts("addressing = 32-bit\n"); 202 puts("addressing = 32-bit\n");
203 #endif 203 #endif
204 #endif 204 #endif
205 205
206 print_eth_ip_addr(); 206 print_eth_ip_addr();
207 print_baudrate(); 207 print_baudrate();
208 print_num("relocaddr", gd->relocaddr); 208 print_num("relocaddr", gd->relocaddr);
209 board_detail(); 209 board_detail();
210 return 0; 210 return 0;
211 } 211 }
212 212
213 #elif defined(CONFIG_NIOS2) 213 #elif defined(CONFIG_NIOS2)
214 214
215 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 215 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
216 { 216 {
217 bd_t *bd = gd->bd; 217 bd_t *bd = gd->bd;
218 218
219 print_bi_dram(bd); 219 print_bi_dram(bd);
220 print_bi_flash(bd); 220 print_bi_flash(bd);
221 221
222 #if defined(CONFIG_SYS_SRAM_BASE) 222 #if defined(CONFIG_SYS_SRAM_BASE)
223 print_num ("sram start", (ulong)bd->bi_sramstart); 223 print_num ("sram start", (ulong)bd->bi_sramstart);
224 print_num ("sram size", (ulong)bd->bi_sramsize); 224 print_num ("sram size", (ulong)bd->bi_sramsize);
225 #endif 225 #endif
226 226
227 print_eth_ip_addr(); 227 print_eth_ip_addr();
228 print_baudrate(); 228 print_baudrate();
229 229
230 return 0; 230 return 0;
231 } 231 }
232 232
233 #elif defined(CONFIG_MICROBLAZE) 233 #elif defined(CONFIG_MICROBLAZE)
234 234
235 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 235 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
236 { 236 {
237 bd_t *bd = gd->bd; 237 bd_t *bd = gd->bd;
238 238
239 print_bi_dram(bd); 239 print_bi_dram(bd);
240 print_bi_flash(bd); 240 print_bi_flash(bd);
241 #if defined(CONFIG_SYS_SRAM_BASE) 241 #if defined(CONFIG_SYS_SRAM_BASE)
242 print_num("sram start ", (ulong)bd->bi_sramstart); 242 print_num("sram start ", (ulong)bd->bi_sramstart);
243 print_num("sram size ", (ulong)bd->bi_sramsize); 243 print_num("sram size ", (ulong)bd->bi_sramsize);
244 #endif 244 #endif
245 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) 245 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
246 print_eths(); 246 print_eths();
247 #endif 247 #endif
248 print_baudrate(); 248 print_baudrate();
249 print_num("relocaddr", gd->relocaddr); 249 print_num("relocaddr", gd->relocaddr);
250 print_num("reloc off", gd->reloc_off); 250 print_num("reloc off", gd->reloc_off);
251 print_num("fdt_blob", (ulong)gd->fdt_blob); 251 print_num("fdt_blob", (ulong)gd->fdt_blob);
252 print_num("new_fdt", (ulong)gd->new_fdt); 252 print_num("new_fdt", (ulong)gd->new_fdt);
253 print_num("fdt_size", (ulong)gd->fdt_size); 253 print_num("fdt_size", (ulong)gd->fdt_size);
254 254
255 return 0; 255 return 0;
256 } 256 }
257 257
258 #elif defined(CONFIG_M68K) 258 #elif defined(CONFIG_M68K)
259 259
260 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 260 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
261 { 261 {
262 bd_t *bd = gd->bd; 262 bd_t *bd = gd->bd;
263 263
264 print_bi_mem(bd); 264 print_bi_mem(bd);
265 print_bi_flash(bd); 265 print_bi_flash(bd);
266 #if defined(CONFIG_SYS_INIT_RAM_ADDR) 266 #if defined(CONFIG_SYS_INIT_RAM_ADDR)
267 print_num("sramstart", (ulong)bd->bi_sramstart); 267 print_num("sramstart", (ulong)bd->bi_sramstart);
268 print_num("sramsize", (ulong)bd->bi_sramsize); 268 print_num("sramsize", (ulong)bd->bi_sramsize);
269 #endif 269 #endif
270 #if defined(CONFIG_SYS_MBAR) 270 #if defined(CONFIG_SYS_MBAR)
271 print_num("mbar", bd->bi_mbar_base); 271 print_num("mbar", bd->bi_mbar_base);
272 #endif 272 #endif
273 print_mhz("cpufreq", bd->bi_intfreq); 273 print_mhz("cpufreq", bd->bi_intfreq);
274 print_mhz("busfreq", bd->bi_busfreq); 274 print_mhz("busfreq", bd->bi_busfreq);
275 #ifdef CONFIG_PCI 275 #ifdef CONFIG_PCI
276 print_mhz("pcifreq", bd->bi_pcifreq); 276 print_mhz("pcifreq", bd->bi_pcifreq);
277 #endif 277 #endif
278 #ifdef CONFIG_EXTRA_CLOCK 278 #ifdef CONFIG_EXTRA_CLOCK
279 print_mhz("flbfreq", bd->bi_flbfreq); 279 print_mhz("flbfreq", bd->bi_flbfreq);
280 print_mhz("inpfreq", bd->bi_inpfreq); 280 print_mhz("inpfreq", bd->bi_inpfreq);
281 print_mhz("vcofreq", bd->bi_vcofreq); 281 print_mhz("vcofreq", bd->bi_vcofreq);
282 #endif 282 #endif
283 print_eth_ip_addr(); 283 print_eth_ip_addr();
284 print_baudrate(); 284 print_baudrate();
285 285
286 return 0; 286 return 0;
287 } 287 }
288 288
289 #elif defined(CONFIG_MIPS) 289 #elif defined(CONFIG_MIPS)
290 290
291 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 291 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
292 { 292 {
293 print_std_bdinfo(gd->bd); 293 print_std_bdinfo(gd->bd);
294 print_num("relocaddr", gd->relocaddr); 294 print_num("relocaddr", gd->relocaddr);
295 print_num("reloc off", gd->reloc_off); 295 print_num("reloc off", gd->reloc_off);
296 296
297 return 0; 297 return 0;
298 } 298 }
299 299
300 #elif defined(CONFIG_ARM) 300 #elif defined(CONFIG_ARM)
301 301
302 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, 302 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
303 char * const argv[]) 303 char * const argv[])
304 { 304 {
305 bd_t *bd = gd->bd; 305 bd_t *bd = gd->bd;
306 306
307 print_num("arch_number", bd->bi_arch_number); 307 print_num("arch_number", bd->bi_arch_number);
308 print_bi_boot_params(bd); 308 print_bi_boot_params(bd);
309 print_bi_dram(bd); 309 print_bi_dram(bd);
310 310
311 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE 311 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
312 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) { 312 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) {
313 print_num("Secure ram", 313 print_num("Secure ram",
314 gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK); 314 gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
315 } 315 }
316 #endif 316 #endif
317 #ifdef CONFIG_RESV_RAM 317 #ifdef CONFIG_RESV_RAM
318 if (gd->arch.resv_ram) 318 if (gd->arch.resv_ram)
319 print_num("Reserved ram", gd->arch.resv_ram); 319 print_num("Reserved ram", gd->arch.resv_ram);
320 #endif 320 #endif
321 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) 321 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
322 print_eths(); 322 print_eths();
323 #endif 323 #endif
324 print_baudrate(); 324 print_baudrate();
325 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) 325 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
326 print_num("TLB addr", gd->arch.tlb_addr); 326 print_num("TLB addr", gd->arch.tlb_addr);
327 #endif 327 #endif
328 print_num("relocaddr", gd->relocaddr); 328 print_num("relocaddr", gd->relocaddr);
329 print_num("reloc off", gd->reloc_off); 329 print_num("reloc off", gd->reloc_off);
330 print_num("irq_sp", gd->irq_sp); /* irq stack pointer */ 330 print_num("irq_sp", gd->irq_sp); /* irq stack pointer */
331 print_num("sp start ", gd->start_addr_sp); 331 print_num("sp start ", gd->start_addr_sp);
332 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 332 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
333 print_num("FB base ", gd->fb_base); 333 print_num("FB base ", gd->fb_base);
334 #endif 334 #endif
335 /* 335 /*
336 * TODO: Currently only support for davinci SOC's is added. 336 * TODO: Currently only support for davinci SOC's is added.
337 * Remove this check once all the board implement this. 337 * Remove this check once all the board implement this.
338 */ 338 */
339 #ifdef CONFIG_CLOCKS 339 #ifdef CONFIG_CLOCKS
340 printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq); 340 printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
341 printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq); 341 printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
342 printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq); 342 printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
343 #endif 343 #endif
344 #ifdef CONFIG_BOARD_TYPES 344 #ifdef CONFIG_BOARD_TYPES
345 printf("Board Type = %ld\n", gd->board_type); 345 printf("Board Type = %ld\n", gd->board_type);
346 #endif 346 #endif
347 #if CONFIG_VAL(SYS_MALLOC_F_LEN) 347 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
348 printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr, 348 printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr,
349 CONFIG_VAL(SYS_MALLOC_F_LEN)); 349 CONFIG_VAL(SYS_MALLOC_F_LEN));
350 #endif 350 #endif
351 if (gd->fdt_blob) 351 if (gd->fdt_blob)
352 printf("fdt_blob = %p\n", gd->fdt_blob); 352 printf("fdt_blob = %p\n", gd->fdt_blob);
353 353
354 return 0; 354 return 0;
355 } 355 }
356 356
357 #elif defined(CONFIG_SH) 357 #elif defined(CONFIG_SH)
358 358
359 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 359 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
360 { 360 {
361 bd_t *bd = gd->bd; 361 bd_t *bd = gd->bd;
362 362
363 print_bi_mem(bd); 363 print_bi_mem(bd);
364 print_bi_flash(bd); 364 print_bi_flash(bd);
365 print_eth_ip_addr(); 365 print_eth_ip_addr();
366 print_baudrate(); 366 print_baudrate();
367 return 0; 367 return 0;
368 } 368 }
369 369
370 #elif defined(CONFIG_X86) 370 #elif defined(CONFIG_X86)
371 371
372 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 372 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
373 { 373 {
374 bd_t *bd = gd->bd; 374 bd_t *bd = gd->bd;
375 375
376 print_bi_boot_params(bd); 376 print_bi_boot_params(bd);
377 377
378 print_bi_dram(bd); 378 print_bi_dram(bd);
379 379
380 #if defined(CONFIG_CMD_NET) 380 #if defined(CONFIG_CMD_NET)
381 print_eth_ip_addr(); 381 print_eth_ip_addr();
382 print_mhz("ethspeed", bd->bi_ethspeed); 382 print_mhz("ethspeed", bd->bi_ethspeed);
383 #endif 383 #endif
384 print_baudrate(); 384 print_baudrate();
385 385
386 return 0; 386 return 0;
387 } 387 }
388 388
389 #elif defined(CONFIG_SANDBOX) 389 #elif defined(CONFIG_SANDBOX)
390 390
391 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 391 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
392 { 392 {
393 bd_t *bd = gd->bd; 393 bd_t *bd = gd->bd;
394 394
395 print_bi_boot_params(bd); 395 print_bi_boot_params(bd);
396 print_bi_dram(bd); 396 print_bi_dram(bd);
397 print_eth_ip_addr(); 397 print_eth_ip_addr();
398 398
399 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 399 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
400 print_num("FB base ", gd->fb_base); 400 print_num("FB base ", gd->fb_base);
401 #endif 401 #endif
402 return 0; 402 return 0;
403 } 403 }
404 404
405 #elif defined(CONFIG_NDS32) 405 #elif defined(CONFIG_NDS32)
406 406
407 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 407 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
408 { 408 {
409 bd_t *bd = gd->bd; 409 bd_t *bd = gd->bd;
410 410
411 print_num("arch_number", bd->bi_arch_number); 411 print_num("arch_number", bd->bi_arch_number);
412 print_bi_boot_params(bd); 412 print_bi_boot_params(bd);
413 print_bi_dram(bd); 413 print_bi_dram(bd);
414 print_eth_ip_addr(); 414 print_eth_ip_addr();
415 print_baudrate(); 415 print_baudrate();
416 416
417 return 0; 417 return 0;
418 } 418 }
419 419
420 #elif defined(CONFIG_RISCV)
421
422 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
423 {
424 bd_t *bd = gd->bd;
425
426 print_num("arch_number", bd->bi_arch_number);
427 print_bi_boot_params(bd);
428 print_bi_dram(bd);
429 print_eth_ip_addr();
430 print_baudrate();
431
432 return 0;
433 }
434
420 #elif defined(CONFIG_ARC) 435 #elif defined(CONFIG_ARC)
421 436
422 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 437 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
423 { 438 {
424 bd_t *bd = gd->bd; 439 bd_t *bd = gd->bd;
425 440
426 print_bi_mem(bd); 441 print_bi_mem(bd);
427 print_eth_ip_addr(); 442 print_eth_ip_addr();
428 print_baudrate(); 443 print_baudrate();
429 444
430 return 0; 445 return 0;
431 } 446 }
432 447
433 #elif defined(CONFIG_XTENSA) 448 #elif defined(CONFIG_XTENSA)
434 449
435 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 450 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
436 { 451 {
437 print_std_bdinfo(gd->bd); 452 print_std_bdinfo(gd->bd);
438 return 0; 453 return 0;
439 } 454 }
440 455
441 #else 456 #else
442 #error "a case for this architecture does not exist!" 457 #error "a case for this architecture does not exist!"
443 #endif 458 #endif
444 459
445 /* -------------------------------------------------------------------- */ 460 /* -------------------------------------------------------------------- */
446 461
447 U_BOOT_CMD( 462 U_BOOT_CMD(
448 bdinfo, 1, 1, do_bdinfo, 463 bdinfo, 1, 1, do_bdinfo,
449 "print Board Info structure", 464 "print Board Info structure",
450 "" 465 ""
451 ); 466 );
452 467
1 /* 1 /*
2 * Copyright (c) 2011 The Chromium OS Authors. 2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006 3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * 5 *
6 * (C) Copyright 2002 6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> 7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de> 8 * Marius Groeger <mgroeger@sysgo.de>
9 * 9 *
10 * SPDX-License-Identifier: GPL-2.0+ 10 * SPDX-License-Identifier: GPL-2.0+
11 */ 11 */
12 12
13 #include <common.h> 13 #include <common.h>
14 #include <console.h> 14 #include <console.h>
15 #include <environment.h> 15 #include <environment.h>
16 #include <dm.h> 16 #include <dm.h>
17 #include <fdtdec.h> 17 #include <fdtdec.h>
18 #include <fs.h> 18 #include <fs.h>
19 #include <i2c.h> 19 #include <i2c.h>
20 #include <initcall.h> 20 #include <initcall.h>
21 #include <init_helpers.h> 21 #include <init_helpers.h>
22 #include <malloc.h> 22 #include <malloc.h>
23 #include <mapmem.h> 23 #include <mapmem.h>
24 #include <os.h> 24 #include <os.h>
25 #include <post.h> 25 #include <post.h>
26 #include <relocate.h> 26 #include <relocate.h>
27 #include <spi.h> 27 #include <spi.h>
28 #include <status_led.h> 28 #include <status_led.h>
29 #include <timer.h> 29 #include <timer.h>
30 #include <trace.h> 30 #include <trace.h>
31 #include <video.h> 31 #include <video.h>
32 #include <watchdog.h> 32 #include <watchdog.h>
33 #ifdef CONFIG_MACH_TYPE 33 #ifdef CONFIG_MACH_TYPE
34 #include <asm/mach-types.h> 34 #include <asm/mach-types.h>
35 #endif 35 #endif
36 #if defined(CONFIG_MP) && defined(CONFIG_PPC) 36 #if defined(CONFIG_MP) && defined(CONFIG_PPC)
37 #include <asm/mp.h> 37 #include <asm/mp.h>
38 #endif 38 #endif
39 #include <asm/io.h> 39 #include <asm/io.h>
40 #include <asm/sections.h> 40 #include <asm/sections.h>
41 #include <dm/root.h> 41 #include <dm/root.h>
42 #include <linux/errno.h> 42 #include <linux/errno.h>
43 43
44 /* 44 /*
45 * Pointer to initial global data area 45 * Pointer to initial global data area
46 * 46 *
47 * Here we initialize it if needed. 47 * Here we initialize it if needed.
48 */ 48 */
49 #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR 49 #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
50 #undef XTRN_DECLARE_GLOBAL_DATA_PTR 50 #undef XTRN_DECLARE_GLOBAL_DATA_PTR
51 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ 51 #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
52 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); 52 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
53 #else 53 #else
54 DECLARE_GLOBAL_DATA_PTR; 54 DECLARE_GLOBAL_DATA_PTR;
55 #endif 55 #endif
56 56
57 /* 57 /*
58 * TODO(sjg@chromium.org): IMO this code should be 58 * TODO(sjg@chromium.org): IMO this code should be
59 * refactored to a single function, something like: 59 * refactored to a single function, something like:
60 * 60 *
61 * void led_set_state(enum led_colour_t colour, int on); 61 * void led_set_state(enum led_colour_t colour, int on);
62 */ 62 */
63 /************************************************************************ 63 /************************************************************************
64 * Coloured LED functionality 64 * Coloured LED functionality
65 ************************************************************************ 65 ************************************************************************
66 * May be supplied by boards if desired 66 * May be supplied by boards if desired
67 */ 67 */
68 __weak void coloured_LED_init(void) {} 68 __weak void coloured_LED_init(void) {}
69 __weak void red_led_on(void) {} 69 __weak void red_led_on(void) {}
70 __weak void red_led_off(void) {} 70 __weak void red_led_off(void) {}
71 __weak void green_led_on(void) {} 71 __weak void green_led_on(void) {}
72 __weak void green_led_off(void) {} 72 __weak void green_led_off(void) {}
73 __weak void yellow_led_on(void) {} 73 __weak void yellow_led_on(void) {}
74 __weak void yellow_led_off(void) {} 74 __weak void yellow_led_off(void) {}
75 __weak void blue_led_on(void) {} 75 __weak void blue_led_on(void) {}
76 __weak void blue_led_off(void) {} 76 __weak void blue_led_off(void) {}
77 77
78 /* 78 /*
79 * Why is gd allocated a register? Prior to reloc it might be better to 79 * Why is gd allocated a register? Prior to reloc it might be better to
80 * just pass it around to each function in this file? 80 * just pass it around to each function in this file?
81 * 81 *
82 * After reloc one could argue that it is hardly used and doesn't need 82 * After reloc one could argue that it is hardly used and doesn't need
83 * to be in a register. Or if it is it should perhaps hold pointers to all 83 * to be in a register. Or if it is it should perhaps hold pointers to all
84 * global data for all modules, so that post-reloc we can avoid the massive 84 * global data for all modules, so that post-reloc we can avoid the massive
85 * literal pool we get on ARM. Or perhaps just encourage each module to use 85 * literal pool we get on ARM. Or perhaps just encourage each module to use
86 * a structure... 86 * a structure...
87 */ 87 */
88 88
89 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG) 89 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
90 static int init_func_watchdog_init(void) 90 static int init_func_watchdog_init(void)
91 { 91 {
92 # if defined(CONFIG_HW_WATCHDOG) && \ 92 # if defined(CONFIG_HW_WATCHDOG) && \
93 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \ 93 (defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
94 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \ 94 defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
95 defined(CONFIG_DESIGNWARE_WATCHDOG) || \ 95 defined(CONFIG_DESIGNWARE_WATCHDOG) || \
96 defined(CONFIG_IMX_WATCHDOG)) 96 defined(CONFIG_IMX_WATCHDOG))
97 hw_watchdog_init(); 97 hw_watchdog_init();
98 puts(" Watchdog enabled\n"); 98 puts(" Watchdog enabled\n");
99 # endif 99 # endif
100 WATCHDOG_RESET(); 100 WATCHDOG_RESET();
101 101
102 return 0; 102 return 0;
103 } 103 }
104 104
105 int init_func_watchdog_reset(void) 105 int init_func_watchdog_reset(void)
106 { 106 {
107 WATCHDOG_RESET(); 107 WATCHDOG_RESET();
108 108
109 return 0; 109 return 0;
110 } 110 }
111 #endif /* CONFIG_WATCHDOG */ 111 #endif /* CONFIG_WATCHDOG */
112 112
113 __weak void board_add_ram_info(int use_default) 113 __weak void board_add_ram_info(int use_default)
114 { 114 {
115 /* please define platform specific board_add_ram_info() */ 115 /* please define platform specific board_add_ram_info() */
116 } 116 }
117 117
118 static int init_baud_rate(void) 118 static int init_baud_rate(void)
119 { 119 {
120 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE); 120 gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
121 return 0; 121 return 0;
122 } 122 }
123 123
124 static int display_text_info(void) 124 static int display_text_info(void)
125 { 125 {
126 #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP) 126 #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
127 ulong bss_start, bss_end, text_base; 127 ulong bss_start, bss_end, text_base;
128 128
129 bss_start = (ulong)&__bss_start; 129 bss_start = (ulong)&__bss_start;
130 bss_end = (ulong)&__bss_end; 130 bss_end = (ulong)&__bss_end;
131 131
132 #ifdef CONFIG_SYS_TEXT_BASE 132 #ifdef CONFIG_SYS_TEXT_BASE
133 text_base = CONFIG_SYS_TEXT_BASE; 133 text_base = CONFIG_SYS_TEXT_BASE;
134 #else 134 #else
135 text_base = CONFIG_SYS_MONITOR_BASE; 135 text_base = CONFIG_SYS_MONITOR_BASE;
136 #endif 136 #endif
137 137
138 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", 138 debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
139 text_base, bss_start, bss_end); 139 text_base, bss_start, bss_end);
140 #endif 140 #endif
141 141
142 return 0; 142 return 0;
143 } 143 }
144 144
145 static int announce_dram_init(void) 145 static int announce_dram_init(void)
146 { 146 {
147 puts("DRAM: "); 147 puts("DRAM: ");
148 return 0; 148 return 0;
149 } 149 }
150 150
151 static int show_dram_config(void) 151 static int show_dram_config(void)
152 { 152 {
153 unsigned long long size; 153 unsigned long long size;
154 154
155 #ifdef CONFIG_NR_DRAM_BANKS 155 #ifdef CONFIG_NR_DRAM_BANKS
156 int i; 156 int i;
157 157
158 debug("\nRAM Configuration:\n"); 158 debug("\nRAM Configuration:\n");
159 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 159 for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
160 size += gd->bd->bi_dram[i].size; 160 size += gd->bd->bi_dram[i].size;
161 debug("Bank #%d: %llx ", i, 161 debug("Bank #%d: %llx ", i,
162 (unsigned long long)(gd->bd->bi_dram[i].start)); 162 (unsigned long long)(gd->bd->bi_dram[i].start));
163 #ifdef DEBUG 163 #ifdef DEBUG
164 print_size(gd->bd->bi_dram[i].size, "\n"); 164 print_size(gd->bd->bi_dram[i].size, "\n");
165 #endif 165 #endif
166 } 166 }
167 debug("\nDRAM: "); 167 debug("\nDRAM: ");
168 #else 168 #else
169 size = gd->ram_size; 169 size = gd->ram_size;
170 #endif 170 #endif
171 171
172 print_size(size, ""); 172 print_size(size, "");
173 board_add_ram_info(0); 173 board_add_ram_info(0);
174 putc('\n'); 174 putc('\n');
175 175
176 return 0; 176 return 0;
177 } 177 }
178 178
179 __weak int dram_init_banksize(void) 179 __weak int dram_init_banksize(void)
180 { 180 {
181 #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE) 181 #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
182 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; 182 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
183 gd->bd->bi_dram[0].size = get_effective_memsize(); 183 gd->bd->bi_dram[0].size = get_effective_memsize();
184 #endif 184 #endif
185 185
186 return 0; 186 return 0;
187 } 187 }
188 188
189 #if defined(CONFIG_SYS_I2C) 189 #if defined(CONFIG_SYS_I2C)
190 static int init_func_i2c(void) 190 static int init_func_i2c(void)
191 { 191 {
192 puts("I2C: "); 192 puts("I2C: ");
193 #ifdef CONFIG_SYS_I2C 193 #ifdef CONFIG_SYS_I2C
194 i2c_init_all(); 194 i2c_init_all();
195 #else 195 #else
196 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); 196 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
197 #endif 197 #endif
198 puts("ready\n"); 198 puts("ready\n");
199 return 0; 199 return 0;
200 } 200 }
201 #endif 201 #endif
202 202
203 #if defined(CONFIG_HARD_SPI) 203 #if defined(CONFIG_HARD_SPI)
204 static int init_func_spi(void) 204 static int init_func_spi(void)
205 { 205 {
206 puts("SPI: "); 206 puts("SPI: ");
207 spi_init(); 207 spi_init();
208 puts("ready\n"); 208 puts("ready\n");
209 return 0; 209 return 0;
210 } 210 }
211 #endif 211 #endif
212 212
213 static int setup_mon_len(void) 213 static int setup_mon_len(void)
214 { 214 {
215 #if defined(__ARM__) || defined(__MICROBLAZE__) 215 #if defined(__ARM__) || defined(__MICROBLAZE__)
216 gd->mon_len = (ulong)&__bss_end - (ulong)_start; 216 gd->mon_len = (ulong)&__bss_end - (ulong)_start;
217 #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) 217 #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
218 gd->mon_len = (ulong)&_end - (ulong)_init; 218 gd->mon_len = (ulong)&_end - (ulong)_init;
219 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA) 219 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
220 gd->mon_len = CONFIG_SYS_MONITOR_LEN; 220 gd->mon_len = CONFIG_SYS_MONITOR_LEN;
221 #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) 221 #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
222 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start); 222 gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
223 #elif defined(CONFIG_SYS_MONITOR_BASE) 223 #elif defined(CONFIG_SYS_MONITOR_BASE)
224 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ 224 /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
225 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; 225 gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
226 #endif 226 #endif
227 return 0; 227 return 0;
228 } 228 }
229 229
230 __weak int arch_cpu_init(void) 230 __weak int arch_cpu_init(void)
231 { 231 {
232 return 0; 232 return 0;
233 } 233 }
234 234
235 __weak int mach_cpu_init(void) 235 __weak int mach_cpu_init(void)
236 { 236 {
237 return 0; 237 return 0;
238 } 238 }
239 239
240 /* Get the top of usable RAM */ 240 /* Get the top of usable RAM */
241 __weak ulong board_get_usable_ram_top(ulong total_size) 241 __weak ulong board_get_usable_ram_top(ulong total_size)
242 { 242 {
243 #ifdef CONFIG_SYS_SDRAM_BASE 243 #ifdef CONFIG_SYS_SDRAM_BASE
244 /* 244 /*
245 * Detect whether we have so much RAM that it goes past the end of our 245 * Detect whether we have so much RAM that it goes past the end of our
246 * 32-bit address space. If so, clip the usable RAM so it doesn't. 246 * 32-bit address space. If so, clip the usable RAM so it doesn't.
247 */ 247 */
248 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE) 248 if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
249 /* 249 /*
250 * Will wrap back to top of 32-bit space when reservations 250 * Will wrap back to top of 32-bit space when reservations
251 * are made. 251 * are made.
252 */ 252 */
253 return 0; 253 return 0;
254 #endif 254 #endif
255 return gd->ram_top; 255 return gd->ram_top;
256 } 256 }
257 257
258 static int setup_dest_addr(void) 258 static int setup_dest_addr(void)
259 { 259 {
260 debug("Monitor len: %08lX\n", gd->mon_len); 260 debug("Monitor len: %08lX\n", gd->mon_len);
261 /* 261 /*
262 * Ram is setup, size stored in gd !! 262 * Ram is setup, size stored in gd !!
263 */ 263 */
264 debug("Ram size: %08lX\n", (ulong)gd->ram_size); 264 debug("Ram size: %08lX\n", (ulong)gd->ram_size);
265 #if defined(CONFIG_SYS_MEM_TOP_HIDE) 265 #if defined(CONFIG_SYS_MEM_TOP_HIDE)
266 /* 266 /*
267 * Subtract specified amount of memory to hide so that it won't 267 * Subtract specified amount of memory to hide so that it won't
268 * get "touched" at all by U-Boot. By fixing up gd->ram_size 268 * get "touched" at all by U-Boot. By fixing up gd->ram_size
269 * the Linux kernel should now get passed the now "corrected" 269 * the Linux kernel should now get passed the now "corrected"
270 * memory size and won't touch it either. This should work 270 * memory size and won't touch it either. This should work
271 * for arch/ppc and arch/powerpc. Only Linux board ports in 271 * for arch/ppc and arch/powerpc. Only Linux board ports in
272 * arch/powerpc with bootwrapper support, that recalculate the 272 * arch/powerpc with bootwrapper support, that recalculate the
273 * memory size from the SDRAM controller setup will have to 273 * memory size from the SDRAM controller setup will have to
274 * get fixed. 274 * get fixed.
275 */ 275 */
276 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE; 276 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
277 #endif 277 #endif
278 #ifdef CONFIG_SYS_SDRAM_BASE 278 #ifdef CONFIG_SYS_SDRAM_BASE
279 gd->ram_top = CONFIG_SYS_SDRAM_BASE; 279 gd->ram_top = CONFIG_SYS_SDRAM_BASE;
280 #endif 280 #endif
281 gd->ram_top += get_effective_memsize(); 281 gd->ram_top += get_effective_memsize();
282 gd->ram_top = board_get_usable_ram_top(gd->mon_len); 282 gd->ram_top = board_get_usable_ram_top(gd->mon_len);
283 gd->relocaddr = gd->ram_top; 283 gd->relocaddr = gd->ram_top;
284 debug("Ram top: %08lX\n", (ulong)gd->ram_top); 284 debug("Ram top: %08lX\n", (ulong)gd->ram_top);
285 #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500)) 285 #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
286 /* 286 /*
287 * We need to make sure the location we intend to put secondary core 287 * We need to make sure the location we intend to put secondary core
288 * boot code is reserved and not used by any part of u-boot 288 * boot code is reserved and not used by any part of u-boot
289 */ 289 */
290 if (gd->relocaddr > determine_mp_bootpg(NULL)) { 290 if (gd->relocaddr > determine_mp_bootpg(NULL)) {
291 gd->relocaddr = determine_mp_bootpg(NULL); 291 gd->relocaddr = determine_mp_bootpg(NULL);
292 debug("Reserving MP boot page to %08lx\n", gd->relocaddr); 292 debug("Reserving MP boot page to %08lx\n", gd->relocaddr);
293 } 293 }
294 #endif 294 #endif
295 return 0; 295 return 0;
296 } 296 }
297 297
298 #ifdef CONFIG_PRAM 298 #ifdef CONFIG_PRAM
299 /* reserve protected RAM */ 299 /* reserve protected RAM */
300 static int reserve_pram(void) 300 static int reserve_pram(void)
301 { 301 {
302 ulong reg; 302 ulong reg;
303 303
304 reg = env_get_ulong("pram", 10, CONFIG_PRAM); 304 reg = env_get_ulong("pram", 10, CONFIG_PRAM);
305 gd->relocaddr -= (reg << 10); /* size is in kB */ 305 gd->relocaddr -= (reg << 10); /* size is in kB */
306 debug("Reserving %ldk for protected RAM at %08lx\n", reg, 306 debug("Reserving %ldk for protected RAM at %08lx\n", reg,
307 gd->relocaddr); 307 gd->relocaddr);
308 return 0; 308 return 0;
309 } 309 }
310 #endif /* CONFIG_PRAM */ 310 #endif /* CONFIG_PRAM */
311 311
312 /* Round memory pointer down to next 4 kB limit */ 312 /* Round memory pointer down to next 4 kB limit */
313 static int reserve_round_4k(void) 313 static int reserve_round_4k(void)
314 { 314 {
315 gd->relocaddr &= ~(4096 - 1); 315 gd->relocaddr &= ~(4096 - 1);
316 return 0; 316 return 0;
317 } 317 }
318 318
319 #ifdef CONFIG_ARM 319 #ifdef CONFIG_ARM
320 __weak int reserve_mmu(void) 320 __weak int reserve_mmu(void)
321 { 321 {
322 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) 322 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
323 /* reserve TLB table */ 323 /* reserve TLB table */
324 gd->arch.tlb_size = PGTABLE_SIZE; 324 gd->arch.tlb_size = PGTABLE_SIZE;
325 gd->relocaddr -= gd->arch.tlb_size; 325 gd->relocaddr -= gd->arch.tlb_size;
326 326
327 /* round down to next 64 kB limit */ 327 /* round down to next 64 kB limit */
328 gd->relocaddr &= ~(0x10000 - 1); 328 gd->relocaddr &= ~(0x10000 - 1);
329 329
330 gd->arch.tlb_addr = gd->relocaddr; 330 gd->arch.tlb_addr = gd->relocaddr;
331 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr, 331 debug("TLB table from %08lx to %08lx\n", gd->arch.tlb_addr,
332 gd->arch.tlb_addr + gd->arch.tlb_size); 332 gd->arch.tlb_addr + gd->arch.tlb_size);
333 333
334 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE 334 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
335 /* 335 /*
336 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten 336 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
337 * with location within secure ram. 337 * with location within secure ram.
338 */ 338 */
339 gd->arch.tlb_allocated = gd->arch.tlb_addr; 339 gd->arch.tlb_allocated = gd->arch.tlb_addr;
340 #endif 340 #endif
341 #endif 341 #endif
342 342
343 return 0; 343 return 0;
344 } 344 }
345 #endif 345 #endif
346 346
347 static int reserve_video(void) 347 static int reserve_video(void)
348 { 348 {
349 #ifdef CONFIG_DM_VIDEO 349 #ifdef CONFIG_DM_VIDEO
350 ulong addr; 350 ulong addr;
351 int ret; 351 int ret;
352 352
353 addr = gd->relocaddr; 353 addr = gd->relocaddr;
354 ret = video_reserve(&addr); 354 ret = video_reserve(&addr);
355 if (ret) 355 if (ret)
356 return ret; 356 return ret;
357 gd->relocaddr = addr; 357 gd->relocaddr = addr;
358 #elif defined(CONFIG_LCD) 358 #elif defined(CONFIG_LCD)
359 # ifdef CONFIG_FB_ADDR 359 # ifdef CONFIG_FB_ADDR
360 gd->fb_base = CONFIG_FB_ADDR; 360 gd->fb_base = CONFIG_FB_ADDR;
361 # else 361 # else
362 /* reserve memory for LCD display (always full pages) */ 362 /* reserve memory for LCD display (always full pages) */
363 gd->relocaddr = lcd_setmem(gd->relocaddr); 363 gd->relocaddr = lcd_setmem(gd->relocaddr);
364 gd->fb_base = gd->relocaddr; 364 gd->fb_base = gd->relocaddr;
365 # endif /* CONFIG_FB_ADDR */ 365 # endif /* CONFIG_FB_ADDR */
366 #elif defined(CONFIG_VIDEO) && \ 366 #elif defined(CONFIG_VIDEO) && \
367 (!defined(CONFIG_PPC)) && \ 367 (!defined(CONFIG_PPC)) && \
368 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \ 368 !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
369 !defined(CONFIG_M68K) 369 !defined(CONFIG_M68K)
370 /* reserve memory for video display (always full pages) */ 370 /* reserve memory for video display (always full pages) */
371 gd->relocaddr = video_setmem(gd->relocaddr); 371 gd->relocaddr = video_setmem(gd->relocaddr);
372 gd->fb_base = gd->relocaddr; 372 gd->fb_base = gd->relocaddr;
373 #endif 373 #endif
374 374
375 return 0; 375 return 0;
376 } 376 }
377 377
378 static int reserve_trace(void) 378 static int reserve_trace(void)
379 { 379 {
380 #ifdef CONFIG_TRACE 380 #ifdef CONFIG_TRACE
381 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE; 381 gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
382 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE); 382 gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
383 debug("Reserving %dk for trace data at: %08lx\n", 383 debug("Reserving %dk for trace data at: %08lx\n",
384 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr); 384 CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
385 #endif 385 #endif
386 386
387 return 0; 387 return 0;
388 } 388 }
389 389
390 static int reserve_uboot(void) 390 static int reserve_uboot(void)
391 { 391 {
392 /* 392 /*
393 * reserve memory for U-Boot code, data & bss 393 * reserve memory for U-Boot code, data & bss
394 * round down to next 4 kB limit 394 * round down to next 4 kB limit
395 */ 395 */
396 gd->relocaddr -= gd->mon_len; 396 gd->relocaddr -= gd->mon_len;
397 gd->relocaddr &= ~(4096 - 1); 397 gd->relocaddr &= ~(4096 - 1);
398 #if defined(CONFIG_E500) || defined(CONFIG_MIPS) 398 #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
399 /* round down to next 64 kB limit so that IVPR stays aligned */ 399 /* round down to next 64 kB limit so that IVPR stays aligned */
400 gd->relocaddr &= ~(65536 - 1); 400 gd->relocaddr &= ~(65536 - 1);
401 #endif 401 #endif
402 402
403 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, 403 debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10,
404 gd->relocaddr); 404 gd->relocaddr);
405 405
406 gd->start_addr_sp = gd->relocaddr; 406 gd->start_addr_sp = gd->relocaddr;
407 407
408 return 0; 408 return 0;
409 } 409 }
410 410
411 /* reserve memory for malloc() area */ 411 /* reserve memory for malloc() area */
412 static int reserve_malloc(void) 412 static int reserve_malloc(void)
413 { 413 {
414 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; 414 gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
415 debug("Reserving %dk for malloc() at: %08lx\n", 415 debug("Reserving %dk for malloc() at: %08lx\n",
416 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); 416 TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
417 return 0; 417 return 0;
418 } 418 }
419 419
420 /* (permanently) allocate a Board Info struct */ 420 /* (permanently) allocate a Board Info struct */
421 static int reserve_board(void) 421 static int reserve_board(void)
422 { 422 {
423 if (!gd->bd) { 423 if (!gd->bd) {
424 gd->start_addr_sp -= sizeof(bd_t); 424 gd->start_addr_sp -= sizeof(bd_t);
425 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t)); 425 gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
426 memset(gd->bd, '\0', sizeof(bd_t)); 426 memset(gd->bd, '\0', sizeof(bd_t));
427 debug("Reserving %zu Bytes for Board Info at: %08lx\n", 427 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
428 sizeof(bd_t), gd->start_addr_sp); 428 sizeof(bd_t), gd->start_addr_sp);
429 } 429 }
430 return 0; 430 return 0;
431 } 431 }
432 432
433 static int setup_machine(void) 433 static int setup_machine(void)
434 { 434 {
435 #ifdef CONFIG_MACH_TYPE 435 #ifdef CONFIG_MACH_TYPE
436 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ 436 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
437 #endif 437 #endif
438 return 0; 438 return 0;
439 } 439 }
440 440
441 static int reserve_global_data(void) 441 static int reserve_global_data(void)
442 { 442 {
443 gd->start_addr_sp -= sizeof(gd_t); 443 gd->start_addr_sp -= sizeof(gd_t);
444 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t)); 444 gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
445 debug("Reserving %zu Bytes for Global Data at: %08lx\n", 445 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
446 sizeof(gd_t), gd->start_addr_sp); 446 sizeof(gd_t), gd->start_addr_sp);
447 return 0; 447 return 0;
448 } 448 }
449 449
450 static int reserve_fdt(void) 450 static int reserve_fdt(void)
451 { 451 {
452 #ifndef CONFIG_OF_EMBED 452 #ifndef CONFIG_OF_EMBED
453 /* 453 /*
454 * If the device tree is sitting immediately above our image then we 454 * If the device tree is sitting immediately above our image then we
455 * must relocate it. If it is embedded in the data section, then it 455 * must relocate it. If it is embedded in the data section, then it
456 * will be relocated with other data. 456 * will be relocated with other data.
457 */ 457 */
458 if (gd->fdt_blob) { 458 if (gd->fdt_blob) {
459 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); 459 gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
460 460
461 gd->start_addr_sp -= gd->fdt_size; 461 gd->start_addr_sp -= gd->fdt_size;
462 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); 462 gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
463 debug("Reserving %lu Bytes for FDT at: %08lx\n", 463 debug("Reserving %lu Bytes for FDT at: %08lx\n",
464 gd->fdt_size, gd->start_addr_sp); 464 gd->fdt_size, gd->start_addr_sp);
465 } 465 }
466 #endif 466 #endif
467 467
468 return 0; 468 return 0;
469 } 469 }
470 470
471 static int reserve_bootstage(void) 471 static int reserve_bootstage(void)
472 { 472 {
473 #ifdef CONFIG_BOOTSTAGE 473 #ifdef CONFIG_BOOTSTAGE
474 int size = bootstage_get_size(); 474 int size = bootstage_get_size();
475 475
476 gd->start_addr_sp -= size; 476 gd->start_addr_sp -= size;
477 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size); 477 gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
478 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size, 478 debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
479 gd->start_addr_sp); 479 gd->start_addr_sp);
480 #endif 480 #endif
481 481
482 return 0; 482 return 0;
483 } 483 }
484 484
485 int arch_reserve_stacks(void) 485 int arch_reserve_stacks(void)
486 { 486 {
487 return 0; 487 return 0;
488 } 488 }
489 489
490 static int reserve_stacks(void) 490 static int reserve_stacks(void)
491 { 491 {
492 /* make stack pointer 16-byte aligned */ 492 /* make stack pointer 16-byte aligned */
493 gd->start_addr_sp -= 16; 493 gd->start_addr_sp -= 16;
494 gd->start_addr_sp &= ~0xf; 494 gd->start_addr_sp &= ~0xf;
495 495
496 /* 496 /*
497 * let the architecture-specific code tailor gd->start_addr_sp and 497 * let the architecture-specific code tailor gd->start_addr_sp and
498 * gd->irq_sp 498 * gd->irq_sp
499 */ 499 */
500 return arch_reserve_stacks(); 500 return arch_reserve_stacks();
501 } 501 }
502 502
503 static int display_new_sp(void) 503 static int display_new_sp(void)
504 { 504 {
505 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp); 505 debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
506 506
507 return 0; 507 return 0;
508 } 508 }
509 509
510 #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ 510 #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
511 defined(CONFIG_SH) 511 defined(CONFIG_SH)
512 static int setup_board_part1(void) 512 static int setup_board_part1(void)
513 { 513 {
514 bd_t *bd = gd->bd; 514 bd_t *bd = gd->bd;
515 515
516 /* 516 /*
517 * Save local variables to board info struct 517 * Save local variables to board info struct
518 */ 518 */
519 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */ 519 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of memory */
520 bd->bi_memsize = gd->ram_size; /* size in bytes */ 520 bd->bi_memsize = gd->ram_size; /* size in bytes */
521 521
522 #ifdef CONFIG_SYS_SRAM_BASE 522 #ifdef CONFIG_SYS_SRAM_BASE
523 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */ 523 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
524 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ 524 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
525 #endif 525 #endif
526 526
527 #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx) 527 #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
528 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */ 528 bd->bi_immr_base = CONFIG_SYS_IMMR; /* base of IMMR register */
529 #endif 529 #endif
530 #if defined(CONFIG_M68K) 530 #if defined(CONFIG_M68K)
531 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */ 531 bd->bi_mbar_base = CONFIG_SYS_MBAR; /* base of internal registers */
532 #endif 532 #endif
533 #if defined(CONFIG_MPC83xx) 533 #if defined(CONFIG_MPC83xx)
534 bd->bi_immrbar = CONFIG_SYS_IMMR; 534 bd->bi_immrbar = CONFIG_SYS_IMMR;
535 #endif 535 #endif
536 536
537 return 0; 537 return 0;
538 } 538 }
539 #endif 539 #endif
540 540
541 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) 541 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
542 static int setup_board_part2(void) 542 static int setup_board_part2(void)
543 { 543 {
544 bd_t *bd = gd->bd; 544 bd_t *bd = gd->bd;
545 545
546 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */ 546 bd->bi_intfreq = gd->cpu_clk; /* Internal Freq, in Hz */
547 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */ 547 bd->bi_busfreq = gd->bus_clk; /* Bus Freq, in Hz */
548 #if defined(CONFIG_CPM2) 548 #if defined(CONFIG_CPM2)
549 bd->bi_cpmfreq = gd->arch.cpm_clk; 549 bd->bi_cpmfreq = gd->arch.cpm_clk;
550 bd->bi_brgfreq = gd->arch.brg_clk; 550 bd->bi_brgfreq = gd->arch.brg_clk;
551 bd->bi_sccfreq = gd->arch.scc_clk; 551 bd->bi_sccfreq = gd->arch.scc_clk;
552 bd->bi_vco = gd->arch.vco_out; 552 bd->bi_vco = gd->arch.vco_out;
553 #endif /* CONFIG_CPM2 */ 553 #endif /* CONFIG_CPM2 */
554 #if defined(CONFIG_M68K) && defined(CONFIG_PCI) 554 #if defined(CONFIG_M68K) && defined(CONFIG_PCI)
555 bd->bi_pcifreq = gd->pci_clk; 555 bd->bi_pcifreq = gd->pci_clk;
556 #endif 556 #endif
557 #if defined(CONFIG_EXTRA_CLOCK) 557 #if defined(CONFIG_EXTRA_CLOCK)
558 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */ 558 bd->bi_inpfreq = gd->arch.inp_clk; /* input Freq in Hz */
559 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */ 559 bd->bi_vcofreq = gd->arch.vco_clk; /* vco Freq in Hz */
560 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */ 560 bd->bi_flbfreq = gd->arch.flb_clk; /* flexbus Freq in Hz */
561 #endif 561 #endif
562 562
563 return 0; 563 return 0;
564 } 564 }
565 #endif 565 #endif
566 566
567 #ifdef CONFIG_POST 567 #ifdef CONFIG_POST
568 static int init_post(void) 568 static int init_post(void)
569 { 569 {
570 post_bootmode_init(); 570 post_bootmode_init();
571 post_run(NULL, POST_ROM | post_bootmode_get(0)); 571 post_run(NULL, POST_ROM | post_bootmode_get(0));
572 572
573 return 0; 573 return 0;
574 } 574 }
575 #endif 575 #endif
576 576
577 static int reloc_fdt(void) 577 static int reloc_fdt(void)
578 { 578 {
579 #ifndef CONFIG_OF_EMBED 579 #ifndef CONFIG_OF_EMBED
580 if (gd->flags & GD_FLG_SKIP_RELOC) 580 if (gd->flags & GD_FLG_SKIP_RELOC)
581 return 0; 581 return 0;
582 if (gd->new_fdt) { 582 if (gd->new_fdt) {
583 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); 583 memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
584 gd->fdt_blob = gd->new_fdt; 584 gd->fdt_blob = gd->new_fdt;
585 } 585 }
586 #endif 586 #endif
587 587
588 return 0; 588 return 0;
589 } 589 }
590 590
591 static int reloc_bootstage(void) 591 static int reloc_bootstage(void)
592 { 592 {
593 #ifdef CONFIG_BOOTSTAGE 593 #ifdef CONFIG_BOOTSTAGE
594 if (gd->flags & GD_FLG_SKIP_RELOC) 594 if (gd->flags & GD_FLG_SKIP_RELOC)
595 return 0; 595 return 0;
596 if (gd->new_bootstage) { 596 if (gd->new_bootstage) {
597 int size = bootstage_get_size(); 597 int size = bootstage_get_size();
598 598
599 debug("Copying bootstage from %p to %p, size %x\n", 599 debug("Copying bootstage from %p to %p, size %x\n",
600 gd->bootstage, gd->new_bootstage, size); 600 gd->bootstage, gd->new_bootstage, size);
601 memcpy(gd->new_bootstage, gd->bootstage, size); 601 memcpy(gd->new_bootstage, gd->bootstage, size);
602 gd->bootstage = gd->new_bootstage; 602 gd->bootstage = gd->new_bootstage;
603 } 603 }
604 #endif 604 #endif
605 605
606 return 0; 606 return 0;
607 } 607 }
608 608
609 static int setup_reloc(void) 609 static int setup_reloc(void)
610 { 610 {
611 if (gd->flags & GD_FLG_SKIP_RELOC) { 611 if (gd->flags & GD_FLG_SKIP_RELOC) {
612 debug("Skipping relocation due to flag\n"); 612 debug("Skipping relocation due to flag\n");
613 return 0; 613 return 0;
614 } 614 }
615 615
616 #ifdef CONFIG_SYS_TEXT_BASE 616 #ifdef CONFIG_SYS_TEXT_BASE
617 #ifdef ARM 617 #ifdef ARM
618 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start; 618 gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
619 #elif defined(CONFIG_M68K) 619 #elif defined(CONFIG_M68K)
620 /* 620 /*
621 * On all ColdFire arch cpu, monitor code starts always 621 * On all ColdFire arch cpu, monitor code starts always
622 * just after the default vector table location, so at 0x400 622 * just after the default vector table location, so at 0x400
623 */ 623 */
624 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400); 624 gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
625 #else 625 #else
626 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE; 626 gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
627 #endif 627 #endif
628 #endif 628 #endif
629 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); 629 memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
630 630
631 debug("Relocation Offset is: %08lx\n", gd->reloc_off); 631 debug("Relocation Offset is: %08lx\n", gd->reloc_off);
632 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", 632 debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
633 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd), 633 gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
634 gd->start_addr_sp); 634 gd->start_addr_sp);
635 635
636 return 0; 636 return 0;
637 } 637 }
638 638
639 #ifdef CONFIG_OF_BOARD_FIXUP 639 #ifdef CONFIG_OF_BOARD_FIXUP
640 static int fix_fdt(void) 640 static int fix_fdt(void)
641 { 641 {
642 return board_fix_fdt((void *)gd->fdt_blob); 642 return board_fix_fdt((void *)gd->fdt_blob);
643 } 643 }
644 #endif 644 #endif
645 645
646 /* ARM calls relocate_code from its crt0.S */ 646 /* ARM calls relocate_code from its crt0.S */
647 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ 647 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
648 !CONFIG_IS_ENABLED(X86_64) 648 !CONFIG_IS_ENABLED(X86_64)
649 649
650 static int jump_to_copy(void) 650 static int jump_to_copy(void)
651 { 651 {
652 if (gd->flags & GD_FLG_SKIP_RELOC) 652 if (gd->flags & GD_FLG_SKIP_RELOC)
653 return 0; 653 return 0;
654 /* 654 /*
655 * x86 is special, but in a nice way. It uses a trampoline which 655 * x86 is special, but in a nice way. It uses a trampoline which
656 * enables the dcache if possible. 656 * enables the dcache if possible.
657 * 657 *
658 * For now, other archs use relocate_code(), which is implemented 658 * For now, other archs use relocate_code(), which is implemented
659 * similarly for all archs. When we do generic relocation, hopefully 659 * similarly for all archs. When we do generic relocation, hopefully
660 * we can make all archs enable the dcache prior to relocation. 660 * we can make all archs enable the dcache prior to relocation.
661 */ 661 */
662 #if defined(CONFIG_X86) || defined(CONFIG_ARC) 662 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
663 /* 663 /*
664 * SDRAM and console are now initialised. The final stack can now 664 * SDRAM and console are now initialised. The final stack can now
665 * be setup in SDRAM. Code execution will continue in Flash, but 665 * be setup in SDRAM. Code execution will continue in Flash, but
666 * with the stack in SDRAM and Global Data in temporary memory 666 * with the stack in SDRAM and Global Data in temporary memory
667 * (CPU cache) 667 * (CPU cache)
668 */ 668 */
669 arch_setup_gd(gd->new_gd); 669 arch_setup_gd(gd->new_gd);
670 board_init_f_r_trampoline(gd->start_addr_sp); 670 board_init_f_r_trampoline(gd->start_addr_sp);
671 #else 671 #else
672 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr); 672 relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
673 #endif 673 #endif
674 674
675 return 0; 675 return 0;
676 } 676 }
677 #endif 677 #endif
678 678
679 /* Record the board_init_f() bootstage (after arch_cpu_init()) */ 679 /* Record the board_init_f() bootstage (after arch_cpu_init()) */
680 static int initf_bootstage(void) 680 static int initf_bootstage(void)
681 { 681 {
682 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) && 682 bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
683 IS_ENABLED(CONFIG_BOOTSTAGE_STASH); 683 IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
684 int ret; 684 int ret;
685 685
686 ret = bootstage_init(!from_spl); 686 ret = bootstage_init(!from_spl);
687 if (ret) 687 if (ret)
688 return ret; 688 return ret;
689 if (from_spl) { 689 if (from_spl) {
690 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR, 690 const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
691 CONFIG_BOOTSTAGE_STASH_SIZE); 691 CONFIG_BOOTSTAGE_STASH_SIZE);
692 692
693 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE); 693 ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
694 if (ret && ret != -ENOENT) { 694 if (ret && ret != -ENOENT) {
695 debug("Failed to unstash bootstage: err=%d\n", ret); 695 debug("Failed to unstash bootstage: err=%d\n", ret);
696 return ret; 696 return ret;
697 } 697 }
698 } 698 }
699 699
700 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f"); 700 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
701 701
702 return 0; 702 return 0;
703 } 703 }
704 704
705 static int initf_console_record(void) 705 static int initf_console_record(void)
706 { 706 {
707 #if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN) 707 #if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
708 return console_record_init(); 708 return console_record_init();
709 #else 709 #else
710 return 0; 710 return 0;
711 #endif 711 #endif
712 } 712 }
713 713
714 static int initf_dm(void) 714 static int initf_dm(void)
715 { 715 {
716 #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN) 716 #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
717 int ret; 717 int ret;
718 718
719 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f"); 719 bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
720 ret = dm_init_and_scan(true); 720 ret = dm_init_and_scan(true);
721 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F); 721 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
722 if (ret) 722 if (ret)
723 return ret; 723 return ret;
724 #endif 724 #endif
725 #ifdef CONFIG_TIMER_EARLY 725 #ifdef CONFIG_TIMER_EARLY
726 ret = dm_timer_init(); 726 ret = dm_timer_init();
727 if (ret) 727 if (ret)
728 return ret; 728 return ret;
729 #endif 729 #endif
730 730
731 return 0; 731 return 0;
732 } 732 }
733 733
734 /* Architecture-specific memory reservation */ 734 /* Architecture-specific memory reservation */
735 __weak int reserve_arch(void) 735 __weak int reserve_arch(void)
736 { 736 {
737 return 0; 737 return 0;
738 } 738 }
739 739
740 __weak int arch_cpu_init_dm(void) 740 __weak int arch_cpu_init_dm(void)
741 { 741 {
742 return 0; 742 return 0;
743 } 743 }
744 744
745 static const init_fnc_t init_sequence_f[] = { 745 static const init_fnc_t init_sequence_f[] = {
746 setup_mon_len, 746 setup_mon_len,
747 #ifdef CONFIG_OF_CONTROL 747 #ifdef CONFIG_OF_CONTROL
748 fdtdec_setup, 748 fdtdec_setup,
749 #endif 749 #endif
750 #ifdef CONFIG_TRACE 750 #ifdef CONFIG_TRACE
751 trace_early_init, 751 trace_early_init,
752 #endif 752 #endif
753 initf_malloc, 753 initf_malloc,
754 log_init, 754 log_init,
755 initf_bootstage, /* uses its own timer, so does not need DM */ 755 initf_bootstage, /* uses its own timer, so does not need DM */
756 initf_console_record, 756 initf_console_record,
757 #if defined(CONFIG_HAVE_FSP) 757 #if defined(CONFIG_HAVE_FSP)
758 arch_fsp_init, 758 arch_fsp_init,
759 #endif 759 #endif
760 arch_cpu_init, /* basic arch cpu dependent setup */ 760 arch_cpu_init, /* basic arch cpu dependent setup */
761 mach_cpu_init, /* SoC/machine dependent CPU setup */ 761 mach_cpu_init, /* SoC/machine dependent CPU setup */
762 initf_dm, 762 initf_dm,
763 arch_cpu_init_dm, 763 arch_cpu_init_dm,
764 #if defined(CONFIG_BOARD_EARLY_INIT_F) 764 #if defined(CONFIG_BOARD_EARLY_INIT_F)
765 board_early_init_f, 765 board_early_init_f,
766 #endif 766 #endif
767 #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K) 767 #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
768 /* get CPU and bus clocks according to the environment variable */ 768 /* get CPU and bus clocks according to the environment variable */
769 get_clocks, /* get CPU and bus clocks (etc.) */ 769 get_clocks, /* get CPU and bus clocks (etc.) */
770 #endif 770 #endif
771 #if !defined(CONFIG_M68K) 771 #if !defined(CONFIG_M68K)
772 timer_init, /* initialize timer */ 772 timer_init, /* initialize timer */
773 #endif 773 #endif
774 #if defined(CONFIG_BOARD_POSTCLK_INIT) 774 #if defined(CONFIG_BOARD_POSTCLK_INIT)
775 board_postclk_init, 775 board_postclk_init,
776 #endif 776 #endif
777 env_init, /* initialize environment */ 777 env_init, /* initialize environment */
778 init_baud_rate, /* initialze baudrate settings */ 778 init_baud_rate, /* initialze baudrate settings */
779 serial_init, /* serial communications setup */ 779 serial_init, /* serial communications setup */
780 console_init_f, /* stage 1 init of console */ 780 console_init_f, /* stage 1 init of console */
781 display_options, /* say that we are here */ 781 display_options, /* say that we are here */
782 display_text_info, /* show debugging info if required */ 782 display_text_info, /* show debugging info if required */
783 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \ 783 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \
784 defined(CONFIG_X86) 784 defined(CONFIG_X86)
785 checkcpu, 785 checkcpu,
786 #endif 786 #endif
787 #if defined(CONFIG_DISPLAY_CPUINFO) 787 #if defined(CONFIG_DISPLAY_CPUINFO)
788 print_cpuinfo, /* display cpu info (and speed) */ 788 print_cpuinfo, /* display cpu info (and speed) */
789 #endif 789 #endif
790 #if defined(CONFIG_DTB_RESELECT) 790 #if defined(CONFIG_DTB_RESELECT)
791 embedded_dtb_select, 791 embedded_dtb_select,
792 #endif 792 #endif
793 #if defined(CONFIG_DISPLAY_BOARDINFO) 793 #if defined(CONFIG_DISPLAY_BOARDINFO)
794 show_board_info, 794 show_board_info,
795 #endif 795 #endif
796 INIT_FUNC_WATCHDOG_INIT 796 INIT_FUNC_WATCHDOG_INIT
797 #if defined(CONFIG_MISC_INIT_F) 797 #if defined(CONFIG_MISC_INIT_F)
798 misc_init_f, 798 misc_init_f,
799 #endif 799 #endif
800 INIT_FUNC_WATCHDOG_RESET 800 INIT_FUNC_WATCHDOG_RESET
801 #if defined(CONFIG_SYS_I2C) 801 #if defined(CONFIG_SYS_I2C)
802 init_func_i2c, 802 init_func_i2c,
803 #endif 803 #endif
804 #if defined(CONFIG_HARD_SPI) 804 #if defined(CONFIG_HARD_SPI)
805 init_func_spi, 805 init_func_spi,
806 #endif 806 #endif
807 announce_dram_init, 807 announce_dram_init,
808 dram_init, /* configure available RAM banks */ 808 dram_init, /* configure available RAM banks */
809 #ifdef CONFIG_POST 809 #ifdef CONFIG_POST
810 post_init_f, 810 post_init_f,
811 #endif 811 #endif
812 INIT_FUNC_WATCHDOG_RESET 812 INIT_FUNC_WATCHDOG_RESET
813 #if defined(CONFIG_SYS_DRAM_TEST) 813 #if defined(CONFIG_SYS_DRAM_TEST)
814 testdram, 814 testdram,
815 #endif /* CONFIG_SYS_DRAM_TEST */ 815 #endif /* CONFIG_SYS_DRAM_TEST */
816 INIT_FUNC_WATCHDOG_RESET 816 INIT_FUNC_WATCHDOG_RESET
817 817
818 #ifdef CONFIG_POST 818 #ifdef CONFIG_POST
819 init_post, 819 init_post,
820 #endif 820 #endif
821 INIT_FUNC_WATCHDOG_RESET 821 INIT_FUNC_WATCHDOG_RESET
822 /* 822 /*
823 * Now that we have DRAM mapped and working, we can 823 * Now that we have DRAM mapped and working, we can
824 * relocate the code and continue running from DRAM. 824 * relocate the code and continue running from DRAM.
825 * 825 *
826 * Reserve memory at end of RAM for (top down in that order): 826 * Reserve memory at end of RAM for (top down in that order):
827 * - area that won't get touched by U-Boot and Linux (optional) 827 * - area that won't get touched by U-Boot and Linux (optional)
828 * - kernel log buffer 828 * - kernel log buffer
829 * - protected RAM 829 * - protected RAM
830 * - LCD framebuffer 830 * - LCD framebuffer
831 * - monitor code 831 * - monitor code
832 * - board info struct 832 * - board info struct
833 */ 833 */
834 setup_dest_addr, 834 setup_dest_addr,
835 #ifdef CONFIG_PRAM 835 #ifdef CONFIG_PRAM
836 reserve_pram, 836 reserve_pram,
837 #endif 837 #endif
838 reserve_round_4k, 838 reserve_round_4k,
839 #ifdef CONFIG_ARM 839 #ifdef CONFIG_ARM
840 reserve_mmu, 840 reserve_mmu,
841 #endif 841 #endif
842 reserve_video, 842 reserve_video,
843 reserve_trace, 843 reserve_trace,
844 reserve_uboot, 844 reserve_uboot,
845 reserve_malloc, 845 reserve_malloc,
846 reserve_board, 846 reserve_board,
847 setup_machine, 847 setup_machine,
848 reserve_global_data, 848 reserve_global_data,
849 reserve_fdt, 849 reserve_fdt,
850 reserve_bootstage, 850 reserve_bootstage,
851 reserve_arch, 851 reserve_arch,
852 reserve_stacks, 852 reserve_stacks,
853 dram_init_banksize, 853 dram_init_banksize,
854 show_dram_config, 854 show_dram_config,
855 #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ 855 #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
856 defined(CONFIG_SH) 856 defined(CONFIG_SH)
857 setup_board_part1, 857 setup_board_part1,
858 #endif 858 #endif
859 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) 859 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
860 INIT_FUNC_WATCHDOG_RESET 860 INIT_FUNC_WATCHDOG_RESET
861 setup_board_part2, 861 setup_board_part2,
862 #endif 862 #endif
863 display_new_sp, 863 display_new_sp,
864 #ifdef CONFIG_OF_BOARD_FIXUP 864 #ifdef CONFIG_OF_BOARD_FIXUP
865 fix_fdt, 865 fix_fdt,
866 #endif 866 #endif
867 INIT_FUNC_WATCHDOG_RESET 867 INIT_FUNC_WATCHDOG_RESET
868 reloc_fdt, 868 reloc_fdt,
869 reloc_bootstage, 869 reloc_bootstage,
870 setup_reloc, 870 setup_reloc,
871 #if defined(CONFIG_X86) || defined(CONFIG_ARC) 871 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
872 copy_uboot_to_ram, 872 copy_uboot_to_ram,
873 do_elf_reloc_fixups, 873 do_elf_reloc_fixups,
874 clear_bss, 874 clear_bss,
875 #endif 875 #endif
876 #if defined(CONFIG_XTENSA) 876 #if defined(CONFIG_XTENSA)
877 clear_bss, 877 clear_bss,
878 #endif 878 #endif
879 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ 879 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
880 !CONFIG_IS_ENABLED(X86_64) 880 !CONFIG_IS_ENABLED(X86_64)
881 jump_to_copy, 881 jump_to_copy,
882 #endif 882 #endif
883 NULL, 883 NULL,
884 }; 884 };
885 885
886 void board_init_f(ulong boot_flags) 886 void board_init_f(ulong boot_flags)
887 { 887 {
888 gd->flags = boot_flags; 888 gd->flags = boot_flags;
889 gd->have_console = 0; 889 gd->have_console = 0;
890 890
891 if (initcall_run_list(init_sequence_f)) 891 if (initcall_run_list(init_sequence_f))
892 hang(); 892 hang();
893 893
894 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ 894 #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
895 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) 895 !defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
896 /* NOTREACHED - jump_to_copy() does not return */ 896 /* NOTREACHED - jump_to_copy() does not return */
897 hang(); 897 hang();
898 #endif 898 #endif
899 } 899 }
900 900
901 #if defined(CONFIG_X86) || defined(CONFIG_ARC) 901 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
902 /* 902 /*
903 * For now this code is only used on x86. 903 * For now this code is only used on x86.
904 * 904 *
905 * init_sequence_f_r is the list of init functions which are run when 905 * init_sequence_f_r is the list of init functions which are run when
906 * U-Boot is executing from Flash with a semi-limited 'C' environment. 906 * U-Boot is executing from Flash with a semi-limited 'C' environment.
907 * The following limitations must be considered when implementing an 907 * The following limitations must be considered when implementing an
908 * '_f_r' function: 908 * '_f_r' function:
909 * - 'static' variables are read-only 909 * - 'static' variables are read-only
910 * - Global Data (gd->xxx) is read/write 910 * - Global Data (gd->xxx) is read/write
911 * 911 *
912 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if 912 * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
913 * supported). It _should_, if possible, copy global data to RAM and 913 * supported). It _should_, if possible, copy global data to RAM and
914 * initialise the CPU caches (to speed up the relocation process) 914 * initialise the CPU caches (to speed up the relocation process)
915 * 915 *
916 * NOTE: At present only x86 uses this route, but it is intended that 916 * NOTE: At present only x86 uses this route, but it is intended that
917 * all archs will move to this when generic relocation is implemented. 917 * all archs will move to this when generic relocation is implemented.
918 */ 918 */
919 static const init_fnc_t init_sequence_f_r[] = { 919 static const init_fnc_t init_sequence_f_r[] = {
920 #if !CONFIG_IS_ENABLED(X86_64) 920 #if !CONFIG_IS_ENABLED(X86_64)
921 init_cache_f_r, 921 init_cache_f_r,
922 #endif 922 #endif
923 923
924 NULL, 924 NULL,
925 }; 925 };
926 926
927 void board_init_f_r(void) 927 void board_init_f_r(void)
928 { 928 {
929 if (initcall_run_list(init_sequence_f_r)) 929 if (initcall_run_list(init_sequence_f_r))
930 hang(); 930 hang();
931 931
932 /* 932 /*
933 * The pre-relocation drivers may be using memory that has now gone 933 * The pre-relocation drivers may be using memory that has now gone
934 * away. Mark serial as unavailable - this will fall back to the debug 934 * away. Mark serial as unavailable - this will fall back to the debug
935 * UART if available. 935 * UART if available.
936 * 936 *
937 * Do the same with log drivers since the memory may not be available. 937 * Do the same with log drivers since the memory may not be available.
938 */ 938 */
939 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY); 939 gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
940 #ifdef CONFIG_TIMER 940 #ifdef CONFIG_TIMER
941 gd->timer = NULL; 941 gd->timer = NULL;
942 #endif 942 #endif
943 943
944 /* 944 /*
945 * U-Boot has been copied into SDRAM, the BSS has been cleared etc. 945 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
946 * Transfer execution from Flash to RAM by calculating the address 946 * Transfer execution from Flash to RAM by calculating the address
947 * of the in-RAM copy of board_init_r() and calling it 947 * of the in-RAM copy of board_init_r() and calling it
948 */ 948 */
949 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr); 949 (board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
950 950
951 /* NOTREACHED - board_init_r() does not return */ 951 /* NOTREACHED - board_init_r() does not return */
952 hang(); 952 hang();
953 } 953 }
954 #endif /* CONFIG_X86 */ 954 #endif /* CONFIG_X86 */
955 955
1 /* 1 /*
2 * Copyright (c) 2011 The Chromium OS Authors. 2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006 3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * 5 *
6 * (C) Copyright 2002 6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> 7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de> 8 * Marius Groeger <mgroeger@sysgo.de>
9 * 9 *
10 * SPDX-License-Identifier: GPL-2.0+ 10 * SPDX-License-Identifier: GPL-2.0+
11 */ 11 */
12 12
13 #include <common.h> 13 #include <common.h>
14 #include <api.h> 14 #include <api.h>
15 /* TODO: can we just include all these headers whether needed or not? */ 15 /* TODO: can we just include all these headers whether needed or not? */
16 #if defined(CONFIG_CMD_BEDBUG) 16 #if defined(CONFIG_CMD_BEDBUG)
17 #include <bedbug/type.h> 17 #include <bedbug/type.h>
18 #endif 18 #endif
19 #include <command.h> 19 #include <command.h>
20 #include <console.h> 20 #include <console.h>
21 #include <dm.h> 21 #include <dm.h>
22 #include <environment.h> 22 #include <environment.h>
23 #include <fdtdec.h> 23 #include <fdtdec.h>
24 #include <ide.h> 24 #include <ide.h>
25 #include <initcall.h> 25 #include <initcall.h>
26 #include <init_helpers.h> 26 #include <init_helpers.h>
27 #ifdef CONFIG_PS2KBD 27 #ifdef CONFIG_PS2KBD
28 #include <keyboard.h> 28 #include <keyboard.h>
29 #endif 29 #endif
30 #if defined(CONFIG_CMD_KGDB) 30 #if defined(CONFIG_CMD_KGDB)
31 #include <kgdb.h> 31 #include <kgdb.h>
32 #endif 32 #endif
33 #include <malloc.h> 33 #include <malloc.h>
34 #include <mapmem.h> 34 #include <mapmem.h>
35 #ifdef CONFIG_BITBANGMII 35 #ifdef CONFIG_BITBANGMII
36 #include <miiphy.h> 36 #include <miiphy.h>
37 #endif 37 #endif
38 #include <mmc.h> 38 #include <mmc.h>
39 #include <nand.h> 39 #include <nand.h>
40 #include <of_live.h> 40 #include <of_live.h>
41 #include <onenand_uboot.h> 41 #include <onenand_uboot.h>
42 #include <scsi.h> 42 #include <scsi.h>
43 #include <serial.h> 43 #include <serial.h>
44 #include <spi.h> 44 #include <spi.h>
45 #include <stdio_dev.h> 45 #include <stdio_dev.h>
46 #include <timer.h> 46 #include <timer.h>
47 #include <trace.h> 47 #include <trace.h>
48 #include <watchdog.h> 48 #include <watchdog.h>
49 #ifdef CONFIG_ADDR_MAP 49 #ifdef CONFIG_ADDR_MAP
50 #include <asm/mmu.h> 50 #include <asm/mmu.h>
51 #endif 51 #endif
52 #include <asm/sections.h> 52 #include <asm/sections.h>
53 #include <dm/root.h> 53 #include <dm/root.h>
54 #include <linux/compiler.h> 54 #include <linux/compiler.h>
55 #include <linux/err.h> 55 #include <linux/err.h>
56 #include <efi_loader.h> 56 #include <efi_loader.h>
57 57
58 DECLARE_GLOBAL_DATA_PTR; 58 DECLARE_GLOBAL_DATA_PTR;
59 59
60 ulong monitor_flash_len; 60 ulong monitor_flash_len;
61 61
62 __weak int board_flash_wp_on(void) 62 __weak int board_flash_wp_on(void)
63 { 63 {
64 /* 64 /*
65 * Most flashes can't be detected when write protection is enabled, 65 * Most flashes can't be detected when write protection is enabled,
66 * so provide a way to let U-Boot gracefully ignore write protected 66 * so provide a way to let U-Boot gracefully ignore write protected
67 * devices. 67 * devices.
68 */ 68 */
69 return 0; 69 return 0;
70 } 70 }
71 71
72 __weak void cpu_secondary_init_r(void) 72 __weak void cpu_secondary_init_r(void)
73 { 73 {
74 } 74 }
75 75
76 static int initr_secondary_cpu(void) 76 static int initr_secondary_cpu(void)
77 { 77 {
78 /* 78 /*
79 * after non-volatile devices & environment is setup and cpu code have 79 * after non-volatile devices & environment is setup and cpu code have
80 * another round to deal with any initialization that might require 80 * another round to deal with any initialization that might require
81 * full access to the environment or loading of some image (firmware) 81 * full access to the environment or loading of some image (firmware)
82 * from a non-volatile device 82 * from a non-volatile device
83 */ 83 */
84 /* TODO: maybe define this for all archs? */ 84 /* TODO: maybe define this for all archs? */
85 cpu_secondary_init_r(); 85 cpu_secondary_init_r();
86 86
87 return 0; 87 return 0;
88 } 88 }
89 89
90 static int initr_trace(void) 90 static int initr_trace(void)
91 { 91 {
92 #ifdef CONFIG_TRACE 92 #ifdef CONFIG_TRACE
93 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE); 93 trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE);
94 #endif 94 #endif
95 95
96 return 0; 96 return 0;
97 } 97 }
98 98
99 static int initr_reloc(void) 99 static int initr_reloc(void)
100 { 100 {
101 /* tell others: relocation done */ 101 /* tell others: relocation done */
102 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; 102 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
103 103
104 return 0; 104 return 0;
105 } 105 }
106 106
107 #ifdef CONFIG_ARM 107 #ifdef CONFIG_ARM
108 /* 108 /*
109 * Some of these functions are needed purely because the functions they 109 * Some of these functions are needed purely because the functions they
110 * call return void. If we change them to return 0, these stubs can go away. 110 * call return void. If we change them to return 0, these stubs can go away.
111 */ 111 */
112 static int initr_caches(void) 112 static int initr_caches(void)
113 { 113 {
114 /* Enable caches */ 114 /* Enable caches */
115 enable_caches(); 115 enable_caches();
116 return 0; 116 return 0;
117 } 117 }
118 #endif 118 #endif
119 119
120 __weak int fixup_cpu(void) 120 __weak int fixup_cpu(void)
121 { 121 {
122 return 0; 122 return 0;
123 } 123 }
124 124
125 static int initr_reloc_global_data(void) 125 static int initr_reloc_global_data(void)
126 { 126 {
127 #ifdef __ARM__ 127 #ifdef __ARM__
128 monitor_flash_len = _end - __image_copy_start; 128 monitor_flash_len = _end - __image_copy_start;
129 #elif defined(CONFIG_NDS32) 129 #elif defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
130 monitor_flash_len = (ulong)&_end - (ulong)&_start; 130 monitor_flash_len = (ulong)&_end - (ulong)&_start;
131 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2) 131 #elif !defined(CONFIG_SANDBOX) && !defined(CONFIG_NIOS2)
132 monitor_flash_len = (ulong)&__init_end - gd->relocaddr; 132 monitor_flash_len = (ulong)&__init_end - gd->relocaddr;
133 #endif 133 #endif
134 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) 134 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
135 /* 135 /*
136 * The gd->cpu pointer is set to an address in flash before relocation. 136 * The gd->cpu pointer is set to an address in flash before relocation.
137 * We need to update it to point to the same CPU entry in RAM. 137 * We need to update it to point to the same CPU entry in RAM.
138 * TODO: why not just add gd->reloc_ofs? 138 * TODO: why not just add gd->reloc_ofs?
139 */ 139 */
140 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; 140 gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
141 141
142 /* 142 /*
143 * If we didn't know the cpu mask & # cores, we can save them of 143 * If we didn't know the cpu mask & # cores, we can save them of
144 * now rather than 'computing' them constantly 144 * now rather than 'computing' them constantly
145 */ 145 */
146 fixup_cpu(); 146 fixup_cpu();
147 #endif 147 #endif
148 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC 148 #ifdef CONFIG_SYS_EXTRA_ENV_RELOC
149 /* 149 /*
150 * Some systems need to relocate the env_addr pointer early because the 150 * Some systems need to relocate the env_addr pointer early because the
151 * location it points to will get invalidated before env_relocate is 151 * location it points to will get invalidated before env_relocate is
152 * called. One example is on systems that might use a L2 or L3 cache 152 * called. One example is on systems that might use a L2 or L3 cache
153 * in SRAM mode and initialize that cache from SRAM mode back to being 153 * in SRAM mode and initialize that cache from SRAM mode back to being
154 * a cache in cpu_init_r. 154 * a cache in cpu_init_r.
155 */ 155 */
156 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; 156 gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE;
157 #endif 157 #endif
158 #ifdef CONFIG_OF_EMBED 158 #ifdef CONFIG_OF_EMBED
159 /* 159 /*
160 * The fdt_blob needs to be moved to new relocation address 160 * The fdt_blob needs to be moved to new relocation address
161 * incase of FDT blob is embedded with in image 161 * incase of FDT blob is embedded with in image
162 */ 162 */
163 gd->fdt_blob += gd->reloc_off; 163 gd->fdt_blob += gd->reloc_off;
164 #endif 164 #endif
165 #ifdef CONFIG_EFI_LOADER 165 #ifdef CONFIG_EFI_LOADER
166 efi_runtime_relocate(gd->relocaddr, NULL); 166 efi_runtime_relocate(gd->relocaddr, NULL);
167 #endif 167 #endif
168 168
169 return 0; 169 return 0;
170 } 170 }
171 171
172 static int initr_serial(void) 172 static int initr_serial(void)
173 { 173 {
174 serial_initialize(); 174 serial_initialize();
175 return 0; 175 return 0;
176 } 176 }
177 177
178 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) 178 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
179 static int initr_trap(void) 179 static int initr_trap(void)
180 { 180 {
181 /* 181 /*
182 * Setup trap handlers 182 * Setup trap handlers
183 */ 183 */
184 #if defined(CONFIG_PPC) 184 #if defined(CONFIG_PPC)
185 trap_init(gd->relocaddr); 185 trap_init(gd->relocaddr);
186 #else 186 #else
187 trap_init(CONFIG_SYS_SDRAM_BASE); 187 trap_init(CONFIG_SYS_SDRAM_BASE);
188 #endif 188 #endif
189 return 0; 189 return 0;
190 } 190 }
191 #endif 191 #endif
192 192
193 #ifdef CONFIG_ADDR_MAP 193 #ifdef CONFIG_ADDR_MAP
194 static int initr_addr_map(void) 194 static int initr_addr_map(void)
195 { 195 {
196 init_addr_map(); 196 init_addr_map();
197 197
198 return 0; 198 return 0;
199 } 199 }
200 #endif 200 #endif
201 201
202 #ifdef CONFIG_POST 202 #ifdef CONFIG_POST
203 static int initr_post_backlog(void) 203 static int initr_post_backlog(void)
204 { 204 {
205 post_output_backlog(); 205 post_output_backlog();
206 return 0; 206 return 0;
207 } 207 }
208 #endif 208 #endif
209 209
210 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) 210 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
211 static int initr_unlock_ram_in_cache(void) 211 static int initr_unlock_ram_in_cache(void)
212 { 212 {
213 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */ 213 unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */
214 return 0; 214 return 0;
215 } 215 }
216 #endif 216 #endif
217 217
218 #ifdef CONFIG_PCI 218 #ifdef CONFIG_PCI
219 static int initr_pci(void) 219 static int initr_pci(void)
220 { 220 {
221 #ifndef CONFIG_DM_PCI 221 #ifndef CONFIG_DM_PCI
222 pci_init(); 222 pci_init();
223 #endif 223 #endif
224 224
225 return 0; 225 return 0;
226 } 226 }
227 #endif 227 #endif
228 228
229 static int initr_barrier(void) 229 static int initr_barrier(void)
230 { 230 {
231 #ifdef CONFIG_PPC 231 #ifdef CONFIG_PPC
232 /* TODO: Can we not use dmb() macros for this? */ 232 /* TODO: Can we not use dmb() macros for this? */
233 asm("sync ; isync"); 233 asm("sync ; isync");
234 #endif 234 #endif
235 return 0; 235 return 0;
236 } 236 }
237 237
238 static int initr_malloc(void) 238 static int initr_malloc(void)
239 { 239 {
240 ulong malloc_start; 240 ulong malloc_start;
241 241
242 #if CONFIG_VAL(SYS_MALLOC_F_LEN) 242 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
243 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr, 243 debug("Pre-reloc malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
244 gd->malloc_ptr / 1024); 244 gd->malloc_ptr / 1024);
245 #endif 245 #endif
246 /* The malloc area is immediately below the monitor copy in DRAM */ 246 /* The malloc area is immediately below the monitor copy in DRAM */
247 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; 247 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN;
248 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), 248 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
249 TOTAL_MALLOC_LEN); 249 TOTAL_MALLOC_LEN);
250 return 0; 250 return 0;
251 } 251 }
252 252
253 static int initr_console_record(void) 253 static int initr_console_record(void)
254 { 254 {
255 #if defined(CONFIG_CONSOLE_RECORD) 255 #if defined(CONFIG_CONSOLE_RECORD)
256 return console_record_init(); 256 return console_record_init();
257 #else 257 #else
258 return 0; 258 return 0;
259 #endif 259 #endif
260 } 260 }
261 261
262 #ifdef CONFIG_SYS_NONCACHED_MEMORY 262 #ifdef CONFIG_SYS_NONCACHED_MEMORY
263 static int initr_noncached(void) 263 static int initr_noncached(void)
264 { 264 {
265 noncached_init(); 265 noncached_init();
266 return 0; 266 return 0;
267 } 267 }
268 #endif 268 #endif
269 269
270 #ifdef CONFIG_OF_LIVE 270 #ifdef CONFIG_OF_LIVE
271 static int initr_of_live(void) 271 static int initr_of_live(void)
272 { 272 {
273 int ret; 273 int ret;
274 274
275 bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live"); 275 bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
276 ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root); 276 ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root);
277 bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE); 277 bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
278 if (ret) 278 if (ret)
279 return ret; 279 return ret;
280 280
281 return 0; 281 return 0;
282 } 282 }
283 #endif 283 #endif
284 284
285 #ifdef CONFIG_DM 285 #ifdef CONFIG_DM
286 static int initr_dm(void) 286 static int initr_dm(void)
287 { 287 {
288 int ret; 288 int ret;
289 289
290 /* Save the pre-reloc driver model and start a new one */ 290 /* Save the pre-reloc driver model and start a new one */
291 gd->dm_root_f = gd->dm_root; 291 gd->dm_root_f = gd->dm_root;
292 gd->dm_root = NULL; 292 gd->dm_root = NULL;
293 #ifdef CONFIG_TIMER 293 #ifdef CONFIG_TIMER
294 gd->timer = NULL; 294 gd->timer = NULL;
295 #endif 295 #endif
296 bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r"); 296 bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r");
297 ret = dm_init_and_scan(false); 297 ret = dm_init_and_scan(false);
298 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R); 298 bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R);
299 if (ret) 299 if (ret)
300 return ret; 300 return ret;
301 #ifdef CONFIG_TIMER_EARLY 301 #ifdef CONFIG_TIMER_EARLY
302 ret = dm_timer_init(); 302 ret = dm_timer_init();
303 if (ret) 303 if (ret)
304 return ret; 304 return ret;
305 #endif 305 #endif
306 306
307 return 0; 307 return 0;
308 } 308 }
309 #endif 309 #endif
310 310
311 static int initr_bootstage(void) 311 static int initr_bootstage(void)
312 { 312 {
313 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r"); 313 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
314 314
315 return 0; 315 return 0;
316 } 316 }
317 317
318 __weak int power_init_board(void) 318 __weak int power_init_board(void)
319 { 319 {
320 return 0; 320 return 0;
321 } 321 }
322 322
323 static int initr_announce(void) 323 static int initr_announce(void)
324 { 324 {
325 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr); 325 debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr);
326 return 0; 326 return 0;
327 } 327 }
328 328
329 #ifdef CONFIG_NEEDS_MANUAL_RELOC 329 #ifdef CONFIG_NEEDS_MANUAL_RELOC
330 static int initr_manual_reloc_cmdtable(void) 330 static int initr_manual_reloc_cmdtable(void)
331 { 331 {
332 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd), 332 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
333 ll_entry_count(cmd_tbl_t, cmd)); 333 ll_entry_count(cmd_tbl_t, cmd));
334 return 0; 334 return 0;
335 } 335 }
336 #endif 336 #endif
337 337
338 #if defined(CONFIG_MTD_NOR_FLASH) 338 #if defined(CONFIG_MTD_NOR_FLASH)
339 static int initr_flash(void) 339 static int initr_flash(void)
340 { 340 {
341 ulong flash_size = 0; 341 ulong flash_size = 0;
342 bd_t *bd = gd->bd; 342 bd_t *bd = gd->bd;
343 343
344 puts("Flash: "); 344 puts("Flash: ");
345 345
346 if (board_flash_wp_on()) 346 if (board_flash_wp_on())
347 printf("Uninitialized - Write Protect On\n"); 347 printf("Uninitialized - Write Protect On\n");
348 else 348 else
349 flash_size = flash_init(); 349 flash_size = flash_init();
350 350
351 print_size(flash_size, ""); 351 print_size(flash_size, "");
352 #ifdef CONFIG_SYS_FLASH_CHECKSUM 352 #ifdef CONFIG_SYS_FLASH_CHECKSUM
353 /* 353 /*
354 * Compute and print flash CRC if flashchecksum is set to 'y' 354 * Compute and print flash CRC if flashchecksum is set to 'y'
355 * 355 *
356 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX 356 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
357 */ 357 */
358 if (env_get_yesno("flashchecksum") == 1) { 358 if (env_get_yesno("flashchecksum") == 1) {
359 printf(" CRC: %08X", crc32(0, 359 printf(" CRC: %08X", crc32(0,
360 (const unsigned char *) CONFIG_SYS_FLASH_BASE, 360 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
361 flash_size)); 361 flash_size));
362 } 362 }
363 #endif /* CONFIG_SYS_FLASH_CHECKSUM */ 363 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
364 putc('\n'); 364 putc('\n');
365 365
366 /* update start of FLASH memory */ 366 /* update start of FLASH memory */
367 #ifdef CONFIG_SYS_FLASH_BASE 367 #ifdef CONFIG_SYS_FLASH_BASE
368 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; 368 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
369 #endif 369 #endif
370 /* size of FLASH memory (final value) */ 370 /* size of FLASH memory (final value) */
371 bd->bi_flashsize = flash_size; 371 bd->bi_flashsize = flash_size;
372 372
373 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE) 373 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
374 /* Make a update of the Memctrl. */ 374 /* Make a update of the Memctrl. */
375 update_flash_size(flash_size); 375 update_flash_size(flash_size);
376 #endif 376 #endif
377 377
378 378
379 #if defined(CONFIG_OXC) || defined(CONFIG_RMU) 379 #if defined(CONFIG_OXC) || defined(CONFIG_RMU)
380 /* flash mapped at end of memory map */ 380 /* flash mapped at end of memory map */
381 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size; 381 bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
382 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE 382 #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
383 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */ 383 bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
384 #endif 384 #endif
385 return 0; 385 return 0;
386 } 386 }
387 #endif 387 #endif
388 388
389 #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI) 389 #if defined(CONFIG_PPC) && !defined(CONFIG_DM_SPI)
390 static int initr_spi(void) 390 static int initr_spi(void)
391 { 391 {
392 /* PPC does this here */ 392 /* PPC does this here */
393 #ifdef CONFIG_SPI 393 #ifdef CONFIG_SPI
394 #if !defined(CONFIG_ENV_IS_IN_EEPROM) 394 #if !defined(CONFIG_ENV_IS_IN_EEPROM)
395 spi_init_f(); 395 spi_init_f();
396 #endif 396 #endif
397 spi_init_r(); 397 spi_init_r();
398 #endif 398 #endif
399 return 0; 399 return 0;
400 } 400 }
401 #endif 401 #endif
402 402
403 #ifdef CONFIG_CMD_NAND 403 #ifdef CONFIG_CMD_NAND
404 /* go init the NAND */ 404 /* go init the NAND */
405 static int initr_nand(void) 405 static int initr_nand(void)
406 { 406 {
407 puts("NAND: "); 407 puts("NAND: ");
408 nand_init(); 408 nand_init();
409 printf("%lu MiB\n", nand_size() / 1024); 409 printf("%lu MiB\n", nand_size() / 1024);
410 return 0; 410 return 0;
411 } 411 }
412 #endif 412 #endif
413 413
414 #if defined(CONFIG_CMD_ONENAND) 414 #if defined(CONFIG_CMD_ONENAND)
415 /* go init the NAND */ 415 /* go init the NAND */
416 static int initr_onenand(void) 416 static int initr_onenand(void)
417 { 417 {
418 puts("NAND: "); 418 puts("NAND: ");
419 onenand_init(); 419 onenand_init();
420 return 0; 420 return 0;
421 } 421 }
422 #endif 422 #endif
423 423
424 #ifdef CONFIG_MMC 424 #ifdef CONFIG_MMC
425 static int initr_mmc(void) 425 static int initr_mmc(void)
426 { 426 {
427 puts("MMC: "); 427 puts("MMC: ");
428 mmc_initialize(gd->bd); 428 mmc_initialize(gd->bd);
429 return 0; 429 return 0;
430 } 430 }
431 #endif 431 #endif
432 432
433 /* 433 /*
434 * Tell if it's OK to load the environment early in boot. 434 * Tell if it's OK to load the environment early in boot.
435 * 435 *
436 * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see 436 * If CONFIG_OF_CONTROL is defined, we'll check with the FDT to see
437 * if this is OK (defaulting to saying it's OK). 437 * if this is OK (defaulting to saying it's OK).
438 * 438 *
439 * NOTE: Loading the environment early can be a bad idea if security is 439 * NOTE: Loading the environment early can be a bad idea if security is
440 * important, since no verification is done on the environment. 440 * important, since no verification is done on the environment.
441 * 441 *
442 * @return 0 if environment should not be loaded, !=0 if it is ok to load 442 * @return 0 if environment should not be loaded, !=0 if it is ok to load
443 */ 443 */
444 static int should_load_env(void) 444 static int should_load_env(void)
445 { 445 {
446 #ifdef CONFIG_OF_CONTROL 446 #ifdef CONFIG_OF_CONTROL
447 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1); 447 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
448 #elif defined CONFIG_DELAY_ENVIRONMENT 448 #elif defined CONFIG_DELAY_ENVIRONMENT
449 return 0; 449 return 0;
450 #else 450 #else
451 return 1; 451 return 1;
452 #endif 452 #endif
453 } 453 }
454 454
455 static int initr_env(void) 455 static int initr_env(void)
456 { 456 {
457 /* initialize environment */ 457 /* initialize environment */
458 if (should_load_env()) 458 if (should_load_env())
459 env_relocate(); 459 env_relocate();
460 else 460 else
461 set_default_env(NULL); 461 set_default_env(NULL);
462 #ifdef CONFIG_OF_CONTROL 462 #ifdef CONFIG_OF_CONTROL
463 env_set_addr("fdtcontroladdr", gd->fdt_blob); 463 env_set_addr("fdtcontroladdr", gd->fdt_blob);
464 #endif 464 #endif
465 465
466 /* Initialize from environment */ 466 /* Initialize from environment */
467 load_addr = env_get_ulong("loadaddr", 16, load_addr); 467 load_addr = env_get_ulong("loadaddr", 16, load_addr);
468 468
469 return 0; 469 return 0;
470 } 470 }
471 471
472 #ifdef CONFIG_SYS_BOOTPARAMS_LEN 472 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
473 static int initr_malloc_bootparams(void) 473 static int initr_malloc_bootparams(void)
474 { 474 {
475 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN); 475 gd->bd->bi_boot_params = (ulong)malloc(CONFIG_SYS_BOOTPARAMS_LEN);
476 if (!gd->bd->bi_boot_params) { 476 if (!gd->bd->bi_boot_params) {
477 puts("WARNING: Cannot allocate space for boot parameters\n"); 477 puts("WARNING: Cannot allocate space for boot parameters\n");
478 return -ENOMEM; 478 return -ENOMEM;
479 } 479 }
480 return 0; 480 return 0;
481 } 481 }
482 #endif 482 #endif
483 483
484 static int initr_jumptable(void) 484 static int initr_jumptable(void)
485 { 485 {
486 jumptable_init(); 486 jumptable_init();
487 return 0; 487 return 0;
488 } 488 }
489 489
490 #if defined(CONFIG_API) 490 #if defined(CONFIG_API)
491 static int initr_api(void) 491 static int initr_api(void)
492 { 492 {
493 /* Initialize API */ 493 /* Initialize API */
494 api_init(); 494 api_init();
495 return 0; 495 return 0;
496 } 496 }
497 #endif 497 #endif
498 498
499 /* enable exceptions */ 499 /* enable exceptions */
500 #ifdef CONFIG_ARM 500 #ifdef CONFIG_ARM
501 static int initr_enable_interrupts(void) 501 static int initr_enable_interrupts(void)
502 { 502 {
503 enable_interrupts(); 503 enable_interrupts();
504 return 0; 504 return 0;
505 } 505 }
506 #endif 506 #endif
507 507
508 #ifdef CONFIG_CMD_NET 508 #ifdef CONFIG_CMD_NET
509 static int initr_ethaddr(void) 509 static int initr_ethaddr(void)
510 { 510 {
511 bd_t *bd = gd->bd; 511 bd_t *bd = gd->bd;
512 512
513 /* kept around for legacy kernels only ... ignore the next section */ 513 /* kept around for legacy kernels only ... ignore the next section */
514 eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr); 514 eth_env_get_enetaddr("ethaddr", bd->bi_enetaddr);
515 #ifdef CONFIG_HAS_ETH1 515 #ifdef CONFIG_HAS_ETH1
516 eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr); 516 eth_env_get_enetaddr("eth1addr", bd->bi_enet1addr);
517 #endif 517 #endif
518 #ifdef CONFIG_HAS_ETH2 518 #ifdef CONFIG_HAS_ETH2
519 eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr); 519 eth_env_get_enetaddr("eth2addr", bd->bi_enet2addr);
520 #endif 520 #endif
521 #ifdef CONFIG_HAS_ETH3 521 #ifdef CONFIG_HAS_ETH3
522 eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr); 522 eth_env_get_enetaddr("eth3addr", bd->bi_enet3addr);
523 #endif 523 #endif
524 #ifdef CONFIG_HAS_ETH4 524 #ifdef CONFIG_HAS_ETH4
525 eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr); 525 eth_env_get_enetaddr("eth4addr", bd->bi_enet4addr);
526 #endif 526 #endif
527 #ifdef CONFIG_HAS_ETH5 527 #ifdef CONFIG_HAS_ETH5
528 eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr); 528 eth_env_get_enetaddr("eth5addr", bd->bi_enet5addr);
529 #endif 529 #endif
530 return 0; 530 return 0;
531 } 531 }
532 #endif /* CONFIG_CMD_NET */ 532 #endif /* CONFIG_CMD_NET */
533 533
534 #ifdef CONFIG_CMD_KGDB 534 #ifdef CONFIG_CMD_KGDB
535 static int initr_kgdb(void) 535 static int initr_kgdb(void)
536 { 536 {
537 puts("KGDB: "); 537 puts("KGDB: ");
538 kgdb_init(); 538 kgdb_init();
539 return 0; 539 return 0;
540 } 540 }
541 #endif 541 #endif
542 542
543 #if defined(CONFIG_LED_STATUS) 543 #if defined(CONFIG_LED_STATUS)
544 static int initr_status_led(void) 544 static int initr_status_led(void)
545 { 545 {
546 #if defined(CONFIG_LED_STATUS_BOOT) 546 #if defined(CONFIG_LED_STATUS_BOOT)
547 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING); 547 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_BLINKING);
548 #else 548 #else
549 status_led_init(); 549 status_led_init();
550 #endif 550 #endif
551 return 0; 551 return 0;
552 } 552 }
553 #endif 553 #endif
554 554
555 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI) 555 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
556 static int initr_scsi(void) 556 static int initr_scsi(void)
557 { 557 {
558 puts("SCSI: "); 558 puts("SCSI: ");
559 scsi_init(); 559 scsi_init();
560 560
561 return 0; 561 return 0;
562 } 562 }
563 #endif 563 #endif
564 564
565 #ifdef CONFIG_BITBANGMII 565 #ifdef CONFIG_BITBANGMII
566 static int initr_bbmii(void) 566 static int initr_bbmii(void)
567 { 567 {
568 bb_miiphy_init(); 568 bb_miiphy_init();
569 return 0; 569 return 0;
570 } 570 }
571 #endif 571 #endif
572 572
573 #ifdef CONFIG_CMD_NET 573 #ifdef CONFIG_CMD_NET
574 static int initr_net(void) 574 static int initr_net(void)
575 { 575 {
576 puts("Net: "); 576 puts("Net: ");
577 eth_initialize(); 577 eth_initialize();
578 #if defined(CONFIG_RESET_PHY_R) 578 #if defined(CONFIG_RESET_PHY_R)
579 debug("Reset Ethernet PHY\n"); 579 debug("Reset Ethernet PHY\n");
580 reset_phy(); 580 reset_phy();
581 #endif 581 #endif
582 return 0; 582 return 0;
583 } 583 }
584 #endif 584 #endif
585 585
586 #ifdef CONFIG_POST 586 #ifdef CONFIG_POST
587 static int initr_post(void) 587 static int initr_post(void)
588 { 588 {
589 post_run(NULL, POST_RAM | post_bootmode_get(0)); 589 post_run(NULL, POST_RAM | post_bootmode_get(0));
590 return 0; 590 return 0;
591 } 591 }
592 #endif 592 #endif
593 593
594 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE) 594 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
595 static int initr_pcmcia(void) 595 static int initr_pcmcia(void)
596 { 596 {
597 puts("PCMCIA:"); 597 puts("PCMCIA:");
598 pcmcia_init(); 598 pcmcia_init();
599 return 0; 599 return 0;
600 } 600 }
601 #endif 601 #endif
602 602
603 #if defined(CONFIG_IDE) 603 #if defined(CONFIG_IDE)
604 static int initr_ide(void) 604 static int initr_ide(void)
605 { 605 {
606 puts("IDE: "); 606 puts("IDE: ");
607 #if defined(CONFIG_START_IDE) 607 #if defined(CONFIG_START_IDE)
608 if (board_start_ide()) 608 if (board_start_ide())
609 ide_init(); 609 ide_init();
610 #else 610 #else
611 ide_init(); 611 ide_init();
612 #endif 612 #endif
613 return 0; 613 return 0;
614 } 614 }
615 #endif 615 #endif
616 616
617 #if defined(CONFIG_PRAM) 617 #if defined(CONFIG_PRAM)
618 /* 618 /*
619 * Export available size of memory for Linux, taking into account the 619 * Export available size of memory for Linux, taking into account the
620 * protected RAM at top of memory 620 * protected RAM at top of memory
621 */ 621 */
622 int initr_mem(void) 622 int initr_mem(void)
623 { 623 {
624 ulong pram = 0; 624 ulong pram = 0;
625 char memsz[32]; 625 char memsz[32];
626 626
627 # ifdef CONFIG_PRAM 627 # ifdef CONFIG_PRAM
628 pram = env_get_ulong("pram", 10, CONFIG_PRAM); 628 pram = env_get_ulong("pram", 10, CONFIG_PRAM);
629 # endif 629 # endif
630 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram)); 630 sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram));
631 env_set("mem", memsz); 631 env_set("mem", memsz);
632 632
633 return 0; 633 return 0;
634 } 634 }
635 #endif 635 #endif
636 636
637 #ifdef CONFIG_CMD_BEDBUG 637 #ifdef CONFIG_CMD_BEDBUG
638 static int initr_bedbug(void) 638 static int initr_bedbug(void)
639 { 639 {
640 bedbug_init(); 640 bedbug_init();
641 641
642 return 0; 642 return 0;
643 } 643 }
644 #endif 644 #endif
645 645
646 #ifdef CONFIG_PS2KBD 646 #ifdef CONFIG_PS2KBD
647 static int initr_kbd(void) 647 static int initr_kbd(void)
648 { 648 {
649 puts("PS/2: "); 649 puts("PS/2: ");
650 kbd_init(); 650 kbd_init();
651 return 0; 651 return 0;
652 } 652 }
653 #endif 653 #endif
654 654
655 static int run_main_loop(void) 655 static int run_main_loop(void)
656 { 656 {
657 #ifdef CONFIG_SANDBOX 657 #ifdef CONFIG_SANDBOX
658 sandbox_main_loop_init(); 658 sandbox_main_loop_init();
659 #endif 659 #endif
660 /* main_loop() can return to retry autoboot, if so just run it again */ 660 /* main_loop() can return to retry autoboot, if so just run it again */
661 for (;;) 661 for (;;)
662 main_loop(); 662 main_loop();
663 return 0; 663 return 0;
664 } 664 }
665 665
666 /* 666 /*
667 * Over time we hope to remove these functions with code fragments and 667 * Over time we hope to remove these functions with code fragments and
668 * stub funtcions, and instead call the relevant function directly. 668 * stub funtcions, and instead call the relevant function directly.
669 * 669 *
670 * We also hope to remove most of the driver-related init and do it if/when 670 * We also hope to remove most of the driver-related init and do it if/when
671 * the driver is later used. 671 * the driver is later used.
672 * 672 *
673 * TODO: perhaps reset the watchdog in the initcall function after each call? 673 * TODO: perhaps reset the watchdog in the initcall function after each call?
674 */ 674 */
675 static init_fnc_t init_sequence_r[] = { 675 static init_fnc_t init_sequence_r[] = {
676 initr_trace, 676 initr_trace,
677 initr_reloc, 677 initr_reloc,
678 /* TODO: could x86/PPC have this also perhaps? */ 678 /* TODO: could x86/PPC have this also perhaps? */
679 #ifdef CONFIG_ARM 679 #ifdef CONFIG_ARM
680 initr_caches, 680 initr_caches,
681 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR. 681 /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR.
682 * A temporary mapping of IFC high region is since removed, 682 * A temporary mapping of IFC high region is since removed,
683 * so environmental variables in NOR flash is not availble 683 * so environmental variables in NOR flash is not availble
684 * until board_init() is called below to remap IFC to high 684 * until board_init() is called below to remap IFC to high
685 * region. 685 * region.
686 */ 686 */
687 #endif 687 #endif
688 initr_reloc_global_data, 688 initr_reloc_global_data,
689 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) 689 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500)
690 initr_unlock_ram_in_cache, 690 initr_unlock_ram_in_cache,
691 #endif 691 #endif
692 initr_barrier, 692 initr_barrier,
693 initr_malloc, 693 initr_malloc,
694 log_init, 694 log_init,
695 initr_bootstage, /* Needs malloc() but has its own timer */ 695 initr_bootstage, /* Needs malloc() but has its own timer */
696 initr_console_record, 696 initr_console_record,
697 #ifdef CONFIG_SYS_NONCACHED_MEMORY 697 #ifdef CONFIG_SYS_NONCACHED_MEMORY
698 initr_noncached, 698 initr_noncached,
699 #endif 699 #endif
700 bootstage_relocate, 700 bootstage_relocate,
701 #ifdef CONFIG_OF_LIVE 701 #ifdef CONFIG_OF_LIVE
702 initr_of_live, 702 initr_of_live,
703 #endif 703 #endif
704 #ifdef CONFIG_DM 704 #ifdef CONFIG_DM
705 initr_dm, 705 initr_dm,
706 #endif 706 #endif
707 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) 707 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV)
708 board_init, /* Setup chipselects */ 708 board_init, /* Setup chipselects */
709 #endif 709 #endif
710 /* 710 /*
711 * TODO: printing of the clock inforamtion of the board is now 711 * TODO: printing of the clock inforamtion of the board is now
712 * implemented as part of bdinfo command. Currently only support for 712 * implemented as part of bdinfo command. Currently only support for
713 * davinci SOC's is added. Remove this check once all the board 713 * davinci SOC's is added. Remove this check once all the board
714 * implement this. 714 * implement this.
715 */ 715 */
716 #ifdef CONFIG_CLOCKS 716 #ifdef CONFIG_CLOCKS
717 set_cpu_clk_info, /* Setup clock information */ 717 set_cpu_clk_info, /* Setup clock information */
718 #endif 718 #endif
719 #ifdef CONFIG_EFI_LOADER 719 #ifdef CONFIG_EFI_LOADER
720 efi_memory_init, 720 efi_memory_init,
721 #endif 721 #endif
722 stdio_init_tables, 722 stdio_init_tables,
723 initr_serial, 723 initr_serial,
724 initr_announce, 724 initr_announce,
725 INIT_FUNC_WATCHDOG_RESET 725 INIT_FUNC_WATCHDOG_RESET
726 #ifdef CONFIG_NEEDS_MANUAL_RELOC 726 #ifdef CONFIG_NEEDS_MANUAL_RELOC
727 initr_manual_reloc_cmdtable, 727 initr_manual_reloc_cmdtable,
728 #endif 728 #endif
729 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) 729 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS)
730 initr_trap, 730 initr_trap,
731 #endif 731 #endif
732 #ifdef CONFIG_ADDR_MAP 732 #ifdef CONFIG_ADDR_MAP
733 initr_addr_map, 733 initr_addr_map,
734 #endif 734 #endif
735 #if defined(CONFIG_BOARD_EARLY_INIT_R) 735 #if defined(CONFIG_BOARD_EARLY_INIT_R)
736 board_early_init_r, 736 board_early_init_r,
737 #endif 737 #endif
738 INIT_FUNC_WATCHDOG_RESET 738 INIT_FUNC_WATCHDOG_RESET
739 #ifdef CONFIG_POST 739 #ifdef CONFIG_POST
740 initr_post_backlog, 740 initr_post_backlog,
741 #endif 741 #endif
742 INIT_FUNC_WATCHDOG_RESET 742 INIT_FUNC_WATCHDOG_RESET
743 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT) 743 #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
744 /* 744 /*
745 * Do early PCI configuration _before_ the flash gets initialised, 745 * Do early PCI configuration _before_ the flash gets initialised,
746 * because PCU ressources are crucial for flash access on some boards. 746 * because PCU ressources are crucial for flash access on some boards.
747 */ 747 */
748 initr_pci, 748 initr_pci,
749 #endif 749 #endif
750 #ifdef CONFIG_ARCH_EARLY_INIT_R 750 #ifdef CONFIG_ARCH_EARLY_INIT_R
751 arch_early_init_r, 751 arch_early_init_r,
752 #endif 752 #endif
753 power_init_board, 753 power_init_board,
754 #ifdef CONFIG_MTD_NOR_FLASH 754 #ifdef CONFIG_MTD_NOR_FLASH
755 initr_flash, 755 initr_flash,
756 #endif 756 #endif
757 INIT_FUNC_WATCHDOG_RESET 757 INIT_FUNC_WATCHDOG_RESET
758 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86) 758 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_X86)
759 /* initialize higher level parts of CPU like time base and timers */ 759 /* initialize higher level parts of CPU like time base and timers */
760 cpu_init_r, 760 cpu_init_r,
761 #endif 761 #endif
762 #ifdef CONFIG_PPC 762 #ifdef CONFIG_PPC
763 initr_spi, 763 initr_spi,
764 #endif 764 #endif
765 #ifdef CONFIG_CMD_NAND 765 #ifdef CONFIG_CMD_NAND
766 initr_nand, 766 initr_nand,
767 #endif 767 #endif
768 #ifdef CONFIG_CMD_ONENAND 768 #ifdef CONFIG_CMD_ONENAND
769 initr_onenand, 769 initr_onenand,
770 #endif 770 #endif
771 #ifdef CONFIG_MMC 771 #ifdef CONFIG_MMC
772 initr_mmc, 772 initr_mmc,
773 #endif 773 #endif
774 initr_env, 774 initr_env,
775 #ifdef CONFIG_SYS_BOOTPARAMS_LEN 775 #ifdef CONFIG_SYS_BOOTPARAMS_LEN
776 initr_malloc_bootparams, 776 initr_malloc_bootparams,
777 #endif 777 #endif
778 INIT_FUNC_WATCHDOG_RESET 778 INIT_FUNC_WATCHDOG_RESET
779 initr_secondary_cpu, 779 initr_secondary_cpu,
780 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET) 780 #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET)
781 mac_read_from_eeprom, 781 mac_read_from_eeprom,
782 #endif 782 #endif
783 INIT_FUNC_WATCHDOG_RESET 783 INIT_FUNC_WATCHDOG_RESET
784 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT) 784 #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
785 /* 785 /*
786 * Do pci configuration 786 * Do pci configuration
787 */ 787 */
788 initr_pci, 788 initr_pci,
789 #endif 789 #endif
790 stdio_add_devices, 790 stdio_add_devices,
791 initr_jumptable, 791 initr_jumptable,
792 #ifdef CONFIG_API 792 #ifdef CONFIG_API
793 initr_api, 793 initr_api,
794 #endif 794 #endif
795 console_init_r, /* fully init console as a device */ 795 console_init_r, /* fully init console as a device */
796 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE 796 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
797 console_announce_r, 797 console_announce_r,
798 show_board_info, 798 show_board_info,
799 #endif 799 #endif
800 #ifdef CONFIG_ARCH_MISC_INIT 800 #ifdef CONFIG_ARCH_MISC_INIT
801 arch_misc_init, /* miscellaneous arch-dependent init */ 801 arch_misc_init, /* miscellaneous arch-dependent init */
802 #endif 802 #endif
803 #ifdef CONFIG_MISC_INIT_R 803 #ifdef CONFIG_MISC_INIT_R
804 misc_init_r, /* miscellaneous platform-dependent init */ 804 misc_init_r, /* miscellaneous platform-dependent init */
805 #endif 805 #endif
806 INIT_FUNC_WATCHDOG_RESET 806 INIT_FUNC_WATCHDOG_RESET
807 #ifdef CONFIG_CMD_KGDB 807 #ifdef CONFIG_CMD_KGDB
808 initr_kgdb, 808 initr_kgdb,
809 #endif 809 #endif
810 interrupt_init, 810 interrupt_init,
811 #ifdef CONFIG_ARM 811 #ifdef CONFIG_ARM
812 initr_enable_interrupts, 812 initr_enable_interrupts,
813 #endif 813 #endif
814 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K) 814 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K)
815 timer_init, /* initialize timer */ 815 timer_init, /* initialize timer */
816 #endif 816 #endif
817 #if defined(CONFIG_LED_STATUS) 817 #if defined(CONFIG_LED_STATUS)
818 initr_status_led, 818 initr_status_led,
819 #endif 819 #endif
820 /* PPC has a udelay(20) here dating from 2002. Why? */ 820 /* PPC has a udelay(20) here dating from 2002. Why? */
821 #ifdef CONFIG_CMD_NET 821 #ifdef CONFIG_CMD_NET
822 initr_ethaddr, 822 initr_ethaddr,
823 #endif 823 #endif
824 #ifdef CONFIG_BOARD_LATE_INIT 824 #ifdef CONFIG_BOARD_LATE_INIT
825 board_late_init, 825 board_late_init,
826 #endif 826 #endif
827 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI) 827 #if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
828 INIT_FUNC_WATCHDOG_RESET 828 INIT_FUNC_WATCHDOG_RESET
829 initr_scsi, 829 initr_scsi,
830 #endif 830 #endif
831 #ifdef CONFIG_BITBANGMII 831 #ifdef CONFIG_BITBANGMII
832 initr_bbmii, 832 initr_bbmii,
833 #endif 833 #endif
834 #ifdef CONFIG_CMD_NET 834 #ifdef CONFIG_CMD_NET
835 INIT_FUNC_WATCHDOG_RESET 835 INIT_FUNC_WATCHDOG_RESET
836 initr_net, 836 initr_net,
837 #endif 837 #endif
838 #ifdef CONFIG_POST 838 #ifdef CONFIG_POST
839 initr_post, 839 initr_post,
840 #endif 840 #endif
841 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE) 841 #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_IDE)
842 initr_pcmcia, 842 initr_pcmcia,
843 #endif 843 #endif
844 #if defined(CONFIG_IDE) 844 #if defined(CONFIG_IDE)
845 initr_ide, 845 initr_ide,
846 #endif 846 #endif
847 #ifdef CONFIG_LAST_STAGE_INIT 847 #ifdef CONFIG_LAST_STAGE_INIT
848 INIT_FUNC_WATCHDOG_RESET 848 INIT_FUNC_WATCHDOG_RESET
849 /* 849 /*
850 * Some parts can be only initialized if all others (like 850 * Some parts can be only initialized if all others (like
851 * Interrupts) are up and running (i.e. the PC-style ISA 851 * Interrupts) are up and running (i.e. the PC-style ISA
852 * keyboard). 852 * keyboard).
853 */ 853 */
854 last_stage_init, 854 last_stage_init,
855 #endif 855 #endif
856 #ifdef CONFIG_CMD_BEDBUG 856 #ifdef CONFIG_CMD_BEDBUG
857 INIT_FUNC_WATCHDOG_RESET 857 INIT_FUNC_WATCHDOG_RESET
858 initr_bedbug, 858 initr_bedbug,
859 #endif 859 #endif
860 #if defined(CONFIG_PRAM) 860 #if defined(CONFIG_PRAM)
861 initr_mem, 861 initr_mem,
862 #endif 862 #endif
863 #ifdef CONFIG_PS2KBD 863 #ifdef CONFIG_PS2KBD
864 initr_kbd, 864 initr_kbd,
865 #endif 865 #endif
866 run_main_loop, 866 run_main_loop,
867 }; 867 };
868 868
869 void board_init_r(gd_t *new_gd, ulong dest_addr) 869 void board_init_r(gd_t *new_gd, ulong dest_addr)
870 { 870 {
871 /* 871 /*
872 * Set up the new global data pointer. So far only x86 does this 872 * Set up the new global data pointer. So far only x86 does this
873 * here. 873 * here.
874 * TODO(sjg@chromium.org): Consider doing this for all archs, or 874 * TODO(sjg@chromium.org): Consider doing this for all archs, or
875 * dropping the new_gd parameter. 875 * dropping the new_gd parameter.
876 */ 876 */
877 #if CONFIG_IS_ENABLED(X86_64) 877 #if CONFIG_IS_ENABLED(X86_64)
878 arch_setup_gd(new_gd); 878 arch_setup_gd(new_gd);
879 #endif 879 #endif
880 880
881 #ifdef CONFIG_NEEDS_MANUAL_RELOC 881 #ifdef CONFIG_NEEDS_MANUAL_RELOC
882 int i; 882 int i;
883 #endif 883 #endif
884 884
885 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) 885 #if !defined(CONFIG_X86) && !defined(CONFIG_ARM) && !defined(CONFIG_ARM64)
886 gd = new_gd; 886 gd = new_gd;
887 #endif 887 #endif
888 gd->flags &= ~GD_FLG_LOG_READY; 888 gd->flags &= ~GD_FLG_LOG_READY;
889 889
890 #ifdef CONFIG_NEEDS_MANUAL_RELOC 890 #ifdef CONFIG_NEEDS_MANUAL_RELOC
891 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++) 891 for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++)
892 init_sequence_r[i] += gd->reloc_off; 892 init_sequence_r[i] += gd->reloc_off;
893 #endif 893 #endif
894 894
895 if (initcall_run_list(init_sequence_r)) 895 if (initcall_run_list(init_sequence_r))
896 hang(); 896 hang();
897 897
898 /* NOTREACHED - run_main_loop() does not return */ 898 /* NOTREACHED - run_main_loop() does not return */
899 hang(); 899 hang();
900 } 900 }
901 901
1 /* 1 /*
2 * Copyright (c) 1995, 1996, 2001, 2002 2 * Copyright (c) 1995, 1996, 2001, 2002
3 * Erik Theisen. All rights reserved. 3 * Erik Theisen. All rights reserved.
4 * 4 *
5 * SPDX-License-Identifier: BSD-3-Clause 5 * SPDX-License-Identifier: BSD-3-Clause
6 */ 6 */
7 7
8 /* 8 /*
9 * This is the ELF ABI header file 9 * This is the ELF ABI header file
10 * formerly known as "elf_abi.h". 10 * formerly known as "elf_abi.h".
11 */ 11 */
12 12
13 #ifndef _ELF_H 13 #ifndef _ELF_H
14 #define _ELF_H 14 #define _ELF_H
15 15
16 #ifndef __ASSEMBLER__ 16 #ifndef __ASSEMBLER__
17 #include "compiler.h" 17 #include "compiler.h"
18 18
19 /* 19 /*
20 * This version doesn't work for 64-bit ABIs - Erik. 20 * This version doesn't work for 64-bit ABIs - Erik.
21 */ 21 */
22 22
23 /* 23 /*
24 * These typedefs need to be handled better. 24 * These typedefs need to be handled better.
25 */ 25 */
26 typedef uint32_t Elf32_Addr; /* Unsigned program address */ 26 typedef uint32_t Elf32_Addr; /* Unsigned program address */
27 typedef uint32_t Elf32_Off; /* Unsigned file offset */ 27 typedef uint32_t Elf32_Off; /* Unsigned file offset */
28 typedef int32_t Elf32_Sword; /* Signed large integer */ 28 typedef int32_t Elf32_Sword; /* Signed large integer */
29 typedef uint32_t Elf32_Word; /* Unsigned large integer */ 29 typedef uint32_t Elf32_Word; /* Unsigned large integer */
30 typedef uint16_t Elf32_Half; /* Unsigned medium integer */ 30 typedef uint16_t Elf32_Half; /* Unsigned medium integer */
31 31
32 /* 64-bit ELF base types. */ 32 /* 64-bit ELF base types. */
33 typedef uint64_t Elf64_Addr; 33 typedef uint64_t Elf64_Addr;
34 typedef uint16_t Elf64_Half; 34 typedef uint16_t Elf64_Half;
35 typedef int16_t Elf64_SHalf; 35 typedef int16_t Elf64_SHalf;
36 typedef uint64_t Elf64_Off; 36 typedef uint64_t Elf64_Off;
37 typedef int32_t Elf64_Sword; 37 typedef int32_t Elf64_Sword;
38 typedef uint32_t Elf64_Word; 38 typedef uint32_t Elf64_Word;
39 typedef uint64_t Elf64_Xword; 39 typedef uint64_t Elf64_Xword;
40 typedef int64_t Elf64_Sxword; 40 typedef int64_t Elf64_Sxword;
41 41
42 /* e_ident[] identification indexes */ 42 /* e_ident[] identification indexes */
43 #define EI_MAG0 0 /* file ID */ 43 #define EI_MAG0 0 /* file ID */
44 #define EI_MAG1 1 /* file ID */ 44 #define EI_MAG1 1 /* file ID */
45 #define EI_MAG2 2 /* file ID */ 45 #define EI_MAG2 2 /* file ID */
46 #define EI_MAG3 3 /* file ID */ 46 #define EI_MAG3 3 /* file ID */
47 #define EI_CLASS 4 /* file class */ 47 #define EI_CLASS 4 /* file class */
48 #define EI_DATA 5 /* data encoding */ 48 #define EI_DATA 5 /* data encoding */
49 #define EI_VERSION 6 /* ELF header version */ 49 #define EI_VERSION 6 /* ELF header version */
50 #define EI_OSABI 7 /* OS/ABI specific ELF extensions */ 50 #define EI_OSABI 7 /* OS/ABI specific ELF extensions */
51 #define EI_ABIVERSION 8 /* ABI target version */ 51 #define EI_ABIVERSION 8 /* ABI target version */
52 #define EI_PAD 9 /* start of pad bytes */ 52 #define EI_PAD 9 /* start of pad bytes */
53 #define EI_NIDENT 16 /* Size of e_ident[] */ 53 #define EI_NIDENT 16 /* Size of e_ident[] */
54 54
55 /* e_ident[] magic number */ 55 /* e_ident[] magic number */
56 #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ 56 #define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
57 #define ELFMAG1 'E' /* e_ident[EI_MAG1] */ 57 #define ELFMAG1 'E' /* e_ident[EI_MAG1] */
58 #define ELFMAG2 'L' /* e_ident[EI_MAG2] */ 58 #define ELFMAG2 'L' /* e_ident[EI_MAG2] */
59 #define ELFMAG3 'F' /* e_ident[EI_MAG3] */ 59 #define ELFMAG3 'F' /* e_ident[EI_MAG3] */
60 #define ELFMAG "\177ELF" /* magic */ 60 #define ELFMAG "\177ELF" /* magic */
61 #define SELFMAG 4 /* size of magic */ 61 #define SELFMAG 4 /* size of magic */
62 62
63 /* e_ident[] file class */ 63 /* e_ident[] file class */
64 #define ELFCLASSNONE 0 /* invalid */ 64 #define ELFCLASSNONE 0 /* invalid */
65 #define ELFCLASS32 1 /* 32-bit objs */ 65 #define ELFCLASS32 1 /* 32-bit objs */
66 #define ELFCLASS64 2 /* 64-bit objs */ 66 #define ELFCLASS64 2 /* 64-bit objs */
67 #define ELFCLASSNUM 3 /* number of classes */ 67 #define ELFCLASSNUM 3 /* number of classes */
68 68
69 /* e_ident[] data encoding */ 69 /* e_ident[] data encoding */
70 #define ELFDATANONE 0 /* invalid */ 70 #define ELFDATANONE 0 /* invalid */
71 #define ELFDATA2LSB 1 /* Little-Endian */ 71 #define ELFDATA2LSB 1 /* Little-Endian */
72 #define ELFDATA2MSB 2 /* Big-Endian */ 72 #define ELFDATA2MSB 2 /* Big-Endian */
73 #define ELFDATANUM 3 /* number of data encode defines */ 73 #define ELFDATANUM 3 /* number of data encode defines */
74 74
75 /* e_ident[] OS/ABI specific ELF extensions */ 75 /* e_ident[] OS/ABI specific ELF extensions */
76 #define ELFOSABI_NONE 0 /* No extension specified */ 76 #define ELFOSABI_NONE 0 /* No extension specified */
77 #define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ 77 #define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
78 #define ELFOSABI_NETBSD 2 /* NetBSD */ 78 #define ELFOSABI_NETBSD 2 /* NetBSD */
79 #define ELFOSABI_LINUX 3 /* Linux */ 79 #define ELFOSABI_LINUX 3 /* Linux */
80 #define ELFOSABI_SOLARIS 6 /* Sun Solaris */ 80 #define ELFOSABI_SOLARIS 6 /* Sun Solaris */
81 #define ELFOSABI_AIX 7 /* AIX */ 81 #define ELFOSABI_AIX 7 /* AIX */
82 #define ELFOSABI_IRIX 8 /* IRIX */ 82 #define ELFOSABI_IRIX 8 /* IRIX */
83 #define ELFOSABI_FREEBSD 9 /* FreeBSD */ 83 #define ELFOSABI_FREEBSD 9 /* FreeBSD */
84 #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ 84 #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
85 #define ELFOSABI_MODESTO 11 /* Novell Modesto */ 85 #define ELFOSABI_MODESTO 11 /* Novell Modesto */
86 #define ELFOSABI_OPENBSD 12 /* OpenBSD */ 86 #define ELFOSABI_OPENBSD 12 /* OpenBSD */
87 /* 64-255 Architecture-specific value range */ 87 /* 64-255 Architecture-specific value range */
88 88
89 /* e_ident[] ABI Version */ 89 /* e_ident[] ABI Version */
90 #define ELFABIVERSION 0 90 #define ELFABIVERSION 0
91 91
92 /* e_ident */ 92 /* e_ident */
93 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 93 #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
94 (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 94 (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
95 (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 95 (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
96 (ehdr).e_ident[EI_MAG3] == ELFMAG3) 96 (ehdr).e_ident[EI_MAG3] == ELFMAG3)
97 97
98 /* ELF Header */ 98 /* ELF Header */
99 typedef struct elfhdr{ 99 typedef struct elfhdr{
100 unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ 100 unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
101 Elf32_Half e_type; /* object file type */ 101 Elf32_Half e_type; /* object file type */
102 Elf32_Half e_machine; /* machine */ 102 Elf32_Half e_machine; /* machine */
103 Elf32_Word e_version; /* object file version */ 103 Elf32_Word e_version; /* object file version */
104 Elf32_Addr e_entry; /* virtual entry point */ 104 Elf32_Addr e_entry; /* virtual entry point */
105 Elf32_Off e_phoff; /* program header table offset */ 105 Elf32_Off e_phoff; /* program header table offset */
106 Elf32_Off e_shoff; /* section header table offset */ 106 Elf32_Off e_shoff; /* section header table offset */
107 Elf32_Word e_flags; /* processor-specific flags */ 107 Elf32_Word e_flags; /* processor-specific flags */
108 Elf32_Half e_ehsize; /* ELF header size */ 108 Elf32_Half e_ehsize; /* ELF header size */
109 Elf32_Half e_phentsize; /* program header entry size */ 109 Elf32_Half e_phentsize; /* program header entry size */
110 Elf32_Half e_phnum; /* number of program header entries */ 110 Elf32_Half e_phnum; /* number of program header entries */
111 Elf32_Half e_shentsize; /* section header entry size */ 111 Elf32_Half e_shentsize; /* section header entry size */
112 Elf32_Half e_shnum; /* number of section header entries */ 112 Elf32_Half e_shnum; /* number of section header entries */
113 Elf32_Half e_shstrndx; /* section header table's "section 113 Elf32_Half e_shstrndx; /* section header table's "section
114 header string table" entry offset */ 114 header string table" entry offset */
115 } Elf32_Ehdr; 115 } Elf32_Ehdr;
116 116
117 /* e_type */ 117 /* e_type */
118 #define ET_NONE 0 /* No file type */ 118 #define ET_NONE 0 /* No file type */
119 #define ET_REL 1 /* relocatable file */ 119 #define ET_REL 1 /* relocatable file */
120 #define ET_EXEC 2 /* executable file */ 120 #define ET_EXEC 2 /* executable file */
121 #define ET_DYN 3 /* shared object file */ 121 #define ET_DYN 3 /* shared object file */
122 #define ET_CORE 4 /* core file */ 122 #define ET_CORE 4 /* core file */
123 #define ET_NUM 5 /* number of types */ 123 #define ET_NUM 5 /* number of types */
124 #define ET_LOOS 0xfe00 /* reserved range for operating */ 124 #define ET_LOOS 0xfe00 /* reserved range for operating */
125 #define ET_HIOS 0xfeff /* system specific e_type */ 125 #define ET_HIOS 0xfeff /* system specific e_type */
126 #define ET_LOPROC 0xff00 /* reserved range for processor */ 126 #define ET_LOPROC 0xff00 /* reserved range for processor */
127 #define ET_HIPROC 0xffff /* specific e_type */ 127 #define ET_HIPROC 0xffff /* specific e_type */
128 128
129 /* e_machine */ 129 /* e_machine */
130 #define EM_NONE 0 /* No Machine */ 130 #define EM_NONE 0 /* No Machine */
131 #define EM_M32 1 /* AT&T WE 32100 */ 131 #define EM_M32 1 /* AT&T WE 32100 */
132 #define EM_SPARC 2 /* SPARC */ 132 #define EM_SPARC 2 /* SPARC */
133 #define EM_386 3 /* Intel 80386 */ 133 #define EM_386 3 /* Intel 80386 */
134 #define EM_68K 4 /* Motorola 68000 */ 134 #define EM_68K 4 /* Motorola 68000 */
135 #define EM_88K 5 /* Motorola 88000 */ 135 #define EM_88K 5 /* Motorola 88000 */
136 #if 0 136 #if 0
137 #define EM_486 6 /* RESERVED - was Intel 80486 */ 137 #define EM_486 6 /* RESERVED - was Intel 80486 */
138 #endif 138 #endif
139 #define EM_860 7 /* Intel 80860 */ 139 #define EM_860 7 /* Intel 80860 */
140 #define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ 140 #define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
141 #define EM_S370 9 /* IBM System/370 Processor */ 141 #define EM_S370 9 /* IBM System/370 Processor */
142 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ 142 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
143 #if 0 143 #if 0
144 #define EM_SPARC64 11 /* RESERVED - was SPARC v9 144 #define EM_SPARC64 11 /* RESERVED - was SPARC v9
145 64-bit unoffical */ 145 64-bit unoffical */
146 #endif 146 #endif
147 /* RESERVED 11-14 for future use */ 147 /* RESERVED 11-14 for future use */
148 #define EM_PARISC 15 /* HPPA */ 148 #define EM_PARISC 15 /* HPPA */
149 /* RESERVED 16 for future use */ 149 /* RESERVED 16 for future use */
150 #define EM_VPP500 17 /* Fujitsu VPP500 */ 150 #define EM_VPP500 17 /* Fujitsu VPP500 */
151 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 151 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
152 #define EM_960 19 /* Intel 80960 */ 152 #define EM_960 19 /* Intel 80960 */
153 #define EM_PPC 20 /* PowerPC */ 153 #define EM_PPC 20 /* PowerPC */
154 #define EM_PPC64 21 /* 64-bit PowerPC */ 154 #define EM_PPC64 21 /* 64-bit PowerPC */
155 #define EM_S390 22 /* IBM System/390 Processor */ 155 #define EM_S390 22 /* IBM System/390 Processor */
156 /* RESERVED 23-35 for future use */ 156 /* RESERVED 23-35 for future use */
157 #define EM_V800 36 /* NEC V800 */ 157 #define EM_V800 36 /* NEC V800 */
158 #define EM_FR20 37 /* Fujitsu FR20 */ 158 #define EM_FR20 37 /* Fujitsu FR20 */
159 #define EM_RH32 38 /* TRW RH-32 */ 159 #define EM_RH32 38 /* TRW RH-32 */
160 #define EM_RCE 39 /* Motorola RCE */ 160 #define EM_RCE 39 /* Motorola RCE */
161 #define EM_ARM 40 /* Advanced Risc Machines ARM */ 161 #define EM_ARM 40 /* Advanced Risc Machines ARM */
162 #define EM_ALPHA 41 /* Digital Alpha */ 162 #define EM_ALPHA 41 /* Digital Alpha */
163 #define EM_SH 42 /* Hitachi SH */ 163 #define EM_SH 42 /* Hitachi SH */
164 #define EM_SPARCV9 43 /* SPARC Version 9 */ 164 #define EM_SPARCV9 43 /* SPARC Version 9 */
165 #define EM_TRICORE 44 /* Siemens TriCore embedded processor */ 165 #define EM_TRICORE 44 /* Siemens TriCore embedded processor */
166 #define EM_ARC 45 /* Argonaut RISC Core */ 166 #define EM_ARC 45 /* Argonaut RISC Core */
167 #define EM_H8_300 46 /* Hitachi H8/300 */ 167 #define EM_H8_300 46 /* Hitachi H8/300 */
168 #define EM_H8_300H 47 /* Hitachi H8/300H */ 168 #define EM_H8_300H 47 /* Hitachi H8/300H */
169 #define EM_H8S 48 /* Hitachi H8S */ 169 #define EM_H8S 48 /* Hitachi H8S */
170 #define EM_H8_500 49 /* Hitachi H8/500 */ 170 #define EM_H8_500 49 /* Hitachi H8/500 */
171 #define EM_IA_64 50 /* Intel Merced */ 171 #define EM_IA_64 50 /* Intel Merced */
172 #define EM_MIPS_X 51 /* Stanford MIPS-X */ 172 #define EM_MIPS_X 51 /* Stanford MIPS-X */
173 #define EM_COLDFIRE 52 /* Motorola Coldfire */ 173 #define EM_COLDFIRE 52 /* Motorola Coldfire */
174 #define EM_68HC12 53 /* Motorola M68HC12 */ 174 #define EM_68HC12 53 /* Motorola M68HC12 */
175 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ 175 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
176 #define EM_PCP 55 /* Siemens PCP */ 176 #define EM_PCP 55 /* Siemens PCP */
177 #define EM_NCPU 56 /* Sony nCPU embeeded RISC */ 177 #define EM_NCPU 56 /* Sony nCPU embeeded RISC */
178 #define EM_NDR1 57 /* Denso NDR1 microprocessor */ 178 #define EM_NDR1 57 /* Denso NDR1 microprocessor */
179 #define EM_STARCORE 58 /* Motorola Start*Core processor */ 179 #define EM_STARCORE 58 /* Motorola Start*Core processor */
180 #define EM_ME16 59 /* Toyota ME16 processor */ 180 #define EM_ME16 59 /* Toyota ME16 processor */
181 #define EM_ST100 60 /* STMicroelectronic ST100 processor */ 181 #define EM_ST100 60 /* STMicroelectronic ST100 processor */
182 #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ 182 #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
183 #define EM_X86_64 62 /* AMD x86-64 */ 183 #define EM_X86_64 62 /* AMD x86-64 */
184 #define EM_PDSP 63 /* Sony DSP Processor */ 184 #define EM_PDSP 63 /* Sony DSP Processor */
185 /* RESERVED 64,65 for future use */ 185 /* RESERVED 64,65 for future use */
186 #define EM_FX66 66 /* Siemens FX66 microcontroller */ 186 #define EM_FX66 66 /* Siemens FX66 microcontroller */
187 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ 187 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
188 #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ 188 #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
189 #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ 189 #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
190 #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ 190 #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
191 #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ 191 #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
192 #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ 192 #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
193 #define EM_SVX 73 /* Silicon Graphics SVx */ 193 #define EM_SVX 73 /* Silicon Graphics SVx */
194 #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ 194 #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
195 #define EM_VAX 75 /* Digital VAX */ 195 #define EM_VAX 75 /* Digital VAX */
196 #define EM_CHRIS 76 /* Axis Communications embedded proc. */ 196 #define EM_CHRIS 76 /* Axis Communications embedded proc. */
197 #define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */ 197 #define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
198 #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ 198 #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
199 #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ 199 #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
200 #define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */ 200 #define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
201 #define EM_HUANY 81 /* Harvard University mach-indep objs */ 201 #define EM_HUANY 81 /* Harvard University mach-indep objs */
202 #define EM_PRISM 82 /* SiTera Prism */ 202 #define EM_PRISM 82 /* SiTera Prism */
203 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ 203 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
204 #define EM_FR30 84 /* Fujitsu FR30 */ 204 #define EM_FR30 84 /* Fujitsu FR30 */
205 #define EM_D10V 85 /* Mitsubishi DV10V */ 205 #define EM_D10V 85 /* Mitsubishi DV10V */
206 #define EM_D30V 86 /* Mitsubishi DV30V */ 206 #define EM_D30V 86 /* Mitsubishi DV30V */
207 #define EM_V850 87 /* NEC v850 */ 207 #define EM_V850 87 /* NEC v850 */
208 #define EM_M32R 88 /* Mitsubishi M32R */ 208 #define EM_M32R 88 /* Mitsubishi M32R */
209 #define EM_MN10300 89 /* Matsushita MN10200 */ 209 #define EM_MN10300 89 /* Matsushita MN10200 */
210 #define EM_MN10200 90 /* Matsushita MN10200 */ 210 #define EM_MN10200 90 /* Matsushita MN10200 */
211 #define EM_PJ 91 /* picoJava */ 211 #define EM_PJ 91 /* picoJava */
212 #define EM_NUM 92 /* number of machine types */ 212 #define EM_NUM 92 /* number of machine types */
213 213
214 /* Version */ 214 /* Version */
215 #define EV_NONE 0 /* Invalid */ 215 #define EV_NONE 0 /* Invalid */
216 #define EV_CURRENT 1 /* Current */ 216 #define EV_CURRENT 1 /* Current */
217 #define EV_NUM 2 /* number of versions */ 217 #define EV_NUM 2 /* number of versions */
218 218
219 /* Section Header */ 219 /* Section Header */
220 typedef struct { 220 typedef struct {
221 Elf32_Word sh_name; /* name - index into section header 221 Elf32_Word sh_name; /* name - index into section header
222 string table section */ 222 string table section */
223 Elf32_Word sh_type; /* type */ 223 Elf32_Word sh_type; /* type */
224 Elf32_Word sh_flags; /* flags */ 224 Elf32_Word sh_flags; /* flags */
225 Elf32_Addr sh_addr; /* address */ 225 Elf32_Addr sh_addr; /* address */
226 Elf32_Off sh_offset; /* file offset */ 226 Elf32_Off sh_offset; /* file offset */
227 Elf32_Word sh_size; /* section size */ 227 Elf32_Word sh_size; /* section size */
228 Elf32_Word sh_link; /* section header table index link */ 228 Elf32_Word sh_link; /* section header table index link */
229 Elf32_Word sh_info; /* extra information */ 229 Elf32_Word sh_info; /* extra information */
230 Elf32_Word sh_addralign; /* address alignment */ 230 Elf32_Word sh_addralign; /* address alignment */
231 Elf32_Word sh_entsize; /* section entry size */ 231 Elf32_Word sh_entsize; /* section entry size */
232 } Elf32_Shdr; 232 } Elf32_Shdr;
233 233
234 /* Special Section Indexes */ 234 /* Special Section Indexes */
235 #define SHN_UNDEF 0 /* undefined */ 235 #define SHN_UNDEF 0 /* undefined */
236 #define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ 236 #define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
237 #define SHN_LOPROC 0xff00 /* reserved range for processor */ 237 #define SHN_LOPROC 0xff00 /* reserved range for processor */
238 #define SHN_HIPROC 0xff1f /* specific section indexes */ 238 #define SHN_HIPROC 0xff1f /* specific section indexes */
239 #define SHN_LOOS 0xff20 /* reserved range for operating */ 239 #define SHN_LOOS 0xff20 /* reserved range for operating */
240 #define SHN_HIOS 0xff3f /* specific semantics */ 240 #define SHN_HIOS 0xff3f /* specific semantics */
241 #define SHN_ABS 0xfff1 /* absolute value */ 241 #define SHN_ABS 0xfff1 /* absolute value */
242 #define SHN_COMMON 0xfff2 /* common symbol */ 242 #define SHN_COMMON 0xfff2 /* common symbol */
243 #define SHN_XINDEX 0xffff /* Index is an extra table */ 243 #define SHN_XINDEX 0xffff /* Index is an extra table */
244 #define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ 244 #define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
245 245
246 /* sh_type */ 246 /* sh_type */
247 #define SHT_NULL 0 /* inactive */ 247 #define SHT_NULL 0 /* inactive */
248 #define SHT_PROGBITS 1 /* program defined information */ 248 #define SHT_PROGBITS 1 /* program defined information */
249 #define SHT_SYMTAB 2 /* symbol table section */ 249 #define SHT_SYMTAB 2 /* symbol table section */
250 #define SHT_STRTAB 3 /* string table section */ 250 #define SHT_STRTAB 3 /* string table section */
251 #define SHT_RELA 4 /* relocation section with addends*/ 251 #define SHT_RELA 4 /* relocation section with addends*/
252 #define SHT_HASH 5 /* symbol hash table section */ 252 #define SHT_HASH 5 /* symbol hash table section */
253 #define SHT_DYNAMIC 6 /* dynamic section */ 253 #define SHT_DYNAMIC 6 /* dynamic section */
254 #define SHT_NOTE 7 /* note section */ 254 #define SHT_NOTE 7 /* note section */
255 #define SHT_NOBITS 8 /* no space section */ 255 #define SHT_NOBITS 8 /* no space section */
256 #define SHT_REL 9 /* relation section without addends */ 256 #define SHT_REL 9 /* relation section without addends */
257 #define SHT_SHLIB 10 /* reserved - purpose unknown */ 257 #define SHT_SHLIB 10 /* reserved - purpose unknown */
258 #define SHT_DYNSYM 11 /* dynamic symbol table section */ 258 #define SHT_DYNSYM 11 /* dynamic symbol table section */
259 #define SHT_INIT_ARRAY 14 /* Array of constructors */ 259 #define SHT_INIT_ARRAY 14 /* Array of constructors */
260 #define SHT_FINI_ARRAY 15 /* Array of destructors */ 260 #define SHT_FINI_ARRAY 15 /* Array of destructors */
261 #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ 261 #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
262 #define SHT_GROUP 17 /* Section group */ 262 #define SHT_GROUP 17 /* Section group */
263 #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */ 263 #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
264 #define SHT_NUM 19 /* number of section types */ 264 #define SHT_NUM 19 /* number of section types */
265 #define SHT_LOOS 0x60000000 /* Start OS-specific */ 265 #define SHT_LOOS 0x60000000 /* Start OS-specific */
266 #define SHT_HIOS 0x6fffffff /* End OS-specific */ 266 #define SHT_HIOS 0x6fffffff /* End OS-specific */
267 #define SHT_LOPROC 0x70000000 /* reserved range for processor */ 267 #define SHT_LOPROC 0x70000000 /* reserved range for processor */
268 #define SHT_HIPROC 0x7fffffff /* specific section header types */ 268 #define SHT_HIPROC 0x7fffffff /* specific section header types */
269 #define SHT_LOUSER 0x80000000 /* reserved range for application */ 269 #define SHT_LOUSER 0x80000000 /* reserved range for application */
270 #define SHT_HIUSER 0xffffffff /* specific indexes */ 270 #define SHT_HIUSER 0xffffffff /* specific indexes */
271 271
272 /* Section names */ 272 /* Section names */
273 #define ELF_BSS ".bss" /* uninitialized data */ 273 #define ELF_BSS ".bss" /* uninitialized data */
274 #define ELF_COMMENT ".comment" /* version control information */ 274 #define ELF_COMMENT ".comment" /* version control information */
275 #define ELF_DATA ".data" /* initialized data */ 275 #define ELF_DATA ".data" /* initialized data */
276 #define ELF_DATA1 ".data1" /* initialized data */ 276 #define ELF_DATA1 ".data1" /* initialized data */
277 #define ELF_DEBUG ".debug" /* debug */ 277 #define ELF_DEBUG ".debug" /* debug */
278 #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ 278 #define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
279 #define ELF_DYNSTR ".dynstr" /* dynamic string table */ 279 #define ELF_DYNSTR ".dynstr" /* dynamic string table */
280 #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ 280 #define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
281 #define ELF_FINI ".fini" /* termination code */ 281 #define ELF_FINI ".fini" /* termination code */
282 #define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */ 282 #define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
283 #define ELF_GOT ".got" /* global offset table */ 283 #define ELF_GOT ".got" /* global offset table */
284 #define ELF_HASH ".hash" /* symbol hash table */ 284 #define ELF_HASH ".hash" /* symbol hash table */
285 #define ELF_INIT ".init" /* initialization code */ 285 #define ELF_INIT ".init" /* initialization code */
286 #define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */ 286 #define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
287 #define ELF_INTERP ".interp" /* Pathname of program interpreter */ 287 #define ELF_INTERP ".interp" /* Pathname of program interpreter */
288 #define ELF_LINE ".line" /* Symbolic line numnber information */ 288 #define ELF_LINE ".line" /* Symbolic line numnber information */
289 #define ELF_NOTE ".note" /* Contains note section */ 289 #define ELF_NOTE ".note" /* Contains note section */
290 #define ELF_PLT ".plt" /* Procedure linkage table */ 290 #define ELF_PLT ".plt" /* Procedure linkage table */
291 #define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */ 291 #define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
292 #define ELF_REL_DATA ".rel.data" /* relocation data */ 292 #define ELF_REL_DATA ".rel.data" /* relocation data */
293 #define ELF_REL_FINI ".rel.fini" /* relocation termination code */ 293 #define ELF_REL_FINI ".rel.fini" /* relocation termination code */
294 #define ELF_REL_INIT ".rel.init" /* relocation initialization code */ 294 #define ELF_REL_INIT ".rel.init" /* relocation initialization code */
295 #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ 295 #define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
296 #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ 296 #define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
297 #define ELF_REL_TEXT ".rel.text" /* relocation code */ 297 #define ELF_REL_TEXT ".rel.text" /* relocation code */
298 #define ELF_RODATA ".rodata" /* read-only data */ 298 #define ELF_RODATA ".rodata" /* read-only data */
299 #define ELF_RODATA1 ".rodata1" /* read-only data */ 299 #define ELF_RODATA1 ".rodata1" /* read-only data */
300 #define ELF_SHSTRTAB ".shstrtab" /* section header string table */ 300 #define ELF_SHSTRTAB ".shstrtab" /* section header string table */
301 #define ELF_STRTAB ".strtab" /* string table */ 301 #define ELF_STRTAB ".strtab" /* string table */
302 #define ELF_SYMTAB ".symtab" /* symbol table */ 302 #define ELF_SYMTAB ".symtab" /* symbol table */
303 #define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */ 303 #define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
304 #define ELF_TBSS ".tbss" /* thread local uninit data */ 304 #define ELF_TBSS ".tbss" /* thread local uninit data */
305 #define ELF_TDATA ".tdata" /* thread local init data */ 305 #define ELF_TDATA ".tdata" /* thread local init data */
306 #define ELF_TDATA1 ".tdata1" /* thread local init data */ 306 #define ELF_TDATA1 ".tdata1" /* thread local init data */
307 #define ELF_TEXT ".text" /* code */ 307 #define ELF_TEXT ".text" /* code */
308 308
309 /* Section Attribute Flags - sh_flags */ 309 /* Section Attribute Flags - sh_flags */
310 #define SHF_WRITE 0x1 /* Writable */ 310 #define SHF_WRITE 0x1 /* Writable */
311 #define SHF_ALLOC 0x2 /* occupies memory */ 311 #define SHF_ALLOC 0x2 /* occupies memory */
312 #define SHF_EXECINSTR 0x4 /* executable */ 312 #define SHF_EXECINSTR 0x4 /* executable */
313 #define SHF_MERGE 0x10 /* Might be merged */ 313 #define SHF_MERGE 0x10 /* Might be merged */
314 #define SHF_STRINGS 0x20 /* Contains NULL terminated strings */ 314 #define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
315 #define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */ 315 #define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
316 #define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/ 316 #define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
317 #define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */ 317 #define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
318 #define SHF_GROUP 0x200 /* Member of section group */ 318 #define SHF_GROUP 0x200 /* Member of section group */
319 #define SHF_TLS 0x400 /* Thread local storage */ 319 #define SHF_TLS 0x400 /* Thread local storage */
320 #define SHF_MASKOS 0x0ff00000 /* OS specific */ 320 #define SHF_MASKOS 0x0ff00000 /* OS specific */
321 #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ 321 #define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
322 /* specific section attributes */ 322 /* specific section attributes */
323 323
324 /* Section Group Flags */ 324 /* Section Group Flags */
325 #define GRP_COMDAT 0x1 /* COMDAT group */ 325 #define GRP_COMDAT 0x1 /* COMDAT group */
326 #define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */ 326 #define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
327 #define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */ 327 #define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
328 328
329 /* Symbol Table Entry */ 329 /* Symbol Table Entry */
330 typedef struct elf32_sym { 330 typedef struct elf32_sym {
331 Elf32_Word st_name; /* name - index into string table */ 331 Elf32_Word st_name; /* name - index into string table */
332 Elf32_Addr st_value; /* symbol value */ 332 Elf32_Addr st_value; /* symbol value */
333 Elf32_Word st_size; /* symbol size */ 333 Elf32_Word st_size; /* symbol size */
334 unsigned char st_info; /* type and binding */ 334 unsigned char st_info; /* type and binding */
335 unsigned char st_other; /* 0 - no defined meaning */ 335 unsigned char st_other; /* 0 - no defined meaning */
336 Elf32_Half st_shndx; /* section header index */ 336 Elf32_Half st_shndx; /* section header index */
337 } Elf32_Sym; 337 } Elf32_Sym;
338 338
339 /* Symbol table index */ 339 /* Symbol table index */
340 #define STN_UNDEF 0 /* undefined */ 340 #define STN_UNDEF 0 /* undefined */
341 341
342 /* Extract symbol info - st_info */ 342 /* Extract symbol info - st_info */
343 #define ELF32_ST_BIND(x) ((x) >> 4) 343 #define ELF32_ST_BIND(x) ((x) >> 4)
344 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) 344 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
345 #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) 345 #define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
346 #define ELF32_ST_VISIBILITY(x) ((x) & 0x3) 346 #define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
347 347
348 /* Symbol Binding - ELF32_ST_BIND - st_info */ 348 /* Symbol Binding - ELF32_ST_BIND - st_info */
349 #define STB_LOCAL 0 /* Local symbol */ 349 #define STB_LOCAL 0 /* Local symbol */
350 #define STB_GLOBAL 1 /* Global symbol */ 350 #define STB_GLOBAL 1 /* Global symbol */
351 #define STB_WEAK 2 /* like global - lower precedence */ 351 #define STB_WEAK 2 /* like global - lower precedence */
352 #define STB_NUM 3 /* number of symbol bindings */ 352 #define STB_NUM 3 /* number of symbol bindings */
353 #define STB_LOOS 10 /* reserved range for operating */ 353 #define STB_LOOS 10 /* reserved range for operating */
354 #define STB_HIOS 12 /* system specific symbol bindings */ 354 #define STB_HIOS 12 /* system specific symbol bindings */
355 #define STB_LOPROC 13 /* reserved range for processor */ 355 #define STB_LOPROC 13 /* reserved range for processor */
356 #define STB_HIPROC 15 /* specific symbol bindings */ 356 #define STB_HIPROC 15 /* specific symbol bindings */
357 357
358 /* Symbol type - ELF32_ST_TYPE - st_info */ 358 /* Symbol type - ELF32_ST_TYPE - st_info */
359 #define STT_NOTYPE 0 /* not specified */ 359 #define STT_NOTYPE 0 /* not specified */
360 #define STT_OBJECT 1 /* data object */ 360 #define STT_OBJECT 1 /* data object */
361 #define STT_FUNC 2 /* function */ 361 #define STT_FUNC 2 /* function */
362 #define STT_SECTION 3 /* section */ 362 #define STT_SECTION 3 /* section */
363 #define STT_FILE 4 /* file */ 363 #define STT_FILE 4 /* file */
364 #define STT_NUM 5 /* number of symbol types */ 364 #define STT_NUM 5 /* number of symbol types */
365 #define STT_TLS 6 /* Thread local storage symbol */ 365 #define STT_TLS 6 /* Thread local storage symbol */
366 #define STT_LOOS 10 /* reserved range for operating */ 366 #define STT_LOOS 10 /* reserved range for operating */
367 #define STT_HIOS 12 /* system specific symbol types */ 367 #define STT_HIOS 12 /* system specific symbol types */
368 #define STT_LOPROC 13 /* reserved range for processor */ 368 #define STT_LOPROC 13 /* reserved range for processor */
369 #define STT_HIPROC 15 /* specific symbol types */ 369 #define STT_HIPROC 15 /* specific symbol types */
370 370
371 /* Symbol visibility - ELF32_ST_VISIBILITY - st_other */ 371 /* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
372 #define STV_DEFAULT 0 /* Normal visibility rules */ 372 #define STV_DEFAULT 0 /* Normal visibility rules */
373 #define STV_INTERNAL 1 /* Processor specific hidden class */ 373 #define STV_INTERNAL 1 /* Processor specific hidden class */
374 #define STV_HIDDEN 2 /* Symbol unavailable in other mods */ 374 #define STV_HIDDEN 2 /* Symbol unavailable in other mods */
375 #define STV_PROTECTED 3 /* Not preemptible, not exported */ 375 #define STV_PROTECTED 3 /* Not preemptible, not exported */
376 376
377 377
378 /* Relocation entry with implicit addend */ 378 /* Relocation entry with implicit addend */
379 typedef struct 379 typedef struct
380 { 380 {
381 Elf32_Addr r_offset; /* offset of relocation */ 381 Elf32_Addr r_offset; /* offset of relocation */
382 Elf32_Word r_info; /* symbol table index and type */ 382 Elf32_Word r_info; /* symbol table index and type */
383 } Elf32_Rel; 383 } Elf32_Rel;
384 384
385 /* Relocation entry with explicit addend */ 385 /* Relocation entry with explicit addend */
386 typedef struct 386 typedef struct
387 { 387 {
388 Elf32_Addr r_offset; /* offset of relocation */ 388 Elf32_Addr r_offset; /* offset of relocation */
389 Elf32_Word r_info; /* symbol table index and type */ 389 Elf32_Word r_info; /* symbol table index and type */
390 Elf32_Sword r_addend; 390 Elf32_Sword r_addend;
391 } Elf32_Rela; 391 } Elf32_Rela;
392 392
393 typedef struct { 393 typedef struct {
394 Elf64_Addr r_offset; /* Location at which to apply the action */ 394 Elf64_Addr r_offset; /* Location at which to apply the action */
395 Elf64_Xword r_info; /* index and type of relocation */ 395 Elf64_Xword r_info; /* index and type of relocation */
396 } Elf64_Rel; 396 } Elf64_Rel;
397 397
398 typedef struct { 398 typedef struct {
399 Elf64_Addr r_offset; /* Location at which to apply the action */ 399 Elf64_Addr r_offset; /* Location at which to apply the action */
400 Elf64_Xword r_info; /* index and type of relocation */ 400 Elf64_Xword r_info; /* index and type of relocation */
401 Elf64_Sxword r_addend; /* Constant addend used to compute value */ 401 Elf64_Sxword r_addend; /* Constant addend used to compute value */
402 } Elf64_Rela; 402 } Elf64_Rela;
403 403
404 /* Extract relocation info - r_info */ 404 /* Extract relocation info - r_info */
405 #define ELF32_R_SYM(i) ((i) >> 8) 405 #define ELF32_R_SYM(i) ((i) >> 8)
406 #define ELF32_R_TYPE(i) ((unsigned char) (i)) 406 #define ELF32_R_TYPE(i) ((unsigned char) (i))
407 #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) 407 #define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
408 408
409 /* Program Header */ 409 /* Program Header */
410 typedef struct { 410 typedef struct {
411 Elf32_Word p_type; /* segment type */ 411 Elf32_Word p_type; /* segment type */
412 Elf32_Off p_offset; /* segment offset */ 412 Elf32_Off p_offset; /* segment offset */
413 Elf32_Addr p_vaddr; /* virtual address of segment */ 413 Elf32_Addr p_vaddr; /* virtual address of segment */
414 Elf32_Addr p_paddr; /* physical address - ignored? */ 414 Elf32_Addr p_paddr; /* physical address - ignored? */
415 Elf32_Word p_filesz; /* number of bytes in file for seg. */ 415 Elf32_Word p_filesz; /* number of bytes in file for seg. */
416 Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ 416 Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
417 Elf32_Word p_flags; /* flags */ 417 Elf32_Word p_flags; /* flags */
418 Elf32_Word p_align; /* memory alignment */ 418 Elf32_Word p_align; /* memory alignment */
419 } Elf32_Phdr; 419 } Elf32_Phdr;
420 420
421 /* Segment types - p_type */ 421 /* Segment types - p_type */
422 #define PT_NULL 0 /* unused */ 422 #define PT_NULL 0 /* unused */
423 #define PT_LOAD 1 /* loadable segment */ 423 #define PT_LOAD 1 /* loadable segment */
424 #define PT_DYNAMIC 2 /* dynamic linking section */ 424 #define PT_DYNAMIC 2 /* dynamic linking section */
425 #define PT_INTERP 3 /* the RTLD */ 425 #define PT_INTERP 3 /* the RTLD */
426 #define PT_NOTE 4 /* auxiliary information */ 426 #define PT_NOTE 4 /* auxiliary information */
427 #define PT_SHLIB 5 /* reserved - purpose undefined */ 427 #define PT_SHLIB 5 /* reserved - purpose undefined */
428 #define PT_PHDR 6 /* program header */ 428 #define PT_PHDR 6 /* program header */
429 #define PT_TLS 7 /* Thread local storage template */ 429 #define PT_TLS 7 /* Thread local storage template */
430 #define PT_NUM 8 /* Number of segment types */ 430 #define PT_NUM 8 /* Number of segment types */
431 #define PT_LOOS 0x60000000 /* reserved range for operating */ 431 #define PT_LOOS 0x60000000 /* reserved range for operating */
432 #define PT_HIOS 0x6fffffff /* system specific segment types */ 432 #define PT_HIOS 0x6fffffff /* system specific segment types */
433 #define PT_LOPROC 0x70000000 /* reserved range for processor */ 433 #define PT_LOPROC 0x70000000 /* reserved range for processor */
434 #define PT_HIPROC 0x7fffffff /* specific segment types */ 434 #define PT_HIPROC 0x7fffffff /* specific segment types */
435 435
436 /* Segment flags - p_flags */ 436 /* Segment flags - p_flags */
437 #define PF_X 0x1 /* Executable */ 437 #define PF_X 0x1 /* Executable */
438 #define PF_W 0x2 /* Writable */ 438 #define PF_W 0x2 /* Writable */
439 #define PF_R 0x4 /* Readable */ 439 #define PF_R 0x4 /* Readable */
440 #define PF_MASKOS 0x0ff00000 /* OS specific segment flags */ 440 #define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
441 #define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ 441 #define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
442 /* specific segment flags */ 442 /* specific segment flags */
443 /* Dynamic structure */ 443 /* Dynamic structure */
444 typedef struct 444 typedef struct
445 { 445 {
446 Elf32_Sword d_tag; /* controls meaning of d_val */ 446 Elf32_Sword d_tag; /* controls meaning of d_val */
447 union 447 union
448 { 448 {
449 Elf32_Word d_val; /* Multiple meanings - see d_tag */ 449 Elf32_Word d_val; /* Multiple meanings - see d_tag */
450 Elf32_Addr d_ptr; /* program virtual address */ 450 Elf32_Addr d_ptr; /* program virtual address */
451 } d_un; 451 } d_un;
452 } Elf32_Dyn; 452 } Elf32_Dyn;
453 453
454 extern Elf32_Dyn _DYNAMIC[]; 454 extern Elf32_Dyn _DYNAMIC[];
455 455
456 typedef struct { 456 typedef struct {
457 Elf64_Sxword d_tag; /* entry tag value */ 457 Elf64_Sxword d_tag; /* entry tag value */
458 union { 458 union {
459 Elf64_Xword d_val; 459 Elf64_Xword d_val;
460 Elf64_Addr d_ptr; 460 Elf64_Addr d_ptr;
461 } d_un; 461 } d_un;
462 } Elf64_Dyn; 462 } Elf64_Dyn;
463 463
464 #define ELF64_R_SYM(i) ((i) >> 32) 464 #define ELF64_R_SYM(i) ((i) >> 32)
465 #define ELF64_R_TYPE(i) ((i) & 0xffffffff) 465 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
466 466
467 /* Dynamic Array Tags - d_tag */ 467 /* Dynamic Array Tags - d_tag */
468 #define DT_NULL 0 /* marks end of _DYNAMIC array */ 468 #define DT_NULL 0 /* marks end of _DYNAMIC array */
469 #define DT_NEEDED 1 /* string table offset of needed lib */ 469 #define DT_NEEDED 1 /* string table offset of needed lib */
470 #define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ 470 #define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
471 #define DT_PLTGOT 3 /* address PLT/GOT */ 471 #define DT_PLTGOT 3 /* address PLT/GOT */
472 #define DT_HASH 4 /* address of symbol hash table */ 472 #define DT_HASH 4 /* address of symbol hash table */
473 #define DT_STRTAB 5 /* address of string table */ 473 #define DT_STRTAB 5 /* address of string table */
474 #define DT_SYMTAB 6 /* address of symbol table */ 474 #define DT_SYMTAB 6 /* address of symbol table */
475 #define DT_RELA 7 /* address of relocation table */ 475 #define DT_RELA 7 /* address of relocation table */
476 #define DT_RELASZ 8 /* size of relocation table */ 476 #define DT_RELASZ 8 /* size of relocation table */
477 #define DT_RELAENT 9 /* size of relocation entry */ 477 #define DT_RELAENT 9 /* size of relocation entry */
478 #define DT_STRSZ 10 /* size of string table */ 478 #define DT_STRSZ 10 /* size of string table */
479 #define DT_SYMENT 11 /* size of symbol table entry */ 479 #define DT_SYMENT 11 /* size of symbol table entry */
480 #define DT_INIT 12 /* address of initialization func. */ 480 #define DT_INIT 12 /* address of initialization func. */
481 #define DT_FINI 13 /* address of termination function */ 481 #define DT_FINI 13 /* address of termination function */
482 #define DT_SONAME 14 /* string table offset of shared obj */ 482 #define DT_SONAME 14 /* string table offset of shared obj */
483 #define DT_RPATH 15 /* string table offset of library 483 #define DT_RPATH 15 /* string table offset of library
484 search path */ 484 search path */
485 #define DT_SYMBOLIC 16 /* start sym search in shared obj. */ 485 #define DT_SYMBOLIC 16 /* start sym search in shared obj. */
486 #define DT_REL 17 /* address of rel. tbl. w addends */ 486 #define DT_REL 17 /* address of rel. tbl. w addends */
487 #define DT_RELSZ 18 /* size of DT_REL relocation table */ 487 #define DT_RELSZ 18 /* size of DT_REL relocation table */
488 #define DT_RELENT 19 /* size of DT_REL relocation entry */ 488 #define DT_RELENT 19 /* size of DT_REL relocation entry */
489 #define DT_PLTREL 20 /* PLT referenced relocation entry */ 489 #define DT_PLTREL 20 /* PLT referenced relocation entry */
490 #define DT_DEBUG 21 /* bugger */ 490 #define DT_DEBUG 21 /* bugger */
491 #define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ 491 #define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
492 #define DT_JMPREL 23 /* add. of PLT's relocation entries */ 492 #define DT_JMPREL 23 /* add. of PLT's relocation entries */
493 #define DT_BIND_NOW 24 /* Process relocations of object */ 493 #define DT_BIND_NOW 24 /* Process relocations of object */
494 #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ 494 #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
495 #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ 495 #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
496 #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ 496 #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
497 #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ 497 #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
498 #define DT_RUNPATH 29 /* Library search path */ 498 #define DT_RUNPATH 29 /* Library search path */
499 #define DT_FLAGS 30 /* Flags for the object being loaded */ 499 #define DT_FLAGS 30 /* Flags for the object being loaded */
500 #define DT_ENCODING 32 /* Start of encoded range */ 500 #define DT_ENCODING 32 /* Start of encoded range */
501 #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ 501 #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
502 #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ 502 #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
503 #define DT_NUM 34 /* Number used. */ 503 #define DT_NUM 34 /* Number used. */
504 #define DT_LOOS 0x60000000 /* reserved range for OS */ 504 #define DT_LOOS 0x60000000 /* reserved range for OS */
505 #define DT_HIOS 0x6fffffff /* specific dynamic array tags */ 505 #define DT_HIOS 0x6fffffff /* specific dynamic array tags */
506 #define DT_LOPROC 0x70000000 /* reserved range for processor */ 506 #define DT_LOPROC 0x70000000 /* reserved range for processor */
507 #define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ 507 #define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
508 508
509 /* Dynamic Tag Flags - d_un.d_val */ 509 /* Dynamic Tag Flags - d_un.d_val */
510 #define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */ 510 #define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
511 #define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */ 511 #define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
512 #define DF_TEXTREL 0x04 /* Object contains text relocations */ 512 #define DF_TEXTREL 0x04 /* Object contains text relocations */
513 #define DF_BIND_NOW 0x08 /* No lazy binding for this object */ 513 #define DF_BIND_NOW 0x08 /* No lazy binding for this object */
514 #define DF_STATIC_TLS 0x10 /* Static thread local storage */ 514 #define DF_STATIC_TLS 0x10 /* Static thread local storage */
515 515
516 /* Standard ELF hashing function */ 516 /* Standard ELF hashing function */
517 unsigned long elf_hash(const unsigned char *name); 517 unsigned long elf_hash(const unsigned char *name);
518 518
519 #define ELF_TARG_VER 1 /* The ver for which this code is intended */ 519 #define ELF_TARG_VER 1 /* The ver for which this code is intended */
520 520
521 #endif /* __ASSEMBLER */ 521 #endif /* __ASSEMBLER */
522 522
523 /* 523 /*
524 * XXX - PowerPC defines really don't belong in here, 524 * XXX - PowerPC defines really don't belong in here,
525 * but we'll put them in for simplicity. 525 * but we'll put them in for simplicity.
526 */ 526 */
527 527
528 /* Values for Elf32/64_Ehdr.e_flags. */ 528 /* Values for Elf32/64_Ehdr.e_flags. */
529 #define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ 529 #define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
530 530
531 /* Cygnus local bits below */ 531 /* Cygnus local bits below */
532 #define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ 532 #define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
533 #define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib 533 #define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
534 flag */ 534 flag */
535 535
536 /* PowerPC relocations defined by the ABIs */ 536 /* PowerPC relocations defined by the ABIs */
537 #define R_PPC_NONE 0 537 #define R_PPC_NONE 0
538 #define R_PPC_ADDR32 1 /* 32bit absolute address */ 538 #define R_PPC_ADDR32 1 /* 32bit absolute address */
539 #define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ 539 #define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
540 #define R_PPC_ADDR16 3 /* 16bit absolute address */ 540 #define R_PPC_ADDR16 3 /* 16bit absolute address */
541 #define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ 541 #define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
542 #define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ 542 #define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
543 #define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ 543 #define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
544 #define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ 544 #define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
545 #define R_PPC_ADDR14_BRTAKEN 8 545 #define R_PPC_ADDR14_BRTAKEN 8
546 #define R_PPC_ADDR14_BRNTAKEN 9 546 #define R_PPC_ADDR14_BRNTAKEN 9
547 #define R_PPC_REL24 10 /* PC relative 26 bit */ 547 #define R_PPC_REL24 10 /* PC relative 26 bit */
548 #define R_PPC_REL14 11 /* PC relative 16 bit */ 548 #define R_PPC_REL14 11 /* PC relative 16 bit */
549 #define R_PPC_REL14_BRTAKEN 12 549 #define R_PPC_REL14_BRTAKEN 12
550 #define R_PPC_REL14_BRNTAKEN 13 550 #define R_PPC_REL14_BRNTAKEN 13
551 #define R_PPC_GOT16 14 551 #define R_PPC_GOT16 14
552 #define R_PPC_GOT16_LO 15 552 #define R_PPC_GOT16_LO 15
553 #define R_PPC_GOT16_HI 16 553 #define R_PPC_GOT16_HI 16
554 #define R_PPC_GOT16_HA 17 554 #define R_PPC_GOT16_HA 17
555 #define R_PPC_PLTREL24 18 555 #define R_PPC_PLTREL24 18
556 #define R_PPC_COPY 19 556 #define R_PPC_COPY 19
557 #define R_PPC_GLOB_DAT 20 557 #define R_PPC_GLOB_DAT 20
558 #define R_PPC_JMP_SLOT 21 558 #define R_PPC_JMP_SLOT 21
559 #define R_PPC_RELATIVE 22 559 #define R_PPC_RELATIVE 22
560 #define R_PPC_LOCAL24PC 23 560 #define R_PPC_LOCAL24PC 23
561 #define R_PPC_UADDR32 24 561 #define R_PPC_UADDR32 24
562 #define R_PPC_UADDR16 25 562 #define R_PPC_UADDR16 25
563 #define R_PPC_REL32 26 563 #define R_PPC_REL32 26
564 #define R_PPC_PLT32 27 564 #define R_PPC_PLT32 27
565 #define R_PPC_PLTREL32 28 565 #define R_PPC_PLTREL32 28
566 #define R_PPC_PLT16_LO 29 566 #define R_PPC_PLT16_LO 29
567 #define R_PPC_PLT16_HI 30 567 #define R_PPC_PLT16_HI 30
568 #define R_PPC_PLT16_HA 31 568 #define R_PPC_PLT16_HA 31
569 #define R_PPC_SDAREL16 32 569 #define R_PPC_SDAREL16 32
570 #define R_PPC_SECTOFF 33 570 #define R_PPC_SECTOFF 33
571 #define R_PPC_SECTOFF_LO 34 571 #define R_PPC_SECTOFF_LO 34
572 #define R_PPC_SECTOFF_HI 35 572 #define R_PPC_SECTOFF_HI 35
573 #define R_PPC_SECTOFF_HA 36 573 #define R_PPC_SECTOFF_HA 36
574 /* Keep this the last entry. */ 574 /* Keep this the last entry. */
575 #define R_PPC_NUM 37 575 #define R_PPC_NUM 37
576 576
577 /* The remaining relocs are from the Embedded ELF ABI, and are not 577 /* The remaining relocs are from the Embedded ELF ABI, and are not
578 in the SVR4 ELF ABI. */ 578 in the SVR4 ELF ABI. */
579 #define R_PPC_EMB_NADDR32 101 579 #define R_PPC_EMB_NADDR32 101
580 #define R_PPC_EMB_NADDR16 102 580 #define R_PPC_EMB_NADDR16 102
581 #define R_PPC_EMB_NADDR16_LO 103 581 #define R_PPC_EMB_NADDR16_LO 103
582 #define R_PPC_EMB_NADDR16_HI 104 582 #define R_PPC_EMB_NADDR16_HI 104
583 #define R_PPC_EMB_NADDR16_HA 105 583 #define R_PPC_EMB_NADDR16_HA 105
584 #define R_PPC_EMB_SDAI16 106 584 #define R_PPC_EMB_SDAI16 106
585 #define R_PPC_EMB_SDA2I16 107 585 #define R_PPC_EMB_SDA2I16 107
586 #define R_PPC_EMB_SDA2REL 108 586 #define R_PPC_EMB_SDA2REL 108
587 #define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ 587 #define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
588 #define R_PPC_EMB_MRKREF 110 588 #define R_PPC_EMB_MRKREF 110
589 #define R_PPC_EMB_RELSEC16 111 589 #define R_PPC_EMB_RELSEC16 111
590 #define R_PPC_EMB_RELST_LO 112 590 #define R_PPC_EMB_RELST_LO 112
591 #define R_PPC_EMB_RELST_HI 113 591 #define R_PPC_EMB_RELST_HI 113
592 #define R_PPC_EMB_RELST_HA 114 592 #define R_PPC_EMB_RELST_HA 114
593 #define R_PPC_EMB_BIT_FLD 115 593 #define R_PPC_EMB_BIT_FLD 115
594 #define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ 594 #define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
595 595
596 /* Diab tool relocations. */ 596 /* Diab tool relocations. */
597 #define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ 597 #define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
598 #define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ 598 #define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
599 #define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ 599 #define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
600 #define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ 600 #define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
601 #define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ 601 #define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
602 #define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ 602 #define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
603 603
604 /* This is a phony reloc to handle any old fashioned TOC16 references 604 /* This is a phony reloc to handle any old fashioned TOC16 references
605 that may still be in object files. */ 605 that may still be in object files. */
606 #define R_PPC_TOC16 255 606 #define R_PPC_TOC16 255
607 607
608 /* ARM relocs */ 608 /* ARM relocs */
609 #define R_ARM_NONE 0 /* No reloc */ 609 #define R_ARM_NONE 0 /* No reloc */
610 #define R_ARM_RELATIVE 23 /* Adjust by program base */ 610 #define R_ARM_RELATIVE 23 /* Adjust by program base */
611 611
612 /* AArch64 relocs */ 612 /* AArch64 relocs */
613 #define R_AARCH64_NONE 0 /* No relocation. */ 613 #define R_AARCH64_NONE 0 /* No relocation. */
614 #define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */ 614 #define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */
615 615
616 /* RISC-V relocations */
617 #define R_RISCV_32 1
618 #define R_RISCV_64 2
619 #define R_RISCV_RELATIVE 3
620
616 #ifndef __ASSEMBLER__ 621 #ifndef __ASSEMBLER__
617 int valid_elf_image(unsigned long addr); 622 int valid_elf_image(unsigned long addr);
618 #endif 623 #endif
619 624
620 #endif /* _ELF_H */ 625 #endif /* _ELF_H */
621 626
1 /* 1 /*
2 * (C) Copyright 2008 Semihalf 2 * (C) Copyright 2008 Semihalf
3 * 3 *
4 * (C) Copyright 2000-2005 4 * (C) Copyright 2000-2005
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * 6 *
7 * SPDX-License-Identifier: GPL-2.0+ 7 * SPDX-License-Identifier: GPL-2.0+
8 ******************************************************************** 8 ********************************************************************
9 * NOTE: This header file defines an interface to U-Boot. Including 9 * NOTE: This header file defines an interface to U-Boot. Including
10 * this (unmodified) header file in another file is considered normal 10 * this (unmodified) header file in another file is considered normal
11 * use of U-Boot, and does *not* fall under the heading of "derived 11 * use of U-Boot, and does *not* fall under the heading of "derived
12 * work". 12 * work".
13 ******************************************************************** 13 ********************************************************************
14 */ 14 */
15 15
16 #ifndef __IMAGE_H__ 16 #ifndef __IMAGE_H__
17 #define __IMAGE_H__ 17 #define __IMAGE_H__
18 18
19 #include "compiler.h" 19 #include "compiler.h"
20 #include <asm/byteorder.h> 20 #include <asm/byteorder.h>
21 21
22 /* Define this to avoid #ifdefs later on */ 22 /* Define this to avoid #ifdefs later on */
23 struct lmb; 23 struct lmb;
24 24
25 #ifdef USE_HOSTCC 25 #ifdef USE_HOSTCC
26 #include <sys/types.h> 26 #include <sys/types.h>
27 27
28 /* new uImage format support enabled on host */ 28 /* new uImage format support enabled on host */
29 #define IMAGE_ENABLE_FIT 1 29 #define IMAGE_ENABLE_FIT 1
30 #define IMAGE_ENABLE_OF_LIBFDT 1 30 #define IMAGE_ENABLE_OF_LIBFDT 1
31 #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */ 31 #define CONFIG_FIT_VERBOSE 1 /* enable fit_format_{error,warning}() */
32 #define CONFIG_FIT_ENABLE_SHA256_SUPPORT 32 #define CONFIG_FIT_ENABLE_SHA256_SUPPORT
33 #define CONFIG_SHA1 33 #define CONFIG_SHA1
34 #define CONFIG_SHA256 34 #define CONFIG_SHA256
35 35
36 #define IMAGE_ENABLE_IGNORE 0 36 #define IMAGE_ENABLE_IGNORE 0
37 #define IMAGE_INDENT_STRING "" 37 #define IMAGE_INDENT_STRING ""
38 38
39 #else 39 #else
40 40
41 #include <lmb.h> 41 #include <lmb.h>
42 #include <asm/u-boot.h> 42 #include <asm/u-boot.h>
43 #include <command.h> 43 #include <command.h>
44 44
45 /* Take notice of the 'ignore' property for hashes */ 45 /* Take notice of the 'ignore' property for hashes */
46 #define IMAGE_ENABLE_IGNORE 1 46 #define IMAGE_ENABLE_IGNORE 1
47 #define IMAGE_INDENT_STRING " " 47 #define IMAGE_INDENT_STRING " "
48 48
49 #define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT) 49 #define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT)
50 #define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT) 50 #define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT)
51 51
52 #endif /* USE_HOSTCC */ 52 #endif /* USE_HOSTCC */
53 53
54 #if IMAGE_ENABLE_FIT 54 #if IMAGE_ENABLE_FIT
55 #include <hash.h> 55 #include <hash.h>
56 #include <libfdt.h> 56 #include <libfdt.h>
57 #include <fdt_support.h> 57 #include <fdt_support.h>
58 # ifdef CONFIG_SPL_BUILD 58 # ifdef CONFIG_SPL_BUILD
59 # ifdef CONFIG_SPL_CRC32_SUPPORT 59 # ifdef CONFIG_SPL_CRC32_SUPPORT
60 # define IMAGE_ENABLE_CRC32 1 60 # define IMAGE_ENABLE_CRC32 1
61 # endif 61 # endif
62 # ifdef CONFIG_SPL_MD5_SUPPORT 62 # ifdef CONFIG_SPL_MD5_SUPPORT
63 # define IMAGE_ENABLE_MD5 1 63 # define IMAGE_ENABLE_MD5 1
64 # endif 64 # endif
65 # ifdef CONFIG_SPL_SHA1_SUPPORT 65 # ifdef CONFIG_SPL_SHA1_SUPPORT
66 # define IMAGE_ENABLE_SHA1 1 66 # define IMAGE_ENABLE_SHA1 1
67 # endif 67 # endif
68 # else 68 # else
69 # define CONFIG_CRC32 /* FIT images need CRC32 support */ 69 # define CONFIG_CRC32 /* FIT images need CRC32 support */
70 # define IMAGE_ENABLE_CRC32 1 70 # define IMAGE_ENABLE_CRC32 1
71 # define IMAGE_ENABLE_MD5 1 71 # define IMAGE_ENABLE_MD5 1
72 # define IMAGE_ENABLE_SHA1 1 72 # define IMAGE_ENABLE_SHA1 1
73 # endif 73 # endif
74 74
75 #ifndef IMAGE_ENABLE_CRC32 75 #ifndef IMAGE_ENABLE_CRC32
76 #define IMAGE_ENABLE_CRC32 0 76 #define IMAGE_ENABLE_CRC32 0
77 #endif 77 #endif
78 78
79 #ifndef IMAGE_ENABLE_MD5 79 #ifndef IMAGE_ENABLE_MD5
80 #define IMAGE_ENABLE_MD5 0 80 #define IMAGE_ENABLE_MD5 0
81 #endif 81 #endif
82 82
83 #ifndef IMAGE_ENABLE_SHA1 83 #ifndef IMAGE_ENABLE_SHA1
84 #define IMAGE_ENABLE_SHA1 0 84 #define IMAGE_ENABLE_SHA1 0
85 #endif 85 #endif
86 86
87 #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \ 87 #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \
88 defined(CONFIG_SPL_SHA256_SUPPORT) 88 defined(CONFIG_SPL_SHA256_SUPPORT)
89 #define IMAGE_ENABLE_SHA256 1 89 #define IMAGE_ENABLE_SHA256 1
90 #else 90 #else
91 #define IMAGE_ENABLE_SHA256 0 91 #define IMAGE_ENABLE_SHA256 0
92 #endif 92 #endif
93 93
94 #endif /* IMAGE_ENABLE_FIT */ 94 #endif /* IMAGE_ENABLE_FIT */
95 95
96 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE 96 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
97 # define IMAGE_BOOT_GET_CMDLINE 1 97 # define IMAGE_BOOT_GET_CMDLINE 1
98 #else 98 #else
99 # define IMAGE_BOOT_GET_CMDLINE 0 99 # define IMAGE_BOOT_GET_CMDLINE 0
100 #endif 100 #endif
101 101
102 #ifdef CONFIG_OF_BOARD_SETUP 102 #ifdef CONFIG_OF_BOARD_SETUP
103 # define IMAGE_OF_BOARD_SETUP 1 103 # define IMAGE_OF_BOARD_SETUP 1
104 #else 104 #else
105 # define IMAGE_OF_BOARD_SETUP 0 105 # define IMAGE_OF_BOARD_SETUP 0
106 #endif 106 #endif
107 107
108 #ifdef CONFIG_OF_SYSTEM_SETUP 108 #ifdef CONFIG_OF_SYSTEM_SETUP
109 # define IMAGE_OF_SYSTEM_SETUP 1 109 # define IMAGE_OF_SYSTEM_SETUP 1
110 #else 110 #else
111 # define IMAGE_OF_SYSTEM_SETUP 0 111 # define IMAGE_OF_SYSTEM_SETUP 0
112 #endif 112 #endif
113 113
114 enum ih_category { 114 enum ih_category {
115 IH_ARCH, 115 IH_ARCH,
116 IH_COMP, 116 IH_COMP,
117 IH_OS, 117 IH_OS,
118 IH_TYPE, 118 IH_TYPE,
119 119
120 IH_COUNT, 120 IH_COUNT,
121 }; 121 };
122 122
123 /* 123 /*
124 * Operating System Codes 124 * Operating System Codes
125 * 125 *
126 * The following are exposed to uImage header. 126 * The following are exposed to uImage header.
127 * Do not change values for backward compatibility. 127 * Do not change values for backward compatibility.
128 */ 128 */
129 enum { 129 enum {
130 IH_OS_INVALID = 0, /* Invalid OS */ 130 IH_OS_INVALID = 0, /* Invalid OS */
131 IH_OS_OPENBSD, /* OpenBSD */ 131 IH_OS_OPENBSD, /* OpenBSD */
132 IH_OS_NETBSD, /* NetBSD */ 132 IH_OS_NETBSD, /* NetBSD */
133 IH_OS_FREEBSD, /* FreeBSD */ 133 IH_OS_FREEBSD, /* FreeBSD */
134 IH_OS_4_4BSD, /* 4.4BSD */ 134 IH_OS_4_4BSD, /* 4.4BSD */
135 IH_OS_LINUX, /* Linux */ 135 IH_OS_LINUX, /* Linux */
136 IH_OS_SVR4, /* SVR4 */ 136 IH_OS_SVR4, /* SVR4 */
137 IH_OS_ESIX, /* Esix */ 137 IH_OS_ESIX, /* Esix */
138 IH_OS_SOLARIS, /* Solaris */ 138 IH_OS_SOLARIS, /* Solaris */
139 IH_OS_IRIX, /* Irix */ 139 IH_OS_IRIX, /* Irix */
140 IH_OS_SCO, /* SCO */ 140 IH_OS_SCO, /* SCO */
141 IH_OS_DELL, /* Dell */ 141 IH_OS_DELL, /* Dell */
142 IH_OS_NCR, /* NCR */ 142 IH_OS_NCR, /* NCR */
143 IH_OS_LYNXOS, /* LynxOS */ 143 IH_OS_LYNXOS, /* LynxOS */
144 IH_OS_VXWORKS, /* VxWorks */ 144 IH_OS_VXWORKS, /* VxWorks */
145 IH_OS_PSOS, /* pSOS */ 145 IH_OS_PSOS, /* pSOS */
146 IH_OS_QNX, /* QNX */ 146 IH_OS_QNX, /* QNX */
147 IH_OS_U_BOOT, /* Firmware */ 147 IH_OS_U_BOOT, /* Firmware */
148 IH_OS_RTEMS, /* RTEMS */ 148 IH_OS_RTEMS, /* RTEMS */
149 IH_OS_ARTOS, /* ARTOS */ 149 IH_OS_ARTOS, /* ARTOS */
150 IH_OS_UNITY, /* Unity OS */ 150 IH_OS_UNITY, /* Unity OS */
151 IH_OS_INTEGRITY, /* INTEGRITY */ 151 IH_OS_INTEGRITY, /* INTEGRITY */
152 IH_OS_OSE, /* OSE */ 152 IH_OS_OSE, /* OSE */
153 IH_OS_PLAN9, /* Plan 9 */ 153 IH_OS_PLAN9, /* Plan 9 */
154 IH_OS_OPENRTOS, /* OpenRTOS */ 154 IH_OS_OPENRTOS, /* OpenRTOS */
155 IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */ 155 IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */
156 156
157 IH_OS_COUNT, 157 IH_OS_COUNT,
158 }; 158 };
159 159
160 /* 160 /*
161 * CPU Architecture Codes (supported by Linux) 161 * CPU Architecture Codes (supported by Linux)
162 * 162 *
163 * The following are exposed to uImage header. 163 * The following are exposed to uImage header.
164 * Do not change values for backward compatibility. 164 * Do not change values for backward compatibility.
165 */ 165 */
166 enum { 166 enum {
167 IH_ARCH_INVALID = 0, /* Invalid CPU */ 167 IH_ARCH_INVALID = 0, /* Invalid CPU */
168 IH_ARCH_ALPHA, /* Alpha */ 168 IH_ARCH_ALPHA, /* Alpha */
169 IH_ARCH_ARM, /* ARM */ 169 IH_ARCH_ARM, /* ARM */
170 IH_ARCH_I386, /* Intel x86 */ 170 IH_ARCH_I386, /* Intel x86 */
171 IH_ARCH_IA64, /* IA64 */ 171 IH_ARCH_IA64, /* IA64 */
172 IH_ARCH_MIPS, /* MIPS */ 172 IH_ARCH_MIPS, /* MIPS */
173 IH_ARCH_MIPS64, /* MIPS 64 Bit */ 173 IH_ARCH_MIPS64, /* MIPS 64 Bit */
174 IH_ARCH_PPC, /* PowerPC */ 174 IH_ARCH_PPC, /* PowerPC */
175 IH_ARCH_S390, /* IBM S390 */ 175 IH_ARCH_S390, /* IBM S390 */
176 IH_ARCH_SH, /* SuperH */ 176 IH_ARCH_SH, /* SuperH */
177 IH_ARCH_SPARC, /* Sparc */ 177 IH_ARCH_SPARC, /* Sparc */
178 IH_ARCH_SPARC64, /* Sparc 64 Bit */ 178 IH_ARCH_SPARC64, /* Sparc 64 Bit */
179 IH_ARCH_M68K, /* M68K */ 179 IH_ARCH_M68K, /* M68K */
180 IH_ARCH_NIOS, /* Nios-32 */ 180 IH_ARCH_NIOS, /* Nios-32 */
181 IH_ARCH_MICROBLAZE, /* MicroBlaze */ 181 IH_ARCH_MICROBLAZE, /* MicroBlaze */
182 IH_ARCH_NIOS2, /* Nios-II */ 182 IH_ARCH_NIOS2, /* Nios-II */
183 IH_ARCH_BLACKFIN, /* Blackfin */ 183 IH_ARCH_BLACKFIN, /* Blackfin */
184 IH_ARCH_AVR32, /* AVR32 */ 184 IH_ARCH_AVR32, /* AVR32 */
185 IH_ARCH_ST200, /* STMicroelectronics ST200 */ 185 IH_ARCH_ST200, /* STMicroelectronics ST200 */
186 IH_ARCH_SANDBOX, /* Sandbox architecture (test only) */ 186 IH_ARCH_SANDBOX, /* Sandbox architecture (test only) */
187 IH_ARCH_NDS32, /* ANDES Technology - NDS32 */ 187 IH_ARCH_NDS32, /* ANDES Technology - NDS32 */
188 IH_ARCH_OPENRISC, /* OpenRISC 1000 */ 188 IH_ARCH_OPENRISC, /* OpenRISC 1000 */
189 IH_ARCH_ARM64, /* ARM64 */ 189 IH_ARCH_ARM64, /* ARM64 */
190 IH_ARCH_ARC, /* Synopsys DesignWare ARC */ 190 IH_ARCH_ARC, /* Synopsys DesignWare ARC */
191 IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */ 191 IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */
192 IH_ARCH_XTENSA, /* Xtensa */ 192 IH_ARCH_XTENSA, /* Xtensa */
193 IH_ARCH_RISCV, /* RISC-V */
193 194
194 IH_ARCH_COUNT, 195 IH_ARCH_COUNT,
195 }; 196 };
196 197
197 /* 198 /*
198 * Image Types 199 * Image Types
199 * 200 *
200 * "Standalone Programs" are directly runnable in the environment 201 * "Standalone Programs" are directly runnable in the environment
201 * provided by U-Boot; it is expected that (if they behave 202 * provided by U-Boot; it is expected that (if they behave
202 * well) you can continue to work in U-Boot after return from 203 * well) you can continue to work in U-Boot after return from
203 * the Standalone Program. 204 * the Standalone Program.
204 * "OS Kernel Images" are usually images of some Embedded OS which 205 * "OS Kernel Images" are usually images of some Embedded OS which
205 * will take over control completely. Usually these programs 206 * will take over control completely. Usually these programs
206 * will install their own set of exception handlers, device 207 * will install their own set of exception handlers, device
207 * drivers, set up the MMU, etc. - this means, that you cannot 208 * drivers, set up the MMU, etc. - this means, that you cannot
208 * expect to re-enter U-Boot except by resetting the CPU. 209 * expect to re-enter U-Boot except by resetting the CPU.
209 * "RAMDisk Images" are more or less just data blocks, and their 210 * "RAMDisk Images" are more or less just data blocks, and their
210 * parameters (address, size) are passed to an OS kernel that is 211 * parameters (address, size) are passed to an OS kernel that is
211 * being started. 212 * being started.
212 * "Multi-File Images" contain several images, typically an OS 213 * "Multi-File Images" contain several images, typically an OS
213 * (Linux) kernel image and one or more data images like 214 * (Linux) kernel image and one or more data images like
214 * RAMDisks. This construct is useful for instance when you want 215 * RAMDisks. This construct is useful for instance when you want
215 * to boot over the network using BOOTP etc., where the boot 216 * to boot over the network using BOOTP etc., where the boot
216 * server provides just a single image file, but you want to get 217 * server provides just a single image file, but you want to get
217 * for instance an OS kernel and a RAMDisk image. 218 * for instance an OS kernel and a RAMDisk image.
218 * 219 *
219 * "Multi-File Images" start with a list of image sizes, each 220 * "Multi-File Images" start with a list of image sizes, each
220 * image size (in bytes) specified by an "uint32_t" in network 221 * image size (in bytes) specified by an "uint32_t" in network
221 * byte order. This list is terminated by an "(uint32_t)0". 222 * byte order. This list is terminated by an "(uint32_t)0".
222 * Immediately after the terminating 0 follow the images, one by 223 * Immediately after the terminating 0 follow the images, one by
223 * one, all aligned on "uint32_t" boundaries (size rounded up to 224 * one, all aligned on "uint32_t" boundaries (size rounded up to
224 * a multiple of 4 bytes - except for the last file). 225 * a multiple of 4 bytes - except for the last file).
225 * 226 *
226 * "Firmware Images" are binary images containing firmware (like 227 * "Firmware Images" are binary images containing firmware (like
227 * U-Boot or FPGA images) which usually will be programmed to 228 * U-Boot or FPGA images) which usually will be programmed to
228 * flash memory. 229 * flash memory.
229 * 230 *
230 * "Script files" are command sequences that will be executed by 231 * "Script files" are command sequences that will be executed by
231 * U-Boot's command interpreter; this feature is especially 232 * U-Boot's command interpreter; this feature is especially
232 * useful when you configure U-Boot to use a real shell (hush) 233 * useful when you configure U-Boot to use a real shell (hush)
233 * as command interpreter (=> Shell Scripts). 234 * as command interpreter (=> Shell Scripts).
234 * 235 *
235 * The following are exposed to uImage header. 236 * The following are exposed to uImage header.
236 * Do not change values for backward compatibility. 237 * Do not change values for backward compatibility.
237 */ 238 */
238 239
239 enum { 240 enum {
240 IH_TYPE_INVALID = 0, /* Invalid Image */ 241 IH_TYPE_INVALID = 0, /* Invalid Image */
241 IH_TYPE_STANDALONE, /* Standalone Program */ 242 IH_TYPE_STANDALONE, /* Standalone Program */
242 IH_TYPE_KERNEL, /* OS Kernel Image */ 243 IH_TYPE_KERNEL, /* OS Kernel Image */
243 IH_TYPE_RAMDISK, /* RAMDisk Image */ 244 IH_TYPE_RAMDISK, /* RAMDisk Image */
244 IH_TYPE_MULTI, /* Multi-File Image */ 245 IH_TYPE_MULTI, /* Multi-File Image */
245 IH_TYPE_FIRMWARE, /* Firmware Image */ 246 IH_TYPE_FIRMWARE, /* Firmware Image */
246 IH_TYPE_SCRIPT, /* Script file */ 247 IH_TYPE_SCRIPT, /* Script file */
247 IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */ 248 IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */
248 IH_TYPE_FLATDT, /* Binary Flat Device Tree Blob */ 249 IH_TYPE_FLATDT, /* Binary Flat Device Tree Blob */
249 IH_TYPE_KWBIMAGE, /* Kirkwood Boot Image */ 250 IH_TYPE_KWBIMAGE, /* Kirkwood Boot Image */
250 IH_TYPE_IMXIMAGE, /* Freescale IMXBoot Image */ 251 IH_TYPE_IMXIMAGE, /* Freescale IMXBoot Image */
251 IH_TYPE_UBLIMAGE, /* Davinci UBL Image */ 252 IH_TYPE_UBLIMAGE, /* Davinci UBL Image */
252 IH_TYPE_OMAPIMAGE, /* TI OMAP Config Header Image */ 253 IH_TYPE_OMAPIMAGE, /* TI OMAP Config Header Image */
253 IH_TYPE_AISIMAGE, /* TI Davinci AIS Image */ 254 IH_TYPE_AISIMAGE, /* TI Davinci AIS Image */
254 /* OS Kernel Image, can run from any load address */ 255 /* OS Kernel Image, can run from any load address */
255 IH_TYPE_KERNEL_NOLOAD, 256 IH_TYPE_KERNEL_NOLOAD,
256 IH_TYPE_PBLIMAGE, /* Freescale PBL Boot Image */ 257 IH_TYPE_PBLIMAGE, /* Freescale PBL Boot Image */
257 IH_TYPE_MXSIMAGE, /* Freescale MXSBoot Image */ 258 IH_TYPE_MXSIMAGE, /* Freescale MXSBoot Image */
258 IH_TYPE_GPIMAGE, /* TI Keystone GPHeader Image */ 259 IH_TYPE_GPIMAGE, /* TI Keystone GPHeader Image */
259 IH_TYPE_ATMELIMAGE, /* ATMEL ROM bootable Image */ 260 IH_TYPE_ATMELIMAGE, /* ATMEL ROM bootable Image */
260 IH_TYPE_SOCFPGAIMAGE, /* Altera SOCFPGA Preloader */ 261 IH_TYPE_SOCFPGAIMAGE, /* Altera SOCFPGA Preloader */
261 IH_TYPE_X86_SETUP, /* x86 setup.bin Image */ 262 IH_TYPE_X86_SETUP, /* x86 setup.bin Image */
262 IH_TYPE_LPC32XXIMAGE, /* x86 setup.bin Image */ 263 IH_TYPE_LPC32XXIMAGE, /* x86 setup.bin Image */
263 IH_TYPE_LOADABLE, /* A list of typeless images */ 264 IH_TYPE_LOADABLE, /* A list of typeless images */
264 IH_TYPE_RKIMAGE, /* Rockchip Boot Image */ 265 IH_TYPE_RKIMAGE, /* Rockchip Boot Image */
265 IH_TYPE_RKSD, /* Rockchip SD card */ 266 IH_TYPE_RKSD, /* Rockchip SD card */
266 IH_TYPE_RKSPI, /* Rockchip SPI image */ 267 IH_TYPE_RKSPI, /* Rockchip SPI image */
267 IH_TYPE_ZYNQIMAGE, /* Xilinx Zynq Boot Image */ 268 IH_TYPE_ZYNQIMAGE, /* Xilinx Zynq Boot Image */
268 IH_TYPE_ZYNQMPIMAGE, /* Xilinx ZynqMP Boot Image */ 269 IH_TYPE_ZYNQMPIMAGE, /* Xilinx ZynqMP Boot Image */
269 IH_TYPE_FPGA, /* FPGA Image */ 270 IH_TYPE_FPGA, /* FPGA Image */
270 IH_TYPE_VYBRIDIMAGE, /* VYBRID .vyb Image */ 271 IH_TYPE_VYBRIDIMAGE, /* VYBRID .vyb Image */
271 IH_TYPE_TEE, /* Trusted Execution Environment OS Image */ 272 IH_TYPE_TEE, /* Trusted Execution Environment OS Image */
272 IH_TYPE_FIRMWARE_IVT, /* Firmware Image with HABv4 IVT */ 273 IH_TYPE_FIRMWARE_IVT, /* Firmware Image with HABv4 IVT */
273 IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */ 274 IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */
274 275
275 IH_TYPE_COUNT, /* Number of image types */ 276 IH_TYPE_COUNT, /* Number of image types */
276 }; 277 };
277 278
278 /* 279 /*
279 * Compression Types 280 * Compression Types
280 * 281 *
281 * The following are exposed to uImage header. 282 * The following are exposed to uImage header.
282 * Do not change values for backward compatibility. 283 * Do not change values for backward compatibility.
283 */ 284 */
284 enum { 285 enum {
285 IH_COMP_NONE = 0, /* No Compression Used */ 286 IH_COMP_NONE = 0, /* No Compression Used */
286 IH_COMP_GZIP, /* gzip Compression Used */ 287 IH_COMP_GZIP, /* gzip Compression Used */
287 IH_COMP_BZIP2, /* bzip2 Compression Used */ 288 IH_COMP_BZIP2, /* bzip2 Compression Used */
288 IH_COMP_LZMA, /* lzma Compression Used */ 289 IH_COMP_LZMA, /* lzma Compression Used */
289 IH_COMP_LZO, /* lzo Compression Used */ 290 IH_COMP_LZO, /* lzo Compression Used */
290 IH_COMP_LZ4, /* lz4 Compression Used */ 291 IH_COMP_LZ4, /* lz4 Compression Used */
291 292
292 IH_COMP_COUNT, 293 IH_COMP_COUNT,
293 }; 294 };
294 295
295 #define IH_MAGIC 0x27051956 /* Image Magic Number */ 296 #define IH_MAGIC 0x27051956 /* Image Magic Number */
296 #define IH_NMLEN 32 /* Image Name Length */ 297 #define IH_NMLEN 32 /* Image Name Length */
297 298
298 /* Reused from common.h */ 299 /* Reused from common.h */
299 #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) 300 #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
300 301
301 /* 302 /*
302 * Legacy format image header, 303 * Legacy format image header,
303 * all data in network byte order (aka natural aka bigendian). 304 * all data in network byte order (aka natural aka bigendian).
304 */ 305 */
305 typedef struct image_header { 306 typedef struct image_header {
306 __be32 ih_magic; /* Image Header Magic Number */ 307 __be32 ih_magic; /* Image Header Magic Number */
307 __be32 ih_hcrc; /* Image Header CRC Checksum */ 308 __be32 ih_hcrc; /* Image Header CRC Checksum */
308 __be32 ih_time; /* Image Creation Timestamp */ 309 __be32 ih_time; /* Image Creation Timestamp */
309 __be32 ih_size; /* Image Data Size */ 310 __be32 ih_size; /* Image Data Size */
310 __be32 ih_load; /* Data Load Address */ 311 __be32 ih_load; /* Data Load Address */
311 __be32 ih_ep; /* Entry Point Address */ 312 __be32 ih_ep; /* Entry Point Address */
312 __be32 ih_dcrc; /* Image Data CRC Checksum */ 313 __be32 ih_dcrc; /* Image Data CRC Checksum */
313 uint8_t ih_os; /* Operating System */ 314 uint8_t ih_os; /* Operating System */
314 uint8_t ih_arch; /* CPU architecture */ 315 uint8_t ih_arch; /* CPU architecture */
315 uint8_t ih_type; /* Image Type */ 316 uint8_t ih_type; /* Image Type */
316 uint8_t ih_comp; /* Compression Type */ 317 uint8_t ih_comp; /* Compression Type */
317 uint8_t ih_name[IH_NMLEN]; /* Image Name */ 318 uint8_t ih_name[IH_NMLEN]; /* Image Name */
318 } image_header_t; 319 } image_header_t;
319 320
320 typedef struct image_info { 321 typedef struct image_info {
321 ulong start, end; /* start/end of blob */ 322 ulong start, end; /* start/end of blob */
322 ulong image_start, image_len; /* start of image within blob, len of image */ 323 ulong image_start, image_len; /* start of image within blob, len of image */
323 ulong load; /* load addr for the image */ 324 ulong load; /* load addr for the image */
324 uint8_t comp, type, os; /* compression, type of image, os type */ 325 uint8_t comp, type, os; /* compression, type of image, os type */
325 uint8_t arch; /* CPU architecture */ 326 uint8_t arch; /* CPU architecture */
326 } image_info_t; 327 } image_info_t;
327 328
328 /* 329 /*
329 * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>() 330 * Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
330 * routines. 331 * routines.
331 */ 332 */
332 typedef struct bootm_headers { 333 typedef struct bootm_headers {
333 /* 334 /*
334 * Legacy os image header, if it is a multi component image 335 * Legacy os image header, if it is a multi component image
335 * then boot_get_ramdisk() and get_fdt() will attempt to get 336 * then boot_get_ramdisk() and get_fdt() will attempt to get
336 * data from second and third component accordingly. 337 * data from second and third component accordingly.
337 */ 338 */
338 image_header_t *legacy_hdr_os; /* image header pointer */ 339 image_header_t *legacy_hdr_os; /* image header pointer */
339 image_header_t legacy_hdr_os_copy; /* header copy */ 340 image_header_t legacy_hdr_os_copy; /* header copy */
340 ulong legacy_hdr_valid; 341 ulong legacy_hdr_valid;
341 342
342 #if IMAGE_ENABLE_FIT 343 #if IMAGE_ENABLE_FIT
343 const char *fit_uname_cfg; /* configuration node unit name */ 344 const char *fit_uname_cfg; /* configuration node unit name */
344 345
345 void *fit_hdr_os; /* os FIT image header */ 346 void *fit_hdr_os; /* os FIT image header */
346 const char *fit_uname_os; /* os subimage node unit name */ 347 const char *fit_uname_os; /* os subimage node unit name */
347 int fit_noffset_os; /* os subimage node offset */ 348 int fit_noffset_os; /* os subimage node offset */
348 349
349 void *fit_hdr_rd; /* init ramdisk FIT image header */ 350 void *fit_hdr_rd; /* init ramdisk FIT image header */
350 const char *fit_uname_rd; /* init ramdisk subimage node unit name */ 351 const char *fit_uname_rd; /* init ramdisk subimage node unit name */
351 int fit_noffset_rd; /* init ramdisk subimage node offset */ 352 int fit_noffset_rd; /* init ramdisk subimage node offset */
352 353
353 void *fit_hdr_fdt; /* FDT blob FIT image header */ 354 void *fit_hdr_fdt; /* FDT blob FIT image header */
354 const char *fit_uname_fdt; /* FDT blob subimage node unit name */ 355 const char *fit_uname_fdt; /* FDT blob subimage node unit name */
355 int fit_noffset_fdt;/* FDT blob subimage node offset */ 356 int fit_noffset_fdt;/* FDT blob subimage node offset */
356 357
357 void *fit_hdr_setup; /* x86 setup FIT image header */ 358 void *fit_hdr_setup; /* x86 setup FIT image header */
358 const char *fit_uname_setup; /* x86 setup subimage node name */ 359 const char *fit_uname_setup; /* x86 setup subimage node name */
359 int fit_noffset_setup;/* x86 setup subimage node offset */ 360 int fit_noffset_setup;/* x86 setup subimage node offset */
360 #endif 361 #endif
361 362
362 #ifndef USE_HOSTCC 363 #ifndef USE_HOSTCC
363 image_info_t os; /* os image info */ 364 image_info_t os; /* os image info */
364 ulong ep; /* entry point of OS */ 365 ulong ep; /* entry point of OS */
365 366
366 ulong rd_start, rd_end;/* ramdisk start/end */ 367 ulong rd_start, rd_end;/* ramdisk start/end */
367 368
368 char *ft_addr; /* flat dev tree address */ 369 char *ft_addr; /* flat dev tree address */
369 ulong ft_len; /* length of flat device tree */ 370 ulong ft_len; /* length of flat device tree */
370 371
371 ulong initrd_start; 372 ulong initrd_start;
372 ulong initrd_end; 373 ulong initrd_end;
373 ulong cmdline_start; 374 ulong cmdline_start;
374 ulong cmdline_end; 375 ulong cmdline_end;
375 bd_t *kbd; 376 bd_t *kbd;
376 #endif 377 #endif
377 378
378 int verify; /* env_get("verify")[0] != 'n' */ 379 int verify; /* env_get("verify")[0] != 'n' */
379 380
380 #define BOOTM_STATE_START (0x00000001) 381 #define BOOTM_STATE_START (0x00000001)
381 #define BOOTM_STATE_FINDOS (0x00000002) 382 #define BOOTM_STATE_FINDOS (0x00000002)
382 #define BOOTM_STATE_FINDOTHER (0x00000004) 383 #define BOOTM_STATE_FINDOTHER (0x00000004)
383 #define BOOTM_STATE_LOADOS (0x00000008) 384 #define BOOTM_STATE_LOADOS (0x00000008)
384 #define BOOTM_STATE_RAMDISK (0x00000010) 385 #define BOOTM_STATE_RAMDISK (0x00000010)
385 #define BOOTM_STATE_FDT (0x00000020) 386 #define BOOTM_STATE_FDT (0x00000020)
386 #define BOOTM_STATE_OS_CMDLINE (0x00000040) 387 #define BOOTM_STATE_OS_CMDLINE (0x00000040)
387 #define BOOTM_STATE_OS_BD_T (0x00000080) 388 #define BOOTM_STATE_OS_BD_T (0x00000080)
388 #define BOOTM_STATE_OS_PREP (0x00000100) 389 #define BOOTM_STATE_OS_PREP (0x00000100)
389 #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */ 390 #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
390 #define BOOTM_STATE_OS_GO (0x00000400) 391 #define BOOTM_STATE_OS_GO (0x00000400)
391 int state; 392 int state;
392 393
393 #ifdef CONFIG_LMB 394 #ifdef CONFIG_LMB
394 struct lmb lmb; /* for memory mgmt */ 395 struct lmb lmb; /* for memory mgmt */
395 #endif 396 #endif
396 } bootm_headers_t; 397 } bootm_headers_t;
397 398
398 extern bootm_headers_t images; 399 extern bootm_headers_t images;
399 400
400 /* 401 /*
401 * Some systems (for example LWMON) have very short watchdog periods; 402 * Some systems (for example LWMON) have very short watchdog periods;
402 * we must make sure to split long operations like memmove() or 403 * we must make sure to split long operations like memmove() or
403 * checksum calculations into reasonable chunks. 404 * checksum calculations into reasonable chunks.
404 */ 405 */
405 #ifndef CHUNKSZ 406 #ifndef CHUNKSZ
406 #define CHUNKSZ (64 * 1024) 407 #define CHUNKSZ (64 * 1024)
407 #endif 408 #endif
408 409
409 #ifndef CHUNKSZ_CRC32 410 #ifndef CHUNKSZ_CRC32
410 #define CHUNKSZ_CRC32 (64 * 1024) 411 #define CHUNKSZ_CRC32 (64 * 1024)
411 #endif 412 #endif
412 413
413 #ifndef CHUNKSZ_MD5 414 #ifndef CHUNKSZ_MD5
414 #define CHUNKSZ_MD5 (64 * 1024) 415 #define CHUNKSZ_MD5 (64 * 1024)
415 #endif 416 #endif
416 417
417 #ifndef CHUNKSZ_SHA1 418 #ifndef CHUNKSZ_SHA1
418 #define CHUNKSZ_SHA1 (64 * 1024) 419 #define CHUNKSZ_SHA1 (64 * 1024)
419 #endif 420 #endif
420 421
421 #define uimage_to_cpu(x) be32_to_cpu(x) 422 #define uimage_to_cpu(x) be32_to_cpu(x)
422 #define cpu_to_uimage(x) cpu_to_be32(x) 423 #define cpu_to_uimage(x) cpu_to_be32(x)
423 424
424 /* 425 /*
425 * Translation table for entries of a specific type; used by 426 * Translation table for entries of a specific type; used by
426 * get_table_entry_id() and get_table_entry_name(). 427 * get_table_entry_id() and get_table_entry_name().
427 */ 428 */
428 typedef struct table_entry { 429 typedef struct table_entry {
429 int id; 430 int id;
430 char *sname; /* short (input) name to find table entry */ 431 char *sname; /* short (input) name to find table entry */
431 char *lname; /* long (output) name to print for messages */ 432 char *lname; /* long (output) name to print for messages */
432 } table_entry_t; 433 } table_entry_t;
433 434
434 /* 435 /*
435 * get_table_entry_id() scans the translation table trying to find an 436 * get_table_entry_id() scans the translation table trying to find an
436 * entry that matches the given short name. If a matching entry is 437 * entry that matches the given short name. If a matching entry is
437 * found, it's id is returned to the caller. 438 * found, it's id is returned to the caller.
438 */ 439 */
439 int get_table_entry_id(const table_entry_t *table, 440 int get_table_entry_id(const table_entry_t *table,
440 const char *table_name, const char *name); 441 const char *table_name, const char *name);
441 /* 442 /*
442 * get_table_entry_name() scans the translation table trying to find 443 * get_table_entry_name() scans the translation table trying to find
443 * an entry that matches the given id. If a matching entry is found, 444 * an entry that matches the given id. If a matching entry is found,
444 * its long name is returned to the caller. 445 * its long name is returned to the caller.
445 */ 446 */
446 char *get_table_entry_name(const table_entry_t *table, char *msg, int id); 447 char *get_table_entry_name(const table_entry_t *table, char *msg, int id);
447 448
448 const char *genimg_get_os_name(uint8_t os); 449 const char *genimg_get_os_name(uint8_t os);
449 450
450 /** 451 /**
451 * genimg_get_os_short_name() - get the short name for an OS 452 * genimg_get_os_short_name() - get the short name for an OS
452 * 453 *
453 * @param os OS (IH_OS_...) 454 * @param os OS (IH_OS_...)
454 * @return OS short name, or "unknown" if unknown 455 * @return OS short name, or "unknown" if unknown
455 */ 456 */
456 const char *genimg_get_os_short_name(uint8_t comp); 457 const char *genimg_get_os_short_name(uint8_t comp);
457 458
458 const char *genimg_get_arch_name(uint8_t arch); 459 const char *genimg_get_arch_name(uint8_t arch);
459 460
460 /** 461 /**
461 * genimg_get_arch_short_name() - get the short name for an architecture 462 * genimg_get_arch_short_name() - get the short name for an architecture
462 * 463 *
463 * @param arch Architecture type (IH_ARCH_...) 464 * @param arch Architecture type (IH_ARCH_...)
464 * @return architecture short name, or "unknown" if unknown 465 * @return architecture short name, or "unknown" if unknown
465 */ 466 */
466 const char *genimg_get_arch_short_name(uint8_t arch); 467 const char *genimg_get_arch_short_name(uint8_t arch);
467 468
468 const char *genimg_get_type_name(uint8_t type); 469 const char *genimg_get_type_name(uint8_t type);
469 470
470 /** 471 /**
471 * genimg_get_type_short_name() - get the short name for an image type 472 * genimg_get_type_short_name() - get the short name for an image type
472 * 473 *
473 * @param type Image type (IH_TYPE_...) 474 * @param type Image type (IH_TYPE_...)
474 * @return image short name, or "unknown" if unknown 475 * @return image short name, or "unknown" if unknown
475 */ 476 */
476 const char *genimg_get_type_short_name(uint8_t type); 477 const char *genimg_get_type_short_name(uint8_t type);
477 478
478 const char *genimg_get_comp_name(uint8_t comp); 479 const char *genimg_get_comp_name(uint8_t comp);
479 480
480 /** 481 /**
481 * genimg_get_comp_short_name() - get the short name for a compression method 482 * genimg_get_comp_short_name() - get the short name for a compression method
482 * 483 *
483 * @param comp compression method (IH_COMP_...) 484 * @param comp compression method (IH_COMP_...)
484 * @return compression method short name, or "unknown" if unknown 485 * @return compression method short name, or "unknown" if unknown
485 */ 486 */
486 const char *genimg_get_comp_short_name(uint8_t comp); 487 const char *genimg_get_comp_short_name(uint8_t comp);
487 488
488 /** 489 /**
489 * genimg_get_cat_name() - Get the name of an item in a category 490 * genimg_get_cat_name() - Get the name of an item in a category
490 * 491 *
491 * @category: Category of item 492 * @category: Category of item
492 * @id: Item ID 493 * @id: Item ID
493 * @return name of item, or "Unknown ..." if unknown 494 * @return name of item, or "Unknown ..." if unknown
494 */ 495 */
495 const char *genimg_get_cat_name(enum ih_category category, uint id); 496 const char *genimg_get_cat_name(enum ih_category category, uint id);
496 497
497 /** 498 /**
498 * genimg_get_cat_short_name() - Get the short name of an item in a category 499 * genimg_get_cat_short_name() - Get the short name of an item in a category
499 * 500 *
500 * @category: Category of item 501 * @category: Category of item
501 * @id: Item ID 502 * @id: Item ID
502 * @return short name of item, or "Unknown ..." if unknown 503 * @return short name of item, or "Unknown ..." if unknown
503 */ 504 */
504 const char *genimg_get_cat_short_name(enum ih_category category, uint id); 505 const char *genimg_get_cat_short_name(enum ih_category category, uint id);
505 506
506 /** 507 /**
507 * genimg_get_cat_count() - Get the number of items in a category 508 * genimg_get_cat_count() - Get the number of items in a category
508 * 509 *
509 * @category: Category to check 510 * @category: Category to check
510 * @return the number of items in the category (IH_xxx_COUNT) 511 * @return the number of items in the category (IH_xxx_COUNT)
511 */ 512 */
512 int genimg_get_cat_count(enum ih_category category); 513 int genimg_get_cat_count(enum ih_category category);
513 514
514 /** 515 /**
515 * genimg_get_cat_desc() - Get the description of a category 516 * genimg_get_cat_desc() - Get the description of a category
516 * 517 *
517 * @return the description of a category, e.g. "architecture". This 518 * @return the description of a category, e.g. "architecture". This
518 * effectively converts the enum to a string. 519 * effectively converts the enum to a string.
519 */ 520 */
520 const char *genimg_get_cat_desc(enum ih_category category); 521 const char *genimg_get_cat_desc(enum ih_category category);
521 522
522 int genimg_get_os_id(const char *name); 523 int genimg_get_os_id(const char *name);
523 int genimg_get_arch_id(const char *name); 524 int genimg_get_arch_id(const char *name);
524 int genimg_get_type_id(const char *name); 525 int genimg_get_type_id(const char *name);
525 int genimg_get_comp_id(const char *name); 526 int genimg_get_comp_id(const char *name);
526 void genimg_print_size(uint32_t size); 527 void genimg_print_size(uint32_t size);
527 528
528 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \ 529 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \
529 defined(USE_HOSTCC) 530 defined(USE_HOSTCC)
530 #define IMAGE_ENABLE_TIMESTAMP 1 531 #define IMAGE_ENABLE_TIMESTAMP 1
531 #else 532 #else
532 #define IMAGE_ENABLE_TIMESTAMP 0 533 #define IMAGE_ENABLE_TIMESTAMP 0
533 #endif 534 #endif
534 void genimg_print_time(time_t timestamp); 535 void genimg_print_time(time_t timestamp);
535 536
536 /* What to do with a image load address ('load = <> 'in the FIT) */ 537 /* What to do with a image load address ('load = <> 'in the FIT) */
537 enum fit_load_op { 538 enum fit_load_op {
538 FIT_LOAD_IGNORED, /* Ignore load address */ 539 FIT_LOAD_IGNORED, /* Ignore load address */
539 FIT_LOAD_OPTIONAL, /* Can be provided, but optional */ 540 FIT_LOAD_OPTIONAL, /* Can be provided, but optional */
540 FIT_LOAD_OPTIONAL_NON_ZERO, /* Optional, a value of 0 is ignored */ 541 FIT_LOAD_OPTIONAL_NON_ZERO, /* Optional, a value of 0 is ignored */
541 FIT_LOAD_REQUIRED, /* Must be provided */ 542 FIT_LOAD_REQUIRED, /* Must be provided */
542 }; 543 };
543 544
544 int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start, 545 int boot_get_setup(bootm_headers_t *images, uint8_t arch, ulong *setup_start,
545 ulong *setup_len); 546 ulong *setup_len);
546 547
547 #ifndef USE_HOSTCC 548 #ifndef USE_HOSTCC
548 /* Image format types, returned by _get_format() routine */ 549 /* Image format types, returned by _get_format() routine */
549 #define IMAGE_FORMAT_INVALID 0x00 550 #define IMAGE_FORMAT_INVALID 0x00
550 #if defined(CONFIG_IMAGE_FORMAT_LEGACY) 551 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
551 #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */ 552 #define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */
552 #endif 553 #endif
553 #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */ 554 #define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */
554 #define IMAGE_FORMAT_ANDROID 0x03 /* Android boot image */ 555 #define IMAGE_FORMAT_ANDROID 0x03 /* Android boot image */
555 556
556 ulong genimg_get_kernel_addr_fit(char * const img_addr, 557 ulong genimg_get_kernel_addr_fit(char * const img_addr,
557 const char **fit_uname_config, 558 const char **fit_uname_config,
558 const char **fit_uname_kernel); 559 const char **fit_uname_kernel);
559 ulong genimg_get_kernel_addr(char * const img_addr); 560 ulong genimg_get_kernel_addr(char * const img_addr);
560 int genimg_get_format(const void *img_addr); 561 int genimg_get_format(const void *img_addr);
561 int genimg_has_config(bootm_headers_t *images); 562 int genimg_has_config(bootm_headers_t *images);
562 563
563 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, 564 int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
564 uint8_t arch, const ulong *ld_start, ulong * const ld_len); 565 uint8_t arch, const ulong *ld_start, ulong * const ld_len);
565 int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images, 566 int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
566 uint8_t arch, ulong *rd_start, ulong *rd_end); 567 uint8_t arch, ulong *rd_start, ulong *rd_end);
567 568
568 /** 569 /**
569 * boot_get_loadable - routine to load a list of binaries to memory 570 * boot_get_loadable - routine to load a list of binaries to memory
570 * @argc: Ignored Argument 571 * @argc: Ignored Argument
571 * @argv: Ignored Argument 572 * @argv: Ignored Argument
572 * @images: pointer to the bootm images structure 573 * @images: pointer to the bootm images structure
573 * @arch: expected architecture for the image 574 * @arch: expected architecture for the image
574 * @ld_start: Ignored Argument 575 * @ld_start: Ignored Argument
575 * @ld_len: Ignored Argument 576 * @ld_len: Ignored Argument
576 * 577 *
577 * boot_get_loadable() will take the given FIT configuration, and look 578 * boot_get_loadable() will take the given FIT configuration, and look
578 * for a field named "loadables". Loadables, is a list of elements in 579 * for a field named "loadables". Loadables, is a list of elements in
579 * the FIT given as strings. exe: 580 * the FIT given as strings. exe:
580 * loadables = "linux_kernel@1", "fdt@2"; 581 * loadables = "linux_kernel@1", "fdt@2";
581 * this function will attempt to parse each string, and load the 582 * this function will attempt to parse each string, and load the
582 * corresponding element from the FIT into memory. Once placed, 583 * corresponding element from the FIT into memory. Once placed,
583 * no aditional actions are taken. 584 * no aditional actions are taken.
584 * 585 *
585 * @return: 586 * @return:
586 * 0, if only valid images or no images are found 587 * 0, if only valid images or no images are found
587 * error code, if an error occurs during fit_image_load 588 * error code, if an error occurs during fit_image_load
588 */ 589 */
589 int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images, 590 int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
590 uint8_t arch, const ulong *ld_start, ulong * const ld_len); 591 uint8_t arch, const ulong *ld_start, ulong * const ld_len);
591 #endif /* !USE_HOSTCC */ 592 #endif /* !USE_HOSTCC */
592 593
593 int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch, 594 int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch,
594 ulong *setup_start, ulong *setup_len); 595 ulong *setup_start, ulong *setup_len);
595 596
596 /** 597 /**
597 * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays) 598 * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays)
598 * 599 *
599 * This deals with all aspects of loading an DTB from a FIT. 600 * This deals with all aspects of loading an DTB from a FIT.
600 * The correct base image based on configuration will be selected, and 601 * The correct base image based on configuration will be selected, and
601 * then any overlays specified will be applied (as present in fit_uname_configp). 602 * then any overlays specified will be applied (as present in fit_uname_configp).
602 * 603 *
603 * @param images Boot images structure 604 * @param images Boot images structure
604 * @param addr Address of FIT in memory 605 * @param addr Address of FIT in memory
605 * @param fit_unamep On entry this is the requested image name 606 * @param fit_unamep On entry this is the requested image name
606 * (e.g. "kernel@1") or NULL to use the default. On exit 607 * (e.g. "kernel@1") or NULL to use the default. On exit
607 * points to the selected image name 608 * points to the selected image name
608 * @param fit_uname_configp On entry this is the requested configuration 609 * @param fit_uname_configp On entry this is the requested configuration
609 * name (e.g. "conf@1") or NULL to use the default. On 610 * name (e.g. "conf@1") or NULL to use the default. On
610 * exit points to the selected configuration name. 611 * exit points to the selected configuration name.
611 * @param arch Expected architecture (IH_ARCH_...) 612 * @param arch Expected architecture (IH_ARCH_...)
612 * @param datap Returns address of loaded image 613 * @param datap Returns address of loaded image
613 * @param lenp Returns length of loaded image 614 * @param lenp Returns length of loaded image
614 * 615 *
615 * @return node offset of base image, or -ve error code on error 616 * @return node offset of base image, or -ve error code on error
616 */ 617 */
617 int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, 618 int boot_get_fdt_fit(bootm_headers_t *images, ulong addr,
618 const char **fit_unamep, const char **fit_uname_configp, 619 const char **fit_unamep, const char **fit_uname_configp,
619 int arch, ulong *datap, ulong *lenp); 620 int arch, ulong *datap, ulong *lenp);
620 621
621 /** 622 /**
622 * fit_image_load() - load an image from a FIT 623 * fit_image_load() - load an image from a FIT
623 * 624 *
624 * This deals with all aspects of loading an image from a FIT, including 625 * This deals with all aspects of loading an image from a FIT, including
625 * selecting the right image based on configuration, verifying it, printing 626 * selecting the right image based on configuration, verifying it, printing
626 * out progress messages, checking the type/arch/os and optionally copying it 627 * out progress messages, checking the type/arch/os and optionally copying it
627 * to the right load address. 628 * to the right load address.
628 * 629 *
629 * The property to look up is defined by image_type. 630 * The property to look up is defined by image_type.
630 * 631 *
631 * @param images Boot images structure 632 * @param images Boot images structure
632 * @param addr Address of FIT in memory 633 * @param addr Address of FIT in memory
633 * @param fit_unamep On entry this is the requested image name 634 * @param fit_unamep On entry this is the requested image name
634 * (e.g. "kernel@1") or NULL to use the default. On exit 635 * (e.g. "kernel@1") or NULL to use the default. On exit
635 * points to the selected image name 636 * points to the selected image name
636 * @param fit_uname_configp On entry this is the requested configuration 637 * @param fit_uname_configp On entry this is the requested configuration
637 * name (e.g. "conf@1") or NULL to use the default. On 638 * name (e.g. "conf@1") or NULL to use the default. On
638 * exit points to the selected configuration name. 639 * exit points to the selected configuration name.
639 * @param arch Expected architecture (IH_ARCH_...) 640 * @param arch Expected architecture (IH_ARCH_...)
640 * @param image_type Required image type (IH_TYPE_...). If this is 641 * @param image_type Required image type (IH_TYPE_...). If this is
641 * IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD 642 * IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
642 * also. 643 * also.
643 * @param bootstage_id ID of starting bootstage to use for progress updates. 644 * @param bootstage_id ID of starting bootstage to use for progress updates.
644 * This will be added to the BOOTSTAGE_SUB values when 645 * This will be added to the BOOTSTAGE_SUB values when
645 * calling bootstage_mark() 646 * calling bootstage_mark()
646 * @param load_op Decribes what to do with the load address 647 * @param load_op Decribes what to do with the load address
647 * @param datap Returns address of loaded image 648 * @param datap Returns address of loaded image
648 * @param lenp Returns length of loaded image 649 * @param lenp Returns length of loaded image
649 * @return node offset of image, or -ve error code on error 650 * @return node offset of image, or -ve error code on error
650 */ 651 */
651 int fit_image_load(bootm_headers_t *images, ulong addr, 652 int fit_image_load(bootm_headers_t *images, ulong addr,
652 const char **fit_unamep, const char **fit_uname_configp, 653 const char **fit_unamep, const char **fit_uname_configp,
653 int arch, int image_type, int bootstage_id, 654 int arch, int image_type, int bootstage_id,
654 enum fit_load_op load_op, ulong *datap, ulong *lenp); 655 enum fit_load_op load_op, ulong *datap, ulong *lenp);
655 656
656 #ifndef USE_HOSTCC 657 #ifndef USE_HOSTCC
657 /** 658 /**
658 * fit_get_node_from_config() - Look up an image a FIT by type 659 * fit_get_node_from_config() - Look up an image a FIT by type
659 * 660 *
660 * This looks in the selected conf@ node (images->fit_uname_cfg) for a 661 * This looks in the selected conf@ node (images->fit_uname_cfg) for a
661 * particular image type (e.g. "kernel") and then finds the image that is 662 * particular image type (e.g. "kernel") and then finds the image that is
662 * referred to. 663 * referred to.
663 * 664 *
664 * For example, for something like: 665 * For example, for something like:
665 * 666 *
666 * images { 667 * images {
667 * kernel@1 { 668 * kernel@1 {
668 * ... 669 * ...
669 * }; 670 * };
670 * }; 671 * };
671 * configurations { 672 * configurations {
672 * conf@1 { 673 * conf@1 {
673 * kernel = "kernel@1"; 674 * kernel = "kernel@1";
674 * }; 675 * };
675 * }; 676 * };
676 * 677 *
677 * the function will return the node offset of the kernel@1 node, assuming 678 * the function will return the node offset of the kernel@1 node, assuming
678 * that conf@1 is the chosen configuration. 679 * that conf@1 is the chosen configuration.
679 * 680 *
680 * @param images Boot images structure 681 * @param images Boot images structure
681 * @param prop_name Property name to look up (FIT_..._PROP) 682 * @param prop_name Property name to look up (FIT_..._PROP)
682 * @param addr Address of FIT in memory 683 * @param addr Address of FIT in memory
683 */ 684 */
684 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name, 685 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
685 ulong addr); 686 ulong addr);
686 687
687 int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch, 688 int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
688 bootm_headers_t *images, 689 bootm_headers_t *images,
689 char **of_flat_tree, ulong *of_size); 690 char **of_flat_tree, ulong *of_size);
690 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob); 691 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob);
691 int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size); 692 int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size);
692 693
693 int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len, 694 int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
694 ulong *initrd_start, ulong *initrd_end); 695 ulong *initrd_start, ulong *initrd_end);
695 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end); 696 int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end);
696 #ifdef CONFIG_SYS_BOOT_GET_KBD 697 #ifdef CONFIG_SYS_BOOT_GET_KBD
697 int boot_get_kbd(struct lmb *lmb, bd_t **kbd); 698 int boot_get_kbd(struct lmb *lmb, bd_t **kbd);
698 #endif /* CONFIG_SYS_BOOT_GET_KBD */ 699 #endif /* CONFIG_SYS_BOOT_GET_KBD */
699 #endif /* !USE_HOSTCC */ 700 #endif /* !USE_HOSTCC */
700 701
701 /*******************************************************************/ 702 /*******************************************************************/
702 /* Legacy format specific code (prefixed with image_) */ 703 /* Legacy format specific code (prefixed with image_) */
703 /*******************************************************************/ 704 /*******************************************************************/
704 static inline uint32_t image_get_header_size(void) 705 static inline uint32_t image_get_header_size(void)
705 { 706 {
706 return (sizeof(image_header_t)); 707 return (sizeof(image_header_t));
707 } 708 }
708 709
709 #define image_get_hdr_l(f) \ 710 #define image_get_hdr_l(f) \
710 static inline uint32_t image_get_##f(const image_header_t *hdr) \ 711 static inline uint32_t image_get_##f(const image_header_t *hdr) \
711 { \ 712 { \
712 return uimage_to_cpu(hdr->ih_##f); \ 713 return uimage_to_cpu(hdr->ih_##f); \
713 } 714 }
714 image_get_hdr_l(magic) /* image_get_magic */ 715 image_get_hdr_l(magic) /* image_get_magic */
715 image_get_hdr_l(hcrc) /* image_get_hcrc */ 716 image_get_hdr_l(hcrc) /* image_get_hcrc */
716 image_get_hdr_l(time) /* image_get_time */ 717 image_get_hdr_l(time) /* image_get_time */
717 image_get_hdr_l(size) /* image_get_size */ 718 image_get_hdr_l(size) /* image_get_size */
718 image_get_hdr_l(load) /* image_get_load */ 719 image_get_hdr_l(load) /* image_get_load */
719 image_get_hdr_l(ep) /* image_get_ep */ 720 image_get_hdr_l(ep) /* image_get_ep */
720 image_get_hdr_l(dcrc) /* image_get_dcrc */ 721 image_get_hdr_l(dcrc) /* image_get_dcrc */
721 722
722 #define image_get_hdr_b(f) \ 723 #define image_get_hdr_b(f) \
723 static inline uint8_t image_get_##f(const image_header_t *hdr) \ 724 static inline uint8_t image_get_##f(const image_header_t *hdr) \
724 { \ 725 { \
725 return hdr->ih_##f; \ 726 return hdr->ih_##f; \
726 } 727 }
727 image_get_hdr_b(os) /* image_get_os */ 728 image_get_hdr_b(os) /* image_get_os */
728 image_get_hdr_b(arch) /* image_get_arch */ 729 image_get_hdr_b(arch) /* image_get_arch */
729 image_get_hdr_b(type) /* image_get_type */ 730 image_get_hdr_b(type) /* image_get_type */
730 image_get_hdr_b(comp) /* image_get_comp */ 731 image_get_hdr_b(comp) /* image_get_comp */
731 732
732 static inline char *image_get_name(const image_header_t *hdr) 733 static inline char *image_get_name(const image_header_t *hdr)
733 { 734 {
734 return (char *)hdr->ih_name; 735 return (char *)hdr->ih_name;
735 } 736 }
736 737
737 static inline uint32_t image_get_data_size(const image_header_t *hdr) 738 static inline uint32_t image_get_data_size(const image_header_t *hdr)
738 { 739 {
739 return image_get_size(hdr); 740 return image_get_size(hdr);
740 } 741 }
741 742
742 /** 743 /**
743 * image_get_data - get image payload start address 744 * image_get_data - get image payload start address
744 * @hdr: image header 745 * @hdr: image header
745 * 746 *
746 * image_get_data() returns address of the image payload. For single 747 * image_get_data() returns address of the image payload. For single
747 * component images it is image data start. For multi component 748 * component images it is image data start. For multi component
748 * images it points to the null terminated table of sub-images sizes. 749 * images it points to the null terminated table of sub-images sizes.
749 * 750 *
750 * returns: 751 * returns:
751 * image payload data start address 752 * image payload data start address
752 */ 753 */
753 static inline ulong image_get_data(const image_header_t *hdr) 754 static inline ulong image_get_data(const image_header_t *hdr)
754 { 755 {
755 return ((ulong)hdr + image_get_header_size()); 756 return ((ulong)hdr + image_get_header_size());
756 } 757 }
757 758
758 static inline uint32_t image_get_image_size(const image_header_t *hdr) 759 static inline uint32_t image_get_image_size(const image_header_t *hdr)
759 { 760 {
760 return (image_get_size(hdr) + image_get_header_size()); 761 return (image_get_size(hdr) + image_get_header_size());
761 } 762 }
762 static inline ulong image_get_image_end(const image_header_t *hdr) 763 static inline ulong image_get_image_end(const image_header_t *hdr)
763 { 764 {
764 return ((ulong)hdr + image_get_image_size(hdr)); 765 return ((ulong)hdr + image_get_image_size(hdr));
765 } 766 }
766 767
767 #define image_set_hdr_l(f) \ 768 #define image_set_hdr_l(f) \
768 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \ 769 static inline void image_set_##f(image_header_t *hdr, uint32_t val) \
769 { \ 770 { \
770 hdr->ih_##f = cpu_to_uimage(val); \ 771 hdr->ih_##f = cpu_to_uimage(val); \
771 } 772 }
772 image_set_hdr_l(magic) /* image_set_magic */ 773 image_set_hdr_l(magic) /* image_set_magic */
773 image_set_hdr_l(hcrc) /* image_set_hcrc */ 774 image_set_hdr_l(hcrc) /* image_set_hcrc */
774 image_set_hdr_l(time) /* image_set_time */ 775 image_set_hdr_l(time) /* image_set_time */
775 image_set_hdr_l(size) /* image_set_size */ 776 image_set_hdr_l(size) /* image_set_size */
776 image_set_hdr_l(load) /* image_set_load */ 777 image_set_hdr_l(load) /* image_set_load */
777 image_set_hdr_l(ep) /* image_set_ep */ 778 image_set_hdr_l(ep) /* image_set_ep */
778 image_set_hdr_l(dcrc) /* image_set_dcrc */ 779 image_set_hdr_l(dcrc) /* image_set_dcrc */
779 780
780 #define image_set_hdr_b(f) \ 781 #define image_set_hdr_b(f) \
781 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \ 782 static inline void image_set_##f(image_header_t *hdr, uint8_t val) \
782 { \ 783 { \
783 hdr->ih_##f = val; \ 784 hdr->ih_##f = val; \
784 } 785 }
785 image_set_hdr_b(os) /* image_set_os */ 786 image_set_hdr_b(os) /* image_set_os */
786 image_set_hdr_b(arch) /* image_set_arch */ 787 image_set_hdr_b(arch) /* image_set_arch */
787 image_set_hdr_b(type) /* image_set_type */ 788 image_set_hdr_b(type) /* image_set_type */
788 image_set_hdr_b(comp) /* image_set_comp */ 789 image_set_hdr_b(comp) /* image_set_comp */
789 790
790 static inline void image_set_name(image_header_t *hdr, const char *name) 791 static inline void image_set_name(image_header_t *hdr, const char *name)
791 { 792 {
792 strncpy(image_get_name(hdr), name, IH_NMLEN); 793 strncpy(image_get_name(hdr), name, IH_NMLEN);
793 } 794 }
794 795
795 int image_check_hcrc(const image_header_t *hdr); 796 int image_check_hcrc(const image_header_t *hdr);
796 int image_check_dcrc(const image_header_t *hdr); 797 int image_check_dcrc(const image_header_t *hdr);
797 #ifndef USE_HOSTCC 798 #ifndef USE_HOSTCC
798 ulong env_get_bootm_low(void); 799 ulong env_get_bootm_low(void);
799 phys_size_t env_get_bootm_size(void); 800 phys_size_t env_get_bootm_size(void);
800 phys_size_t env_get_bootm_mapsize(void); 801 phys_size_t env_get_bootm_mapsize(void);
801 #endif 802 #endif
802 void memmove_wd(void *to, void *from, size_t len, ulong chunksz); 803 void memmove_wd(void *to, void *from, size_t len, ulong chunksz);
803 804
804 static inline int image_check_magic(const image_header_t *hdr) 805 static inline int image_check_magic(const image_header_t *hdr)
805 { 806 {
806 return (image_get_magic(hdr) == IH_MAGIC); 807 return (image_get_magic(hdr) == IH_MAGIC);
807 } 808 }
808 static inline int image_check_type(const image_header_t *hdr, uint8_t type) 809 static inline int image_check_type(const image_header_t *hdr, uint8_t type)
809 { 810 {
810 return (image_get_type(hdr) == type); 811 return (image_get_type(hdr) == type);
811 } 812 }
812 static inline int image_check_arch(const image_header_t *hdr, uint8_t arch) 813 static inline int image_check_arch(const image_header_t *hdr, uint8_t arch)
813 { 814 {
814 return (image_get_arch(hdr) == arch) || 815 return (image_get_arch(hdr) == arch) ||
815 (image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64); 816 (image_get_arch(hdr) == IH_ARCH_ARM && arch == IH_ARCH_ARM64);
816 } 817 }
817 static inline int image_check_os(const image_header_t *hdr, uint8_t os) 818 static inline int image_check_os(const image_header_t *hdr, uint8_t os)
818 { 819 {
819 return (image_get_os(hdr) == os); 820 return (image_get_os(hdr) == os);
820 } 821 }
821 822
822 ulong image_multi_count(const image_header_t *hdr); 823 ulong image_multi_count(const image_header_t *hdr);
823 void image_multi_getimg(const image_header_t *hdr, ulong idx, 824 void image_multi_getimg(const image_header_t *hdr, ulong idx,
824 ulong *data, ulong *len); 825 ulong *data, ulong *len);
825 826
826 void image_print_contents(const void *hdr); 827 void image_print_contents(const void *hdr);
827 828
828 #ifndef USE_HOSTCC 829 #ifndef USE_HOSTCC
829 static inline int image_check_target_arch(const image_header_t *hdr) 830 static inline int image_check_target_arch(const image_header_t *hdr)
830 { 831 {
831 #ifndef IH_ARCH_DEFAULT 832 #ifndef IH_ARCH_DEFAULT
832 # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h" 833 # error "please define IH_ARCH_DEFAULT in your arch asm/u-boot.h"
833 #endif 834 #endif
834 return image_check_arch(hdr, IH_ARCH_DEFAULT); 835 return image_check_arch(hdr, IH_ARCH_DEFAULT);
835 } 836 }
836 #endif /* USE_HOSTCC */ 837 #endif /* USE_HOSTCC */
837 838
838 /** 839 /**
839 * Set up properties in the FDT 840 * Set up properties in the FDT
840 * 841 *
841 * This sets up properties in the FDT that is to be passed to linux. 842 * This sets up properties in the FDT that is to be passed to linux.
842 * 843 *
843 * @images: Images information 844 * @images: Images information
844 * @blob: FDT to update 845 * @blob: FDT to update
845 * @of_size: Size of the FDT 846 * @of_size: Size of the FDT
846 * @lmb: Points to logical memory block structure 847 * @lmb: Points to logical memory block structure
847 * @return 0 if ok, <0 on failure 848 * @return 0 if ok, <0 on failure
848 */ 849 */
849 int image_setup_libfdt(bootm_headers_t *images, void *blob, 850 int image_setup_libfdt(bootm_headers_t *images, void *blob,
850 int of_size, struct lmb *lmb); 851 int of_size, struct lmb *lmb);
851 852
852 /** 853 /**
853 * Set up the FDT to use for booting a kernel 854 * Set up the FDT to use for booting a kernel
854 * 855 *
855 * This performs ramdisk setup, sets up the FDT if required, and adds 856 * This performs ramdisk setup, sets up the FDT if required, and adds
856 * paramters to the FDT if libfdt is available. 857 * paramters to the FDT if libfdt is available.
857 * 858 *
858 * @param images Images information 859 * @param images Images information
859 * @return 0 if ok, <0 on failure 860 * @return 0 if ok, <0 on failure
860 */ 861 */
861 int image_setup_linux(bootm_headers_t *images); 862 int image_setup_linux(bootm_headers_t *images);
862 863
863 /** 864 /**
864 * bootz_setup() - Extract stat and size of a Linux xImage 865 * bootz_setup() - Extract stat and size of a Linux xImage
865 * 866 *
866 * @image: Address of image 867 * @image: Address of image
867 * @start: Returns start address of image 868 * @start: Returns start address of image
868 * @end : Returns end address of image 869 * @end : Returns end address of image
869 * @return 0 if OK, 1 if the image was not recognised 870 * @return 0 if OK, 1 if the image was not recognised
870 */ 871 */
871 int bootz_setup(ulong image, ulong *start, ulong *end); 872 int bootz_setup(ulong image, ulong *start, ulong *end);
872 873
873 874
874 /*******************************************************************/ 875 /*******************************************************************/
875 /* New uImage format specific code (prefixed with fit_) */ 876 /* New uImage format specific code (prefixed with fit_) */
876 /*******************************************************************/ 877 /*******************************************************************/
877 878
878 #define FIT_IMAGES_PATH "/images" 879 #define FIT_IMAGES_PATH "/images"
879 #define FIT_CONFS_PATH "/configurations" 880 #define FIT_CONFS_PATH "/configurations"
880 881
881 /* hash/signature node */ 882 /* hash/signature node */
882 #define FIT_HASH_NODENAME "hash" 883 #define FIT_HASH_NODENAME "hash"
883 #define FIT_ALGO_PROP "algo" 884 #define FIT_ALGO_PROP "algo"
884 #define FIT_VALUE_PROP "value" 885 #define FIT_VALUE_PROP "value"
885 #define FIT_IGNORE_PROP "uboot-ignore" 886 #define FIT_IGNORE_PROP "uboot-ignore"
886 #define FIT_SIG_NODENAME "signature" 887 #define FIT_SIG_NODENAME "signature"
887 888
888 /* image node */ 889 /* image node */
889 #define FIT_DATA_PROP "data" 890 #define FIT_DATA_PROP "data"
890 #define FIT_DATA_POSITION_PROP "data-position" 891 #define FIT_DATA_POSITION_PROP "data-position"
891 #define FIT_DATA_OFFSET_PROP "data-offset" 892 #define FIT_DATA_OFFSET_PROP "data-offset"
892 #define FIT_DATA_SIZE_PROP "data-size" 893 #define FIT_DATA_SIZE_PROP "data-size"
893 #define FIT_TIMESTAMP_PROP "timestamp" 894 #define FIT_TIMESTAMP_PROP "timestamp"
894 #define FIT_DESC_PROP "description" 895 #define FIT_DESC_PROP "description"
895 #define FIT_ARCH_PROP "arch" 896 #define FIT_ARCH_PROP "arch"
896 #define FIT_TYPE_PROP "type" 897 #define FIT_TYPE_PROP "type"
897 #define FIT_OS_PROP "os" 898 #define FIT_OS_PROP "os"
898 #define FIT_COMP_PROP "compression" 899 #define FIT_COMP_PROP "compression"
899 #define FIT_ENTRY_PROP "entry" 900 #define FIT_ENTRY_PROP "entry"
900 #define FIT_LOAD_PROP "load" 901 #define FIT_LOAD_PROP "load"
901 902
902 /* configuration node */ 903 /* configuration node */
903 #define FIT_KERNEL_PROP "kernel" 904 #define FIT_KERNEL_PROP "kernel"
904 #define FIT_RAMDISK_PROP "ramdisk" 905 #define FIT_RAMDISK_PROP "ramdisk"
905 #define FIT_FDT_PROP "fdt" 906 #define FIT_FDT_PROP "fdt"
906 #define FIT_LOADABLE_PROP "loadables" 907 #define FIT_LOADABLE_PROP "loadables"
907 #define FIT_DEFAULT_PROP "default" 908 #define FIT_DEFAULT_PROP "default"
908 #define FIT_SETUP_PROP "setup" 909 #define FIT_SETUP_PROP "setup"
909 #define FIT_FPGA_PROP "fpga" 910 #define FIT_FPGA_PROP "fpga"
910 911
911 #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE 912 #define FIT_MAX_HASH_LEN HASH_MAX_DIGEST_SIZE
912 913
913 #if IMAGE_ENABLE_FIT 914 #if IMAGE_ENABLE_FIT
914 /* cmdline argument format parsing */ 915 /* cmdline argument format parsing */
915 int fit_parse_conf(const char *spec, ulong addr_curr, 916 int fit_parse_conf(const char *spec, ulong addr_curr,
916 ulong *addr, const char **conf_name); 917 ulong *addr, const char **conf_name);
917 int fit_parse_subimage(const char *spec, ulong addr_curr, 918 int fit_parse_subimage(const char *spec, ulong addr_curr,
918 ulong *addr, const char **image_name); 919 ulong *addr, const char **image_name);
919 920
920 int fit_get_subimage_count(const void *fit, int images_noffset); 921 int fit_get_subimage_count(const void *fit, int images_noffset);
921 void fit_print_contents(const void *fit); 922 void fit_print_contents(const void *fit);
922 void fit_image_print(const void *fit, int noffset, const char *p); 923 void fit_image_print(const void *fit, int noffset, const char *p);
923 924
924 /** 925 /**
925 * fit_get_end - get FIT image size 926 * fit_get_end - get FIT image size
926 * @fit: pointer to the FIT format image header 927 * @fit: pointer to the FIT format image header
927 * 928 *
928 * returns: 929 * returns:
929 * size of the FIT image (blob) in memory 930 * size of the FIT image (blob) in memory
930 */ 931 */
931 static inline ulong fit_get_size(const void *fit) 932 static inline ulong fit_get_size(const void *fit)
932 { 933 {
933 return fdt_totalsize(fit); 934 return fdt_totalsize(fit);
934 } 935 }
935 936
936 /** 937 /**
937 * fit_get_end - get FIT image end 938 * fit_get_end - get FIT image end
938 * @fit: pointer to the FIT format image header 939 * @fit: pointer to the FIT format image header
939 * 940 *
940 * returns: 941 * returns:
941 * end address of the FIT image (blob) in memory 942 * end address of the FIT image (blob) in memory
942 */ 943 */
943 ulong fit_get_end(const void *fit); 944 ulong fit_get_end(const void *fit);
944 945
945 /** 946 /**
946 * fit_get_name - get FIT node name 947 * fit_get_name - get FIT node name
947 * @fit: pointer to the FIT format image header 948 * @fit: pointer to the FIT format image header
948 * 949 *
949 * returns: 950 * returns:
950 * NULL, on error 951 * NULL, on error
951 * pointer to node name, on success 952 * pointer to node name, on success
952 */ 953 */
953 static inline const char *fit_get_name(const void *fit_hdr, 954 static inline const char *fit_get_name(const void *fit_hdr,
954 int noffset, int *len) 955 int noffset, int *len)
955 { 956 {
956 return fdt_get_name(fit_hdr, noffset, len); 957 return fdt_get_name(fit_hdr, noffset, len);
957 } 958 }
958 959
959 int fit_get_desc(const void *fit, int noffset, char **desc); 960 int fit_get_desc(const void *fit, int noffset, char **desc);
960 int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp); 961 int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp);
961 962
962 int fit_image_get_node(const void *fit, const char *image_uname); 963 int fit_image_get_node(const void *fit, const char *image_uname);
963 int fit_image_get_os(const void *fit, int noffset, uint8_t *os); 964 int fit_image_get_os(const void *fit, int noffset, uint8_t *os);
964 int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch); 965 int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch);
965 int fit_image_get_type(const void *fit, int noffset, uint8_t *type); 966 int fit_image_get_type(const void *fit, int noffset, uint8_t *type);
966 int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp); 967 int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp);
967 int fit_image_get_load(const void *fit, int noffset, ulong *load); 968 int fit_image_get_load(const void *fit, int noffset, ulong *load);
968 int fit_image_get_entry(const void *fit, int noffset, ulong *entry); 969 int fit_image_get_entry(const void *fit, int noffset, ulong *entry);
969 int fit_image_get_data(const void *fit, int noffset, 970 int fit_image_get_data(const void *fit, int noffset,
970 const void **data, size_t *size); 971 const void **data, size_t *size);
971 int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset); 972 int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset);
972 int fit_image_get_data_position(const void *fit, int noffset, 973 int fit_image_get_data_position(const void *fit, int noffset,
973 int *data_position); 974 int *data_position);
974 int fit_image_get_data_size(const void *fit, int noffset, int *data_size); 975 int fit_image_get_data_size(const void *fit, int noffset, int *data_size);
975 976
976 int fit_image_hash_get_algo(const void *fit, int noffset, char **algo); 977 int fit_image_hash_get_algo(const void *fit, int noffset, char **algo);
977 int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, 978 int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
978 int *value_len); 979 int *value_len);
979 980
980 int fit_set_timestamp(void *fit, int noffset, time_t timestamp); 981 int fit_set_timestamp(void *fit, int noffset, time_t timestamp);
981 982
982 /** 983 /**
983 * fit_add_verification_data() - add verification data to FIT image nodes 984 * fit_add_verification_data() - add verification data to FIT image nodes
984 * 985 *
985 * @keydir: Directory containing keys 986 * @keydir: Directory containing keys
986 * @kwydest: FDT blob to write public key information to 987 * @kwydest: FDT blob to write public key information to
987 * @fit: Pointer to the FIT format image header 988 * @fit: Pointer to the FIT format image header
988 * @comment: Comment to add to signature nodes 989 * @comment: Comment to add to signature nodes
989 * @require_keys: Mark all keys as 'required' 990 * @require_keys: Mark all keys as 'required'
990 * @engine_id: Engine to use for signing 991 * @engine_id: Engine to use for signing
991 * 992 *
992 * Adds hash values for all component images in the FIT blob. 993 * Adds hash values for all component images in the FIT blob.
993 * Hashes are calculated for all component images which have hash subnodes 994 * Hashes are calculated for all component images which have hash subnodes
994 * with algorithm property set to one of the supported hash algorithms. 995 * with algorithm property set to one of the supported hash algorithms.
995 * 996 *
996 * Also add signatures if signature nodes are present. 997 * Also add signatures if signature nodes are present.
997 * 998 *
998 * returns 999 * returns
999 * 0, on success 1000 * 0, on success
1000 * libfdt error code, on failure 1001 * libfdt error code, on failure
1001 */ 1002 */
1002 int fit_add_verification_data(const char *keydir, void *keydest, void *fit, 1003 int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
1003 const char *comment, int require_keys, 1004 const char *comment, int require_keys,
1004 const char *engine_id); 1005 const char *engine_id);
1005 1006
1006 int fit_image_verify(const void *fit, int noffset); 1007 int fit_image_verify(const void *fit, int noffset);
1007 int fit_config_verify(const void *fit, int conf_noffset); 1008 int fit_config_verify(const void *fit, int conf_noffset);
1008 int fit_all_image_verify(const void *fit); 1009 int fit_all_image_verify(const void *fit);
1009 int fit_image_check_os(const void *fit, int noffset, uint8_t os); 1010 int fit_image_check_os(const void *fit, int noffset, uint8_t os);
1010 int fit_image_check_arch(const void *fit, int noffset, uint8_t arch); 1011 int fit_image_check_arch(const void *fit, int noffset, uint8_t arch);
1011 int fit_image_check_type(const void *fit, int noffset, uint8_t type); 1012 int fit_image_check_type(const void *fit, int noffset, uint8_t type);
1012 int fit_image_check_comp(const void *fit, int noffset, uint8_t comp); 1013 int fit_image_check_comp(const void *fit, int noffset, uint8_t comp);
1013 int fit_check_format(const void *fit); 1014 int fit_check_format(const void *fit);
1014 1015
1015 int fit_conf_find_compat(const void *fit, const void *fdt); 1016 int fit_conf_find_compat(const void *fit, const void *fdt);
1016 int fit_conf_get_node(const void *fit, const char *conf_uname); 1017 int fit_conf_get_node(const void *fit, const char *conf_uname);
1017 1018
1018 /** 1019 /**
1019 * fit_conf_get_prop_node() - Get node refered to by a configuration 1020 * fit_conf_get_prop_node() - Get node refered to by a configuration
1020 * @fit: FIT to check 1021 * @fit: FIT to check
1021 * @noffset: Offset of conf@xxx node to check 1022 * @noffset: Offset of conf@xxx node to check
1022 * @prop_name: Property to read from the conf node 1023 * @prop_name: Property to read from the conf node
1023 * 1024 *
1024 * The conf@ nodes contain references to other nodes, using properties 1025 * The conf@ nodes contain references to other nodes, using properties
1025 * like 'kernel = "kernel@1"'. Given such a property name (e.g. "kernel"), 1026 * like 'kernel = "kernel@1"'. Given such a property name (e.g. "kernel"),
1026 * return the offset of the node referred to (e.g. offset of node 1027 * return the offset of the node referred to (e.g. offset of node
1027 * "/images/kernel@1". 1028 * "/images/kernel@1".
1028 */ 1029 */
1029 int fit_conf_get_prop_node(const void *fit, int noffset, 1030 int fit_conf_get_prop_node(const void *fit, int noffset,
1030 const char *prop_name); 1031 const char *prop_name);
1031 1032
1032 void fit_conf_print(const void *fit, int noffset, const char *p); 1033 void fit_conf_print(const void *fit, int noffset, const char *p);
1033 1034
1034 int fit_check_ramdisk(const void *fit, int os_noffset, 1035 int fit_check_ramdisk(const void *fit, int os_noffset,
1035 uint8_t arch, int verify); 1036 uint8_t arch, int verify);
1036 1037
1037 int calculate_hash(const void *data, int data_len, const char *algo, 1038 int calculate_hash(const void *data, int data_len, const char *algo,
1038 uint8_t *value, int *value_len); 1039 uint8_t *value, int *value_len);
1039 1040
1040 /* 1041 /*
1041 * At present we only support signing on the host, and verification on the 1042 * At present we only support signing on the host, and verification on the
1042 * device 1043 * device
1043 */ 1044 */
1044 #if defined(CONFIG_FIT_SIGNATURE) 1045 #if defined(CONFIG_FIT_SIGNATURE)
1045 # ifdef USE_HOSTCC 1046 # ifdef USE_HOSTCC
1046 # define IMAGE_ENABLE_SIGN 1 1047 # define IMAGE_ENABLE_SIGN 1
1047 # define IMAGE_ENABLE_VERIFY 1 1048 # define IMAGE_ENABLE_VERIFY 1
1048 # include <openssl/evp.h> 1049 # include <openssl/evp.h>
1049 #else 1050 #else
1050 # define IMAGE_ENABLE_SIGN 0 1051 # define IMAGE_ENABLE_SIGN 0
1051 # define IMAGE_ENABLE_VERIFY 1 1052 # define IMAGE_ENABLE_VERIFY 1
1052 # endif 1053 # endif
1053 #else 1054 #else
1054 # define IMAGE_ENABLE_SIGN 0 1055 # define IMAGE_ENABLE_SIGN 0
1055 # define IMAGE_ENABLE_VERIFY 0 1056 # define IMAGE_ENABLE_VERIFY 0
1056 #endif 1057 #endif
1057 1058
1058 #ifdef USE_HOSTCC 1059 #ifdef USE_HOSTCC
1059 void *image_get_host_blob(void); 1060 void *image_get_host_blob(void);
1060 void image_set_host_blob(void *host_blob); 1061 void image_set_host_blob(void *host_blob);
1061 # define gd_fdt_blob() image_get_host_blob() 1062 # define gd_fdt_blob() image_get_host_blob()
1062 #else 1063 #else
1063 # define gd_fdt_blob() (gd->fdt_blob) 1064 # define gd_fdt_blob() (gd->fdt_blob)
1064 #endif 1065 #endif
1065 1066
1066 #ifdef CONFIG_FIT_BEST_MATCH 1067 #ifdef CONFIG_FIT_BEST_MATCH
1067 #define IMAGE_ENABLE_BEST_MATCH 1 1068 #define IMAGE_ENABLE_BEST_MATCH 1
1068 #else 1069 #else
1069 #define IMAGE_ENABLE_BEST_MATCH 0 1070 #define IMAGE_ENABLE_BEST_MATCH 0
1070 #endif 1071 #endif
1071 1072
1072 /* Information passed to the signing routines */ 1073 /* Information passed to the signing routines */
1073 struct image_sign_info { 1074 struct image_sign_info {
1074 const char *keydir; /* Directory conaining keys */ 1075 const char *keydir; /* Directory conaining keys */
1075 const char *keyname; /* Name of key to use */ 1076 const char *keyname; /* Name of key to use */
1076 void *fit; /* Pointer to FIT blob */ 1077 void *fit; /* Pointer to FIT blob */
1077 int node_offset; /* Offset of signature node */ 1078 int node_offset; /* Offset of signature node */
1078 const char *name; /* Algorithm name */ 1079 const char *name; /* Algorithm name */
1079 struct checksum_algo *checksum; /* Checksum algorithm information */ 1080 struct checksum_algo *checksum; /* Checksum algorithm information */
1080 struct crypto_algo *crypto; /* Crypto algorithm information */ 1081 struct crypto_algo *crypto; /* Crypto algorithm information */
1081 const void *fdt_blob; /* FDT containing public keys */ 1082 const void *fdt_blob; /* FDT containing public keys */
1082 int required_keynode; /* Node offset of key to use: -1=any */ 1083 int required_keynode; /* Node offset of key to use: -1=any */
1083 const char *require_keys; /* Value for 'required' property */ 1084 const char *require_keys; /* Value for 'required' property */
1084 const char *engine_id; /* Engine to use for signing */ 1085 const char *engine_id; /* Engine to use for signing */
1085 }; 1086 };
1086 #endif /* Allow struct image_region to always be defined for rsa.h */ 1087 #endif /* Allow struct image_region to always be defined for rsa.h */
1087 1088
1088 /* A part of an image, used for hashing */ 1089 /* A part of an image, used for hashing */
1089 struct image_region { 1090 struct image_region {
1090 const void *data; 1091 const void *data;
1091 int size; 1092 int size;
1092 }; 1093 };
1093 1094
1094 #if IMAGE_ENABLE_FIT 1095 #if IMAGE_ENABLE_FIT
1095 1096
1096 #if IMAGE_ENABLE_VERIFY 1097 #if IMAGE_ENABLE_VERIFY
1097 # include <u-boot/rsa-checksum.h> 1098 # include <u-boot/rsa-checksum.h>
1098 #endif 1099 #endif
1099 struct checksum_algo { 1100 struct checksum_algo {
1100 const char *name; 1101 const char *name;
1101 const int checksum_len; 1102 const int checksum_len;
1102 const int der_len; 1103 const int der_len;
1103 const uint8_t *der_prefix; 1104 const uint8_t *der_prefix;
1104 #if IMAGE_ENABLE_SIGN 1105 #if IMAGE_ENABLE_SIGN
1105 const EVP_MD *(*calculate_sign)(void); 1106 const EVP_MD *(*calculate_sign)(void);
1106 #endif 1107 #endif
1107 int (*calculate)(const char *name, 1108 int (*calculate)(const char *name,
1108 const struct image_region region[], 1109 const struct image_region region[],
1109 int region_count, uint8_t *checksum); 1110 int region_count, uint8_t *checksum);
1110 }; 1111 };
1111 1112
1112 struct crypto_algo { 1113 struct crypto_algo {
1113 const char *name; /* Name of algorithm */ 1114 const char *name; /* Name of algorithm */
1114 const int key_len; 1115 const int key_len;
1115 1116
1116 /** 1117 /**
1117 * sign() - calculate and return signature for given input data 1118 * sign() - calculate and return signature for given input data
1118 * 1119 *
1119 * @info: Specifies key and FIT information 1120 * @info: Specifies key and FIT information
1120 * @data: Pointer to the input data 1121 * @data: Pointer to the input data
1121 * @data_len: Data length 1122 * @data_len: Data length
1122 * @sigp: Set to an allocated buffer holding the signature 1123 * @sigp: Set to an allocated buffer holding the signature
1123 * @sig_len: Set to length of the calculated hash 1124 * @sig_len: Set to length of the calculated hash
1124 * 1125 *
1125 * This computes input data signature according to selected algorithm. 1126 * This computes input data signature according to selected algorithm.
1126 * Resulting signature value is placed in an allocated buffer, the 1127 * Resulting signature value is placed in an allocated buffer, the
1127 * pointer is returned as *sigp. The length of the calculated 1128 * pointer is returned as *sigp. The length of the calculated
1128 * signature is returned via the sig_len pointer argument. The caller 1129 * signature is returned via the sig_len pointer argument. The caller
1129 * should free *sigp. 1130 * should free *sigp.
1130 * 1131 *
1131 * @return: 0, on success, -ve on error 1132 * @return: 0, on success, -ve on error
1132 */ 1133 */
1133 int (*sign)(struct image_sign_info *info, 1134 int (*sign)(struct image_sign_info *info,
1134 const struct image_region region[], 1135 const struct image_region region[],
1135 int region_count, uint8_t **sigp, uint *sig_len); 1136 int region_count, uint8_t **sigp, uint *sig_len);
1136 1137
1137 /** 1138 /**
1138 * add_verify_data() - Add verification information to FDT 1139 * add_verify_data() - Add verification information to FDT
1139 * 1140 *
1140 * Add public key information to the FDT node, suitable for 1141 * Add public key information to the FDT node, suitable for
1141 * verification at run-time. The information added depends on the 1142 * verification at run-time. The information added depends on the
1142 * algorithm being used. 1143 * algorithm being used.
1143 * 1144 *
1144 * @info: Specifies key and FIT information 1145 * @info: Specifies key and FIT information
1145 * @keydest: Destination FDT blob for public key data 1146 * @keydest: Destination FDT blob for public key data
1146 * @return: 0, on success, -ve on error 1147 * @return: 0, on success, -ve on error
1147 */ 1148 */
1148 int (*add_verify_data)(struct image_sign_info *info, void *keydest); 1149 int (*add_verify_data)(struct image_sign_info *info, void *keydest);
1149 1150
1150 /** 1151 /**
1151 * verify() - Verify a signature against some data 1152 * verify() - Verify a signature against some data
1152 * 1153 *
1153 * @info: Specifies key and FIT information 1154 * @info: Specifies key and FIT information
1154 * @data: Pointer to the input data 1155 * @data: Pointer to the input data
1155 * @data_len: Data length 1156 * @data_len: Data length
1156 * @sig: Signature 1157 * @sig: Signature
1157 * @sig_len: Number of bytes in signature 1158 * @sig_len: Number of bytes in signature
1158 * @return 0 if verified, -ve on error 1159 * @return 0 if verified, -ve on error
1159 */ 1160 */
1160 int (*verify)(struct image_sign_info *info, 1161 int (*verify)(struct image_sign_info *info,
1161 const struct image_region region[], int region_count, 1162 const struct image_region region[], int region_count,
1162 uint8_t *sig, uint sig_len); 1163 uint8_t *sig, uint sig_len);
1163 }; 1164 };
1164 1165
1165 /** 1166 /**
1166 * image_get_checksum_algo() - Look up a checksum algorithm 1167 * image_get_checksum_algo() - Look up a checksum algorithm
1167 * 1168 *
1168 * @param full_name Name of algorithm in the form "checksum,crypto" 1169 * @param full_name Name of algorithm in the form "checksum,crypto"
1169 * @return pointer to algorithm information, or NULL if not found 1170 * @return pointer to algorithm information, or NULL if not found
1170 */ 1171 */
1171 struct checksum_algo *image_get_checksum_algo(const char *full_name); 1172 struct checksum_algo *image_get_checksum_algo(const char *full_name);
1172 1173
1173 /** 1174 /**
1174 * image_get_crypto_algo() - Look up a cryptosystem algorithm 1175 * image_get_crypto_algo() - Look up a cryptosystem algorithm
1175 * 1176 *
1176 * @param full_name Name of algorithm in the form "checksum,crypto" 1177 * @param full_name Name of algorithm in the form "checksum,crypto"
1177 * @return pointer to algorithm information, or NULL if not found 1178 * @return pointer to algorithm information, or NULL if not found
1178 */ 1179 */
1179 struct crypto_algo *image_get_crypto_algo(const char *full_name); 1180 struct crypto_algo *image_get_crypto_algo(const char *full_name);
1180 1181
1181 /** 1182 /**
1182 * fit_image_verify_required_sigs() - Verify signatures marked as 'required' 1183 * fit_image_verify_required_sigs() - Verify signatures marked as 'required'
1183 * 1184 *
1184 * @fit: FIT to check 1185 * @fit: FIT to check
1185 * @image_noffset: Offset of image node to check 1186 * @image_noffset: Offset of image node to check
1186 * @data: Image data to check 1187 * @data: Image data to check
1187 * @size: Size of image data 1188 * @size: Size of image data
1188 * @sig_blob: FDT containing public keys 1189 * @sig_blob: FDT containing public keys
1189 * @no_sigsp: Returns 1 if no signatures were required, and 1190 * @no_sigsp: Returns 1 if no signatures were required, and
1190 * therefore nothing was checked. The caller may wish 1191 * therefore nothing was checked. The caller may wish
1191 * to fall back to other mechanisms, or refuse to 1192 * to fall back to other mechanisms, or refuse to
1192 * boot. 1193 * boot.
1193 * @return 0 if all verified ok, <0 on error 1194 * @return 0 if all verified ok, <0 on error
1194 */ 1195 */
1195 int fit_image_verify_required_sigs(const void *fit, int image_noffset, 1196 int fit_image_verify_required_sigs(const void *fit, int image_noffset,
1196 const char *data, size_t size, const void *sig_blob, 1197 const char *data, size_t size, const void *sig_blob,
1197 int *no_sigsp); 1198 int *no_sigsp);
1198 1199
1199 /** 1200 /**
1200 * fit_image_check_sig() - Check a single image signature node 1201 * fit_image_check_sig() - Check a single image signature node
1201 * 1202 *
1202 * @fit: FIT to check 1203 * @fit: FIT to check
1203 * @noffset: Offset of signature node to check 1204 * @noffset: Offset of signature node to check
1204 * @data: Image data to check 1205 * @data: Image data to check
1205 * @size: Size of image data 1206 * @size: Size of image data
1206 * @required_keynode: Offset in the control FDT of the required key node, 1207 * @required_keynode: Offset in the control FDT of the required key node,
1207 * if any. If this is given, then the image wil not 1208 * if any. If this is given, then the image wil not
1208 * pass verification unless that key is used. If this is 1209 * pass verification unless that key is used. If this is
1209 * -1 then any signature will do. 1210 * -1 then any signature will do.
1210 * @err_msgp: In the event of an error, this will be pointed to a 1211 * @err_msgp: In the event of an error, this will be pointed to a
1211 * help error string to display to the user. 1212 * help error string to display to the user.
1212 * @return 0 if all verified ok, <0 on error 1213 * @return 0 if all verified ok, <0 on error
1213 */ 1214 */
1214 int fit_image_check_sig(const void *fit, int noffset, const void *data, 1215 int fit_image_check_sig(const void *fit, int noffset, const void *data,
1215 size_t size, int required_keynode, char **err_msgp); 1216 size_t size, int required_keynode, char **err_msgp);
1216 1217
1217 /** 1218 /**
1218 * fit_region_make_list() - Make a list of regions to hash 1219 * fit_region_make_list() - Make a list of regions to hash
1219 * 1220 *
1220 * Given a list of FIT regions (offset, size) provided by libfdt, create 1221 * Given a list of FIT regions (offset, size) provided by libfdt, create
1221 * a list of regions (void *, size) for use by the signature creationg 1222 * a list of regions (void *, size) for use by the signature creationg
1222 * and verification code. 1223 * and verification code.
1223 * 1224 *
1224 * @fit: FIT image to process 1225 * @fit: FIT image to process
1225 * @fdt_regions: Regions as returned by libfdt 1226 * @fdt_regions: Regions as returned by libfdt
1226 * @count: Number of regions returned by libfdt 1227 * @count: Number of regions returned by libfdt
1227 * @region: Place to put list of regions (NULL to allocate it) 1228 * @region: Place to put list of regions (NULL to allocate it)
1228 * @return pointer to list of regions, or NULL if out of memory 1229 * @return pointer to list of regions, or NULL if out of memory
1229 */ 1230 */
1230 struct image_region *fit_region_make_list(const void *fit, 1231 struct image_region *fit_region_make_list(const void *fit,
1231 struct fdt_region *fdt_regions, int count, 1232 struct fdt_region *fdt_regions, int count,
1232 struct image_region *region); 1233 struct image_region *region);
1233 1234
1234 static inline int fit_image_check_target_arch(const void *fdt, int node) 1235 static inline int fit_image_check_target_arch(const void *fdt, int node)
1235 { 1236 {
1236 #ifndef USE_HOSTCC 1237 #ifndef USE_HOSTCC
1237 return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT); 1238 return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
1238 #else 1239 #else
1239 return 0; 1240 return 0;
1240 #endif 1241 #endif
1241 } 1242 }
1242 1243
1243 #ifdef CONFIG_FIT_VERBOSE 1244 #ifdef CONFIG_FIT_VERBOSE
1244 #define fit_unsupported(msg) printf("! %s:%d " \ 1245 #define fit_unsupported(msg) printf("! %s:%d " \
1245 "FIT images not supported for '%s'\n", \ 1246 "FIT images not supported for '%s'\n", \
1246 __FILE__, __LINE__, (msg)) 1247 __FILE__, __LINE__, (msg))
1247 1248
1248 #define fit_unsupported_reset(msg) printf("! %s:%d " \ 1249 #define fit_unsupported_reset(msg) printf("! %s:%d " \
1249 "FIT images not supported for '%s' " \ 1250 "FIT images not supported for '%s' " \
1250 "- must reset board to recover!\n", \ 1251 "- must reset board to recover!\n", \
1251 __FILE__, __LINE__, (msg)) 1252 __FILE__, __LINE__, (msg))
1252 #else 1253 #else
1253 #define fit_unsupported(msg) 1254 #define fit_unsupported(msg)
1254 #define fit_unsupported_reset(msg) 1255 #define fit_unsupported_reset(msg)
1255 #endif /* CONFIG_FIT_VERBOSE */ 1256 #endif /* CONFIG_FIT_VERBOSE */
1256 #endif /* CONFIG_FIT */ 1257 #endif /* CONFIG_FIT */
1257 1258
1258 #if defined(CONFIG_ANDROID_BOOT_IMAGE) 1259 #if defined(CONFIG_ANDROID_BOOT_IMAGE)
1259 struct andr_img_hdr; 1260 struct andr_img_hdr;
1260 int android_image_check_header(const struct andr_img_hdr *hdr); 1261 int android_image_check_header(const struct andr_img_hdr *hdr);
1261 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, 1262 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
1262 ulong *os_data, ulong *os_len); 1263 ulong *os_data, ulong *os_len);
1263 int android_image_get_ramdisk(const struct andr_img_hdr *hdr, 1264 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
1264 ulong *rd_data, ulong *rd_len); 1265 ulong *rd_data, ulong *rd_len);
1265 ulong android_image_get_end(const struct andr_img_hdr *hdr); 1266 ulong android_image_get_end(const struct andr_img_hdr *hdr);
1266 ulong android_image_get_kload(const struct andr_img_hdr *hdr); 1267 ulong android_image_get_kload(const struct andr_img_hdr *hdr);
1267 void android_print_contents(const struct andr_img_hdr *hdr); 1268 void android_print_contents(const struct andr_img_hdr *hdr);
1268 1269
1269 #endif /* CONFIG_ANDROID_BOOT_IMAGE */ 1270 #endif /* CONFIG_ANDROID_BOOT_IMAGE */
1270 1271
1271 /** 1272 /**
1272 * board_fit_config_name_match() - Check for a matching board name 1273 * board_fit_config_name_match() - Check for a matching board name
1273 * 1274 *
1274 * This is used when SPL loads a FIT containing multiple device tree files 1275 * This is used when SPL loads a FIT containing multiple device tree files
1275 * and wants to work out which one to use. The description of each one is 1276 * and wants to work out which one to use. The description of each one is
1276 * passed to this function. The description comes from the 'description' field 1277 * passed to this function. The description comes from the 'description' field
1277 * in each (FDT) image node. 1278 * in each (FDT) image node.
1278 * 1279 *
1279 * @name: Device tree description 1280 * @name: Device tree description
1280 * @return 0 if this device tree should be used, non-zero to try the next 1281 * @return 0 if this device tree should be used, non-zero to try the next
1281 */ 1282 */
1282 int board_fit_config_name_match(const char *name); 1283 int board_fit_config_name_match(const char *name);
1283 1284
1284 #if defined(CONFIG_SPL_FIT_IMAGE_POST_PROCESS) || \ 1285 #if defined(CONFIG_SPL_FIT_IMAGE_POST_PROCESS) || \
1285 defined(CONFIG_FIT_IMAGE_POST_PROCESS) 1286 defined(CONFIG_FIT_IMAGE_POST_PROCESS)
1286 /** 1287 /**
1287 * board_fit_image_post_process() - Do any post-process on FIT binary data 1288 * board_fit_image_post_process() - Do any post-process on FIT binary data
1288 * 1289 *
1289 * This is used to do any sort of image manipulation, verification, decryption 1290 * This is used to do any sort of image manipulation, verification, decryption
1290 * etc. in a platform or board specific way. Obviously, anything done here would 1291 * etc. in a platform or board specific way. Obviously, anything done here would
1291 * need to be comprehended in how the images were prepared before being injected 1292 * need to be comprehended in how the images were prepared before being injected
1292 * into the FIT creation (i.e. the binary blobs would have been pre-processed 1293 * into the FIT creation (i.e. the binary blobs would have been pre-processed
1293 * before being added to the FIT image). 1294 * before being added to the FIT image).
1294 * 1295 *
1295 * @image: pointer to the image start pointer 1296 * @image: pointer to the image start pointer
1296 * @size: pointer to the image size 1297 * @size: pointer to the image size
1297 * @return no return value (failure should be handled internally) 1298 * @return no return value (failure should be handled internally)
1298 */ 1299 */
1299 void board_fit_image_post_process(void **p_image, size_t *p_size); 1300 void board_fit_image_post_process(void **p_image, size_t *p_size);
1300 #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */ 1301 #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
1301 1302
1302 #define FDT_ERROR ((ulong)(-1)) 1303 #define FDT_ERROR ((ulong)(-1))
1303 1304
1304 ulong fdt_getprop_u32(const void *fdt, int node, const char *prop); 1305 ulong fdt_getprop_u32(const void *fdt, int node, const char *prop);
1305 1306
1306 /** 1307 /**
1307 * fit_find_config_node() - Find the node for the best DTB in a FIT image 1308 * fit_find_config_node() - Find the node for the best DTB in a FIT image
1308 * 1309 *
1309 * A FIT image contains one or more DTBs. This function parses the 1310 * A FIT image contains one or more DTBs. This function parses the
1310 * configurations described in the FIT images and returns the node of 1311 * configurations described in the FIT images and returns the node of
1311 * the first matching DTB. To check if a DTB matches a board, this function 1312 * the first matching DTB. To check if a DTB matches a board, this function
1312 * calls board_fit_config_name_match(). If no matching DTB is found, it returns 1313 * calls board_fit_config_name_match(). If no matching DTB is found, it returns
1313 * the node described by the default configuration if it exists. 1314 * the node described by the default configuration if it exists.
1314 * 1315 *
1315 * @fdt: pointer to flat device tree 1316 * @fdt: pointer to flat device tree
1316 * @return the node if found, -ve otherwise 1317 * @return the node if found, -ve otherwise
1317 */ 1318 */
1318 int fit_find_config_node(const void *fdt); 1319 int fit_find_config_node(const void *fdt);
1319 1320
1320 /** 1321 /**
1321 * Mapping of image types to function handlers to be invoked on the associated 1322 * Mapping of image types to function handlers to be invoked on the associated
1322 * loaded images 1323 * loaded images
1323 * 1324 *
1324 * @type: Type of image, I.E. IH_TYPE_* 1325 * @type: Type of image, I.E. IH_TYPE_*
1325 * @handler: Function to call on loaded image 1326 * @handler: Function to call on loaded image
1326 */ 1327 */
1327 struct fit_loadable_tbl { 1328 struct fit_loadable_tbl {
1328 int type; 1329 int type;
1329 /** 1330 /**
1330 * handler() - Process a loaded image 1331 * handler() - Process a loaded image
1331 * 1332 *
1332 * @data: Pointer to start of loaded image data 1333 * @data: Pointer to start of loaded image data
1333 * @size: Size of loaded image data 1334 * @size: Size of loaded image data
1334 */ 1335 */
1335 void (*handler)(ulong data, size_t size); 1336 void (*handler)(ulong data, size_t size);
1336 }; 1337 };
1337 1338
1338 /* 1339 /*
1339 * Define a FIT loadable image type handler 1340 * Define a FIT loadable image type handler
1340 * 1341 *
1341 * _type is a valid uimage_type ID as defined in the "Image Type" enum above 1342 * _type is a valid uimage_type ID as defined in the "Image Type" enum above
1342 * _handler is the handler function to call after this image type is loaded 1343 * _handler is the handler function to call after this image type is loaded
1343 */ 1344 */
1344 #define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \ 1345 #define U_BOOT_FIT_LOADABLE_HANDLER(_type, _handler) \
1345 ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \ 1346 ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \
1346 .type = _type, \ 1347 .type = _type, \
1347 .handler = _handler, \ 1348 .handler = _handler, \
1348 } 1349 }
1349 1350
1350 #endif /* __IMAGE_H__ */ 1351 #endif /* __IMAGE_H__ */
1351 1352