Blame view

common/spl/spl.c 8.1 KB
bcae72116   Aneesh V   omap: add basic S...
1
2
3
4
5
6
  /*
   * (C) Copyright 2010
   * Texas Instruments, <www.ti.com>
   *
   * Aneesh V <aneesh@ti.com>
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
7
   * SPDX-License-Identifier:	GPL-2.0+
bcae72116   Aneesh V   omap: add basic S...
8
9
   */
  #include <common.h>
115165183   Simon Glass   dm: spl: Allow dr...
10
  #include <dm.h>
47f7bcae8   Tom Rini   SPL: Move the oma...
11
  #include <spl.h>
bcae72116   Aneesh V   omap: add basic S...
12
  #include <asm/u-boot.h>
bb085b87e   Simon Schwarz   omap-common: add ...
13
  #include <nand.h>
8cf686e19   Aneesh V   omap: add MMC and...
14
  #include <fat.h>
efb2172ec   Simon Glass   Move timestamp an...
15
  #include <version.h>
8cf686e19   Aneesh V   omap: add MMC and...
16
17
  #include <i2c.h>
  #include <image.h>
2d01dd953   Aneesh V   omap: spl: fix bu...
18
  #include <malloc.h>
115165183   Simon Glass   dm: spl: Allow dr...
19
  #include <dm/root.h>
761ca31e4   Andreas Müller   omap_rev_string: ...
20
  #include <linux/compiler.h>
bcae72116   Aneesh V   omap: add basic S...
21
22
  
  DECLARE_GLOBAL_DATA_PTR;
3c6f8a0d1   Stefan Roese   SPL: Enable use o...
23
24
25
  #ifndef CONFIG_SYS_UBOOT_START
  #define CONFIG_SYS_UBOOT_START	CONFIG_SYS_TEXT_BASE
  #endif
ae83d882f   Stefano Babic   SPL: do not use f...
26
  #ifndef CONFIG_SYS_MONITOR_LEN
e76caa627   Andreas Bießmann   spl: move comment...
27
  /* Unknown U-Boot size, let's assume it will not be more than 200 KB */
ae83d882f   Stefano Babic   SPL: do not use f...
28
29
  #define CONFIG_SYS_MONITOR_LEN	(200 * 1024)
  #endif
47f7bcae8   Tom Rini   SPL: Move the oma...
30
  u32 *boot_params_ptr = NULL;
9ea5c6efd   Simon Schwarz   omap-common: reor...
31
  struct spl_image_info spl_image;
6507f133f   Tom Rini   SPL: Create arch/...
32
  /* Define board data structure */
bcae72116   Aneesh V   omap: add basic S...
33
  static bd_t bdata __attribute__ ((section(".data")));
379c19ab7   Simon Schwarz   omap-common/spl: ...
34
35
36
37
38
39
40
41
42
43
44
45
46
  /*
   * Default function to determine if u-boot or the OS should
   * be started. This implementation always returns 1.
   *
   * Please implement your own board specific funcion to do this.
   *
   * RETURN
   * 0 to not start u-boot
   * positive if u-boot should start
   */
  #ifdef CONFIG_SPL_OS_BOOT
  __weak int spl_start_uboot(void)
  {
026b2fe32   Tom Rini   ARM: SPL: Clean u...
47
48
49
50
  	puts("SPL: Please implement spl_start_uboot() for your board
  ");
  	puts("SPL: Direct Linux boot not active!
  ");
379c19ab7   Simon Schwarz   omap-common/spl: ...
51
52
53
  	return 1;
  }
  #endif
ea8256f07   Stefan Roese   SPL: Port SPL fra...
54
55
56
57
58
59
60
61
62
  /*
   * Weak default function for board specific cleanup/preparation before
   * Linux boot. Some boards/platforms might not need it, so just provide
   * an empty stub here.
   */
  __weak void spl_board_prepare_for_linux(void)
  {
  	/* Nothing to do! */
  }
0c3117b1f   Heiko Schocher   spl, nand: add op...
63
64
65
66
67
68
69
70
  void spl_set_header_raw_uboot(void)
  {
  	spl_image.size = CONFIG_SYS_MONITOR_LEN;
  	spl_image.entry_point = CONFIG_SYS_UBOOT_START;
  	spl_image.load_addr = CONFIG_SYS_TEXT_BASE;
  	spl_image.os = IH_OS_U_BOOT;
  	spl_image.name = "U-Boot";
  }
9ea5c6efd   Simon Schwarz   omap-common: reor...
71
  void spl_parse_image_header(const struct image_header *header)
8cf686e19   Aneesh V   omap: add MMC and...
72
73
  {
  	u32 header_size = sizeof(struct image_header);
77552b063   Stefan Roese   SPL: Use image_ge...
74
  	if (image_get_magic(header) == IH_MAGIC) {
022b4975c   Stefan Roese   SPL: Add option t...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  		if (spl_image.flags & SPL_COPY_PAYLOAD_ONLY) {
  			/*
  			 * On some system (e.g. powerpc), the load-address and
  			 * entry-point is located at address 0. We can't load
  			 * to 0-0x40. So skip header in this case.
  			 */
  			spl_image.load_addr = image_get_load(header);
  			spl_image.entry_point = image_get_ep(header);
  			spl_image.size = image_get_data_size(header);
  		} else {
  			spl_image.entry_point = image_get_load(header);
  			/* Load including the header */
  			spl_image.load_addr = spl_image.entry_point -
  				header_size;
  			spl_image.size = image_get_data_size(header) +
  				header_size;
  		}
77552b063   Stefan Roese   SPL: Use image_ge...
92
93
  		spl_image.os = image_get_os(header);
  		spl_image.name = image_get_name(header);
62cf11c09   Taras Kondratiuk   SPL: Limit image ...
94
95
  		debug("spl: payload image: %.*s load addr: 0x%x size: %d
  ",
5d69a5d17   Vasili Galka   Fix a few printf ...
96
  			(int)sizeof(spl_image.name), spl_image.name,
62cf11c09   Taras Kondratiuk   SPL: Limit image ...
97
  			spl_image.load_addr, spl_image.size);
8cf686e19   Aneesh V   omap: add MMC and...
98
  	} else {
8c80eb3b5   Albert ARIBAUD \(3ADEV\)   Introduce CONFIG_...
99
100
101
102
103
104
105
106
107
108
109
  #ifdef CONFIG_SPL_PANIC_ON_RAW_IMAGE
  		/*
  		 * CONFIG_SPL_PANIC_ON_RAW_IMAGE is defined when the
  		 * code which loads images in SPL cannot guarantee that
  		 * absolutely all read errors will be reported.
  		 * An example is the LPC32XX MLC NAND driver, which
  		 * will consider that a completely unreadable NAND block
  		 * is bad, and thus should be skipped silently.
  		 */
  		panic("** no mkimage signature but raw image not supported");
  #else
8cf686e19   Aneesh V   omap: add MMC and...
110
  		/* Signature not found - assume u-boot.bin */
026b2fe32   Tom Rini   ARM: SPL: Clean u...
111
112
  		debug("mkimage signature not found - ih_magic = %x
  ",
8cf686e19   Aneesh V   omap: add MMC and...
113
  			header->ih_magic);
0c3117b1f   Heiko Schocher   spl, nand: add op...
114
  		spl_set_header_raw_uboot();
8c80eb3b5   Albert ARIBAUD \(3ADEV\)   Introduce CONFIG_...
115
  #endif
8cf686e19   Aneesh V   omap: add MMC and...
116
117
  	}
  }
a759f1e0d   Allen Martin   SPL: make jump_to...
118
  __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
8cf686e19   Aneesh V   omap: add MMC and...
119
  {
4a0eb7575   SRICHARAN R   ARM: OMAP: Cleanu...
120
  	typedef void __noreturn (*image_entry_noargs_t)(void);
8cf686e19   Aneesh V   omap: add MMC and...
121
  	image_entry_noargs_t image_entry =
a759f1e0d   Allen Martin   SPL: make jump_to...
122
  			(image_entry_noargs_t) spl_image->entry_point;
8cf686e19   Aneesh V   omap: add MMC and...
123

a759f1e0d   Allen Martin   SPL: make jump_to...
124
125
  	debug("image entry point: 0x%X
  ", spl_image->entry_point);
4a0eb7575   SRICHARAN R   ARM: OMAP: Cleanu...
126
  	image_entry();
8cf686e19   Aneesh V   omap: add MMC and...
127
  }
c57b953da   Pavel Machek   SPL: Add support ...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  #ifdef CONFIG_SPL_RAM_DEVICE
  static void spl_ram_load_image(void)
  {
  	const struct image_header *header;
  
  	/*
  	 * Get the header.  It will point to an address defined by handoff
  	 * which will tell where the image located inside the flash. For
  	 * now, it will temporary fixed to address pointed by U-Boot.
  	 */
  	header = (struct image_header *)
  		(CONFIG_SYS_TEXT_BASE -	sizeof(struct image_header));
  
  	spl_parse_image_header(header);
  }
  #endif
6507f133f   Tom Rini   SPL: Create arch/...
144
  void board_init_r(gd_t *dummy1, ulong dummy2)
bcae72116   Aneesh V   omap: add basic S...
145
  {
8cf686e19   Aneesh V   omap: add MMC and...
146
147
148
  	u32 boot_device;
  	debug(">>spl:board_init_r()
  ");
fb4f5e7c9   Simon Glass   dm: spl: Make sim...
149
  #if defined(CONFIG_SYS_SPL_MALLOC_START)
2d01dd953   Aneesh V   omap: spl: fix bu...
150
151
  	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
  			CONFIG_SYS_SPL_MALLOC_SIZE);
fb4f5e7c9   Simon Glass   dm: spl: Make sim...
152
153
154
155
  	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  #elif defined(CONFIG_SYS_MALLOC_F_LEN)
  	gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
  	gd->malloc_ptr = 0;
24dafad5c   Tom Rini   ARM: SPL: Only ca...
156
  #endif
115165183   Simon Glass   dm: spl: Allow dr...
157
158
  #ifdef CONFIG_SPL_DM
  	dm_init_and_scan(true);
24dafad5c   Tom Rini   ARM: SPL: Only ca...
159
  #endif
2d01dd953   Aneesh V   omap: spl: fix bu...
160

ea8256f07   Stefan Roese   SPL: Port SPL fra...
161
162
163
164
165
  #ifndef CONFIG_PPC
  	/*
  	 * timer_init() does not exist on PPC systems. The timer is initialized
  	 * and enabled (decrementer) in interrupt_init() here.
  	 */
4063c77de   Ilya Yanok   OMAP: spl: call t...
166
  	timer_init();
ea8256f07   Stefan Roese   SPL: Port SPL fra...
167
  #endif
4063c77de   Ilya Yanok   OMAP: spl: call t...
168

ee08a8260   Tom Rini   OMAP3: Add SPL_BO...
169
170
171
  #ifdef CONFIG_SPL_BOARD_INIT
  	spl_board_init();
  #endif
8e1b836ec   Tom Rini   ARM: SPL: Rename ...
172
  	boot_device = spl_boot_device();
8cf686e19   Aneesh V   omap: add MMC and...
173
174
175
  	debug("boot device - %d
  ", boot_device);
  	switch (boot_device) {
c57b953da   Pavel Machek   SPL: Add support ...
176
177
178
179
180
  #ifdef CONFIG_SPL_RAM_DEVICE
  	case BOOT_DEVICE_RAM:
  		spl_ram_load_image();
  		break;
  #endif
bb085b87e   Simon Schwarz   omap-common: add ...
181
  #ifdef CONFIG_SPL_MMC_SUPPORT
8cf686e19   Aneesh V   omap: add MMC and...
182
183
  	case BOOT_DEVICE_MMC1:
  	case BOOT_DEVICE_MMC2:
f75231b79   Balaji T K   arm: omap5: corre...
184
  	case BOOT_DEVICE_MMC2_2:
9ea5c6efd   Simon Schwarz   omap-common: reor...
185
  		spl_mmc_load_image();
8cf686e19   Aneesh V   omap: add MMC and...
186
  		break;
bb085b87e   Simon Schwarz   omap-common: add ...
187
188
189
  #endif
  #ifdef CONFIG_SPL_NAND_SUPPORT
  	case BOOT_DEVICE_NAND:
9ea5c6efd   Simon Schwarz   omap-common: reor...
190
  		spl_nand_load_image();
bb085b87e   Simon Schwarz   omap-common: add ...
191
192
  		break;
  #endif
6000992e2   Enric Balletbo i Serra   SPL: ONENAND: Sup...
193
194
195
196
197
  #ifdef CONFIG_SPL_ONENAND_SUPPORT
  	case BOOT_DEVICE_ONENAND:
  		spl_onenand_load_image();
  		break;
  #endif
33d346464   Stefan Roese   SPL: Add NOR flas...
198
199
200
201
202
  #ifdef CONFIG_SPL_NOR_SUPPORT
  	case BOOT_DEVICE_NOR:
  		spl_nor_load_image();
  		break;
  #endif
24de357a3   Matt Porter   SPL: Add YMODEM o...
203
204
205
206
207
  #ifdef CONFIG_SPL_YMODEM_SUPPORT
  	case BOOT_DEVICE_UART:
  		spl_ymodem_load_image();
  		break;
  #endif
d4c4e0e11   Tom Rini   ARM: SPL: Start h...
208
209
  #ifdef CONFIG_SPL_SPI_SUPPORT
  	case BOOT_DEVICE_SPI:
a4cc1c487   Tom Rini   SPL: SPI: Enhance...
210
211
  		spl_spi_load_image();
  		break;
d4c4e0e11   Tom Rini   ARM: SPL: Start h...
212
  #endif
7ac2fe2da   Ilya Yanok   OMAP: networking ...
213
214
215
216
217
218
219
220
221
  #ifdef CONFIG_SPL_ETH_SUPPORT
  	case BOOT_DEVICE_CPGMAC:
  #ifdef CONFIG_SPL_ETH_DEVICE
  		spl_net_load_image(CONFIG_SPL_ETH_DEVICE);
  #else
  		spl_net_load_image(NULL);
  #endif
  		break;
  #endif
62a814310   Ilya Yanok   spl: support for ...
222
223
224
225
226
  #ifdef CONFIG_SPL_USBETH_SUPPORT
  	case BOOT_DEVICE_USBETH:
  		spl_net_load_image("usb_ether");
  		break;
  #endif
8cffe5bd0   Dan Murphy   spl: common: Supp...
227
228
229
230
231
  #ifdef CONFIG_SPL_USB_SUPPORT
  	case BOOT_DEVICE_USB:
  		spl_usb_load_image();
  		break;
  #endif
fff40a7e0   Dan Murphy   common: spl: Add ...
232
233
234
235
236
  #ifdef CONFIG_SPL_SATA_SUPPORT
  	case BOOT_DEVICE_SATA:
  		spl_sata_load_image();
  		break;
  #endif
c01c71bc1   Simon Glass   arm: spl: Provide...
237
238
239
240
241
  #ifdef CONFIG_SPL_BOARD_LOAD_IMAGE
  	case BOOT_DEVICE_BOARD:
  		spl_board_load_image();
  		break;
  #endif
8cf686e19   Aneesh V   omap: add MMC and...
242
  	default:
18f26fdbd   Stefan Roese   spl: Change debug...
243
  #if defined(CONFIG_SPL_SERIAL_SUPPORT) && defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
e860d012c   Stefan Roese   spl: Change print...
244
245
  		puts("SPL: Unsupported Boot Device!
  ");
18f26fdbd   Stefan Roese   spl: Change debug...
246
  #endif
8cf686e19   Aneesh V   omap: add MMC and...
247
  		hang();
8cf686e19   Aneesh V   omap: add MMC and...
248
  	}
9ea5c6efd   Simon Schwarz   omap-common: reor...
249
  	switch (spl_image.os) {
8cf686e19   Aneesh V   omap: add MMC and...
250
251
252
  	case IH_OS_U_BOOT:
  		debug("Jumping to U-Boot
  ");
8cf686e19   Aneesh V   omap: add MMC and...
253
  		break;
379c19ab7   Simon Schwarz   omap-common/spl: ...
254
255
256
257
258
259
  #ifdef CONFIG_SPL_OS_BOOT
  	case IH_OS_LINUX:
  		debug("Jumping to Linux
  ");
  		spl_board_prepare_for_linux();
  		jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR);
379c19ab7   Simon Schwarz   omap-common/spl: ...
260
  #endif
8cf686e19   Aneesh V   omap: add MMC and...
261
  	default:
421209818   Tom Rini   SPL: Rework how w...
262
263
  		debug("Unsupported OS image.. Jumping nevertheless..
  ");
8cf686e19   Aneesh V   omap: add MMC and...
264
  	}
fb4f5e7c9   Simon Glass   dm: spl: Make sim...
265
266
267
268
269
  #if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
  	debug("SPL malloc() used %#lx bytes (%ld KB)
  ", gd->malloc_ptr,
  	      gd->malloc_ptr / 1024);
  #endif
a759f1e0d   Allen Martin   SPL: make jump_to...
270
  	jump_to_image_no_args(&spl_image);
bcae72116   Aneesh V   omap: add basic S...
271
  }
6507f133f   Tom Rini   SPL: Create arch/...
272
273
274
275
  /*
   * This requires UART clocks to be enabled.  In order for this to work the
   * caller must ensure that the gd pointer is valid.
   */
bcae72116   Aneesh V   omap: add basic S...
276
277
  void preloader_console_init(void)
  {
bcae72116   Aneesh V   omap: add basic S...
278
  	gd->bd = &bdata;
bcae72116   Aneesh V   omap: add basic S...
279
  	gd->baudrate = CONFIG_BAUDRATE;
bcae72116   Aneesh V   omap: add basic S...
280
  	serial_init();		/* serial communications setup */
b88befa55   Ilya Yanok   omap/spl: actuall...
281
  	gd->have_console = 1;
026b2fe32   Tom Rini   ARM: SPL: Clean u...
282
283
284
285
  	puts("
  U-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
  			U_BOOT_TIME ")
  ");
861a86f46   Tom Rini   omap-common: SPL:...
286
287
288
  #ifdef CONFIG_SPL_DISPLAY_PRINT
  	spl_display_print();
  #endif
cc3f70584   Tom Rini   OMAP3 SPL: Provid...
289
  }
db910353a   Simon Glass   arm: spl: Allow b...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  
  /**
   * spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
   *
   * Sometimes board_init_f() runs with a stack in SRAM but we want to use SDRAM
   * for the main board_init_r() execution. This is typically because we need
   * more stack space for things like the MMC sub-system.
   *
   * This function calculates the stack position, copies the global_data into
   * place and returns the new stack position. The caller is responsible for
   * setting up the sp register.
   *
   * @return new stack location, or 0 to use the same stack
   */
  ulong spl_relocate_stack_gd(void)
  {
  #ifdef CONFIG_SPL_STACK_R
  	gd_t *new_gd;
  	ulong ptr;
  
  	/* Get stack position: use 8-byte alignment for ABI compliance */
  	ptr = CONFIG_SPL_STACK_R - sizeof(gd_t);
  	ptr &= ~7;
  	new_gd = (gd_t *)ptr;
  	memcpy(new_gd, (void *)gd, sizeof(gd_t));
  	gd = new_gd;
  
  	/* Clear the BSS. */
  	memset(__bss_start, 0, __bss_end - __bss_start);
  
  	return ptr;
  #else
  	return 0;
  #endif
  }