From 42283461d3f236881f67d8aa9bb8bc96decdacae Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 18 Jan 2019 16:09:14 +0900 Subject: payload: rename dummy payload to test payload Use a more neutral term more representative of this payload intent. Signed-off-by: Damien Le Moal --- docs/firmware/fw_payload.md | 1 + firmware/objects.mk | 2 +- firmware/payloads/dummy.elf.ldS | 87 ----------------------------------------- firmware/payloads/dummy_head.S | 87 ----------------------------------------- firmware/payloads/dummy_main.c | 31 --------------- firmware/payloads/objects.mk | 10 ++--- firmware/payloads/test.elf.ldS | 87 +++++++++++++++++++++++++++++++++++++++++ firmware/payloads/test_head.S | 87 +++++++++++++++++++++++++++++++++++++++++ firmware/payloads/test_main.c | 31 +++++++++++++++ 9 files changed, 212 insertions(+), 211 deletions(-) delete mode 100644 firmware/payloads/dummy.elf.ldS delete mode 100644 firmware/payloads/dummy_head.S delete mode 100644 firmware/payloads/dummy_main.c create mode 100644 firmware/payloads/test.elf.ldS create mode 100644 firmware/payloads/test_head.S create mode 100644 firmware/payloads/test_main.c diff --git a/docs/firmware/fw_payload.md b/docs/firmware/fw_payload.md index 3a8a14d..aff254d 100644 --- a/docs/firmware/fw_payload.md +++ b/docs/firmware/fw_payload.md @@ -35,6 +35,7 @@ firmware: * **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_BASE* where the payload binary will be linked in the final *FW_PAYLOAD* firmware binary image. +<<<<<<< HEAD This configuration parameter is mandatory if *FW_PAYLOAD_ALIGN* is not defined. Compilation errors will result from an incorrect definition of *FW_PAYLOAD_OFFSET* or *FW_PAYLOAD_ALIGN*, or if neither of these diff --git a/firmware/objects.mk b/firmware/objects.mk index 1c7cc69..128834c 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -29,7 +29,7 @@ firmware-bins-$(FW_PAYLOAD) += fw_payload.bin ifdef FW_PAYLOAD_PATH FW_PAYLOAD_PATH_FINAL=$(FW_PAYLOAD_PATH) else -FW_PAYLOAD_PATH_FINAL=$(build_dir)/$(platform_subdir)/firmware/payloads/dummy.bin +FW_PAYLOAD_PATH_FINAL=$(build_dir)/$(platform_subdir)/firmware/payloads/test.bin endif firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH_FINAL) ifdef FW_PAYLOAD_OFFSET diff --git a/firmware/payloads/dummy.elf.ldS b/firmware/payloads/dummy.elf.ldS deleted file mode 100644 index d0854d5..0000000 --- a/firmware/payloads/dummy.elf.ldS +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -OUTPUT_ARCH(riscv) -ENTRY(_start) - -SECTIONS -{ -#ifdef FW_PAYLOAD_OFFSET - . = FW_TEXT_START + FW_PAYLOAD_OFFSET; -#else - . = ALIGN(FW_PAYLOAD_ALIGN); -#endif - - 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 deleted file mode 100644 index 1b36319..0000000 --- a/firmware/payloads/dummy_head.S +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - * - * 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 deleted file mode 100644 index d4bc360..0000000 --- a/firmware/payloads/dummy_main.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2018 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#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 index 7e82b77..0395599 100644 --- a/firmware/payloads/objects.mk +++ b/firmware/payloads/objects.mk @@ -7,13 +7,13 @@ # SPDX-License-Identifier: BSD-2-Clause # -firmware-bins-$(FW_PAYLOAD) += payloads/dummy.bin +firmware-bins-$(FW_PAYLOAD) += payloads/test.bin -dummy-y += dummy_head.o -dummy-y += dummy_main.o +test-y += test_head.o +test-y += test_main.o -%/dummy.o: $(foreach obj,$(dummy-y),%/$(obj)) +%/test.o: $(foreach obj,$(test-y),%/$(obj)) $(call merge_objs,$@,$^) -%/dummy.dep: $(foreach dep,$(dummy-y:.o=.dep),%/$(dep)) +%/test.dep: $(foreach dep,$(test-y:.o=.dep),%/$(dep)) $(call merge_deps,$@,$^) diff --git a/firmware/payloads/test.elf.ldS b/firmware/payloads/test.elf.ldS new file mode 100644 index 0000000..d0854d5 --- /dev/null +++ b/firmware/payloads/test.elf.ldS @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +OUTPUT_ARCH(riscv) +ENTRY(_start) + +SECTIONS +{ +#ifdef FW_PAYLOAD_OFFSET + . = FW_TEXT_START + FW_PAYLOAD_OFFSET; +#else + . = ALIGN(FW_PAYLOAD_ALIGN); +#endif + + 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/test_head.S b/firmware/payloads/test_head.S new file mode 100644 index 0000000..e2b5f7b --- /dev/null +++ b/firmware/payloads/test_head.S @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * 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 test_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/test_main.c b/firmware/payloads/test_main.c new file mode 100644 index 0000000..666ce7c --- /dev/null +++ b/firmware/payloads/test_main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +#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 test_main(unsigned long a0, unsigned long a1) +{ + sbi_puts("\nTest payload running\n"); + + while (1) + wfi(); +} -- cgit v1.2.3