RISC-V: Add to build system
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> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
1edef90cf9
commit
09d8eedbba
22 changed files with 201 additions and 21 deletions
|
@ -285,6 +285,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
|
||||
|
|
|
@ -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)';
|
||||
|
@ -114,6 +120,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;
|
||||
|
@ -248,6 +256,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 = kern/i386/pc/tpm.c;
|
||||
|
@ -320,6 +334,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;
|
||||
|
@ -795,6 +817,8 @@ module = {
|
|||
enable = arm64_efi;
|
||||
enable = arm_uboot;
|
||||
enable = arm_coreboot;
|
||||
enable = riscv32_efi;
|
||||
enable = riscv64_efi;
|
||||
};
|
||||
|
||||
module = {
|
||||
|
@ -1703,6 +1727,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 = {
|
||||
|
@ -1804,6 +1829,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;
|
||||
|
@ -1906,6 +1933,8 @@ module = {
|
|||
enable = ia64_efi;
|
||||
enable = arm_efi;
|
||||
enable = arm64_efi;
|
||||
enable = riscv32_efi;
|
||||
enable = riscv64_efi;
|
||||
enable = mips;
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -571,6 +576,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;
|
||||
|
@ -616,7 +622,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))
|
||||
|
|
|
@ -237,7 +237,8 @@ union component64
|
|||
};
|
||||
};
|
||||
|
||||
#if defined (__powerpc__) || defined (__arm__) || defined(__mips__)
|
||||
#if defined (__powerpc__) || defined (__arm__) || defined(__mips__) || \
|
||||
(defined(__riscv) && (__riscv_xlen == 32))
|
||||
|
||||
/* Based on libgcc2.c from gcc suite. */
|
||||
grub_uint64_t
|
||||
|
@ -343,7 +344,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
|
||||
|
|
|
@ -666,7 +666,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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
#include "../sparc64/cache.S"
|
||||
#elif defined(__powerpc__)
|
||||
#include "../powerpc/cache.S"
|
||||
#elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || defined(__mips__)
|
||||
#elif defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
|
||||
defined(__mips__) || defined(__riscv)
|
||||
#else
|
||||
#error "No target cpu type is defined"
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue