diff mbox series

[9/9] RISC-V: Add to build system

Message ID 20181106175837.9083-10-agraf@suse.de
State Superseded
Headers show
Series Add RISC-V support | expand

Commit Message

Alexander Graf Nov. 6, 2018, 5:58 p.m. UTC
This patch adds support for RISC-V to the grub build system. With this
patch, I can successfully build grub on RISC-V as a UEFI application.

Signed-off-by: Alexander Graf <agraf@suse.de>

---
 configure.ac                 | 28 ++++++++++++++++++++++++++--
 gentpl.py                    |  9 ++++++---
 grub-core/Makefile.am        | 12 ++++++++++++
 grub-core/Makefile.core.def  | 29 +++++++++++++++++++++++++++++
 grub-core/commands/file.c    | 14 +++++++++++++-
 grub-core/kern/compiler-rt.c |  3 ++-
 grub-core/kern/efi/mm.c      |  2 +-
 grub-core/kern/emu/cache.c   |  6 ++++++
 grub-core/kern/emu/cache_s.S |  1 +
 grub-core/kern/emu/lite.c    |  2 ++
 grub-core/lib/efi/halt.c     |  3 ++-
 grub-core/lib/setjmp.S       |  2 ++
 include/grub/compiler-rt.h   |  6 ++++--
 include/grub/efi/api.h       |  3 ++-
 include/grub/efi/efi.h       |  2 +-
 include/grub/util/install.h  |  2 ++
 util/grub-install-common.c   |  2 ++
 util/grub-install.c          | 28 ++++++++++++++++++++++++++++
 util/grub-mknetdir.c         |  4 +++-
 util/grub-mkrescue.c         | 16 +++++++++++++++-
 util/mkimage.c               | 32 ++++++++++++++++++++++++++++++++
 21 files changed, 191 insertions(+), 15 deletions(-)

-- 
2.12.3


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Comments

Alistair Francis Nov. 8, 2018, 10:57 p.m. UTC | #1
On Tue, 2018-11-06 at 18:58 +0100, Alexander Graf wrote:
> This patch adds support for RISC-V to the grub build system. With

> this

> patch, I can successfully build grub on RISC-V as a UEFI application.

> 

> Signed-off-by: Alexander Graf <agraf@suse.de>


Reviewed-by: Alistair Francis <alistair.francis@wdc.com>


Alistair

> ---

>  configure.ac                 | 28 ++++++++++++++++++++++++++--

>  gentpl.py                    |  9 ++++++---

>  grub-core/Makefile.am        | 12 ++++++++++++

>  grub-core/Makefile.core.def  | 29 +++++++++++++++++++++++++++++

>  grub-core/commands/file.c    | 14 +++++++++++++-

>  grub-core/kern/compiler-rt.c |  3 ++-

>  grub-core/kern/efi/mm.c      |  2 +-

>  grub-core/kern/emu/cache.c   |  6 ++++++

>  grub-core/kern/emu/cache_s.S |  1 +

>  grub-core/kern/emu/lite.c    |  2 ++

>  grub-core/lib/efi/halt.c     |  3 ++-

>  grub-core/lib/setjmp.S       |  2 ++

>  include/grub/compiler-rt.h   |  6 ++++--

>  include/grub/efi/api.h       |  3 ++-

>  include/grub/efi/efi.h       |  2 +-

>  include/grub/util/install.h  |  2 ++

>  util/grub-install-common.c   |  2 ++

>  util/grub-install.c          | 28 ++++++++++++++++++++++++++++

>  util/grub-mknetdir.c         |  4 +++-

>  util/grub-mkrescue.c         | 16 +++++++++++++++-

>  util/mkimage.c               | 32 ++++++++++++++++++++++++++++++++

>  21 files changed, 191 insertions(+), 15 deletions(-)

> 

> diff --git a/configure.ac b/configure.ac

> index 5e63c4af3..2cc2ffb2c 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -104,6 +104,12 @@ case "$target_cpu" in

>    aarch64*)

>  		target_cpu=arm64

>  		;;

> +  riscv32*)

> +		target_cpu=riscv32

> +		;;

> +  riscv64*)

> +		target_cpu=riscv64

> +		;;

>  esac

>  

>  # Specify the platform (such as firmware).

> @@ -127,6 +133,8 @@ if test "x$with_platform" = x; then

>      ia64-*) platform=efi ;;

>      arm-*) platform=uboot ;;

>      arm64-*) platform=efi ;;

> +    riscv32-*) platform=efi ;;

> +    riscv64-*) platform=efi ;;

>      *)

>        AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building

> utilities])

>        platform=none

> @@ -174,6 +182,8 @@ case "$target_cpu"-"$platform" in

>    arm-coreboot) ;;

>    arm-efi) ;;

>    arm64-efi) ;;

> +  riscv32-efi) ;;

> +  riscv64-efi) ;;

>    *-emu) ;;

>    *-none) ;;

>    *) AC_MSG_ERROR([platform "$platform" is not supported for target

> CPU "$target_cpu"]) ;;

> @@ -826,6 +836,16 @@ if test x"$platform" != xemu ; then

>         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],

>  		         [grub_cv_target_cc_soft_float="-mgeneral-regs-

> only"], [])

>      fi

> +    if test "x$target_cpu" = xriscv32; then

> +       CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror"

> +       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],

> +		         [grub_cv_target_cc_soft_float="-march=rv32imac 

> -mabi=ilp32"], [])

> +    fi

> +    if test "x$target_cpu" = xriscv64; then

> +       CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror"

> +       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],

> +		         [grub_cv_target_cc_soft_float="-march=rv64imac 

> -mabi=lp64"], [])

> +    fi

>      if test "x$target_cpu" = xia64; then

>         CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-

> sqrt -Werror"

>         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],

> @@ -1141,7 +1161,7 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)

>  

>  LDFLAGS="$TARGET_LDFLAGS"

>  

> -if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ;

> then

> +if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ||

> test "$target_cpu" = riscv64 ; then

>    # Use large model to support 4G memory

>    AC_CACHE_CHECK([whether option -mcmodel=large works],

> grub_cv_cc_mcmodel, [

>      CFLAGS="$TARGET_CFLAGS -mcmodel=large"

> @@ -1151,7 +1171,7 @@ if test "$target_cpu" = x86_64 || test

> "$target_cpu" = sparc64 ; then

>    ])

>    if test "x$grub_cv_cc_mcmodel" = xyes; then

>      TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"

> -  elif test "$target_cpu" = sparc64; then

> +  elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64;

> then

>      TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"

>    fi

>  fi

> @@ -1913,6 +1933,10 @@ AM_CONDITIONAL([COND_arm_coreboot], [test

> x$target_cpu = xarm -a x$platform = xc

>  AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a

> x$platform = xefi])

>  AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])

>  AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a

> x$platform = xefi])

> +AM_CONDITIONAL([COND_riscv32], [test x$target_cpu = xriscv32 ])

> +AM_CONDITIONAL([COND_riscv64], [test x$target_cpu = xriscv64 ])

> +AM_CONDITIONAL([COND_riscv32_efi], [test x$target_cpu = xriscv32 -a

> x$platform = xefi])

> +AM_CONDITIONAL([COND_riscv64_efi], [test x$target_cpu = xriscv64 -a

> x$platform = xefi])

>  

>  AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])

>  AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])

> diff --git a/gentpl.py b/gentpl.py

> index da67965a4..6a34a30b3 100644

> --- a/gentpl.py

> +++ b/gentpl.py

> @@ -32,7 +32,7 @@ GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi",

> "i386_qemu", "i386_coreboot",

>                     "mips_loongson", "sparc64_ieee1275",

>                     "powerpc_ieee1275", "mips_arc", "ia64_efi",

>                     "mips_qemu_mips", "arm_uboot", "arm_efi",

> "arm64_efi",

> -                   "arm_coreboot"]

> +                   "arm_coreboot", "riscv32_efi", "riscv64_efi" ]

>  

>  GROUPS = {}

>  

> @@ -47,9 +47,12 @@ GROUPS["sparc64"]  = [ "sparc64_ieee1275" ]

>  GROUPS["powerpc"]  = [ "powerpc_ieee1275" ]

>  GROUPS["arm"]      = [ "arm_uboot", "arm_efi", "arm_coreboot" ]

>  GROUPS["arm64"]    = [ "arm64_efi" ]

> +GROUPS["riscv32"]  = [ "riscv32_efi" ]

> +GROUPS["riscv64"]  = [ "riscv64_efi" ]

>  

>  # Groups based on firmware

> -GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi",

> "arm64_efi" ]

> +GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi",

> "arm64_efi",

> +		   "riscv32_efi", "riscv64_efi" ]

>  GROUPS["ieee1275"]   = [ "i386_ieee1275", "sparc64_ieee1275",

> "powerpc_ieee1275" ]

>  GROUPS["uboot"] = [ "arm_uboot" ]

>  GROUPS["xen"]  = [ "i386_xen", "x86_64_xen" ]

> @@ -76,7 +79,7 @@ GROUPS["terminfomodule"]   = GRUB_PLATFORMS[:];

>  for i in GROUPS["terminfoinkernel"]:

> GROUPS["terminfomodule"].remove(i)

>  

>  # Flattened Device Trees (FDT)

> -GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi" ]

> +GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi",

> "riscv32_efi", "riscv64_efi" ]

>  

>  # Needs software helpers for division

>  # Must match GRUB_DIVISION_IN_SOFTWARE in misc.h

> diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am

> index f4ff62b76..30e849c5e 100644

> --- a/grub-core/Makefile.am

> +++ b/grub-core/Makefile.am

> @@ -266,6 +266,18 @@ KERNEL_HEADER_FILES +=

> $(top_srcdir)/include/grub/efi/disk.h

>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h

>  endif

>  

> +if COND_riscv32_efi

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h

> +endif

> +

> +if COND_riscv64_efi

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h

> +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h

> +endif

> +

>  if COND_emu

>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h

>  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h

> diff --git a/grub-core/Makefile.core.def b/grub-

> core/Makefile.core.def

> index 9590e87d9..21f6e227f 100644

> --- a/grub-core/Makefile.core.def

> +++ b/grub-core/Makefile.core.def

> @@ -65,6 +65,12 @@ kernel = {

>    arm64_efi_ldflags          = '-Wl,-r,-d';

>    arm64_efi_stripflags       = '--strip-unneeded -K start -R .note

> -R .comment -R .note.gnu.gold-version -R .eh_frame';

>  

> +  riscv32_efi_ldflags      = '-Wl,-r,-d';

> +  riscv32_efi_stripflags   = '--strip-unneeded -K start -R .note -R

> .comment -R .note.gnu.gold-version -R .eh_frame';

> +

> +  riscv64_efi_ldflags      = '-Wl,-r,-d';

> +  riscv64_efi_stripflags   = '--strip-unneeded -K start -R .note -R

> .comment -R .note.gnu.gold-version -R .eh_frame';

> +

>    i386_pc_ldflags          = '$(TARGET_IMG_LDFLAGS)';

>    i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT),0x9000';

>    i386_qemu_ldflags        = '$(TARGET_IMG_LDFLAGS)';

> @@ -111,6 +117,8 @@ kernel = {

>    arm_coreboot_startup = kern/arm/startup.S;

>    arm_efi_startup = kern/arm/efi/startup.S;

>    arm64_efi_startup = kern/arm64/efi/startup.S;

> +  riscv32_efi_startup = kern/riscv/efi/startup.S;

> +  riscv64_efi_startup = kern/riscv/efi/startup.S;

>  

>    common = kern/command.c;

>    common = kern/corecmd.c;

> @@ -234,6 +242,12 @@ kernel = {

>    arm64_efi = kern/arm64/efi/init.c;

>    arm64_efi = kern/efi/fdt.c;

>  

> +  riscv32_efi = kern/riscv/efi/init.c;

> +  riscv32_efi = kern/efi/fdt.c;

> +

> +  riscv64_efi = kern/riscv/efi/init.c;

> +  riscv64_efi = kern/efi/fdt.c;

> +

>    i386_pc = kern/i386/pc/init.c;

>    i386_pc = kern/i386/pc/mmap.c;

>    i386_pc = term/i386/pc/console.c;

> @@ -305,6 +319,14 @@ kernel = {

>    arm64 = kern/arm64/dl.c;

>    arm64 = kern/arm64/dl_helper.c;

>  

> +  riscv32 = kern/riscv/cache.c;

> +  riscv32 = kern/riscv/cache_flush.S;

> +  riscv32 = kern/riscv/dl.c;

> +

> +  riscv64 = kern/riscv/cache.c;

> +  riscv64 = kern/riscv/cache_flush.S;

> +  riscv64 = kern/riscv/dl.c;

> +

>    emu = disk/host.c;

>    emu = kern/emu/cache_s.S;

>    emu = kern/emu/hostdisk.c;

> @@ -780,6 +802,8 @@ module = {

>    enable = arm64_efi;

>    enable = arm_uboot;

>    enable = arm_coreboot;

> +  enable = riscv32_efi;

> +  enable = riscv64_efi;

>  };

>  

>  module = {

> @@ -1600,6 +1624,7 @@ module = {

>    extra_dist = lib/ia64/longjmp.S;

>    extra_dist = lib/arm/setjmp.S;

>    extra_dist = lib/arm64/setjmp.S;

> +  extra_dist = lib/riscv/setjmp.S;

>  };

>  

>  module = {

> @@ -1696,6 +1721,8 @@ module = {

>    arm_efi = loader/arm64/linux.c;

>    arm_uboot = loader/arm/linux.c;

>    arm64 = loader/arm64/linux.c;

> +  riscv32 = loader/riscv/linux.c;

> +  riscv64 = loader/riscv/linux.c;

>    common = loader/linux.c;

>    common = lib/cmdline.c;

>    enable = noemu;

> @@ -1787,6 +1814,8 @@ module = {

>    enable = ia64_efi;

>    enable = arm_efi;

>    enable = arm64_efi;

> +  enable = riscv32_efi;

> +  enable = riscv64_efi;

>    enable = mips;

>  };

>  

> diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c

> index 3ff6d5522..1f8c492dd 100644

> --- a/grub-core/commands/file.c

> +++ b/grub-core/commands/file.c

> @@ -90,6 +90,10 @@ static const struct grub_arg_option options[] = {

>     N_("Check if FILE is ARM64 EFI file"), 0, 0},

>    {"is-arm-efi", 0, 0,

>     N_("Check if FILE is ARM EFI file"), 0, 0},

> +  {"is-riscv32-efi", 0, 0,

> +   N_("Check if FILE is RISC-V 32bit EFI file"), 0, 0},

> +  {"is-riscv64-efi", 0, 0,

> +   N_("Check if FILE is RISC-V 64bit EFI file"), 0, 0},

>    {"is-hibernated-hiberfil", 0, 0,

>     N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0},

>    {"is-x86_64-xnu", 0, 0,

> @@ -130,6 +134,7 @@ enum

>    IS_IA_EFI,

>    IS_ARM64_EFI,

>    IS_ARM_EFI,

> +  IS_RISCV_EFI,

>    IS_HIBERNATED,

>    IS_XNU64,

>    IS_XNU32,

> @@ -570,6 +575,7 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int

> argc, char **args)

>      case IS_IA_EFI:

>      case IS_ARM64_EFI:

>      case IS_ARM_EFI:

> +    case IS_RISCV_EFI:

>        {

>  	char signature[4];

>  	grub_uint32_t pe_offset;

> @@ -615,7 +621,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int

> argc, char **args)

>  	    && coff_head.machine !=

>  	    grub_cpu_to_le16_compile_time

> (GRUB_PE32_MACHINE_ARMTHUMB_MIXED))

>  	  break;

> -	if (type == IS_IA_EFI || type == IS_64_EFI || type ==

> IS_ARM64_EFI)

> +	if (type == IS_RISCV_EFI

> +	    && coff_head.machine !=

> +	    grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV64))

> +          /* TODO: Determine bitness dynamically */

> +	  break;

> +	if (type == IS_IA_EFI || type == IS_64_EFI || type ==

> IS_ARM64_EFI ||

> +	    type == IS_RISCV_EFI)

>  	  {

>  	    struct grub_pe64_optional_header o64;

>  	    if (grub_file_read (file, &o64, sizeof (o64)) != sizeof

> (o64))

> diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-

> rt.c

> index 5cfcb3907..0c0c3629f 100644

> --- a/grub-core/kern/compiler-rt.c

> +++ b/grub-core/kern/compiler-rt.c

> @@ -343,7 +343,8 @@ __ucmpdi2 (grub_uint64_t a, grub_uint64_t b)

>  

>  #endif

>  

> -#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__)

> || defined(__arm__)

> +#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__)

> || \

> +    defined(__arm__) || defined(__riscv)

>  

>  /* Based on libgcc2.c from gcc suite.  */

>  grub_uint32_t

> diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c

> index 42ad7c570..a29af9fa5 100644

> --- a/grub-core/kern/efi/mm.c

> +++ b/grub-core/kern/efi/mm.c

> @@ -634,7 +634,7 @@ grub_efi_mm_init (void)

>  		       2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));

>  }

>  

> -#if defined (__aarch64__) || defined (__arm__)

> +#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)

>  grub_err_t

>  grub_efi_get_ram_base(grub_addr_t *base_addr)

>  {

> diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c

> index 6f89e871a..113682cc4 100644

> --- a/grub-core/kern/emu/cache.c

> +++ b/grub-core/kern/emu/cache.c

> @@ -25,5 +25,11 @@ grub_arch_sync_caches (void *address, grub_size_t

> len)

>    return _flush_cache (address, len, 0);

>  }

>  

> +#elif defined(__riscv)

> +void

> +grub_arch_sync_caches (void *address, grub_size_t len)

> +{

> +}

> +

>  #endif

>  

> diff --git a/grub-core/kern/emu/cache_s.S b/grub-

> core/kern/emu/cache_s.S

> index 76cf7560d..e27b865f9 100644

> --- a/grub-core/kern/emu/cache_s.S

> +++ b/grub-core/kern/emu/cache_s.S

> @@ -9,6 +9,7 @@

>  #elif defined(__powerpc__)

>  #include "../powerpc/cache.S"

>  #elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__)

> || defined(__mips__)

> +#elif defined(__riscv)

>  #else

>  #error "No target cpu type is defined"

>  #endif

> diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c

> index b2fc93d7f..b327d4e41 100644

> --- a/grub-core/kern/emu/lite.c

> +++ b/grub-core/kern/emu/lite.c

> @@ -24,6 +24,8 @@

>  #elif defined(__aarch64__)

>  #include "../arm64/dl_helper.c"

>  #include "../arm64/dl.c"

> +#elif defined(__riscv)

> +#include "../riscv/dl.c"

>  #else

>  #error "No target cpu type is defined"

>  #endif

> diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c

> index e9441c844..5859f0498 100644

> --- a/grub-core/lib/efi/halt.c

> +++ b/grub-core/lib/efi/halt.c

> @@ -29,7 +29,8 @@ void

>  grub_halt (void)

>  {

>    grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);

> -#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__)

> +#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__)

> && \

> +    !defined(__riscv)

>    grub_acpi_halt ();

>  #endif

>    efi_call_4 (grub_efi_system_table->runtime_services->reset_system,

> diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S

> index f6e4905e2..aa297ab0a 100644

> --- a/grub-core/lib/setjmp.S

> +++ b/grub-core/lib/setjmp.S

> @@ -15,6 +15,8 @@

>  #include "./arm/setjmp.S"

>  #elif defined(__aarch64__)

>  #include "./arm64/setjmp.S"

> +#elif defined(__riscv)

> +#include "./riscv/setjmp.S"

>  #else

>  #error "Unknown target cpu type"

>  #endif

> diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h

> index dc73649a5..d4f2c125f 100644

> --- a/include/grub/compiler-rt.h

> +++ b/include/grub/compiler-rt.h

> @@ -53,7 +53,8 @@ EXPORT_FUNC (__umoddi3) (grub_uint64_t a,

> grub_uint64_t b);

>  

>  #endif

>  

> -#if defined (__sparc__) || defined (__powerpc__) || defined

> (__mips__) || defined (__arm__)

> +#if defined (__sparc__) || defined (__powerpc__) || defined

> (__mips__) || \

> +    defined (__arm__) || defined(__riscv)

>  unsigned

>  EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);

>  #define NEED_CTZDI2 1

> @@ -165,7 +166,8 @@ grub_uint64_t

>  EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);

>  #endif

>  

> -#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__)

> || defined (__arm__)

> +#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__)

> || \

> +    defined (__arm__) || defined(__riscv)

>  grub_uint32_t

>  EXPORT_FUNC(__bswapsi2) (grub_uint32_t u);

>  

> diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h

> index c7c9f0e1d..addcbfa8f 100644

> --- a/include/grub/efi/api.h

> +++ b/include/grub/efi/api.h

> @@ -1686,7 +1686,8 @@ struct grub_efi_block_io

>  typedef struct grub_efi_block_io grub_efi_block_io_t;

>  

>  #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \

> -  || defined (__aarch64__) || defined (__MINGW64__) || defined

> (__CYGWIN__)

> +  || defined (__aarch64__) || defined (__MINGW64__) || defined

> (__CYGWIN__) \

> +  || defined(__riscv)

>  

>  #define efi_call_0(func)		func()

>  #define efi_call_1(func, a)		func(a)

> diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h

> index ec44aef7e..e90e00dc4 100644

> --- a/include/grub/efi/efi.h

> +++ b/include/grub/efi/efi.h

> @@ -90,7 +90,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config))

> (grub_efi_handle_t hnd,

>  						char **device,

>  						char **path);

>  

> -#if defined(__arm__) || defined(__aarch64__)

> +#if defined(__arm__) || defined(__aarch64__) || defined(__riscv)

>  void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);

>  grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);

>  #include <grub/cpu/linux.h>

> diff --git a/include/grub/util/install.h

> b/include/grub/util/install.h

> index 0dba8b67f..15186e8ea 100644

> --- a/include/grub/util/install.h

> +++ b/include/grub/util/install.h

> @@ -102,6 +102,8 @@ enum grub_install_plat

>      GRUB_INSTALL_PLATFORM_X86_64_XEN,

>      GRUB_INSTALL_PLATFORM_ARM64_EFI,

>      GRUB_INSTALL_PLATFORM_ARM_COREBOOT,

> +    GRUB_INSTALL_PLATFORM_RISCV32_EFI,

> +    GRUB_INSTALL_PLATFORM_RISCV64_EFI,

>      GRUB_INSTALL_PLATFORM_MAX

>    };

>  

> diff --git a/util/grub-install-common.c b/util/grub-install-common.c

> index 0a2e24a79..d0cc93725 100644

> --- a/util/grub-install-common.c

> +++ b/util/grub-install-common.c

> @@ -728,6 +728,8 @@ static struct

>      [GRUB_INSTALL_PLATFORM_ARM64_EFI] =        {

> "arm64",   "efi"       },

>      [GRUB_INSTALL_PLATFORM_ARM_UBOOT] =        {

> "arm",     "uboot"     },

>      [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] =     {

> "arm",     "coreboot"  },

> +    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] =      { "riscv32",

> "efi"       },

> +    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] =      { "riscv64",

> "efi"       },

>    }; 

>  

>  char *

> diff --git a/util/grub-install.c b/util/grub-install.c

> index 78d0138cb..6649b2c14 100644

> --- a/util/grub-install.c

> +++ b/util/grub-install.c

> @@ -477,6 +477,8 @@ have_bootdev (enum grub_install_plat pl)

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_I386_IEEE1275:

>      case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:

>      case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:

> @@ -899,6 +901,8 @@ main (int argc, char *argv[])

>      case GRUB_INSTALL_PLATFORM_X86_64_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>      case GRUB_INSTALL_PLATFORM_I386_IEEE1275:

>      case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:

> @@ -943,6 +947,8 @@ main (int argc, char *argv[])

>      case GRUB_INSTALL_PLATFORM_X86_64_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>      case GRUB_INSTALL_PLATFORM_I386_IEEE1275:

>      case GRUB_INSTALL_PLATFORM_ARM_UBOOT:

> @@ -995,6 +1001,8 @@ main (int argc, char *argv[])

>      case GRUB_INSTALL_PLATFORM_X86_64_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>        is_efi = 1;

>        break;

> @@ -1108,6 +1116,12 @@ main (int argc, char *argv[])

>  	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:

>  	      efi_file = "BOOTAA64.EFI";

>  	      break;

> +	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +	      efi_file = "BOOTRISCV32.EFI";

> +	      break;

> +	    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

> +	      efi_file = "BOOTRISCV64.EFI";

> +	      break;

>  	    default:

>  	      grub_util_error ("%s", _("You've found a bug"));

>  	      break;

> @@ -1135,6 +1149,12 @@ main (int argc, char *argv[])

>  	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:

>  	      efi_file = "grubaa64.efi";

>  	      break;

> +	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +	      efi_file = "grubriscv32.efi";

> +	      break;

> +	    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

> +	      efi_file = "grubriscv64.efi";

> +	      break;

>  	    default:

>  	      efi_file = "grub.efi";

>  	      break;

> @@ -1437,6 +1457,8 @@ main (int argc, char *argv[])

>  		  case GRUB_INSTALL_PLATFORM_X86_64_EFI:

>  		  case GRUB_INSTALL_PLATFORM_ARM_EFI:

>  		  case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +		  case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +		  case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>  		  case GRUB_INSTALL_PLATFORM_IA64_EFI:

>  		    g = grub_util_guess_efi_drive (*curdev);

>  		    break;

> @@ -1529,6 +1551,8 @@ main (int argc, char *argv[])

>      case GRUB_INSTALL_PLATFORM_X86_64_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>        core_name = "core.efi";

>        snprintf (mkimage_target, sizeof (mkimage_target),

> @@ -1631,6 +1655,8 @@ main (int argc, char *argv[])

>        break;

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>      case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:

>      case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:

> @@ -1865,6 +1891,8 @@ main (int argc, char *argv[])

>        /* FALLTHROUGH */

>      case GRUB_INSTALL_PLATFORM_ARM_EFI:

>      case GRUB_INSTALL_PLATFORM_ARM64_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:

> +    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:

>      case GRUB_INSTALL_PLATFORM_IA64_EFI:

>        {

>  	char *dst = grub_util_path_concat (2, efidir, efi_file);

> diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c

> index 82073d5cc..602574d52 100644

> --- a/util/grub-mknetdir.c

> +++ b/util/grub-mknetdir.c

> @@ -107,7 +107,9 @@ static const struct

>      [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet",

> ".efi" },

>      [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet",

> ".efi" },

>      [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi"

> },

> -    [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet",

> ".efi" }

> +    [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet",

> ".efi" },

> +    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet",

> ".efi" },

> +    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet",

> ".efi" },

>    };

>  

>  static void

> diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c

> index 9545945d8..21e5ce4e4 100644

> --- a/util/grub-mkrescue.c

> +++ b/util/grub-mkrescue.c

> @@ -538,6 +538,8 @@ main (int argc, char *argv[])

>  	  || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]

>  	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]

>  	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]

> +	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]

> +	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]

>  	  || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])

>  	system_area = SYS_AREA_COMMON;

>        else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275])

> @@ -735,7 +737,9 @@ main (int argc, char *argv[])

>        || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]

>        || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]

>        || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]

> -      || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI])

> +      || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]

> +      || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]

> +      || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])

>      {

>        char *efidir = grub_util_make_temporary_dir ();

>        char *efidir_efi = grub_util_path_concat (2, efidir, "efi");

> @@ -770,6 +774,16 @@ main (int argc, char *argv[])

>  			     imgname);

>        free (imgname);

>  

> +      imgname = grub_util_path_concat (2, efidir_efi_boot,

> "bootriscv32.efi");

> +      make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI,

> "riscv32-efi",

> +			     imgname);

> +      free (imgname);

> +

> +      imgname = grub_util_path_concat (2, efidir_efi_boot,

> "bootriscv64.efi");

> +      make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI,

> "riscv64-efi",

> +			     imgname);

> +      free (imgname);

> +

>        if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])

>  	{

>  	  imgname = grub_util_path_concat (2, efidir_efi_boot,

> "boot.efi");

> diff --git a/util/mkimage.c b/util/mkimage.c

> index e22d82afa..b5368ffd2 100644

> --- a/util/mkimage.c

> +++ b/util/mkimage.c

> @@ -609,6 +609,38 @@ static const struct

> grub_install_image_target_desc image_targets[] =

>        .pe_target = GRUB_PE32_MACHINE_ARM64,

>        .elf_target = EM_AARCH64,

>      },

> +    {

> +      .dirname = "riscv32-efi",

> +      .names = { "riscv32-efi", NULL },

> +      .voidp_sizeof = 4,

> +      .bigendian = 0,

> +      .id = IMAGE_EFI,

> +      .flags = PLATFORM_FLAGS_NONE,

> +      .total_module_size = TARGET_NO_FIELD,

> +      .decompressor_compressed_size = TARGET_NO_FIELD,

> +      .decompressor_uncompressed_size = TARGET_NO_FIELD,

> +      .decompressor_uncompressed_addr = TARGET_NO_FIELD,

> +      .section_align = GRUB_PE32_SECTION_ALIGNMENT,

> +      .vaddr_offset = EFI32_HEADER_SIZE,

> +      .pe_target = GRUB_PE32_MACHINE_RISCV32,

> +      .elf_target = EM_RISCV,

> +    },

> +    {

> +      .dirname = "riscv64-efi",

> +      .names = { "riscv64-efi", NULL },

> +      .voidp_sizeof = 8,

> +      .bigendian = 0,

> +      .id = IMAGE_EFI,

> +      .flags = PLATFORM_FLAGS_NONE,

> +      .total_module_size = TARGET_NO_FIELD,

> +      .decompressor_compressed_size = TARGET_NO_FIELD,

> +      .decompressor_uncompressed_size = TARGET_NO_FIELD,

> +      .decompressor_uncompressed_addr = TARGET_NO_FIELD,

> +      .section_align = GRUB_PE32_SECTION_ALIGNMENT,

> +      .vaddr_offset = EFI64_HEADER_SIZE,

> +      .pe_target = GRUB_PE32_MACHINE_RISCV64,

> +      .elf_target = EM_RISCV,

> +    },

>    };

>  

>  #include <grub/lib/LzmaEnc.h>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 5e63c4af3..2cc2ffb2c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,12 @@  case "$target_cpu" in
   aarch64*)
 		target_cpu=arm64
 		;;
+  riscv32*)
+		target_cpu=riscv32
+		;;
+  riscv64*)
+		target_cpu=riscv64
+		;;
 esac
 
 # Specify the platform (such as firmware).
@@ -127,6 +133,8 @@  if test "x$with_platform" = x; then
     ia64-*) platform=efi ;;
     arm-*) platform=uboot ;;
     arm64-*) platform=efi ;;
+    riscv32-*) platform=efi ;;
+    riscv64-*) platform=efi ;;
     *)
       AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities])
       platform=none
@@ -174,6 +182,8 @@  case "$target_cpu"-"$platform" in
   arm-coreboot) ;;
   arm-efi) ;;
   arm64-efi) ;;
+  riscv32-efi) ;;
+  riscv64-efi) ;;
   *-emu) ;;
   *-none) ;;
   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
@@ -826,6 +836,16 @@  if test x"$platform" != xemu ; then
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
 		         [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], [])
     fi
+    if test "x$target_cpu" = xriscv32; then
+       CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror"
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+		         [grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], [])
+    fi
+    if test "x$target_cpu" = xriscv64; then
+       CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror"
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+		         [grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], [])
+    fi
     if test "x$target_cpu" = xia64; then
        CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
@@ -1141,7 +1161,7 @@  AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
 
 LDFLAGS="$TARGET_LDFLAGS"
 
-if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
+if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
   # Use large model to support 4G memory
   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
     CFLAGS="$TARGET_CFLAGS -mcmodel=large"
@@ -1151,7 +1171,7 @@  if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
   ])
   if test "x$grub_cv_cc_mcmodel" = xyes; then
     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
-  elif test "$target_cpu" = sparc64; then
+  elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
   fi
 fi
@@ -1913,6 +1933,10 @@  AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xc
 AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
 AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
 AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
+AM_CONDITIONAL([COND_riscv32], [test x$target_cpu = xriscv32 ])
+AM_CONDITIONAL([COND_riscv64], [test x$target_cpu = xriscv64 ])
+AM_CONDITIONAL([COND_riscv32_efi], [test x$target_cpu = xriscv32 -a x$platform = xefi])
+AM_CONDITIONAL([COND_riscv64_efi], [test x$target_cpu = xriscv64 -a x$platform = xefi])
 
 AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
 AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
diff --git a/gentpl.py b/gentpl.py
index da67965a4..6a34a30b3 100644
--- a/gentpl.py
+++ b/gentpl.py
@@ -32,7 +32,7 @@  GRUB_PLATFORMS = [ "emu", "i386_pc", "i386_efi", "i386_qemu", "i386_coreboot",
                    "mips_loongson", "sparc64_ieee1275",
                    "powerpc_ieee1275", "mips_arc", "ia64_efi",
                    "mips_qemu_mips", "arm_uboot", "arm_efi", "arm64_efi",
-                   "arm_coreboot"]
+                   "arm_coreboot", "riscv32_efi", "riscv64_efi" ]
 
 GROUPS = {}
 
@@ -47,9 +47,12 @@  GROUPS["sparc64"]  = [ "sparc64_ieee1275" ]
 GROUPS["powerpc"]  = [ "powerpc_ieee1275" ]
 GROUPS["arm"]      = [ "arm_uboot", "arm_efi", "arm_coreboot" ]
 GROUPS["arm64"]    = [ "arm64_efi" ]
+GROUPS["riscv32"]  = [ "riscv32_efi" ]
+GROUPS["riscv64"]  = [ "riscv64_efi" ]
 
 # Groups based on firmware
-GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ]
+GROUPS["efi"]  = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi",
+		   "riscv32_efi", "riscv64_efi" ]
 GROUPS["ieee1275"]   = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ]
 GROUPS["uboot"] = [ "arm_uboot" ]
 GROUPS["xen"]  = [ "i386_xen", "x86_64_xen" ]
@@ -76,7 +79,7 @@  GROUPS["terminfomodule"]   = GRUB_PLATFORMS[:];
 for i in GROUPS["terminfoinkernel"]: GROUPS["terminfomodule"].remove(i)
 
 # Flattened Device Trees (FDT)
-GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi" ]
+GROUPS["fdt"] = [ "arm64_efi", "arm_uboot", "arm_efi", "riscv32_efi", "riscv64_efi" ]
 
 # Needs software helpers for division
 # Must match GRUB_DIVISION_IN_SOFTWARE in misc.h
diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
index f4ff62b76..30e849c5e 100644
--- a/grub-core/Makefile.am
+++ b/grub-core/Makefile.am
@@ -266,6 +266,18 @@  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
 endif
 
+if COND_riscv32_efi
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
+endif
+
+if COND_riscv64_efi
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
+endif
+
 if COND_emu
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/datetime.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/misc.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 9590e87d9..21f6e227f 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -65,6 +65,12 @@  kernel = {
   arm64_efi_ldflags          = '-Wl,-r,-d';
   arm64_efi_stripflags       = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
 
+  riscv32_efi_ldflags      = '-Wl,-r,-d';
+  riscv32_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
+
+  riscv64_efi_ldflags      = '-Wl,-r,-d';
+  riscv64_efi_stripflags   = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version -R .eh_frame';
+
   i386_pc_ldflags          = '$(TARGET_IMG_LDFLAGS)';
   i386_pc_ldflags          = '$(TARGET_IMG_BASE_LDOPT),0x9000';
   i386_qemu_ldflags        = '$(TARGET_IMG_LDFLAGS)';
@@ -111,6 +117,8 @@  kernel = {
   arm_coreboot_startup = kern/arm/startup.S;
   arm_efi_startup = kern/arm/efi/startup.S;
   arm64_efi_startup = kern/arm64/efi/startup.S;
+  riscv32_efi_startup = kern/riscv/efi/startup.S;
+  riscv64_efi_startup = kern/riscv/efi/startup.S;
 
   common = kern/command.c;
   common = kern/corecmd.c;
@@ -234,6 +242,12 @@  kernel = {
   arm64_efi = kern/arm64/efi/init.c;
   arm64_efi = kern/efi/fdt.c;
 
+  riscv32_efi = kern/riscv/efi/init.c;
+  riscv32_efi = kern/efi/fdt.c;
+
+  riscv64_efi = kern/riscv/efi/init.c;
+  riscv64_efi = kern/efi/fdt.c;
+
   i386_pc = kern/i386/pc/init.c;
   i386_pc = kern/i386/pc/mmap.c;
   i386_pc = term/i386/pc/console.c;
@@ -305,6 +319,14 @@  kernel = {
   arm64 = kern/arm64/dl.c;
   arm64 = kern/arm64/dl_helper.c;
 
+  riscv32 = kern/riscv/cache.c;
+  riscv32 = kern/riscv/cache_flush.S;
+  riscv32 = kern/riscv/dl.c;
+
+  riscv64 = kern/riscv/cache.c;
+  riscv64 = kern/riscv/cache_flush.S;
+  riscv64 = kern/riscv/dl.c;
+
   emu = disk/host.c;
   emu = kern/emu/cache_s.S;
   emu = kern/emu/hostdisk.c;
@@ -780,6 +802,8 @@  module = {
   enable = arm64_efi;
   enable = arm_uboot;
   enable = arm_coreboot;
+  enable = riscv32_efi;
+  enable = riscv64_efi;
 };
 
 module = {
@@ -1600,6 +1624,7 @@  module = {
   extra_dist = lib/ia64/longjmp.S;
   extra_dist = lib/arm/setjmp.S;
   extra_dist = lib/arm64/setjmp.S;
+  extra_dist = lib/riscv/setjmp.S;
 };
 
 module = {
@@ -1696,6 +1721,8 @@  module = {
   arm_efi = loader/arm64/linux.c;
   arm_uboot = loader/arm/linux.c;
   arm64 = loader/arm64/linux.c;
+  riscv32 = loader/riscv/linux.c;
+  riscv64 = loader/riscv/linux.c;
   common = loader/linux.c;
   common = lib/cmdline.c;
   enable = noemu;
@@ -1787,6 +1814,8 @@  module = {
   enable = ia64_efi;
   enable = arm_efi;
   enable = arm64_efi;
+  enable = riscv32_efi;
+  enable = riscv64_efi;
   enable = mips;
 };
 
diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 3ff6d5522..1f8c492dd 100644
--- a/grub-core/commands/file.c
+++ b/grub-core/commands/file.c
@@ -90,6 +90,10 @@  static const struct grub_arg_option options[] = {
    N_("Check if FILE is ARM64 EFI file"), 0, 0},
   {"is-arm-efi", 0, 0,
    N_("Check if FILE is ARM EFI file"), 0, 0},
+  {"is-riscv32-efi", 0, 0,
+   N_("Check if FILE is RISC-V 32bit EFI file"), 0, 0},
+  {"is-riscv64-efi", 0, 0,
+   N_("Check if FILE is RISC-V 64bit EFI file"), 0, 0},
   {"is-hibernated-hiberfil", 0, 0,
    N_("Check if FILE is hiberfil.sys in hibernated state"), 0, 0},
   {"is-x86_64-xnu", 0, 0,
@@ -130,6 +134,7 @@  enum
   IS_IA_EFI,
   IS_ARM64_EFI,
   IS_ARM_EFI,
+  IS_RISCV_EFI,
   IS_HIBERNATED,
   IS_XNU64,
   IS_XNU32,
@@ -570,6 +575,7 @@  grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
     case IS_IA_EFI:
     case IS_ARM64_EFI:
     case IS_ARM_EFI:
+    case IS_RISCV_EFI:
       {
 	char signature[4];
 	grub_uint32_t pe_offset;
@@ -615,7 +621,13 @@  grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
 	    && coff_head.machine !=
 	    grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_ARMTHUMB_MIXED))
 	  break;
-	if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI)
+	if (type == IS_RISCV_EFI
+	    && coff_head.machine !=
+	    grub_cpu_to_le16_compile_time (GRUB_PE32_MACHINE_RISCV64))
+          /* TODO: Determine bitness dynamically */
+	  break;
+	if (type == IS_IA_EFI || type == IS_64_EFI || type == IS_ARM64_EFI ||
+	    type == IS_RISCV_EFI)
 	  {
 	    struct grub_pe64_optional_header o64;
 	    if (grub_file_read (file, &o64, sizeof (o64)) != sizeof (o64))
diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c
index 5cfcb3907..0c0c3629f 100644
--- a/grub-core/kern/compiler-rt.c
+++ b/grub-core/kern/compiler-rt.c
@@ -343,7 +343,8 @@  __ucmpdi2 (grub_uint64_t a, grub_uint64_t b)
 
 #endif
 
-#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || defined(__arm__)
+#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \
+    defined(__arm__) || defined(__riscv)
 
 /* Based on libgcc2.c from gcc suite.  */
 grub_uint32_t
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 42ad7c570..a29af9fa5 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -634,7 +634,7 @@  grub_efi_mm_init (void)
 		       2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
 }
 
-#if defined (__aarch64__) || defined (__arm__)
+#if defined (__aarch64__) || defined (__arm__) || defined (__riscv)
 grub_err_t
 grub_efi_get_ram_base(grub_addr_t *base_addr)
 {
diff --git a/grub-core/kern/emu/cache.c b/grub-core/kern/emu/cache.c
index 6f89e871a..113682cc4 100644
--- a/grub-core/kern/emu/cache.c
+++ b/grub-core/kern/emu/cache.c
@@ -25,5 +25,11 @@  grub_arch_sync_caches (void *address, grub_size_t len)
   return _flush_cache (address, len, 0);
 }
 
+#elif defined(__riscv)
+void
+grub_arch_sync_caches (void *address, grub_size_t len)
+{
+}
+
 #endif
 
diff --git a/grub-core/kern/emu/cache_s.S b/grub-core/kern/emu/cache_s.S
index 76cf7560d..e27b865f9 100644
--- a/grub-core/kern/emu/cache_s.S
+++ b/grub-core/kern/emu/cache_s.S
@@ -9,6 +9,7 @@ 
 #elif defined(__powerpc__)
 #include "../powerpc/cache.S"
 #elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || defined(__mips__)
+#elif defined(__riscv)
 #else
 #error "No target cpu type is defined"
 #endif
diff --git a/grub-core/kern/emu/lite.c b/grub-core/kern/emu/lite.c
index b2fc93d7f..b327d4e41 100644
--- a/grub-core/kern/emu/lite.c
+++ b/grub-core/kern/emu/lite.c
@@ -24,6 +24,8 @@ 
 #elif defined(__aarch64__)
 #include "../arm64/dl_helper.c"
 #include "../arm64/dl.c"
+#elif defined(__riscv)
+#include "../riscv/dl.c"
 #else
 #error "No target cpu type is defined"
 #endif
diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c
index e9441c844..5859f0498 100644
--- a/grub-core/lib/efi/halt.c
+++ b/grub-core/lib/efi/halt.c
@@ -29,7 +29,8 @@  void
 grub_halt (void)
 {
   grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
-#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__)
+#if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \
+    !defined(__riscv)
   grub_acpi_halt ();
 #endif
   efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S
index f6e4905e2..aa297ab0a 100644
--- a/grub-core/lib/setjmp.S
+++ b/grub-core/lib/setjmp.S
@@ -15,6 +15,8 @@ 
 #include "./arm/setjmp.S"
 #elif defined(__aarch64__)
 #include "./arm64/setjmp.S"
+#elif defined(__riscv)
+#include "./riscv/setjmp.S"
 #else
 #error "Unknown target cpu type"
 #endif
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
index dc73649a5..d4f2c125f 100644
--- a/include/grub/compiler-rt.h
+++ b/include/grub/compiler-rt.h
@@ -53,7 +53,8 @@  EXPORT_FUNC (__umoddi3) (grub_uint64_t a, grub_uint64_t b);
 
 #endif
 
-#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || defined (__arm__)
+#if defined (__sparc__) || defined (__powerpc__) || defined (__mips__) || \
+    defined (__arm__) || defined(__riscv)
 unsigned
 EXPORT_FUNC (__ctzdi2) (grub_uint64_t x);
 #define NEED_CTZDI2 1
@@ -165,7 +166,8 @@  grub_uint64_t
 EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b);
 #endif
 
-#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || defined (__arm__)
+#if defined (__powerpc__) || defined(__mips__) || defined(__sparc__) || \
+    defined (__arm__) || defined(__riscv)
 grub_uint32_t
 EXPORT_FUNC(__bswapsi2) (grub_uint32_t u);
 
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index c7c9f0e1d..addcbfa8f 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -1686,7 +1686,8 @@  struct grub_efi_block_io
 typedef struct grub_efi_block_io grub_efi_block_io_t;
 
 #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
-  || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__)
+  || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
+  || defined(__riscv)
 
 #define efi_call_0(func)		func()
 #define efi_call_1(func, a)		func(a)
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
index ec44aef7e..e90e00dc4 100644
--- a/include/grub/efi/efi.h
+++ b/include/grub/efi/efi.h
@@ -90,7 +90,7 @@  extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
 						char **device,
 						char **path);
 
-#if defined(__arm__) || defined(__aarch64__)
+#if defined(__arm__) || defined(__aarch64__) || defined(__riscv)
 void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
 #include <grub/cpu/linux.h>
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index 0dba8b67f..15186e8ea 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -102,6 +102,8 @@  enum grub_install_plat
     GRUB_INSTALL_PLATFORM_X86_64_XEN,
     GRUB_INSTALL_PLATFORM_ARM64_EFI,
     GRUB_INSTALL_PLATFORM_ARM_COREBOOT,
+    GRUB_INSTALL_PLATFORM_RISCV32_EFI,
+    GRUB_INSTALL_PLATFORM_RISCV64_EFI,
     GRUB_INSTALL_PLATFORM_MAX
   };
 
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
index 0a2e24a79..d0cc93725 100644
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -728,6 +728,8 @@  static struct
     [GRUB_INSTALL_PLATFORM_ARM64_EFI] =        { "arm64",   "efi"       },
     [GRUB_INSTALL_PLATFORM_ARM_UBOOT] =        { "arm",     "uboot"     },
     [GRUB_INSTALL_PLATFORM_ARM_COREBOOT] =     { "arm",     "coreboot"  },
+    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] =      { "riscv32", "efi"       },
+    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] =      { "riscv64", "efi"       },
   }; 
 
 char *
diff --git a/util/grub-install.c b/util/grub-install.c
index 78d0138cb..6649b2c14 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -477,6 +477,8 @@  have_bootdev (enum grub_install_plat pl)
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
     case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
@@ -899,6 +901,8 @@  main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
@@ -943,6 +947,8 @@  main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
     case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
     case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
@@ -995,6 +1001,8 @@  main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
       is_efi = 1;
       break;
@@ -1108,6 +1116,12 @@  main (int argc, char *argv[])
 	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
 	      efi_file = "BOOTAA64.EFI";
 	      break;
+	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+	      efi_file = "BOOTRISCV32.EFI";
+	      break;
+	    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+	      efi_file = "BOOTRISCV64.EFI";
+	      break;
 	    default:
 	      grub_util_error ("%s", _("You've found a bug"));
 	      break;
@@ -1135,6 +1149,12 @@  main (int argc, char *argv[])
 	    case GRUB_INSTALL_PLATFORM_ARM64_EFI:
 	      efi_file = "grubaa64.efi";
 	      break;
+	    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+	      efi_file = "grubriscv32.efi";
+	      break;
+	    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
+	      efi_file = "grubriscv64.efi";
+	      break;
 	    default:
 	      efi_file = "grub.efi";
 	      break;
@@ -1437,6 +1457,8 @@  main (int argc, char *argv[])
 		  case GRUB_INSTALL_PLATFORM_X86_64_EFI:
 		  case GRUB_INSTALL_PLATFORM_ARM_EFI:
 		  case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+		  case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+		  case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
 		  case GRUB_INSTALL_PLATFORM_IA64_EFI:
 		    g = grub_util_guess_efi_drive (*curdev);
 		    break;
@@ -1529,6 +1551,8 @@  main (int argc, char *argv[])
     case GRUB_INSTALL_PLATFORM_X86_64_EFI:
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
       core_name = "core.efi";
       snprintf (mkimage_target, sizeof (mkimage_target),
@@ -1631,6 +1655,8 @@  main (int argc, char *argv[])
       break;
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
     case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
     case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
@@ -1865,6 +1891,8 @@  main (int argc, char *argv[])
       /* FALLTHROUGH */
     case GRUB_INSTALL_PLATFORM_ARM_EFI:
     case GRUB_INSTALL_PLATFORM_ARM64_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
+    case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
     case GRUB_INSTALL_PLATFORM_IA64_EFI:
       {
 	char *dst = grub_util_path_concat (2, efidir, efi_file);
diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c
index 82073d5cc..602574d52 100644
--- a/util/grub-mknetdir.c
+++ b/util/grub-mknetdir.c
@@ -107,7 +107,9 @@  static const struct
     [GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" },
     [GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" },
-    [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" }
+    [GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" },
+    [GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" },
+    [GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" },
   };
 
 static void
diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c
index 9545945d8..21e5ce4e4 100644
--- a/util/grub-mkrescue.c
+++ b/util/grub-mkrescue.c
@@ -538,6 +538,8 @@  main (int argc, char *argv[])
 	  || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
+	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
+	  || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]
 	  || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
 	system_area = SYS_AREA_COMMON;
       else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275])
@@ -735,7 +737,9 @@  main (int argc, char *argv[])
       || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
       || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
-      || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI])
+      || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
+      || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
+      || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])
     {
       char *efidir = grub_util_make_temporary_dir ();
       char *efidir_efi = grub_util_path_concat (2, efidir, "efi");
@@ -770,6 +774,16 @@  main (int argc, char *argv[])
 			     imgname);
       free (imgname);
 
+      imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi");
+      make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi",
+			     imgname);
+      free (imgname);
+
+      imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi");
+      make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi",
+			     imgname);
+      free (imgname);
+
       if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
 	{
 	  imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi");
diff --git a/util/mkimage.c b/util/mkimage.c
index e22d82afa..b5368ffd2 100644
--- a/util/mkimage.c
+++ b/util/mkimage.c
@@ -609,6 +609,38 @@  static const struct grub_install_image_target_desc image_targets[] =
       .pe_target = GRUB_PE32_MACHINE_ARM64,
       .elf_target = EM_AARCH64,
     },
+    {
+      .dirname = "riscv32-efi",
+      .names = { "riscv32-efi", NULL },
+      .voidp_sizeof = 4,
+      .bigendian = 0,
+      .id = IMAGE_EFI,
+      .flags = PLATFORM_FLAGS_NONE,
+      .total_module_size = TARGET_NO_FIELD,
+      .decompressor_compressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_addr = TARGET_NO_FIELD,
+      .section_align = GRUB_PE32_SECTION_ALIGNMENT,
+      .vaddr_offset = EFI32_HEADER_SIZE,
+      .pe_target = GRUB_PE32_MACHINE_RISCV32,
+      .elf_target = EM_RISCV,
+    },
+    {
+      .dirname = "riscv64-efi",
+      .names = { "riscv64-efi", NULL },
+      .voidp_sizeof = 8,
+      .bigendian = 0,
+      .id = IMAGE_EFI,
+      .flags = PLATFORM_FLAGS_NONE,
+      .total_module_size = TARGET_NO_FIELD,
+      .decompressor_compressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_size = TARGET_NO_FIELD,
+      .decompressor_uncompressed_addr = TARGET_NO_FIELD,
+      .section_align = GRUB_PE32_SECTION_ALIGNMENT,
+      .vaddr_offset = EFI64_HEADER_SIZE,
+      .pe_target = GRUB_PE32_MACHINE_RISCV64,
+      .elf_target = EM_RISCV,
+    },
   };
 
 #include <grub/lib/LzmaEnc.h>