All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 14/18] rockchip: back-to-bootrom: replace assembly-implementation with C-code
Date: Tue, 10 Oct 2017 16:21:14 +0200	[thread overview]
Message-ID: <1507645279-25188-15-git-send-email-philipp.tomsich@theobroma-systems.com> (raw)
In-Reply-To: <1507645279-25188-1-git-send-email-philipp.tomsich@theobroma-systems.com>

The back-to-bootrom implementation for Rockchip has always relied on
the stack-pointer being valid on entry, so there was little reason to
have this as an assembly implementation.

This provides a new C-only implementation of save_boot_params and
back_to_bootrom (relying on setjmp/longjmp) and removes the older
assembly-only implementation.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Tested-by: Andy Yan <andy.yan@rock-chips.com>
---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-rockchip/bootrom.h | 27 ++++++++---
 arch/arm/mach-rockchip/Makefile              |  4 +-
 arch/arm/mach-rockchip/bootrom.c             | 52 ++++++++++++++++++++-
 arch/arm/mach-rockchip/save_boot_param.S     | 69 ----------------------------
 4 files changed, 73 insertions(+), 79 deletions(-)
 delete mode 100644 arch/arm/mach-rockchip/save_boot_param.S

diff --git a/arch/arm/include/asm/arch-rockchip/bootrom.h b/arch/arm/include/asm/arch-rockchip/bootrom.h
index 169cc5e..2f61a33 100644
--- a/arch/arm/include/asm/arch-rockchip/bootrom.h
+++ b/arch/arm/include/asm/arch-rockchip/bootrom.h
@@ -1,5 +1,6 @@
 /*
  * (C) Copyright 2017 Heiko Stuebner <heiko@sntech.de>
+ * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
  *
  * SPDX-License-Identifier:	GPL-2.0
  */
@@ -14,15 +15,27 @@
 extern u32 SAVE_SP_ADDR;
 
 /**
- * Hand control back to the bootrom to load another
- * boot stage.
+ * back_to_bootrom() - return to bootrom (for TPL/SPL), passing a
+ *                     result code
+ *
+ * Transfer control back to the Rockchip BROM, restoring necessary
+ * register context and passing a command/result code to the BROM
+ * to instruct its next actions (e.g. continue boot sequence, enter
+ * download mode, ...).
+ *
+ * This function does not return.
  */
-void back_to_bootrom(void);
+enum rockchip_bootrom_cmd {
+	/*
+	 * These can not start at 0, as 0 has a special meaning
+	 * for setjmp().
+	 */
 
-/**
- * Assembler component for the above (do not call this directly)
- */
-void _back_to_bootrom_s(void);
+	BROM_BOOT_NEXTSTAGE = 1,  /* continue boot-sequence */
+	BROM_BOOT_ENTER_DNL,      /* have BROM enter download-mode */
+};
+
+void back_to_bootrom(void);
 
 /**
  * Boot-device identifiers as used by the BROM
diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index daafc8d..b875dfc 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -8,8 +8,8 @@
 # this may have entered from ATF with the stack-pointer pointing to
 # inaccessible/protected memory (and the bootrom-helper assumes that
 # the stack-pointer is valid before switching to the U-Boot stack).
-obj-spl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o
-obj-tpl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o save_boot_param.o
+obj-spl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o
+obj-tpl-$(CONFIG_ROCKCHIP_BROM_HELPER) += bootrom.o
 
 obj-tpl-$(CONFIG_ROCKCHIP_RK3188) += rk3188-board-tpl.o
 obj-tpl-$(CONFIG_ROCKCHIP_RK3288) += rk3288-board-tpl.o
diff --git a/arch/arm/mach-rockchip/bootrom.c b/arch/arm/mach-rockchip/bootrom.c
index 8380e4e..7b9b307 100644
--- a/arch/arm/mach-rockchip/bootrom.c
+++ b/arch/arm/mach-rockchip/bootrom.c
@@ -6,11 +6,61 @@
 
 #include <common.h>
 #include <asm/arch/bootrom.h>
+#include <asm/setjmp.h>
+#include <asm/system.h>
+
+/*
+ * Force the jmp_buf to the data-section, as .bss will not be valid
+ * when save_boot_params is invoked.
+ */
+static jmp_buf brom_ctx __section(".data");
 
 void back_to_bootrom(void)
 {
 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
 	puts("Returning to boot ROM...\n");
 #endif
-	_back_to_bootrom_s();
+	longjmp(brom_ctx, BROM_BOOT_NEXTSTAGE);
+}
+
+/*
+ * All Rockchip BROM implementations enter with a valid stack-pointer,
+ * so this can safely be implemented in C (providing a single
+ * implementation both for ARMv7 and AArch64).
+ */
+int save_boot_params(void)
+{
+	int  ret = setjmp(brom_ctx);
+
+	switch (ret) {
+	case 0:
+		/*
+		 * This is the initial pass through this function
+		 * (i.e. saving the context), setjmp just setup up the
+		 * brom_ctx: transfer back into the startup-code at
+		 * 'save_boot_params_ret' and let the compiler know
+		 * that this will not return.
+		 */
+		save_boot_params_ret();
+		while (true)
+			/* does not return */;
+		break;
+
+	case BROM_BOOT_NEXTSTAGE:
+		/*
+		 * To instruct the BROM to boot the next stage, we
+		 * need to return 0 to it: i.e. we need to rewrite
+		 * the return code once more.
+		 */
+		ret = 0;
+		break;
+
+	default:
+#if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
+		puts("FATAL: unexpected command to back_to_bootrom()\n");
+#endif
+		hang();
+	};
+
+	return ret;
 }
diff --git a/arch/arm/mach-rockchip/save_boot_param.S b/arch/arm/mach-rockchip/save_boot_param.S
deleted file mode 100644
index 50fce20..0000000
--- a/arch/arm/mach-rockchip/save_boot_param.S
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * (C) Copyright 2016 Rockchip Electronics Co., Ltd
- * (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
- *
- * SPDX-License-Identifier:     GPL-2.0+
- */
-
-#include <linux/linkage.h>
-
-#if defined(CONFIG_ARM64)
-.globl	SAVE_SP_ADDR
-SAVE_SP_ADDR:
-	.quad 0
-
-ENTRY(save_boot_params)
-	sub	sp, sp, #0x60
-	stp	x29, x30, [sp, #0x50]
-	stp	x27, x28, [sp, #0x40]
-	stp	x25, x26, [sp, #0x30]
-	stp	x23, x24, [sp, #0x20]
-	stp	x21, x22, [sp, #0x10]
-	stp	x19, x20, [sp, #0]
-	ldr	x8, =SAVE_SP_ADDR
-	mov	x9, sp
-	str	x9, [x8]
-	b	save_boot_params_ret  /* back to my caller */
-ENDPROC(save_boot_params)
-
-.globl _back_to_bootrom_s
-ENTRY(_back_to_bootrom_s)
-	ldr	x0, =SAVE_SP_ADDR
-	ldr	x0, [x0]
-	mov	sp, x0
-	ldp	x29, x30, [sp, #0x50]
-	ldp	x27, x28, [sp, #0x40]
-	ldp	x25, x26, [sp, #0x30]
-	ldp	x23, x24, [sp, #0x20]
-	ldp	x21, x22, [sp, #0x10]
-	ldp	x19, x20, [sp]
-	add	sp, sp, #0x60
-	mov	x0, xzr
-	ret
-ENDPROC(_back_to_bootrom_s)
-#else
-.globl	SAVE_SP_ADDR
-SAVE_SP_ADDR:
-	.word 0
-
-/*
- * void save_boot_params
- *
- * Save sp, lr, r1~r12
- */
-ENTRY(save_boot_params)
-	push	{r1-r12, lr}
-	ldr	r0, =SAVE_SP_ADDR
-	str	sp, [r0]
-	b	save_boot_params_ret		@ back to my caller
-ENDPROC(save_boot_params)
-
-
-.globl _back_to_bootrom_s
-ENTRY(_back_to_bootrom_s)
-	ldr	r0, =SAVE_SP_ADDR
-	ldr	sp, [r0]
-	mov	r0, #0
-	pop	{r1-r12, pc}
-ENDPROC(_back_to_bootrom_s)
-#endif
-- 
2.1.4

  parent reply	other threads:[~2017-10-10 14:21 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 14:21 [U-Boot] [PATCH v5 00/18] rockchip: back-to-bootrom: replace assembly-implementation with C-code Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 01/18] arm: boot0 hook: move boot0 hook before '_start' Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 02/18] rockchip: boot0: align to 0x20 for armv7 '_start' Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-11-09 12:59   ` [U-Boot] [PATCH v5 " Andy Yan
2017-11-09 13:03     ` Dr. Philipp Tomsich
2017-11-10  3:43       ` Kever Yang
2017-10-10 14:21 ` [U-Boot] [PATCH v5 03/18] rockchip: enable boot0-hook for all Rockchip SoCs Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 04/18] rockchip: mkimage: use spl_boot0 " Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 05/18] rockchip: rk3288: use aligned address for SPL_TEXT_BASE Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 06/18] rockchip: rk3036: " Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 07/18] socfpga: boot0 hook: adjust to unified boot0 semantics Philipp Tomsich
2017-11-06 17:26   ` Dr. Philipp Tomsich
2017-11-06 17:54     ` Marek Vasut
2017-11-06 17:55       ` Dr. Philipp Tomsich
2017-11-06 17:57         ` Marek Vasut
2017-11-07  4:46           ` Chee, Tien Fong
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 08/18] bcm235xx: " Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 09/18] bcm281xx: " Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 10/18] rockchip: boot0 hook: support early return for RK3188/RK3066-style BROM Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 11/18] arm: make save_boot_params_ret prototype visible for AArch64 Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 12/18] arm: mark save_boot_params_ret as a function Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 13/18] arm: provide a PCS-compliant setjmp implementation Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` Philipp Tomsich [this message]
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, 14/18] rockchip: back-to-bootrom: replace assembly-implementation with C-code Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 15/18] rockchip: rk3188: use boot0 hook to load up SPL in 2 steps Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 16/18] rockchip: back-to-bootrom: allow passing a cmd to the bootrom Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 17/18] rockchip: rk3188: move CONFIG_SPL_* entries from rk3188_common.h to Kconfig Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-10 14:21 ` [U-Boot] [PATCH v5 18/18] rockchip: mkimage: remove unused code-paths (spl_boot0 is now implied) Philipp Tomsich
2017-11-07 14:18   ` [U-Boot] [U-Boot, v5, " Philipp Tomsich
2017-10-11 13:07 ` [U-Boot] [PATCH v5 00/18] rockchip: back-to-bootrom: replace assembly-implementation with C-code Heiko Stuebner

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=1507645279-25188-15-git-send-email-philipp.tomsich@theobroma-systems.com \
    --to=philipp.tomsich@theobroma-systems.com \
    --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.