9
0
Fork 0

defaultenv-2: add boot sequence

This allows to boot a sequence of boot entries until one succeeds.

boot sources can be passed in $global.boot.default, which is now treated
as a list. Also a list of boot entries can be specified as arguments
to the boot script. The entries can be:

- a plain filename from /env/boot/
- a full path to an arbitrary file
- a directory containing boot entries

With this this command:

boot net nand-ubi /env/boot.d

would first use the /env/boot/net entry, if this fails the /env/boot/nand-ubi
entry and if this also fails the files from /env/boot.d/ (which could also
be links to boot scripts)

To make the above the default, global.boot.default would be specified as:

global.boot.default="net nand-ubi /env/boot.d"

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2013-02-18 19:44:24 +01:00 committed by Sascha Hauer
parent 94e71b843f
commit 8be08d9cf2
6 changed files with 119 additions and 35 deletions

View File

@ -532,6 +532,8 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
select CMD_GLOBAL
select CMD_AUTOMOUNT
select CMD_BASENAME
select CMD_READLINK
select CMD_DIRNAME
select FLEXIBLE_BOOTARGS
prompt "Generic environment template"

View File

@ -0,0 +1,44 @@
#!/bin/sh
# The real boot script, to be called from _boot_list which is called
# from boot
. /env/data/ansi-colors
# clear linux.bootargs.dyn.* and bootm.*
global -r linux.bootargs.dyn.
global -r bootm.
file="$1"
scr=/env/boot/$file
if [ ! -f "$scr" ]; then
scr="$file"
fi
if [ ! -f "$scr" ]; then
echo -e "${RED}/env/boot/${file}${NC} or ${RED}${file}${NC} do not exist"
_boot_help
exit 2
fi
if [ -L $scr ]; then
readlink -f $scr boot
basename $boot link
basename $scr boot
echo -e "${GREEN}boot${NC} ${YELLOW}${boot}${NC} -> ${CYAN}${link}${NC}"
else
echo -e "${GREEN}booting ${YELLOW}$file${NC}..."
fi
$scr
if [ -n "$BOOT_DRYRUN" ]; then
echo "dryrun. exiting now"
exit 0
fi
${global.bootm.image} $BOOT_BOOTM_OPTS
bootm $BOOT_BOOTM_OPTS
echo -e "${GREEN}booting ${YELLOW}$file${NC} ${RED}failed${NC}"

View File

@ -0,0 +1,20 @@
#!/bin/sh
for i in /env/boot/*; do
basename $i s
sources="$sources$s "
done
if [ -d /env/boot.d ]; then
seq_sources="boot sequence:"
for i in /env/boot.d/*; do
readlink -f $i s
basename $s link
basename $i s
seq_sources="$seq_sources\n ${YELLOW}${s}${NC} -> ${CYAN}${link}${NC}"
done
else
seq_sources="boot sequence:\n${GREEN}none${NC}"
fi
echo -e "boot sources:\n$sources\n\n$seq_sources"

View File

@ -0,0 +1,7 @@
#!/bin/sh
# This script is a workaround for buggy globbing in for loops
for i in $*; do
_boot $i;
done

View File

@ -1,7 +1,10 @@
#!/bin/sh
verbose=
dryrun=
BOOT_BOOTM_OPTS=
BOOT_DRYRUN=
BOOT_VERBOSE=
list=
bootsrc=${global.boot.default}
usage="
$0 [OPTIONS] [source]\n
@ -10,49 +13,53 @@ $0 [OPTIONS] [source]\n
-l list boot sources\n
-h help"
for i in /env/boot/*; do
basename $i s
sources="$sources$s "
done
. /env/data/ansi-colors
while getopt "vdhl" opt; do
if [ ${opt} = v ]; then
if [ -n "$verbose" ]; then
verbose="-v -v"
else
verbose="-v"
fi
BOOT_BOOTMOPTS="$BOOT_BOOTMOPTS -v"
BOOT_VERBOSE=1
elif [ ${opt} = d ]; then
dryrun=1
BOOT_DRYRUN=1
elif [ ${opt} = l ]; then
echo -e "boot sources:\n$sources"
exit 0
list=1
elif [ ${opt} = h ]; then
echo -e "$usage"
exit 0
fi
done
# clear linux.bootargs.dyn.* and bootm.*
global -r linux.bootargs.dyn.
global -r bootm.
if [ $# = 0 ]; then
scr="$global.boot.default"
else
scr="$1"
fi
if [ -n "$scr" ]; then
if [ ! -f /env/boot/$scr ]; then
echo -e "/env/boot/$scr does not exist. Valid choices:\n$sources"
exit
fi
/env/boot/$scr
fi
if [ -n "$dryrun" ]; then
if [ -n "$list" ]; then
echo "boot sources:"
for i in /env/boot/*; do
basename $i s
echo $s
done
exit 0
fi
bootm $verbose
if [ -n "$1" ]; then
bootsrc="$*"
fi
export BOOT_BOOTM_OPTS
export BOOT_DRYRUN
export BOOT_VERBOSE
for src in $bootsrc; do
if [ -d ${src} ]; then
realsrc="$realsrc $src/*"
else
realsrc="$realsrc $src"
fi
done
if [ -n "$BOOT_VERBOSE" ]; then
echo -e "\nboot sequence:${YELLOW}$realsrc${NC}\n"
fi
for s in $realsrc; do
_boot_list $s
done
exit $ret

View File

@ -14,7 +14,11 @@
# timeout in seconds before the default boot entry is started
#global.autoboot_timeout=3
# default boot entry (one of /env/boot/*)
# list of boot entries. These are executed in order until one
# succeeds. An entry can be:
# - a filename in /env/boot/
# - a full path to a directory. All files in this directory are
# treated as boot files and executed in alphabetical order
#global.boot.default=net
# base bootargs