platform/kernel/opensbi.git
5 years agofirmware: Move _boot_hart_done to the data section
Xiang Wang [Mon, 4 Mar 2019 09:17:08 +0000 (17:17 +0800)]
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>
5 years agoAdd tags to .gitignore for being development friendly
Xiang Wang [Mon, 4 Mar 2019 03:20:58 +0000 (11:20 +0800)]
Add tags to .gitignore for being development friendly

Signed-off-by: Xiang Wang <wxjstz@126.com>
5 years agoFix missing quotes in Makefile
Andreas Schwab [Wed, 27 Feb 2019 11:57:56 +0000 (12:57 +0100)]
Fix missing quotes in Makefile

5 years agoFix makefile dependency generation
Andreas Schwab [Wed, 27 Feb 2019 11:53:07 +0000 (12:53 +0100)]
Fix makefile dependency generation

5 years agoinclude: Bump-up version to 0.3 v0.3
Anup Patel [Tue, 26 Feb 2019 16:54:59 +0000 (22:24 +0530)]
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>
5 years agoMakefile: Set the platform variables before parsing the platforms
Alistair Francis [Fri, 22 Feb 2019 23:02:55 +0000 (15:02 -0800)]
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>
5 years agoinclude: Bump-up version to 0.2 v0.2
Anup Patel [Fri, 22 Feb 2019 06:03:22 +0000 (11:33 +0530)]
include: Bump-up version to 0.2

This patch increases OpenSBI version to 0.2.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoscripts: Add script for creating binary archive
Anup Patel [Wed, 20 Feb 2019 08:48:12 +0000 (14:18 +0530)]
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>
5 years agoMakefile: Rename compile_ld() to compile_elf()
Anup Patel [Wed, 20 Feb 2019 08:46:48 +0000 (14:16 +0530)]
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>
5 years agodoc: Fix root partition details for fu540.
Atish Patra [Fri, 22 Feb 2019 02:04:07 +0000 (18:04 -0800)]
doc: Fix root partition details for fu540.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agofirmware: Improve low-level trap handler for M-mode to M-mode traps
Anup Patel [Tue, 19 Feb 2019 12:41:22 +0000 (18:11 +0530)]
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>
5 years agoinclude: Add PRILX define to help print unsigned long
Anup Patel [Tue, 19 Feb 2019 12:36:46 +0000 (18:06 +0530)]
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>
5 years agotemplate: Fix some callback names
Sergi Granell [Tue, 19 Feb 2019 06:35:06 +0000 (07:35 +0100)]
template: Fix some callback names

5 years agotemplate: Remove trailing ';'
Sergi Granell [Mon, 18 Feb 2019 14:46:29 +0000 (15:46 +0100)]
template: Remove trailing ';'

5 years agotemplate: Fix typo in platform_final_init
Sergi Granell [Mon, 18 Feb 2019 14:40:25 +0000 (15:40 +0100)]
template: Fix typo in platform_final_init

There was a space instead of '_' in the function `platform_final_init`.

5 years agodocs: Update unleashed platform guide.
Atish Patra [Tue, 19 Feb 2019 07:18:04 +0000 (23:18 -0800)]
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>
5 years agodocs: Add a payload section describing different payloads.
Atish Patra [Tue, 19 Feb 2019 07:17:16 +0000 (23:17 -0800)]
docs: Add a payload section describing different payloads.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Wrap text to 80 columns.
Atish Patra [Sat, 16 Feb 2019 05:47:37 +0000 (21:47 -0800)]
docs: Wrap text to 80 columns.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Update about toolchain section.
Atish Patra [Sat, 16 Feb 2019 04:57:12 +0000 (20:57 -0800)]
docs: Update about toolchain section.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoMakefile: Use sed instead of awk to parse OpenSBI version
Anup Patel [Tue, 19 Feb 2019 07:45:35 +0000 (13:15 +0530)]
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>
5 years agoMakefile: Fix error evaluating OPENSBI_CC_XLEN
Anup Patel [Mon, 18 Feb 2019 04:10:51 +0000 (09:40 +0530)]
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>
5 years agolib: Fix mask shift in sbi_ipi_send_many()
Anup Patel [Mon, 18 Feb 2019 13:09:02 +0000 (18:39 +0530)]
lib: Fix mask shift in sbi_ipi_send_many()

The mask shift in for-loop of sbi_ipi_send_many() is
broken with commit 918c1354b75c74b62f67c4e929551d643f035443
("lib: Improve delivery of SBI_IPI_EVENT_HALT")

This patch fix it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Fix small typo on sbi_ipi.c
Nick Kossifidis [Sun, 17 Feb 2019 21:43:41 +0000 (23:43 +0200)]
lib: Fix small typo on sbi_ipi.c

5 years agolib: Improve delivery of SBI_IPI_EVENT_HALT
Nick Kossifidis [Sun, 17 Feb 2019 07:00:20 +0000 (09:00 +0200)]
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>
5 years agoplatform: qemu-virt: Implement system shutdown
Nick Kossifidis [Sun, 17 Feb 2019 02:02:15 +0000 (04:02 +0200)]
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>
5 years agolib: Send IPI for all harts to hang on system shutdown
Nick Kossifidis [Sun, 17 Feb 2019 01:52:44 +0000 (03:52 +0200)]
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>
5 years agoMakefile: Fix the assignment of OPENSBI_CC_XLEN
Alistair Francis [Fri, 15 Feb 2019 22:56:53 +0000 (14:56 -0800)]
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>
5 years agoMerge pull request #59 from avpatel/make-run
Alistair Francis [Fri, 15 Feb 2019 23:02:19 +0000 (15:02 -0800)]
Merge pull request #59 from avpatel/make-run

Add 'make run' command for platform specific run

5 years agoMakefile: Add 'make run' command for platform specific run
Olof Johansson [Fri, 15 Feb 2019 03:46:47 +0000 (09:16 +0530)]
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>
5 years agodocs: fu540: Add steps for the Microsemi Expansion board
Alistair Francis [Tue, 12 Feb 2019 23:39:38 +0000 (15:39 -0800)]
docs: fu540: Add steps for the Microsemi Expansion board

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform: fu540: Initial commit of Microsemi device tree
Alistair Francis [Mon, 11 Feb 2019 22:12:57 +0000 (14:12 -0800)]
platform: fu540: Initial commit of Microsemi device tree

Add a device tree for th HiFive Unleashed that includes the Microsemi
PCIe root complex.

Once we have support for u-boot and in tree Linux kernel device trees
this device tree should be removed.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform: fu540: Fix missing newline
Alistair Francis [Tue, 12 Feb 2019 23:31:14 +0000 (15:31 -0800)]
platform: fu540: Fix missing newline

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agofirmware: Ensure the payloads are 4 bit alligned
Alistair Francis [Thu, 14 Feb 2019 22:47:41 +0000 (14:47 -0800)]
firmware: Ensure the payloads are 4 bit alligned

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>
5 years agoMakefile: Make sure ld is always aware of the target abi/emulation
Nick Kossifidis [Thu, 14 Feb 2019 03:37:13 +0000 (05:37 +0200)]
Makefile: Make sure ld is always aware of the target abi/emulation

On Makefile merge_objs calls ld without providing any hints
on the target so on a multilib toolchain for example it will
always pick the default one (elf64-littleriscv) which will
then result a failure when compiling on RV32 since the objects
will be 32bits and the target will be 64bits. The same happens
on compile_ld that calls gcc without CFLAGS so it doesn't
get mabi/march.

With this patch OpenSBI compiles on RV32 (PLATFORM_RISCV_XLEN=32),
I tested fw_jump.elf on qemu (but it doesn't boot the kernel yet
-bbl also doesn't boot the kernel so it may be something else).

Signed-off-by: Nick Kossifidis <mickflemm@gmail.com>
5 years agofirmware: Use CSR_<FOO> instead of <foo> for csr*
Atish Patra [Wed, 13 Feb 2019 19:03:53 +0000 (11:03 -0800)]
firmware: Use CSR_<FOO> instead of <foo> for csr*

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>
5 years agoplatform: Use CSR_<FOO> instead of <foo> for csr_*()
Atish Patra [Wed, 13 Feb 2019 02:32:58 +0000 (18:32 -0800)]
platform: Use CSR_<FOO> instead of <foo> for csr_*()

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.

Suggested-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Use CSR_<FOO> instead of <foo> for csr_*()
Atish Patra [Wed, 13 Feb 2019 02:32:06 +0000 (18:32 -0800)]
lib: Use CSR_<FOO> instead of <foo> for csr_*()

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.

Suggested-by: Olof Johansson <olof@lixom.net>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Use normal hyphen instead of non-breaking hyphen
Atish Patra [Tue, 12 Feb 2019 21:02:58 +0000 (13:02 -0800)]
docs: Use normal hyphen instead of non-breaking hyphen

Usage non-breaking hyphen breaks make docs as doxygen doesn't know
how to handle this.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoMakefile: Set ABI, ISA and Code Model in top-level make
Anup Patel [Fri, 8 Feb 2019 07:17:01 +0000 (12:47 +0530)]
Makefile: Set ABI, ISA and Code Model in top-level make

This patch introduces following optional PLATFORM options:
PLATFORM_RISCV_XLEN -> RISC-V register width
PLATFORM_RISCV_ABI -> RISC-V GCC ABI
PLATFORM_RISCV_ISA -> RISC-V GCC ISA string
PLATFORM_RISCV_CODE_MODEL -> RISC-V GCC Code Model

If the above options are not provided by platform config.mk
or by command-line parameters then:
1. PLATFORM_RISCV_XLEN will be determined using toolchain
capability
2. PLATFORM_RISCV_ABI, PLATFORM_RISCV_ISA, and
PLATFORM_RISCV_CODE_MODEL is set to value best suited for
generic libsbi.a

As a result of these optional PLATFORM options, the
platform-cflags-y and platform-asflags-y is further
simplified for platform config.mk.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: qemu: Set FW_JUMP_ADDR and FW_PAYLOAD_OFFSET as-per XLEN
Anup Patel [Fri, 8 Feb 2019 04:43:07 +0000 (10:13 +0530)]
platform: qemu: Set FW_JUMP_ADDR and FW_PAYLOAD_OFFSET as-per XLEN

The current 4MB aligned FW_JUMP_ADDR and FW_PAYLOAD_OFFSET breaks
U-Boot on QEMU virt and sifive_u machines.

Instead of using 4MB aligned for both 32bit and 64bit systems, we
use different values based compiler XLEN. Another advantage of this
approach will be that our fw_payload.bin will smaller for 64bit
systems.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: template: Improve comments for FW_JUMP_ADDR and FW_PAYLOAD_OFFSET
Anup Patel [Fri, 8 Feb 2019 04:16:12 +0000 (09:46 +0530)]
platform: template: Improve comments for FW_JUMP_ADDR and FW_PAYLOAD_OFFSET

Both FW_JUMP_ADDR and FW_PAYLOAD_OFFSET, should be:
1. 4MB aligned for 32bit system
2. 2MB aligned for 64bit system

Explicitly specify the above details in config.mk comments
for template platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: improve library usage document
Damien Le Moal [Thu, 7 Feb 2019 09:41:50 +0000 (18:41 +0900)]
docs: improve library usage document

Clarify the libraries descriptions.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs: platform guide updates
Damien Le Moal [Thu, 7 Feb 2019 09:18:49 +0000 (18:18 +0900)]
docs: platform guide updates

Clarify platform support description.
Also fix some Typos, grammar and document style.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agotop: README.md updates
Damien Le Moal [Thu, 7 Feb 2019 09:11:41 +0000 (18:11 +0900)]
top: README.md updates

Clarify OpenSBI components explanation.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Ensure lgcc is included
Alistair Francis [Wed, 23 Jan 2019 22:38:21 +0000 (14:38 -0800)]
Makefile: Ensure lgcc is included

This fixes errors like this:
  undefined reference to `__umoddi3'
when buildilng for 32-bit systems

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agofirmware: Use lw instead of lwu for 32-bit architectures
Alistair Francis [Wed, 23 Jan 2019 17:29:55 +0000 (09:29 -0800)]
firmware: Use lw instead of lwu for 32-bit architectures

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform: clint: Allow running on 32-bit systems
Alistair Francis [Wed, 23 Jan 2019 00:50:50 +0000 (16:50 -0800)]
platform: clint: Allow running on 32-bit systems

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agosbi_emulate_csr: Shift sbi_timer_value directly
Alistair Francis [Fri, 18 Jan 2019 19:36:32 +0000 (11:36 -0800)]
sbi_emulate_csr: Shift sbi_timer_value directly

csr_val is a tartget length based variable, so on 32-bit devices it's
only 32-bits. To avoid clearing the entire register perform both steps
in a single line.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform: qemu/virt: Move kernel start address to 4MB alligned
Alistair Francis [Tue, 29 Jan 2019 17:59:31 +0000 (09:59 -0800)]
platform: qemu/virt: Move kernel start address to 4MB alligned

In order to support 32-bit guests move the start address to a 4MB
allignment. As 64-bit kernels have a requirement on being 2MB alligned
let's just make this the default for both 32 and 64 bit kernels.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform: template: Move kernel start address to 4MB alligned
Alistair Francis [Tue, 5 Feb 2019 21:51:32 +0000 (13:51 -0800)]
platform: template: Move kernel start address to 4MB alligned

In order to support 32-bit guests move the start address to a 4MB
allignment. As 64-bit kernels have a requirement on being 2MB alligned
let's just make this the default for both 32 and 64 bit kernels.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoplatform/qemu/virt: Dynamically calculate xlen
Alistair Francis [Fri, 18 Jan 2019 01:33:47 +0000 (17:33 -0800)]
platform/qemu/virt: Dynamically calculate xlen

The QEMU virt machine can be either 32 or 66 bit. Don't hard code the
CPU bit length and instead let the compiler determine it.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agosbi_ecall: Fix logical OR to be bitwise OR
Alistair Francis [Wed, 6 Feb 2019 22:02:22 +0000 (14:02 -0800)]
sbi_ecall: Fix logical OR to be bitwise OR

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agofirwmare: don't expand macros in FW_PAYLOAD_PATH
Andreas Schwab [Mon, 4 Feb 2019 14:05:36 +0000 (15:05 +0100)]
firwmare: don't expand macros in FW_PAYLOAD_PATH

Signed-off-by: Andreas Schwab <schwab@suse.de>
5 years agoMakefile: don't disable built-in variables
Andreas Schwab [Mon, 4 Feb 2019 11:48:26 +0000 (12:48 +0100)]
Makefile: don't disable built-in variables

Signed-off-by: Andreas Schwab <schwab@suse.de>
5 years agoMakefile: Don't rely on "echo -n"
Olof Johansson [Mon, 4 Feb 2019 02:48:43 +0000 (18:48 -0800)]
Makefile: Don't rely on "echo -n"

Turns out it doesn't behave as expected on MacOS, it doesn't honor
-n and echoes that to the file instead. Add a slash and just let
the newline be there instead.

Signed-off-by: Olof Johansson <olof@lixom.net>
5 years agoriscv_asm.h: Use CSR_<FOO> instead of <foo> for csr_read()
Olof Johansson [Mon, 4 Feb 2019 02:49:20 +0000 (18:49 -0800)]
riscv_asm.h: Use CSR_<FOO> instead of <foo> for csr_read()

Some toolchains might not have all the CSRs available (as seen with
GCC 7.2). So, instead use the defined CSR_ values.

Signed-off-by: Olof Johansson <olof@lixom.net>
5 years agodocs: Update doxygen config file v0.1
Anup Patel [Tue, 29 Jan 2019 12:30:36 +0000 (18:00 +0530)]
docs: Update doxygen config file

This patch updates doxygen config file to include
docs/platform_guide.md and docs/library_usage.md in
generated PDF document.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add library usage guide
Anup Patel [Tue, 29 Jan 2019 12:29:02 +0000 (17:59 +0530)]
docs: Add library usage guide

This patch adds static library usage guide (i.e.
docs/library_usage.md).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add platform support guide
Anup Patel [Tue, 29 Jan 2019 12:26:14 +0000 (17:56 +0530)]
docs: Add platform support guide

This patch adds initial platform support guide (i.e.
docs/platform_guide.md).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agotop: Fix typo in README.md
Anup Patel [Tue, 29 Jan 2019 12:24:17 +0000 (17:54 +0530)]
top: Fix typo in README.md

This patch renames <platform_sub_dir> to <platform_subdir> to be
consistent everywhere.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add a fu540 document.
Atish Patra [Sun, 27 Jan 2019 07:47:17 +0000 (23:47 -0800)]
docs: Add a fu540 document.

Add a readme guide for fu540 with different types of build & booting steps.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Typo fixes
Atish Patra [Sun, 27 Jan 2019 07:41:54 +0000 (23:41 -0800)]
docs: Typo fixes

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: fu540: Provide a compile time option selective hart booting.
Atish Patra [Thu, 24 Jan 2019 22:48:45 +0000 (14:48 -0800)]
platform: fu540: Provide a compile time option selective hart booting.

Currently, only hart 1 is enabled for fu540 platform to support U-boot.

Introduce a compile time FU540_ENABLED_HART_MASK option so that specific
harts can be selected for booting. As fu540 is a multicore, we should
boot all cores by default except hart 0.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoinclude: Add separate header for OpenSBI version
Anup Patel [Fri, 25 Jan 2019 05:49:22 +0000 (11:19 +0530)]
include: Add separate header for OpenSBI version

Currently, the OpenSBI version is in top-level Makefile so
firmware linking to OpenSBI static library have no-way to
know OpenSBI version.

This patch moves OpenSBI version from top-level Makefile to
sbi/sbi_version.h header which provides OPENSBI_VERSION_MAJOR
and OPENSBI_VERSION_MINOR defines.

NOTE: the SBI spec (or SBI ecall interface) version is
different. The SBI spec version is provided by functions
sbi_ecall_version_major() and sbi_ecall_version_minor().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: README.md update
Damien Le Moal [Wed, 23 Jan 2019 06:14:13 +0000 (15:14 +0900)]
docs: README.md update

Reformat to fit lines within 80 chars, fix hyperlinks, etc.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs/platform: Update QEMU platforms documentation
Damien Le Moal [Wed, 23 Jan 2019 15:56:44 +0000 (00:56 +0900)]
docs/platform: Update QEMU platforms documentation

Mostly reformating. Some minor edits.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs/platform: Add top level document file
Damien Le Moal [Thu, 24 Jan 2019 03:51:22 +0000 (12:51 +0900)]
docs/platform: Add top level document file

List supported platforms and point to the platform specific document.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs/firmware: Update FW_PAYLOAD documentation
Damien Le Moal [Wed, 23 Jan 2019 07:21:59 +0000 (16:21 +0900)]
docs/firmware: Update FW_PAYLOAD documentation

Reformatting, typos, and various corrections.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs/firmware: Update FW_JUMP documentation
Damien Le Moal [Wed, 23 Jan 2019 07:00:35 +0000 (16:00 +0900)]
docs/firmware: Update FW_JUMP documentation

Reformatting, typos, and various corrections.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs/firmware: Add top level document file
Damien Le Moal [Wed, 23 Jan 2019 14:48:42 +0000 (23:48 +0900)]
docs/firmware: Add top level document file

Provide an overview of all supported firmware files and point to each
firmware type documentation file.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agodocs: Contribution guideline update
Damien Le Moal [Tue, 22 Jan 2019 07:42:54 +0000 (16:42 +0900)]
docs: Contribution guideline update

Explicitely mention that this project adheres to the Developer
Certificate of Origin (DCO) and include this short text.

Also reformat the file to have lines bounded at 80 chars and add some
more details regarding the expected commit message format.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agotop: Rename LICENSE file to COPYING.BSD
Damien Le Moal [Wed, 23 Jan 2019 05:48:05 +0000 (14:48 +0900)]
top: Rename LICENSE file to COPYING.BSD

Also make sure that this file contains only the official BSD 2-clause
license text, nothing else.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoplatform: add template platform files
Damien Le Moal [Thu, 24 Jan 2019 07:56:47 +0000 (16:56 +0900)]
platform: add template platform files

Create commented template files to use as a base for new platforms
support implementation.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoall: Update copyright header in all files
Anup patel [Thu, 24 Jan 2019 06:11:10 +0000 (11:41 +0530)]
all: Update copyright header in all files

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>
5 years agoinclude: Use TRUE/FALSE as return values in sbi_platform_hart_disabled()
Anup Patel [Wed, 23 Jan 2019 03:30:35 +0000 (09:00 +0530)]
include: Use TRUE/FALSE as return values in sbi_platform_hart_disabled()

The sbi_platform_hart_disabled() returns bool hence explicitly return
TRUE or FALSE instead of 1 or 0.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Rename ipi_inject() to ipi_send() for sbi_platform
Anup Patel [Wed, 23 Jan 2019 02:43:29 +0000 (08:13 +0530)]
include: Rename ipi_inject() to ipi_send() for sbi_platform

For better naming, we rename ipi_inject() to ipi_send() in
struct sbi_platform. We also replace term "inject" with
"send" in all related places.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Drop MMIO from SBI_PLATFORM_HAS_MMIO_TIMER_VALUE
Anup Patel [Wed, 23 Jan 2019 02:33:20 +0000 (08:03 +0530)]
include: Drop MMIO from SBI_PLATFORM_HAS_MMIO_TIMER_VALUE

It is not necessary that platform has MMIO-based timer value
register. It can also have some custom (implementation specific)
CSR for timer value.

This patch renames SBI_PLATFORM_HAS_MMIO_TIMER_VALUE to
SBI_PLATFORM_HAS_TIMER_VALUE to imply "platform timer value"
instead of "mmio timer value".

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Update documentation of sbi_platform after callback cleanup
Anup Patel [Tue, 22 Jan 2019 09:21:38 +0000 (14:51 +0530)]
include: Update documentation of sbi_platform after callback cleanup

The prototypes of sbi_platform callbacks have changed hence we
update related documentation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove target_hart and hartid parameter from TIMER callbacks
Anup Patel [Tue, 22 Jan 2019 09:17:03 +0000 (14:47 +0530)]
lib: Remove target_hart and hartid parameter from TIMER callbacks

The target_hart and hartid paramter of TIMER callbacks is not
required because it always current hartid which can be obtained
using sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove hartid parameter from IRQCHIP callbacks
Anup Patel [Tue, 22 Jan 2019 09:03:41 +0000 (14:33 +0530)]
lib: Remove hartid parameter from IRQCHIP callbacks

The hartid parameter in IRQCHIP callbacks of sbi_platform
is not required because current hartid can be determined
using sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove source_hart and hartid parameter from IPI callbacks
Anup patel [Tue, 22 Jan 2019 08:50:59 +0000 (14:20 +0530)]
lib: Remove source_hart and hartid parameter from IPI callbacks

The source_hart and hartid parameter is really not required in
IPI callbacks of sbi_platform because current hartid can always
be obtained by calling sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove hartid paramter from early_init() and final_init() callbacks
Anup Patel [Tue, 22 Jan 2019 08:22:25 +0000 (13:52 +0530)]
lib: Remove hartid paramter from early_init() and final_init() callbacks

We simplify early_init() and final_init() callbacks of sbi_platform
by removing "hartid" parameter.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Typo fixes.
Atish Patra [Mon, 21 Jan 2019 08:01:23 +0000 (00:01 -0800)]
docs: Typo fixes.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Fix nits in firmware/fw_jump.md
Bin Meng [Mon, 21 Jan 2019 14:29:59 +0000 (22:29 +0800)]
docs: Fix nits in firmware/fw_jump.md

Add a space before (FW_JUMP) to make it more readable.

This also fixes "No newline at end of file" warning.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
5 years agotop: Fix broken links in top-level README.md
Bin Meng [Mon, 21 Jan 2019 14:14:16 +0000 (22:14 +0800)]
top: Fix broken links in top-level README.md

There are 2 markdown links that are currently broken in top-level
README.md. Fix them so that github could render the URL correctly.

This also fixes "No newline at end of file" warning.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
5 years agolib: Add doxygen style documentation for sbi_platform
Anup Patel [Mon, 21 Jan 2019 17:53:23 +0000 (23:23 +0530)]
lib: Add doxygen style documentation for sbi_platform

This patch adds doxygen style documenation for struct sbi_platform
and related functions/macros/defines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Update documentation of sbi_init()
Anup Patel [Tue, 22 Jan 2019 05:36:31 +0000 (11:06 +0530)]
lib: Update documentation of sbi_init()

We don't need to pre-enable MSIP in MIE CSR when
calling sbi_init() from firmware. This patch updates
documentation accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMakefile: Don't install generic headers under <install_dir>/platform
Anup Patel [Mon, 21 Jan 2019 05:35:36 +0000 (11:05 +0530)]
Makefile: Don't install generic headers under <install_dir>/platform

We don't need to install generic headers separately for every
platforn under <install_dir>/platform. It is unnecessary duplication
of files hence updating install_libplatsbi in top-level makefile.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add OpenSBI version to doxygen.cfg
Anup Patel [Mon, 21 Jan 2019 05:31:14 +0000 (11:01 +0530)]
docs: Add OpenSBI version to doxygen.cfg

The PDF document generated by doxygen should have OpenSBI version
hence this patch adds OpenSBI version to doxygen.cfg.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Do not access mi/edeleg register if S mode is not present.
Atish Patra [Tue, 22 Jan 2019 02:17:45 +0000 (18:17 -0800)]
lib: Do not access mi/edeleg register if S mode is not present.

As per the RISC-V ISA, mideleg and medeleg registers should not exist
if S-mode is not present for a hart.

We shouldn't access these CSRs if non S-mode harts.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Allow sending IPI to self.
Atish Patra [Tue, 22 Jan 2019 01:54:00 +0000 (17:54 -0800)]
lib: Allow sending IPI to self.

S-mode software may send IPI to self. For example,
tlbflush may be executed for the same hart.

Let the hart send IPI to itself. It's an overhead
but doesn't break anything. However, if we don't
allow it, it breaks if S-mode keep sending IPIs.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Fix ipi type update
Atish Patra [Mon, 21 Jan 2019 07:24:26 +0000 (23:24 -0800)]
lib: Fix ipi type update

IPIs are updated in scratch space by source hart.
However, different harts or same hart may want to
send different IPIs before previous IPI was read
by the target hart. Currently, previous IPI type
is overwritten in that case.

Use atomic bit set/clear operations to update IPIs.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Add atomic bit set/clear operations.
Atish Patra [Mon, 21 Jan 2019 07:23:28 +0000 (23:23 -0800)]
lib: Add atomic bit set/clear operations.

Add addtional functionlities for set/clear bits
atomically.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Move software interrupt enablement from firmware to lib
Atish Patra [Fri, 18 Jan 2019 21:35:47 +0000 (13:35 -0800)]
lib: Move software interrupt enablement from firmware to lib

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>
5 years agolib: Use AMO instructions whenever __riscv_atomic is defined
Anup Patel [Mon, 21 Jan 2019 11:23:46 +0000 (16:53 +0530)]
lib: Use AMO instructions whenever __riscv_atomic is defined

We should use AMO instructions whenever __riscv_atomic is
defined (i.e. atomics are supported). We use LR/SC only when
__riscv_atomic is not defined.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agosbi: Add ecall helpers
Damien Le Moal [Fri, 18 Jan 2019 07:28:32 +0000 (16:28 +0900)]
sbi: Add ecall helpers

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>
5 years agopayload: rename dummy payload to test payload
Damien Le Moal [Fri, 18 Jan 2019 07:09:14 +0000 (16:09 +0900)]
payload: rename dummy payload to test payload

Use a more neutral term more representative of this payload intent.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agokendryte/k210: Add device tree support
Damien Le Moal [Mon, 14 Jan 2019 04:00:37 +0000 (13:00 +0900)]
kendryte/k210: Add device tree support

The Kendryte k210 board initial loader does not provide a device tree
for the firmware and subsequent payload. Add the k210.dts device tree
description file to solve this. This file describes only the SoC core
components: CPUs, memory and PLIC.

Automatically compile and add this file to the firmware generated
using the FW_PAYLOAD_FDT_PATH configuration parameter.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agokendryte/k210: Fix console
Damien Le Moal [Fri, 18 Jan 2019 04:46:31 +0000 (13:46 +0900)]
kendryte/k210: Fix console

Clear console input when intializing it.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Improve readability
Damien Le Moal [Fri, 18 Jan 2019 06:57:31 +0000 (15:57 +0900)]
Makefile: Improve readability

Repeating "ifdef CROSS_COMPILE" multiple times does not help with
readability. Simplify by grouping compilation command setup under a
single ifdef statement.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>