All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: u-boot@lists.denx.de
Subject: [PATCH 2/5] Nokia RX-51: Use U-Boot generic position independent code
Date: Thu, 11 Aug 2022 22:27:22 +0200	[thread overview]
Message-ID: <20220811202725.24752-2-pali@kernel.org> (raw)
In-Reply-To: <20220811202725.24752-1-pali@kernel.org>

Switch from custom board specific fixup/copy code to U-Boot generic
position independent code provided by config option POSITION_INDEPENDENT.

This also slightly decrease size of u-boot.bin binary (by 52 bytes). Note
that option POSITION_INDEPENDENT increase size but not more than custom
board fixup/copy code which is being deleted (as it is not needed anymore).

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 arch/arm/mach-omap2/omap3/Kconfig |   1 +
 board/nokia/rx51/lowlevel_init.S  | 127 ++++--------------------------
 configs/nokia_rx51_defconfig      |   1 -
 3 files changed, 16 insertions(+), 113 deletions(-)

diff --git a/arch/arm/mach-omap2/omap3/Kconfig b/arch/arm/mach-omap2/omap3/Kconfig
index 81c898b66e34..18574ab2b2ea 100644
--- a/arch/arm/mach-omap2/omap3/Kconfig
+++ b/arch/arm/mach-omap2/omap3/Kconfig
@@ -107,6 +107,7 @@ config TARGET_OMAP3_LOGIC
 
 config TARGET_NOKIA_RX51
 	bool "Nokia RX51"
+	select POSITION_INDEPENDENT
 
 config TARGET_TAO3530
 	bool "TAO3530"
diff --git a/board/nokia/rx51/lowlevel_init.S b/board/nokia/rx51/lowlevel_init.S
index 632595f83785..dd3c830cc2e2 100644
--- a/board/nokia/rx51/lowlevel_init.S
+++ b/board/nokia/rx51/lowlevel_init.S
@@ -33,16 +33,24 @@ z_magic:		/* LINUX_ARM_ZIMAGE_MAGIC */
 /*
  * Routine: save_boot_params (called after reset from start.S)
  * Description: Copy attached kernel to address KERNEL_ADDRESS
- *              Copy u-boot to address CONFIG_SYS_TEXT_BASE
- *              Return to copied u-boot address
  */
 
 .global save_boot_params
 save_boot_params:
-	/* Get return address */
-	ldr	lr, =save_boot_params_ret
 
-/* Copy valid attached kernel to address KERNEL_ADDRESS */
+/*
+ * 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_SYS_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_SYS_TEXT_BASE).
+ */
 
 copy_kernel_start:
 	adr	r0, relocaddr	/* r0 - address of section relocaddr */
@@ -100,110 +108,5 @@ copy_kernel_end:
 	str	r5, [r0]	/* remove 4 bytes header of kernel uImage */
 	str	r5, [r0, #36]	/* remove 4 bytes header of kernel zImage */
 
-
-/* Fix u-boot code */
-
-fix_start:
-	adr	r0, relocaddr	/* r0 - address of section relocaddr */
-	ldr	r1, relocaddr	/* r1 - address of relocaddr after relocation */
-	cmp	r0, r1
-
-	beq	copy_uboot_end	/* skip if u-boot is on correct address */
-
-	/* r5 - calculated offset */
-	subhi	r5, r0, r1
-	sublo	r5, r1, r0
-
-	/* r6 - maximal u-boot size */
-	ldr	r6, imagesize
-
-	/* r1 - start of u-boot after */
-	ldr	r1, startaddr
-
-	/* r0 - start of u-boot before */
-	addhi	r0, r1, r5
-	sublo	r0, r1, r5
-
-	/* check if we need to move uboot copy code before calling it */
-	cmp	r5, r6
-	bhi	copy_uboot_start /* now coping u-boot code directly is safe */
-
-
-copy_code_start:
-	/* r0 - start of u-boot before */
-	/* r1 - start of u-boot after */
-	/* r6 - maximal u-boot size */
-
-	/* r7 - maximal kernel size */
-	ldr	r7, kernsize
-
-	/* r4 - end of kernel before */
-	add	r4, r0, r6
-	add	r4, r4, r7
-
-	/* r5 - end of u-boot after */
-	ldr	r5, startaddr
-	add	r5, r5, r6
-
-	/* r2 - start of loop code after */
-	cmp	r4, r5		/* higher address (r4 or r5) */
-	movhs	r2, r4
-	movlo	r2, r5
-
-	/* r3 - end of loop code before */
-	adr	r3, end
-
-	/* r4 - end of loop code after */
-	adr	r4, copy_uboot_start
-	sub	r4, r3, r4
-	add	r4, r2, r4
-
-copy_code_loop:
-	ldmdb	r3!, {r7 - r10}
-	stmdb	r4!, {r7 - r10}
-	cmp	r4, r2
-	bhi	copy_code_loop
-
-copy_code_end:
-	mov	pc, r2
-
-
-/*
- * Copy u-boot to address CONFIG_SYS_TEXT_BASE
- *
- * Nokia X-Loader loading secondary image to address 0x80400000
- * NOLO loading boot image to random place, so it doesn't really
- * matter what is set in CONFIG_SYS_TEXT_BASE. We have to copy
- * u-boot to CONFIG_SYS_TEXT_BASE address.
- */
-
-copy_uboot_start:
-	/* r0 - start of u-boot before */
-	/* r1 - start of u-boot after */
-	/* r6 - maximal u-boot size */
-
-	/* r2 - end of u-boot after */
-	add	r2, r1, r6
-
-	/* condition for copying from left to right */
-	cmp	r0, r1
-	addlo	r1, r0, r6	/* r1 - end of u-boot before */
-	blo	copy_uboot_loop_right
-
-copy_uboot_loop_left:
-	ldmia	r0!, {r3 - r10}
-	stmia	r1!, {r3 - r10}
-	cmp	r1, r2
-	blo	copy_uboot_loop_left
-	b	copy_uboot_end
-
-copy_uboot_loop_right:
-	ldmdb	r1!, {r3 - r10}
-	stmdb	r2!, {r3 - r10}
-	cmp	r1, r0
-	bhi	copy_uboot_loop_right
-
-copy_uboot_end:
-	bx	lr
-
-end:
+	/* Returns */
+	b	save_boot_params_ret
diff --git a/configs/nokia_rx51_defconfig b/configs/nokia_rx51_defconfig
index 309cf28269c1..3365f7ae58df 100644
--- a/configs/nokia_rx51_defconfig
+++ b/configs/nokia_rx51_defconfig
@@ -9,7 +9,6 @@ CONFIG_INITRD_TAG=y
 CONFIG_REVISION_TAG=y
 CONFIG_STATIC_MACH_TYPE=y
 CONFIG_MACH_TYPE=1955
-CONFIG_SYS_TEXT_BASE=0x80008000
 CONFIG_SYS_MALLOC_LEN=0xc0000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_TARGET_NOKIA_RX51=y
-- 
2.20.1


  reply	other threads:[~2022-08-11 20:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 20:27 [PATCH 1/5] Nokia RX-51: Fix invalidating zImage kernel format Pali Rohár
2022-08-11 20:27 ` Pali Rohár [this message]
2022-08-20 23:01   ` [PATCH 2/5] Nokia RX-51: Use U-Boot generic position independent code Tom Rini
2022-08-11 20:27 ` [PATCH 3/5] Nokia RX-51: Simplify copy kernel code Pali Rohár
2022-08-20 23:01   ` Tom Rini
2022-08-11 20:27 ` [PATCH 4/5] Nokia RX-51: Simplify calculation of attached kernel image address Pali Rohár
2022-08-20 23:01   ` Tom Rini
2022-08-11 20:27 ` [PATCH 5/5] Nokia RX-51: Move board required options from defconfig to Kconfig Pali Rohár
2022-08-20 23:01   ` Tom Rini
2022-08-20 23:01 ` [PATCH 1/5] Nokia RX-51: Fix invalidating zImage kernel format Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220811202725.24752-2-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.