blob: c1785bc3f72ff1a05a3914524d5fff4a584a6bca [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 */
10 .word KERNEL_OFFSET - (. - CONFIG_SYS_TEXT_BASE)
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
40 * matter what is set in CONFIG_SYS_TEXT_BASE. We have to detect
41 * 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
46 * (CONFIG_SYS_TEXT_BASE).
47 */
Pali Rohár248ef0a2012-10-29 07:54:01 +000048
49copy_kernel_start:
Pali Rohár248ef0a2012-10-29 07:54:01 +000050 /* r0 - start of kernel before */
Pali Rohárb043e872022-08-11 22:27:24 +020051 adr r0, kernoffs /* r0 - current address of kernoffs section */
52 ldr r1, kernoffs /* r1 - offset of kernel image from kernoffs section */
Pali Rohár248ef0a2012-10-29 07:54:01 +000053 add r0, r0, r1
54
55 /* r3 - start of kernel after */
56 ldr r3, kernaddr
57
58 /* r2 - end of kernel after */
59 ldr r1, kernsize
60 add r2, r3, r1
61
62 /* r1 - end of kernel before */
63 add r1, r0, r1
64
65 /* remove header in target kernel */
66 mov r5, #0
Pali Rohárf8a6c902022-08-11 22:27:21 +020067 str r5, [r3] /* remove 4 bytes header of kernel uImage */
68 str r5, [r3, #36] /* remove 4 bytes header of kernel zImage */
Pali Rohár248ef0a2012-10-29 07:54:01 +000069
70 /* check for valid kernel uImage */
71 ldr r4, [r0] /* r4 - 4 bytes header of kernel */
72 ldr r5, ih_magic /* r5 - IH_MAGIC */
73 cmp r4, r5
Pali Rohár0a8825c2021-06-18 15:27:03 +020074 beq copy_kernel_loop
75
76 /* check for valid kernel zImage */
77 ldr r4, [r0, #36] /* r4 - 4 bytes header of kernel at offset 36 */
78 ldr r5, z_magic /* r5 - LINUX_ARM_ZIMAGE_MAGIC */
79 cmp r4, r5
Pali Rohár248ef0a2012-10-29 07:54:01 +000080 bne copy_kernel_end /* skip if invalid image */
81
82copy_kernel_loop:
83 ldmdb r1!, {r3 - r10}
84 stmdb r2!, {r3 - r10}
85 cmp r1, r0
86 bhi copy_kernel_loop
87
88copy_kernel_end:
Pali Rohárf8a6c902022-08-11 22:27:21 +020089
90 /* remove header in source kernel image */
Pali Rohár248ef0a2012-10-29 07:54:01 +000091 mov r5, #0
Pali Rohár0a8825c2021-06-18 15:27:03 +020092 str r5, [r0] /* remove 4 bytes header of kernel uImage */
93 str r5, [r0, #36] /* remove 4 bytes header of kernel zImage */
Pali Rohár248ef0a2012-10-29 07:54:01 +000094
Pali Rohárc1aec222022-08-11 22:27:22 +020095 /* Returns */
96 b save_boot_params_ret