# Disable debug packages, we don't need them.
%global debug_package %{nil}
+# Make sure we use the cross-binary to strip.
+%global __strip riscv64-linux-gnu-strip
+
+# Avoid this error caused by cross-compilation and packaging the
+# result in a noarch package:
+# error: Arch dependent binaries in noarch package
+%global _binaries_in_noarch_packages_terminate_build 0
+
%global forgeurl https://github.com/riscv/opensbi
-%global commit 791953030836d39687688a8e7f1a3e708892cfa1
+%global commit 355796c5bc1906d749850e4215e0f7f53802ba5b
%forgemeta
Name: opensbi
URL: %{forgeurl}
Source: %{forgesource}
-BuildRequires: gcc
-BuildRequires: binutils
+# The resulting binary contains RISC-V firmware intended to be used
+# under virtualization, so it can be used on any architecture.
+Buildarch: noarch
+
+BuildRequires: gcc-riscv64-linux-gnu
+BuildRequires: binutils-riscv64-linux-gnu
BuildRequires: findutils
BuildRequires: grep
BuildRequires: coreutils
%description
-RISC-V Open Source Supervisor Binary Interface. This is for QEMU
-RISC-V virt machines.
+RISC-V Open Source Supervisor Binary Interface.
+
+The current version is for QEMU RISC-V virt machines, SiFive HiFive
+Unleashed, T-HEAD C9xx and some others.
%prep
%build
-make \
+mkdir build32 build64
+# Build 32 bit firmware.
+%make_build \
+ O=build32 \
+ CROSS_COMPILE=riscv64-linux-gnu- \
+ PLATFORM=generic \
+ PLATFORM_RISCV_XLEN=32
+# Build 64 bit firmware.
+%make_build \
+ O=build32 \
+ CROSS_COMPILE=riscv64-linux-gnu- \
PLATFORM=generic
-
%install
-make \
+# Install 32 bit firmware.
+%make_install \
+ O=build32 \
+ CROSS_COMPILE=riscv64-linux-gnu- \
PLATFORM=generic \
+ PLATFORM_RISCV_XLEN=32 \
I=%{buildroot} \
- INSTALL_LIB_PATH=lib64 \
- INSTALL_FIRMWARE_PATH=%{_datadir}/%{name} \
- install
-
-rm -rfv %{buildroot}/lib64
+ INSTALL_LIB_PATH=%{_libdir} \
+ INSTALL_FIRMWARE_PATH=%{_datadir}/%{name}
+pushd %{buildroot}%{_datadir}/%{name}/generic/firmware
+for f in fw_*.bin fw_*.elf; do
+ mv $f opensbi-riscv32-generic-$f
+done
+popd
+
+# Install 64 bit firmware.
+%make_install \
+ O=build64 \
+ CROSS_COMPILE=riscv64-linux-gnu- \
+ PLATFORM=generic \
+ I=%{buildroot} \
+ INSTALL_LIB_PATH=%{_libdir} \
+ INSTALL_FIRMWARE_PATH=%{_datadir}/%{name}
+pushd %{buildroot}%{_datadir}/%{name}/generic/firmware
+for f in fw_*.bin fw_*.elf; do
+ mv $f opensbi-riscv64-generic-$f
+done
+popd
+
+# Remove development libraries and headers for the time being.
+rm -rfv %{buildroot}%{_libdir}
rm -rfv %{buildroot}/include
+
+# Remove the example/testing payloads.
rm -rfv %{buildroot}%{_datadir}/%{name}/*/firmware/payloads
%changelog
* Tue May 23 2023 Richard W.M. Jones <rjones@redhat.com> 1.2
- Use forge macros
+- Convert to use cross-compilation
- Fix dates in changelog
* Tue May 02 2023 David Abdurachmanov <davidlt@rivosinc.com> v1.2.116.2023.05.02.7919530-1