~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 44f32f114e756e7a7fa3876886e5f9cc8788dfd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * (C) Copyright 2011-2012
 * Pali Rohár <pali@kernel.org>
 */

#include <config.h>
#include <linux/linkage.h>

kernoffs:		/* offset of kernel image from this address */
	.word . - CONFIG_TEXT_BASE - KERNEL_OFFSET

kernaddr:		/* address of kernel after copying */
	.word KERNEL_ADDRESS

kernsize:		/* maximal size of kernel image */
	.word KERNEL_MAXSIZE

imagesize:		/* maximal size of image */
	.word IMAGE_MAXSIZE

ih_magic:		/* IH_MAGIC in big endian from include/image.h */
	.word 0x56190527

z_magic:		/* LINUX_ARM_ZIMAGE_MAGIC */
	.word 0x016f2818

/*
 * Routine: save_boot_params (called after reset from start.S)
 * Description: Copy attached kernel to address KERNEL_ADDRESS
 */

ENTRY(save_boot_params)

/*
 * Copy valid attached kernel to absolute address KERNEL_ADDRESS
 *
 * Nokia X-Loader is loading secondary image to address 0x80400000.
 * NOLO is loading boot image to random place, so it doesn't really
 * matter what is set in CONFIG_TEXT_BASE. We have to detect
 * KERNEL_OFFSET from the current execution address and copy it to
 * absolute address KERNEL_ADDRESS.
 *
 * Note that U-Boot has to be compiled with CONFIG_POSITION_INDEPENDENT
 * because it is loaded at random address and not to the fixed address
 * (CONFIG_TEXT_BASE).
 */

	/* r0 - start of kernel before */
	adr	r0, kernoffs	/* r0 - current address of kernoffs section */
	ldr	r1, kernoffs	/* r1 - offset of kernel image from kernoffs section */
	sub	r0, r0, r1

	/* r3 - start of kernel after */
	ldr	r3, kernaddr

	/* r2 - end of kernel after */
	ldr	r1, kernsize
	add	r2, r3, r1

	/* r1 - end of kernel before */
	add	r1, r0, r1

	/* remove header in target kernel */
	mov	r5, #0
	str	r5, [r3]	/* remove 4 bytes header of kernel uImage */
	str	r5, [r3, #36]	/* remove 4 bytes header of kernel zImage */

	/* check for valid kernel uImage */
	ldr	r4, [r0]	/* r4 - 4 bytes header of kernel */
	ldr	r5, ih_magic	/* r5 - IH_MAGIC */
	cmp	r4, r5
	beq	copy_kernel_loop

	/* check for valid kernel zImage */
	ldr	r4, [r0, #36]	/* r4 - 4 bytes header of kernel at offset 36 */
	ldr	r5, z_magic	/* r5 - LINUX_ARM_ZIMAGE_MAGIC */
	cmp	r4, r5
	bne	skip_copy	/* skip if invalid image */

copy_kernel_loop:
	ldmdb	r1!, {r3 - r10}
	stmdb	r2!, {r3 - r10}
	cmp	r1, r0
	bhi	copy_kernel_loop

	/* remove header in source kernel image */
	mov	r5, #0
	str	r5, [r0]	/* remove 4 bytes header of kernel uImage */
	str	r5, [r0, #36]	/* remove 4 bytes header of kernel zImage */

skip_copy:

	/* Returns */
	b	save_boot_params_ret

ENDPROC(save_boot_params)