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 07/14] bootm: move initrd code together
Date: Fri, 22 Jan 2016 08:32:25 +0100	[thread overview]
Message-ID: <1453447952-30818-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1453447952-30818-1-git-send-email-s.hauer@pengutronix.de>

The initrd code is distributed in several places in the bootm code.
Move it all together in bootm_load_initrd().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/bootm.c |   8 ++-
 common/bootm.c       | 151 +++++++++++++++++++++++++--------------------------
 include/boot.h       |   3 +
 3 files changed, 83 insertions(+), 79 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index eef906a..4dfe148 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -86,9 +86,11 @@ static int __do_bootm_linux(struct image_data *data, unsigned long free_mem, int
 		}
 	}
 
-	ret = bootm_load_initrd(data, initrd_start);
-	if (ret)
-		return ret;
+	if (bootm_has_initrd(data)) {
+		ret = bootm_load_initrd(data, initrd_start);
+		if (ret)
+			return ret;
+	}
 
 	if (data->initrd_res) {
 		initrd_start = data->initrd_res->start;
diff --git a/common/bootm.c b/common/bootm.c
index 7f6533b..06f1f8a 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -91,6 +91,41 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
 	return -EINVAL;
 }
 
+bool bootm_has_initrd(struct image_data *data)
+{
+	if (!IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
+		return false;
+
+	if (data->initrd_file)
+		return true;
+
+	return false;
+}
+
+static int bootm_open_initrd_uimage(struct image_data *data)
+{
+	int ret;
+
+	if (strcmp(data->os_file, data->initrd_file)) {
+		data->initrd = uimage_open(data->initrd_file);
+		if (!data->initrd)
+			return -EINVAL;
+
+		if (data->verify) {
+			ret = uimage_verify(data->initrd);
+			if (ret) {
+				printf("Checking data crc failed with %s\n",
+					strerror(-ret));
+			}
+		}
+		uimage_print_contents(data->initrd);
+	} else {
+		data->initrd = data->os;
+	}
+
+	return 0;
+}
+
 /*
  * bootm_load_initrd() - load initrd to RAM
  *
@@ -106,11 +141,34 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)
  */
 int bootm_load_initrd(struct image_data *data, unsigned long load_address)
 {
+	enum filetype type;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_CMD_BOOTM_INITRD))
+		return -ENOSYS;
+
+	if (!bootm_has_initrd(data))
+		return -EINVAL;
+
 	if (data->initrd_res)
 		return 0;
 
-	if (data->initrd) {
+	type = file_name_detect_type(data->initrd_file);
+
+	if ((int)type < 0) {
+		printf("could not open %s: %s\n", data->initrd_file,
+				strerror(-type));
+		return (int)type;
+	}
+
+	if (type == filetype_uimage) {
 		int num;
+		ret = bootm_open_initrd_uimage(data);
+		if (ret) {
+			printf("loading initrd failed with %s\n",
+					strerror(-ret));
+			return ret;
+		}
 
 		num = simple_strtoul(data->initrd_part, NULL, 0);
 
@@ -119,16 +177,24 @@ int bootm_load_initrd(struct image_data *data, unsigned long load_address)
 		if (!data->initrd_res)
 			return -ENOMEM;
 
-		return 0;
+		goto done;
 	}
 
-	if (data->initrd_file) {
-		data->initrd_res = file_to_sdram(data->initrd_file, load_address);
-		if (!data->initrd_res)
-			return -ENOMEM;
+	data->initrd_res = file_to_sdram(data->initrd_file, load_address);
+	if (!data->initrd_res)
+		return -ENOMEM;
 
-		return 0;
-	}
+done:
+
+	printf("Loaded initrd %s '%s'", file_type_to_string(type),
+	       data->initrd_file);
+	if (type == filetype_uimage && data->initrd->header.ih_type == IH_TYPE_MULTI)
+		printf(", multifile image %s", data->initrd_part);
+	printf("\n");
+
+	printf("initrd is at " PRINTF_CONVERSION_RESOURCE "-" PRINTF_CONVERSION_RESOURCE "\n",
+		data->initrd_res->start,
+		data->initrd_res->end);
 
 	return 0;
 }
@@ -245,33 +311,6 @@ static int bootm_open_os_uimage(struct image_data *data)
 	return 0;
 }
 
-static int bootm_open_initrd_uimage(struct image_data *data)
-{
-	int ret;
-
-	if (!data->initrd_file)
-		return 0;
-
-	if (strcmp(data->os_file, data->initrd_file)) {
-		data->initrd = uimage_open(data->initrd_file);
-		if (!data->initrd)
-			return -EINVAL;
-
-		if (data->verify) {
-			ret = uimage_verify(data->initrd);
-			if (ret) {
-				printf("Checking data crc failed with %s\n",
-					strerror(-ret));
-			}
-		}
-		uimage_print_contents(data->initrd);
-	} else {
-		data->initrd = data->os;
-	}
-
-	return 0;
-}
-
 static int bootm_open_oftree_uimage(struct image_data *data)
 {
 	struct fdt_header *fdt;
@@ -358,24 +397,6 @@ static void bootm_print_info(struct image_data *data)
 				data->os_res->end);
 	else
 		printf("OS image not yet relocated\n");
-
-	if (data->initrd_file) {
-		enum filetype initrd_type = file_name_detect_type(data->initrd_file);
-
-		printf("Loading initrd %s '%s'",
-				file_type_to_string(initrd_type),
-				data->initrd_file);
-		if (initrd_type == filetype_uimage &&
-				data->initrd->header.ih_type == IH_TYPE_MULTI)
-			printf(", multifile image %s", data->initrd_part);
-		printf("\n");
-		if (data->initrd_res)
-			printf("initrd is at " PRINTF_CONVERSION_RESOURCE "-" PRINTF_CONVERSION_RESOURCE "\n",
-				data->initrd_res->start,
-				data->initrd_res->end);
-		else
-			printf("initrd image not yet relocated\n");
-	}
 }
 
 static int bootm_image_name_and_part(const char *name, char **filename, char **part)
@@ -409,7 +430,7 @@ 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;
+	enum filetype os_type;
 	enum filetype oftree_type = filetype_unknown;
 
 	if (!bootm_data->os_file) {
@@ -444,17 +465,6 @@ int bootm_boot(struct bootm_data *bootm_data)
 		goto err_out;
 	}
 
-	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && data->initrd_file) {
-		initrd_type = file_name_detect_type(data->initrd_file);
-
-		if ((int)initrd_type < 0) {
-			printf("could not open %s: %s\n", data->initrd_file,
-					strerror(-initrd_type));
-			ret = (int)initrd_type;
-			goto err_out;
-		}
-	}
-
 	if (IS_ENABLED(CONFIG_OFTREE) && data->oftree_file) {
 		oftree_type = file_name_detect_type(data->oftree_file);
 
@@ -475,17 +485,6 @@ int bootm_boot(struct bootm_data *bootm_data)
 		}
 	}
 
-	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && data->initrd_file) {
-		if (initrd_type == filetype_uimage) {
-			ret = bootm_open_initrd_uimage(data);
-			if (ret) {
-				printf("loading initrd failed with %s\n",
-						strerror(-ret));
-				goto err_out;
-			}
-		}
-	}
-
 	printf("\nLoading %s '%s'", file_type_to_string(os_type),
 			data->os_file);
 	if (os_type == filetype_uimage &&
diff --git a/include/boot.h b/include/boot.h
index 9ddb18b..7c6d9c8 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -110,7 +110,10 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
 #endif
 
 int bootm_load_os(struct image_data *data, unsigned long load_address);
+
+bool bootm_has_initrd(struct image_data *data);
 int bootm_load_initrd(struct image_data *data, unsigned long load_address);
+
 int bootm_load_devicetree(struct image_data *data, unsigned long load_address);
 int bootm_get_os_size(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 ` Sascha Hauer [this message]
2016-01-22  7:32 ` [PATCH 08/14] bootm: move oftree code together Sascha Hauer
2016-01-22  7:32 ` [PATCH 09/14] bootm: Initialize bootm_data defaults in single place Sascha Hauer
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-8-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