From 21a313dedc50ebb175f930199de4d915882cc14b Mon Sep 17 00:00:00 2001 From: Robert Millan Date: Fri, 20 Aug 2010 16:36:07 +0200 Subject: [PATCH] 2010-08-20 Robert Millan Make kFreeBSD code more generic to support ext2fs as root, ufs as a separate module and maybe other interesting combinations. * util/grub.d/10_kfreebsd.in (load_kfreebsd_module): New function. (kfreebsd_entry): Use load_kfreebsd_module() to load modules. (kfreebsd_entry): Add generic filesystem module load routine. Map GRUB `ext2' to kFreeBSD `ext2fs'. --- ChangeLog | 10 +++++++ util/grub.d/10_kfreebsd.in | 54 +++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d82e08fb..fa2178875 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-08-20 Robert Millan + + Make kFreeBSD code more generic to support ext2fs as root, ufs as + a separate module and maybe other interesting combinations. + + * util/grub.d/10_kfreebsd.in (load_kfreebsd_module): New function. + (kfreebsd_entry): Use load_kfreebsd_module() to load modules. + (kfreebsd_entry): Add generic filesystem module load routine. + Map GRUB `ext2' to kFreeBSD `ext2fs'. + 2010-08-20 Colin Watson * commands/i386/pc/sendkey.c (keysym_table): Rename "numlock" to diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 3a42de529..40ac240c7 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -39,6 +39,31 @@ case "${GRUB_DISTRIBUTOR}" in ;; esac +load_kfreebsd_module () +{ + mod="$1" + allow_fail="$2" + + if ! test -e "${module_dir}/${mod}.ko" ; then + if [ "${allow_fail}" = "true" ] ; then + # Return silently + return + else + # Print an error and fail. + ls "${module_dir}/${mod}.ko" > /dev/null + fi + fi + + if [ -z "${prepare_module_dir_cache}" ]; then + prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")" + fi + + printf '%s\n' "${prepare_module_dir_cache}" + cat << EOF + kfreebsd_module_elf ${module_dir_rel}/${mod}.ko +EOF +} + kfreebsd_entry () { os="$1" @@ -51,9 +76,6 @@ kfreebsd_entry () if [ -z "${prepare_boot_cache}" ]; then prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")" fi - if [ -z "${prepare_module_dir_cache}" ]; then - prepare_module_dir_cache="$(prepare_grub_to_access_device $(grub-probe -t device "${module_dir}") | sed -e "s/^/\t/")" - fi printf '%s\n' "${prepare_boot_cache}" cat << EOF @@ -67,26 +89,13 @@ EOF EOF fi - if test -e "${module_dir}/acpi.ko" ; then - printf '%s\n' "${prepare_module_dir_cache}" - cat << EOF - kfreebsd_module_elf ${module_dir_rel}/acpi.ko -EOF - fi + load_kfreebsd_module acpi true case "${kfreebsd_fs}" in zfs) - for i in "${module_dir}/opensolaris.ko" "${module_dir}/zfs.ko" \ - "${dirname}/zfs/zpool.cache" ; do - ls "$i" > /dev/null - done - - printf '%s\n' "${prepare_module_dir_cache}" - cat << EOF - kfreebsd_module_elf ${module_dir_rel}/opensolaris.ko - kfreebsd_module_elf ${module_dir_rel}/zfs.ko -EOF + load_kfreebsd_module opensolaris false + ls "${dirname}/zfs/zpool.cache" > /dev/null printf '%s\n' "${prepare_boot_cache}" cat << EOF kfreebsd_module ${rel_dirname}/zfs/zpool.cache type=/boot/zfs/zpool.cache @@ -94,6 +103,8 @@ EOF ;; esac + load_kfreebsd_module ${kfreebsd_fs} false + cat << EOF set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device} set kFreeBSD.vfs.root.mountfrom.options=rw @@ -121,8 +132,9 @@ while [ "x$list" != "x" ] ; do fi case ${GRUB_FS} in - ufs1 | ufs2) kfreebsd_fs=ufs ;; - *) kfreebsd_fs=${GRUB_FS} ;; + ufs1 | ufs2) kfreebsd_fs=ufs ;; + ext2) kfreebsd_fs=ext2fs ;; + *) kfreebsd_fs=${GRUB_FS} ;; esac case ${GRUB_FS} in