Skip to content

Commit

Permalink
firmware/fw_payload: reduce the size by getting rid of padding
Browse files Browse the repository at this point in the history
Signed-off-by: Tekkaman Ninja <tekkamanninja@163.com>
  • Loading branch information
tekkamanninja committed Apr 28, 2021
1 parent fb50238 commit 2524b0e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
11 changes: 11 additions & 0 deletions firmware/fw_payload.S
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/
fw_boot_hart:
li a0, -1
#ifdef FW_PAYLOAD_NOPAD

#include "fw_reloc_payload.S"

.globl _relocate_payload_done
_relocate_payload_done:
#endif
ret

.section .entry, "ax", %progbits
Expand Down Expand Up @@ -59,7 +66,11 @@ fw_next_arg1:
* The next address should be returned in 'a0'.
*/
fw_next_addr:
#ifdef FW_PAYLOAD_NOPAD
li a0, (FW_TEXT_START + FW_PAYLOAD_OFFSET)
#else
lla a0, payload_bin
#endif
ret

.section .entry, "ax", %progbits
Expand Down
2 changes: 1 addition & 1 deletion firmware/fw_payload.elf.ldS
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SECTIONS
{
#include "fw_base.ldS"

#ifdef FW_PAYLOAD_OFFSET
#if defined(FW_PAYLOAD_OFFSET) && !defined(FW_PAYLOAD_NOPAD)
. = FW_TEXT_START + FW_PAYLOAD_OFFSET;
#else
. = ALIGN(FW_PAYLOAD_ALIGN);
Expand Down
63 changes: 63 additions & 0 deletions firmware/fw_reloc_payload.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021
* Authors: Tekkaman Ninja <tekkamanninja@163.com>
*
* t0 --> payload text base addr
* t1 --> payload end addr in fw_payload.bin
* t2 --> payload start addr in fw_payload.bin
* t3 --> payload text end addr (ti - t2 + t0)
* t4 --> _relocate_payload_done
* t2 t1 t0 t3
* +-----------+-----------+----------+-------------+-------+
* | fw_base + fw_payload| -------> |*fw_payload* | |
* +-----------+-----------+----------+-------------+-------+
*
*/

_relocate_payload:
li t0, (FW_TEXT_START + FW_PAYLOAD_OFFSET)
lla t1, _pl_end
REG_L t1, 0(t1)
lla t2, _pl_start
REG_L t2, 0(t2)

sub t3, t1, t2
add t3, t3, t0

beq t0, t2, _relocate_payload_done

lla t4, _relocate_payload_done

lla t5, _load_start
REG_L t5, 0(t5)
sub t4, t4, t5

lla t5, _link_start
REG_L t5, 0(t5)
add t4, t4, t5

blt t2, t0, _relocate_payload_copy_to_upper_loop

_relocate_payload_copy_to_lower_loop:
REG_L t3, 0(t2)
REG_S t3, 0(t0)
add t0, t0, __SIZEOF_POINTER__
add t2, t2, __SIZEOF_POINTER__
blt t2, t1, _relocate_payload_copy_to_lower_loop
jr t4

_relocate_payload_copy_to_upper_loop:
add t3, t3, -__SIZEOF_POINTER__
add t1, t1, -__SIZEOF_POINTER__
REG_L t0, 0(t1)
REG_S t0, 0(t3)
blt t2, t1, _relocate_payload_copy_to_upper_loop
jr t4

.align 3
_pl_end:
RISCV_PTR _payload_end
_pl_start:
RISCV_PTR _payload_start
4 changes: 4 additions & 0 deletions firmware/objects.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ ifdef FW_PAYLOAD_FDT_ADDR
firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR)
endif

ifdef FW_PAYLOAD_NOPAD
firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_NOPAD=$(FW_PAYLOAD_NOPAD)
endif

ifdef FW_OPTIONS
firmware-genflags-y += -DFW_OPTIONS=$(FW_OPTIONS)
endif
2 changes: 2 additions & 0 deletions platform/starfive/vic7100/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ FW_PAYLOAD=y
FW_PAYLOAD_FDT_ADDR=0x88000000

FW_PAYLOAD_ALIGN=0x1000

FW_PAYLOAD_NOPAD=y

2 comments on commit 2524b0e

@avpatel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will not require this patch if you have U-Boot SPL support because U-Boot SPL loads fw_dynamic.bin and U-Boot.bin separately.

Regards,
Anup

@tekkamanninja
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will not require this patch if you have U-Boot SPL support because U-Boot SPL loads fw_dynamic.bin and U-Boot.bin separately.

Regards,
Anup

I am agree with you.
I added this temporarily, because the firmware(ddrinit from starfive) has a 1MB size limitation of next stage firmware before(it seems they expand the size to 10MB now for uefi).
If we can do SPL->opensbi+uboot(fw_payload.bin), we don't need this patch
I guess some one is working on SPL.

Please sign in to comment.