blob: 44f32f114e756e7a7fa3876886e5f9cc8788dfd5 [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>
Pali Rohárbe108c42022-11-24 00:45:00 +01008#include <linux/linkage.h>
Pali Rohár248ef0a2012-10-29 07:54:01 +00009
Pali Rohárb043e872022-08-11 22:27:24 +020010kernoffs: /* offset of kernel image from this address */
Simon Glass72cc5382022-10-20 18:22:39 -060011 .word . - CONFIG_TEXT_BASE - KERNEL_OFFSET
Pali Rohár248ef0a2012-10-29 07:54:01 +000012
13kernaddr: /* address of kernel after copying */
14 .word KERNEL_ADDRESS
15
16kernsize: /* maximal size of kernel image */
17 .word KERNEL_MAXSIZE
18
Pali Rohár248ef0a2012-10-29 07:54:01 +000019imagesize: /* maximal size of image */
20 .word IMAGE_MAXSIZE
21
22ih_magic: /* IH_MAGIC in big endian from include/image.h */
23 .word 0x56190527
24
Pali Rohár0a8825c2021-06-18 15:27:03 +020025z_magic: /* LINUX_ARM_ZIMAGE_MAGIC */
26 .word 0x016f2818
27
Pali Rohár248ef0a2012-10-29 07:54:01 +000028/*
29 * Routine: save_boot_params (called after reset from start.S)
30 * Description: Copy attached kernel to address KERNEL_ADDRESS
Pali Rohár248ef0a2012-10-29 07:54:01 +000031 */
32
Pali Rohárbe108c42022-11-24 00:45:00 +010033ENTRY(save_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
Pali Rohárbe108c42022-11-24 00:45:00 +010096
97ENDPROC(save_boot_params)