[PATCH 3/3] defenv-2: improve boot script

Sascha Hauer s.hauer at pengutronix.de
Thu Jul 5 03:18:40 EDT 2012


- 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 at 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




More information about the barebox mailing list