aboutsummaryrefslogtreecommitdiff
path: root/Makefile
AgeCommit message (Collapse)AuthorFilesLines
2025-12-01Makefile: define C language standard to "gnu11"Vladimir Kondratiev1-0/+1
C language standard was not specified, implying default that is depending on the compiler version. Force "gnu11", same as for the Linux kernel Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251113081648.2708990-1-vladimir.kondratiev@mobileye.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-12-01Makefile: Only enable --print-gc-section for verbose (V=1) buildRahul Pathak1-1/+4
Earlier this option was enabled during debug build which only prints the linker logs of removing the unused sections. Instead enable this for V=1 and keep the debug build clean. Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251110164352.163801-1-rpathak@ventanamicro.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-06-15Makefile: Add flag for reprodubility compiler flagsKhem Raj1-0/+7
Provides mechanism to remove absolute paths from binaries using -ffile-prefix-map It will help distros (e.g. yocto based ones ) which want to ship the .elf files but need to scrub absolute paths in objects Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Khem Raj <raj.khem@gmail.com> Link: https://lore.kernel.org/r/20250515025931.3383142-1-raj.khem@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-06-14Makefile: Make $(LLVM) more flexibleCharlie Jenkins1-4/+10
Introduce a way for developers to easily switch between LLVM versions with LLVM=/path/to/llvm/ and LLVM=-version. This is a useful addition to the existing LLVM=1 variable which will select the first clang and llvm binutils available on the path. Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20250430-improve_llvm_building-v1-1-caae96cc6be6@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-05-15Makefile: fix missing .debug_frame DWARF section for GCCParshintsev Anatoly1-0/+1
When OpenSBI is built with a relatively new compiler (gcc-13 and greater) I observed that GDB is unable to produce proper backtraces and some variable values appear corrupted (even if the associated DWARF location descriptor is correct). Turns out that to properly work with debug information, debuggers often need to unwind the stack. They generally rely on Call Frame Information (CFI) records provided by the compiler to facilitate this task. Currently, the GCC compiler offers two mechanisms: - `.debug_frame` section (as described in the DWARF specification). - `.eh_frame` sections (as described in LSB documents). The latter (`.eh_frame`) supports stack unwinding at runtime, providing a framework for C++ exceptions or enabling backtrace generation using libraries like libunwind. However, the downside of this approach is that these sections should be part of loadable segments. The former (`.debug_frame`) is simply an ordinary debug section. Starting from GCC 13, Linux targets enable the `-fasynchronous-unwind-tables` and `-funwind-tables` flags by default. Relevant commit: https://github.com/gcc-mirror/gcc/commit/3cd08f7168 When these flags are active, the compiler generates `.eh_frame` sections instead of `.debug_frame`. Since OpenSBI is built using the **Linux toolchain**, this behavior applies to OpenSBI as well. The problem arises because the SBI build system uses `-Wl,--gc-sections`, which discards the `.eh_frame` section. Possible Fixes: 1. Enforce `.debug_frame` generation – Modify compiler flags to generate `.debug_frame` instead of `.eh_frame`. 2. Preserve `.eh_frame` in the linker script – Add `KEEP(*(.eh_frame))` to ensure the section is not discarded. I chose Option 1 because it avoids any runtime overhead. Signed-off-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20250421124729.36364-1-anatoly.parshintsev@syntacore.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-04-13Makefile: Avoid repeated evaluation of shell commandsSamuel Holland1-6/+8
Recursively expanded variables (defined with '=') are expanded at evaluation time. These version information variables are evaluated inside a recipe as part of GENFLAGS. As a result, the shell commands are executed separately for each compiler invocation. Convert the version information variables to be simply expanded, so the shell commands are executed only once, at Makefile evaluation time. This speeds up the build by as much as 75%. A separate check is needed to maintain the behavior of preferring the value of OPENSBI_BUILD_TIME_STAMP from the environment. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20250313035755.3796610-1-samuel.holland@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi: Avoid GOT indirection for global symbol referencesSamuel Holland1-0/+1
OpenSBI is compiled with -fPIE, which generally implies dynamic linking. This causes the compiler to generate GOT references for global symbols in order to support runtime symbol interposition. However, OpenSBI does not actually perform dynamic linking, so the GOT indirection just adds unnecessary overhead. The GOT references can be avoided by declaring global symbols with hidden visibility, thus making them local to this dynamic object and non-interposable. GCC/Clang's -fvisibility parameter is insufficient for this purpose when referencing objects from other translation units; either __attribute__((visibility(...)) or the pragma is required. Use the pragma since it is easier to apply to every symbol. Additionally clean up the one GOT reference from inline assembly. With this change, a firmware linked with LLD does not contain either a GOT or a PLT, and a firmware linked with BFD ld contains only a GOT with a single (unreferenced, legacy) _GLOBAL_OFFSET_TABLE_ entry. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15Makefile: remove carry output if scripts/carray.sh failsBen Dooks1-1/+1
If the script fails, we end up trying to build either an empty or damaged .c file. Just remove it and let gcc fail on non-existent file. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15Makefile: Don't enable V-extension using -march optionAnup Patel1-4/+4
Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler. As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c. Fixes: c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2024-12-06lib: sbi_misaligned_ldst: Add handling of vector load/storeNylon Chen1-3/+8
Add misaligned load/store handling for the vector extension to the sbi_misaligned_ldst library. This implementation is inspired from the misaligned_vec_ldst implementation in the riscv-pk project. Co-developed-by: Zong Li <zong.li@sifive.com> Signed-off-by: Zong Li <zong.li@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> Reviewed-by: Andy Chiu <andy.chiu@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-01Makefile: Fix POSIX grep for multiple patternsIgor Melnikov1-2/+2
grep -e "-mstrict-align\|-mno-unaligned-access" makes use of GNU grep's backslash-escaped alternation operator \| which is available in basic regular expression syntax (BRE) mode. However, in POSIX grep's BRE mode | is an ordinary character which, when backslash-escaped, matches itself. Therefore, the search pattern becomes a plain string '-mstrict-align|-mno-unaligned-access' which obviously never matches the expected error and CC_SUPPORT_STRICT_ALIGN is always set to y. When cross-compiling with LLVM on amd64-unknown-openbsd7.6 host for riscv64-unknown-elf target this results in a compilation error: clang: error: unsupported option '-mno-unaligned-access' for target 'riscv64-unknown-elf' Using multiple -e options for this case maintains consistent behaviour across different grep implementations and fixes the issue. Signed-off-by: Igor Melnikov <imel@purelymail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-06Makefile: enable --gc-sectionsKele Zhang1-6/+9
The --gc-sections option enables the linker to perform garbage collection of unreferenced code and data, thereby reducing the binary size. The -ffunction-sections option will place each function into a separate section, so it is necessary to add .text.* to the linker script. Signed-off-by: Kele Zhang <zhangcola2003@gmail.com> Signed-off-by: Yuan Tan <tanyuan@tinylab.org> Signed-off-by: Zhangjin Wu <falcon@tinylab.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-09-27Makefile: Make .carray.c files depend on carray.shSamuel Holland1-3/+3
Force carray C source files to be regenerated when the script changes, since their contents depend on the script's output. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24Makefile: fix OPENSBI_VERSION_GIT build with submodulesDaniel Henrique Barboza1-1/+10
When building OpenSBI via a submodule, OPENSBI_VERSION_GIT can be left unset in case '.git' isn't a dir. This is the case when building OpenSBI as a QEMU submodule: $ cat .git gitdir: ../../.git/modules/roms/opensbi As a result, building OpenSBI tag v1.5.1 in QEMU will result in a binary that will have "OpenSBI v1.5" as a banner. Use "git rev-parse --git-dir" instead of checking if '.git' is a dir to detect if the current dir is a git repo. Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-04Makefile: remove any .carray.c during cleanBen Dooks1-0/+2
Now we've renamed the carray output files to .carray.c we can now use find to remove them. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-04Makefile: change to using .carray.c for carray filesBen Dooks1-4/+4
We would like to clean any files generated by the carray scripts by just searching for the filename as the current make system turns f.carray into f.o. Change to make the make system turn f.carray into f.carray.o note, command to go through .mk files changing the .o in the .mk files is: find . -type f -name "*.carray" | xargs -t -I fname /bin/bash -x -c ' fn=`basename -s .carray fname`; echo "$fn"; sed -i `dirname fname `/objects.mk -e s/"$fn".o/"$fn".carray.o/g' Link: https://patchwork.ozlabs.org/project/opensbi/patch/20240401213438.590209-2-ivan.orlov0322@gmail.com/ Reported-by: Ivan Orlov <ivan.orlov0322@gmail.com> Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-04-08Makefile: Remove unnecessary dependenciesSamuel Holland1-1/+1
The rule included from auto.conf.cmd adds a dependency on every Kconfig file, so these two Kconfig files do not need to be specified again here. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org>
2024-04-07Makefile: Respect manual changes to .configSamuel Holland1-19/+24
The .config file may be manually edited or copied from another location. Since genconfig.py is responsible for generating auto.conf (the Makefile fragment) and autoconf.h (the C header) from .config, it must be run any time .config changes, not just when running menuconfig. Fixes: 662e631ccef2 ("Makefile: Add initial kconfig support for each platform") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org>
2024-04-05firmware: remove copy-base relocationXiang W1-1/+7
Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-02-05Makefile: check for --exclude-libsLeon M. Busch-George1-0/+5
While writing to the dynsym is futile, the --exclude-libs options is not recognized by all linkers (e.g. riscv64-elf-ld.bfd). Signed-off-by: Leon M. Busch-George <leon@georgemail.eu> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-02-05Makefile: don't pass -mstrict-align if not supportedKalle Wachsmuth1-4/+13
Support for that option will be added in LLVM 18: https://github.com/llvm/llvm-project/commit/23ce5368409c760f3dd49d0f17f34772b0b869d8 Clang 17.0.6, however, will error when passed the `-mstrict-align` flag. We should only use the flag if it is supported. Signed-off-by: Kalle Wachsmuth <kalle.wachsmuth@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Xiang W <wxjstz@126.com>
2023-10-06Makefile: Add --exclude-libs ALL to avoid .dynsymVivian Wang1-0/+1
Since everything is statically linked, we don't need to expose symbols for dynamic linking. For a default build this saves about 2 KiB of useless read only data in .dynsym, .dynstr, .hash, .gnu.hash sections. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-08-22Makefile: Fix grep warningAndrew Jones1-1/+1
grep (at least my version, grep-3.8-3.fc38.x86_64) warns with "grep: warning: stray \ before -". Fix the warning by making the command line input to grep less ambiguous. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-05-22Makefile: Dereference symlinks on installFilip Filmar1-4/+4
Adds the `-L` flag (follow symlinks) to the `cp` commands used to install `libsbi.a` and `include/sbi/*`. This should make no difference in regular compilation. However, it does make a difference when compiling with bazel. Namely, bazel's sandboxing will turn all the source files into symlinks. After installation with `cp` the destination files will be symlinks pointing to the sandbox symlinks. As the sandbox files are removed when compilation ends, the just-copied symlinks become dangling symlinks. The resulting include files will be unusable due to the dangling symlink issues. Adding `-L` when copying ensures that the files obtained by executing the `install` targets are always dereferenced to files, rather than symlinks, eliminating this issue. Signed-off-by: Filip Filmar <fmil@google.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-03-01make: Add a command line option for debugging OpenSBIBin Meng1-1/+6
Add a new make command line option "make DEBUG=1" to prevent compiler optimizations using -O2. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-02-08Makefile: Add missing .dep files for fw_*.elf.ldJessica Clarke1-0/+9
Since we don't currently create these, changes to fw_base.ldS do not cause the preprocessed fw_*.elf.ld files to be rebuilt, and thus incremental builds can end up failing with missing symbols if crossing the recent commits that introduced _fw_rw_offset and then replaced it with _fw_rw_start. Reported-by: Ben Dooks <ben.dooks@sifive.com> Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-01-06Makefile: Remove -N ldflag to prevent linker RWX warningRahul Pathak1-1/+1
-N option coalesce all sections into single LOAD segment which causes data and other sections to have executable permission causing warning with new binutils ld 2.39. New ld emits warning when any segment have all three permissions RWX. ld.bfd: warning: test.elf has a LOAD segment with RWX permissions ld.bfd: warning: fw_dynamic.elf has a LOAD segment with RWX permissions ld.bfd: warning: fw_jump.elf has a LOAD segment with RWX permissions ld.bfd: warning: fw_payload.elf has a LOAD segment with RWX permissions This option was added in below commit - commit: eeab92f2423e ("Makefile: Convert to a more standard format") Removing -N option allows to have text and rodata into one LOAD segment and other sections into separate LOAD segment which prevents RWX permissions on single LOAD segment. Here X == E Current LOAD 0x0000000000000120 0x0000000080000000 0x0000000080000000 0x000000000001d4d0 0x0000000000032ed8 RWE 0x10 -N removed LOAD 0x0000000000001000 0x0000000080000000 0x0000000080000000 0x00000000000198cc 0x00000000000198cc R E 0x1000 LOAD 0x000000000001b000 0x000000008001a000 0x000000008001a000 0x00000000000034d0 0x0000000000018ed8 RW 0x1000 Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Samuel Holland <samuel@sholland.org>
2022-12-04Makefile: bugfix for handling platform pathsAlejandro Cabrera Aldaya1-1/+1
If the path where this repo is located contains the platform name on it, the original Makefile replaced its occurrences from the path making it an invalid path. This commit prevents this behavior replacing only the last part of the path as intended. Signed-off-by: Alejandro Cabrera Aldaya <aldaya@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-12-04Makefile: replace `echo` with `printf` for compatibilityKaDiWa1-1/+1
I don't know why but `echo -n` didn't work for me. macOS supports the `-n` option but it doesn't work in the makefile. What it does instead is it literally writes `-n` to the file and then also leaves a newline at the end. I'm using GNU Make 4.4 (`gmake` from Homebrew). Signed-off-by: KaDiWa <kalle.wachsmuth@gmail.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-23Makefile: Add rules for carray sources in lib/sbiVivian Wang1-0/+7
Add back the missing rules needed to build carray files in lib/sbi. This allows future usage of carray in lib/sbi. Fixes: de80e9337d81 ("Makefile: Compile lib/utils sources separately for each platform") Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-23Makefile: Add cscope supportTan En De1-0/+13
Add cscope support so that running `make cscope` will generate/update cscope files used for source code browsing, while running `make distclean` will remove the cscope files. Also add entry in .gitignore to ignore generated cscope files. Signed-off-by: Tan En De <ende.tan@linux.starfivetech.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2022-08-08Makefile: Fix typo related to object.mkAnup Patel1-1/+1
The "object.mk" name referred in top-level makefile should be "objects.mk". Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08platform: Remove redundant config.mk from all platformsAnup Patel1-3/+1
The options defined in config.mk can be specified in objects.mk of each platform so let us remove config.mk from all platforms. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08Makefile: Compile lib/utils sources separately for each platformAnup Patel1-24/+24
Currently, if same build directory is used to compile two different platforms then lib/utils objects are shared for these platforms. We will be having platform specific configs to enable/disable drivers in lib/utils and select compile time options for lib/utils sources. This means lib/utils sources will now be compiled in a platform specific way. To tackle above, we update top-level Makefile as follows: 1) Don't create libsbiutils.a anymore because this can't be shared between platforms. 2) Compile lib/utils sources separately for each platform. 3) Add comments showing which make rules are for lib/sbi, lib/utils, firmware, and platform sources. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08Makefile: Add initial kconfig support for each platformAnup Patel1-12/+60
We extend the top-level makefile to allow kconfig based configuration for each platform where each platform has it's own set of configs with "defconfig" being the default config. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-05-13Makefile: Add support for generating C array at compile timeAnup Patel1-0/+11
Generating C array at compile time based on details provided by objects.mk is a very useful feature which will help us compile only a subset of drivers or modules. We add a bash script (carray.sh) which takes array details and object/variable list from command-line to generate a C source containing array of object/variable pointers. We also extend top-level makefile to use carray.sh whenever specified through objects.mk. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-05-13Makefile: Allow generated C source to be anywhere in build directoryAnup Patel1-3/+3
The generated C source could be anywhere within build directory so let us update the make rule to comple generated C source accordingly. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-02-04Makefile: fix build with binutils 2.38Aurelien Jarno1-1/+8
From version 2.38, binutils default to ISA spec version 20191213. This means that the csr read/write (csrr*/csrw*) instructions and fence.i instruction has separated from the `I` extension, become two standalone extensions: Zicsr and Zifencei. As the kernel uses those instruction, this causes the following build failure: CC lib/sbi/sbi_tlb.o <<BUILDDIR>>/lib/sbi/sbi_tlb.c: Assembler messages: <<BUILDDIR>>/lib/sbi/sbi_tlb.c:190: Error: unrecognized opcode `fence.i' make: *** [Makefile:431: <<BUILDDIR>>/build/lib/sbi/sbi_tlb.o] Error 1 The fix is to specify those extensions explicitly in -march. However as older binutils version do not support this, we first need to detect that. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Alexandre Ghiti <alexandre.ghiti@canonical.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2021-12-16Makefile: Improve the method to disable -m(no-)save-restore optionXiang W1-4/+7
The commit 69d7e53 disables the -m(no-)save-restore option for clang, but clang11 supports this option. This patch uses the output information of the compiler to check whether the compiler supports this option. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-12-11Makefile: Fix -msave-restore compile warning with CLANG-10 (or lower)Anup Patel1-4/+10
The riscv target of CLANG-10 (or lower) does not support the -m(no-)save-restore option so we get compile warnings. This patch fixes compile warning by using -m(no-)save-restore option only for GCC. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
2021-10-20Makefile: Add build time and compiler info stringWei Fu1-0/+31
When we are doing opensbi development, we want to know the build time and compiler info for debug purpose. To enable this message, please add "BUILD_INFO=y", like: ``` make BUILD_INFO=y ``` NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds". Signed-off-by: Wei Fu <wefu@redhat.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-07-27Makefile: Manually forward RELAX_FLAG to the assembler when linking with LLDBin Meng1-0/+5
When generating code with -mno-relax, GCC puts .option norelax in the generated assembly, and so doesn’t bother passing on -mno-relax to the assembler. This has the unfortunate effect that, when using GCC to assemble hand-written assembly, -mno-relax does nothing, and we have to pass -Wa,-mno-relax to manually forward it to the assembler. This is an old GCC bug that was fixed [1] recently. For the time being, let's pass "-Wa,-mno-relax" to ASFLAGS for the GCC + LLD combination to work, e.g.: $ make CC=riscv64-unknown-elf-gcc LLVM=1 PLATFORM=generic [1] https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857 Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-11lib: utils: Drop dependency on libgcc by importing part of FreeBSD's libquadJessica Clarke1-1/+1
We only need libgcc for 64-bit division on RV32. Whilst GCC toolchains bundle libgcc, Clang toolchains tend not to ship libclang_rt.builtins given every compiler is a cross-compiler for every target and so you would need a silly number of builds of it, with only the native library available; only vendor-provided Clang toolchains specifically for bare metal cross-compiling are likely to provide it. Thus, import part of FreeBSD's implementation of the division support functions needed and stop linking against libgcc. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Tested-by: Anup Patel <anup.patel@wdc.com>
2021-07-11Makefile: Support building with Clang and LLVM binutilsJessica Clarke1-7/+59
This is intended to mirror the Linux kernel. Building with CC=clang will use Clang as the compiler but default to using the existing binutils. Building with LLVM=1 will default to using Clang and LLVM binutils. Whilst GCC will accept the -N linker option and forward it on to the linker, Clang will not, and so in order to support both compilers we must use -Wl, to forward it to the linker as is required for most other linker options. Note that there is currently a bug when using Clang as the compiler and riscv64-linux-gnu-ld as the linker for FW_PIC=y. At first glance this appears to be a bug in GNU binutils, but this could also be Clang or OpenSBI at fault in some subtle way. Thus, for now, advise that this combination be avoided. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Tested-by: Anup Patel <anup.patel@wdc.com>
2021-07-11firmware: Only default FW_PIC to y if supportedJessica Clarke1-0/+3
Bare-metal GNU ld does not support PIE, so if using it this will result in a failure to build. Instead, default to FW_PIC=n if not supported. Note that an explicit FW_PIC=y is not overridden, to ensure the build fails rather than silently producing a position-dependent binary. Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-05-19Makefile: unconditionally disable SSPFabrice Fontaine1-1/+1
Though -nostdlib is passed in CFLAGS, -fno-stack-protector must also be passed to avoid linking errors related to undefined references to '__stack_chk_guard' and '__stack_chk_fail' if toolchain enforces -fstack-protector. Fixes: - https://gitlab.com/kubu93/buildroot/-/jobs/1247043359 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri1-1/+1
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-19firmware: Support position independent executionVincent Chen1-1/+1
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>
2020-11-02Makefile: Add option to use toolchain default ABI and ISA stringAnup Patel1-4/+14
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-10-18Makefile: Allow padding zeros when converting DTB to C sourceHeinrich Schuchardt1-2/+5
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>