From ac0289ba9269f9acc776b0ba7b4ad38134dfcedc Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 29 Dec 2009 11:24:13 +0100 Subject: [PATCH 1/4] grub-mkrescue for EFI (untested) --- conf/common.rmk | 6 ++++++ conf/i386-coreboot.rmk | 7 +------ conf/i386-efi.rmk | 3 +++ conf/i386-ieee1275.rmk | 7 +------ conf/i386-pc.rmk | 7 +------ conf/powerpc-ieee1275.rmk | 6 ------ conf/sparc64-ieee1275.rmk | 6 ------ conf/x86_64-efi.rmk | 3 +++ util/grub-mkrescue.in | 35 ++++++++++++++++++++++++++++++++--- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/conf/common.rmk b/conf/common.rmk index 896705526..a961e502a 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -632,3 +632,9 @@ pkglib_MODULES += setjmp.mod setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS) setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For memdisk.mod. +pkglib_MODULES += memdisk.mod +memdisk_mod_SOURCES = disk/memdisk.c +memdisk_mod_CFLAGS = $(COMMON_CFLAGS) +memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index ccc326f5c..439e462c5 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -102,7 +102,7 @@ grub_mkrescue_SOURCES = util/grub-mkrescue.in # Modules. pkglib_MODULES = linux.mod multiboot.mod \ aout.mod play.mod serial.mod \ - memdisk.mod pci.mod lspci.mod reboot.mod \ + pci.mod lspci.mod reboot.mod \ halt.mod datetime.mod date.mod datehook.mod \ lsmmap.mod mmap.mod @@ -165,11 +165,6 @@ play_mod_SOURCES = commands/i386/pc/play.c play_mod_CFLAGS = $(COMMON_CFLAGS) play_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For pci.mod pci_mod_SOURCES = bus/pci.c pci_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index c135ded4e..e55d7c95a 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -15,6 +15,9 @@ grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ util/misc.c util/resolve.c util/i386/efi/grub-mkimage.c_DEPENDENCIES = Makefile +bin_SCRIPTS += grub-mkrescue +grub_mkrescue_SOURCES = util/grub-mkrescue.in + # For grub-setup. #grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ # util/misc.c util/getroot.c kern/device.c kern/disk.c \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 8d9577844..78a100c1a 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -56,7 +56,7 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = halt.mod reboot.mod suspend.mod \ aout.mod serial.mod linux.mod \ - nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + nand.mod pci.mod lspci.mod datetime.mod \ date.mod datehook.mod lsmmap.mod mmap.mod # For boot.mod. @@ -106,11 +106,6 @@ nand_mod_SOURCES = disk/ieee1275/nand.c nand_mod_CFLAGS = $(COMMON_CFLAGS) nand_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For pci.mod pci_mod_SOURCES = bus/pci.c pci_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 7e54b3b67..b682aad94 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -121,7 +121,7 @@ grub_mkfloppy_SOURCES = util/i386/pc/grub-mkfloppy.in pkglib_MODULES = biosdisk.mod chain.mod \ multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \ - vga.mod memdisk.mod pci.mod lspci.mod \ + vga.mod pci.mod lspci.mod \ aout.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \ @@ -239,11 +239,6 @@ vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_CFLAGS = $(COMMON_CFLAGS) vga_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For pci.mod pci_mod_SOURCES = bus/pci.c pci_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 85b1fa211..0b5b03c5d 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -62,7 +62,6 @@ pkglib_MODULES = halt.mod \ reboot.mod \ suspend.mod \ multiboot.mod \ - memdisk.mod \ lsmmap.mod # For boot.mod. @@ -98,11 +97,6 @@ multiboot_mod_SOURCES = loader/ieee1275/multiboot2.c \ multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For lsmmap.mod lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/sparc64-ieee1275.rmk b/conf/sparc64-ieee1275.rmk index 8c8bf27e6..dc845e1a5 100644 --- a/conf/sparc64-ieee1275.rmk +++ b/conf/sparc64-ieee1275.rmk @@ -99,7 +99,6 @@ grub_install_SOURCES = util/sparc64/ieee1275/grub-install.in pkglib_MODULES = halt.mod \ linux.mod \ reboot.mod \ - memdisk.mod \ lsmmap.mod # For boot.mod. @@ -123,11 +122,6 @@ halt_mod_SOURCES = commands/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For memdisk.mod. -memdisk_mod_SOURCES = disk/memdisk.c -memdisk_mod_CFLAGS = $(COMMON_CFLAGS) -memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) - # For lsmmap.mod lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index 22ed2d639..2de6ab443 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -14,6 +14,9 @@ bin_UTILITIES = grub-mkimage grub_mkimage_SOURCES = gnulib/progname.c util/i386/efi/grub-mkimage.c \ util/misc.c util/resolve.c +bin_SCRIPTS += grub-mkrescue +grub_mkrescue_SOURCES = util/grub-mkrescue.in + # For grub-setup. #grub_setup_SOURCES = util/i386/pc/grub-setup.c util/hostdisk.c \ # util/misc.c util/getroot.c kern/device.c kern/disk.c \ diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 51639ccb1..30f319dc3 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -31,6 +31,8 @@ native_platform=@platform@ coreboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-coreboot pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-pc +efi32_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-efi +efi64_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/x86_64-efi # Usage: usage # Print the usage. @@ -109,13 +111,23 @@ if [ "${override_dir}" = "" ] ; then if test -e "${pc_dir}" ; then process_input_dir ${pc_dir} pc fi + if test -e "${efi32_dir}" ; then + process_input_dir ${efi32_dir} efi32 + fi + if test -e "${efi64_dir}" ; then + process_input_dir ${efi64_dir} efi64 + fi else process_input_dir ${override_dir} ${native_platform} coreboot_dir= pc_dir= - case "${native_platform}" in - coreboot) coreboot_dir=${override_dir} ;; - pc) pc_dir=${override_dir} ;; + efi32_dir= + efi64_dir= + case "${target_cpu}-${native_platform}" in + i386-coreboot) coreboot_dir=${override_dir} ;; + i386-pc) pc_dir=${override_dir} ;; + i386-efi) efi32_dir=${override_dir} ;; + x86_64-efi) efi64_dir=${override_dir} ;; esac fi @@ -168,6 +180,23 @@ if test -e "${pc_dir}" ; then grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -boot-info-table" fi +# build bootx64.efi +if test -e "${efi64_dir}" ; then + echo "Generates bootx64.efi" + mkdir -p ${iso9660_dir}/efi/boot + grub-mkimage -d ${efi64_dir}/ -o ${iso9660_dir}/efi/boot/bootx64.efi --prefix=/boot/grub/x86_64-efi \ + search iso9660 configfile sh + + modules="$(cat ${efi64_dir}/partmap.lst) ${modules}" + (for i in ${modules} ; do + if [ "x$i" != xkernel.mod ]; then + echo "insmod $i" + fi + done ; \ + echo "source /boot/grub/grub.cfg") \ + > ${iso9660_dir}/boot/grub/x86_64-efi/grub.cfg +fi + # build iso image grub-mkisofs ${grub_mkisofs_arguments} -o ${output_image} -r ${iso9660_dir} ${source} rm -rf ${iso9660_dir} From 260ddb94173888f802d9de8f50603fa4f3c717ae Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 17 Apr 2010 16:43:04 +0200 Subject: [PATCH 2/4] create a fat16 image as efi spec requires --- util/grub-mkrescue.in | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index b86be39e0..e7dbb45ff 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -203,21 +203,31 @@ if test -e "${pc_dir}" ; then --embedded-boot ${embed_img}" fi +if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then + efi_dir=`mktemp -d "$MKTEMP_TEMPLATE"` + mkdir -p "${efi_dir}/efi/boot" +else + efi_dir= +fi + # build bootx64.efi if test -e "${efi64_dir}" ; then echo "Generates bootx64.efi" - mkdir -p ${iso9660_dir}/efi/boot - grub-mkimage -d ${efi64_dir}/ -o ${iso9660_dir}/efi/boot/bootx64.efi --prefix=/boot/grub/x86_64-efi \ + grub-mkimage -d "${efi64_dir}" -o "${efi_dir}"/efi/boot/bootx64.efi --prefix=/boot/grub/x86_64-efi \ search iso9660 configfile sh - modules="$(cat ${efi64_dir}/partmap.lst) ${modules}" + modules="$(cat "${efi64_dir}"/partmap.lst) ${modules}" (for i in ${modules} ; do - if [ "x$i" != xkernel.mod ]; then - echo "insmod $i" - fi + echo "insmod $i" done ; \ echo "source /boot/grub/grub.cfg") \ - > ${iso9660_dir}/boot/grub/x86_64-efi/grub.cfg + > "${iso9660_dir}"/boot/grub/x86_64-efi/grub.cfg +fi + +if test x"${efi_dir}" != x; then + mformat -C -f 2880 -L 16 -i "${iso9660_dir}"/efi.img :: + mcopy -s -i "${iso9660_dir}"/efi.img ${efi_dir}/efi ::/ + grub_mkisofs_arguments="${grub_mkisofs_arguments} --efi-boot efi.img" fi # build iso image From bc05c2cb2c3c77d4bda5900f7cc24c9c00da356f Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sat, 24 Apr 2010 21:08:25 +0200 Subject: [PATCH 3/4] Change to xorrisofs. Make message more clear. --- util/grub-mkrescue.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index e7dbb45ff..057577272 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -212,7 +212,7 @@ fi # build bootx64.efi if test -e "${efi64_dir}" ; then - echo "Generates bootx64.efi" + echo "Enabling EFI64 support ..." grub-mkimage -d "${efi64_dir}" -o "${efi_dir}"/efi/boot/bootx64.efi --prefix=/boot/grub/x86_64-efi \ search iso9660 configfile sh @@ -231,7 +231,7 @@ if test x"${efi_dir}" != x; then fi # build iso image -grub-mkisofs ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} ${source} +xorrisofs ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} ${source} rm -rf ${iso9660_dir} rm -f ${embed_img} From 13ac43057bcac4644bc50e572c804c7e04470a49 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 27 Apr 2010 11:08:53 +0200 Subject: [PATCH 4/4] use uuids on efi --- kern/efi/init.c | 76 +++++++++++++++++++++++++++---------------- util/grub-mkrescue.in | 24 +++++++++++--- 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/kern/efi/init.c b/kern/efi/init.c index afd21055d..b79084a6a 100644 --- a/kern/efi/init.c +++ b/kern/efi/init.c @@ -24,6 +24,7 @@ #include #include #include +#include void grub_efi_init (void) @@ -41,39 +42,58 @@ grub_efi_init (void) void grub_efi_set_prefix (void) { - grub_efi_loaded_image_t *image; + grub_efi_loaded_image_t *image = NULL; + char *device = NULL; + char *path = NULL; - image = grub_efi_get_loaded_image (grub_efi_image_handle); - if (image) + { + char *pptr = NULL; + if (grub_prefix[0] == '(') + { + pptr = grub_strrchr (grub_prefix, ')'); + if (pptr) + { + device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1); + pptr++; + } + } + if (!pptr) + pptr = grub_prefix; + if (pptr[0]) + path = grub_strdup (pptr); + } + + if (!device || !path) + image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (image && !device) + device = grub_efidisk_get_device_name (image->device_handle); + + if (image && !path) { - char *device; - char *file; + char *p; - device = grub_efidisk_get_device_name (image->device_handle); - file = grub_efi_get_filename (image->file_path); + path = grub_efi_get_filename (image->file_path); - if (device && file) - { - char *p; - char *prefix; - - /* Get the directory. */ - p = grub_strrchr (file, '/'); - if (p) - *p = '\0'; - - prefix = grub_xasprintf ("(%s)%s", device, file); - if (prefix) - { - - grub_env_set ("prefix", prefix); - grub_free (prefix); - } - } - - grub_free (device); - grub_free (file); + /* Get the directory. */ + p = grub_strrchr (path, '/'); + if (p) + *p = '\0'; } + + if (device && path) + { + char *prefix; + + prefix = grub_xasprintf ("(%s)%s", device, path); + if (prefix) + { + grub_env_set ("prefix", prefix); + grub_free (prefix); + } + } + + grub_free (device); + grub_free (path); } void diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index cf791d108..0265f9b81 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -150,14 +150,16 @@ else esac fi +# obtain date-based UUID +iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00) +grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)" + # build coreboot core.img if test -e "${coreboot_dir}" ; then echo "Enabling coreboot support ..." memdisk_img=`mktemp "$MKTEMP_TEMPLATE"` memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"` mkdir -p ${memdisk_dir}/boot/grub - # obtain date-based UUID - iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00) modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}" cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg @@ -176,7 +178,6 @@ EOF memdisk tar search iso9660 configfile sh \ ata at_keyboard rm -f ${memdisk_img} - grub_mkisofs_arguments="${grub_mkisofs_arguments} --modification-date=$(echo ${iso_uuid} | sed -e s/-//g)" fi # build BIOS core.img @@ -213,8 +214,21 @@ fi # build bootx64.efi if test -e "${efi64_dir}" ; then echo "Enabling EFI64 support ..." - grub-mkimage -O x86_64-efi -d "${efi64_dir}" -o "${efi_dir}"/efi/boot/bootx64.efi --prefix=/boot/grub/x86_64-efi \ - search iso9660 configfile sh + memdisk_img=`mktemp "$MKTEMP_TEMPLATE"` + memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"` + mkdir -p ${memdisk_dir}/boot/grub + + cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg +search --fs-uuid --set ${iso_uuid} +set prefix=(\${root})/boot/grub/${target_cpu}-efi +EOF + + tar -C ${memdisk_dir} -cf ${memdisk_img} boot + rm -rf ${memdisk_dir} + + grub-mkimage -O x86_64-efi -d "${efi64_dir}" -m "${memdisk_img}" -o "${efi_dir}"/efi/boot/bootx64.efi --prefix='(memdisk)/boot/grub' \ + search iso9660 configfile sh memdisk tar + rm -f ${memdisk_img} modules="$(cat "${efi64_dir}"/partmap.lst) ${modules}" (for i in ${modules} ; do