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: 58*b9756a5bSKever Yang /* Init gd as null */ 59*b9756a5bSKever Yang #ifdef CONFIG_ARM64 60*b9756a5bSKever Yang mov x18, #0 61*b9756a5bSKever Yang #else 62*b9756a5bSKever Yang mov r9, #0 63*b9756a5bSKever Yang #endif 6437e5dcc8SYouMin Chen b board_init_f 6537e5dcc8SYouMin Chen #else 663d54eabcSPhilipp Tomsich b reset 679d33a67dSKever Yang #endif 689d33a67dSKever Yang 6937e5dcc8SYouMin Chen #endif 7037e5dcc8SYouMin Chen 71a3f8c59fSZhihuan He #if !defined(CONFIG_ARM64) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK) 725577f854SKever Yang /* 735577f854SKever Yang * For armv7, the addr '_start' will used as vector start address 745577f854SKever Yang * and write to VBAR register, which needs to aligned to 0x20. 755577f854SKever Yang */ 76dff737c4SPhilipp Tomsich .align(5), 0x0 775577f854SKever Yang _start: 785577f854SKever Yang ARM_VECTORS 795577f854SKever Yang #endif 8082c369d0SKever Yang 81c7b9ee6bSKever Yang #if !defined(CONFIG_TPL_BUILD) && defined(CONFIG_SPL_BUILD) && (CONFIG_ROCKCHIP_SPL_RESERVE_IRAM > 0) 8282c369d0SKever Yang .space CONFIG_ROCKCHIP_SPL_RESERVE_IRAM /* space for the ATF data */ 8382c369d0SKever Yang #endif 84