blob: 930052ea60f259201a0ebaa34bdd3c474f7abf0e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Pali Rohár248ef0a2012-10-29 07:54:01 +00002/*
3 * (C) Copyright 2011-2012
Pali Rohár10a953d2020-04-01 00:35:08 +02004 * Pali Rohár <pali@kernel.org>
Pali Rohár248ef0a2012-10-29 07:54:01 +00005 */
6
7#include <config.h>
8
Pali Rohárb043e872022-08-11 22:27:24 +02009kernoffs: /* offset of kernel image from this address */
Simon Glass72cc5382022-10-20 18:22:39 -060010 .word . - CONFIG_TEXT_BASE - KERNEL_OFFSET
Pali Rohár248ef0a2012-10-29 07:54:01 +000011
12kernaddr: /* address of kernel after copying */
13 .word KERNEL_ADDRESS
14
15kernsize: /* maximal size of kernel image */
16 .word KERNEL_MAXSIZE
17
Pali Rohár248ef0a2012-10-29 07:54:01 +000018imagesize: /* maximal size of image */
19 .word IMAGE_MAXSIZE
20
21ih_magic: /* IH_MAGIC in big endian from include/image.h */
22 .word 0x56190527
23
Pali Rohár0a8825c2021-06-18 15:27:03 +020024z_magic: /* LINUX_ARM_ZIMAGE_MAGIC */
25 .word 0x016f2818
26
Pali Rohár248ef0a2012-10-29 07:54:01 +000027/*
28 * Routine: save_boot_params (called after reset from start.S)
29 * Description: Copy attached kernel to address KERNEL_ADDRESS
Pali Rohár248ef0a2012-10-29 07:54:01 +000030 */
31
32.global save_boot_params
33save_boot_params:
Pali Rohár248ef0a2012-10-29 07:54:01 +000034
Pali Rohárc1aec222022-08-11 22:27:22 +020035/*
36 * Copy valid attached kernel to absolute address KERNEL_ADDRESS
37 *
38 * Nokia X-Loader is loading secondary image to address 0x80400000.
39 * NOLO is loading boot image to random place, so it doesn't really
Simon Glass72cc5382022-10-20 18:22:39 -060040 * matter what is set in CONFIG_TEXT_BASE. We have to detect
Pali Rohárc1aec222022-08-11 22:27:22 +020041 * KERNEL_OFFSET from the current execution address and copy it to
42 * absolute address KERNEL_ADDRESS.
43 *
44 * Note that U-Boot has to be compiled with CONFIG_POSITION_INDEPENDENT
45 * because it is loaded at random address and not to the fixed address
Simon Glass72cc5382022-10-20 18:22:39 -060046 * (CONFIG_TEXT_BASE).
Pali Rohárc1aec222022-08-11 22:27:22 +020047 */
Pali Rohár248ef0a2012-10-29 07:54:01 +000048
Pali Rohár248ef0a2012-10-29 07:54:01 +000049 /* r0 - start of kernel before */
Pali Rohárb043e872022-08-11 22:27:24 +020050 adr r0, kernoffs /* r0 - current address of kernoffs section */
51 ldr r1, kernoffs /* r1 - offset of kernel image from kernoffs section */
Pali Rohár0d9083b2022-10-09 21:37:13 +020052 sub r0, r0, r1
Pali Rohár248ef0a2012-10-29 07:54:01 +000053
54 /* r3 - start of kernel after */
55 ldr r3, kernaddr
56
57 /* r2 - end of kernel after */
58 ldr r1, kernsize
59 add r2, r3, r1
60
61 /* r1 - end of kernel before */
62 add r1, r0, r1
63
64 /* remove header in target kernel */
65 mov r5, #0
Pali Rohárf8a6c902022-08-11 22:27:21 +020066 str r5, [r3] /* remove 4 bytes header of kernel uImage */
67 str r5, [r3, #36] /* remove 4 bytes header of kernel zImage */
Pali Rohár248ef0a2012-10-29 07:54:01 +000068
69 /* check for valid kernel uImage */
70 ldr r4, [r0] /* r4 - 4 bytes header of kernel */
71 ldr r5, ih_magic /* r5 - IH_MAGIC */
72 cmp r4, r5
Pali Rohár0a8825c2021-06-18 15:27:03 +020073 beq copy_kernel_loop
74
75 /* check for valid kernel zImage */
76 ldr r4, [r0, #36] /* r4 - 4 bytes header of kernel at offset 36 */
77 ldr r5, z_magic /* r5 - LINUX_ARM_ZIMAGE_MAGIC */
78 cmp r4, r5
Pali Rohára4001fd2022-09-04 03:28:59 +020079 bne skip_copy /* skip if invalid image */
Pali Rohár248ef0a2012-10-29 07:54:01 +000080
81copy_kernel_loop:
82 ldmdb r1!, {r3 - r10}
83 stmdb r2!, {r3 - r10}
84 cmp r1, r0
85 bhi copy_kernel_loop
86
Pali Rohárf8a6c902022-08-11 22:27:21 +020087 /* remove header in source kernel image */
Pali Rohár248ef0a2012-10-29 07:54:01 +000088 mov r5, #0
Pali Rohár0a8825c2021-06-18 15:27:03 +020089 str r5, [r0] /* remove 4 bytes header of kernel uImage */
90 str r5, [r0, #36] /* remove 4 bytes header of kernel zImage */
Pali Rohár248ef0a2012-10-29 07:54:01 +000091
Pali Rohára4001fd2022-09-04 03:28:59 +020092skip_copy:
93
Pali Rohárc1aec222022-08-11 22:27:22 +020094 /* Returns */
95 b save_boot_params_ret