public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] riscv: bypass malloc when spl fit boots from ram
@ 2022-12-22  7:21 Rick Chen
  2022-12-28  2:47 ` Samuel Holland
  0 siblings, 1 reply; 5+ messages in thread
From: Rick Chen @ 2022-12-22  7:21 UTC (permalink / raw)
  To: ycliang, rick, rickchen36; +Cc: u-boot

When fit image boots from ram, the payload will
be prepared in the address of SPL_LOAD_FIT_ADDRESS.
In spl fit generic flow, it will malloc another
memory address and copy whole fit image to this
malloc address.  But it is un-necessary for booting
from RAM.

This patch improves this flow by declare the
board_spl_fit_buffer_addr() to replace the original one.
The larger image size (eq: Kernel Image 10~20MB), it
can save more booting time.

Also enhance memcpy function by checking source and
destination address. If they are the same address,
just return and don't copy data anymore.

Signed-off-by: Rick Chen <rick@andestech.com>
---
 arch/riscv/lib/memcpy.S |  2 ++
 arch/riscv/lib/spl.c    | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/arch/riscv/lib/memcpy.S b/arch/riscv/lib/memcpy.S
index 00672c19ad..9884077c93 100644
--- a/arch/riscv/lib/memcpy.S
+++ b/arch/riscv/lib/memcpy.S
@@ -9,6 +9,7 @@
 /* void *memcpy(void *, const void *, size_t) */
 ENTRY(__memcpy)
 WEAK(memcpy)
+	beq	a0, a1, .copy_end
 	/* Save for return value */
 	mv	t6, a0
 
@@ -121,6 +122,7 @@ WEAK(memcpy)
 2:
 
 	mv	a0, t6
+.copy_end:
 	ret
 
 .Lmisaligned_word_copy:
diff --git a/arch/riscv/lib/spl.c b/arch/riscv/lib/spl.c
index f4d3b67e5d..18f86ee207 100644
--- a/arch/riscv/lib/spl.c
+++ b/arch/riscv/lib/spl.c
@@ -61,3 +61,19 @@ void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 #endif
 	image_entry(gd->arch.boot_hart, fdt_blob);
 }
+
+#ifdef CONFIG_SPL_RAM_SUPPORT
+struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
+{
+	return (void *)(CONFIG_SPL_LOAD_FIT_ADDRESS + offset);
+}
+
+void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len)
+{
+	void *buf;
+
+	buf = spl_get_load_buffer(0, sectors * bl_len);
+
+	return buf;
+}
+#endif
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-28  5:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-22  7:21 [PATCH] riscv: bypass malloc when spl fit boots from ram Rick Chen
2022-12-28  2:47 ` Samuel Holland
2022-12-28  3:22   ` Rick Chen
2022-12-28  4:26     ` Samuel Holland
2022-12-28  5:12       ` Rick Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox