In preparation for the new common PBL entry code that will make
use of relocate_to_adr_full(), implement it for RISC-V as on ARM.

Unlike relocate_to_adr(), which stops copying at __bss_start, the _full
variant copies up to __image_end, so barebox proper can still be
decompressed after the move.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 arch/riscv/include/asm/reloc.h |  1 +
 arch/riscv/lib/setupc.S        | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/riscv/include/asm/reloc.h b/arch/riscv/include/asm/reloc.h
index 9a59326cad27..6b921ff702d7 100644
--- a/arch/riscv/include/asm/reloc.h
+++ b/arch/riscv/include/asm/reloc.h
@@ -7,6 +7,7 @@ unsigned long get_runtime_offset(void);
 
 void relocate_to_current_adr(void);
 void relocate_to_adr(unsigned long target);
+void relocate_to_adr_full(unsigned long target);
 
 void setup_c(void);
 
diff --git a/arch/riscv/lib/setupc.S b/arch/riscv/lib/setupc.S
index 938c78350c7c..68924f2f94df 100644
--- a/arch/riscv/lib/setupc.S
+++ b/arch/riscv/lib/setupc.S
@@ -39,13 +39,22 @@ bss_cleared:
 
 /*
  * void relocate_to_adr(unsigned long targetadr)
+ * void relocate_to_adr_full(unsigned long targetadr)
  *
  * Copy binary to targetadr, relocate code and continue
- * executing at new address.
+ * executing at new address. The _full variant takes the piggy data
+ * along, so barebox proper can still be decompressed afterwards.
  */
 .section .text.relocate_to_adr
-ENTRY(relocate_to_adr)
                                        /* a0: target address */
+ENTRY(relocate_to_adr_full)
+       lla     a3, __image_end         /* include piggy data */
+       j       1f
+ENDPROC(relocate_to_adr_full)
+
+ENTRY(relocate_to_adr)
+       lla     a3, __bss_start         /* skip piggy data */
+1:
        addi    sp, sp, -SZREG * 2
        lla     a1, _text               /* a1: source address */
 
@@ -61,8 +70,7 @@ ENTRY(relocate_to_adr)
        add     a2, a2, a0
        REG_S   a2, (sp)
 
-       lla     a2, __bss_start
-       sub     a2, a2, a1               /* a2: size */
+       sub     a2, a3, a1               /* a2: size */
 
        jal     __memcpy
 
-- 
2.47.3


Reply via email to