Commit Graph

240 Commits

Author SHA1 Message Date
Bin Meng 215c200ccb lib: Group all prints during boot into sbi_boot_prints()
Refactor the codes a little bit to put all prints during boot into
sbi_boot_prints().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-29 15:49:11 +05:30
Bin Meng 132f3e024b firmware: Introduce "options" in "struct sbi_scratch"
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-29 15:49:11 +05:30
Bin Meng e921fc2691 platform: plic: Fix comments of programming the interrupt enable register
The codes that currently program the interrupt enable register for
S-mode disagrees with what the comments say. Fix the comments.

While we are here, add one line comment to describe what is done
for M-mode too.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-18 18:18:16 +05:30
Atish Patra 6c39ea99ee lib: Return ENOTSUPP incase of invalid SBI function ID
OpenSBI should show error trace only if any valid SBI function
does not perform as expected.

However, OpenSBI should show notify the caller with a negative
error if given SBI function ID is not valid.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-14 20:44:22 +05:30
Bin Meng 312850148a platform: plic: Bypass interrupt ID 0's priority programming
Per PLIC spec, interrupt ID 0 is defined to mean "no interrupt".
We should bypass it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-14 20:43:35 +05:30
Bin Meng ebe351e550 platform: plic: Fix plic_set_priority()
At present plic_set_priority() ignores the 'source' and the priority
register to be programmed is constant. Fix it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-14 20:43:35 +05:30
Atish Patra ab91c143a3 firmware: Move scratch setup to _start instead of _start_warm
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-14 20:43:09 +05:30
Atish Patra 1e24e21d56 lib: Fix full tlb flush behavior
Currently, global page mappings are not flushed if start and size
arguments are zero.

Flush entire TLB if both size and start argument is passed as zero.

Fixes : 90cb491 (lib: Implement sfence.vma correctly)

Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-14 20:41:13 +05:30
Bin Meng 896870e9b0 platform: fu540: Fix cosmetic styling issues
There are some spaces or mixed usage of spaces and tabs in the macro
definition. Change to use tab consistently.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-13 23:53:21 +05:30
Bin Meng 6cd668df12 docs: firmware: Fix spelling of U-Boot
It's U-Boot, not U-boot.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2019-03-13 23:53:21 +05:30
Atish Patra 90cb4917b5 lib: Implement sfence.vma correctly.
Currently, OpenSBI doesn't distinguish between sfence.vma
and sfence.vm asid calls. Moreover, it ignores the page
ranges and just flush entire TLB everytime.

Fix the sfence implementation by keeping all the tlb flush
info in scratch area.

The relevant Linux kernel code was added by
https://patchwork.kernel.org/project/linux-riscv/list/?series=89695

However, this patch is backward compatible with older version kernel
that doesn't have the above patches as well.

Fixes #87
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-12 22:07:25 +05:30
Alistair Francis 508a27204c lib: Create a sbi_ipi_data structure
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-10 21:08:21 +05:30
Atish Patra 007a6b26d9 firmware: Reset all registers and flush icache
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-07 08:07:18 +05:30
Atish Patra b225583881 firmware: Add nop to reduce bus traffic.
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-07 08:07:18 +05:30
Atish Patra 69d794cbcb Revert "firmware: Add a barrier instruction for wait for boot hart"
This reverts commit 05602e2bf4.

Introducing a fence causes warm reset issue to reappear. Revert it
for the time being.
2019-03-07 08:07:18 +05:30
Xiang Wang 9eb8f0f90d platform: Make the `platform` read-only
platform should be a read-only variable, if it is placed in the data
segment, it may be exploited.

Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-06 11:10:35 -08:00
Atish Patra 27fae182dc firmware: Reset all the general purpose registers to zero.
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-06 08:59:54 +05:30
Atish Patra d4dd2b37f3 firmware: Ensure the mtvec is updated.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06 08:59:54 +05:30
Atish Patra 754ff34108 firmware: Fix a typo
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-06 08:59:54 +05:30
Atish Patra 86cc9b8633 lib:platform: Fix sbi_getc return type.
As per the current SBI specification, sbi_getc should return
an int instead of char.

In case of FIFO is empty, return -1 as per the specification.

Reported-by: Sergi Granell <xerpi.g.12@gmail.com>
Suggested-by:Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-03-05 14:05:12 +05:30
Xiang Wang 05602e2bf4 firmware: Add a barrier instruction for wait for boot hart
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-05 09:09:40 +05:30
Xiang Wang 1c87f0f9b1 firmware: Move _boot_hart_done to the data section
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-03-05 09:09:40 +05:30
Xiang Wang a72467f574 Add tags to .gitignore for being development friendly
Signed-off-by: Xiang Wang <wxjstz@126.com>
2019-03-05 09:07:23 +05:30
Andreas Schwab 87fbcf9376 Fix missing quotes in Makefile 2019-02-28 09:02:54 +05:30
Andreas Schwab 178a0307a2 Fix makefile dependency generation 2019-02-28 09:02:54 +05:30
Anup Patel ca20ac0cd4 include: Bump-up version to 0.3
This patch updates OpenSBI version to 0.3 as part of
release preparation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-26 22:24:59 +05:30
Alistair Francis 42e9ad556d Makefile: Set the platform variables before parsing the platforms
Ensure the platform variable PLATFORM_RISCV_XLEN is set before we parse
the platform files.

This fixes the 32-bit openSBI FW_JUMP_ADDR.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-26 19:23:26 +05:30
Anup Patel a1ffba1ac9 include: Bump-up version to 0.2
This patch increases OpenSBI version to 0.2.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-22 11:33:22 +05:30
Anup Patel d022c5d3ae scripts: Add script for creating binary archive
This patch adds scripts/create-binary-archive.sh which helps
us create a common tarball containing headers, static library
and firmware ELFs for all platforms.

This script can be used for release purpose OR for compile
testing all platforms.

Example usage commands are as follows:

1) Binary release archive for 32bit systems
./scripts/create-binary-archive.sh -s "bin" -x 32 -d

2) Binary release archive for 64bit systems
./scripts/create-binary-archive.sh -s "bin" -d

3) Compile test for 32bit systems
./scripts/create-binary-archive.sh -x 32 -t

4) Compile test for 64bit systems
./scripts/create-binary-archive.sh -t

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-22 11:28:41 +05:30
Anup Patel 889e746fd7 Makefile: Rename compile_ld() to compile_elf()
The compile_ld() is actually used to create ELF files so
the name is misleading hence this patch renames it to
compile_elf(). We also rename LDFLAGS to ELFFLAGS because
these will be used for ELF creation only.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-22 11:28:41 +05:30
Atish Patra fde1c42db3 doc: Fix root partition details for fu540.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-22 09:58:55 +05:30
Anup Patel 122d00ba67 firmware: Improve low-level trap handler for M-mode to M-mode traps
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-20 12:02:40 +05:30
Anup Patel ce6189f7a5 include: Add PRILX define to help print unsigned long
The unsigned long is always machine word size. This means it is
4 bytes on 32bit system and 8 bytes on 64bit system.

This patch adds PRILX define for sbi_printf() which will help us
print unsigned long without worrying whether it is 32bit or 64bit
system.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-20 12:02:40 +05:30
Sergi Granell db5b25af49 template: Fix some callback names 2019-02-19 18:22:58 +05:30
Sergi Granell 72a8272066 template: Remove trailing ';' 2019-02-19 18:22:58 +05:30
Sergi Granell 4b92518959 template: Fix typo in platform_final_init
There was a space instead of '_' in the function `platform_final_init`.
2019-02-19 18:22:58 +05:30
Atish Patra d046974cf6 docs: Update unleashed platform guide.
Following updates to fu540 platform guide.

1. Update a section about flashing the firmware binary
to sdcard with correct partition identifier.
2. Refer the individual payload section.
3. Update uboot booting section.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-19 18:22:26 +05:30
Atish Patra 0db43770b3 docs: Add a payload section describing different payloads.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-19 18:22:26 +05:30
Atish Patra 3265310b05 docs: Wrap text to 80 columns.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-19 18:22:26 +05:30
Atish Patra 34bf6d4a0f docs: Update about toolchain section.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-02-19 18:22:26 +05:30
Anup Patel 6a3dc84f66 Makefile: Use sed instead of awk to parse OpenSBI version
This patch replaces use of awk with sed in top-level makefile
to parse OpenSBI version from include/sbi/sbi_version.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-19 13:47:18 +05:30
Anup Patel f4a17177ce Makefile: Fix error evaluating OPENSBI_CC_XLEN
We get following error evaluating OPENSBI_CC_XLEN on
Ubuntu-18.04:
/bin/sh: 1: Bad substitution

This patch fixes above error by using "awk" in string
assigned to OPENSBI_CC_XLEN and it also moves "Setup
compilation commands" before OPENSBI_CC_XLEN.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-19 13:47:18 +05:30
Anup Patel 4e774f5470 lib: Fix mask shift in sbi_ipi_send_many()
The mask shift in for-loop of sbi_ipi_send_many() is
broken with commit 918c1354b7
("lib: Improve delivery of SBI_IPI_EVENT_HALT")

This patch fix it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-18 18:39:02 +05:30
Nick Kossifidis 148423d141 lib: Fix small typo on sbi_ipi.c 2019-02-18 09:21:58 +05:30
Nick Kossifidis 918c1354b7 lib: Improve delivery of SBI_IPI_EVENT_HALT
When sbi_ipi_send_many gets called with the current hartid
included on pmask (or when pmask is NULL), and we send
a HALT event, since the for loop works sequentially over
all hartids on the mask, we may send a HALT event to the
current hart before the loop finishes. So we will halt
the current hart before it can deliver a HALT IPI to the
rest and some harts will remain active.

Make sure we send an IPI to the current hart after we've
finished with everybody else.

Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
2019-02-18 09:21:58 +05:30
Nick Kossifidis 51e543511a platform: qemu-virt: Implement system shutdown
In order for QEMU to be compatible with Spike, it implements
a simple protocol used for reporting back the simulation's
status, through the memory-mapped "test finisher" device. We
use that protocol to make QEMU exit on system shutdown.

Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
2019-02-18 09:21:58 +05:30
Nick Kossifidis b44878b773 lib: Send IPI for all harts to hang on system shutdown
In case the platform specific method for shutting down
the system fails (or is not implemented), at least make
sure that all harts hang instead of just the current hart.

Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
2019-02-18 09:21:58 +05:30
Alistair Francis 16426420b5 Makefile: Fix the assignment of OPENSBI_CC_XLEN
Previously OPENSBI_CC_XLEN was not being correctly assigned either 32 or
64. It also was not assigned before config.mk was parsed. Ensure that it
will always be assigned.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-02-17 16:21:18 +05:30
Alistair Francis 3c53950b00
Merge pull request #59 from avpatel/make-run
Add 'make run' command for platform specific run
2019-02-15 15:02:19 -08:00
Olof Johansson 868e20df8b Makefile: Add 'make run' command for platform specific run
Makes for easy and quick build-run one-stop command.

For now only added for qemu targets. It can be added for
any platform having simulator/emulator (such as QEMU).

Signed-off-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-02-15 15:54:44 +05:30