mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] defenv-2 updates
@ 2012-07-05  7:18 Sascha Hauer
  2012-07-05  7:18 ` [PATCH 1/3] hush getopt: shift argv arguments Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-07-05  7:18 UTC (permalink / raw)
  To: barebox

Hi all,

The following contains some defenv-2 updates like more usage informations
for the scripts and it makes the boot script a bit more flexible.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      hush getopt: shift argv arguments
      defenv-2: Add usage information for bootargs scripts
      defenv-2: improve boot script

 common/Kconfig                             |    1 +
 common/hush.c                              |    5 +++-
 defaultenv-2/base/bin/boot                 |   42 ++++++++++++++++++++++++++--
 defaultenv-2/base/bin/bootargs-root-initrd |    7 ++++-
 defaultenv-2/base/bin/bootargs-root-jffs2  |   16 ++++++++++-
 defaultenv-2/base/bin/bootargs-root-nfs    |    7 ++++-
 defaultenv-2/base/bin/bootargs-root-ubi    |   13 ++++++++-
 7 files changed, 83 insertions(+), 8 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] hush getopt: shift argv arguments
  2012-07-05  7:18 [PATCH] defenv-2 updates Sascha Hauer
@ 2012-07-05  7:18 ` Sascha Hauer
  2012-07-05  7:18 ` [PATCH 2/3] defenv-2: Add usage information for bootargs scripts Sascha Hauer
  2012-07-05  7:18 ` [PATCH 3/3] defenv-2: improve boot script Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-07-05  7:18 UTC (permalink / raw)
  To: barebox

Make the nonopt arguments to a script available starting from $1
after running getopt. This allows for scripts which use option
parsing but also have nonopts.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/hush.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 @@ 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,
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] defenv-2: Add usage information for bootargs scripts
  2012-07-05  7:18 [PATCH] defenv-2 updates Sascha Hauer
  2012-07-05  7:18 ` [PATCH 1/3] hush getopt: shift argv arguments Sascha Hauer
@ 2012-07-05  7:18 ` Sascha Hauer
  2012-07-05  7:22   ` Eric Bénard
  2012-07-05  7:18 ` [PATCH 3/3] defenv-2: improve boot script Sascha Hauer
  2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2012-07-05  7:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 defaultenv-2/base/bin/bootargs-root-initrd |    7 ++++++-
 defaultenv-2/base/bin/bootargs-root-jffs2  |   16 +++++++++++++++-
 defaultenv-2/base/bin/bootargs-root-nfs    |    7 ++++++-
 defaultenv-2/base/bin/bootargs-root-ubi    |   13 ++++++++++++-
 4 files changed, 39 insertions(+), 4 deletions(-)

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 <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 db036da..ac9a4bd 100644
--- a/defaultenv-2/base/bin/bootargs-root-jffs2
+++ b/defaultenv-2/base/bin/bootargs-root-jffs2
@@ -1,9 +1,23 @@
 #!/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
 
+echo "huhu; $1"
+
+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 <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 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 <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"
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] defenv-2: improve boot script
  2012-07-05  7:18 [PATCH] defenv-2 updates Sascha Hauer
  2012-07-05  7:18 ` [PATCH 1/3] hush getopt: shift argv arguments Sascha Hauer
  2012-07-05  7:18 ` [PATCH 2/3] defenv-2: Add usage information for bootargs scripts Sascha Hauer
@ 2012-07-05  7:18 ` Sascha Hauer
  2 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-07-05  7:18 UTC (permalink / raw)
  To: barebox

- add usage information
- add option parsing:
  -v verbose
  -v -v more verbose
  -l list b´possible boot sources
  -d dryrun

The dryrun option sets the global variables necessary for booting
but does not actually boot the system. This way it is possible to
make additional adjustments to the boot variables and then invoke
bootm manually.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig             |    1 +
 defaultenv-2/base/bin/boot |   42 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index b776031..763983e 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/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 @@ 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
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] defenv-2: Add usage information for bootargs scripts
  2012-07-05  7:18 ` [PATCH 2/3] defenv-2: Add usage information for bootargs scripts Sascha Hauer
@ 2012-07-05  7:22   ` Eric Bénard
  2012-07-05  7:35     ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Bénard @ 2012-07-05  7:22 UTC (permalink / raw)
  To: barebox

Hi Sascha,

Le Thu,  5 Jul 2012 09:18:39 +0200,
Sascha Hauer <s.hauer@pengutronix.de> a écrit :

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  defaultenv-2/base/bin/bootargs-root-initrd |    7 ++++++-
>  defaultenv-2/base/bin/bootargs-root-jffs2  |   16 +++++++++++++++-
>  defaultenv-2/base/bin/bootargs-root-nfs    |    7 ++++++-
>  defaultenv-2/base/bin/bootargs-root-ubi    |   13 ++++++++++++-
>  4 files changed, 39 insertions(+), 4 deletions(-)
> 
> 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 <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 db036da..ac9a4bd 100644
> --- a/defaultenv-2/base/bin/bootargs-root-jffs2
> +++ b/defaultenv-2/base/bin/bootargs-root-jffs2
> @@ -1,9 +1,23 @@
>  #!/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
>  
> +echo "huhu; $1"

is that huhu expected here ? ;-)

Eric

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] defenv-2: Add usage information for bootargs scripts
  2012-07-05  7:22   ` Eric Bénard
@ 2012-07-05  7:35     ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-07-05  7:35 UTC (permalink / raw)
  To: Eric Bénard; +Cc: barebox

Hi Eric,

On Thu, Jul 05, 2012 at 09:22:47AM +0200, Eric Bénard wrote:
> Hi Sascha,
> 
> Le Thu,  5 Jul 2012 09:18:39 +0200,
> Sascha Hauer <s.hauer@pengutronix.de> a écrit :
> 
> > +while getopt "m:h" opt; do
> >  	if [ ${opt} = m ]; then
> >  		mtd=${OPTARG}
> > +	elif [ ${opt} = h ]; then
> > +		echo -e "$usage"
> > +		exit 0
> >  	fi
> >  done
> >  
> > +echo "huhu; $1"
> 
> is that huhu expected here ? ;-)

Just to check if someone actually reads my patches ;)

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-07-05  7:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-05  7:18 [PATCH] defenv-2 updates Sascha Hauer
2012-07-05  7:18 ` [PATCH 1/3] hush getopt: shift argv arguments Sascha Hauer
2012-07-05  7:18 ` [PATCH 2/3] defenv-2: Add usage information for bootargs scripts Sascha Hauer
2012-07-05  7:22   ` Eric Bénard
2012-07-05  7:35     ` Sascha Hauer
2012-07-05  7:18 ` [PATCH 3/3] defenv-2: improve boot script Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox