diff --git a/common/Kconfig b/common/Kconfig index 3a55e01..683460b 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -532,6 +532,8 @@ select CMD_GLOBAL select CMD_AUTOMOUNT select CMD_BASENAME + select CMD_READLINK + select CMD_DIRNAME select FLEXIBLE_BOOTARGS prompt "Generic environment template" diff --git a/defaultenv-2/base/bin/_boot b/defaultenv-2/base/bin/_boot new file mode 100644 index 0000000..71d1490 --- /dev/null +++ b/defaultenv-2/base/bin/_boot @@ -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}" diff --git a/defaultenv-2/base/bin/_boot_help b/defaultenv-2/base/bin/_boot_help new file mode 100644 index 0000000..5679e91 --- /dev/null +++ b/defaultenv-2/base/bin/_boot_help @@ -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" diff --git a/defaultenv-2/base/bin/_boot_list b/defaultenv-2/base/bin/_boot_list new file mode 100644 index 0000000..17f29bf --- /dev/null +++ b/defaultenv-2/base/bin/_boot_list @@ -0,0 +1,7 @@ +#!/bin/sh + +# This script is a workaround for buggy globbing in for loops + +for i in $*; do + _boot $i; +done diff --git a/defaultenv-2/base/bin/boot b/defaultenv-2/base/bin/boot index ebbd951..f7f460e 100644 --- a/defaultenv-2/base/bin/boot +++ b/defaultenv-2/base/bin/boot @@ -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 @@ -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 diff --git a/defaultenv-2/base/config b/defaultenv-2/base/config index dec0595..784ae52 100644 --- a/defaultenv-2/base/config +++ b/defaultenv-2/base/config @@ -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