Index: usr.sbin/bsdinstall/partedit/partedit.h =================================================================== --- usr.sbin/bsdinstall/partedit/partedit.h +++ usr.sbin/bsdinstall/partedit/partedit.h @@ -83,5 +83,6 @@ const char *bootpart_type(const char *scheme); const char *bootcode_path(const char *scheme); const char *partcode_path(const char *scheme, const char *fs_type); +void apply_workaround(struct gmesh *mesh); #endif Index: usr.sbin/bsdinstall/partedit/partedit.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit.c +++ usr.sbin/bsdinstall/partedit/partedit.c @@ -44,7 +44,6 @@ static int sade_mode = 0; static int apply_changes(struct gmesh *mesh); -static void apply_workaround(struct gmesh *mesh); static struct partedit_item *read_geom_mesh(struct gmesh *mesh, int *nitems); static void add_geom_children(struct ggeom *gp, int recurse, struct partedit_item **items, int *nitems); @@ -393,43 +392,6 @@ return (0); } -static void -apply_workaround(struct gmesh *mesh) -{ - struct gclass *classp; - struct ggeom *gp; - struct gconfig *gc; - const char *scheme = NULL, *modified = NULL; - - LIST_FOREACH(classp, &mesh->lg_class, lg_class) { - if (strcmp(classp->lg_name, "PART") == 0) - break; - } - - if (strcmp(classp->lg_name, "PART") != 0) { - dialog_msgbox("Error", "gpart not found!", 0, 0, TRUE); - return; - } - - LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - LIST_FOREACH(gc, &gp->lg_config, lg_config) { - if (strcmp(gc->lg_name, "scheme") == 0) { - scheme = gc->lg_val; - } else if (strcmp(gc->lg_name, "modified") == 0) { - modified = gc->lg_val; - } - } - - if (scheme && strcmp(scheme, "GPT") == 0 && - modified && strcmp(modified, "true") == 0) { - if (getenv("WORKAROUND_LENOVO")) - gpart_set_root(gp->lg_name, "lenovofix"); - if (getenv("WORKAROUND_GPTACTIVE")) - gpart_set_root(gp->lg_name, "active"); - } - } -} - static struct partedit_item * read_geom_mesh(struct gmesh *mesh, int *nitems) { Index: usr.sbin/bsdinstall/partedit/partedit_generic.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_generic.c +++ usr.sbin/bsdinstall/partedit/partedit_generic.c @@ -77,3 +77,7 @@ return (NULL); } +void +apply_workaround(struct gmesh *mesh) +{ +} Index: usr.sbin/bsdinstall/partedit/partedit_pc98.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_pc98.c +++ usr.sbin/bsdinstall/partedit/partedit_pc98.c @@ -81,3 +81,7 @@ return (NULL); } +void +apply_workaround(struct gmesh *mesh) +{ +} Index: usr.sbin/bsdinstall/partedit/partedit_powerpc.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_powerpc.c +++ usr.sbin/bsdinstall/partedit/partedit_powerpc.c @@ -122,3 +122,7 @@ return (NULL); } +void +apply_workaround(struct gmesh *mesh) +{ +} Index: usr.sbin/bsdinstall/partedit/partedit_sparc64.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_sparc64.c +++ usr.sbin/bsdinstall/partedit/partedit_sparc64.c @@ -80,3 +80,7 @@ return (NULL); } +void +apply_workaround(struct gmesh *mesh) +{ +} Index: usr.sbin/bsdinstall/partedit/partedit_x86.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_x86.c +++ usr.sbin/bsdinstall/partedit/partedit_x86.c @@ -28,7 +28,9 @@ #include #include +#include #include +#include #include "partedit.h" @@ -148,3 +150,42 @@ return (NULL); } +void +apply_workaround(struct gmesh *mesh) +{ + struct gclass *classp; + struct ggeom *gp; + struct gconfig *gc; + const char *scheme = NULL, *modified = NULL; + int workaround_lenovo, workaround_gptactive; + + workaround_lenovo = system("bsdinstall workaround_lenovo"); + workaround_gptactive = system("bsdinstall workaround_gptactive"); + + LIST_FOREACH(classp, &mesh->lg_class, lg_class) { + if (strcmp(classp->lg_name, "PART") == 0) + break; + } + + if (strcmp(classp->lg_name, "PART") != 0) { + return; + } + + LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { + LIST_FOREACH(gc, &gp->lg_config, lg_config) { + if (strcmp(gc->lg_name, "scheme") == 0) { + scheme = gc->lg_val; + } else if (strcmp(gc->lg_name, "modified") == 0) { + modified = gc->lg_val; + } + } + + if (scheme && strcmp(scheme, "GPT") == 0 && + modified && strcmp(modified, "true") == 0) { + if (workaround_lenovo != 0) + gpart_set_root(gp->lg_name, "lenovofix"); + if (workaround_gptactive != 0) + gpart_set_root(gp->lg_name, "active"); + } + } +} Index: usr.sbin/bsdinstall/scripts/Makefile =================================================================== --- usr.sbin/bsdinstall/scripts/Makefile +++ usr.sbin/bsdinstall/scripts/Makefile @@ -2,7 +2,8 @@ SCRIPTS= auto adduser checksum config docsinstall entropy hostname jail \ keymap mirrorselect mount netconfig netconfig_ipv4 netconfig_ipv6 \ - rootpass script services time umount wlanconfig zfsboot + rootpass script services time umount wlanconfig \ + workaround_gptactive workaround_lenovo zfsboot BINDIR= ${LIBEXECDIR}/bsdinstall MAN= Index: usr.sbin/bsdinstall/scripts/auto =================================================================== --- usr.sbin/bsdinstall/scripts/auto +++ usr.sbin/bsdinstall/scripts/auto @@ -52,54 +52,6 @@ fi } -hline_arrows_tab_enter="Press arrows, TAB or ENTER" -msg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?" -msg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?" -msg_no="NO" -msg_yes="YES" - -# dialog_workaround -# -# Ask the user if they wish to apply a workaround -# -dialog_workaround() -{ - local passed_msg="$1" - local title="$DIALOG_TITLE" - local btitle="$DIALOG_BACKTITLE" - local prompt # Calculated below - local hline="$hline_arrows_tab_enter" - - local height=8 width=50 prefix=" " - local plen=${#prefix} list= line= - local max_width=$(( $width - 3 - $plen )) - - local yes no defaultno extra_args format - if [ "$USE_XDIALOG" ]; then - yes=ok no=cancel defaultno=default-no - extra_args="--wrap --left" - format="$passed_msg" - else - yes=yes no=no defaultno=defaultno - extra_args="--cr-wrap" - format="$passed_msg" - fi - - # Add height for Xdialog(1) - [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) - - prompt=$( printf "$format" ) - f_dprintf "%s: Workaround prompt" "$0" - $DIALOG \ - --title "$title" \ - --backtitle "$btitle" \ - --hline "$hline" \ - --$yes-label "$msg_yes" \ - --$no-label "$msg_no" \ - $extra_args \ - --yesno "$prompt" $height $width -} - ############################################################ MAIN f_dprintf "Began Installation at %s" "$( date )" @@ -160,99 +112,6 @@ rm -f $PATH_FSTAB touch $PATH_FSTAB -# -# Try to detect known broken platforms and apply their workarounds -# - -if f_interactive; then - sys_maker=$( kenv -q smbios.system.maker ) - f_dprintf "smbios.system.maker=[%s]" "$sys_maker" - sys_model=$( kenv -q smbios.system.product ) - f_dprintf "smbios.system.product=[%s]" "$sys_model" - sys_version=$( kenv -q smbios.system.version ) - f_dprintf "smbios.system.version=[%s]" "$sys_version" - sys_mb_maker=$( kenv -q smbios.planar.maker ) - f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker" - sys_mb_product=$( kenv -q smbios.planar.product ) - f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product" - - # - # Laptop Models - # - case "$sys_maker" in - "LENOVO") - case "$sys_version" in - "ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520") - dialog_workaround "$msg_lenovo_fix" - retval=$? - f_dprintf "lenovofix_prompt=[%s]" "$retval" - if [ $retval -eq $DIALOG_OK ]; then - export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" - export WORKAROUND_LENOVO=1 - fi - ;; - esac - ;; - "Dell Inc.") - case "$sys_model" in - "Latitude E7440"|"Latitude E7240"|"Precision Tower 5810") - dialog_workaround "$msg_gpt_active_fix" - retval=$? - f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" - if [ $retval -eq $DIALOG_OK ]; then - export ZFSBOOT_PARTITION_SCHEME="GPT + Active" - export WORKAROUND_GPTACTIVE=1 - fi - ;; - esac - ;; - "Hewlett-Packard") - case "$sys_model" in - "HP ProBook 4330s") - dialog_workaround "$msg_gpt_active_fix" - retval=$? - f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" - if [ $retval -eq $DIALOG_OK ]; then - export ZFSBOOT_PARTITION_SCHEME="GPT + Active" - export WORKAROUND_GPTACTIVE=1 - fi - ;; - esac - ;; - esac - # - # Motherboard Models - # - case "$sys_mb_maker" in - "Intel Corporation") - case "$sys_mb_product" in - "DP965LT"|"D510MO") - dialog_workaround "$msg_gpt_active_fix" - retval=$? - f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" - if [ $retval -eq $DIALOG_OK ]; then - export ZFSBOOT_PARTITION_SCHEME="GPT + Active" - export WORKAROUND_GPTACTIVE=1 - fi - ;; - esac - ;; - "Acer") - case "$sys_mb_product" in - "Veriton M6630G") - dialog_workaround "$msg_gpt_active_fix" - retval=$? - f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" - if [ $retval -eq $DIALOG_OK ]; then - export ZFSBOOT_PARTITION_SCHEME="GPT + Active" - export WORKAROUND_GPTACTIVE=1 - fi - ;; - esac - ;; - esac -fi - PMODES="\ \"Auto (UFS)\" \"Guided Disk Setup\" \ Manual \"Manual Disk Setup (experts)\" \ Index: usr.sbin/bsdinstall/scripts/workaround_gptactive =================================================================== --- /dev/null +++ usr.sbin/bsdinstall/scripts/workaround_gptactive @@ -0,0 +1,164 @@ +#!/bin/sh +#- +# Copyright (c) 2015-2016 Allan Jude +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ FUNCTIONS + +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?" +msg_no="NO" +msg_yes="YES" + +# dialog_workaround +# +# Ask the user if they wish to apply a workaround +# +dialog_workaround() +{ + local passed_msg="$1" + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt # Calculated below + local hline="$hline_arrows_tab_enter" + + local height=8 width=50 prefix=" " + local plen=${#prefix} list= line= + local max_width=$(( $width - 3 - $plen )) + + local yes no defaultno extra_args format + if [ "$USE_XDIALOG" ]; then + yes=ok no=cancel defaultno=default-no + extra_args="--wrap --left" + format="$passed_msg" + else + yes=yes no=no defaultno=defaultno + extra_args="--cr-wrap" + format="$passed_msg" + fi + + # Add height for Xdialog(1) + [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) + + prompt=$( printf "$format" ) + f_dprintf "%s: Workaround prompt" "$0" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --$yes-label "$msg_yes" \ + --$no-label "$msg_no" \ + $extra_args \ + --yesno "$prompt" $height $width +} + +############################################################ MAIN + +# +# Try to detect known broken platforms and apply their workarounds +# + +if f_interactive; then + sys_maker=$( kenv -q smbios.system.maker ) + f_dprintf "smbios.system.maker=[%s]" "$sys_maker" + sys_model=$( kenv -q smbios.system.product ) + f_dprintf "smbios.system.product=[%s]" "$sys_model" + sys_version=$( kenv -q smbios.system.version ) + f_dprintf "smbios.system.version=[%s]" "$sys_version" + sys_mb_maker=$( kenv -q smbios.planar.maker ) + f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker" + sys_mb_product=$( kenv -q smbios.planar.product ) + f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product" + + # + # Laptop Models + # + case "$sys_maker" in + "Dell Inc.") + case "$sys_model" in + "Latitude E7440"|"Latitude E7240"|"Precision Tower 5810") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + exit 1 + fi + ;; + esac + ;; + "Hewlett-Packard") + case "$sys_model" in + "HP ProBook 4330s") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + exit 1 + fi + ;; + esac + ;; + esac + # + # Motherboard Models + # + case "$sys_mb_maker" in + "Intel Corporation") + case "$sys_mb_product" in + "DP965LT"|"D510MO") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + exit 1 + fi + ;; + esac + ;; + "Acer") + case "$sys_mb_product" in + "Veriton M6630G") + dialog_workaround "$msg_gpt_active_fix" + retval=$? + f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + exit 1 + fi + ;; + esac + ;; + esac +fi + +################################################################################ +# END +################################################################################ Index: usr.sbin/bsdinstall/scripts/workaround_lenovo =================================================================== --- /dev/null +++ usr.sbin/bsdinstall/scripts/workaround_lenovo @@ -0,0 +1,111 @@ +#!/bin/sh +#- +# Copyright (c) 2015-2016 Allan Jude +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +############################################################ INCLUDES + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 +f_include $BSDCFG_SHARE/dialog.subr + +############################################################ FUNCTIONS + +hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?" +msg_no="NO" +msg_yes="YES" + +# dialog_workaround +# +# Ask the user if they wish to apply a workaround +# +dialog_workaround() +{ + local passed_msg="$1" + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt # Calculated below + local hline="$hline_arrows_tab_enter" + + local height=8 width=50 prefix=" " + local plen=${#prefix} list= line= + local max_width=$(( $width - 3 - $plen )) + + local yes no defaultno extra_args format + if [ "$USE_XDIALOG" ]; then + yes=ok no=cancel defaultno=default-no + extra_args="--wrap --left" + format="$passed_msg" + else + yes=yes no=no defaultno=defaultno + extra_args="--cr-wrap" + format="$passed_msg" + fi + + # Add height for Xdialog(1) + [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) + + prompt=$( printf "$format" ) + f_dprintf "%s: Workaround prompt" "$0" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --hline "$hline" \ + --$yes-label "$msg_yes" \ + --$no-label "$msg_no" \ + $extra_args \ + --yesno "$prompt" $height $width +} + +############################################################ MAIN + +# +# Try to detect known broken platforms and apply their workarounds +# + +if f_interactive; then + sys_version=$( kenv -q smbios.system.version ) + f_dprintf "smbios.system.version=[%s]" "$sys_version" + + # + # Lenovo Laptop Models + # + case "$sys_version" in + "ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520") + dialog_workaround "$msg_lenovo_fix" + retval=$? + f_dprintf "lenovofix_prompt=[%s]" "$retval" + if [ $retval -eq $DIALOG_OK ]; then + exit 1 + fi + ;; + esac +fi + +################################################################################ +# END +################################################################################ Index: usr.sbin/bsdinstall/scripts/zfsboot =================================================================== --- usr.sbin/bsdinstall/scripts/zfsboot +++ usr.sbin/bsdinstall/scripts/zfsboot @@ -1447,6 +1447,10 @@ else : ${ZFSBOOT_BOOT_TYPE:=BIOS} : ${ZFSBOOT_PARTITION_SCHEME:=GPT} + bsdinstall workaround_lenovo || + export WORKAROUND_LENOVO=1 ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" + bsdinstall workaround_gptactive || + export WORKAROUND_GPTACTIVE=1 ZFSBOOT_PARTITION_SCHEME="GPT + Active" fi #