blob: 930052ea60f259201a0ebaa34bdd3c474f7abf0e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Pali Roháred407be2012-10-29 07:54:01 +00002/*
3 * (C) Copyright 2011-2012
Pali Rohár53086652020-04-01 00:35:08 +02004 * Pali Rohár <pali@kernel.org>
Pali Roháred407be2012-10-29 07:54:01 +00005 */
6
7#include <config.h>
8
Pali Rohár0ba6ce42022-08-11 22:27:24 +02009kernoffs: /* offset of kernel image from this address */
Simon Glass98463902022-10-20 18:22:39 -060010 .word . - CONFIG_TEXT_BASE - KERNEL_OFFSET
Pali Roháred407be2012-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áred407be2012-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árcc434fc2021-06-18 15:27:03 +020024z_magic: /* LINUX_ARM_ZIMAGE_MAGIC */
25 .word 0x016f2818
26
Pali Roháred407be2012-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áred407be2012-10-29 07:54:01 +000030 */
31
32.global save_boot_params
33save_boot_params:
Pali Roháred407be2012-10-29 07:54:01 +000034
Pali Rohárc5be5f62022-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 Glass98463902022-10-20 18:22:39 -060040 * matter what is set in CONFIG_TEXT_BASE. We have to detect
Pali Rohárc5be5f62022-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 Glass98463902022-10-20 18:22:39 -060046 * (CONFIG_TEXT_BASE).
Pali Rohárc5be5f62022-08-11 22:27:22 +020047 */
Pali Roháred407be2012-10-29 07:54:01 +000048
Pali Roháred407be2012-10-29 07:54:01 +000049 /* r0 - start of kernel before */
Pali Rohár0ba6ce42022-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ár892759f2022-10-09 21:37:13 +020052 sub r0, r0, r1
Pali Roháred407be2012-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ár7c4ad982022-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áred407be2012-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árcc434fc2021-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ár5c9bf1d2022-09-04 03:28:59 +020079 bne skip_copy /* skip if invalid image */
Pali Roháred407be2012-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ár7c4ad982022-08-11 22:27:21 +020087 /* remove header in source kernel image */
Pali Roháred407be2012-10-29 07:54:01 +000088 mov r5, #0
Pali Rohárcc434fc2021-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áred407be2012-10-29 07:54:01 +000091
Pali Rohár5c9bf1d2022-09-04 03:28:59 +020092skip_copy:
93
Pali Rohárc5be5f62022-08-11 22:27:22 +020094 /* Returns */
95 b save_boot_params_ret