From Fedora Project Wiki
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{lang|en|zh-cn|page=Architectures/RISC-V/GRUB2}}
= GRUB2 for RISC-V =
= GRUB2 for RISC-V =
This page will provide the info about how to build GRUB2 for RISCV64.
This page will provide the info about how to build GRUB2 for RISCV64.
Line 11: Line 13:


<pre>
<pre>
push grub
pushd grub
git remote add github.com_tekkamanninja https://github.com/tekkamanninja/grub.git
git remote add github.com_tekkamanninja https://github.com/tekkamanninja/grub.git
git fetch github.com_tekkamanninja
git fetch github.com_tekkamanninja
git checkout github.com_tekkamanninja/riscv_devel_Nikita_V2
git checkout github.com_tekkamanninja/riscv_devel_Nikita_V3
pop
popd
</pre>
</pre>


== Build ==
== Build ==


=== default config ===
the '''default.cfg''', we will use it later:
<pre>
search -f /grub.cfg -s root
set prefix=($root)
</pre>
The config makes GRUB will set root as a partition with grub.cfg file in '/', and set prefix as ($root)
Then GRUB will auto get config file '''grub.cfg''' in ($root)


=== build ===
<pre>
<pre>
pushd
pushd grub
 
#setup build env
GRUB_INSTALL_DIR=${RISCV_ROOTFS}
 
GRUB_BUILD_CONFIG=--target=riscv64-linux-gnu --with-platform=efi --prefix=${GRUB_INSTALL_DIR}


GRUB_INSTALL_DIR=$(join $(GRUB_INSTALL_DIR), $(STARFIVE_STARLIGHT_SUBFIX))
GRUB_DEFAULT_CFG_RISCV=${GRUB_INFO_DIR}/default.cfg
GRUB_BUILD_CONFIG=--target=riscv64-linux-gnu --with-platform=efi --prefix=${RISCV_ROOTFS}
GRUB_PREBUILD_DIR=$(SDK_PREBUILD_DIR)/Fedora
GRUB_BINARY_NAME_RISCV=grubriscv64.efi
GRUB_BINARY_NAME_RISCV=grubriscv64.efi
GRUB_BINARY_FORMAT_RISCV=riscv64-efi
GRUB_BINARY_FORMAT_RISCV=riscv64-efi
GRUB_PREFIX_DIR_RISCV=efi
GRUB_PREFIX_DIR_RISCV=efi
GRUB_DEFAULT_CFG_RISCV=${GRUB_DIR}/default.cfg
GRUB_UEFI_IMAGE_MODULES_RISCV=acpi adler32 affs afs afsplitter all_video archelp bfs bitmap bitmap_scale blocklist boot bswap_test btrfs bufio cat cbfs chain cmdline_cat_test cmp cmp_test configfile cpio_be cpio crc64 cryptodisk crypto ctz_test datehook date datetime diskfilter disk div div_test dm_nv echo efifwsetup efi_gop efinet elf eval exfat exfctest ext2 extcmd f2fs fat fdt file font fshelp functional_test gcry_arcfour gcry_blowfish gcry_camellia gcry_cast5 gcry_crc gcry_des gcry_dsa gcry_idea gcry_md4 gcry_md5 gcry_rfc2268 gcry_rijndael gcry_rmd160 gcry_rsa gcry_seed gcry_serpent gcry_sha1 gcry_sha256 gcry_sha512 gcry_tiger gcry_twofish gcry_whirlpool geli gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync gzio halt hashsum hello help hexdump hfs hfspluscomp hfsplus http iso9660 jfs jpeg json keystatus ldm linux loadenv loopback lsacpi lsefimmap lsefi lsefisystab lsmmap ls lssal luks2 luks lvm lzopio macbless macho mdraid09_be mdraid09 mdraid1x memdisk memrw minicmd minix2_be minix2 minix3_be minix3 minix_be minix mmap mpi msdospart mul_test net newc nilfs2 normal ntfscomp ntfs odc offsetio part_acorn part_amiga part_apple part_bsd part_dfly part_dvh part_gpt part_msdos part_plan part_sun part_sunpc parttool password password_pbkdf2 pbkdf2 pbkdf2_test pgp png priority_queue probe procfs progress raid5rec raid6rec read reboot regexp reiserfs romfs scsi search_fs_file search_fs_uuid search_label search serial setjmp setjmp_test sfs shift_test signature_test sleep sleep_test smbios squash4 strtoull_test syslinuxcfg tar terminal terminfo test_blockarg testload test testspeed tftp tga time tpm trig tr true udf ufs1_be ufs1 ufs2 video_colors video_fb videoinfo video videotest_checksum videotest xfs xnu_uuid xnu_uuid_test xzio zfscrypt zfsinfo zfs zstd  
GRUB_UEFI_IMAGE_MODULES_RISCV=acpi adler32 affs afs afsplitter all_video archelp bfs bitmap bitmap_scale blocklist boot bswap_test btrfs bufio cat cbfs chain cmdline_cat_test cmp cmp_test configfile cpio_be cpio crc64 cryptodisk crypto ctz_test datehook date datetime diskfilter disk div div_test dm_nv echo efifwsetup efi_gop efinet elf eval exfat exfctest ext2 extcmd f2fs fat fdt file font fshelp functional_test gcry_arcfour gcry_blowfish gcry_camellia gcry_cast5 gcry_crc gcry_des gcry_dsa gcry_idea gcry_md4 gcry_md5 gcry_rfc2268 gcry_rijndael gcry_rmd160 gcry_rsa gcry_seed gcry_serpent gcry_sha1 gcry_sha256 gcry_sha512 gcry_tiger gcry_twofish gcry_whirlpool geli gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync gzio halt hashsum hello help hexdump hfs hfspluscomp hfsplus http iso9660 jfs jpeg json keystatus ldm linux loadenv loopback lsacpi lsefimmap lsefi lsefisystab lsmmap ls lssal luks2 luks lvm lzopio macbless macho mdraid09_be mdraid09 mdraid1x memdisk memrw minicmd minix2_be minix2 minix3_be minix3 minix_be minix mmap mpi msdospart mul_test net newc nilfs2 normal ntfscomp ntfs odc offsetio part_acorn part_amiga part_apple part_bsd part_dfly part_dvh part_gpt part_msdos part_plan part_sun part_sunpc parttool password password_pbkdf2 pbkdf2 pbkdf2_test pgp png priority_queue probe procfs progress raid5rec raid6rec read reboot regexp reiserfs romfs scsi search_fs_file search_fs_uuid search_label search serial setjmp setjmp_test sfs shift_test signature_test sleep sleep_test smbios squash4 strtoull_test syslinuxcfg tar terminal terminfo test_blockarg testload test testspeed tftp tga time tpm trig tr true udf ufs1_be ufs1 ufs2 video_colors video_fb videoinfo video videotest_checksum videotest xfs xnu_uuid xnu_uuid_test xzio zfscrypt zfsinfo zfs zstd  
GRUB_MKIMAGE_ARG_RISCV=-c $(GRUB_DEFAULT_CFG_RISCV) $(GRUB_UEFI_IMAGE_MODULES_RISCV)
GRUB_MKIMAGE_ARG_RISCV=-c $(GRUB_DEFAULT_CFG_RISCV) $(GRUB_UEFI_IMAGE_MODULES_RISCV)


#bootstrap, download gunlib...
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./bootstrap
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./bootstrap
#auto generate the config files
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./autogen.sh
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./autogen.sh
#auto config and generate Makefile
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./configure  ${GRUB_BUILD_CONFIG}
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./configure  ${GRUB_BUILD_CONFIG}
#build and install to ${RISCV_ROOTFS}
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make install
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make install
#make executable efi file
pushd ${GRUB_INSTALL_DIR}
./bin/grub-mkimage -v \
./bin/grub-mkimage -v \
                   -o ${GRUB_BINARY_NAME_RISCV} \
                   -o ${GRUB_BINARY_NAME_RISCV} \
Line 44: Line 64:
                   -p ${GRUB_PREFIX_DIR_RISCV}  \
                   -p ${GRUB_PREFIX_DIR_RISCV}  \
                   ${GRUB_MKIMAGE_ARG_RISCV}
                   ${GRUB_MKIMAGE_ARG_RISCV}
popd
popd
popd
</pre>
</pre>
The you will find a '''grubriscv64.efi''' file in ${RISCV_ROOTFS}, this file can be executed by U-boot or UEFI.

Latest revision as of 18:33, 24 November 2021

GRUB2 for RISC-V

This page will provide the info about how to build GRUB2 for RISCV64.

Source code

Get Upstream code

git clone git://git.savannah.gnu.org/grub.git

Fetch some patches for RISC-V build

pushd grub
git remote add github.com_tekkamanninja https://github.com/tekkamanninja/grub.git
git fetch github.com_tekkamanninja
git checkout github.com_tekkamanninja/riscv_devel_Nikita_V3
popd

Build

default config

the default.cfg, we will use it later:

search -f /grub.cfg -s root
set prefix=($root)

The config makes GRUB will set root as a partition with grub.cfg file in '/', and set prefix as ($root) Then GRUB will auto get config file grub.cfg in ($root)

build

pushd grub

#setup build env
GRUB_INSTALL_DIR=${RISCV_ROOTFS}

GRUB_BUILD_CONFIG=--target=riscv64-linux-gnu --with-platform=efi --prefix=${GRUB_INSTALL_DIR}

GRUB_DEFAULT_CFG_RISCV=${GRUB_INFO_DIR}/default.cfg
GRUB_BINARY_NAME_RISCV=grubriscv64.efi
GRUB_BINARY_FORMAT_RISCV=riscv64-efi
GRUB_PREFIX_DIR_RISCV=efi
GRUB_UEFI_IMAGE_MODULES_RISCV=acpi adler32 affs afs afsplitter all_video archelp bfs bitmap bitmap_scale blocklist boot bswap_test btrfs bufio cat cbfs chain cmdline_cat_test cmp cmp_test configfile cpio_be cpio crc64 cryptodisk crypto ctz_test datehook date datetime diskfilter disk div div_test dm_nv echo efifwsetup efi_gop efinet elf eval exfat exfctest ext2 extcmd f2fs fat fdt file font fshelp functional_test gcry_arcfour gcry_blowfish gcry_camellia gcry_cast5 gcry_crc gcry_des gcry_dsa gcry_idea gcry_md4 gcry_md5 gcry_rfc2268 gcry_rijndael gcry_rmd160 gcry_rsa gcry_seed gcry_serpent gcry_sha1 gcry_sha256 gcry_sha512 gcry_tiger gcry_twofish gcry_whirlpool geli gettext gfxmenu gfxterm_background gfxterm_menu gfxterm gptsync gzio halt hashsum hello help hexdump hfs hfspluscomp hfsplus http iso9660 jfs jpeg json keystatus ldm linux loadenv loopback lsacpi lsefimmap lsefi lsefisystab lsmmap ls lssal luks2 luks lvm lzopio macbless macho mdraid09_be mdraid09 mdraid1x memdisk memrw minicmd minix2_be minix2 minix3_be minix3 minix_be minix mmap mpi msdospart mul_test net newc nilfs2 normal ntfscomp ntfs odc offsetio part_acorn part_amiga part_apple part_bsd part_dfly part_dvh part_gpt part_msdos part_plan part_sun part_sunpc parttool password password_pbkdf2 pbkdf2 pbkdf2_test pgp png priority_queue probe procfs progress raid5rec raid6rec read reboot regexp reiserfs romfs scsi search_fs_file search_fs_uuid search_label search serial setjmp setjmp_test sfs shift_test signature_test sleep sleep_test smbios squash4 strtoull_test syslinuxcfg tar terminal terminfo test_blockarg testload test testspeed tftp tga time tpm trig tr true udf ufs1_be ufs1 ufs2 video_colors video_fb videoinfo video videotest_checksum videotest xfs xnu_uuid xnu_uuid_test xzio zfscrypt zfsinfo zfs zstd 
GRUB_MKIMAGE_ARG_RISCV=-c $(GRUB_DEFAULT_CFG_RISCV) $(GRUB_UEFI_IMAGE_MODULES_RISCV)

#bootstrap, download gunlib...
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./bootstrap
#auto generate the config files
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./autogen.sh
#auto config and generate Makefile
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./configure  ${GRUB_BUILD_CONFIG}
#build and install to ${RISCV_ROOTFS}
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make install

#make executable efi file 
pushd ${GRUB_INSTALL_DIR}
./bin/grub-mkimage -v \
                   -o ${GRUB_BINARY_NAME_RISCV} \
                   -O  ${GRUB_BINARY_FORMAT_RISCV} \
                   -p ${GRUB_PREFIX_DIR_RISCV}  \
                   ${GRUB_MKIMAGE_ARG_RISCV}
popd

popd

The you will find a grubriscv64.efi file in ${RISCV_ROOTFS}, this file can be executed by U-boot or UEFI.