diff --git a/common/Kconfig b/common/Kconfig index b776031..763983e 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -508,6 +508,7 @@ 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 3ac1d10..8200931 100644 --- a/common/hush.c +++ b/common/hush.c @@ -521,6 +521,8 @@ 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 @@ "hush option parser. 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 ,\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 c5ad73d..4ebda3f 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 @@ 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 0000000..df8750e --- /dev/null +++ b/defaultenv-2/base/bin/bootargs-root-disk @@ -0,0 +1,26 @@ +#!/bin/sh + +usage="$0 [OPTIONS]\n -p \n -t " + +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 4c59625..7072cea 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 (/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 db036da..74d59af 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 " + +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 bf97555..27bb6c4 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 \n -s " + +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 ef89104..fb7f328 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 (root)\n -m " + +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"