diff options
-rw-r--r-- | common/Kconfig | 1 | ||||
-rw-r--r-- | common/hush.c | 5 | ||||
-rw-r--r-- | defaultenv-2/base/bin/boot | 42 | ||||
-rw-r--r-- | defaultenv-2/base/bin/bootargs-root-disk | 26 | ||||
-rw-r--r-- | defaultenv-2/base/bin/bootargs-root-initrd | 7 | ||||
-rw-r--r-- | defaultenv-2/base/bin/bootargs-root-jffs2 | 14 | ||||
-rw-r--r-- | defaultenv-2/base/bin/bootargs-root-nfs | 7 | ||||
-rw-r--r-- | defaultenv-2/base/bin/bootargs-root-ubi | 13 |
8 files changed, 107 insertions, 8 deletions
diff --git a/common/Kconfig b/common/Kconfig index b776031bad..763983e7d5 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -508,6 +508,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW select GLOB_SORT select CMD_GLOBAL select CMD_AUTOMOUNT + select CMD_BASENAME select FLEXIBLE_BOOTARGS prompt "Generic environment template" diff --git a/common/hush.c b/common/hush.c index 3ac1d10195..8200931387 100644 --- a/common/hush.c +++ b/common/hush.c @@ -521,6 +521,8 @@ static int builtin_getopt(struct p_context *ctx, struct child_prog *child, o->optarg = xstrdup(optarg); list_add_tail(&o->list, &ctx->options); } + ctx->global_argv += optind - 1; + ctx->global_argc -= optind - 1; } ctx->options_parsed = 1; @@ -1899,7 +1901,8 @@ static const __maybe_unused char cmd_getopt_help[] = "hush option parser. <optstring> is a string with valid options. Add\n" "a colon to an options if this option has a required argument or two\n" "colons for an optional argument. The current option is saved in <var>,\n" -"arguments are saved in OPTARG.\n"; +"arguments are saved in OPTARG. After this command additional nonopts\n" +"can be accessed starting from $1\n"; BAREBOX_CMD_START(getopt) .cmd = do_getopt, diff --git a/defaultenv-2/base/bin/boot b/defaultenv-2/base/bin/boot index c5ad73dde8..4ebda3f4b2 100644 --- a/defaultenv-2/base/bin/boot +++ b/defaultenv-2/base/bin/boot @@ -1,5 +1,38 @@ #!/bin/sh +verbose= +dryrun= + +usage=" +$0 [OPTIONS] [source]\n + -v verbose\n + -d dryrun\n + -l list boot sources\n + -h help" + +for i in /env/boot/*; do + basename $i s + sources="$sources$s " +done + +while getopt "vdhl" opt; do + if [ ${opt} = v ]; then + if [ -n "$verbose" ]; then + verbose="-v -v" + else + verbose="-v" + fi + elif [ ${opt} = d ]; then + dryrun=1 + elif [ ${opt} = l ]; then + echo -e "boot sources:\n$sources" + exit 0 + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 + fi +done + if [ $# = 0 ]; then scr="$global.boot.default" else @@ -8,11 +41,14 @@ fi if [ -n "$scr" ]; then if [ ! -f /env/boot/$scr ]; then - echo -e "/env/boot/$scr does not exist.\nValid choices:" - ls /env/boot + echo -e "/env/boot/$scr does not exist.Valid choices:\n$sources" exit fi /env/boot/$scr fi -bootm +if [ -n "$dryrun" ]; then + exit 0 +fi + +bootm $verbose diff --git a/defaultenv-2/base/bin/bootargs-root-disk b/defaultenv-2/base/bin/bootargs-root-disk new file mode 100644 index 0000000000..df8750e46d --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-disk @@ -0,0 +1,26 @@ +#!/bin/sh + +usage="$0 [OPTIONS]\n -p <partition>\n -t <fstype>" + +while getopt "p:t:h" opt; do + if [ ${opt} = p ]; then + part=${OPTARG} + elif [ ${opt} = t ]; then + fstype=${OPTARG} + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 + fi +done + +if [ -z "${part}" ]; then + echo "$0: no partition given" + exit 1 +fi + +if [ -z "${fstype}" ]; then + echo "$0: no filesystem type given" + exit 1 +fi + +global.linux.bootargs.root="root=/dev/$part rootfstype=$fstype rootwait" diff --git a/defaultenv-2/base/bin/bootargs-root-initrd b/defaultenv-2/base/bin/bootargs-root-initrd index 4c596252ee..7072cea65b 100644 --- a/defaultenv-2/base/bin/bootargs-root-initrd +++ b/defaultenv-2/base/bin/bootargs-root-initrd @@ -2,9 +2,14 @@ rdinit="/sbin/init" -while getopt "i:" opt; do +usage="$0 [OPTIONS]\n -i <rdinitpath> (/sbin/init)" + +while getopt "i:h" opt; do if [ ${opt} = i ]; then rdinit=${OPTARG} + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 fi done diff --git a/defaultenv-2/base/bin/bootargs-root-jffs2 b/defaultenv-2/base/bin/bootargs-root-jffs2 index db036dac6f..74d59afe39 100644 --- a/defaultenv-2/base/bin/bootargs-root-jffs2 +++ b/defaultenv-2/base/bin/bootargs-root-jffs2 @@ -1,9 +1,21 @@ #!/bin/sh -while getopt "m:" opt; do +mtd= + +usage="$0 [OPTIONS]\n -m <mtd>" + +while getopt "m:h" opt; do if [ ${opt} = m ]; then mtd=${OPTARG} + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 fi done +if [ -z "$mtd" ]; then + echo -e "$usage" + exit 1 +fi + global.linux.bootargs.root="root=$mtd rootfstype=jffs2" diff --git a/defaultenv-2/base/bin/bootargs-root-nfs b/defaultenv-2/base/bin/bootargs-root-nfs index bf97555f44..27bb6c40fa 100644 --- a/defaultenv-2/base/bin/bootargs-root-nfs +++ b/defaultenv-2/base/bin/bootargs-root-nfs @@ -1,10 +1,15 @@ #!/bin/sh -while getopt "n:s:" opt; do +usage="$0 [OPTIONS]\n -n <nfspath>\n -s <serverip>" + +while getopt "n:s:h" opt; do if [ ${opt} = n ]; then nfsroot=${OPTARG} elif [ ${opt} = s ]; then serverip=${OPTARG} + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 fi done diff --git a/defaultenv-2/base/bin/bootargs-root-ubi b/defaultenv-2/base/bin/bootargs-root-ubi index ef891041da..fb7f328bef 100644 --- a/defaultenv-2/base/bin/bootargs-root-ubi +++ b/defaultenv-2/base/bin/bootargs-root-ubi @@ -1,13 +1,24 @@ #!/bin/sh ubiroot=root +mtd= -while getopt "m:r:" opt; do +usage="$0 [OPTIONS]\n -r <ubiroot> (root)\n -m <mtd>" + +while getopt "m:r:h" opt; do if [ ${opt} = r ]; then ubiroot=${OPTARG} elif [ ${opt} = m ]; then mtd=${OPTARG} + elif [ ${opt} = h ]; then + echo -e "$usage" + exit 0 fi done +if [ -z "$mtd" ]; then + echo -e "$usage" + exit 1 +fi + global.linux.bootargs.root="root=ubi0:$ubiroot ubi.mtd=$mtd rootfstype=ubifs" |