Commit Graph

59 Commits

Author SHA1 Message Date
Marouene Boubakri bfc85c70e7 include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__
GCC has already a predefined macro __ASSEMBLER__ therefore, it can be
used without the need to define a new flag with -D__ASSEMBLY__.
This is useful when adding the library to projects having a build
system such one can build without the need to make changes.
THe build system does not use the Makefile in the sources tree.

Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-03-22 16:02:48 +05:30
Vincent Chen 0f20e8adcf firmware: Support position independent execution
Enable OpenSBI to support position independent execution. Because the
position independent code will cause an additional GOT reference when
accessing the global variables, it will reduce performance a bit. Therefore,
the position independent execution is disabled by default. Users can
through specifying "FW_PIC=y" on the make command to enable this feature.

In theory, after enabling position-independent execution, the OpenSBI
can run at arbitrary address with appropriate alignment. Therefore, the
original relocation mechanism will be skipped. In other words, OpenSBI will
directly run at the load address without any code movement.

Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-19 15:00:50 +05:30
Anup Patel 914f81fbee Makefile: Add option to use toolchain default ABI and ISA string
When PLATFORM_RISCV_ABI and PLATFORM_RISCV_ISA are not specified,
we force "-mabi=lp64 -march=rv64gc" for RV64 and force "-mabi=ilp32
-march=rv32gc" for RV32. This can prevent users from using the
toolchain default "-mabi" and "-march" options.

To allow using toolchain defaults, we add compile-time option
PLATFORM_RISCV_TOOLCHAIN_DEFAULT which when enabled forces the
top-level makefile to use toolchain default ABI and ISA string.

To enable the option, pass "PLATFORM_RISCV_TOOLCHAIN_DEFAULT=1"
to top-level make.

Reported-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-11-02 09:21:50 +05:30
Heinrich Schuchardt e9a4bfb7b5 Makefile: Allow padding zeros when converting DTB to C source
We extend d2c.sh to allow padding zeros in output C source when
converting DTB to C source. Using this feature, platforms can
create extra room for in-place FDT fixups on built-in DTBs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18 10:33:57 +05:30
Anup Patel af4b50f896 Makefile: Build ELF, BIN and LD script in platform build directory
Currently, the make rules for ELF, BIN and LD script are little
generic to allowing ELF, BIN and LD script to be anywhere in the
build directory. For OpenSBI firmwares, the ELF, BIN, and LD script
are always platform specific so we update make rules accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-18 10:14:17 +05:30
Damien Le Moal a04c46506a makefile: fix clean directive
Add cleaning of compiled device tree files (.dtb files).

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-10 11:02:23 +05:30
Anup Patel 51f0e4a053 firmware: Remove FW_PAYLOAD_FDT and related documentation
Now that no platform is using FW_PAYLOAD_FDT mechanism, we
remove related code from Makefile and related documentation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-05 09:03:05 +05:30
Anup Patel 4e3876d5be Makefile: Add mechanism for platforms to have multiple builtin DTBs
Currently, we can only include one DTB as builtin for a platform
using FDT_PAYLOAD_DTB make variable in platform config.mk.

This patch adds new mechanism using which we can convert any DTS
file to C source and futher compile-n-link it with libplatsbi.a.

The generated C source will have the DTB contents as an array
"const char <varprefix>_start[]" where <varprefix> is specified
in platform objects.mk makefile.

Example1
--------
If we have built-in k210.dts and desired <varprefix> is
"dt_k210" then specify following in platform objects.mk:
platform-objs-y += k210.o
platform-varprefix-k210.o = dt_k210

Example2
--------
If we have built-in abc/k210.dts and desired <varprefix> is
"dt_abc_k210" then specify following in platform objects.mk:
platform-objs-y += abc/k210.o
platform-varprefix-abc-k210.o = dt_abc_k210

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-05 09:02:59 +05:30
Anup Patel c6c65ee861 Makefile: Preprocess builtin DTS
In order to use GCC style defines and macros in DTS, we should
preporcess builtin DTS before converting it to DTB.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-05 09:02:55 +05:30
Anup Patel 30b60401e1 Makefile: Fix builtin DTB compilation for out-of-tree platforms
The make rule for builtin DTB compilation does not consider
out-of-tree platforms so this patch fixes it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-05 09:02:27 +05:30
Anup Patel 9aabba2665 Makefile: Fix distclean make target
The default install directory is not being removed correctly by
distclean make target due to recent changes. This patch fixes
distclean make target to fix default install directory removal.

Fixes: 82ae8e8fe2 ("makefile: Do setup of the install target
more flexible")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-13 12:22:34 +05:30
Nikita Ermakov 82ae8e8fe2 makefile: Do setup of the install target more flexible
- Add possibility to setup include, libs, firmware and docs paths.

- Change the default installation paths for include, libs, firmware
  and docs to meet FHS [1].

[1] https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html

Signed-off-by: Nikita Ermakov <coffe92@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-08 10:05:45 +05:30
Alex Richardson 5ff1ab0ed8 makefile: add support for building on macOS
On macOS the readlink command does not include a -f flag. Instead default
to using GNU readlink (which is often installed as greadlink).

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
2020-02-06 15:42:47 +05:30
Khem Raj 049ad0b387 build: Use -ffreestanding
this is a stand-alone/baremetal application, therefore demanding
-ffreestanding would help it compile with hosted toolchains e.g. ( linux
toolchains ), it also ensures that it won't be using platform
optimizations like inlining mem* str* functions which gcc might decide
especially with wrapper string functions in opensbi code

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-01-08 09:10:24 +05:30
Anup Patel 2c7bab76a2 Makefile: Minor fix in OPENSBI_VERSION_GIT
Currently, if someone has forked OpenSBI repo quite sometime back
and this fork is not having updated tags from upstream riscv/opensbi
repo then "git describe" command can fail. To tackle this, we redirect
error output of "git describe" to /dev/null.

Signed-off-by: Anup Patel <anup.pate@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-10-02 17:03:54 +05:30
Palmer Dabbelt a2a7763ac7 Include `git describe` in OpenSBI
OpenSBI includes a version, but that is only updated when tagged.  For
users that are using the git releases we instead end up with an
ambiguous version number, which makes it hard to figure out what
everyone is using.  This patch checks for a git directory and prints out
the result of `git describe`, which is a mix of pretty and unambiguous.

Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
2019-08-19 10:58:21 +05:30
Abner Chang 08b196956d include: Add version info to struct sbi_platform
Add version control of sbi_platform structure
- Add opensbi_version, this gives information of opensbi revision on
which the sbi_platform table was created.
- Add platform_version field in sbi_platform structure for platform
level version control.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-29 19:26:26 +05:30
Atish Patra 793e5e1184 platform: Move platform common to lib/utils.
Currently, platform/common contains platform/non-platform specific
common minimal drivers and libraries. This is helpful is all platforms
are built within opensbi framework.

Move them to lib/utils so that any external platform code also can
reuse the minimalistic drivers or other common libraries.

This patch doesn't introduce any functional changes.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-19 09:48:56 +05:30
Atish Patra 749b0b0932 lib: Move sbi core library to lib/sbi
Signed-off-by: Atish Patra <atish.patra@wdc.com>
Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-19 09:48:51 +05:30
Karsten Merker f9643f3472 Makefile: explicitly disable PIE
The various available RISC-V toolchains differ in their default
configuration regarding PIE, e.g. the buildroot RISC-V toolchain
has PIE disabled by default while the Debian toolchain has it
enabled by default.

OpenSBI currently doesn't support being built with PIE enabled,
therefore disable it explicitly by passing "-fno-pie -no-pie" in
CFLAGS.

Signed-off-by: Karsten Merker <merker@debian.org>
Acked-by: Anup Patel <anup.patel@wdc.com>
2019-04-30 09:21:47 +05:30
Anup Patel 54f31e8209 TOP: Allow building platform out-of-tree
This patch extends our current build-system for building platform
sources which are not part of OpenSBI sources.

For example:

Let's say we have out-of-tree ABC platform sources. We place these
sources under <XYZ>/ABC directory along with its config.mk and
objects.mk.

To build out-of-tree ABC platform from OpenSBI directory:
$ make PLATFORM_DIR=<XYZ>/ABC
OR
$ make PLATFORM_DIR=<XYZ> PLATFORM=ABC

To build out-of-tree ABC platform from <XYZ>/ABC directory:
$ make PLATFORM_DIR=<XYZ>/ABC -C <path_to_opensbi>
OR
$ make PLATFORM_DIR=<XYZ> PLATFORM=ABC -C <path_to_opensbi>

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2019-04-09 09:14:09 +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
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 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
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
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
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
Nick Kossifidis 286b80768b 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>
2019-02-15 08:55:45 +05:30
Anup Patel c5467fce46 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>
2019-02-12 15:55:15 +05:30
Alistair Francis 76c759df6a 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>
2019-02-08 09:18:46 +05:30
Alistair Francis 5a91fec1a8 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>
2019-02-08 09:18:46 +05:30
Andreas Schwab 190a80dc40 Makefile: don't disable built-in variables
Signed-off-by: Andreas Schwab <schwab@suse.de>
2019-02-06 10:39:17 +05:30
Olof Johansson 9a72e5006c 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>
2019-02-05 18:53:27 +05:30
Anup Patel bd98d77298 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>
2019-01-25 11:05:49 -08:00
Anup patel 20990ee0ab 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>
2019-01-24 14:07:47 +05:30
Anup Patel f37f7e21e0 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>
2019-01-22 11:40:15 +05:30
Anup Patel ac003ff6bf 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>
2019-01-22 11:40:15 +05:30
Damien Le Moal 9c4aca4f1b 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal 0df8269477 Makefile: Add support for device tree compilation
Add rules to compile dts files into dtb files using the device tree
compiler (dtc). A platform can specify the DTS file to compile using
the platform-dtb-y variable. The flattened device tree binary file to be
used for building the final polatform firmware can be specified using
the new FW_PAYLOAD_FDT firmware configuration option to point to the
automatically compiled FDT file. Using the existing FW_PAYLOAD_FDT_PATH
configuration option is still possible and will take precedence over
the FW_PAYLOAD_FDT definition.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21 09:58:33 +05:30
Atish Patra cf83b6e438 platform: Include libfdt & libc.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-18 10:05:12 +05:30
Anup Patel c2e0b02914 Makefile: Add make targets to build and install documentation
This patch extends top-level makefile to build and install
documentation. The 'docs' make target is for building the
documentation PDF whereas 'install_docs' make target is for
installing the documentation PDF.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-16 11:25:25 +05:30
Anup Patel 2e5ede8279 Makefile: Use '=' instead of '?=' for make variables
The '?=' will not assign value if the target make variable is
overriden via command-line or is set in environment variable.
On other hand, '=' will not assign value only if variable is
overriden via command-line parameter.

It is quite common to have CC, AS, CPP, LD, etc to be set as
environment variables pointing to native compiler and binutils.
If '-rR' option is not set in MAKEFLAGS then this results in
compile error because '?=' will use the native compiler and
binutils. If '-rR' option is set in MAKEFLAGS then this again
results in compile error because CC, AS, CPP, etc are set to
empty strings which causes '?=' to use empty string as compiler
and binutils.

To handle this, we use '?=' only when CROSS_COMPILE is not
defined and we use '=' when CROSS_COMPILE is defined.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-05 16:40:22 +05:30
Alistair Francis 5cbc24b95a Makefile: Force GCC to preprocess the linker file
To avoid this message (and subsequent errors):
    warning: linker input file unused because linking not done
force GCC to treat the linker script preprocessing as a C file.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-04 08:20:50 +05:30
Alistair Francis eeab92f242 Makefile: Convert to a more standard format
Convert the Makefile to a more standard format and don't forcefully
overwrite a users enviroment.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-04 08:20:50 +05:30
Alistair Francis d6ddfdce39 Makefile: Use generic flags for the firmware
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-04 08:20:50 +05:30
Alistair Francis 116f10973b Makefile: Use generic flags for the platform
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-04 08:20:50 +05:30
Alistair Francis 6d9e390f5b Makefile: Support verbosity using standard V=1
Instead of using a confusing and custom option, allow verbose Makefile
with the standard V=1.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-04 08:20:50 +05:30
Damien Le Moal da86853a51 Makefile: Fix messages
Instead of printing the generic "<build_directory>" and
"<install_directory>" strings, print the actual paths for the build
and install directories during "make clean" and "make distclean".

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-03 13:27:17 +09:00