diff --git a/local/recipes/core/grub/grub.cfg b/local/recipes/core/grub/grub.cfg new file mode 100644 index 00000000..5a547b7b --- /dev/null +++ b/local/recipes/core/grub/grub.cfg @@ -0,0 +1,28 @@ +# Red Bear OS GRUB Configuration +# +# GRUB presents this menu at boot and chainloads the Redox bootloader. +# The Redox bootloader then reads the RedoxFS partition and boots the kernel. +# +# Place this file at EFI/BOOT/grub.cfg on the ESP. +# The install-grub.sh script handles this automatically. +# +# To customize: edit this file before running install-grub.sh, +# or modify the ESP directly with mtools: +# mcopy -i harddrive.img@@1048576 grub.cfg ::EFI/BOOT/grub.cfg + +set default=0 +set timeout=5 + +# Default: boot Red Bear OS via Redox bootloader chainload +menuentry "Red Bear OS" { + chainloader /EFI/REDBEAR/redbear.efi + boot +} + +menuentry "Reboot" { + reboot +} + +menuentry "Shutdown" { + halt +} diff --git a/local/recipes/core/grub/recipe.toml b/local/recipes/core/grub/recipe.toml new file mode 100644 index 00000000..1fca80ad --- /dev/null +++ b/local/recipes/core/grub/recipe.toml @@ -0,0 +1,126 @@ +# 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 +# +# Build: make r.grub +# Install into image: ./local/scripts/install-grub.sh build/x86_64/harddrive.img +# +# Requires: gcc, make, bison, flex, autoconf, automake on host + +[source] +tar = "https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz" + +[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 + +# Out-of-tree build (GRUB requires this for some configurations) +mkdir -p "${COOKBOOK_BUILD}/grub-build" +cd "${COOKBOOK_BUILD}/grub-build" + +# GRUB release tarballs miss extra_deps.lst (normally generated by autogen.sh) +touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst" + +# 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" + +echo "Building GRUB..." +make -j "${COOKBOOK_MAKE_JOBS}" + +# 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 curated 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). +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 \ + part_gpt \ + part_msdos \ + fat \ + ext2 \ + normal \ + configfile \ + search \ + search_fs_uuid \ + search_label \ + chain \ + echo \ + test \ + ls \ + cat \ + halt \ + reboot + +# 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 -f%z "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" 2>/dev/null || 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 "WARNING: grub.cfg not found in ${COOKBOOK_RECIPE}" >&2 +fi + +echo "GRUB recipe complete." +echo "Install with: ./local/scripts/install-grub.sh build/x86_64/harddrive.img" +""" diff --git a/recipes/core/grub b/recipes/core/grub new file mode 120000 index 00000000..ba093047 --- /dev/null +++ b/recipes/core/grub @@ -0,0 +1 @@ +../../local/recipes/core/grub \ No newline at end of file diff --git a/recipes/wip/services/grub/recipe.toml b/recipes/wip/services/grub/recipe.toml deleted file mode 100644 index e314bc84..00000000 --- a/recipes/wip/services/grub/recipe.toml +++ /dev/null @@ -1,5 +0,0 @@ -#TODO compilation error -[source] -tar = "https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz" -[build] -template = "configure" diff --git a/recipes/wip/services/grub/recipe.toml b/recipes/wip/services/grub/recipe.toml new file mode 120000 index 00000000..a7765fc6 --- /dev/null +++ b/recipes/wip/services/grub/recipe.toml @@ -0,0 +1 @@ +../../../../local/recipes/core/grub/recipe.toml \ No newline at end of file