aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
authorSwift Geek <swiftgeek@gmail.com>2017-08-29 18:55:39 +0000
committerGogs <gogitservice@gmail.com>2017-08-29 18:55:39 +0000
commita099162ed39a82bd9778f245c860482aec97cfef (patch)
treecf4e18e56053916ba0efddcad4a6a0e3c78d7995 /projects
parentf9de0975d7f32374bc63eb2b73188c09ace2ed48 (diff)
parent33c337e484d39ae86b0f2752336334a2d84c8c2d (diff)
downloadlibrebootfr-a099162ed39a82bd9778f245c860482aec97cfef.tar.gz
librebootfr-a099162ed39a82bd9778f245c860482aec97cfef.zip
Merge branch 'grub-integration' of kragle/libreboot into master
Diffstat (limited to 'projects')
-rw-r--r--projects/grub/configs/bios/arch1
-rw-r--r--projects/grub/configs/bios/config2
-rw-r--r--projects/grub/configs/bios/format1
-rw-r--r--projects/grub/configs/bios/install202
-rw-r--r--projects/grub/configs/bios/modules-minimal7
-rw-r--r--projects/grub/configs/bios/platform1
-rw-r--r--projects/grub/configs/bios/prefix1
-rw-r--r--projects/grub/configs/bios/size1
-rw-r--r--projects/grub/configs/install2
-rw-r--r--projects/grub/configs/modules-install (renamed from projects/grub/configs/grub-install-modules)0
-rw-r--r--projects/grub/configs/modules-preload (renamed from projects/grub/configs/grub-load-modules)0
-rw-r--r--projects/grub/configs/targets1
-rwxr-xr-xprojects/grub/grub50
-rwxr-xr-xprojects/grub/grub-helper174
14 files changed, 415 insertions, 28 deletions
diff --git a/projects/grub/configs/bios/arch b/projects/grub/configs/bios/arch
new file mode 100644
index 00000000..5a9a476a
--- /dev/null
+++ b/projects/grub/configs/bios/arch
@@ -0,0 +1 @@
+i386
diff --git a/projects/grub/configs/bios/config b/projects/grub/configs/bios/config
new file mode 100644
index 00000000..9e627e2f
--- /dev/null
+++ b/projects/grub/configs/bios/config
@@ -0,0 +1,2 @@
+set root=(cbfsdisk)
+source (cbfsdisk)/fallback/grub.cfg
diff --git a/projects/grub/configs/bios/format b/projects/grub/configs/bios/format
new file mode 100644
index 00000000..58df395e
--- /dev/null
+++ b/projects/grub/configs/bios/format
@@ -0,0 +1 @@
+i386-pc
diff --git a/projects/grub/configs/bios/install b/projects/grub/configs/bios/install
new file mode 100644
index 00000000..241e2762
--- /dev/null
+++ b/projects/grub/configs/bios/install
@@ -0,0 +1,202 @@
+i386-pc/acpi.mod:i386-pc/acpi.mod
+i386-pc/adler32.mod:i386-pc/adler32.mod
+i386-pc/affs.mod:i386-pc/affs.mod
+i386-pc/afs.mod:i386-pc/afs.mod
+i386-pc/ahci.mod:i386-pc/ahci.mod
+i386-pc/all_video.mod:i386-pc/all_video.mod
+i386-pc/archelp.mod:i386-pc/archelp.mod
+i386-pc/ata.mod:i386-pc/ata.mod
+i386-pc/at_keyboard.mod:i386-pc/at_keyboard.mod
+i386-pc/backtrace.mod:i386-pc/backtrace.mod
+i386-pc/bfs.mod:i386-pc/bfs.mod
+i386-pc/biosdisk.mod:i386-pc/biosdisk.mod
+i386-pc/bitmap.mod:i386-pc/bitmap.mod
+i386-pc/bitmap_scale.mod:i386-pc/bitmap_scale.mod
+i386-pc/boot.mod:i386-pc/boot.mod
+i386-pc/bsd.mod:i386-pc/bsd.mod
+i386-pc/btrfs.mod:i386-pc/btrfs.mod
+i386-pc/cat.mod:i386-pc/cat.mod
+i386-pc/cbfs.mod:i386-pc/cbfs.mod
+i386-pc/cbls.mod:i386-pc/cbls.mod
+i386-pc/cbmemc.mod:i386-pc/cbmemc.mod
+i386-pc/cbtime.mod:i386-pc/cbtime.mod
+i386-pc/chain.mod:i386-pc/chain.mod
+i386-pc/cmosdump.mod:i386-pc/cmosdump.mod
+i386-pc/cmostest.mod:i386-pc/cmostest.mod
+i386-pc/cmp.mod:i386-pc/cmp.mod
+i386-pc/configfile.mod:i386-pc/configfile.mod
+i386-pc/cpio.mod:i386-pc/cpio.mod
+i386-pc/cpio_be.mod:i386-pc/cpio_be.mod
+i386-pc/cpuid.mod:i386-pc/cpuid.mod
+i386-pc/crc64.mod:i386-pc/crc64.mod
+i386-pc/crypto.mod:i386-pc/crypto.mod
+i386-pc/cryptodisk.mod:i386-pc/cryptodisk.mod
+i386-pc/cs5536.mod:i386-pc/cs5536.mod
+i386-pc/date.mod:i386-pc/date.mod
+i386-pc/datehook.mod:i386-pc/datehook.mod
+i386-pc/datetime.mod:i386-pc/datetime.mod
+i386-pc/disk.mod:i386-pc/disk.mod
+i386-pc/diskfilter.mod:i386-pc/diskfilter.mod
+i386-pc/div_test.mod:i386-pc/div_test.mod
+i386-pc/echo.mod:i386-pc/echo.mod
+i386-pc/efiemu.mod:i386-pc/efiemu.mod
+i386-pc/ehci.mod:i386-pc/ehci.mod
+i386-pc/elf.mod:i386-pc/elf.mod
+i386-pc/eval.mod:i386-pc/eval.mod
+i386-pc/exfat.mod:i386-pc/exfat.mod
+i386-pc/ext2.mod:i386-pc/ext2.mod
+i386-pc/extcmd.mod:i386-pc/extcmd.mod
+i386-pc/fat.mod:i386-pc/fat.mod
+i386-pc/file.mod:i386-pc/file.mod
+i386-pc/fshelp.mod:i386-pc/fshelp.mod
+i386-pc/gcry_arcfour.mod:i386-pc/gcry_arcfour.mod
+i386-pc/gcry_blowfish.mod:i386-pc/gcry_blowfish.mod
+i386-pc/gcry_camellia.mod:i386-pc/gcry_camellia.mod
+i386-pc/gcry_cast5.mod:i386-pc/gcry_cast5.mod
+i386-pc/gcry_crc.mod:i386-pc/gcry_crc.mod
+i386-pc/gcry_des.mod:i386-pc/gcry_des.mod
+i386-pc/gcry_dsa.mod:i386-pc/gcry_dsa.mod
+i386-pc/gcry_idea.mod:i386-pc/gcry_idea.mod
+i386-pc/gcry_md4.mod:i386-pc/gcry_md4.mod
+i386-pc/gcry_md5.mod:i386-pc/gcry_md5.mod
+i386-pc/gcry_rfc2268.mod:i386-pc/gcry_rfc2268.mod
+i386-pc/gcry_rijndael.mod:i386-pc/gcry_rijndael.mod
+i386-pc/gcry_rmd160.mod:i386-pc/gcry_rmd160.mod
+i386-pc/gcry_rsa.mod:i386-pc/gcry_rsa.mod
+i386-pc/gcry_seed.mod:i386-pc/gcry_seed.mod
+i386-pc/gcry_serpent.mod:i386-pc/gcry_serpent.mod
+i386-pc/gcry_sha1.mod:i386-pc/gcry_sha1.mod
+i386-pc/gcry_sha256.mod:i386-pc/gcry_sha256.mod
+i386-pc/gcry_sha512.mod:i386-pc/gcry_sha512.mod
+i386-pc/gcry_tiger.mod:i386-pc/gcry_tiger.mod
+i386-pc/gcry_twofish.mod:i386-pc/gcry_twofish.mod
+i386-pc/gcry_whirlpool.mod:i386-pc/gcry_whirlpool.mod
+i386-pc/gettext.mod:i386-pc/gettext.mod
+i386-pc/gfxmenu.mod:i386-pc/gfxmenu.mod
+i386-pc/gfxterm_background.mod:i386-pc/gfxterm_background.mod
+i386-pc/gfxterm_menu.mod:i386-pc/gfxterm_menu.mod
+i386-pc/gptsync.mod:i386-pc/gptsync.mod
+i386-pc/gzio.mod:i386-pc/gzio.mod
+i386-pc/halt.mod:i386-pc/halt.mod
+i386-pc/hashsum.mod:i386-pc/hashsum.mod
+i386-pc/hdparm.mod:i386-pc/hdparm.mod
+i386-pc/help.mod:i386-pc/help.mod
+i386-pc/hexdump.mod:i386-pc/hexdump.mod
+i386-pc/hfs.mod:i386-pc/hfs.mod
+i386-pc/hfsplus.mod:i386-pc/hfsplus.mod
+i386-pc/http.mod:i386-pc/http.mod
+i386-pc/iorw.mod:i386-pc/iorw.mod
+i386-pc/iso9660.mod:i386-pc/iso9660.mod
+i386-pc/jfs.mod:i386-pc/jfs.mod
+i386-pc/jpeg.mod:i386-pc/jpeg.mod
+i386-pc/keystatus.mod:i386-pc/keystatus.mod
+i386-pc/linux.mod:i386-pc/linux.mod
+i386-pc/linux16.mod:i386-pc/linux16.mod
+i386-pc/loadenv.mod:i386-pc/loadenv.mod
+i386-pc/loopback.mod:i386-pc/loopback.mod
+i386-pc/ls.mod:i386-pc/ls.mod
+i386-pc/lsacpi.mod:i386-pc/lsacpi.mod
+i386-pc/lsmmap.mod:i386-pc/lsmmap.mod
+i386-pc/lspci.mod:i386-pc/lspci.mod
+i386-pc/luks.mod:i386-pc/luks.mod
+i386-pc/lvm.mod:i386-pc/lvm.mod
+i386-pc/lzopio.mod:i386-pc/lzopio.mod
+i386-pc/mda_text.mod:i386-pc/mda_text.mod
+i386-pc/mdraid09.mod:i386-pc/mdraid09.mod
+i386-pc/mdraid09_be.mod:i386-pc/mdraid09_be.mod
+i386-pc/mdraid1x.mod:i386-pc/mdraid1x.mod
+i386-pc/memdisk.mod:i386-pc/memdisk.mod
+i386-pc/memrw.mod:i386-pc/memrw.mod
+i386-pc/minicmd.mod:i386-pc/minicmd.mod
+i386-pc/minix.mod:i386-pc/minix.mod
+i386-pc/minix2.mod:i386-pc/minix2.mod
+i386-pc/minix2_be.mod:i386-pc/minix2_be.mod
+i386-pc/minix3.mod:i386-pc/minix3.mod
+i386-pc/minix3_be.mod:i386-pc/minix3_be.mod
+i386-pc/minix_be.mod:i386-pc/minix_be.mod
+i386-pc/mmap.mod:i386-pc/mmap.mod
+i386-pc/morse.mod:i386-pc/morse.mod
+i386-pc/mpi.mod:i386-pc/mpi.mod
+i386-pc/msdospart.mod:i386-pc/msdospart.mod
+i386-pc/multiboot.mod:i386-pc/multiboot.mod
+i386-pc/multiboot2.mod:i386-pc/multiboot2.mod
+i386-pc/nativedisk.mod:i386-pc/nativedisk.mod
+i386-pc/net.mod:i386-pc/net.mod
+i386-pc/newc.mod:i386-pc/newc.mod
+i386-pc/nilfs2.mod:i386-pc/nilfs2.mod
+i386-pc/normal.mod:i386-pc/normal.mod
+i386-pc/ntfs.mod:i386-pc/ntfs.mod
+i386-pc/ntfscomp.mod:i386-pc/ntfscomp.mod
+i386-pc/odc.mod:i386-pc/odc.mod
+i386-pc/offsetio.mod:i386-pc/offsetio.mod
+i386-pc/ohci.mod:i386-pc/ohci.mod
+i386-pc/part_bsd.mod:i386-pc/part_bsd.mod
+i386-pc/part_gpt.mod:i386-pc/part_gpt.mod
+i386-pc/part_msdos.mod:i386-pc/part_msdos.mod
+i386-pc/parttool.mod:i386-pc/parttool.mod
+i386-pc/password.mod:i386-pc/password.mod
+i386-pc/password_pbkdf2.mod:i386-pc/password_pbkdf2.mod
+i386-pc/pata.mod:i386-pc/pata.mod
+i386-pc/pbkdf2.mod:i386-pc/pbkdf2.mod
+i386-pc/pci.mod:i386-pc/pci.mod
+i386-pc/pcidump.mod:i386-pc/pcidump.mod
+i386-pc/play.mod:i386-pc/play.mod
+i386-pc/png.mod:i386-pc/png.mod
+i386-pc/priority_queue.mod:i386-pc/priority_queue.mod
+i386-pc/probe.mod:i386-pc/probe.mod
+i386-pc/procfs.mod:i386-pc/procfs.mod
+i386-pc/progress.mod:i386-pc/progress.mod
+i386-pc/raid5rec.mod:i386-pc/raid5rec.mod
+i386-pc/raid6rec.mod:i386-pc/raid6rec.mod
+i386-pc/read.mod:i386-pc/read.mod
+i386-pc/reboot.mod:i386-pc/reboot.mod
+i386-pc/regexp.mod:i386-pc/regexp.mod
+i386-pc/reiserfs.mod:i386-pc/reiserfs.mod
+i386-pc/relocator.mod:i386-pc/relocator.mod
+i386-pc/romfs.mod:i386-pc/romfs.mod
+i386-pc/scsi.mod:i386-pc/scsi.mod
+i386-pc/search.mod:i386-pc/search.mod
+i386-pc/search_fs_file.mod:i386-pc/search_fs_file.mod
+i386-pc/search_fs_uuid.mod:i386-pc/search_fs_uuid.mod
+i386-pc/search_label.mod:i386-pc/search_label.mod
+i386-pc/serial.mod:i386-pc/serial.mod
+i386-pc/setjmp.mod:i386-pc/setjmp.mod
+i386-pc/setpci.mod:i386-pc/setpci.mod
+i386-pc/sfs.mod:i386-pc/sfs.mod
+i386-pc/sleep.mod:i386-pc/sleep.mod
+i386-pc/spkmodem.mod:i386-pc/spkmodem.mod
+i386-pc/squash4.mod:i386-pc/squash4.mod
+i386-pc/syslinuxcfg.mod:i386-pc/syslinuxcfg.mod
+i386-pc/tar.mod:i386-pc/tar.mod
+i386-pc/terminal.mod:i386-pc/terminal.mod
+i386-pc/terminfo.mod:i386-pc/terminfo.mod
+i386-pc/test.mod:i386-pc/test.mod
+i386-pc/testload.mod:i386-pc/testload.mod
+i386-pc/testspeed.mod:i386-pc/testspeed.mod
+i386-pc/tftp.mod:i386-pc/tftp.mod
+i386-pc/tga.mod:i386-pc/tga.mod
+i386-pc/time.mod:i386-pc/time.mod
+i386-pc/tr.mod:i386-pc/tr.mod
+i386-pc/trig.mod:i386-pc/trig.mod
+i386-pc/true.mod:i386-pc/true.mod
+i386-pc/udf.mod:i386-pc/udf.mod
+i386-pc/ufs1.mod:i386-pc/ufs1.mod
+i386-pc/ufs1_be.mod:i386-pc/ufs1_be.mod
+i386-pc/ufs2.mod:i386-pc/ufs2.mod
+i386-pc/uhci.mod:i386-pc/uhci.mod
+i386-pc/usb.mod:i386-pc/usb.mod
+i386-pc/usb_keyboard.mod:i386-pc/usb_keyboard.mod
+i386-pc/usbms.mod:i386-pc/usbms.mod
+i386-pc/usbserial_common.mod:i386-pc/usbserial_common.mod
+i386-pc/usbserial_ftdi.mod:i386-pc/usbserial_ftdi.mod
+i386-pc/usbserial_pl2303.mod:i386-pc/usbserial_pl2303.mod
+i386-pc/usbserial_usbdebug.mod:i386-pc/usbserial_usbdebug.mod
+i386-pc/usbtest.mod:i386-pc/usbtest.mod
+i386-pc/verify.mod:i386-pc/verify.mod
+i386-pc/video_colors.mod:i386-pc/video_colors.mod
+i386-pc/videoinfo.mod:i386-pc/videoinfo.mod
+i386-pc/videotest.mod:i386-pc/videotest.mod
+i386-pc/videotest_checksum.mod:i386-pc/videotest_checksum.mod
+i386-pc/xfs.mod:i386-pc/xfs.mod
+i386-pc/xzio.mod:i386-pc/xzio.mod
+i386-pc/zfs.mod:i386-pc/zfs.mod
diff --git a/projects/grub/configs/bios/modules-minimal b/projects/grub/configs/bios/modules-minimal
new file mode 100644
index 00000000..abd265c0
--- /dev/null
+++ b/projects/grub/configs/bios/modules-minimal
@@ -0,0 +1,7 @@
+biosdisk
+ext2
+halt
+part_bsd
+part_gpt
+reboot
+verify
diff --git a/projects/grub/configs/bios/platform b/projects/grub/configs/bios/platform
new file mode 100644
index 00000000..581a7690
--- /dev/null
+++ b/projects/grub/configs/bios/platform
@@ -0,0 +1 @@
+pc
diff --git a/projects/grub/configs/bios/prefix b/projects/grub/configs/bios/prefix
new file mode 100644
index 00000000..48604ad8
--- /dev/null
+++ b/projects/grub/configs/bios/prefix
@@ -0,0 +1 @@
+(cbfsdisk)/fallback
diff --git a/projects/grub/configs/bios/size b/projects/grub/configs/bios/size
new file mode 100644
index 00000000..a7625603
--- /dev/null
+++ b/projects/grub/configs/bios/size
@@ -0,0 +1 @@
+160
diff --git a/projects/grub/configs/install b/projects/grub/configs/install
index dead10fa..b167d022 100644
--- a/projects/grub/configs/install
+++ b/projects/grub/configs/install
@@ -1 +1 @@
-grub.elf:grub.elf
+grub2:grub2
diff --git a/projects/grub/configs/grub-install-modules b/projects/grub/configs/modules-install
index 1d0d78ba..1d0d78ba 100644
--- a/projects/grub/configs/grub-install-modules
+++ b/projects/grub/configs/modules-install
diff --git a/projects/grub/configs/grub-load-modules b/projects/grub/configs/modules-preload
index bbbac61f..bbbac61f 100644
--- a/projects/grub/configs/grub-load-modules
+++ b/projects/grub/configs/modules-preload
diff --git a/projects/grub/configs/targets b/projects/grub/configs/targets
new file mode 100644
index 00000000..b033e320
--- /dev/null
+++ b/projects/grub/configs/targets
@@ -0,0 +1 @@
+bios
diff --git a/projects/grub/grub b/projects/grub/grub
index 4a7ba1ec..e77deb6d 100755
--- a/projects/grub/grub
+++ b/projects/grub/grub
@@ -57,6 +57,7 @@ update_check() {
}
build() {
+ local target="$1"
local repository="${project}"
project_sources_directory_missing_empty_error "${project}" "${repository}" "$@"
@@ -68,37 +69,32 @@ build() {
local project_path="$(project_path "${project}")"
local sources_path="$(project_sources_path "${project}" "${repository}" "$@")"
local build_path="$(project_build_path "${project}" "$@")"
-
- mapfile -t grub_install_modules < "${project_path}/${CONFIGS}/grub-install-modules"
- mapfile -t grub_load_modules < "${project_path}/${CONFIGS}/grub-load-modules"
+ local rawmap_path="${project_path}/${CONFIGS}/${target}/original"
mkdir -p "${build_path}"
+ grub_build_utils
+
+ case "${target}" in
+ bios)
+ grub_build_floppy_image
+ grub_copy_modules
+ ;;
+ keymap)
+ for rawmap in "${rawmap_path}"/*; do
+ grub_build_layout "${rawmap}"
+ done
+ ;;
+ *)
+ grub_build_standalone_image
+ grub_copy_modules
+ ;;
+ esac
+
+ # Temporary until the function project_make_distclean is written
(
- cd "${sources_path}"
-
- # Compile GRUB first
- ./autogen.sh
- ./configure --with-platform=coreboot
- make -j"${TASKS}"
-
- # Now compile GRUB ELF executable
- ./grub-mkstandalone \
- --grub-mkimage=./grub-mkimage \
- --fonts='' \
- --themes='' \
- --locales='' \
- --modules="${grub_load_modules[*]}" \
- --install-modules="${grub_install_modules[*]}" \
- --directory=grub-core \
- -O i386-coreboot \
- -o grub.elf \
- /boot/grub/grub.cfg="${project_path}/${CONFIGS}/grub.cfg"
-
- # Copy the ELF to its build directory
- cp grub.elf "${build_path}"
-
- # Tidy up
+ cd "${sources_path}" || return
+
make distclean
)
}
diff --git a/projects/grub/grub-helper b/projects/grub/grub-helper
new file mode 100755
index 00000000..342b03eb
--- /dev/null
+++ b/projects/grub/grub-helper
@@ -0,0 +1,174 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2017 Andrew Robbins <contact@andrewrobbins.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ARCH='arch'
+CONFIG='config'
+FORMAT='format'
+MODMIN='modules-minimal'
+PLATFORM='platform'
+PREFIX='prefix'
+SIZE='size'
+
+grub_arch() {
+ project_file_contents "${project}" "${CONFIGS}" "${ARCH}" "$@"
+}
+
+grub_format() {
+ project_file_contents "${project}" "${CONFIGS}" "${FORMAT}" "$@"
+}
+
+grub_platform() {
+ project_file_contents "${project}" "${CONFIGS}" "${PLATFORM}" "$@"
+}
+
+grub_prefix() {
+ project_file_contents "${project}" "${CONFIGS}" "${PREFIX}" "$@"
+}
+
+grub_size() {
+ project_file_contents "${project}" "${CONFIGS}" "${SIZE}" "$@"
+}
+
+grub_config_path() {
+ project_file_path "${project}" "${CONFIGS}" "${CONFIG}" "$@"
+}
+
+grub_modmin_path() {
+ project_file_path "${project}" "${CONFIGS}" "${MODMIN}" "$@"
+}
+
+grub_copy_modules() {
+ local grub_module_dir="${sources_path}/grub-core"
+ local keep_dir="${build_path}/$(grub_format "${target}" "$@")"
+
+ mkdir -p "${keep_dir}"
+
+ cp -a "${grub_module_dir}"/*.@(mod|lst) "${keep_dir}"
+}
+
+grub_build_utils() {
+ (
+ # If arch and/or platform files don't exist,
+ # the configure script will pick a reasonable default
+ local arch="$(grub_arch "${target}" "$@")"
+ local platform="$(grub_platform "${target}" "$@")"
+
+ cd "${sources_path}" || return
+
+ if git_project_check "${repository}"; then
+ ./autogen.sh
+ fi
+
+ ./configure --target="${arch}" --with-platform="${platform}"
+
+ make -j"${TASKS}"
+ )
+}
+
+grub_build_layout() {
+ local raw_layout="${1##*/}"
+ local raw_layout_path="$1"
+ local grub_kbdcomp="${sources_path}/grub-kbdcomp"
+ local grub_kbd_layout="${build_path}/${raw_layout}.gkb"
+
+ "${grub_kbdcomp}" --output="${grub_kbd_layout}" "${raw_layout_path}"
+}
+
+grub_build_bootable_image() {
+ local arch="$(grub_arch "${target}" "$@")"
+ local format="$(grub_format "${target}" "$@")"
+ local prefix="$(grub_prefix "${target}" "$@")"
+ local config_path="$(grub_config_path "${target}" "$@")"
+
+ local grub_mkimage="${sources_path}/grub-mkimage"
+ local grub_module_dir="${sources_path}/grub-core"
+
+ local grubimg="${build_path}/grub.img"
+ local grub_bootimg="${grub_module_dir}/boot.img"
+ local grub_bootable_img="${build_path}/grub2"
+
+ "${grub_mkimage}" \
+ --config="${config_path}" \
+ --directory="${grub_module_dir}" \
+ --output="${grubimg}" \
+ --format="${format}" \
+ --prefix="${prefix}" \
+ cbfs configfile
+
+ cat "${grub_bootimg}" "${grubimg}" > "${grub_bootable_img}"
+ rm -f "${grubimg}"
+}
+
+grub_build_floppy_image() {
+ local grubimg="${build_path}/grub2"
+ local tempfile="${build_path}/temp.file"
+
+ if ! ( grub_build_bootable_image "$@" ); then
+ printf '\n%s\n\n' "Error: Failed to build a GRUB image" 1>&2
+ return 1
+ fi
+
+ local size="$(grub_size "${target}" "$@")"
+
+ # Pre-allocate a floppy-sized image
+ # SeaBIOS requires floppy images to have a "correct" size
+ if ! [[ -e "${tempfile}" ]]; then
+ dd if=/dev/zero of="${tempfile}" bs=1024 count="${size:-160}"
+ else
+ printf '\n%s\n\n' "Error: File ${tempfile} already exists!" 1>&2
+ return 1
+ fi
+
+ local -i grubimg_size="$(stat -c %s "${grubimg}")"
+ local -i floppy_size="$((${size:-160} * 1024))"
+
+ # Graft the GRUB image onto the blank floppy image
+ if ((grubimg_size <= floppy_size)); then
+ dd if="${grubimg}" of="${tempfile}" bs=1 conv=notrunc
+
+ rm -f "${grubimg}"
+ mv "${tempfile}" "${grubimg}"
+ else
+ printf '\n%s' "Error: Image ${grubimg##*/} is too large; " 1>&2
+ printf '%s\n\n' "it must be less than ${size}KiB in size." 1>&2
+ return 1
+ fi
+}
+
+grub_build_standalone_image() {
+ local arch="$(grub_arch "${target}" "$@")"
+ local format="$(grub_format "${target}" "$@")"
+ local prefix="$(grub_prefix "${target}" "$@")"
+ local config_path="$(grub_config_path "${target}" "$@")"
+
+ local grubimg="${build_path}/grub2"
+
+ local grub_mkimage="${sources_path}/grub-mkimage"
+ local grub_mkstandalone="${sources_path}/grub-mkstandalone"
+ local grub_module_dir="${sources_path}/grub-core"
+
+ "${grub_mkstandalone}" \
+ --grub-mkimage="${grub_mkimage}" \
+ --fonts='' \
+ --themes='' \
+ --locales='' \
+ --install-modules='cbfs configfile' \
+ --directory="${grub_module_dir}" \
+ --format="${format}" \
+ --output="${grubimg}" \
+ /boot/grub/grub.cfg="${config_path}"
+}