Files
RedBear-OS/local/recipes/core/grub/recipe.toml
T
2026-04-21 16:15:16 +01:00

187 lines
5.7 KiB
TOML

# Red Bear OS — GRUB Boot Manager
#
# Builds GRUB for the HOST machine (not the Redox target).
# GRUB is a build tool that produces standalone EFI binaries.
# The resulting grub.efi chainloads the Redox bootloader.
#
# Output: /usr/lib/boot/grub.efi, /usr/lib/boot/grub.cfg
# Required local module: local/recipes/core/grub/modules/redoxfs.mod
#
# Build: make r.grub
# Install into image (Phase 1): ./local/scripts/install-grub.sh build/x86_64/harddrive.img
# Install into image (Phase 2): make all CONFIG_NAME=redbear-full-grub
#
# Requires: gcc, make, bison, flex, autoconf, automake on host
[source]
tar = "https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz"
blake3 = "13c48453f9becf4a6e49618749dc7cb83a2c4a0d7600eeeadc6c7c2772c0b877"
[build]
template = "custom"
script = """
# GRUB must be built for the HOST machine, not the Redox target.
# It is a build tool that produces EFI binaries for bare-metal boot.
# Override cookbook cross-compilation environment.
# Force HOST compiler — cookbook sets CC to Redox cross-compiler.
# GRUB is a host build tool, not a Redox binary.
unset CC CXX CPP LD AR NM RANLIB OBJCOPY STRIP PKG_CONFIG
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
# Verify host tools are available before starting the build.
for tool in gcc make bison flex; do
if ! command -v "${tool}" &>/dev/null; then
echo "ERROR: Required host tool '${tool}' not found" >&2
exit 1
fi
done
# Out-of-tree build (GRUB requires this for some configurations)
mkdir -p "${COOKBOOK_BUILD}/grub-build" || exit 1
cd "${COOKBOOK_BUILD}/grub-build" || exit 1
# GRUB release tarballs miss extra_deps.lst (normally generated by autogen.sh)
touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst" || exit 1
# Configure for host, targeting x86_64 EFI platform output.
# --target=x86_64 means "produce boot images for x86_64"
# --with-platform=efi means "EFI platform output"
# We intentionally do NOT set --host (it should be the build machine).
echo "Configuring GRUB for x86_64 EFI..."
"${COOKBOOK_SOURCE}/configure" \
--target=x86_64 \
--with-platform=efi \
--disable-werror \
--disable-nls \
--disable-grub-mkfont \
--disable-grub-themes \
--disable-grub-mount \
--disable-device-mapper \
--disable-libzfs \
--prefix="${COOKBOOK_STAGE}/usr" || exit 1
echo "Building GRUB..."
make -j "${COOKBOOK_MAKE_JOBS}" || exit 1
# Create output directory
mkdir -p "${COOKBOOK_STAGE}/usr/lib/boot"
# Locate GRUB modules directory.
# In an out-of-tree build, modules are in grub-core/ under the build dir.
MOD_DIR=""
for d in grub-core .; do
if [ -f "${d}/part_gpt.mod" ]; then
MOD_DIR="${d}"
break
fi
done
if [ -z "${MOD_DIR}" ]; then
echo "ERROR: Cannot find GRUB modules directory" >&2
echo "Looked in: grub-core/ ." >&2
find . -name "part_gpt.mod" 2>/dev/null || true
exit 1
fi
echo "Found GRUB modules in: ${MOD_DIR}"
# Build standalone EFI image with a broad module set.
# -O x86_64-efi: output format
# -d MOD_DIR: module search directory
# -p /EFI/BOOT: prefix for GRUB config search path
# The resulting image is self-contained (no external module files needed).
has_mod() {
local name="$1"
[ -f "${MOD_DIR}/${name}.mod" ]
}
add_mod() {
local name="$1"
if has_mod "${name}"; then
SELECTED_MODULES+=("${name}")
else
echo "WARN: GRUB module not found, skipping: ${name}" >&2
fi
}
# Keep this list broad for first-class multi-filesystem support.
# Missing modules are skipped with a warning so builds stay resilient.
SELECTED_MODULES=()
for m in \
part_gpt part_msdos \
normal configfile search search_fs_uuid search_label \
echo test ls cat halt reboot chain \
fat ext2 btrfs xfs jfs reiserfs udf iso9660 ntfs ntfscomp hfs hfsplus zfs \
gzio xzio lzopio lzma; do
add_mod "${m}"
done
# RedoxFS module is mandatory for Red Bear GRUB first-class support.
# Prefer local tree artifact, then fall back to staged sysroot copy.
REDOXFS_MOD_CANDIDATES=(
"${COOKBOOK_RECIPE}/modules/redoxfs.mod"
"${COOKBOOK_SYSROOT}/usr/lib/grub/x86_64-efi/redoxfs.mod"
)
REDOXFS_MOD=""
for cand in "${REDOXFS_MOD_CANDIDATES[@]}"; do
if [ -f "${cand}" ]; then
REDOXFS_MOD="${cand}"
break
fi
done
if [ -z "${REDOXFS_MOD}" ]; then
echo "ERROR: redoxfs.mod not found." >&2
echo "Expected one of:" >&2
for cand in "${REDOXFS_MOD_CANDIDATES[@]}"; do
echo " - ${cand}" >&2
done
exit 1
fi
cp "${REDOXFS_MOD}" "${MOD_DIR}/redoxfs.mod"
echo "Using mandatory RedoxFS GRUB module: ${REDOXFS_MOD}"
if ! printf '%s\n' "${SELECTED_MODULES[@]}" | grep -qx "redoxfs"; then
SELECTED_MODULES+=("redoxfs")
fi
if [ "${#SELECTED_MODULES[@]}" -eq 0 ]; then
echo "ERROR: No GRUB modules selected for grub-mkimage" >&2
exit 1
fi
echo "Creating standalone GRUB EFI image..."
./grub-mkimage \
-O x86_64-efi \
-d "${MOD_DIR}" \
-o "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" \
-p /EFI/BOOT \
"${SELECTED_MODULES[@]}" || exit 1
# Verify output
if [ ! -f "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" ]; then
echo "ERROR: grub.efi was not created" >&2
exit 1
fi
GRUB_SIZE=$(stat -c%s "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" 2>/dev/null || echo "unknown")
echo "GRUB EFI image size: ${GRUB_SIZE} bytes"
# Copy default GRUB configuration from recipe directory.
# grub.cfg lives alongside recipe.toml, not in the extracted source tarball.
if [ -f "${COOKBOOK_RECIPE}/grub.cfg" ]; then
cp "${COOKBOOK_RECIPE}/grub.cfg" "${COOKBOOK_STAGE}/usr/lib/boot/grub.cfg"
echo "Installed grub.cfg"
else
echo "ERROR: grub.cfg not found in ${COOKBOOK_RECIPE}" >&2
echo "The grub.cfg file must exist alongside recipe.toml." >&2
exit 1
fi
echo "GRUB recipe complete."
echo "Install with: ./local/scripts/install-grub.sh build/x86_64/harddrive.img"
"""