summaryrefslogtreecommitdiff
path: root/firmware
AgeCommit message (Collapse)AuthorFilesLines
2019-08-09firmware: Use macro instead of magic number for boot statusBin Meng1-4/+7
The boot status is currently hard-coded. Define some macros for it. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-07firmware: Fix the loop condition of _wait_relocate_copy_done sectionNylon Chen1-1/+1
If core-0 have finished _fdt_reloc_done but any of other cores has not yet left the loop in _wait_relocate_copy_done, they could never leave the loop because _boot_status is not equal to 1.
2019-07-01firmware: For no relocation skip two stage wait for secondary HARTsAnup Patel1-0/+1
When relocation is not required (i.e. _load_start == _link_start), we can skip two stage wait for secondary HARTs. This means secondary HARTs can skip the _wait_relocate_copy_done() loop and directly jump to the _wait_for_boot_hart() loop when no relocation not required. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-06-24firmware: Handle overlapping load and link addresses in relocationXiang W1-21/+39
The old code may corrupt the code of the waiting hart hence this patch keeps waiting HART within relocation code range at time of relocation. Signed-off-by: Xiang W <wxjstz@126.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-17firmware: Handle overlapping load and link addresses in relocationXiang W1-2/+42
This patch extends relocation to handle overlapping load and link addresses. The updated relocation will work fine in most cases except when the relocate copy loop itself falls in overlapping load and link addresses. Signed-off-by: Xiang W <wxjstz@126.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-06-12firmware: Relocate when load address is not equal to link addressAnup Patel4-6/+53
This patch extends fw_base to relocate to link address whenever firmware load address is not equal to link address. The relocation will not work when load start to load end overlap link start to link end. Signed-off-by: Anup Patel <anup.patel@wdc.com> Tested-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
2019-06-12firmware: add missing linker sections to fw_base.ldSLukas Auer1-0/+4
The linker sections .sdata and .sbss are missing from the linker script fw_base.ldS. Add them to the .data and .bss sections. On current builds, most variables are in the .sbss section. They are not correctly initialized to zero, because they are not within the boundaries indicated by _bss_start and _bss_end. Currently, this does not cause any issues, however with relocation support lock-ups may occur due to incorrectly initialized lock variables. Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-05-10firmware: Add fw_dynamic firmwareAnup Patel3-0/+136
This patch provides first-cut implementation of fw_dynamic firmware. As compared to fw_jump and fw_payload, the fw_dynamic obtains next address, next mode and OpenSBI options from struct fw_dynamic_info. The previous booting stage can create struct fw_dynamic_info in memory and pass address of struct fw_dynamic_info in 'a2' register. Also, the struct fw_dynamic_info has versioning as well so changes to the struct fw_dynamic_info can be done in a backward compatible manner. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-05-10firmware: Allow firmwares to provide next mode and optionsAnup Patel3-25/+148
This patch extends existing firmwares (i.e. fw_jump and fw_payload) to explicitly provide next mode and options to fw_base. We also introduce fw_save_info() which is called by fw_base very early on boot HART. This function can be used by existing firmwares (i.e. fw_jump and fw_payload) to save information passed by previous booting stage. Overall, this is a preparatory patch for implementing fw_dynamic. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-04-24all: run clang-format and update checked-in filesOlof Johansson1-4/+4
Noisy commit, no functional changes. Generated with an current upstream clang-format and: clang-format -i $(find . -name \*.[ch]) Signed-off-by: Olof Johansson <olof@lixom.net>
2019-04-09TOP: Allow building platform out-of-treeAnup Patel2-4/+4
This patch extends our current build-system for building platform sources which are not part of OpenSBI sources. For example: Let's say we have out-of-tree ABC platform sources. We place these sources under <XYZ>/ABC directory along with its config.mk and objects.mk. To build out-of-tree ABC platform from OpenSBI directory: $ make PLATFORM_DIR=<XYZ>/ABC OR $ make PLATFORM_DIR=<XYZ> PLATFORM=ABC To build out-of-tree ABC platform from <XYZ>/ABC directory: $ make PLATFORM_DIR=<XYZ>/ABC -C <path_to_opensbi> OR $ make PLATFORM_DIR=<XYZ> PLATFORM=ABC -C <path_to_opensbi> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2019-04-04firmware: Fix source fdt alignmentXiang Wang1-1/+1
When I tried to start opensbi with coreboot, I found that aligning to a 16-byte boundary would make a copy error. Corrected to align to an machine word length boundary. Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-29firmware: Introduce "options" in "struct sbi_scratch"Bin Meng2-0/+10
Introduce "options" in "struct sbi_scratch" and firmware can update it based on optional compile time flags before calling sbi_init(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-14firmware: Move scratch setup to _start instead of _start_warmAtish Patra1-31/+60
Scratch space setup needs to be done once for reboot for each hart. _start_warm may be called several times if hart hotplug is implemented. Move scratch space setup to the beginning so that it is done only once. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-10lib: Create a sbi_ipi_data structureAlistair Francis1-1/+0
Create a sbi_ipi_data structure that holds unpacked IPI information. At the same time remove ipi_type from the sbi_scratch struct and use a fixed offset to access it. This structure fits in behind the sbi_scratch structure. This fixes https://github.com/riscv/opensbi/issues/81 Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-03-07firmware: Reset all registers and flush icacheAtish Patra1-0/+4
A warm reset using reset button may put icache and registers in non-coherent state. Flush the icache and reset all registers for every hart. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-07firmware: Add nop to reduce bus traffic.Atish Patra1-0/+4
All the non-boot harts run in a tight loop which may cause a heavy load on the memory bus. This may delay the boot hart to complete the cold boot process. Introduce few nop that will ease up the traffic. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-07Revert "firmware: Add a barrier instruction for wait for boot hart"Atish Patra1-1/+0
This reverts commit 05602e2bf4812533adcb7acb1a67e43726c0e7bb. Introducing a fence causes warm reset issue to reappear. Revert it for the time being.
2019-03-06firmware: Reset all the general purpose registers to zero.Atish Patra1-0/+41
A warm reset by pressing the reset button may not initialize all the registers to zero. Do it for every hart during warm boot. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06firmware: Ensure the mtvec is updated.Atish Patra1-0/+5
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06firmware: Fix a typoAtish Patra1-1/+1
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-05firmware: Add a barrier instruction for wait for boot hartXiang Wang1-0/+1
Multi-core communication via memory requires the addition of a barrier instructions to ensure cache coherency. Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-05firmware: Move _boot_hart_done to the data sectionXiang Wang1-6/+5
Writable code section can cause some security problems, so move _boot_hart_done to the data section Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-02-20firmware: Improve low-level trap handler for M-mode to M-mode trapsAnup Patel1-39/+53
This patch extends our low-level trap handler in fw_base.S for handling M-mode to M-mode traps without overwritting stack. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-15firmware: Ensure the payloads are 4 bit allignedAlistair Francis1-4/+5
We expect the payloads to be 4 bit alligned as we later AND them with ~0xf. As most of the addresses are manually specified we don't really need this, but better to be over cautious. Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-14firmware: Use CSR_<FOO> instead of <foo> for csr*Atish Patra2-19/+20
Some older toolchains may not have all the csr's defined. Update all the csr functions to use the CSR_ #define values instead of the toolchain defined values. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-08firmware: Use lw instead of lwu for 32-bit architecturesAlistair Francis1-0/+14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-06firwmare: don't expand macros in FW_PAYLOAD_PATHAndreas Schwab2-7/+4
Signed-off-by: Andreas Schwab <schwab@suse.de>
2019-01-24all: Update copyright header in all filesAnup patel12-36/+36
This patch updates copyright header in all files as follows: 1. Makes "SPDX-License-Identifier: BSD-2-Clause" as first line 2. Change copyright year to 2019 for Western Digital Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-22lib: Move software interrupt enablement from firmware to libAtish Patra1-4/+0
The secondary hart waits for an IPI signal from the boot hart to executing boot code (hot boot). As a result, software generated interrupts have to be enabled for secondary harts before waiting for the boot hart boot completion IPI signal. Enabling software generated interrupts (IPI) can be done independently of the firmware code and moved to libsbi code so that the different firmware do not have to implement this. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-21sbi: Add ecall helpersDamien Le Moal1-9/+1
Define sbi_ecall_console_puts() using sbi_ecall_console_putchar() renamed as sbi_ecall_console_putc() and remove the hardcoded version of the same funtion in the test payload code. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21payload: rename dummy payload to test payloadDamien Le Moal5-9/+9
Use a more neutral term more representative of this payload intent. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21Makefile: Add support for device tree compilationDamien Le Moal2-0/+6
Add rules to compile dts files into dtb files using the device tree compiler (dtc). A platform can specify the DTS file to compile using the platform-dtb-y variable. The flattened device tree binary file to be used for building the final polatform firmware can be specified using the new FW_PAYLOAD_FDT firmware configuration option to point to the automatically compiled FDT file. Using the existing FW_PAYLOAD_FDT_PATH configuration option is still possible and will take precedence over the FW_PAYLOAD_FDT definition. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21build: Introduce FW_PAYLOAD_ALIGNDamien Le Moal3-0/+12
The firmware payload offset defined by FW_PAYLOAD_OFFSET must specify a value large enough so the the payload does not overlap with the base firmware data, bss and text. For platforms without any strong requirement on the payload address, introduce the FW_PAYLOAD_ALIGN build parameter to automatically place the payload right after the base firmware at an address aligned with the defined value. Either FW_PAYLOAD_OFFSET or FW_PAYLOAD_ALIGN should be defined by a platform configuration. If both FW_PAYLOAD_OFFSET and FW_PAYLOAD_ALIGN are defined by a platform, FW_PAYLOAD_OFFSET has precedence and is used for building the final firmawre image. Using FW_PAYLOAD_ALIGN=4096 with the Kendryte platform rather than the abitrary FW_PAYLOAD_OFFSET=0x10000 value reduces the final firmware image size by about 20KB. Add a description of the FW_PAYLOAD_ALIGN configuration parameter in the fw_payload documentation file as well. And while at it, also fix various grammar and style issues in that file.. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-04Makefile: Use generic flags for the firmwareAlistair Francis1-7/+8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-03include: Remove redundant tmp0 from struct sbi_scratchAnup Patel1-1/+0
The tmp0 member was added in struct sbi_scratch to assist register save/restore at time of trap handling. This tmp0 is not unsed any more hence removing it. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Move RISCV_TRAP_REGS_xyz defines to sbi_trap.hAnup Patel1-69/+70
The struct sbi_trap_regs related defines RISCV_TRAP_REGS_xyz should be in sbi_trap.h so that we can keep these defines in-sync with changes in struct sbi_trap_regs. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Move RISCV_PLATFORM_xyz defines to sbi_platform.hAnup Patel1-4/+5
The struct sbi_platform related defines RISCV_PLATFORM_xyz should be in sbi_platform.h so that we can keep these defines in-sync with changes in struct sbi_platform. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Move RISCV_SCRATCH_xyz defines to sbi_scratch.hAnup Patel1-12/+13
The struct sbi_scratch related defines RISCV_SCRATCH_xyz should be in sbi_scratch.h so that we can keep these defines in-sync with changes in struct sbi_scratch. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27firmware: Rename fw_common.S to fw_base.SAnup Patel6-4/+4
The fw_common.S is the base firmware extendend by fw_jump and fw_payload. This patch renames fw_common.S to fw_base.S to have more clear/intutive name for base firmware. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27firmware: Use dummy payload for FW_PAYLOADAnup Patel2-5/+18
We use recently added separate dummy payload for FW_PAYLOAD when FW_PAYLOAD_PATH is not specified. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27firmware: Add separate dummy payload for FW_PAYLOADAnup Patel4-0/+220
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>
2018-12-22firmware: Don't depend on PLAT_HART_COUNT and PLAT_HART_STACK_SIZEAnup Patel1-4/+6
The hart_count and hart_stack_size information is already available in "struct sbi_platform" so we use that instead of depending on PLAT_HART_COUNT and PLAT_HART_STACK_SIZE. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-22firmware: Remove stack section from common linker scriptAnup Patel2-31/+42
We don't need a separate stack section for per-HART stack instead we create per-HART stack at the end of firmware (i.e. after _fw_end symbol). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21firmware: Remove redundant write to mideleg and medelegAnup Patel1-2/+0
The mideleg and medeleg are already programmed in delegate_traps() so no need to set it here. Any CSR setup in our reference firmware becomes a requirement for bootloader linking to libsbi.a so we should have minimum possible CSR setup in our reference firmware. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21Revert "Fix FDT relocation"Anup Patel1-2/+0
This patch reverts "Fix FDT relocation" because it breaks fw_jump firmware. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21Fiw comment typoDamien Le Moal1-1/+1
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21fw: Disable delegationDamien Le Moal1-0/+2
Also disable interrupts and exceptions delegation when clearing mie and mip. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Fix FDT relocationDamien Le Moal1-0/+2
Or rather, disable it if FW_PAYLOAD_FDT_ADDR is not defined. This correspond to cases where the underlying FW that loaded and started opensbi did not provide any FDT. In such case, the platform code will need to prepare one. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21top: Rename "blob" to "firmware" everywhereAnup Patel7-0/+607
This patch renames "blob" to "firmware" everywhere for better and intutive naming. Signed-off-by: Anup Patel <anup@brainfault.org>