mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Bootm patches
@ 2013-09-24  7:08 Sascha Hauer
  2013-09-24  7:08 ` [PATCH 01/11] bootm: fix possible memory leak Sascha Hauer
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

The following contains some memory leak fixes and cleanups for bootm,
but more important: The conversion of the current defenv-2 'boot' script
to a command with the same semantics.

Motivation for doing this was that the current shell script(s) are already
stretched to the limits we can handle with our limited shell. The C code
instead looks rather simple and can be further extended. One of these
extensions will come very soon in the form of the bootloader spec:
http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/
So this series is mainly a preparation for it.

Sascha

----------------------------------------------------------------
Sascha Hauer (11):
      bootm: fix possible memory leak
      bootm: fix memory leak
      bootm: check for os image file
      bootm: remove unused define
      bootm: move getenv_loadaddr from command to common
      bootm: move globalvars from command to common
      bootm: separate bootm input data and internal data
      bootm: Add dryrun support
      ARM: compile bootm code depending on CONFIG_BOOTM
      command: Let builtin command take precedence
      defenv-2: replace boot script with command

 arch/arm/Kconfig                 |   2 +-
 arch/arm/lib/Makefile            |   2 +-
 commands/Kconfig                 |  11 ++
 commands/Makefile                |   1 +
 commands/boot.c                  | 258 +++++++++++++++++++++++++++++++++++++++
 commands/bootm.c                 |  81 +++---------
 common/Kconfig                   |   1 +
 common/binfmt.c                  |   5 +-
 common/bootm.c                   |  87 ++++++++++++-
 defaultenv-2/base/bin/_boot      |  44 -------
 defaultenv-2/base/bin/_boot_help |  20 ---
 defaultenv-2/base/bin/_boot_list |   7 --
 defaultenv-2/base/bin/boot       |  65 ----------
 include/boot.h                   |  18 ++-
 14 files changed, 395 insertions(+), 207 deletions(-)
 create mode 100644 commands/boot.c
 delete mode 100644 defaultenv-2/base/bin/_boot
 delete mode 100644 defaultenv-2/base/bin/_boot_help
 delete mode 100644 defaultenv-2/base/bin/_boot_list
 delete mode 100644 defaultenv-2/base/bin/boot

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

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

* [PATCH 01/11] bootm: fix possible memory leak
  2013-09-24  7:08 Bootm patches Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 02/11] bootm: fix " Sascha Hauer
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

fdt is allocated, free it in error case.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/bootm.c b/common/bootm.c
index 1987a09..1ddc6d2 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -167,6 +167,7 @@ static int bootm_open_oftree(struct image_data *data, const char *oftree, int nu
 	data->of_root_node = of_unflatten_dtb(NULL, fdt);
 	if (!data->of_root_node) {
 		pr_err("unable to unflatten devicetree\n");
+		free(fdt);
 		return -EINVAL;
 	}
 
-- 
1.8.4.rc3


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

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

* [PATCH 02/11] bootm: fix memory leak
  2013-09-24  7:08 Bootm patches Sascha Hauer
  2013-09-24  7:08 ` [PATCH 01/11] bootm: fix possible memory leak Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 03/11] bootm: check for os image file Sascha Hauer
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

data->of_root_node may be allocated from of of_unflatten_dtb.
Free it in this case.

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

diff --git a/common/bootm.c b/common/bootm.c
index 1ddc6d2..14b4cff 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -299,6 +299,8 @@ err_out:
 		uimage_close(data->initrd);
 	if (data->os)
 		uimage_close(data->os);
+	if (data->of_root_node && data->of_root_node != of_get_root_node())
+		of_delete_node(data->of_root_node);
 
 	return ret;
 }
-- 
1.8.4.rc3


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

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

* [PATCH 03/11] bootm: check for os image file
  2013-09-24  7:08 Bootm patches Sascha Hauer
  2013-09-24  7:08 ` [PATCH 01/11] bootm: fix possible memory leak Sascha Hauer
  2013-09-24  7:08 ` [PATCH 02/11] bootm: fix " Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 04/11] bootm: remove unused define Sascha Hauer
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

Check if an os image file has been given.

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

diff --git a/common/bootm.c b/common/bootm.c
index 14b4cff..f7e4f9a 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -210,6 +210,11 @@ int bootm_boot(struct image_data *data)
 	int ret;
 	enum filetype os_type, initrd_type = filetype_unknown;
 
+	if (!data->os_file) {
+		printf("no image given\n");
+		return -ENOENT;
+	}
+
 	os_type = file_name_detect_type(data->os_file);
 	if ((int)os_type < 0) {
 		printf("could not open %s: %s\n", data->os_file,
-- 
1.8.4.rc3


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

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

* [PATCH 04/11] bootm: remove unused define
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 03/11] bootm: check for os image file Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 05/11] bootm: move getenv_loadaddr from command to common Sascha Hauer
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

OFTREE_SIZE_INCREASE isn't used anymore.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index a4004df..8ce4867 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -46,11 +46,6 @@
 #include <magicvar.h>
 #include <asm-generic/memory_layout.h>
 
-/*
- * Additional oftree size for the fixed tree
- */
-#define OFTREE_SIZE_INCREASE	0x8000
-
 static char *bootm_image_name_and_no(const char *name, int *no)
 {
 	char *at, *ret;
-- 
1.8.4.rc3


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

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

* [PATCH 05/11] bootm: move getenv_loadaddr from command to common
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 04/11] bootm: remove unused define Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 06/11] bootm: move globalvars " Sascha Hauer
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

getenv_loadaddr may be used by other code, so move it
from command/ to common/

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c | 13 -------------
 common/bootm.c   | 13 +++++++++++++
 include/boot.h   |  2 ++
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 8ce4867..c1d2ec4 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -75,19 +75,6 @@ static char *bootm_image_name_and_no(const char *name, int *no)
 #define BOOTM_OPTS BOOTM_OPTS_COMMON
 #endif
 
-unsigned long long getenv_loadaddr(const char *name)
-{
-	const char *valstr = getenv(name);
-
-	if (!valstr)
-		return UIMAGE_SOME_ADDRESS;
-
-	if (valstr[0] == '\0')
-		return UIMAGE_SOME_ADDRESS;
-
-	return simple_strtoull(valstr, NULL, 0);
-}
-
 static int do_bootm(int argc, char *argv[])
 {
 	int opt;
diff --git a/common/bootm.c b/common/bootm.c
index f7e4f9a..6b2c2a6 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -26,6 +26,19 @@ int register_image_handler(struct image_handler *handler)
 	return 0;
 }
 
+unsigned long long getenv_loadaddr(const char *name)
+{
+	const char *valstr = getenv(name);
+
+	if (!valstr)
+		return UIMAGE_SOME_ADDRESS;
+
+	if (valstr[0] == '\0')
+		return UIMAGE_SOME_ADDRESS;
+
+	return simple_strtoull(valstr, NULL, 0);
+}
+
 static struct image_handler *bootm_find_handler(enum filetype filetype,
 		struct image_data *data)
 {
diff --git a/include/boot.h b/include/boot.h
index ccce8e1..8d42d39 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -96,4 +96,6 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
 
 int bootm_boot(struct image_data *);
 
+unsigned long long getenv_loadaddr(const char *name);
+
 #endif /* __BOOT_H */
-- 
1.8.4.rc3


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

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

* [PATCH 06/11] bootm: move globalvars from command to common
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 05/11] bootm: move getenv_loadaddr from command to common Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 07/11] bootm: separate bootm input data and internal data Sascha Hauer
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

The globalvars should be available even if the bootm command
is not directly present.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c | 14 --------------
 common/bootm.c   | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index c1d2ec4..005d582 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -158,20 +158,6 @@ err_out:
 	return 1;
 }
 
-static int bootm_init(void)
-{
-	globalvar_add_simple("bootm.image", NULL);
-	globalvar_add_simple("bootm.image.loadaddr", NULL);
-	globalvar_add_simple("bootm.oftree", NULL);
-	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD)) {
-		globalvar_add_simple("bootm.initrd", NULL);
-		globalvar_add_simple("bootm.initrd.loadaddr", NULL);
-	}
-
-	return 0;
-}
-late_initcall(bootm_init);
-
 BAREBOX_CMD_HELP_START(bootm)
 BAREBOX_CMD_HELP_USAGE("bootm [OPTIONS] image\n")
 BAREBOX_CMD_HELP_SHORT("Boot an application image.\n")
diff --git a/common/bootm.c b/common/bootm.c
index 6b2c2a6..259feac 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -16,6 +16,8 @@
 #include <fs.h>
 #include <malloc.h>
 #include <memory.h>
+#include <globalvar.h>
+#include <init.h>
 
 static LIST_HEAD(handler_list);
 
@@ -322,3 +324,17 @@ err_out:
 
 	return ret;
 }
+
+static int bootm_init(void)
+{
+	globalvar_add_simple("bootm.image", NULL);
+	globalvar_add_simple("bootm.image.loadaddr", NULL);
+	globalvar_add_simple("bootm.oftree", NULL);
+	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD)) {
+		globalvar_add_simple("bootm.initrd", NULL);
+		globalvar_add_simple("bootm.initrd.loadaddr", NULL);
+	}
+
+	return 0;
+}
+late_initcall(bootm_init);
-- 
1.8.4.rc3


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

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

* [PATCH 07/11] bootm: separate bootm input data and internal data
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 06/11] bootm: move globalvars " Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 08/11] bootm: Add dryrun support Sascha Hauer
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

We used to use struct image_data as the central data structure for bootm and
also as the input data structure. This makes it unclear which of the fields
are actually input data. This patch creates a struct bootm_data which is
exclusively used for input data to make usage clearer.

Also it moves the dispatching of multifile uImage pathnames to the core bootm
code so that the core code gets more flexible and the command code simpler.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c | 34 ++++------------------------------
 common/bootm.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 include/boot.h   | 16 ++++++++++++++--
 3 files changed, 62 insertions(+), 34 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 005d582..927c2fb 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -46,27 +46,6 @@
 #include <magicvar.h>
 #include <asm-generic/memory_layout.h>
 
-static char *bootm_image_name_and_no(const char *name, int *no)
-{
-	char *at, *ret;
-
-	if (!name || !*name)
-		return NULL;
-
-	*no = 0;
-
-	ret = xstrdup(name);
-	at = strchr(ret, '@');
-	if (!at)
-		return ret;
-
-	*at++ = 0;
-
-	*no = simple_strtoul(at, NULL, 10);
-
-	return ret;
-}
-
 #define BOOTM_OPTS_COMMON "ca:e:vo:f"
 
 #ifdef CONFIG_CMD_BOOTM_INITRD
@@ -78,12 +57,10 @@ static char *bootm_image_name_and_no(const char *name, int *no)
 static int do_bootm(int argc, char *argv[])
 {
 	int opt;
-	struct image_data data;
+	struct bootm_data data = {};
 	int ret = 1;
 	const char *oftree = NULL, *initrd_file = NULL, *os_file = NULL;
 
-	memset(&data, 0, sizeof(struct image_data));
-
 	data.initrd_address = UIMAGE_INVALID_ADDRESS;
 	data.os_address = UIMAGE_SOME_ADDRESS;
 	data.verify = 0;
@@ -143,18 +120,15 @@ static int do_bootm(int argc, char *argv[])
 	if (oftree && !*oftree)
 		oftree = NULL;
 
-	data.os_file = bootm_image_name_and_no(os_file, &data.os_num);
-	data.oftree_file = bootm_image_name_and_no(oftree, &data.oftree_num);
-	data.initrd_file = bootm_image_name_and_no(initrd_file, &data.initrd_num);
+	data.os_file = os_file;
+	data.oftree_file = oftree;
+	data.initrd_file = initrd_file;
 
 	ret = bootm_boot(&data);
 
 	printf("handler failed with %s\n", strerror(-ret));
 
 err_out:
-	free(data.initrd_file);
-	free(data.os_file);
-
 	return 1;
 }
 
diff --git a/common/bootm.c b/common/bootm.c
index 259feac..3c5689b 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -219,17 +219,54 @@ static void bootm_print_info(struct image_data *data)
 	}
 }
 
-int bootm_boot(struct image_data *data)
+static char *bootm_image_name_and_no(const char *name, int *no)
 {
+	char *at, *ret;
+
+	if (!name || !*name)
+		return NULL;
+
+	*no = 0;
+
+	ret = xstrdup(name);
+	at = strchr(ret, '@');
+	if (!at)
+		return ret;
+
+	*at++ = 0;
+
+	*no = simple_strtoul(at, NULL, 10);
+
+	return ret;
+}
+
+/*
+ * bootm_boot - Boot an application image described by bootm_data
+ */
+int bootm_boot(struct bootm_data *bootm_data)
+{
+	struct image_data *data;
 	struct image_handler *handler;
 	int ret;
 	enum filetype os_type, initrd_type = filetype_unknown;
 
-	if (!data->os_file) {
+	if (!bootm_data->os_file) {
 		printf("no image given\n");
 		return -ENOENT;
 	}
 
+	data = xzalloc(sizeof(*data));
+
+	data->os_file = bootm_image_name_and_no(bootm_data->os_file, &data->os_num);
+	data->oftree_file = bootm_image_name_and_no(bootm_data->oftree_file, &data->oftree_num);
+	data->initrd_file = bootm_image_name_and_no(bootm_data->initrd_file, &data->initrd_num);
+	data->verbose = bootm_data->verbose;
+	data->verify = bootm_data->verify;
+	data->force = bootm_data->force;
+	data->initrd_address = bootm_data->initrd_address;
+	data->os_address = bootm_data->os_address;
+	data->os_entry = bootm_data->os_entry;
+
 	os_type = file_name_detect_type(data->os_file);
 	if ((int)os_type < 0) {
 		printf("could not open %s: %s\n", data->os_file,
@@ -322,6 +359,11 @@ err_out:
 	if (data->of_root_node && data->of_root_node != of_get_root_node())
 		of_delete_node(data->of_root_node);
 
+	free(data->os_file);
+	free(data->oftree_file);
+	free(data->initrd_file);
+	free(data);
+
 	return ret;
 }
 
diff --git a/include/boot.h b/include/boot.h
index 8d42d39..3bb55e7 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -7,6 +7,20 @@
 #include <linux/list.h>
 #include <environment.h>
 
+struct bootm_data {
+	const char *os_file;
+	const char *initrd_file;
+	const char *oftree_file;
+	int verbose;
+	bool verify;
+	bool force;
+	unsigned long initrd_address;
+	unsigned long os_address;
+	unsigned long os_entry;
+};
+
+int bootm_boot(struct bootm_data *data);
+
 struct image_data {
 	/* simplest case. barebox has already loaded the os here */
 	struct resource *os_res;
@@ -94,8 +108,6 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
 
 #define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
 
-int bootm_boot(struct image_data *);
-
 unsigned long long getenv_loadaddr(const char *name);
 
 #endif /* __BOOT_H */
-- 
1.8.4.rc3


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

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

* [PATCH 08/11] bootm: Add dryrun support
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 07/11] bootm: separate bootm input data and internal data Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 09/11] ARM: compile bootm code depending on CONFIG_BOOTM Sascha Hauer
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

This adds support for checking the bootm command without actually booting.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/bootm.c | 15 ++++++++++++---
 common/bootm.c   |  6 +++++-
 include/boot.h   |  2 ++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/commands/bootm.c b/commands/bootm.c
index 927c2fb..44facd4 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -46,7 +46,7 @@
 #include <magicvar.h>
 #include <asm-generic/memory_layout.h>
 
-#define BOOTM_OPTS_COMMON "ca:e:vo:f"
+#define BOOTM_OPTS_COMMON "ca:e:vo:fd"
 
 #ifdef CONFIG_CMD_BOOTM_INITRD
 #define BOOTM_OPTS BOOTM_OPTS_COMMON "L:r:"
@@ -101,6 +101,9 @@ static int do_bootm(int argc, char *argv[])
 		case 'f':
 			data.force = 1;
 			break;
+		case 'd':
+			data.dryrun = 1;
+			break;
 		default:
 			break;
 		}
@@ -125,17 +128,23 @@ static int do_bootm(int argc, char *argv[])
 	data.initrd_file = initrd_file;
 
 	ret = bootm_boot(&data);
+	if (ret) {
+		printf("handler failed with: %s\n", strerror(-ret));
+		goto err_out;
+	}
 
-	printf("handler failed with %s\n", strerror(-ret));
+	if (data.dryrun)
+		printf("Dryrun. Aborted\n");
 
 err_out:
-	return 1;
+	return ret ? 1 : 0;
 }
 
 BAREBOX_CMD_HELP_START(bootm)
 BAREBOX_CMD_HELP_USAGE("bootm [OPTIONS] image\n")
 BAREBOX_CMD_HELP_SHORT("Boot an application image.\n")
 BAREBOX_CMD_HELP_OPT  ("-c",  "crc check uImage data\n")
+BAREBOX_CMD_HELP_OPT  ("-d",  "dryrun. Check data, but do not run\n")
 #ifdef CONFIG_CMD_BOOTM_INITRD
 BAREBOX_CMD_HELP_OPT  ("-r <initrd>","specify an initrd image\n")
 BAREBOX_CMD_HELP_OPT  ("-L <load addr>","specify initrd load address\n")
diff --git a/common/bootm.c b/common/bootm.c
index 3c5689b..a431dff 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -263,6 +263,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 	data->verbose = bootm_data->verbose;
 	data->verify = bootm_data->verify;
 	data->force = bootm_data->force;
+	data->dryrun = bootm_data->dryrun;
 	data->initrd_address = bootm_data->initrd_address;
 	data->os_address = bootm_data->os_address;
 	data->os_entry = bootm_data->os_entry;
@@ -346,7 +347,10 @@ int bootm_boot(struct bootm_data *bootm_data)
 		printf("Passing control to %s handler\n", handler->name);
 	}
 
-	ret = handler->bootm(data);
+	if (data->dryrun)
+		ret = 0;
+	else
+		ret = handler->bootm(data);
 err_out:
 	if (data->os_res)
 		release_sdram_region(data->os_res);
diff --git a/include/boot.h b/include/boot.h
index 3bb55e7..84b4fd0 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -14,6 +14,7 @@ struct bootm_data {
 	int verbose;
 	bool verify;
 	bool force;
+	bool dryrun;
 	unsigned long initrd_address;
 	unsigned long os_address;
 	unsigned long os_entry;
@@ -64,6 +65,7 @@ struct image_data {
 	int verify;
 	int verbose;
 	int force;
+	int dryrun;
 };
 
 struct image_handler {
-- 
1.8.4.rc3


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

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

* [PATCH 09/11] ARM: compile bootm code depending on CONFIG_BOOTM
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (7 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 08/11] bootm: Add dryrun support Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 10/11] command: Let builtin command take precedence Sascha Hauer
  2013-09-24  7:08 ` [PATCH 11/11] defenv-2: replace boot script with command Sascha Hauer
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

The bootm code is now independent from the actual bootm command, so
compile the ARM specific bootm code based on CONFIG_BOOTM and not on
CONFIG_CMD_BOOTM.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/Kconfig      | 2 +-
 arch/arm/lib/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 687acca..38116be 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -10,7 +10,7 @@ config ARM
 config ARM_LINUX
 	bool
 	default y
-	depends on CMD_BOOTZ || CMD_BOOTU || CMD_BOOTM
+	depends on CMD_BOOTZ || CMD_BOOTU || BOOTM
 
 config HAVE_MACH_ARM_HEAD
 	bool
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 3ea695c..a328795 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_ARM_LINUX)	+= armlinux.o
-obj-$(CONFIG_CMD_BOOTM)	+= bootm.o
+obj-$(CONFIG_BOOTM)	+= bootm.o
 obj-$(CONFIG_CMD_BOOTZ)	+= bootz.o
 obj-$(CONFIG_CMD_BOOTU)	+= bootu.o
 obj-y	+= div0.o
-- 
1.8.4.rc3


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

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

* [PATCH 10/11] command: Let builtin command take precedence
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (8 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 09/11] ARM: compile bootm code depending on CONFIG_BOOTM Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  2013-09-24  7:08 ` [PATCH 11/11] defenv-2: replace boot script with command Sascha Hauer
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

In theory we can overwrite a builtin command with a script. However,
I don't know a single case where this has been done. Scripts are
often more unflexible than commands so it's unlikely that a script
can extend the functionality of a builtin command. Moreover, the
internal command is no longer accessible once it's overwritten by
a script.

Invert this logic so that a builtin command can overwrite an existing
script. This will help when the 'boot' script is converted to a
builting command. Then with old environments the builtin command will
be used instead of the script.

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

diff --git a/common/binfmt.c b/common/binfmt.c
index 7dcf5d7..f2ff624 100644
--- a/common/binfmt.c
+++ b/common/binfmt.c
@@ -60,6 +60,9 @@ int execute_binfmt(int argc, char **argv)
 	if (strchr(argv[0], '/'))
 		return binfmt_run(argv[0], argc, argv);
 
+	if (find_cmd(argv[0]))
+		return execute_command(argc, &argv[0]);
+
 	path = find_execable(argv[0]);
 	if (path) {
 		ret = binfmt_run(path, argc, argv);
@@ -67,7 +70,7 @@ int execute_binfmt(int argc, char **argv)
 		return ret;
 	}
 
-	return execute_command(argc, &argv[0]);
+	return -ENOENT;
 }
 
 int binfmt_register(struct binfmt_hook *b)
-- 
1.8.4.rc3


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

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

* [PATCH 11/11] defenv-2: replace boot script with command
  2013-09-24  7:08 Bootm patches Sascha Hauer
                   ` (9 preceding siblings ...)
  2013-09-24  7:08 ` [PATCH 10/11] command: Let builtin command take precedence Sascha Hauer
@ 2013-09-24  7:08 ` Sascha Hauer
  10 siblings, 0 replies; 12+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:08 UTC (permalink / raw)
  To: barebox

This replaces the 'boot' script in the defaultenv-2 with a command
with the same behaviour. A command gives more flexibility for future
externsions

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/Kconfig                 |  11 ++
 commands/Makefile                |   1 +
 commands/boot.c                  | 258 +++++++++++++++++++++++++++++++++++++++
 common/Kconfig                   |   1 +
 defaultenv-2/base/bin/_boot      |  44 -------
 defaultenv-2/base/bin/_boot_help |  20 ---
 defaultenv-2/base/bin/_boot_list |   7 --
 defaultenv-2/base/bin/boot       |  65 ----------
 8 files changed, 271 insertions(+), 136 deletions(-)
 create mode 100644 commands/boot.c
 delete mode 100644 defaultenv-2/base/bin/_boot
 delete mode 100644 defaultenv-2/base/bin/_boot_help
 delete mode 100644 defaultenv-2/base/bin/_boot_list
 delete mode 100644 defaultenv-2/base/bin/boot

diff --git a/commands/Kconfig b/commands/Kconfig
index 55e46a0..9738ec4 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -514,6 +514,17 @@ config CMD_LINUX16
 	  Compile the linux16 command to be able to boot bzImages
 	  via real mode.
 
+config CMD_BOOT
+	tristate
+	select BOOTM
+	prompt "boot"
+	help
+	  Select this for booting based on scripts. unlike the bootm command which
+	  can boot a single image this command offers the possibility to boot with
+	  scripts (by default placed under /env/boot/). This command iterates over
+	  multiple scripts until one succeeds. It supersedes the previous 'boot'
+	  script.
+
 config CMD_RESET
 	tristate
 	prompt "reset"
diff --git a/commands/Makefile b/commands/Makefile
index 6acffc8..f4e0ac6 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -91,3 +91,4 @@ obj-$(CONFIG_CMD_FILETYPE)	+= filetype.o
 obj-$(CONFIG_CMD_BAREBOX_UPDATE)+= barebox-update.o
 obj-$(CONFIG_CMD_MIITOOL)	+= miitool.o
 obj-$(CONFIG_CMD_DETECT)	+= detect.o
+obj-$(CONFIG_CMD_BOOT)		+= boot.o
diff --git a/commands/boot.c b/commands/boot.c
new file mode 100644
index 0000000..93bf148
--- /dev/null
+++ b/commands/boot.c
@@ -0,0 +1,258 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <environment.h>
+#include <globalvar.h>
+#include <magicvar.h>
+#include <command.h>
+#include <common.h>
+#include <getopt.h>
+#include <libgen.h>
+#include <malloc.h>
+#include <boot.h>
+#include <fs.h>
+
+#include <linux/stat.h>
+
+static int verbose;
+static int dryrun;
+
+static void bootsources_list(void)
+{
+	DIR *dir;
+	struct dirent *d;
+	const char *path = "/env/boot";
+
+	dir = opendir(path);
+	if (!dir) {
+		printf("cannot open %s: %s\n", path, strerror(-errno));
+		return;
+	}
+
+	printf("Bootsources: ");
+
+	while ((d = readdir(dir))) {
+		if (*d->d_name == '.')
+			continue;
+
+		printf("%s ", d->d_name);
+	}
+
+	printf("\n");
+
+	closedir(dir);
+}
+
+static const char *getenv_or_null(const char *var)
+{
+	const char *val = getenv(var);
+
+	if (val && *val)
+		return val;
+	return NULL;
+}
+
+/*
+ * Start a single boot script. 'path' is a full path to a boot script.
+ */
+static int boot_script(char *path)
+{
+	struct bootm_data data = {};
+	int ret;
+
+	printf("booting %s...\n", basename(path));
+
+	globalvar_set_match("linux.bootargs.dyn.", "");
+	globalvar_set_match("bootm.", "");
+
+	ret = run_command(path, 0);
+	if (ret) {
+		printf("Running %s failed\n", path);
+		goto out;
+	}
+
+	data.initrd_address = UIMAGE_INVALID_ADDRESS;
+	data.os_address = UIMAGE_SOME_ADDRESS;
+	data.oftree_file = getenv_or_null("global.bootm.oftree");
+	data.os_file = getenv_or_null("global.bootm.image");
+	data.os_address = getenv_loadaddr("global.bootm.image.loadaddr");
+	data.initrd_address = getenv_loadaddr("global.bootm.initrd.loadaddr");
+	data.initrd_file = getenv_or_null("global.bootm.initrd");
+	data.verbose = verbose;
+	data.dryrun = dryrun;
+
+	ret = bootm_boot(&data);
+	if (ret)
+		pr_err("Booting %s failed: %s\n", basename(path), strerror(-ret));
+out:
+	return ret;
+}
+
+/*
+ * boot a script. 'name' can either be a filename under /env/boot/,
+ * a full path to a boot script or a path to a directory. This function
+ * returns a negative error on failure, or 0 on a successful dryrun boot.
+ */
+static int boot(const char *name)
+{
+	char *path;
+	DIR *dir;
+	struct dirent *d;
+	struct stat s;
+	int ret;
+
+	if (*name == '/')
+		path = xstrdup(name);
+	else
+		path = asprintf("/env/boot/%s", name);
+
+	ret = stat(path, &s);
+	if (ret) {
+		pr_err("%s: %s\n", path, strerror(-ret));
+		goto out;
+	}
+
+	if (S_ISREG(s.st_mode)) {
+		ret = boot_script(path);
+		goto out;
+	}
+
+	dir = opendir(path);
+	if (!dir) {
+		ret = -errno;
+		printf("cannot open %s: %s\n", path, strerror(-errno));
+		goto out;
+	}
+
+	while ((d = readdir(dir))) {
+		char *file;
+		struct stat s;
+
+		if (*d->d_name == '.')
+			continue;
+
+		file = asprintf("%s/%s", path, d->d_name);
+
+		ret = stat(file, &s);
+		if (ret) {
+			free(file);
+			continue;
+		}
+
+		if (!S_ISREG(s.st_mode)) {
+			free(file);
+			continue;
+		}
+
+		ret = boot_script(file);
+
+                free(file);
+
+		if (!ret)
+			break;
+	}
+
+	closedir(dir);
+out:
+	free(path);
+
+	return ret;
+}
+
+static int do_boot(int argc, char *argv[])
+{
+	const char *sources = NULL;
+	char *source, *freep;
+	int opt, ret = 0, do_list = 0;
+
+	verbose = 0;
+	dryrun = 0;
+
+	while ((opt = getopt(argc, argv, "vld")) > 0) {
+		switch (opt) {
+		case 'v':
+			verbose++;
+			break;
+		case 'l':
+			do_list = 1;
+			break;
+		case 'd':
+			dryrun = 1;
+			break;
+		}
+	}
+
+	if (do_list) {
+		bootsources_list();
+		return 0;
+	}
+
+	if (optind < argc) {
+		while (optind < argc) {
+			source = argv[optind];
+			optind++;
+			ret = boot(source);
+			if (!ret)
+				break;
+		}
+		return ret;
+	}
+
+	sources = getenv("global.boot.default");
+	if (!sources)
+		return 0;
+
+	freep = source = xstrdup(sources);
+
+	while (1) {
+		char *sep = strchr(source, ' ');
+		if (sep)
+			*sep = 0;
+		ret = boot(source);
+		if (!ret)
+			break;
+
+		if (sep)
+			source = sep + 1;
+		else
+			break;
+	}
+
+	free(freep);
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(boot)
+BAREBOX_CMD_HELP_USAGE("boot [OPTIONS] [BOOTSRC...]\n")
+BAREBOX_CMD_HELP_SHORT("Boot an operating system.\n")
+BAREBOX_CMD_HELP_SHORT("[BOOTSRC...] can be:\n")
+BAREBOX_CMD_HELP_SHORT("- a filename from /env/boot/\n")
+BAREBOX_CMD_HELP_SHORT("- a full path to a file\n")
+BAREBOX_CMD_HELP_SHORT("- a path to a directory. All files in this directory are treated\n")
+BAREBOX_CMD_HELP_SHORT("  as boot scripts.\n")
+BAREBOX_CMD_HELP_SHORT("Multiple bootsources may be given which are probed in order until\n")
+BAREBOX_CMD_HELP_SHORT("one succeeds.\n")
+BAREBOX_CMD_HELP_SHORT("\nOptions:\n")
+BAREBOX_CMD_HELP_OPT  ("-v","Increase verbosity\n")
+BAREBOX_CMD_HELP_OPT  ("-d","Dryrun. See what happens but do no actually boot\n")
+BAREBOX_CMD_HELP_OPT  ("-l","List available boot sources\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(boot)
+	.cmd	= do_boot,
+	.usage		= "boot the machine",
+	BAREBOX_CMD_HELP(cmd_boot_help)
+BAREBOX_CMD_END
+
+BAREBOX_MAGICVAR_NAMED(global_boot_default, global.boot.default, "default boot order");
diff --git a/common/Kconfig b/common/Kconfig
index dd70578..f83644b 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -549,6 +549,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
 	select CMD_READLINK
 	select CMD_DIRNAME
 	select FLEXIBLE_BOOTARGS
+	select CMD_BOOT
 	prompt "Generic environment template"
 
 config DEFAULT_ENVIRONMENT_GENERIC
diff --git a/defaultenv-2/base/bin/_boot b/defaultenv-2/base/bin/_boot
deleted file mode 100644
index 71d1490..0000000
--- a/defaultenv-2/base/bin/_boot
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/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
deleted file mode 100644
index 5679e91..0000000
--- a/defaultenv-2/base/bin/_boot_help
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/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
deleted file mode 100644
index 17f29bf..0000000
--- a/defaultenv-2/base/bin/_boot_list
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/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
deleted file mode 100644
index eed4b3c..0000000
--- a/defaultenv-2/base/bin/boot
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-
-BOOT_BOOTM_OPTS=
-BOOT_DRYRUN=
-BOOT_VERBOSE=
-list=
-bootsrc=${global.boot.default}
-
-usage="
-$0 [OPTIONS] [source]\n
- -v  verbose\n
- -d  dryrun\n
- -l  list boot sources\n
- -h  help"
-
-. /env/data/ansi-colors
-
-while getopt "vdhl" opt; do
-	if [ ${opt} = v ]; then
-		BOOT_BOOTM_OPTS="$BOOT_BOOTM_OPTS -v"
-		BOOT_VERBOSE=1
-	elif [ ${opt} = d ]; then
-		BOOT_DRYRUN=1
-	elif [ ${opt} = l ]; then
-		list=1
-	elif [ ${opt} = h ]; then
-		echo -e "$usage"
-		exit 0
-	fi
-done
-
-if [ -n "$list" ]; then
-	echo "boot sources:"
-	for i in /env/boot/*; do
-		basename $i s
-		echo $s
-	done
-	exit 0
-fi
-
-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
-- 
1.8.4.rc3


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

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

end of thread, other threads:[~2013-09-24  7:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-24  7:08 Bootm patches Sascha Hauer
2013-09-24  7:08 ` [PATCH 01/11] bootm: fix possible memory leak Sascha Hauer
2013-09-24  7:08 ` [PATCH 02/11] bootm: fix " Sascha Hauer
2013-09-24  7:08 ` [PATCH 03/11] bootm: check for os image file Sascha Hauer
2013-09-24  7:08 ` [PATCH 04/11] bootm: remove unused define Sascha Hauer
2013-09-24  7:08 ` [PATCH 05/11] bootm: move getenv_loadaddr from command to common Sascha Hauer
2013-09-24  7:08 ` [PATCH 06/11] bootm: move globalvars " Sascha Hauer
2013-09-24  7:08 ` [PATCH 07/11] bootm: separate bootm input data and internal data Sascha Hauer
2013-09-24  7:08 ` [PATCH 08/11] bootm: Add dryrun support Sascha Hauer
2013-09-24  7:08 ` [PATCH 09/11] ARM: compile bootm code depending on CONFIG_BOOTM Sascha Hauer
2013-09-24  7:08 ` [PATCH 10/11] command: Let builtin command take precedence Sascha Hauer
2013-09-24  7:08 ` [PATCH 11/11] defenv-2: replace boot script with command Sascha Hauer

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