From: U2FsdGVkX1 <U2FsdGVkX1@gmail.com>
Signed-off-by: Songsong Zhang <U2FsdGVkX1@gmail.com>
Reviewed-by: Wei Fu <wefu@redhat.com>
Subject: [PATCH] Backport a riscv64 enablement patch from upstream

Signed-off-by: jchzhou <zhoujiacheng@iscas.ac.cn>
---
 pyanaconda/modules/storage/bootloader/efi.py  |  8 ++++
 .../modules/storage/bootloader/factory.py     |  8 ++++
 pyanaconda/modules/storage/platform.py        | 38 +++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/pyanaconda/modules/storage/bootloader/efi.py b/pyanaconda/modules/storage/bootloader/efi.py
index 1b47e24..6743717 100644
--- a/pyanaconda/modules/storage/bootloader/efi.py
+++ b/pyanaconda/modules/storage/bootloader/efi.py
@@ -214,6 +214,14 @@ class ArmEFIGRUB(EFIGRUB):
         self._is_32bit_firmware = True
 
 
+class RISCV64EFIGRUB(EFIGRUB):
+    _serial_consoles = ["ttyS"]
+    _efi_binary = "\\grubriscv64.efi"
+
+    def __init__(self):
+        super().__init__()
+        self._packages64 = ["grub2-efi-riscv64"]
+
 class MacEFIGRUB(EFIGRUB):
     def __init__(self):
         super().__init__()
diff --git a/pyanaconda/modules/storage/bootloader/factory.py b/pyanaconda/modules/storage/bootloader/factory.py
index 8aa3afb..4815685 100644
--- a/pyanaconda/modules/storage/bootloader/factory.py
+++ b/pyanaconda/modules/storage/bootloader/factory.py
@@ -146,4 +146,12 @@ class BootLoaderFactory(object):
             from pyanaconda.modules.storage.bootloader.efi import ArmEFIGRUB
             return ArmEFIGRUB
 
+        if platform_class is platform.RISCV64:
+            from pyanaconda.modules.storage.bootloader.extlinux import EXTLINUX
+            return EXTLINUX
+
+        if platform_class is platform.RISCV64EFI:
+            from pyanaconda.modules.storage.bootloader.efi import RISCV64EFIGRUB
+            return RISCV64EFIGRUB
+
         return None
diff --git a/pyanaconda/modules/storage/platform.py b/pyanaconda/modules/storage/platform.py
index d0aa7ca..20f2c4d 100644
--- a/pyanaconda/modules/storage/platform.py
+++ b/pyanaconda/modules/storage/platform.py
@@ -459,6 +459,40 @@ class ARM(Platform):
         }
         return dict(super().stage1_constraints, **constraints)
 
+class RISCV64(Platform):
+
+    @property
+    def stage1_suggestion(self):
+        """The platform-specific suggestion about the stage1 device."""
+        return _(
+            "You must include at least one MBR-formatted "
+            "disk as an install target."
+        )
+
+    @property
+    def stage1_descriptions(self):
+        """The platform-specific descriptions of the stage1 device."""
+        return {
+            "disk": _(MBR_DESCRIPTION),
+            "partition": _(PARTITION_DESCRIPTION)
+        }
+
+    @property
+    def stage1_constraints(self):
+        """The platform-specific constraints for the stage1 device."""
+        constraints = {
+            PLATFORM_DEVICE_TYPES: ["disk"]
+        }
+        return dict(super().stage1_constraints, **constraints)
+
+
+class RISCV64EFI(EFI):
+
+    @property
+    def non_linux_format_types(self):
+        """Format types of devices with non-linux operating systems."""
+        return ["vfat", "ntfs"]
+
 
 def get_platform():
     """Check the architecture of the system and return an instance of a
@@ -486,12 +520,16 @@ def get_platform():
             return Aarch64EFI()
         elif arch.is_arm():
             return ArmEFI()
+        elif arch.is_riscv64():
+            return RISCV64EFI()
         else:
             return EFI()
     elif arch.is_x86():
         return X86()
     elif arch.is_arm():
         return ARM()
+    elif arch.is_riscv64():
+        return RISCV64()
     else:
         raise SystemError("Could not determine system architecture.")
 
-- 
2.44.0

