diff options
author | Anup Patel <anup.patel@wdc.com> | 2018-12-26 09:44:49 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2018-12-27 09:29:29 +0530 |
commit | bb3665d0f097745f5f081e687b7487f3bbed3500 (patch) | |
tree | 3779622142f0f0512091f4301d1d706a2bfca450 /firmware/payloads | |
parent | b46970b47e63dce030ef6d4196f7c395a9ea23c1 (diff) |
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>
Diffstat (limited to 'firmware/payloads')
-rw-r--r-- | firmware/payloads/dummy.elf.ldS | 83 | ||||
-rw-r--r-- | firmware/payloads/dummy_head.S | 87 | ||||
-rw-r--r-- | firmware/payloads/dummy_main.c | 31 | ||||
-rw-r--r-- | firmware/payloads/objects.mk | 19 |
4 files changed, 220 insertions, 0 deletions
diff --git a/firmware/payloads/dummy.elf.ldS b/firmware/payloads/dummy.elf.ldS new file mode 100644 index 0000000..b4d9f75 --- /dev/null +++ b/firmware/payloads/dummy.elf.ldS @@ -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 = .); +} diff --git a/firmware/payloads/dummy_head.S b/firmware/payloads/dummy_head.S new file mode 100644 index 0000000..1b36319 --- /dev/null +++ b/firmware/payloads/dummy_head.S @@ -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 diff --git a/firmware/payloads/dummy_main.c b/firmware/payloads/dummy_main.c new file mode 100644 index 0000000..d4bc360 --- /dev/null +++ b/firmware/payloads/dummy_main.c @@ -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(); +} diff --git a/firmware/payloads/objects.mk b/firmware/payloads/objects.mk new file mode 100644 index 0000000..7e82b77 --- /dev/null +++ b/firmware/payloads/objects.mk @@ -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,$@,$^) |