File uefi-shell.spec of Package ovmf

#
# spec file for package uefi-shell
#
# Copyright (c) 2026 SUSE LLC
# Copyright (c) 2026 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
# needssslcertforbuild


%undefine _build_create_debug
%global openssl_version 3.5.1
%global softfloat_version b64af41c3276f
%if 0%{?suse_version} < 1599
%bcond_with build_riscv64
%else
%bcond_without build_riscv64
%endif

Name:                      uefi-shell
Version:                202511
Release:                0
Summary:                Open Virtual Machine Firmware
License:                BSD-2-Clause-Patent
Group:                    System/Emulators/PC
URL:                        https://github.com/tianocore/edk2
Source0:                edk2-edk2-stable%{version}.tar.gz
Source1:                https://www.openssl.org/source/old/3.0/openssl-%{openssl_version}.tar.gz
Source111:            https://www.openssl.org/source/old/3.0/openssl-%{openssl_version}.tar.gz.asc
Source112:            openssl.keyring
Source113:            openssl.keyring.README
Source114:            descriptors.tar.xz.README
Source2:                README
Source3:                SLES-UEFI-CA-Certificate-2048.crt
Source4:                openSUSE-UEFI-CA-Certificate-2048.crt
Source7:                descriptors.tar.xz
# oniguruma: https://github.com/kkos/oniguruma,  "src" directory only
Source8:                oniguruma-v6.9.4_mark1-src.tar.xz
# public-mipi-sys-t: https://github.com/MIPI-Alliance/public-mipi-sys-t
Source9:                public-mipi-sys-t-1.1-edk2.tar.gz
# mbedtls: https://github.com/Mbed-TLS/mbedtls
Source10:              mbedtls-3.3.0.tar.gz
# brotli: https://github.com/google/brotli
Source11:              brotli-e230f474b87134e8c6c85b630084c612057f253e.tar.gz
# libspdm: https://github.com/DMTF/libspdm.git
Source12:              libspdm-50924a4c8145fc721e17208f55814d2b38766fe6.tar.gz
# pylibfdt: https://github.com/devicetree-org/pylibfdt
Source13:              pylibfdt-cfff805481bdea27f900c32698171286542b8d3c.tar.gz
Source100:            %{name}-rpmlintrc
Source101:            gdb_uefi.py.in
Patch1:                  %{name}-gdb-symbols.patch
Patch2:                  %{name}-pie.patch
Patch3:                  %{name}-disable-ia32-firmware-piepic.patch
Patch4:                  %{name}-OvmfPkg-Adjust-Memory-Layout-for-2MB-OVMF.patch
Patch6:                  %{name}-ignore-spurious-GCC-12-warning.patch
# Bug 1255113 - Build Failure for RISC-V 64 When Secure Boot is Enabled Due to SecureBootDefaultKeysInit module
Patch7:                  %{name}-Revert-OvmfPkg-RiscVVirt-Add-SecureBootDefaultKeysIn.patch
# Bug 1207095 - ASSERT [ArmCpuDxe] /home/abuild/rpmbuild/BUILD/edk2-edk2-stable202211/ArmPkg/Library/DefaultExceptionHandlerLib/AArch64/DefaultExceptionHandler.c(333): ((BOOLEAN)(0==1))
Patch8:                  %{name}-Revert-ArmVirtPkg-make-EFI_LOADER_DATA-non-executabl.patch
# Bug 1205613 - L3: win 2k22 UEFI xen VMs cannot boot in xen after upgrade
Patch9:                  %{name}-Revert-OvmfPkg-OvmfXen-Set-PcdFSBClock.patch
# Bug 1236009 - Build failure on Leap 15.5/15.6 due to unsupported GCC flag -mstack-protector-guard for aarch64 cross-compiler
Patch10:                %{name}-Revert-Add-Stack-Cookie-Support-to-MSVC-and-GCC.patch
%ifarch x86_64
%if 0%{?sle_version} >= 150500 && 0%{?sle_version} <= 150700
Patch11:                %{name}-BaseTools-Using-gcc12-for-building-image.patch
%endif
%endif
# Bug 1240420 - UEFI boot breaks: X64 Exception Type - 0E(#PF - Page-Fault) CPU Apic ID - 00000000
Patch13:                %{name}-UefiCpuPkg-Disable-EFI-memory-attributes-protocol.patch
# Bug 1244218 - ovmf: non-deterministic .bin files (about unreproducible)
Patch14:                %{name}-OvmfPkg-ArmVirtPkg-Keep-JSON-stack-cookie-files.patch
# Bug 1257495 - nasm > 3 is stricter
Patch15:                %{name}-nasm3.patch
BuildRequires:  bc
BuildRequires:  cross-arm-binutils
BuildRequires:  dosfstools
BuildRequires:  fdupes
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:    cross-arm-gcc%{gcc_version}
%ifarch x86_64
%if 0%{?sle_version} >= 150500 && 0%{?sle_version} <= 150700
BuildRequires:  gcc12
BuildRequires:  gcc12-c++
BuildRequires:   
BuildRequires:   
%endif
%endif
BuildRequires:  iasl
BuildRequires:  libbpf1
BuildRequires:  libuuid-devel
BuildRequires:  mkisofs
BuildRequires:  mtools
BuildRequires:  nasm
BuildRequires:  openssl
BuildRequires:  python3
BuildRequires:  unzip
BuildRequires:  virt-firmware
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
BuildRequires:   
%ifnarch aarch64
BuildRequires:  cross-aarch64-binutils
BuildRequires:   
BuildRequires:    cross-aarch64-gcc%{gcc_version}
%endif
%ifnarch x86_64
BuildRequires:  cross-x86_64-binutils
BuildRequires:   
%if 0%{?sle_version} >= 150500 && 0%{?sle_version} <= 150700
BuildRequires:  cross-x86_64-gcc12
BuildRequires:   
%else
BuildRequires:    cross-x86_64-gcc%{gcc_version}
%endif
%endif
%ifnarch riscv64
%if %{with build_riscv64}
BuildRequires:  cross-riscv64-binutils
BuildRequires:   
BuildRequires:    cross-riscv64-gcc%{gcc_version}
%endif
%endif
# Only build on the architectures with
#  1. cross-compilers, 2. iasl
ExclusiveArch:    x86_64 aarch64 riscv64

%description
The Open Virtual Machine Firmware (OVMF) project aims to support
firmware for Virtual Machines using the edk2 code base.

%package uefi-shell
Summary:                The Shell from edk2
Group:                    System/Emulators/PC

%description uefi-shell
This package provides the UEFI Shell binary.

%prep
%setup -q -n edk2-edk2-stable%{version}

# bsc#973038 Remove the packages we don't need to avoid any potential
# license issue.
PKG_TO_REMOVE="EmulatorPkg"
rm -rf $PKG_TO_REMOVE

%autopatch -p1

# add openssl
pushd CryptoPkg/Library/OpensslLib/openssl
tar -xf %{SOURCE1} --strip 1
popd

# prepare the firmware descriptors for qemu
tar -xf %{SOURCE7}

# add oniguruma
pushd MdeModulePkg/Universal/RegularExpressionDxe/oniguruma
tar -xf %{SOURCE8} --strip 1
popd

# add public-mipi-sys-t%files uefi-shell
%dir %{_datadir}/ovmf/
%{_datadir}/ovmf/x86_64/Shell.efi
%{_datadir}/ovmf/aarch64/Shell.efi
%if %{with build_riscv64}
%{_datadir}/ovmf/riscv64/Shell.efi
%endif
pushd MdePkg/Library/MipiSysTLib/mipisyst
tar -xf %{SOURCE9} --strip 1
popd

# add mbedtls
pushd CryptoPkg/Library/MbedTlsLib/mbedtls
tar -xf %{SOURCE10} --strip 1
popd

# add brotli
pushd BaseTools/Source/C/BrotliCompress/brotli
tar -xf %{SOURCE11} --strip 1
popd
pushd MdeModulePkg/Library/BrotliCustomDecompressLib/brotli
tar -xf %{SOURCE11} --strip 1
popd

# add libspdm
pushd SecurityPkg/DeviceSecurity/SpdmLib/libspdm
tar -xf %{SOURCE12} --strip 1
popd

# add libfdt
pushd MdePkg/Library/BaseFdtLib/libfdt
tar -xf %{SOURCE13} --strip 1
popd

%build

# Enable python3 build
export PYTHON3_ENABLE=TRUE
export PYTHON_COMMAND=python3

%if 0%{?suse_version} > 1320
TOOL_CHAIN=GCC5
%else
echo `gcc -dumpversion`
TOOL_CHAIN=GCC$(gcc -dumpversion|sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/')
%endif

# Build BaseTools
%ifarch x86_64
%if 0%{?sle_version} >= 150500 && 0%{?sle_version} <= 150700
echo "gcc_version="`gcc -dumpversion`
export CC=gcc-12
export CXX=g++-12
%endif
	make -C BaseTools
%endif
%ifarch aarch64
	ARCH=AARCH64 make -C BaseTools
%endif
%ifarch riscv64
	ARCH=RISCV64 make -C BaseTools
%endif

# Import the build functions
source ./edksetup.sh

# Build Shell.efi for X64
build -a X64 -p ShellPkg/ShellPkg.dsc -t $TOOL_CHAIN -q
mkdir X64
cp Build/Shell/DEBUG_*/X64/ShellPkg/Application/Shell/Shell/DEBUG/Shell.efi X64

# Build Shell.efi for AARCH64
%ifnarch aarch64
# Assign the cross-compiler prefix
export ${TOOL_CHAIN}_AARCH64_PREFIX="aarch64-suse-linux-"
%endif
# Add Shell.efi for AARCH64
build -a AARCH64 -p ShellPkg/ShellPkg.dsc -t $TOOL_CHAIN -q
mkdir AARCH64
cp Build/Shell/DEBUG_*/AARCH64/ShellPkg/Application/Shell/Shell/DEBUG/Shell.efi AARCH64

# Build Shell.efi for RISCV64
%if %{with build_riscv64}
%ifnarch riscv64
# Assign the cross-compiler prefix
export ${TOOL_CHAIN}_RISCV64_PREFIX="riscv64-suse-linux-"
%endif
build -a RISCV64 -p ShellPkg/ShellPkg.dsc -t $TOOL_CHAIN -q
mkdir RISCV64
cp Build/Shell/DEBUG_*/RISCV64/ShellPkg/Application/Shell/Shell/DEBUG/Shell.efi RISCV64
%endif

%install

# Install BaseTools

mkdir -p %{buildroot}/%{_datadir}/ovmf/
install -m 0644 X64/Shell.efi %{buildroot}/%{_datadir}/ovmf/x86_64/Shell.efi
install -m 0644 AARCH64/Shell.efi %{buildroot}/%{_datadir}/ovmf/aarch64/Shell.efi
%if %{with build_riscv64}
install -m 0644 RISCV64/Shell.efi %{buildroot}/%{_datadir}/ovmf/riscv64/Shell.efi
%endif

%files uefi-shell
%dir %{_datadir}/ovmf
%dir %{_datadir}/ovmf/x86_64
%dir %{_datadir}/ovmf/aarch64
%{_datadir}/ovmf/x86_64/Shell.efi
%{_datadir}/ovmf/aarch64/Shell.efi
%if %{with build_riscv64}
%dir %{_datadir}/ovmf/riscv64
%{_datadir}/ovmf/riscv64/Shell.efi
%endif

%changelog
openSUSE Build Service is sponsored by