1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright 2017 Theobroma Systems Design und Consulting GmbH 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun /* 8*4882a593Smuzhiyun * Execution starts on the instruction following this 4-byte header 9*4882a593Smuzhiyun * (containing the magic 'RK30', 'RK31', 'RK32' or 'RK33'). This 10*4882a593Smuzhiyun * magic constant will be written into the final image by the rkimage 11*4882a593Smuzhiyun * tool, but we need to reserve space for it here. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * To make life easier for everyone, we build the SPL binary with 14*4882a593Smuzhiyun * space for this 4-byte header already included in the binary. 15*4882a593Smuzhiyun */ 16*4882a593Smuzhiyun #ifdef CONFIG_SPL_BUILD 17*4882a593Smuzhiyun /* 18*4882a593Smuzhiyun * We need to add 4 bytes of space for the 'RK33' at the 19*4882a593Smuzhiyun * beginning of the executable. However, as we want to keep 20*4882a593Smuzhiyun * this generic and make it applicable to builds that are like 21*4882a593Smuzhiyun * the RK3368 (TPL needs this, SPL doesn't) or the RK3399 (no 22*4882a593Smuzhiyun * TPL, but extra space needed in the SPL), we simply insert 23*4882a593Smuzhiyun * a branch-to-next-instruction-word with the expectation that 24*4882a593Smuzhiyun * the first one may be overwritten, if this is the first stage 25*4882a593Smuzhiyun * contained in the final image created with mkimage)... 26*4882a593Smuzhiyun */ 27*4882a593Smuzhiyun b 1f /* if overwritten, entry-address is at the next word */ 28*4882a593Smuzhiyun 1: 29*4882a593Smuzhiyun #endif 30*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(ROCKCHIP_EARLYRETURN_TO_BROM) 31*4882a593Smuzhiyun adr r3, entry_counter 32*4882a593Smuzhiyun ldr r0, [r3] 33*4882a593Smuzhiyun cmp r0, #1 /* check if entry_counter == 1 */ 34*4882a593Smuzhiyun beq reset /* regular bootup */ 35*4882a593Smuzhiyun add r0, #1 36*4882a593Smuzhiyun str r0, [r3] /* increment the entry_counter in memory */ 37*4882a593Smuzhiyun mov r0, #0 /* return 0 to the BROM to signal 'OK' */ 38*4882a593Smuzhiyun bx lr /* return control to the BROM */ 39*4882a593Smuzhiyun entry_counter: 40*4882a593Smuzhiyun .word 0 41*4882a593Smuzhiyun #endif 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun #if (defined(CONFIG_SPL_BUILD) || defined(CONFIG_ARM64)) 44*4882a593Smuzhiyun /* U-Boot proper of armv7 do not need this */ 45*4882a593Smuzhiyun #if CONFIG_IS_ENABLED(TINY_FRAMEWORK) 46*4882a593Smuzhiyun #if !defined(CONFIG_ARM64) 47*4882a593Smuzhiyun /* 48*4882a593Smuzhiyun * For armv7, the addr '_start' will check by u-boot-tpl.lds file. 49*4882a593Smuzhiyun */ 50*4882a593Smuzhiyun _start: 51*4882a593Smuzhiyun #endif 52*4882a593Smuzhiyun /* Allow the board to save important registers */ 53*4882a593Smuzhiyun b save_boot_params 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun .type save_boot_params_ret, % function 56*4882a593Smuzhiyun .globl save_boot_params_ret 57*4882a593Smuzhiyun save_boot_params_ret: 58*4882a593Smuzhiyun /* Init gd as null */ 59*4882a593Smuzhiyun #ifdef CONFIG_ARM64 60*4882a593Smuzhiyun mov x18, #0 61*4882a593Smuzhiyun #else 62*4882a593Smuzhiyun mov r9, #0 63*4882a593Smuzhiyun #endif 64*4882a593Smuzhiyun b board_init_f 65*4882a593Smuzhiyun #else 66*4882a593Smuzhiyun b reset 67*4882a593Smuzhiyun #endif 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun #endif 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun #if !defined(CONFIG_ARM64) && !CONFIG_IS_ENABLED(TINY_FRAMEWORK) 72*4882a593Smuzhiyun /* 73*4882a593Smuzhiyun * For armv7, the addr '_start' will used as vector start address 74*4882a593Smuzhiyun * and write to VBAR register, which needs to aligned to 0x20. 75*4882a593Smuzhiyun */ 76*4882a593Smuzhiyun .align(5), 0x0 77*4882a593Smuzhiyun _start: 78*4882a593Smuzhiyun ARM_VECTORS 79*4882a593Smuzhiyun #endif 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun #if !defined(CONFIG_TPL_BUILD) && defined(CONFIG_SPL_BUILD) && (CONFIG_ROCKCHIP_SPL_RESERVE_IRAM > 0) 82*4882a593Smuzhiyun .space CONFIG_ROCKCHIP_SPL_RESERVE_IRAM /* space for the ATF data */ 83*4882a593Smuzhiyun #endif 84