This patch requires the nvram tool which is part of the
powerpc-ibm-utils package.

v1 -> v2:

  - adapted changelog entry and shrinked commit message
  - added help messages for manual setting of NVRAM vars if automatic
    setting fails
  - configure NVRAM to automatically boot the machine
  - failure of unmounting and mounting of the OFFS (NewWorld bootstrap
    partition) before and after the CHRP boot script is made bootable
    from OpenFirmware is now fatal for the GRUB installation

---
 debian/changelog |   3 ++
 grub-installer   | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 1d61497..78870f3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,9 @@ grub-installer (1.147) UNRELEASED; urgency=medium
   * Detect and select newworld bootstrap partitions
   * Handle HFS file systems (format, mount, unmount, fstab entry)
   * Patch the CHRP boot script
+  * Adapt grub-install parameters and finally perform GRUB installation. Make
+    CHRP script bootable by OpenFirmware. Configure NVRAM defaults and boot
+    automatically.
 
  -- Frank Scheiner <[email protected]>  Thu, 16 Nov 2017 07:20:38 +0100
 
diff --git a/grub-installer b/grub-installer
index 7d68fb2..45f8083 100755
--- a/grub-installer
+++ b/grub-installer
@@ -240,6 +240,105 @@ nw_patch_boot_script()
        fi
 }
 
+nw_make_boot_script_of_bootable()
+{
+       local offs_part="$1"
+       local hfs_path="$2"
+       local boot_script_name="$3"
+
+       local self="nw_make_boot_script_of_bootable"
+       local exit_code=0
+
+       # create script for in-target Operation
+       cat > ${ROOT}/tmp/make_boot_script_of_bootable <<-EOF
+               #!/bin/sh
+               if hmount "$offs_part"; then
+                       # Set file type of boot script to tbxi and "bless" 
directory
+                       hattrib -t tbxi -c UNIX 
"${hfs_path}:${boot_script_name}" && \\
+                       hattrib -b "${hfs_path}"
+                       if [ $? -ne 0 ]; then
+                               humount
+                               exit 1
+                       else
+                               humount
+                               exit 0
+                       fi
+               else
+                       exit 2
+               fi
+       EOF
+
+       chmod +x ${ROOT}/tmp/make_boot_script_of_bootable
+
+       in-target /tmp/make_boot_script_of_bootable || exit_code=$?
+
+       if [ $exit_code -eq 0 ]; then
+               info "$self: Operation suceeded."
+               rm ${ROOT}/tmp/make_boot_script_of_bootable
+               return 0
+       elif [ $exit_code -eq 1 ]; then
+               error "$self: Operation failed." 1>&2
+               return 1
+       elif [ $exit_code -eq 2 ]; then
+               error "$self: Couldn't hmount \"$offs_part\"" 1>&2
+               return 1
+       fi
+}
+
+nw_backup_nvram_contents()
+{
+       local self="nw_backup_nvram_contents"
+       local nvram_backup="${ROOT}/root/nvram_backup"
+
+       if in-target nvram --print-config > "$nvram_backup"; then
+               info "$self: Original NVRAM contents backed up to $nvram_backup"
+               return 0
+       else
+               error "$self: Original NVRAM contents couldn't be backed up to 
$nvram_backup" 1>&2
+               return 1
+       fi
+}
+
+nw_configure_nvram()
+{
+       local self="nw_configure_nvram"
+       local configure_failed=0
+
+       # `boot-device`
+       # boot file of type tbxi from "blessed" directory
+       if in-target nvram --update-config boot-device='hd:,\\:tbxi'; then
+               info "$self: Configured \"boot-device\" to \"hd:,\\:tbxi\""
+       else
+               error "$self: Couldn't configure \"boot-device\" to 
\"hd:,\\:tbxi\". " \
+                     "Use \`setenv boot-device hd:,\\:tbxi' in OpenFirmware 
instead." 1>&2
+               configure_failed=1
+       fi
+
+       # `boot-command`
+       if in-target nvram --update-config boot-command='mac-boot'; then
+               info "$self: Configured \"boot-command\" to \"mac-boot\""
+       else
+               error "$self: Couldn't configure \"boot-command\" to 
\"mac-boot\". " \
+                     "Use \`setenv boot-command mac-boot' in OpenFirmware 
instead." 1>&2
+               configure_failed=1
+       fi
+
+       # `auto-boot?`
+       if in-target nvram --update-config 'auto-boot?'='true'; then
+               info "$self: Configured \"auto-boot?\" to \"true\""
+       else
+               error "$self: Couldn't configure \"auto-boot?\" to \"true\". " \
+                     "Use \`setenv auto-boot? true' in OpenFirmware instead." 
1>&2
+               configure_failed=1
+       fi
+
+       if [ $configure_failed -eq 0 ]; then
+               return 0
+       else
+               return 1
+       fi
+}
+
 ARCH="$(archdetect)"
 info "architecture: $ARCH"
 
@@ -1097,6 +1196,9 @@ if [ -z "$frdisk" ]; then
                        # see: https://github.com/esnowberg/grub2-sparc/wiki
                        grub_install_params="$grub_install_params 
--skip-fs-probe"
                        ;;
+                   powerpc/powermac_newworld|ppc64/powermac_newworld)
+                       grub_install_params="$grub_install_params 
--macppc-directory=$NW_OFFS_MOUNT_POINT"
+                       ;;
                esac
 
                if [ "$grub_version" = "grub" ] ; then
@@ -1108,6 +1210,25 @@ if [ -z "$frdisk" ]; then
 
                CODE=0
                case $ARCH:$grub_package in
+                   
powerpc/powermac_newworld:grub-ieee1275|ppc64/powermac_newworld:grub-ieee1275)
+                       nw_backup_nvram_contents || true
+                       info "Running $chroot $ROOT grub-install 
$grub_install_params"
+                       log-output -t grub-installer $chroot $ROOT grub-install 
$grub_install_params || CODE=$?
+                       # Unmount OFFS before using `hattrib` in the next step 
so all
+                       # changes in the file system are written back and are 
visible
+                       # to `hattrib` later on.
+                       nw_unmount_offs "$offs_part" || exit 1
+                       # HFS path from [1] adapted for use with `hattrib`. 
`BootX`
+                       # - which is the final name for the CHRP boot script - 
as
+                       # installed by `grub-install` later is located in the 
same HFS
+                       # path as the `grub.elf` referenced in `BootX`
+                       #
+                       # [1]: 
http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/boot/powerpc/grub.chrp.in?id=446794de8da4329ea532cbee4ca877bcafd0e534
+                       nw_make_boot_script_of_bootable "$offs_part" 
"bootstrap:System:Library:CoreServices" "BootX" || exit 1
+                       # Mount OFFS again before continuing
+                       nw_mount_offs "$offs_part" || exit 1
+                       nw_configure_nvram || true
+                       ;;
                    
*:grub|*:grub-pc|*:grub-efi*|sparc/*:grub-ieee1275|sparc64/*:grub-ieee1275|powerpc/*:grub-ieee1275|ppc64/*:grub-ieee1275|ppc64el/*:grub-ieee1275)
                        info "Running $chroot $ROOT grub-install 
$grub_install_params \"$bootdev\""
                        log-output -t grub-installer $chroot $ROOT grub-install 
$grub_install_params "$bootdev" || CODE=$?
-- 
1.9.1

Reply via email to