diff options
author | Matthias Hentges <oe@hentges.net> | 2006-04-17 19:21:34 +0000 |
---|---|---|
committer | OpenEmbedded Project <openembedded-devel@lists.openembedded.org> | 2006-04-17 19:21:34 +0000 |
commit | 6a23a1d754a1d081aee5687ffbfaecb805fa8db5 (patch) | |
tree | 77980626a7320c4647d19671b67d83c217983c20 /packages/altboot/files | |
parent | 059820ddf64d15cbb63c6cf6984c0da2b4e205f0 (diff) |
altboot: Add initial support for kexec, reworked parts of the menu code
Diffstat (limited to 'packages/altboot/files')
-rw-r--r-- | packages/altboot/files/altboot-menu/Advanced/35-kexec | 62 | ||||
-rw-r--r-- | packages/altboot/files/altboot-menu/Advanced/70-setKernel | 65 | ||||
-rw-r--r-- | packages/altboot/files/altboot-menu/Advanced/80-configure-kexec | 244 | ||||
-rw-r--r-- | packages/altboot/files/altboot.func | 90 | ||||
-rw-r--r-- | packages/altboot/files/init.altboot | 176 |
5 files changed, 490 insertions, 147 deletions
diff --git a/packages/altboot/files/altboot-menu/Advanced/35-kexec b/packages/altboot/files/altboot-menu/Advanced/35-kexec deleted file mode 100644 index 41b193a379..0000000000 --- a/packages/altboot/files/altboot-menu/Advanced/35-kexec +++ /dev/null @@ -1,62 +0,0 @@ -# !/bin/sh -M_TITLE="init=/bin/sh" - -exit 0 - -# Only kernel 2.6 offers kexec support -uname -r | grep -q "^2.6" || exit 0 - -run_module() { - - test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!" - - test -z "$KEXEC_KERNEL_DIR" && KEXEC_KERNEL_DIR="/boot" - test -x "$KEXEC_BIN" || die "kexec-tools not found [$KEXEC_BIN]" - - # Mount /proc, etc - init_rootfs - - if test "`find "$KEXEC_KERNEL_DIR" -type f -name "*zImage*" | wc -l | tr -d " "`" -gt 1 - then - echo "Please choose a kernel to boot:" - cd "$KEXEC_KERNEL_DIR" - - cnt=1 - for f in `ls -1 "$KEXEC_KERNEL_DIR"` - do - echo "[$cnt] $f" - let cnt=$cnt+1 - done - - while true - do - echo -n "Boot kernel: " - read junk - - if test -n "$junk" - then - cnt=1 - for f in `ls -1 "$KEXEC_KERNEL_DIR"` - do - if test "$cnt" = "$junk" - then - KEXEC_KERNEL="$f" - break - fi - let cnt=$cnt+1 - done - fi - done - - echo "kernel dir:[$KEXEC_KERNEL_DIR]" - echo "Using kernel: [$KEXEC_KERNEL]" - - - for -} - -case "$1" in -title) echo "$M_TITLE";; -run) run_module;; -esac - diff --git a/packages/altboot/files/altboot-menu/Advanced/70-setKernel b/packages/altboot/files/altboot-menu/Advanced/70-setKernel new file mode 100644 index 0000000000..3479637ba1 --- /dev/null +++ b/packages/altboot/files/altboot-menu/Advanced/70-setKernel @@ -0,0 +1,65 @@ +# !/bin/sh +M_TITLE="Choose kernel for next boot" + + + +# Only kernel 2.6 offers kexec support +uname -r | grep -q "^2.6" || exit 0 + +run_module() { + + test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!" + + test -z "$KEXEC_KERNEL_DIR" && KEXEC_KERNEL_DIR="/boot" + test -x "$KEXEC_BIN" || die "kexec-tools not found [$KEXEC_BIN]" + + # Mount /proc, etc + # init_rootfs + + if test `ls -1 $KEXEC_KERNEL_DIR | grep -v "kexec.cfg" | wc -l | tr -d " "` -gt 1 + then + echo -e "\nSelect the kernel for use of the next boot:\n" + + cnt=1 ; reset_pref "kexec_klist" + for k in `ls -1 $KEXEC_KERNEL_DIR/zImage* | grep -v "kexec.cfg" ` + do + echo -e "\t[$cnt] $k" + set_pref "kexec_klist" "$cnt" "$k" + + let cnt=$cnt+1 + done + + echo "" + + while true + do + echo -n "Select a kernel: " + read junk + + #echo_pref kexec_klist + + get_pref "kexec_klist" "$junk" KEXEC_SELECTED_KERNEL && break + + done + + echo "Using [$KEXEC_SELECTED_KERNEL]" + fi + + if ! test -e "$KEXEC_SELECTED_KERNEL.kexec.cfg" + then + echo -e "\nWARNING: This kernel has not been configured." + echo -e "It will only boot correctly if CMDLINE is compiled in.\n" + fi + + export USE_KEXEC_ON_NEXT_BOOT=yes + export KEXEC_SELECTED_KERNEL + show_menu +} + + + +case "$1" in +title) echo "$M_TITLE";; +run) run_module;; +esac + diff --git a/packages/altboot/files/altboot-menu/Advanced/80-configure-kexec b/packages/altboot/files/altboot-menu/Advanced/80-configure-kexec new file mode 100644 index 0000000000..9418e30dcf --- /dev/null +++ b/packages/altboot/files/altboot-menu/Advanced/80-configure-kexec @@ -0,0 +1,244 @@ +# !/bin/sh +M_TITLE="Configure kexec CMDLINE" + + + +# Only kernel 2.6 offers kexec support +uname -r | grep -q "^2.6" || exit 0 + +run_module() { + + test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!" + + test -z "$KEXEC_KERNEL_DIR" && KEXEC_KERNEL_DIR="/boot" + test -x "$KEXEC_BIN" || die "kexec-tools not found [$KEXEC_BIN]" + + # Mount /proc, etc + init_rootfs + + if test `ls -1 $KEXEC_KERNEL_DIR | grep -v "kexec.cfg" | wc -l | tr -d " "` -gt 1 + then + echo -e "\nPlease select the kernel you want to configure:\n" + + cnt=1 ; reset_pref "kexec_klist" + for k in `ls -1 $KEXEC_KERNEL_DIR/zImage* | grep -v "kexec.cfg" ` + do + echo -e "\t[$cnt] $k" + set_pref "kexec_klist" "$cnt" "$k" + + let cnt=$cnt+1 + done + + echo "" + + while true + do + echo -n "Select a kernel: " + read junk + + get_pref "kexec_klist" "$junk" KEXEC_KERNEL && break + + done + + echo "Using [$KEXEC_KERNEL]" + fi + + configure_rootdev + configure_roottype + configure_verbose + configure_custom + + CMDLINE="console=ttyS0,115200n8 console=tty1 dyntick=enable fbcon=rotate:1 noinitrd root=$KERNEL_ROOTDEV rootfstype=$KERNEL_ROOTFSTYPE $KERNEL_VERBOSE $KERNEL_CUSTOM" + + echo -en "\nWriting CMDLINE to $KEXEC_KERNEL.kexec.cfg..." + echo "$CMDLINE" > $KEXEC_KERNEL.kexec.cfg && echo ok || mdie FAILED + + show_menu +} + +configure_rootdev() { + + echo -e "\nPlease choose a root device (root=*):\n" + + cnt=1 ; reset_pref "kexec_rootdev" + for root in /dev/mtdblock2 /dev/hda1 "Manual Entry" + do + echo -e "\t[$cnt] $root" + set_pref kexec_rootdev "$cnt" "$root" + let cnt=cnt+1 + done + + echo "" + + while true + do + echo -n "Select a root device: " + read junk + + get_pref kexec_rootdev "$junk" KERNEL_ROOTDEV && break + done + + if test "$KERNEL_ROOTDEV" = "Manual Entry" + then + echo "" + + KERNEL_ROOTDEV="" + + while test -z "$KERNEL_ROOTDEV" + do + while true + do + echo -n "Enter the root device: " + read junk + test -n "$junk" && break + done + + echo -en "\nIs [$junk] correct? [Y|n] " + read junk2 + while true + do + if test "$junk2" = y -o "$junk2" = Y -o -z "$junk2" + then + KERNEL_ROOTDEV="$junk" + break + fi + + break + done + done + fi + + echo "Using [$KERNEL_ROOTDEV] as root device" +} + +configure_roottype() { + + echo -e "\nPlease choose a rootfs type (rootfs=*):\n" + + cnt=1 ; reset_pref "kexec_rootfstype" + for root in jffs2 ext2 ext3 "Manual Entry" + do + echo -e "\t[$cnt] $root" + set_pref kexec_rootfstype "$cnt" "$root" + let cnt=cnt+1 + done + + echo "" + + while true + do + echo -n "Select a rootfs type: " + read junk + + get_pref kexec_rootfstype "$junk" KERNEL_ROOTFSTYPE && break + done + + if test "$KERNEL_ROOTFSTYPE" = "Manual Entry" + then + echo "" + + KERNEL_ROOTFSTYPE="" + + while test -z "$KERNEL_ROOTFSTYPE" + do + while true + do + echo -n "Enter the rootfs type: " + read junk + test -n "$junk" && break + done + + echo -en "\nIs [$junk] correct? [Y|n] " + read junk2 + while true + do + if test "$junk2" = y -o "$junk2" = Y -o -z "$junk2" + then + KERNEL_ROOTFSTYPE="$junk" + break + fi + + break + done + done + fi + + echo "Using [$KERNEL_ROOTFSTYPE] as rootfs type" +} + +configure_verbose() { + echo -e "\nDo you want to see kernel messages? ([quiet | debug]):\n" + + echo -e "\t[1] Yes" + echo -e "\t[2] No" + + echo "" + + while true + do + echo -n "Select one of the above: " + read junk + + test "$junk" = 1 -o "$junk" = 2 && break + done + + test "$junk" = 1 && KERNEL_VERBOSE="debug" || KERNEL_VERBOSE="quiet" + +} + +configure_custom() { + echo -e "\nDo you want to set custom kernel options?\n" + + echo -e "\t[1] Yes" + echo -e "\t[2] No" + + echo "" + + while true + do + echo -n "Select one of the above: " + read junk + + test "$junk" = 1 -o "$junk" = 2 && break + done + + if test "$junk" = 1 + then + + echo "" + + KERNEL_CUSTOM="" + + while test -z "$KERNEL_CUSTOM" + do + while true + do + echo -n "Enter kernel options: " + read junk + test -n "$junk" && break + done + + echo -en "\nIs [$junk] correct? [Y|n] " + read junk2 + while true + do + if test "$junk2" = y -o "$junk2" = Y -o -z "$junk2" + then + KERNEL_CUSTOM="$junk" + break + fi + + break + done + done + fi + + echo "Using [$KERNEL_CUSTOM] as custom kernel options" + +} + +case "$1" in +title) echo "$M_TITLE";; +run) run_module;; +esac + diff --git a/packages/altboot/files/altboot.func b/packages/altboot/files/altboot.func index 3c6d165851..31b79c52a5 100644 --- a/packages/altboot/files/altboot.func +++ b/packages/altboot/files/altboot.func @@ -181,6 +181,30 @@ pivot_image() { #$1=mountpoint of the soon-to-be rootfs, $2=Runlevel do_pivot(){ + + echo "[$USE_KEXEC_ON_NEXT_BOOT]" + + if test "$USE_KEXEC_ON_NEXT_BOOT" = yes + then + if test -e "$KEXEC_SELECTED_KERNEL.kexec.cfg" + then + CMDLINE="--append=\"`cat $KEXEC_SELECTED_KERNEL.kexec.cfg`\"" + else + CMDLINE="" + echo "WARNING: This kernel has not been configured!" + echo "Trying to boot anyway..." + fi + + echo "$KEXEC_BIN -l $KEXEC_SELECTED_KERNEL $CMDLINE" + $KEXEC_BIN -l $KEXEC_SELECTED_KERNEL $CMDLINE + sync + + read junk + $KEXEC_BIN -e + exit 0 + fi + + echo -n "Pivoting root..." if (/sbin/pivot_root "$1" "$1/media/ROM") then @@ -526,6 +550,70 @@ mount_home(){ fi } +show_menu() { + + echo -e "\nPress <ENTER> to return to the menu" + read junk + + test "$junk" = x && exec /bin/sh || exec /sbin/init.altboot -force</dev/tty0 >/dev/tty0 2>&1 +} + +mdie() { + echo "ERROR: $1" >/dev/tty0 + + echo -e "\nPress <ENTER> to return to the menu" + read junk + + test "$junk" = x && exec /bin/sh || exec /sbin/init.altboot -force</dev/tty0 >/dev/tty0 2>&1 +} + +# $1: uniq name, $2 identifier, $3 value +set_pref() { + data_name="$1" + data_id="$2" + data_value="$3" + + #echo "[$1] [$2] [$3]" + #export "${data_name}"="`eval echo -e \\$${data_name} | sed "s/\#\#\#/\#\#\#\\n/g"|sed s/^\ // | sed s/^$data_id.*//`" + + export "${data_name}"="`eval echo -e \\$${data_name} ` +$data_id##$data_value###" + +} + +# $1: uniq name +reset_pref() { + data_name="$1" + export "${data_name}"="" +} + +echo_pref() { + data_name="$1" + echo "****** $1 ******" + echo "`eval echo -e \\$${data_name} | sed "s/\#\#\#/\#\#\#\\n/g"|sed s/^\ // `" + echo "******" +} + +dump_pref() { + data_name="$1" + echo "`eval echo -e \\$${data_name} | sed "s/\#\#\#/\#\#\#\\n/g"|sed s/^\ // `" +} + +# $1: uniq name, $2 identifier, $3 out var +get_pref() { + data_name="$1" + data_id="$2" + data_out="$3" + data_list="`eval echo -e \\$${data_name}`" + + data_value="`echo "$data_list"| sed "s/\#\#\#/\\n/g"|sed s/^\ // | grep "^$data_id##" | sed -n "s/.*\#\(.*\)$/\1/p"`" + + # echo "WERT: [$data_value]" + + export "${data_out}"="$data_value" + test -n "$data_value" && return 0 +} + start_networking() { if test "$USB_NETWORKING_AVAILABLE" = "yes" @@ -586,7 +674,7 @@ start_networking() { /etc/init.d/pcmcia start >/dev/null 2>&1 || die "/etc/init.d/pcmcia start failed!" else # With kernel 2.6.16+ udev is used - /etc/init.d/udev start >/dev/null 2>&1 || die "/etc/init.d/udev start failed!" + ps ax| grep -v grep | grep -q udevd || /etc/init.d/udev start >/dev/null 2>&1 || die "/etc/init.d/udev start failed!" /etc/init.d/udev stop fi diff --git a/packages/altboot/files/init.altboot b/packages/altboot/files/init.altboot index 7d8b1b6592..a987918760 100644 --- a/packages/altboot/files/init.altboot +++ b/packages/altboot/files/init.altboot @@ -31,14 +31,6 @@ C_BLUE="\033[34m" C_WHITE="\033[37m" C_RESET="\033[0m" -mdie() { - echo "ERROR: $1" >/dev/tty0 - - echo -e "\nPress <ENTER> to return to the menu" - read junk - - test "$junk" = x && exec /bin/sh || exec /sbin/init.altboot -force</dev/tty0 >/dev/tty0 2>&1 -} die() { echo -e "ERROR: $1" >/dev/tty0 @@ -50,77 +42,82 @@ die() { # $1: Directory containing the scripts for the menu-items show_menu() { test -z "$1" && die "DEBUG: Parameter 1 is empty in show_menu" + ! test -d "$1" && die "show_menu: [$1] not found or no directory." + echo "" echo -e "altboot v$VERSION\n" - cnt=0 + m_entry="" - if test -d $1 - then - # Build "m_entry" for scripts in /etc/altboot-menu - cd $1 - for file in `ls -1` - do - if ! test -d "$1/$file" - then - M_TITLE="`$1/$file title`" - if ! test -z "$M_TITLE" - then - let cnt=$cnt+1 - # Keep a list of existing "modules" together with an index number - # This sure is ugly, but Busybox sh doesn't do arrays.... - m_entry="`echo -e "$m_entry\n$cnt:$file\n"`" - echo -e "\t\t[$cnt] $M_TITLE" - fi - M_TITLE="" + # Build "m_entry" for scripts in /etc/altboot-menu + cd $1 + + cnt=0 ; reset_pref "menu_filelist" + for file in `ls -1` + do + if ! test -d "$1/$file" + then + M_TITLE="`$1/$file title`" + if ! test -z "$M_TITLE" + then + let cnt=$cnt+1 + # Keep a list of existing "modules" together with an index number + # This sure is ugly, but Busybox sh doesn't do arrays.... + #m_entry="`echo -e "$m_entry\n$cnt:$file\n"`" + + set_pref "menu_filelist" "$cnt" "$file" + echo -e "\t\t[$cnt] $M_TITLE" fi - done + M_TITLE="" + fi + done - # Display directories below /etc/altboot-menu as menu-item - # and add all scripts inside the directory to m_entry - for dir in `ls -1` - do - if test -d "$1/$dir" - then - M_TITLE="`basename "$1/$dir"`" - if ! test -z "$M_TITLE" - then - let cnt=$cnt+1 - # Keep a list of existing "modules" together with an index number - # This sure is ugly, but Busybox sh doesn't do arrays.... - m_entry="`echo -e "$m_entry\n$cnt:$dir:DIR\n"`" - echo -e "\t\t[$cnt] $M_TITLE" - - OLD_PWD="$PWD" - cd "$1/$dir" - for file in `ls -1` - do - if ! test -d "$1/$dir/$file" - then - M_TITLE="`$1/$dir/$file title`" - if ! test -z "$M_TITLE" - then - let cnt=$cnt+1 - # Keep a list of existing "modules" together with an index number - # This sure is ugly, but Busybox sh doesn't do arrays.... - m_entry="`echo -e "$m_entry\n$cnt:$dir/$file\n"`" - #echo -e "\t\t[$cnt] $M_TITLE" - fi - M_TITLE="" + # Display directories below /etc/altboot-menu as menu-item + # and add all scripts inside the directory to m_entry + for dir in `ls -1` + do + if test -d "$1/$dir" + then + M_TITLE="`basename "$1/$dir"`" + if ! test -z "$M_TITLE" + then + let cnt=$cnt+1 + # Keep a list of existing "modules" together with an index number + # This sure is ugly, but Busybox sh doesn't do arrays.... + #m_entry="`echo -e "$m_entry\n$cnt:$dir:DIR\n"`" + + set_pref "menu_filelist" "$cnt" "$dir:DIR" + echo -e "\t\t[$cnt] $M_TITLE" + + OLD_PWD="$PWD" + cd "$1/$dir" + for file in `ls -1` + do + if ! test -d "$1/$dir/$file" + then + M_TITLE="`$1/$dir/$file title`" + if ! test -z "$M_TITLE" + then + let cnt=$cnt+1 + # Keep a list of existing "modules" together with an index number + # This sure is ugly, but Busybox sh doesn't do arrays.... + #m_entry="`echo -e "$m_entry\n$cnt:$dir/$file\n"`" + + set_pref "menu_filelist" "$cnt" "$dir/$file" + #echo -e "\t\t[$cnt] $M_TITLE" fi - done - cd "$OLD_PWD" + M_TITLE="" + fi + done + cd "$OLD_PWD" - fi - M_TITLE="" fi - done - - - echo "" - else - echo "WARNING: $1 not found" - fi + M_TITLE="" + fi + done + + #echo_pref "menu_filelist" + echo "" } @@ -129,17 +126,17 @@ show_menu() { show_sub_menu() { dirname="`basename "$1"`" - d_entries="`echo "$m_entry"|grep "$dirname/"`" + d_entries="`dump_pref "menu_filelist" | grep "$dirname/"`" -# echo "[$d_entries]" + #echo "[$d_entries]" echo -e "\naltboot v$VERSION: $dirname menu\n" for d_entry in $d_entries do - d_entry_number="`echo "$d_entry"| sed -n "s/\(.*\)\:\(.*\)/\1/p"`" - d_entry_file="`echo "$d_entry"| sed -n "s/\(.*\)\:\(.*\)/\2/p"`" + d_entry_number="`echo "$d_entry"| sed -n "s/\(.*\)\#\#\(.*\)\#\#\#/\1/p"`" + d_entry_file="`echo "$d_entry"| sed -n "s/\(.*\)\#\#\(.*\)\#\#\#/\2/p"`" d_entry_title="`$d_entry_file title`" # echo "number: [$d_entry_number]" @@ -197,6 +194,7 @@ run_timer() { else rm -f /etc/.altboot*.last fi + else launch_altboot=yes fi @@ -208,25 +206,31 @@ launch_selection() { test -z "$1" && die "Parameter 1 of launch_selection is empty!" case "$junk" in - *) file="`echo "$m_entry"| sed -n "/$junk\:/s/^.*\:\(.*\)/\1/p"`" + *) #file="`echo "$m_entry"| sed -n "/$junk\:/s/^.*\:\(.*\)/\1/p"`" + + get_pref "menu_filelist" "$junk" file_ + type="`echo "$file_" | sed -n "s/\(.*\)\:\(.*\)/\2/p"`" + file="`echo "$file_" | sed -n "s/\(.*\)\:\(.*\)/\1/p"`" + test -z "$file" && file="$file_" + + #echo "[$file_]: [$type] / [$file] ($junk)" # The selected menu-item points to a directory - if test "$file" = DIR + if test "$type" = DIR then - dir="`echo "$m_entry"| sed -n "/$junk\:/s/^.*\:\(.*\)\:\(.*\)/\1/p"`" - show_sub_menu /etc/altboot-menu/$dir >/dev/tty0 + show_sub_menu /etc/altboot-menu/$file >/dev/tty0 wait_for_input >/dev/tty0 launch_selection /etc/altboot-menu >/dev/tty0 fi - if test "$file" = MAIN + if test "$type" = MAIN then show_sub_menu /etc/altboot-menu >/dev/tty0 wait_for_input >/dev/tty0 launch_selection /etc/altboot-menu >/dev/tty0 fi - #echo "[$file]" + . $1/$file run "$file" >/dev/tty0 die "WARNING: Using failsafe shell" >/dev/tty0 @@ -257,15 +261,17 @@ wait_for_input() { ( while :; do read x< /dev/tty0 2>&1; done; ) > /dev/null 2>&1 & sleep 1; kill $! >/dev/null 2>&1 fi - - - + echo -n "Please choose one of the above [$last_selection]: " </dev/tty0 > /dev/tty0 2>&1 + stty echo </dev/tty0 >/dev/tty0 2>&1 read junk< /dev/tty0 2>&1 # This filters other chars the user may have used - junk="`echo "$junk" | sed -n "s/.*\([0-9]\)/\1/p"`" + #echo "junk: [$junk]" + junk="`echo "$junk" | sed "s/[a-zA-Z]//g"`" + #echo "junk: [$junk]" + if test "$junk" -lt "$cnt" -o "$junk" -eq "$cnt" then if test ! -z "$junk" @@ -346,9 +352,11 @@ else launch_selection /etc/altboot-menu >/dev/tty0 fi + # Anything after this point will never be reached if $launch_altboot != yes # Show the altboot menu + stty -echo </dev/tty0 >/dev/tty0 2>&1 show_menu /etc/altboot-menu >/dev/tty0 # Load last selection for use as default if <ENTER> is pressed at the prompt |