From e782f95713da959f669ea1e48dbb979787cf16b2 Mon Sep 17 00:00:00 2001
From: David Abdurachmanov <davidlt@rivosinc.com>
Date: Thu, 2 Oct 2025 13:45:50 +0000
Subject: [PATCH vfoobar] Enable riscv64 arch
Content-type: text/plain

Backported from David's branch here:
http://fedora.riscv.rocks:3000/rpms/oz/commits/branch/f38-riscv64

Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
---
 0027-Enable-riscv64-arch.patch | 133 +++++++++++++++++++++++++++++++++
 oz.spec                        |   8 +-
 2 files changed, 140 insertions(+), 1 deletion(-)
 create mode 100644 0027-Enable-riscv64-arch.patch

diff --git a/0027-Enable-riscv64-arch.patch b/0027-Enable-riscv64-arch.patch
new file mode 100644
index 0000000000000000000000000000000000000000..cb2f6b1f0d9c1a375349933e5f71dfecf5f17529
--- /dev/null
+++ b/0027-Enable-riscv64-arch.patch
@@ -0,0 +1,133 @@
+From d7af1b1f03957f11f5f766c55ed5e8ab5612bc6c Mon Sep 17 00:00:00 2001
+From: David Abdurachmanov <davidlt@rivosinc.com>
+Date: Thu, 2 Oct 2025 13:28:20 +0000
+Subject: [PATCH] Enable riscv64 support
+Content-type: text/plain
+
+Backporting David's RISC-V enablement patches from here:
+http://fedora.riscv.rocks:3000/rpms/oz/commits/branch/f38-riscv64
+
+Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
+Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
+---
+ oz.cfg       |  8 ++++----
+ oz/Guest.py  | 12 ++++++++----
+ oz/TDL.py    |  4 ++--
+ oz/ozutil.py |  6 ++++++
+ oz/tdl.rng   |  1 +
+ 5 files changed, 21 insertions(+), 10 deletions(-)
+
+diff --git a/oz.cfg b/oz.cfg
+index 8913f9d401b3986ec0b3876be4e4dec94d37b811..1a07c2738f74a008ce933a0f0a833382b9edb146 100644
+--- a/oz.cfg
++++ b/oz.cfg
+@@ -21,7 +21,7 @@ jeos = no
+ safe_generation = no
+ 
+ [timeouts]
+-install = 1200
+-inactivity = 300
+-boot = 300
+-shutdown = 90
++install = 120000
++inactivity = 30000
++boot = 30000
++shutdown = 9000
+diff --git a/oz/Guest.py b/oz/Guest.py
+index aa18582a1bd00703b315ae9531ea88a6f87d7b93..64ab0e0931b48fa166767376c8046c6e60b3a905 100644
+--- a/oz/Guest.py
++++ b/oz/Guest.py
+@@ -137,7 +137,7 @@ class Guest(object):
+         # for backwards compatibility
+         self.name = self.tdl.name
+ 
+-        if self.tdl.arch not in ["i386", "x86_64", "ppc64", "ppc64le", "aarch64", "armv7l", "s390x"]:
++        if self.tdl.arch not in ["i386", "x86_64", "ppc64", "ppc64le", "aarch64", "armv7l", "s390x", "riscv64"]:
+             raise oz.OzException.OzException("Unsupported guest arch " + self.tdl.arch)
+ 
+         if os.uname()[4] in ["i386", "i586", "i686"] and self.tdl.arch == "x86_64":
+@@ -261,7 +261,7 @@ class Guest(object):
+             self.clockoffset = "utc"
+         self.mousetype = mousetype
+         if self.mousetype is None:
+-            if self.tdl.arch in ["aarch64", "armv7l"]:
++            if self.tdl.arch in ["aarch64", "armv7l", "riscv64"]:
+                 self.mousetype = "usb"
+             else:
+                 self.mousetype = "ps2"
+@@ -488,7 +488,7 @@ class Guest(object):
+         # os
+         osNode = oz.ozutil.lxml_subelement(domain, "os")
+         mods = None
+-        if self.tdl.arch in ["aarch64", "armv7l"]:
++        if self.tdl.arch in ["aarch64", "armv7l", "riscv64"]:
+             mods = {'arch': self.tdl.arch, 'machine': 'virt'}
+         oz.ozutil.lxml_subelement(osNode, "type", "hvm", mods)
+         if bootdev:
+@@ -503,6 +503,10 @@ class Guest(object):
+             loader, nvram = oz.ozutil.find_uefi_firmware(self.tdl.arch)
+             oz.ozutil.lxml_subelement(osNode, "loader", loader, {'readonly': 'yes', 'type': 'pflash'})
+             oz.ozutil.lxml_subelement(osNode, "nvram", None, {'template': nvram})
++        if self.tdl.arch in ["riscv64"]:
++            loader, nvram = oz.ozutil.find_uefi_firmware(self.tdl.arch)
++            oz.ozutil.lxml_subelement(osNode, "loader", loader, {'readonly': 'yes', 'type': 'pflash', 'format': 'qcow2'})
++            oz.ozutil.lxml_subelement(osNode, "nvram", None, {'template': nvram, 'format': 'qcow2'})
+         # x86_64 has legacy requirements so we check for defaults as well as for edk2
+         if self.tdl.arch == "x86_64" and hasattr(self.config, "useuefi") and self.config.useuefi is True:
+             loader, nvram = oz.ozutil.find_uefi_firmware(self.tdl.arch)
+@@ -531,7 +535,7 @@ class Guest(object):
+             elif self.mousetype == "usb":
+                 mousedict['type'] = 'tablet'
+             oz.ozutil.lxml_subelement(devices, "input", None, mousedict)
+-            if self.tdl.arch in ["aarch64", "armv7l"]:
++            if self.tdl.arch in ["aarch64", "armv7l", "riscv64"]:
+                 # Other arches add a keyboard by default, for historical reasons ARM doesn't
+                 # so we add it here so graphical works and hence we can get debug screenshots RHBZ 1538637
+                 oz.ozutil.lxml_subelement(devices, 'controller', None, {'type': 'usb', 'index': '0'})
+diff --git a/oz/TDL.py b/oz/TDL.py
+index aee74a3d79f8cb75f5f0d3a51fb97c594453f7ff..f16f652faf80d9c503715d2f4d3eb6fde4c14232 100644
+--- a/oz/TDL.py
++++ b/oz/TDL.py
+@@ -218,8 +218,8 @@ class TDL(object):
+ 
+         self.arch = _xml_get_value(self.doc, '/template/os/arch',
+                                    'OS architecture')
+-        if self.arch not in ["i386", "x86_64", "ppc64", "ppc64le", "aarch64", "armv7l", "s390x"]:
+-            raise oz.OzException.OzException("Architecture must be one of 'i386, x86_64, ppc64, ppc64le, armv7l, aarch64, or s390x'")
++        if self.arch not in ["i386", "x86_64", "ppc64", "ppc64le", "aarch64", "armv7l", "s390x", "riscv64"]:
++            raise oz.OzException.OzException("Architecture must be one of 'i386, x86_64, ppc64, ppc64le, armv7l, aarch64, s390x, or riscv64'")
+ 
+         self.key = _xml_get_value(self.doc, '/template/os/key', 'OS key',
+                                   optional=True)
+diff --git a/oz/ozutil.py b/oz/ozutil.py
+index be27d3f08891d5d7f6d21a06e7bb9727576fb404..8f4e317b7743bdbc02f70f7de91c8683b6a536de 100644
+--- a/oz/ozutil.py
++++ b/oz/ozutil.py
+@@ -1075,6 +1075,12 @@ def find_uefi_firmware(arch):
+                           '/usr/share/edk2/aarch64/vars-template-pflash.raw'),
+                      UEFI('/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw',
+                           '/usr/share/edk2.git/aarch64/vars-template-pflash.raw')]
++    elif arch in ['riscv64']:
++        uefi_list = [UEFI('/usr/share/edk2/riscv/RISCV_VIRT_CODE.qcow2',
++                          '/usr/share/edk2/riscv/RISCV_VIRT_VARS.qcow2'),
++                     UEFI('/usr/share/edk2/riscv/RISCV_VIRT_CODE.fd',
++                          '/usr/share/edk2/riscv/RISCV_VIRT_VARS.fd')]
++
+     elif arch in ['armv7l']:
+         uefi_list = [UEFI('/usr/share/edk2/arm/QEMU_EFI-pflash.raw',
+                           '/usr/share/edk2/arm/vars-template-pflash.raw')]
+diff --git a/oz/tdl.rng b/oz/tdl.rng
+index 9ca94ccd87f0c3535befe7dfd729ac984d767585..4d7090409e439de456d4ae5d1aea6f0404924c58 100644
+--- a/oz/tdl.rng
++++ b/oz/tdl.rng
+@@ -35,6 +35,7 @@
+                 <value>aarch64</value>
+                 <value>armv7l</value>
+                 <value>s390x</value>
++                <value>riscv64</value>
+               </choice>
+             </element>
+             <optional>
+-- 
+2.47.0
+
diff --git a/oz.spec b/oz.spec
index 10ab3cede9d53959625a1caa7dabcc59db7cf88d..54ed4b8cb1dc86810f9b11166c1ede382b551b3c 100644
--- a/oz.spec
+++ b/oz.spec
@@ -1,6 +1,6 @@
 Name:    oz
 Version: 0.18.1
-Release: 23%{?dist}
+Release: 24%{?dist}
 Summary: Library and utilities for automated guest OS installs
 # Automatically converted from old format: LGPLv2 - review is highly recommended.
 License: LicenseRef-Callaway-LGPLv2
@@ -50,6 +50,9 @@ Patch: 0001-Really-rename-oz-examples.1-to-oz-examples.5.patch
 # Avoid monotonic dependency
 Patch: 0001-Switch-to-time.monotonic.patch
 
+# Enable RISC-V arch
+Patch: 0027-Enable-riscv64-arch.patch
+
 BuildArch: noarch
 
 BuildRequires: python3
@@ -143,6 +146,9 @@ libvirtd -d
 %{python3_sitelib}/%{name}*.egg-info
 
 %changelog
+* Thu Oct 02 2025 David Abdurachmanov <davidlt@rivosinc.com> - 0.18.1-24
+- Enable riscv64 arch
+
 * Fri Sep 19 2025 Python Maint <python-maint@redhat.com> - 0.18.1-23
 - Rebuilt for Python 3.14.0rc3 bytecode
 
-- 
2.47.0

