mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 09/14] bootm: Initialize bootm_data defaults in single place
Date: Fri, 22 Jan 2016 08:32:27 +0100	[thread overview]
Message-ID: <1453447952-30818-10-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1453447952-30818-1-git-send-email-s.hauer@pengutronix.de>

Both the bootm and the boot code initialize the struct bootm_data
with defaults from the bootm global variables. Create a common
function for doing this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/boot.c  | 14 ++------------
 commands/bootm.c | 31 +++++--------------------------
 common/bootm.c   | 11 +++++++++++
 include/boot.h   |  2 ++
 4 files changed, 20 insertions(+), 38 deletions(-)

diff --git a/commands/boot.c b/commands/boot.c
index fd58824..f403010 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -42,13 +42,9 @@ static int timeout;
 static int boot_script(char *path)
 {
 	int ret;
-	struct bootm_data data = {
-		.os_address = UIMAGE_SOME_ADDRESS,
-		.initrd_address = UIMAGE_SOME_ADDRESS,
-	};
+	struct bootm_data data = {};
 
 	globalvar_set_match("linux.bootargs.dyn.", "");
-	globalvar_set_match("bootm.", "");
 
 	ret = run_command(path);
 	if (ret) {
@@ -56,15 +52,9 @@ static int boot_script(char *path)
 		goto out;
 	}
 
-	data.initrd_address = UIMAGE_INVALID_ADDRESS;
-	data.os_address = UIMAGE_SOME_ADDRESS;
-	data.oftree_file = getenv_nonempty("global.bootm.oftree");
-	data.os_file = getenv_nonempty("global.bootm.image");
-	getenv_ul("global.bootm.image.loadaddr", &data.os_address);
-	getenv_ul("global.bootm.initrd.loadaddr", &data.initrd_address);
-	data.initrd_file = getenv_nonempty("global.bootm.initrd");
 	data.verbose = verbose;
 	data.dryrun = dryrun;
+	bootm_data_init_defaults(&data);
 
 	ret = bootm_boot(&data);
 	if (ret)
diff --git a/commands/bootm.c b/commands/bootm.c
index 063da62..6db0e65 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -59,19 +59,8 @@ static int do_bootm(int argc, char *argv[])
 	int opt;
 	struct bootm_data data = {};
 	int ret = 1;
-	const char *oftree = NULL, *initrd_file = NULL, *os_file = NULL;
 
-	data.initrd_address = UIMAGE_INVALID_ADDRESS;
-	data.os_address = UIMAGE_SOME_ADDRESS;
-	data.verify = 0;
-	data.verbose = 0;
-
-	oftree = getenv("global.bootm.oftree");
-	os_file = getenv("global.bootm.image");
-	getenv_ul("global.bootm.image.loadaddr", &data.os_address);
-	getenv_ul("global.bootm.initrd.loadaddr", &data.initrd_address);
-	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
-		initrd_file = getenv("global.bootm.initrd");
+	bootm_data_init_defaults(&data);
 
 	while ((opt = getopt(argc, argv, BOOTM_OPTS)) > 0) {
 		switch(opt) {
@@ -83,7 +72,7 @@ static int do_bootm(int argc, char *argv[])
 			data.initrd_address = simple_strtoul(optarg, NULL, 0);
 			break;
 		case 'r':
-			initrd_file = optarg;
+			data.initrd_file = optarg;
 			break;
 #endif
 		case 'a':
@@ -96,7 +85,7 @@ static int do_bootm(int argc, char *argv[])
 			data.verbose++;
 			break;
 		case 'o':
-			oftree = optarg;
+			data.oftree_file = optarg;
 			break;
 		case 'f':
 			data.force = 1;
@@ -110,23 +99,13 @@ static int do_bootm(int argc, char *argv[])
 	}
 
 	if (optind != argc)
-		os_file = argv[optind];
+		data.os_file = argv[optind];
 
-	if (!os_file || !*os_file) {
+	if (!data.os_file) {
 		printf("no boot image given\n");
 		goto err_out;
 	}
 
-	if (initrd_file && !*initrd_file)
-		initrd_file = NULL;
-
-	if (oftree && !*oftree)
-		oftree = NULL;
-
-	data.os_file = os_file;
-	data.oftree_file = oftree;
-	data.initrd_file = initrd_file;
-
 	ret = bootm_boot(&data);
 	if (ret) {
 		printf("handler failed with: %s\n", strerror(-ret));
diff --git a/common/bootm.c b/common/bootm.c
index e399a6a..4409a8b 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -47,6 +47,17 @@ static struct image_handler *bootm_find_handler(enum filetype filetype,
 	return NULL;
 }
 
+void bootm_data_init_defaults(struct bootm_data *data)
+{
+	data->initrd_address = UIMAGE_INVALID_ADDRESS;
+	data->os_address = UIMAGE_SOME_ADDRESS;
+	data->oftree_file = getenv_nonempty("global.bootm.oftree");
+	data->os_file = getenv_nonempty("global.bootm.image");
+	getenv_ul("global.bootm.image.loadaddr", &data->os_address);
+	getenv_ul("global.bootm.initrd.loadaddr", &data->initrd_address);
+	data->initrd_file = getenv_nonempty("global.bootm.initrd");
+}
+
 /*
  * bootm_load_os() - load OS to RAM
  *
diff --git a/include/boot.h b/include/boot.h
index 7c6d9c8..0c0febe 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -109,6 +109,8 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
 }
 #endif
 
+void bootm_data_init_defaults(struct bootm_data *data);
+
 int bootm_load_os(struct image_data *data, unsigned long load_address);
 
 bool bootm_has_initrd(struct image_data *data);
-- 
2.7.0.rc3


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

  parent reply	other threads:[~2016-01-22  7:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22  7:32 [PATCH v4] FIT support Sascha Hauer
2016-01-22  7:32 ` [PATCH 01/14] ARM: zImage: add missing free() in appended device tree code Sascha Hauer
2016-01-22  7:32 ` [PATCH 02/14] bootm: Do not call uimage_close twice Sascha Hauer
2016-01-22  7:32 ` [PATCH 03/14] bootm: introduce bootm_get_os_size Sascha Hauer
2016-01-22  7:32 ` [PATCH 04/14] bootm: use names instead of numbers for image parts Sascha Hauer
2016-01-22  7:32 ` [PATCH 05/14] ARM: bootm: Use kernel handler to start barebox image Sascha Hauer
2016-01-22  7:32 ` [PATCH 06/14] bootm: Push dryrun to handlers Sascha Hauer
2016-01-22  7:32 ` [PATCH 07/14] bootm: move initrd code together Sascha Hauer
2016-01-22  7:32 ` [PATCH 08/14] bootm: move oftree " Sascha Hauer
2016-01-22  7:32 ` Sascha Hauer [this message]
2016-01-22  7:32 ` [PATCH 10/14] crypto: add digest_alloc_by_algo() Sascha Hauer
2016-01-22  7:32 ` [PATCH 11/14] crypto: add RSA support Sascha Hauer
2016-01-22  7:32 ` [PATCH 12/14] bootm: make verifying/hashing configurable Sascha Hauer
2016-01-22  7:32 ` [PATCH 13/14] bootm: add initial FIT support Sascha Hauer
2016-01-22  7:32 ` [PATCH 14/14] bootm: Add option to force booting signed images Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453447952-30818-10-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox