xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-rockchip/boot0.h (revision c7b9ee6b6f206c31475cfd7a6a965be5c07d9331)
13d54eabcSPhilipp Tomsich /*
23d54eabcSPhilipp Tomsich  * Copyright 2017 Theobroma Systems Design und Consulting GmbH
33d54eabcSPhilipp Tomsich  *
43d54eabcSPhilipp Tomsich  * SPDX-License-Identifier:	GPL-2.0+
53d54eabcSPhilipp Tomsich  */
63d54eabcSPhilipp Tomsich 
73d54eabcSPhilipp Tomsich /*
83d54eabcSPhilipp Tomsich  * Execution starts on the instruction following this 4-byte header
95577f854SKever Yang  * (containing the magic 'RK30', 'RK31', 'RK32' or 'RK33').  This
105577f854SKever Yang  * magic constant will be written into the final image by the rkimage
115577f854SKever Yang  * tool, but we need to reserve space for it here.
123d54eabcSPhilipp Tomsich  *
133d54eabcSPhilipp Tomsich  * To make life easier for everyone, we build the SPL binary with
143d54eabcSPhilipp Tomsich  * space for this 4-byte header already included in the binary.
153d54eabcSPhilipp Tomsich  */
163d54eabcSPhilipp Tomsich #ifdef CONFIG_SPL_BUILD
17700f3108SPhilipp Tomsich 	/*
18700f3108SPhilipp Tomsich 	 * We need to add 4 bytes of space for the 'RK33' at the
19700f3108SPhilipp Tomsich 	 * beginning of the executable.	 However, as we want to keep
20700f3108SPhilipp Tomsich 	 * this generic and make it applicable to builds that are like
21700f3108SPhilipp Tomsich 	 * the RK3368 (TPL needs this, SPL doesn't) or the RK3399 (no
22dff737c4SPhilipp Tomsich 	 * TPL, but extra space needed in the SPL), we simply insert
23dff737c4SPhilipp Tomsich 	 * a branch-to-next-instruction-word with the expectation that
24dff737c4SPhilipp Tomsich 	 * the first one may be overwritten, if this is the first stage
25dff737c4SPhilipp Tomsich 	 * contained in the final image created with mkimage)...
26700f3108SPhilipp Tomsich 	 */
27dff737c4SPhilipp Tomsich 	b 1f	 /* if overwritten, entry-address is at the next word */
28dff737c4SPhilipp Tomsich 1:
2982c369d0SKever Yang #endif
30dff737c4SPhilipp Tomsich #if CONFIG_IS_ENABLED(ROCKCHIP_EARLYRETURN_TO_BROM)
31dff737c4SPhilipp Tomsich 	adr     r3, entry_counter
32dff737c4SPhilipp Tomsich 	ldr	r0, [r3]
33dff737c4SPhilipp Tomsich 	cmp	r0, #1           /* check if entry_counter == 1 */
34dff737c4SPhilipp Tomsich 	beq	reset            /* regular bootup */
35dff737c4SPhilipp Tomsich 	add     r0, #1
36dff737c4SPhilipp Tomsich 	str	r0, [r3]         /* increment the entry_counter in memory */
37dff737c4SPhilipp Tomsich 	mov     r0, #0           /* return 0 to the BROM to signal 'OK' */
38dff737c4SPhilipp Tomsich 	bx	lr               /* return control to the BROM */
39dff737c4SPhilipp Tomsich entry_counter:
40dff737c4SPhilipp Tomsich 	.word   0
413d54eabcSPhilipp Tomsich #endif
429d33a67dSKever Yang 
439d33a67dSKever Yang #if (defined(CONFIG_SPL_BUILD) || defined(CONFIG_ARM64))
449d33a67dSKever Yang 	/* U-Boot proper of armv7 do not need this */
45a3f8c59fSZhihuan He #if CONFIG_IS_ENABLED(TINY_FRAMEWORK)
46a3f8c59fSZhihuan He #if !defined(CONFIG_ARM64)
47a3f8c59fSZhihuan He 	/*
48a3f8c59fSZhihuan He 	 * For armv7, the addr '_start' will check by u-boot-tpl.lds file.
49a3f8c59fSZhihuan He 	 */
50a3f8c59fSZhihuan He _start:
51a3f8c59fSZhihuan He #endif
5237e5dcc8SYouMin Chen 	/* Allow the board to save important registers */
5337e5dcc8SYouMin Chen 	b save_boot_params
54a3f8c59fSZhihuan He 
55a3f8c59fSZhihuan He .type   save_boot_params_ret, % function
5637e5dcc8SYouMin Chen .globl	save_boot_params_ret
5737e5dcc8SYouMin Chen save_boot_params_ret:
5837e5dcc8SYouMin Chen 	b board_init_f
5937e5dcc8SYouMin Chen #else
603d54eabcSPhilipp Tomsich 	b reset
619d33a67dSKever Yang #endif
629d33a67dSKever Yang 
6337e5dcc8SYouMin Chen #endif
6437e5dcc8SYouMin Chen 
65a3f8c59fSZhihuan He #if !defined(CONFIG_ARM64) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK)
665577f854SKever Yang 	/*
675577f854SKever Yang 	 * For armv7, the addr '_start' will used as vector start address
685577f854SKever Yang 	 * and write to VBAR register, which needs to aligned to 0x20.
695577f854SKever Yang 	 */
70dff737c4SPhilipp Tomsich 	.align(5), 0x0
715577f854SKever Yang _start:
725577f854SKever Yang 	ARM_VECTORS
735577f854SKever Yang #endif
7482c369d0SKever Yang 
75*c7b9ee6bSKever Yang #if !defined(CONFIG_TPL_BUILD) && defined(CONFIG_SPL_BUILD) && (CONFIG_ROCKCHIP_SPL_RESERVE_IRAM > 0)
7682c369d0SKever Yang 	.space CONFIG_ROCKCHIP_SPL_RESERVE_IRAM	/* space for the ATF data */
7782c369d0SKever Yang #endif
78