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 04/13] bootm: use names instead of numbers for image parts
Date: Fri, 15 Jan 2016 16:07:09 +0100	[thread overview]
Message-ID: <1452870438-29656-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1452870438-29656-1-git-send-email-s.hauer@pengutronix.de>

The uImage format uses numbers for to identify the different
parts of a image, but the FIT image format uses names. To better
integrate the FIT image format into bootm always use names and
convert them to numbers when necessary.

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

diff --git a/common/bootm.c b/common/bootm.c
index a38d7e0..f8d9330 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -68,8 +68,12 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 		return -EINVAL;
 
 	if (data->os) {
+		int num;
+
+		num = simple_strtoul(data->os_part, NULL, 0);
+
 		data->os_res = uimage_load_to_sdram(data->os,
-			data->os_num, load_address);
+			num, load_address);
 		if (!data->os_res)
 			return -ENOMEM;
 
@@ -106,8 +110,12 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
 		return 0;
 
 	if (data->initrd) {
+		int num;
+
+		num = simple_strtoul(data->initrd_part, NULL, 0);
+
 		data->initrd_res = uimage_load_to_sdram(data->initrd,
-			data->initrd_num, load_address);
+			num, load_address);
 		if (!data->initrd_res)
 			return -ENOMEM;
 
@@ -191,7 +199,8 @@ int bootm_get_os_size(struct image_data *data)
 	int ret;
 
 	if (data->os)
-		return uimage_get_size(data->os, data->os_num);
+		return uimage_get_size(data->os,
+				       simple_strtoul(data->os_part, NULL, 0));
 
 	if (data->os_file) {
 		struct stat s;
@@ -268,7 +277,7 @@ static int bootm_open_oftree_uimage(struct image_data *data)
 	struct fdt_header *fdt;
 	enum filetype ft;
 	const char *oftree = data->oftree_file;
-	int num = data->oftree_num;
+	int num = simple_strtoul(data->oftree_part, NULL, 0);
 	struct uimage_handle *of_handle;
 	int release = 0;
 	size_t size;
@@ -358,7 +367,7 @@ static void bootm_print_info(struct image_data *data)
 				data->initrd_file);
 		if (initrd_type == filetype_uimage &&
 				data->initrd->header.ih_type == IH_TYPE_MULTI)
-			printf(", multifile image %d", data->initrd_num);
+			printf(", multifile image %s", data->initrd_part);
 		printf("\n");
 		if (data->initrd_res)
 			printf("initrd is at " PRINTF_CONVERSION_RESOURCE "-" PRINTF_CONVERSION_RESOURCE "\n",
@@ -369,25 +378,27 @@ static void bootm_print_info(struct image_data *data)
 	}
 }
 
-static char *bootm_image_name_and_no(const char *name, int *no)
+static int bootm_image_name_and_part(const char *name, char **filename, char **part)
 {
 	char *at, *ret;
 
 	if (!name || !*name)
-		return NULL;
-
-	*no = 0;
+		return -EINVAL;
 
 	ret = xstrdup(name);
+
+	*filename = ret;
+	*part = NULL;
+
 	at = strchr(ret, '@');
 	if (!at)
-		return ret;
+		return 0;
 
 	*at++ = 0;
 
-	*no = simple_strtoul(at, NULL, 10);
+	*part = at;
 
-	return ret;
+	return 0;
 }
 
 /*
@@ -408,9 +419,9 @@ int bootm_boot(struct bootm_data *bootm_data)
 
 	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);
+	bootm_image_name_and_part(bootm_data->os_file, &data->os_file, &data->os_part);
+	bootm_image_name_and_part(bootm_data->oftree_file, &data->oftree_part, &data->os_part);
+	bootm_image_name_and_part(bootm_data->initrd_file, &data->initrd_part, &data->os_part);
 	data->verbose = bootm_data->verbose;
 	data->verify = bootm_data->verify;
 	data->force = bootm_data->force;
@@ -479,7 +490,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 			data->os_file);
 	if (os_type == filetype_uimage &&
 			data->os->header.ih_type == IH_TYPE_MULTI)
-		printf(", multifile image %d", data->os_num);
+		printf(", multifile image %s", data->os_part);
 	printf("\n");
 
 	if (IS_ENABLED(CONFIG_OFTREE)) {
diff --git a/include/boot.h b/include/boot.h
index b172c05..9ddb18b 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -28,7 +28,7 @@ struct image_data {
 
 	/* if os is an uImage this will be provided */
 	struct uimage_handle *os;
-	int os_num;
+	char *os_part;
 
 	/* otherwise only the filename will be provided */
 	char *os_file;
@@ -49,7 +49,7 @@ struct image_data {
 
 	/* if initrd is an uImage this will be provided */
 	struct uimage_handle *initrd;
-	int initrd_num;
+	char *initrd_part;
 
 	/* otherwise only the filename will be provided */
 	char *initrd_file;
@@ -57,7 +57,7 @@ struct image_data {
 	unsigned long initrd_address;
 
 	char *oftree_file;
-	int oftree_num;
+	char *oftree_part;
 
 	struct device_node *of_root_node;
 	struct fdt_header *oftree;
-- 
2.6.4


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

  parent reply	other threads:[~2016-01-15 15:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 15:07 [PATCH v3] FIT support Sascha Hauer
2016-01-15 15:07 ` [PATCH 01/13] ARM: zImage: add missing free() in appended device tree code Sascha Hauer
2016-01-15 15:07 ` [PATCH 02/13] bootm: Do not call uimage_close twice Sascha Hauer
2016-01-15 15:07 ` [PATCH 03/13] bootm: introduce bootm_get_os_size Sascha Hauer
2016-01-15 15:07 ` Sascha Hauer [this message]
2016-01-15 15:07 ` [PATCH 05/13] ARM: bootm: Use kernel handler to start barebox image Sascha Hauer
2016-01-15 15:07 ` [PATCH 06/13] bootm: Push dryrun to handlers Sascha Hauer
2016-01-15 15:07 ` [PATCH 07/13] bootm: move initrd code together Sascha Hauer
2016-01-15 15:07 ` [PATCH 08/13] bootm: move oftree " Sascha Hauer
2016-01-15 15:07 ` [PATCH 09/13] bootm: Initialize bootm_data defaults in single place Sascha Hauer
2016-01-15 15:07 ` [PATCH 10/13] crypto: add digest_alloc_by_algo() Sascha Hauer
2016-01-15 15:07 ` [PATCH 11/13] crypto: add RSA support Sascha Hauer
2016-01-15 15:07 ` [PATCH 12/13] bootm: make verifying/hashing configurable Sascha Hauer
2016-01-15 15:07 ` [PATCH 13/13] bootm: add initial FIT support Sascha Hauer
2016-01-15 15:37   ` Holger Schurig
2016-01-18  7:31     ` Sascha Hauer
2016-01-15 15:50 ` [PATCH v3] " Yegor Yefremov

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=1452870438-29656-5-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