Git Product home page Git Product logo

opensbi's Introduction

RISC-V Open Source Supervisor Binary Interface (OpenSBI)

RISC-V OpenSBI

Copyright and License

The OpenSBI project is:

  • Copyright (c) 2019 Western Digital Corporation or its affiliates
  • Copyright (c) 2023 RISC-V International

It is distributed under the terms of the BSD 2-clause license ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). A copy of this license with OpenSBI copyright can be found in the file COPYING.BSD.

All source files in OpenSBI contain the 2-Clause BSD license SPDX short identifier in place of the full license text.

SPDX-License-Identifier:    BSD-2-Clause

This enables machine processing of license information based on the SPDX License Identifiers that are available on the SPDX web site.

OpenSBI source code also contains code reused from other projects as listed below. The original license text of these projects is included in the source files where the reused code is present.

  • The libfdt source code is disjunctively dual licensed (GPL-2.0+ OR BSD-2-Clause). Some of this project code is used in OpenSBI under the terms of the BSD 2-Clause license. Any contributions to this code must be made under the terms of both licenses.

See also the third party notices file for more information.

Introduction

The RISC-V Supervisor Binary Interface (SBI) is the recommended interface between:

  1. A platform-specific firmware running in M-mode and a bootloader, a hypervisor or a general-purpose OS executing in S-mode or HS-mode.
  2. A hypervisor running in HS-mode and a bootloader or a general-purpose OS executing in VS-mode.

The RISC-V SBI specification is maintained as an independent project by the RISC-V Foundation on Github.

The goal of the OpenSBI project is to provide an open-source reference implementation of the RISC-V SBI specifications for platform-specific firmwares executing in M-mode (case 1 mentioned above). An OpenSBI implementation can be easily extended by RISC-V platform and system-on-chip vendors to fit a particular hardware configuration.

The main component of OpenSBI is provided in the form of a platform-independent static library libsbi.a implementing the SBI interface. A firmware or bootloader implementation can link against this library to ensure conformance with the SBI interface specifications. libsbi.a also defines an interface for integrating with platform-specific operations provided by the platform firmware implementation (e.g. console access functions, inter-processor interrupt control, etc).

To illustrate the use of the libsbi.a library, OpenSBI also provides a set of platform-specific support examples. For each example, a platform-specific static library libplatsbi.a can be compiled. This library implements SBI call processing by integrating libsbi.a with the necessary platform-dependent hardware manipulation functions. For all supported platforms, OpenSBI also provides several runtime firmware examples built using the platform libplatsbi.a. These example firmwares can be used to replace the legacy riscv-pk bootloader (aka BBL) and enable the use of well-known bootloaders such as U-Boot.

Supported SBI version

Currently, OpenSBI fully supports SBI specification v0.2. OpenSBI also supports Hart State Management (HSM) SBI extension starting from OpenSBI v0.7. HSM extension allows S-mode software to boot all the harts a defined order rather than legacy method of random booting of harts. As a result, many required features such as CPU hotplug, kexec/kdump can also be supported easily in S-mode. HSM extension in OpenSBI is implemented in a non-backward compatible manner to reduce the maintenance burden and avoid confusion. That's why, any S-mode software using OpenSBI will not be able to boot more than 1 hart if HSM extension is not supported in S-mode.

Linux kernel already supports SBI v0.2 and HSM SBI extension starting from v5.7-rc1. If you are using an Linux kernel older than 5.7-rc1 or any other S-mode software without HSM SBI extension, you should stick to OpenSBI v0.6 to boot all the harts. For a UMP systems, it doesn't matter.

N.B. Any S-mode boot loader (i.e. U-Boot) doesn't need to support HSM extension, as it doesn't need to boot all the harts. The operating system should be capable enough to bring up all other non-booting harts using HSM extension.

Required Toolchain and Packages

OpenSBI can be compiled natively or cross-compiled on a x86 host. For cross-compilation, you can build your own toolchain, download a prebuilt one from the Bootlin toolchain repository or install a distribution-provided toolchain; if you opt to use LLVM/Clang, most distribution toolchains will support cross-compiling for RISC-V using the same toolchain as your native LLVM/Clang toolchain due to LLVM's ability to support multiple backends in the same binary, so is often an easy way to obtain a working cross-compilation toolchain.

Basically, we prefer toolchains with Position Independent Executable (PIE) support like riscv64-linux-gnu-gcc, riscv64-unknown-freebsd-gcc, or Clang/LLVM as they generate PIE firmware images that can run at arbitrary address with appropriate alignment. If a bare-metal GNU toolchain (e.g. riscv64-unknown-elf-gcc) is used, static linked firmware images are generated instead. Clang/LLVM can still generate PIE images if a bare-metal triple is used (e.g. -target riscv64-unknown-elf).

Please note that only a 64-bit version of the toolchain is available in the Bootlin toolchain repository for now.

In addition to a toolchain, OpenSBI also requires the following packages on the host:

  1. device-tree-compiler: The device tree compiler for compiling device tree sources (DTS files).
  2. python3: The python 3.0 (or compatible) language support for various scripts.

Building and Installing the OpenSBI Platform-Independent Library

The OpenSBI platform-independent static library libsbi.a can be compiled natively or it can be cross-compiled on a host with a different base architecture than RISC-V.

For cross-compiling, the environment variable CROSS_COMPILE must be defined to specify the name prefix of the RISC-V compiler toolchain executables, e.g. riscv64-linux-gnu- if the gcc executable used is riscv64-linux-gnu-gcc.

To build libsbi.a simply execute:

make

All compiled binaries as well as the resulting libsbi.a static library file will be placed in the build/lib directory. To specify an alternate build root directory path, run:

make O=<build_directory>

To generate files to be installed for using libsbi.a in other projects, run:

make install

This will create the install directory with all necessary include files copied under the install/include directory and the library file copied into the install/lib directory. To specify an alternate installation root directory path, run:

make I=<install_directory> install

Building and Installing a Reference Platform Static Library and Firmware

When the PLATFORM=<platform_subdir> argument is specified on the make command line, the platform-specific static library libplatsbi.a and firmware examples are built for the platform <platform_subdir> present in the directory platform in the OpenSBI top directory. For example, to compile the platform library and the firmware examples for the QEMU RISC-V virt machine, <platform_subdir> should be generic.

To build libsbi.a, libplatsbi.a and the firmware for one of the supported platforms, run:

make PLATFORM=<platform_subdir>

An alternate build directory path can also be specified:

make PLATFORM=<platform_subdir> O=<build_directory>

The platform-specific library libplatsbi.a will be generated in the build/platform/<platform_subdir>/lib directory. The platform firmware files will be under the build/platform/<platform_subdir>/firmware directory. The compiled firmwares will be available in two different formats: an ELF file and an expanded image file.

To install libsbi.a, libplatsbi.a, and the compiled firmwares, run:

make PLATFORM=<platform_subdir> install

This will copy the compiled platform-specific libraries and firmware files under the install/platform/<platform_subdir>/ directory. An alternate install root directory path can be specified as follows:

make PLATFORM=<platform_subdir> I=<install_directory> install

In addition, platform-specific configuration options can be specified with the top-level make command line. These options, such as PLATFORM_ or FW_, are platform-specific and described in more details in the docs/platform/<platform_name>.md files and docs/firmware/<firmware_name>.md files.

All OpenSBI platforms support Kconfig style build-time configuration. Users can change the build-time configuration of a platform using a graphical interface as follows:

make PLATFORM=<platform_subdir> menuconfig

Alternately, an OpenSBI platform can have multiple default configurations and users can select a custom default configuration as follows:

make PLATFORM=<platform_subdir> PLATFORM_DEFCONFIG=<platform_custom_defconfig>

Building 32-bit / 64-bit OpenSBI Images

By default, building OpenSBI generates 32-bit or 64-bit images based on the supplied RISC-V cross-compile toolchain. For example if CROSS_COMPILE is set to riscv64-linux-gnu-, 64-bit OpenSBI images will be generated. If building 32-bit OpenSBI images, CROSS_COMPILE should be set to a toolchain that is pre-configured to generate 32-bit RISC-V codes, like riscv32-linux-gnu-.

However it's possible to explicitly specify the image bits we want to build with a given RISC-V toolchain. This can be done by setting the environment variable PLATFORM_RISCV_XLEN to the desired width, for example:

export CROSS_COMPILE=riscv64-linux-gnu-
export PLATFORM_RISCV_XLEN=32

will generate 32-bit OpenSBI images. And vice vesa.

Building with Clang/LLVM

OpenSBI can also be built with Clang/LLVM. To build with just Clang but keep the default binutils (which will still use the CROSS_COMPILE prefix if defined), override the CC make variable with:

make CC=clang

To build with a full LLVM-based toolchain, not just Clang, enable the LLVM option with:

make LLVM=1

When using Clang, CROSS_COMPILE often does not need to be defined unless using GNU binutils with prefixed binary names. PLATFORM_RISCV_XLEN will be used to infer a default triple to pass to Clang, so if PLATFORM_RISCV_XLEN itself defaults to an undesired value then prefer setting that rather than the full triple via CROSS_COMPILE. If CROSS_COMPILE is nonetheless defined, rather than being used as a prefix for the executable name, it will instead be passed via the --target option with the trailing - removed, so must be a valid triple.

These can also be mixed; for example using a GCC cross-compiler but LLVM binutils would be:

make CC=riscv64-linux-gnu-gcc LLVM=1

These variables must be passed for all the make invocations described in this document.

NOTE: Using Clang with a riscv*-linux-gnu GNU binutils linker has been seen to produce broken binaries with missing relocations; it is therefore currently recommended that this combination be avoided.

Building with timestamp and compiler info

When doing development, we may want to know the build time and compiler info for debug purpose. OpenSBI can also be built with timestamp and compiler info. To build with those info and print it out at boot time, we can just simply add BUILD_INFO=y, like:

make BUILD_INFO=y

But if you have used BUILD_INFO=y, and want to switch back to BUILD_INFO=n, you must do

make clean

before the next build.

NOTE: Using BUILD_INFO=y without specifying SOURCE_DATE_EPOCH will violate reproducible builds. This definition is ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds".

Building with optimization off for debugging

When debugging OpenSBI, we may want to turn off the compiler optimization and make debugging produce the expected results for a better debugging experience. To build with optimization off we can just simply add DEBUG=1, like:

make DEBUG=1

This definition is ONLY for development and debug purpose, and should NOT be used in a product build.

Contributing to OpenSBI

The OpenSBI project encourages and welcomes contributions. Contributions should follow the rules described in the OpenSBI Contribution Guideline document. In particular, all patches sent should contain a Signed-off-by tag.

The Contributors List document provides a list of individuals and organizations actively contributing to the OpenSBI project.

Documentation

Detailed documentation of various aspects of OpenSBI can be found under the docs directory. The documentation covers the following topics.

OpenSBI source code is also well documented. For source level documentation, doxygen style is used. Please refer to the Doxygen manual for details on this format.

Doxygen can be installed on Linux distributions using .deb packages using the following command.

sudo apt-get install doxygen doxygen-latex doxygen-doc doxygen-gui graphviz

For .rpm based Linux distributions, the following commands can be used.

sudo yum install doxygen doxygen-latex doxywizard graphviz

or

sudo yum install doxygen doxygen-latex doxywizard graphviz

To build a consolidated refman.pdf of all documentation, run:

make docs

or

make O=<build_directory> docs

the resulting refman.pdf will be available under the directory <build_directory>/docs/latex. To install this file, run:

make install_docs

or

make I=<install_directory> install_docs

refman.pdf will be installed under <install_directory>/docs.

opensbi's People

Contributors

alistair23 avatar atishp04 avatar avpatel avatar clementleger avatar covanam avatar damien-lemoal avatar ddnirvana avatar dramforever avatar ganboing avatar guoren83 avatar hschauhan avatar inochisa avatar ivanorlov2206 avatar johnazoidberg avatar jones-drew avatar jrtc27 avatar lbmeng avatar lyctw avatar maquefel avatar mardteabk201 avatar mdchitale avatar mickflemm avatar olofj avatar pathakraul avatar prabhakarlad avatar remes-codasip avatar sifiveholland avatar smaeul avatar wxjstz avatar xypron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opensbi's Issues

cannot reboot the system

i am using Linux 5.0 kernel and opensbi, i found it cannot reboot:

root@: ~# reboot
[ OK ] Closed LVM2 poll daemon socket.
[ OK ] Stopped target Timers.
[ OK ] Stopped Daily apt upgrade and clean activities.
[ OK ] Stopped target Graphical Interface.
[ OK ] Stopped Daily rotation of log files.
[ OK ] Stopped target Multi-User System.
Stopping Regular background program processing daemon...
[ OK ] Stopped Periodic ext4 Onli…ata Check for All Filesystems.
[ OK ] Stopped Daily apt download activities.
[ OK ] Stopped target System Time Synchronized.
[ OK ] Stopped target Login Prompts.
Stopping Getty on tty1...
[ OK ] Stopped getty on tty2-tty6… and logind are not available.
Stopping Getty on tty5...
Stopping Serial Getty on hvc0...
Stopping Getty on tty3...
Stopping Getty on tty4...
Stopping Getty on tty6...
Stopping Getty on tty2...
[ OK ] Stopped Daily Cleanup of Temporary Directories.
Stopping Serial Getty on ttyS0...
Stopping Availability of block devices...
[ OK ] Stopped Regular background program processing daemon.
[ OK ] Stopped Getty on tty2.
[ OK ] Stopped Serial Getty on hvc0.
[ OK ] Stopped Getty on tty1.
[ OK ] Stopped Serial Getty on ttyS0.
[ OK ] Stopped Getty on tty3.
[ OK ] Stopped Getty on tty4.
[ OK ] Stopped Getty on tty5.
[ OK ] Stopped Getty on tty6.
[ OK ] Removed slice system-serial\x2dgetty.slice.
[ OK ] Removed slice system-getty.slice.
Stopping Permit User Sessions...
[ OK ] Stopped Availability of block devices.
[ OK ] Stopped Permit User Sessions.
[ OK ] Stopped target Network.
Stopping ifup for eth0...
Stopping Raise network interfaces...
[ OK ] Stopped target Basic System.
[ OK ] Stopped target Slices.
[ OK ] Stopped target Paths.
[ OK ] Stopped target Sockets.
[ OK ] Stopped target Remote File Systems.
[ OK ] Stopped target System Initialization.
Stopping Load/Save Random Seed...
[ OK ] Stopped target Swap.
[ OK ] Stopped target Local Encrypted Volumes.
[ OK ] Stopped Forward Password R…uests to Wall Directory Watch.
[ OK ] Stopped Dispatch Password …ts to Console Directory Watch.
Stopping Update UTMP about System Boot/Shutdown...
Stopping Network Time Synchronization...
[ OK ] Stopped Network Time Synchronization.
[ OK ] Stopped Raise network interfaces.
[ OK ] Stopped Load/Save Random Seed.
[ OK ] Stopped Update UTMP about System Boot/Shutdown.
[ OK ] Stopped Create Volatile Files and Directories.
[ OK ] Stopped ifup for eth0.
[ OK ] Stopped Apply Kernel Variables.
[ OK ] Stopped Load Kernel Modules.
[ OK ] Stopped target Local File Systems.
Unmounting /mnt...
[ OK ] Unmounted /mnt.
[ OK ] Reached target Unmount All Filesystems.
[ OK ] Stopped target Local File Systems (Pre).
[ OK ] Stopped Create Static Device Nodes in /dev.
[ OK ] Stopped Create System Users.
[ OK ] Stopped Remount Root and Kernel File Systems.
[ OK ] Reached target Shutdown.
[ OK ] Reached target Final Step.
[ OK ] Started Reboot.
[ OK ] Reached target Reboot.
Stopping Monitoring of LVM…meventd or progress polling...
[ 64.117212] printk: systemd-shutdow: 28 output lines suppressed due to ratelimiting
[ 64.997467] systemd-shutdown[1]: Syncing filesystems and block devices.
[ 65.155286] systemd-shutdown[1]: Sending SIGTERM to remaining processes...
[ 65.214518] systemd-journald[86]: Received SIGTERM from PID 1 (systemd-shutdow).
[ 65.239998] systemd-shutdown[1]: Sending SIGKILL to remaining processes...
[ 65.296737] systemd-shutdown[1]: Unmounting file systems.
[ 65.314410] [265]: Remounting '/' read-only in with options '(null)'.
[ 65.438658] EXT4-fs (vda): re-mounted. Opts: (null)
[ 65.460945] systemd-shutdown[1]: All filesystems unmounted.
[ 65.461367] systemd-shutdown[1]: Deactivating swaps.
[ 65.462366] systemd-shutdown[1]: All swaps deactivated.
[ 65.462689] systemd-shutdown[1]: Detaching loop devices.
[ 65.498962] systemd-shutdown[1]: All loop devices detached.
[ 65.499464] systemd-shutdown[1]: Detaching DM devices.
[ 65.536748] reboot: Restarting system
[ 86.532464] rcu: INFO: rcu_sched self-detected stall on CPU
[ 86.533065] rcu: 0-....: (5249 ticks this GP) idle=702/1/0x4000000000000002 softirq=16275/16275 fqs=2614
[ 86.533453] rcu: (t=5250 jiffies g=9509 q=18)
[ 86.533891] Task dump for CPU 0:
[ 86.534165] systemd-shutdow R running task 0 1 0 0x00000008
[ 86.534537] Call Trace:
[ 86.534754] [] walk_stackframe+0x0/0x156
[ 86.535037] [] show_stack+0x30/0x3a
[ 86.535292] [] sched_show_task+0x408/0x41e
[ 86.535564] [] dump_cpu_task+0x58/0x62
[ 86.535824] [] rcu_dump_cpu_stacks+0x9e/0x110
[ 86.536182] [] print_cpu_stall+0x1f0/0x438
[ 86.536660] [] check_cpu_stall+0x4fe/0x594
[ 86.536930] [] rcu_pending+0x46/0x28c
[ 86.537183] [] rcu_check_callbacks+0x206/0x224
[ 86.537464] [] update_process_times+0x30/0x110
[ 86.537737] [] tick_periodic+0x202/0x212
[ 86.537993] [] tick_handle_periodic+0x28/0x98
[ 86.538264] [] riscv_timer_interrupt+0x50/0x5a
[ 86.538582] [] do_IRQ+0xd4/0x1a2
[ 86.538869] [] ret_from_exception+0x0/0xc
[ 86.539143] [] machine_restart+0x14/0x16

Can opensbi support smp directly? without uboot

I try to boot linux using opensbi directly.
one core: success
8cores:
[ 0.000992] smp: Bringing up secondary CPUs …
[ 1.057750] CPU1: failed to come online
.....
only one core can work..

delegate_traps requires medeleg[0] to be writable

In section 3.1.8, the privileged architecture spec says:

An implementation can choose to subset the delegatable traps, with the supported delegatable bits found by writing one to every bit location, then reading back the value in medeleg or mideleg to see which bit positions hold a one.

Presumably, an implementation can hard-wire medeleg to 0.

The delegate_traps function assumes that various traps are delegatable and are not hard-wired to 0 (at minimum: misaligned fetches, breakpoints, and user ecalls). If any of the bits that it wants to delegate are hard-wired to 0 then it will return a failure which prevents that hart from booting.

I can understand that there are some minimum requirements for OpenSBI to run (such as misa being implemented and possibly breakpoints and user ecalls being delegatable, though I can't find these requirements documented anywhere). However...

The privileged spec says:

For exceptions that cannot occur in less privileged modes, the corresponding medeleg bits should be hardwired to zero.

and the unprivileged spec says:

With the addition of the C extension, no instructions can raise instruction-address-misaligned exceptions.

So if misa.C is hard-wired to 1 then the spec says that medeleg[0] should be hard-wired to 0 but OpenSBI requires that bit to be writable. To resolve the conflict, I think that OpenSBI should only require medeleg[0] to be writable in implementations where misa.C can be 0.

This was found by inspection so it's possible that I'm missing something.

Which UBoot branch against which openSBI branch

Hi,

As there was quite a few (incompatible) changes in the way SMP core come to life between opensbi 0.6 and openSBI master, i'm not sure which u-boot branch/hash work with opensbi 0.6.

Any idea ? Else how such information can found ?

Regards
Charles

fw_payload.o(.text+0x1961): 15 bytes required for alignment to 16-byte boundary, but only 14 present

I have updated binutils to 2.33.1 in Fedora 32/Rawhide and looks like I cannot recompile opensbi (there are no changes compared to F31 build).

BUILDSTDERR: /usr/bin/ld: /builddir/build/BUILD/opensbi-be92da280d87c38a2e0adc5d3f43bab7b5468f09/fedora-builds/uboot-sifive-fu540/build/platform/sifive/fu540/firmware/fw_payload.o(.text+0x1961): 15 bytes required for alignment to 16-byte boundary, but only 14 present
BUILDSTDERR: /usr/bin/ld: can't relax section: bad value
BUILDSTDERR: collect2: error: ld returned 1 exit status
BUILDSTDERR: make: *** [Makefile:278: /builddir/build/BUILD/opensbi-be92da280d87c38a2e0adc5d3f43bab7b5468f09/fedora-builds/uboot-sifive-fu540/build/platform/sifive/fu540/firmware/fw_payload.elf] Error 1

Other changes between F31 and F32 today is kernel (5.3 vs master branch) and glibc (2.30 vs master branch).

PMP access failure

On SiFive FU540, OpenSBI sets up the PMP regions as follows:

PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0x0000007fffffffff (A,R,W,X)

With above settings, when booting my kernel, I got:

sbi_trap_error: hart1: trap handler failed (error -5)
sbi_trap_error: hart1: mcause=0x0000000000000001 mtval=0xffffffff80200034
sbi_trap_error: hart1: mepc=0xffffffff80200034 mstatus=0x8000000a00006900
sbi_trap_error: hart1: ra=0x0000000080200032 sp=0x00000000ff798c40
sbi_trap_error: hart1: gp=0x00000000ff79ce70 tp=0x0000000000000001
sbi_trap_error: hart1: s0=0x0000000000000001 s1=0x00000000ff7991f0
sbi_trap_error: hart1: a0=0x0000000030000000 a1=0x00000000ff7991f0
sbi_trap_error: hart1: a2=0x8000000000000000 a3=0x0000000000000007
sbi_trap_error: hart1: a4=0x0000000000000000 a5=0x0000000000002c6a
sbi_trap_error: hart1: a6=0x0000000000000006 a7=0x00000000ff79d6be
sbi_trap_error: hart1: s2=0x00000000fff9ebc2 s3=0xffffffff00000000
sbi_trap_error: hart1: s4=0x0000000000000003 s5=0x00000000ff7a5c88
sbi_trap_error: hart1: s6=0x00000000fffebdb8 s7=0x0000000000000000
sbi_trap_error: hart1: s8=0x0000000000000000 s9=0x0000000000000000
sbi_trap_error: hart1: s10=0x0000000084000040 s11=0x0000000084979a78
sbi_trap_error: hart1: t0=0x8000000000080b4e t1=0x0000000040000000
sbi_trap_error: hart1: t2=0x0000000000000ff0 t3=0x0000000080b4eff8
sbi_trap_error: hart1: t4=0x00000000300000cf t5=0x0000000080000000
sbi_trap_error: hart1: t6=0x000000000000001e

From above log, both mepc and mtval point to 0xffffffff80200034, and this is the location where stvec is programmed. My codes is supposed to jump to stevc after satp is programmed with valid page tables. Both mstatus.MPP and mstatus.SPP is set to S-mode, so what happened is that after satp is written, the next instruction will immediately trap to stvec (mstatus.SPP <= 1), but at the same time, another exception trapped when trying to read instructions from stvec (mstatus.MPP <= 1)

After I changed OpenSBI to not program the PMP region 0 for the firmware image, like below:

PMP0: 0x0000000000000000-0x0000007fffffffff (A,R,W,X)

Then my kernel successfully boots.

So it seems that accessing 0xffffffff80200034 somehow falls into the access check of PMP region 0. But its address is not in the range at all. I can't figure out why this is the case.

Dynamic IPI registration

Hi,

I have another question regarding PMP.
Currently, I see that PMP is initialized at sbi_hart_init(), which is one-time called per-hart at boot.

Keystone Enclave uses PMP for dynamic memory isolation, and all of the PMP entries in all cores must be synchronized when an enclave is created/destroyed.

In bbl version of keystone, we have done it by adding a custom IPl, where one core initiates the IPI to update PMP entries and then waits until all the other cores finishes updating PMP.

I see there is no way for now to cleanly add a custom IPI without changing the core functions like sbi_ipi_process().
Do you have any suggestions on what would be the best way to add this?

libsbi documentation

We need to have a document that explains following. As mentioned in the README guide, it should be put at docs/library_usage.md.

  1. What is libsbi. (Readme already has enough details. May be move some stuff)
  2. Mandatory API & its description.
  3. An template or example would be nice as well.

We need this before we make the repo public.

Code logic problem (coldboot/warmboot)

static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0);

void __noreturn sbi_init(struct sbi_scratch *scratch)
{
	bool coldboot = FALSE;
	u32 hartid = sbi_current_hartid();
	const struct sbi_platform *plat = sbi_platform_ptr(scratch);

	if (sbi_platform_hart_disabled(plat, hartid))
		sbi_hart_hang();
		
	if (atomic_add_return(&coldboot_lottery, 1) == 1)
		coldboot = TRUE;

	if (coldboot)
		init_coldboot(scratch, hartid);
	else
		init_warmboot(scratch, hartid);
}

These codes cannot determine coldboot or warmboot.

These codes can only be used to select one processor to perform common tasks.

What is the true meaning of these codes?

If it is coldboot/warmboot, coldboot_lottery should not be a static variable, it should be a reserved memory, because the program will be reloaded under normal circumstances, the value will be reset when warmboot.

If it is select a processor to perform common tasks. The naming of these codes is strange.

How to payload elf for debug using?

I'm trying to debug my own program boatloaded by OpenSBI with FW_PAYLOAD.
currently binary can be payloaded by OpenSBI with FW_PAYLOAD.
If I wanna connect my FPGA to debug this program with gdb elf, how can I do?

it cannot load the kernel

i am using linux 5.0 kernel, but it canot load the kernel on qemu, what is the problem?

figo@figo-OptiPlex-9020: linux 5.0$ qemu-system-riscv64 -machine virt -kernel opensbi/build/platform/qemu/virt/firmware/fw_jump.elf -device loader,file=arch/riscv/boot/Image,addr=0x80200000 -nographic --append "rdinit=/linuxrc console=ttyAMA0"
qemu-system-riscv64: plic: invalid register write: 000001fc

OpenSBI v0.3 (Apr 25 2019 05:45:54)


/ __ \ / | _ _ |
| | | |
__ ___ _ __ | (
| |
) || |
| | | | '_ \ / _ \ '_ \ ___ | _ < | |
| || | |) | __/ | | |) | |) || |
_
/| ./ _|| ||/|____/|
| |
|_|

Platform Name : QEMU Virt Machine
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs : 8
Current Hart : 0
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.1

PMP0: 0x0000000080000000-0x000000008001ffff (A)
PMP1: 0x0000000000000000-0xffffffffffffffff (A,R,W,X)

make docs fails

I tried make docs after installing required packages. Here are the errors I got.

! Package inputenc Error: Unicode char ‑ (U+2011)
(inputenc) not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type H for immediate help.
...

l.1 ... world’s first 4+1 64-/bit R+I+S+C‑
V SoC from Si+Five. The H...

?

We should also release a refman.pdf.

Publish RISC-V OpenSBI spec somewhere in OpenSBI repo

In order to standardize the incorporation of OpenSBI on RISC-V UEFI port in UEFI Platform Initialization spec, we need to public RISC-C OpenSBI spec somewhere in OpenSBI repo. So we can put the external references to RISC-V OpenSBI repo as the reference of sbi_scratch and sbi_platform structure in PI spec.

MSIP is supposed to be read-only in MIP?

https://github.com/riscv/opensbi/blob/a6395acd6cb2c35871481d3e4f0beaf449f8c0fd/lib/sbi_hart.c#L351

riscv-privileged-20190405: The mip register is an MXLEN-bit read/write register containing information on pending interrupts, while mie is the corresponding MXLEN-bit read/write register containing interrupt enable bits. Only the bits corresponding to lower-privilege software interrupts (USIP, SSIP), timer interrupts (UTIP, STIP), and external interrupts (UEIP, SEIP) in mip are writable through this CSR address; the remaining bits are read-only.

Is this targeting older, non-compliant HW, or am I misunderstanding something?

Remove the fu540 dt modification

Currently, we modify fu540 DT for following purpose.

  1. Modify M mode IRQ context to 0xFFFFFFF so kernel won't try to parse them.
    fixed in kernel now
    https://patchwork.kernel.org/project/linux-riscv/list/?series=193125

  2. Change hart0 status to disabled
    Latest DT in Linux kernel already have it disabled.

  3. Add chosen node for U-Boot serial console
    It is now added to DT as well.
    https://patchwork.kernel.org/patch/11182027/

We should remove the DT modifications but it can't be done now to avoid compatibility breakage.
It should be done some time in the future. The issue is created to serve as a reminder.

Can't clear supervisor timer interrupt

I'm running a simple bare-metal application over sbi on qemu virt. I use the sbi_set_timer function to set a tick at a given interval. It seems to work fine. However, when I try to disable the timer interrupts by calling sbi_set_timer((uint64_t)-1) it seems to have the inverse effect: the interrupt is triggered consecutively ad infinitum.

I've set a breakpoint at sbi_timer_event_start and confirmed the nex_event argument is indeed ((uint64_t)-1).

Am I doing something wrong? Or maybe this is a QEMU issue?

Is Floating Point Required?

Is there a requirement for a floating point unit? I tried compiling with

make CROSS_COMPILE=riscv64-unknown-elf- \
       PLATFORM_RISCV_XLEN=32 \
       PLATFORM_RISCV_ABI=ilp32 \
       PLATFORM_RISCV_ISA=rv32imac \
       PLATFORM=qemu/virt \
       V=1 \
       O=./build/

It seems I get the error in riscv_fp.h and the #define guards look like it is required.

Race condition in sbi_hart_wake_coldboot_harts?

I guess this is probably more of question than a bug report so I hope you don't mind me opening an issue for this. While running OpenSBI with a custom riscv simulator I noticed that some of my simulated harts are stuck in sbi_hart_wait_for_coldboot. After briefly reading the OpenSBI code I wonder if this is due to a race condition.

If I understand the terminology correctly OpenSBI differentiates between cold- and warmboot. Where coldboot means "full init" and is only performed once and warmboot means "little init".

https://github.com/riscv/opensbi/blob/a2a7763ac7651e64c3928ba0a13be9317bd48c4d/lib/sbi/sbi_init.c#L179-L182

If the current hart is booted in coldboot it invokes sbi_hart_wake_coldboot_harts. If it is booted in warmboot it invokes sbi_hart_wait_for_coldboot.

The sbi_hart_wait_for_coldboot function periodically checks if the MIP register of the current hart has been set. The sbi_hart_wake_coldboot_harts sets the MIP register of all harts except the current one, but only if the hart has been marked as waiting in a bitmap (coldboot_wait_bitmap) beforehand. This bitmap is set from sbi_hart_wait_for_coldboot.

https://github.com/riscv/opensbi/blob/3f738f5897a6694b8630d3a9c6751f49c3c7d540/lib/sbi/sbi_hart.c#L355

Since coldboot is only performed once sbi_hart_wake_coldboot_harts is only called once. Now: If my outlined observations are correct an implicit assumption made here is that all harts booted in warmboot reached the sbi_hart_wait_for_coldboot function (and modified the bitmap) before the sbi_hart_wake_coldboot_harts function is invoked. If this assumption doesn't hold some harts will never return from the sbi_hart_wait_for_coldboot function.

This is assumption is what I consider to be a race condition as it doesn't not necessarily hold, right? The problem in this regard being the bitmap which has been introduced in 6f02b69 if I remove the bitmap I don't run into this problem. However, as I said I encountered this with a custom riscv simulator and it might as well be a bug in the emulator.

Add libfdt support to openSBI

Currently, we have a minimum required fdt support via platfrom/common/fdt.c.
I am currently adding following features to fdt.c

  1. Modify any DT property.
  2. Add any DT property.
  3. Print the entire DT.

1 & 2 feature also requires DT offsets to be moved accordingly in addition to providing option of reserving extra amount of memory for DT. I feel we will need more complex features in future as well.
Instead of reinventing the wheel every time, I think we can include libfdt in platform/common code base.

Here are the source code and library size breakdown.
libfdt - 200K (entire source code)
libfdt.a - 77K

I am not sure if 77K is too much overhead for an embedded system aiming to run Linux. We may be able to trim it down if required. However, adding libfdt support seems to be a better option to me.

Any thoughts ?

Add two new members to sbi_platform structure. One to indicate the openSBI version this table is created base on. Another is a pointer to firmware-system information.

This issue has dependence with #108. Better to reorganize sbi_platform structure first and then add these two new members.
opensbi_revision
On UEFI EDK2, 23 will have entire OpenSBI code tree under EDK2 RiscVPkg, however, we won’t use platform code under OpenSBI. Instead, we will leverage some of OpenSBI platform code and create RISC-V platform tree under EDK2 Platform repo which follows EDK2 implementation.
EDK2 RISC-V platform code is expected to deliver by the vendor and separated from OpenSBI release, this means RISC-V platform code is possible not align with OpenSBI on EDK2 code tree because edk2 RISC-V package is maintained by EDK2 owner other than vendors. Furthermore, OEM may maintain their own in-house UEFI BIOS, which does not sync up with EDK2 open source often. The mismatched version of OpenSBI and sbi_platform is possible to happen.
With opensbi_revision declared in sbi_platform table, OpenSBI can throw an error message and halts system if the platform table version is not matched with openSBI revision. Or openSBI can return UNSUPPORTED status to the caller, so the caller can have further fallbacks processes. This reduces the debugging effort in case EDK2 developer is not aware of the inconsistency of these two structures.
Another use case is that revsion information could be posted on screen during UEFI system POST or log to event logger for system management.

sbi_firmware_context
EDK2 RISC-V platform code maintains sbi_platform for the platform and build up the data structure which is delivered through mscratch. However, UEFI needs to handoff some UEFI-specific information to the next phase (such as PEI or DXE). Current sbi_platform is not sufficient to pass any UEFI-specific information.
In order to increase the flexibility of sbi_platform for supporting any system firmware implementations and reduce the dependence between OpenSBI and specific firmware implementation. We propose to add a sbi_firmware_context in sbi_platform which is owned and comsumed by system firmware.
We would like to create UEFI-specific sbi_firmware_context structure and publish it in UEFI Platform Initialization spec. With this, any format changes of sbi_firmware_context structure don’t impact OpenSBI spec.

Memory reserved by opensbi not indicated in devicetree on qemu virt platform?

This is with the fw_jump.elf binary from the 0.1 release. I'm loading it with qemu's "-kernel" option. According to the ELF header, it occupies memory address 0x80000000.

So far so good. But the flattened devicetree passed via a1 indicates that this is normal, usable memory (if I'm parsing the devicetree data correctly). If my payload attempts to write to this memory, qemu's emulated CPU mysteriously stops doing anything useful.

Apparently this memory is reserved. By a conservative estimate, this means that all memory from 0x80000000 to 0x80200000 (fw_jump.elf 64 bit load address) is reserved by the SBI. Indeed, SBI logs this to the qemu serial console:

PMP0: 0x0000000080000000-0x000000008001ffff (A)

The problem here is that there is no indication anywhere to the SBI client that it is not allowed to use this memory. (The PMP registers are not readable from supervisor mode, if I read riscv-privileged-v1.10.pdf correctly.)

I believe opensbi should mark this as reserved memory range using the devicetree Memory Reservation Block. Or alternatively, not include this memory in any "/memory" node.

I've only tested with the 0.1 release (sorry), but I didn't see any commits in the git log that seemed to touch this. Not sure how exactly Linux handles this. I might be overlooking something.

Building opensbi with Debian gcc-riscv64-linux-gnu fails to load

OpenSBI fails to load Kernel (or loading fw_payload.elf) when built with gcc-riscv64-linux-gnu from https://packages.debian.org/buster/gcc-riscv64-linux-gnu installed with:

sudo dpkg --add-architecture riscv64
sudo apt-get install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu
sudo sh -c "cat >/etc/ld.so.conf.d/riscv64-linux-gnu.conf <<EOF
/usr/local/lib/riscv64-linux-gnu
/lib/riscv64-linux-gnu
/usr/lib/riscv64-linux-gnu
/usr/riscv64-linux-gnu/lib/
EOF
"

riscv64-linux-gcc --version
riscv64-linux-gcc.br_real (Buildroot 2018.11-rc2-00003-ga0787e9) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

When building with Bootlin (https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64/tarballs/riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2) riscv64--glibc--bleeding-edge-2018.11-1.tar.bz2 it succeeds.

Unable to find the preferred boot HART id

I've run FSBL on all 5 cores of the HiFive Unleased board and then launching the openSBI on all 5 cores by building the openSBI(078686d) by:
make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=u-boot-gitlab/u-boot.bin
OR
make PLATFORM=sifive/fu540 FW_PAYLOAD_PATH=u-boot-gitlab/u-boot.bin FU540_ENABLED_HART_MASK=0x02
In both cases, the _boot_status is never being set to BOOT_STATUS_BOOT_HART_DONE and all cores keeps on waiting for the _boot_status to be updated. What is wrong here?

The workaround is to specify the boot core id in fw_boot_hart function avoiding _try_lottery function which don't do any good.

plic: invalid register write: 000001fc

I am running QEMU emulator version 3.1.50 (qemu-3.1.50.201903180749.1d023a5-1.fc29), QEMU commit 1d023a5.

I am using master of OpenSBI, I get the following:

qemu-system-riscv64: plic: invalid register write: 000001fc

OpenSBI v0.3 (Mar 19 2019 08:32:46)
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name          : QEMU Virt Machine
Platform HART Features : RV64ACDFIMSU
Platform Max HARTs     : 8
Current Hart           : 1
Firmware Base          : 0x80000000
Firmware Size          : 100 KB
Runtime SBI Version    : 0.1

It boots and it works just fine.

Booting opensbi+linux under qemu ..network tap issue.

I have used busybear ( https://github.com/michaeljclark/busybear-linux ) to help me boot opensbi+linux payload

I have setup tap0 on my ubuntu18 (VM) and have a br0 bridge configured.

The Host interface is a Virtualbox Host-Only Interface. I just want to talk with the riscv machine from the HOST..

I am booting riscv on qemu-system-riscv64:

qemu-system-riscv64 -M virt -m 1024M -nographic
-kernel images/opensbi_linux.elf
-drive file=images/ramdisk,format=raw,id=hd0
-device virtio-blk-device,drive=hd0
-append "root=/dev/vda rw console=ttyS0"
-netdev type=tap,ifname=tap0,script=ramdisk/scripts/ifup.sh,downscript=ramdisk/scripts/ifdown.sh,id=net0
-device virtio-net-device,netdev=net0

I have configured the eth0 on the image as both static ip and dchp.

When dhcp I see the request on the Host and it gets an ipaddr during boot. But it never shows up in ifconfig. And I cannot ping the HOST.

If i configure it as static ifconfig shows the address but no route to the outside.

Both are going through the same tap0 interface above.
bridge name bridge id STP enabled interfaces
br0 8000.080027ea438c no enp0s8
tap0

I am at a loss now as the bridge seems to be working at least for dhcp....

Trying to compile: Invalid -march= option: `rv32imafdc'

Tried compiling this with riscv64-buildroot-linux-gnu and riscv64-linux toolchains (both included in bootlin tar)
CC lib/sbi/riscv_asm.o Assembler messages: Fatal error: invalid -march= option: 'rv32imafdc' Makefile:297: recipe for target '/mnt/d/Projectos/Ubuntu-gcc/opensbi-master/build/lib/sbi/riscv_asm.o' failed make: *** [/mnt/d/Projectos/Ubuntu-gcc/opensbi-master/build/lib/sbi/riscv_asm.o] Error 1

Tried changing PLATFORM_RISCV_ISA = rv$(PLATFORM_RISCV_XLEN)imafdc on the makefile to multiple combinations of ISA extensions ("i","imac","g",etc) only "e" made a difference with "invalid ISA string" (is rv32e not supported?), also tried doing XLEN=64 and nothing worked.

I tried both a plain make and make for plarform qemu/virt

I'm on WSL Ubuntu18.04

Standard way of getting memory map info

Follow up from my comment on #70 where I argue that adding a standard way of querying info about the memory map would be a good idea.

A quick recap:

  • Add an extension to query OpenSBI about the memory map at runtime. It's very flexible, but maybe overkill for the most common situation where it remains fixed.
  • Pass info at boot time in an structure generated by the firmware: the simplest to implement solution (for both OpenSBI and the payload), but don't allow modifications to the memory map (although after boot, the OS should be able to manage it by itself)
  • Do nothing, and rely on info currently available (on almost all platforms the Device Tree, but as a standard I don't know if we can be sure this is going to be true for all platforms which OpenSBI will support). This leads to parsing at certain level platform-specific structures, but maybe it should be that way.

sbi_trap_error: hart2: trap handler failed (error -5)

sbi_trap_error: hart2: trap handler failed (error -5)
sbi_trap_error: hart2: mcause=0xd mtval=0x155574e000
sbi_trap_error: hart2: mepc=0x80003dba mstatus=0x8000000a00027822
sbi_trap_error: hart2: ra=0x80001eaa sp=0x80011d60
sbi_trap_error: hart2: gp=0x2aaaccdd18 tp=0x155573cb30
sbi_trap_error: hart2: s0=0x80011dc0 s1=0x5e
sbi_trap_error: hart2: a0=0x20000 a1=0x80011df0
sbi_trap_error: hart2: a2=0x15555eee96 a3=0x8000000a00006022
sbi_trap_error: hart2: a4=0x80011d6b a5=0x155574e001
sbi_trap_error: hart2: a6=0x0 a7=0x155574e001
sbi_trap_error: hart2: s2=0xee s3=0x3
sbi_trap_error: hart2: s4=0x96 s5=0x20
sbi_trap_error: hart2: s6=0x0 s7=0x15555eee96
sbi_trap_error: hart2: s8=0x74 s9=0x14774
sbi_trap_error: hart2: s10=0x58782b5b s11=0x34fe3e52
sbi_trap_error: hart2: t0=0x4 t1=0x155574dffd
sbi_trap_error: hart2: t2=0x55 t3=0x85a303
sbi_trap_error: hart2: t4=0x0 t5=0x0
sbi_trap_error: hart2: t6=0x15

The kernel was booted via u-boot.

Is it possible to use vmlinux with opensbi?

I've read that bbl is/is going to be deprecated, so I am trying to move to a more current bootloader. I use riscv64 QEMU with the stage4 disk image and have been attempting to load a vmlinux kernel with opensbi with no success (note I am able to use the normal kernel image with opensbi, but I specifically need to use a statically-linked linux build).

As I've seen no mention/documentation of it, I wanted to specifically ask if it possible to configure opensbi such that its payload can be vmlinux.

master branch can't build, v0.7 is OK

wgb@wgb-virtual-machine:~/riscvSpace/opensbi$ export CROSS_COMPILE=riscv64-linux-
wgb@wgb-virtual-machine:~/riscvSpace/opensbi$ make PLATFORM=qemu/virt FW_PAYLOAD_PATH=../u-boot/u-boot.bin
 CC-DEP    lib/utils/fdt/fdt_fixup.dep
 CC-DEP    lib/utils/fdt/fdt_helper.dep
 CC-DEP    lib/utils/ipi/fdt_ipi_clint.dep
 CC-DEP    lib/utils/ipi/fdt_ipi.dep
 CC-DEP    lib/utils/irqchip/plic.dep
 CC-DEP    lib/utils/irqchip/fdt_irqchip_plic.dep
 CC-DEP    lib/utils/irqchip/fdt_irqchip.dep
 CC-DEP    lib/utils/libfdt/fdt_wip.dep
 CC-DEP    lib/utils/libfdt/fdt_sw.dep
 CC-DEP    lib/utils/libfdt/fdt_strerror.dep
 CC-DEP    lib/utils/libfdt/fdt_rw.dep
 CC-DEP    lib/utils/libfdt/fdt_ro.dep
 CC-DEP    lib/utils/libfdt/fdt_empty_tree.dep
 CC-DEP    lib/utils/libfdt/fdt_addresses.dep
 CC-DEP    lib/utils/libfdt/fdt.dep
 CC-DEP    lib/utils/reset/fdt_reset_sifive.dep
 CC-DEP    lib/utils/reset/fdt_reset_htif.dep
 CC-DEP    lib/utils/reset/fdt_reset.dep
 CC-DEP    lib/utils/serial/uart8250.dep
 CC-DEP    lib/utils/serial/sifive-uart.dep
 CC-DEP    lib/utils/serial/fdt_serial_uart8250.dep
 CC-DEP    lib/utils/serial/fdt_serial_sifive.dep
 CC-DEP    lib/utils/serial/fdt_serial_htif.dep
 CC-DEP    lib/utils/serial/fdt_serial.dep
 CC-DEP    lib/utils/sys/sifive_test.dep
 CC-DEP    lib/utils/sys/htif.dep
 CC-DEP    lib/utils/sys/clint.dep
 CC-DEP    lib/utils/timer/fdt_timer_clint.dep
 CC-DEP    lib/utils/timer/fdt_timer.dep
 AS-DEP    lib/sbi/sbi_expected_trap.dep
 CC-DEP    lib/sbi/sbi_unpriv.dep
 CC-DEP    lib/sbi/sbi_trap.dep
 CC-DEP    lib/sbi/sbi_tlb.dep
 CC-DEP    lib/sbi/sbi_timer.dep
 CC-DEP    lib/sbi/sbi_system.dep
 CC-DEP    lib/sbi/sbi_string.dep
 CC-DEP    lib/sbi/sbi_scratch.dep
 CC-DEP    lib/sbi/sbi_platform.dep
 CC-DEP    lib/sbi/sbi_misaligned_ldst.dep
 CC-DEP    lib/sbi/sbi_ipi.dep
 CC-DEP    lib/sbi/sbi_init.dep
 CC-DEP    lib/sbi/sbi_illegal_insn.dep
 CC-DEP    lib/sbi/sbi_hsm.dep
 AS-DEP    lib/sbi/sbi_hfence.dep
 CC-DEP    lib/sbi/sbi_math.dep
 CC-DEP    lib/sbi/sbi_hart.dep
 CC-DEP    lib/sbi/sbi_fifo.dep
 CC-DEP    lib/sbi/sbi_emulate_csr.dep
 CC-DEP    lib/sbi/sbi_ecall_vendor.dep
 CC-DEP    lib/sbi/sbi_ecall_replace.dep
 CC-DEP    lib/sbi/sbi_ecall_legacy.dep
 CC-DEP    lib/sbi/sbi_ecall_hsm.dep
 CC-DEP    lib/sbi/sbi_ecall_base.dep
 CC-DEP    lib/sbi/sbi_ecall.dep
 CC-DEP    lib/sbi/sbi_console.dep
 CC-DEP    lib/sbi/sbi_bitops.dep
 CC-DEP    lib/sbi/sbi_bitmap.dep
 CC-DEP    lib/sbi/riscv_locks.dep
 AS-DEP    lib/sbi/riscv_hardfp.dep
 CC-DEP    lib/sbi/riscv_atomic.dep
 CC-DEP    lib/sbi/riscv_asm.dep
Makefile:117: /home/wgb/riscvSpace/opensbi/platform/qemu/virt/config.mk: 没有那个文件或目录
make: *** 没有规则可制作目标“/home/wgb/riscvSpace/opensbi/platform/qemu/virt/config.mk”。 停止。

The right way for instruction emulation in OpenSBI ?

Hi,
I'm interested in the possibility to port OpenSBI for Linux-on-VexRiscv , which uses its own SBI implementation.
Yet the issue is that A extension is not fully supported in VexRiscv and the unsupported ones are emulated in its SBI .
And if memory serves me right, in RISC-V's unprivileged specification, this kind of simulation is mentioned as well.

I know there's a illegal instruction handling part yet it seems to be too generic.
I'd like to know is there a platform specific way to do this ?

Consolidate platform function pointers into one structure member in sbi_platform structure

The current design of sbi_platform table seems not flexible to add new structure member. We should consolidate those platform function pointers into one structure member in sbi_platform. So any new Non-function pointer member added to sbi_platform doesn’t bother the order of platform function pointers listed in structure and keep the backward compatibility, also the structure looks nicer.

Unable to handle kernel NULL pointer dereference when snd_mtpav enabled

When CONFIG_SND_MTPAV is enabled in the kernel (5.0-rc3 + handful of required patches) I see this kernel NULL pointer dereference crash when booting using openSBI direct boot:

[ 4.282241] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000379
[ 4.290786] Oops [#1]
[ 4.293019] Modules linked in:
[ 4.296064] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc3-riscv #1
[ 4.302747] sepc: ffffffe0006d62a4 ra : ffffffe0006d689e sp : ffffffe1f7ac9a90
[ 4.309953] gp : ffffffe000ae9dc8 tp : ffffffe1f7ac0000 t0 : ffffffe1f6e1fc00
[ 4.317158] t1 : ffffffe0007bc500 t2 : 000000000000f9ac s0 : ffffffe1f7ac9ac0
[ 4.324365] s1 : ffffffe1f7c56638 a0 : ffffffe1f7c56638 a1 : 00000000000000f5
[ 4.331570] a2 : 0000000000000038 a3 : ffffffe1f7ac9957 a4 : ffffffe1f7c56063
[ 4.338776] a5 : 0000000000000379 a6 : 0000000000000030 a7 : 0000000000000003
[ 4.345983] s2 : ffffffe1f7c56638 s3 : 0000000000000000 s4 : 00000000000000f5
[ 4.353189] s5 : 0000000000000008 s6 : ffffffe000ae9f4c s7 : ffffffe1f6e4d800
[ 4.360396] s8 : ffffffe000000266 s9 : ffffffe000aea240 s10: ffffffe000aea230
[ 4.367601] s11: 0000000000000000 t3 : 000000000000000f t4 : ffffffe000a95470
[ 4.374807] t5 : 0000000000000040 t6 : ffffffe1f7c56060
[ 4.380104] sstatus: 0000000200000120 sbadaddr: 0000000000000379 scause: 000000000000000d
[ 4.388319] ---[ end trace ad20f5585df9d44a ]---
[ 4.392874] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 4.400513] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---

If using bbl on the same kernel with the same config, I see this:

[ 3.906570] MTVAP IRQ 7 busy
[ 3.909237] snd_mtpav: probe of snd_mtpav failed with error -16
[ 3.915258] specify port
[ 3.917644] snd_mpu401: probe of snd_mpu401.0 failed with error -22

There are only two differences between the openSBI and bbl case:

  1. The bootloader used
  2. The kernel format used, vmlinux for bbl and Image for openSBI

Adding non-platform-specific but custom SBI?

Hi, 

I'm used to bbl and new to opensbi.

I found that bbl is slowing down and people are moving to opensbi.

We are research team at Berkeley building hardware enclave extension on the firmware (Keystone Enclave).

We want to move forward to opensbi so that it would easily work with more platforms.

I found that opensbi is really nice in building a platform-specific firmware.

However, we want to make our extension (having a few additional SBIs) work on multiple platforms including sifive/fu540 and qemu/virt.

So, we want the library to be included in multiple platforms.

Currently, I see that all common libs are in lib where all platform-specific functions should go to platform, and you get to choose one platform when you compile the firmware.

Do you have any plans for adding SBI extensions in the build system that works with multiple platforms? 

What is your recommendation for putting such non-standard extension in opensbi?

Thank you!

Large kernel images and FW_JUMP_FDT_ADDR

I am trying to determine how to handle loading of an S-mode OS kernel that is > 32MB (it has a root filesystem embedded in the kernel binary) in QEMU (with -kernel) using the generic fw_jump.

The problem I see is that the default FDT address is FW_TEXT_START + 34 MB and the kernel starts at FW_TEXT_START+2MB.
If the kernel is larger than 32 MB the FDT will overwrite the mapped kernel image.
Since the FDT is quite small this is unlikely to write over an important file, but could have fatal consequences if we're unlucky.

As a workaround we can build OpenSBI with FW_JUMP_FDT_ADDR to some larger value (e.g. start + 256MB). This will work for us since we don't support < 256MB RAM, but does not seem ideal.
I'm not sure we can move the FDT before the kernel start since some kernels may assume 2MB alignment?

rv32ima minimum possible architecture?

Hello,

I have a rv32ia core that I wish to run Linux on using opensbi, but I can't seem to
build opensbi for rv32ia because of errors like this:
opensbi/firmware/fw_base.S:180: Error: unrecognized opcode `mul a5,s8,t1'

Building it for rv32ima solves this error but now my core can't run it.

I could add the extension but it would be good to know if I actually have to, time is a factor.

Thankful for any input

Support M-mode to M-mode traps (avoid stack overwrite)

At init both the sp and CSR_MSCRATCH registers are set to the same value (some offset from tp).

Then, when entering _trap_handler from M-mode (instead of S-mode), the sp will be set to CSR_MSCRATCH which is the base of the M-mode stack, and therefore the M-mode context stack before the trap will be overwritten.

Something like this should be done: https://github.com/torvalds/linux/blob/master/arch/riscv/kernel/entry.S#L36 : if coming from M-mode there is no need to touch sp (and tp).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.