Skip to contentSkip to conversation

riscv: ax25: bypass malloc when spl fit boots from ram

PATCH Superseded Rick Chen 3 participants 3 messages Jan 3, 2023 – Jan 4, 2023 RISC-V

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Rick Chen

author
#0 lore raw

PATCH v2 1/1 riscv: ax25: bypass malloc when spl fit boots from ram

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.

---
Changes in v2
- Move spl.c to board level instead of arch level

---
 arch/riscv/cpu/ax25/Makefile |  1 +
 arch/riscv/cpu/ax25/spl.c    | 31 +++++++++++++++++++++++++++++++
 arch/riscv/lib/memcpy.S      |  2 ++
 3 files changed, 34 insertions(+)
 create mode 100644 arch/riscv/cpu/ax25/spl.c
arch/riscv/cpu/ax25/Makefile +1 -0
index 318baccb09..f1c21eadd4 100644
@@ -5,3 +5,4 @@
 
 obj-y	:= cpu.o
 obj-y	+= cache.o
+obj-y += spl.o
arch/riscv/cpu/ax25/spl.c new file +31 -0
new file mode 100644
index 0000000000..6bf357d26d
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Andes Technology Corporation
+ * Rick Chen, Andes Technology Corporation <[email protected]>
+ */
+#include <common.h>
+#include <cpu_func.h>
+#include <hang.h>
+#include <init.h>
+#include <log.h>
+#include <spl.h>
+#include <asm/global_data.h>
+#include <asm/system.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if CONFIG_IS_ENABLED(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
arch/riscv/lib/memcpy.S +2 -0
index 00672c19ad..9884077c93 100644
@@ -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:
Signature · 1 line
2.17.1
#1 lore raw

Hi Rick,

Quoted 7 lines · Rick Chen

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.

Quoted 8 lines

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.

Starting a paragraph with "also" is a good indication that this should be split into two separate patches.

Quoted 16 lines

---
Changes in v2
- Move spl.c to board level instead of arch level

---
 arch/riscv/cpu/ax25/Makefile |  1 +
 arch/riscv/cpu/ax25/spl.c    | 31 +++++++++++++++++++++++++++++++
 arch/riscv/lib/memcpy.S      |  2 ++
 3 files changed, 34 insertions(+)
 create mode 100644 arch/riscv/cpu/ax25/spl.c
arch/riscv/cpu/ax25/Makefile +0 -0
index 318baccb09..f1c21eadd4 100644

arch/riscv/cpu/ax25/Makefile line 8

Quoted 4 lines
arch/riscv/cpu/ax25/Makefile +1 -0
@@ -5,3 +5,4 @@
 
 obj-y	:= cpu.o
 obj-y	+= cache.o
+obj-y += spl.o

nit: alignment

Quoted 25 lines
arch/riscv/cpu/ax25/spl.c new file +19 -0
new file mode 100644
index 0000000000..6bf357d26d
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Andes Technology Corporation
+ * Rick Chen, Andes Technology Corporation <[email protected]>
+ */
+#include <common.h>
+#include <cpu_func.h>
+#include <hang.h>
+#include <init.h>
+#include <log.h>
+#include <spl.h>
+#include <asm/global_data.h>
+#include <asm/system.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if CONFIG_IS_ENABLED(RAM_SUPPORT)
+struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
+{

arch/riscv/cpu/ax25/spl.c line 29

Quoted 10 lines
arch/riscv/cpu/ax25/spl.c new file +10 -0
+	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;

nit: this could all be one line

Regards,
Samuel

Quoted 22 lines
arch/riscv/cpu/ax25/spl.c new file +2 -0
+}
+#endif
arch/riscv/lib/memcpy.S +2 -0
index 00672c19ad..9884077c93 100644
@@ -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:
#2 lore raw
Quoted 15 lines

Hi Rick,

Quoted 12 lines · Rick Chen

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.

Quoted 6 lines
Quoted 3 lines

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

Starting a paragraph with "also" is a good indication that this should be split into two separate patches.

OK, I will separate it to another patch.

Quoted 18 lines
Quoted 18 lines

---
Changes in v2
- Move spl.c to board level instead of arch level

---
 arch/riscv/cpu/ax25/Makefile |  1 +
 arch/riscv/cpu/ax25/spl.c    | 31 +++++++++++++++++++++++++++++++
 arch/riscv/lib/memcpy.S      |  2 ++
 3 files changed, 34 insertions(+)
 create mode 100644 arch/riscv/cpu/ax25/spl.c
arch/riscv/cpu/ax25/Makefile +0 -0
index 318baccb09..f1c21eadd4 100644
@@ -5,3 +5,4 @@
 
Quoted 5 lines

arch/riscv/cpu/ax25/Makefile line 8

Quoted 3 lines
arch/riscv/cpu/ax25/Makefile +1 -0
 obj-y        := cpu.o
 obj-y        += cache.o
+obj-y += spl.o

nit: alignment

OK, I will fix it.

Quoted 30 lines
Quoted 30 lines
arch/riscv/cpu/ax25/spl.c new file +23 -0
new file mode 100644
index 0000000000..6bf357d26d
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Andes Technology Corporation
+ * Rick Chen, Andes Technology Corporation <[email protected]>
+ */
+#include <common.h>
+#include <cpu_func.h>
+#include <hang.h>
+#include <init.h>
+#include <log.h>
+#include <spl.h>
+#include <asm/global_data.h>
+#include <asm/system.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if CONFIG_IS_ENABLED(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)
Quoted 8 lines

arch/riscv/cpu/ax25/spl.c line 29

Quoted 6 lines
arch/riscv/cpu/ax25/spl.c new file +6 -0
+{
+     void *buf;
+
+     buf = spl_get_load_buffer(0, sectors * bl_len);
+
+     return buf;

nit: this could all be one line

OK, I will refine it.

B,R,
Rick

Quoted 27 lines

Regards,
Samuel

Quoted 22 lines
arch/riscv/cpu/ax25/spl.c new file +2 -0
+}
+#endif
arch/riscv/lib/memcpy.S +2 -0
index 00672c19ad..9884077c93 100644
@@ -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: