mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00
firmware: Add separate dummy payload for FW_PAYLOAD
Currently, the default payload for FW_PAYLOAD is embedded fw_payload.S itself. This means people have to hack fw_payload.S if they want to have some temporary S-mode test code. This patch adds a separate dummy payload for FW_PAYLOAD which can be easily hacked for some S-mode testing. Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
83
firmware/payloads/dummy.elf.ldS
Normal file
83
firmware/payloads/dummy.elf.ldS
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
OUTPUT_ARCH(riscv)
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = FW_TEXT_START + FW_PAYLOAD_OFFSET;
|
||||
|
||||
PROVIDE(_payload_start = .);
|
||||
|
||||
. = ALIGN(0x1000); /* Need this to create proper sections */
|
||||
|
||||
/* Beginning of the code section */
|
||||
|
||||
.text :
|
||||
{
|
||||
PROVIDE(_text_start = .);
|
||||
*(.entry)
|
||||
*(.text)
|
||||
. = ALIGN(8);
|
||||
PROVIDE(_text_end = .);
|
||||
}
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* End of the code sections */
|
||||
|
||||
/* Beginning of the read-only data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
.rodata :
|
||||
{
|
||||
PROVIDE(_rodata_start = .);
|
||||
*(.rodata .rodata.*)
|
||||
. = ALIGN(8);
|
||||
PROVIDE(_rodata_end = .);
|
||||
}
|
||||
|
||||
/* End of the read-only data sections */
|
||||
|
||||
/* Beginning of the read-write data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
.data :
|
||||
{
|
||||
PROVIDE(_data_start = .);
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.readmostly.data)
|
||||
*(*.data)
|
||||
. = ALIGN(8);
|
||||
|
||||
PROVIDE(_data_end = .);
|
||||
}
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
.bss :
|
||||
{
|
||||
PROVIDE(_bss_start = .);
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
. = ALIGN(8);
|
||||
PROVIDE(_bss_end = .);
|
||||
}
|
||||
|
||||
/* End of the read-write data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Need this to create proper sections */
|
||||
|
||||
PROVIDE(_payload_end = .);
|
||||
}
|
87
firmware/payloads/dummy_head.S
Normal file
87
firmware/payloads/dummy_head.S
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#define __ASM_STR(x) x
|
||||
|
||||
#if __riscv_xlen == 64
|
||||
#define __REG_SEL(a, b) __ASM_STR(a)
|
||||
#define RISCV_PTR .dword
|
||||
#elif __riscv_xlen == 32
|
||||
#define __REG_SEL(a, b) __ASM_STR(b)
|
||||
#define RISCV_PTR .word
|
||||
#else
|
||||
#error "Unexpected __riscv_xlen"
|
||||
#endif
|
||||
|
||||
#define REG_L __REG_SEL(ld, lw)
|
||||
#define REG_S __REG_SEL(sd, sw)
|
||||
|
||||
.align 3
|
||||
.section .entry, "ax", %progbits
|
||||
.globl _start
|
||||
_start:
|
||||
/* Pick one hart to run the main boot sequence */
|
||||
la a3, _hart_lottery
|
||||
li a2, 1
|
||||
amoadd.w a3, a2, (a3)
|
||||
bnez a3, _start_hang
|
||||
|
||||
/* Save a0 and a1 */
|
||||
la a3, _boot_a0
|
||||
REG_S a0, 0(a3)
|
||||
la a3, _boot_a1
|
||||
REG_S a1, 0(a3)
|
||||
|
||||
/* Zero-out BSS */
|
||||
la a4, _bss_start
|
||||
la a5, _bss_end
|
||||
_bss_zero:
|
||||
REG_S zero, (a4)
|
||||
add a4, a4, __SIZEOF_POINTER__
|
||||
blt a4, a5, _bss_zero
|
||||
|
||||
_start_warm:
|
||||
/* Disable and clear all interrupts */
|
||||
csrw sie, zero
|
||||
csrw sip, zero
|
||||
|
||||
/* Setup exception vectors */
|
||||
la a3, _start_hang
|
||||
csrw stvec, a3
|
||||
|
||||
/* Setup stack */
|
||||
la a3, _payload_end
|
||||
li a4, 0x2000
|
||||
add sp, a3, a4
|
||||
|
||||
/* Jump to C main */
|
||||
la a3, _boot_a0
|
||||
REG_L a0, 0(a3)
|
||||
la a3, _boot_a1
|
||||
REG_L a1, 0(a3)
|
||||
call dummy_main
|
||||
|
||||
/* We don't expect to reach here hence just hang */
|
||||
j _start_hang
|
||||
|
||||
.align 3
|
||||
.section .entry, "ax", %progbits
|
||||
.globl _start_hang
|
||||
_start_hang:
|
||||
wfi
|
||||
j _start_hang
|
||||
|
||||
.align 3
|
||||
.section .entry, "ax", %progbits
|
||||
_hart_lottery:
|
||||
RISCV_PTR 0
|
||||
_boot_a0:
|
||||
RISCV_PTR 0
|
||||
_boot_a1:
|
||||
RISCV_PTR 0
|
31
firmware/payloads/dummy_main.c
Normal file
31
firmware/payloads/dummy_main.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
*
|
||||
* Authors:
|
||||
* Anup Patel <anup.patel@wdc.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
|
||||
#define wfi() \
|
||||
do { \
|
||||
__asm__ __volatile__ ("wfi" ::: "memory"); \
|
||||
} while (0)
|
||||
|
||||
static void sbi_puts(const char *str)
|
||||
{
|
||||
while (*str) {
|
||||
SBI_ECALL_1(SBI_ECALL_CONSOLE_PUTCHAR, *str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void dummy_main(unsigned long a0, unsigned long a1)
|
||||
{
|
||||
sbi_puts("\nDummy Payload\n");
|
||||
|
||||
while (1)
|
||||
wfi();
|
||||
}
|
19
firmware/payloads/objects.mk
Normal file
19
firmware/payloads/objects.mk
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright (c) 2018 Western Digital Corporation or its affiliates.
|
||||
#
|
||||
# Authors:
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
|
||||
firmware-bins-$(FW_PAYLOAD) += payloads/dummy.bin
|
||||
|
||||
dummy-y += dummy_head.o
|
||||
dummy-y += dummy_main.o
|
||||
|
||||
%/dummy.o: $(foreach obj,$(dummy-y),%/$(obj))
|
||||
$(call merge_objs,$@,$^)
|
||||
|
||||
%/dummy.dep: $(foreach dep,$(dummy-y:.o=.dep),%/$(dep))
|
||||
$(call merge_deps,$@,$^)
|
Reference in New Issue
Block a user