Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
To: kexec@lists.infradead.org
Cc: linux-mips@linux-mips.org, Ralf Baechle <ralf@linux-mips.org>
Subject: [PATCH 6/6] mips: add option to load initrd from a specified file
Date: Fri, 2 Dec 2016 10:49:11 +0100	[thread overview]
Message-ID: <1480672151-18503-7-git-send-email-marcin.nowakowski@imgtec.com> (raw)
In-Reply-To: <1480672151-18503-1-git-send-email-marcin.nowakowski@imgtec.com>

Use kexec's existing infrastrucutre for supporting initrd loading.
The initrd image is loaded into a buffer after the dtb and its details
passed through the device tree, so it's supported on newer platforms
that make use of the device tree passed from kexec.

Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
---
 kexec/arch/mips/include/arch/options.h |  4 +++-
 kexec/arch/mips/kexec-elf-mips.c       | 19 +++++++++++++++++++
 kexec/arch/mips/kexec-mips.c           |  4 ++++
 kexec/arch/mips/kexec-mips.h           |  1 +
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/kexec/arch/mips/include/arch/options.h b/kexec/arch/mips/include/arch/options.h
index 86b620f..416e224 100644
--- a/kexec/arch/mips/include/arch/options.h
+++ b/kexec/arch/mips/include/arch/options.h
@@ -4,6 +4,7 @@
 #define OPT_ARCH_MAX	(OPT_MAX+0)
 #define OPT_APPEND	(OPT_ARCH_MAX+0)
 #define OPT_DTB		(OPT_ARCH_MAX+1)
+#define OPT_RAMDISK	(OPT_ARCH_MAX+2)
 
 /* Options relevant to the architecture (excluding loader-specific ones),
  * in this case none:
@@ -12,7 +13,8 @@
 	KEXEC_OPTIONS \
 	{"command-line", 1, 0, OPT_APPEND}, \
 	{"append",	 1, 0, OPT_APPEND}, \
-	{"dtb",		1, 0, OPT_DTB },
+	{"dtb",		1, 0, OPT_DTB }, \
+	{"initrd",	1, 0, OPT_RAMDISK },
 
 
 #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR ""
diff --git a/kexec/arch/mips/kexec-elf-mips.c b/kexec/arch/mips/kexec-elf-mips.c
index 6ca7ca0..849a7ba 100644
--- a/kexec/arch/mips/kexec-elf-mips.c
+++ b/kexec/arch/mips/kexec-elf-mips.c
@@ -79,6 +79,7 @@ int elf_mips_load(int argc, char **argv, const char *buf, off_t len,
 	size_t i;
 	off_t dtb_length;
 	char *dtb_buf;
+	char *initrd_buf = NULL;
 	unsigned long long kernel_addr = 0, kernel_size = 0;
 	unsigned long pagesize = getpagesize();
 
@@ -152,6 +153,24 @@ int elf_mips_load(int argc, char **argv, const char *buf, off_t len,
 		create_flatten_tree(&dtb_buf, &dtb_length, cmdline_buf + strlen(CMDLINE_PREFIX));
 	}
 
+	if (arch_options.initrd_file) {
+		initrd_buf = slurp_file(arch_options.initrd_file, &initrd_size);
+
+		/* Create initrd entries in dtb - although at this time
+		 * they would not point to the correct location */
+		dtb_set_initrd(&dtb_buf, &dtb_length, initrd_buf, initrd_buf + initrd_size);
+
+		initrd_base = add_buffer(info, initrd_buf, initrd_size,
+					initrd_size, sizeof(void *),
+					_ALIGN_UP(kernel_addr + kernel_size + dtb_length,
+						pagesize), 0x0fffffff, 1);
+
+		/* Now that the buffer for initrd is prepared, update the dtb
+		 * with an appropriate location */
+		dtb_set_initrd(&dtb_buf, &dtb_length, initrd_base, initrd_base + initrd_size);
+	}
+
+
 	/* This is a legacy method for commandline passing used
 	 * currently by Octeon CPUs only */
 	add_buffer(info, cmdline_buf, sizeof(cmdline_buf),
diff --git a/kexec/arch/mips/kexec-mips.c b/kexec/arch/mips/kexec-mips.c
index 2605c17..ee3cd3a 100644
--- a/kexec/arch/mips/kexec-mips.c
+++ b/kexec/arch/mips/kexec-mips.c
@@ -82,6 +82,7 @@ void arch_usage(void)
 	"    --command-line=STRING Set the kernel command line to STRING.\n"
 	"    --append=STRING       Set the kernel command line to STRING.\n"
 	"    --dtb=FILE            Use FILE as the device tree blob.\n"
+	"    --initrd=FILE         Use FILE as initial ramdisk.\n"
 	);
 }
 
@@ -111,6 +112,9 @@ int arch_process_options(int argc, char **argv)
 		case OPT_DTB:
 			arch_options.dtb_file = optarg;
 			break;
+		case OPT_RAMDISK:
+			arch_options.initrd_file = optarg;
+			break;
 		default:
 			break;
 		}
diff --git a/kexec/arch/mips/kexec-mips.h b/kexec/arch/mips/kexec-mips.h
index a609fb5..222c815 100644
--- a/kexec/arch/mips/kexec-mips.h
+++ b/kexec/arch/mips/kexec-mips.h
@@ -20,6 +20,7 @@ void elf_mips_usage(void);
 struct arch_options_t {
 	char *command_line;
 	char *dtb_file;
+	char *initrd_file;
 	int core_header_type;
 };
 
-- 
2.7.4


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

  parent reply	other threads:[~2016-12-02  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  9:49 [PATCH 0/6] Kexec fixes and updates for MIPS platforms Marcin Nowakowski
2016-12-02  9:49 ` [PATCH 1/6] mips: remove incorrect arch_usage string Marcin Nowakowski
2016-12-02  9:49 ` [PATCH 2/6] mips: use arch_options for both 32 and 64 bit variants Marcin Nowakowski
2016-12-02  9:49 ` [PATCH 3/6] mips: move arch option parsing from elf loader to common arch code Marcin Nowakowski
2016-12-02  9:49 ` [PATCH 4/6] mips: crashdump: add little-endian support Marcin Nowakowski
2016-12-02  9:49 ` [PATCH 5/6] mips: add dtb loading support Marcin Nowakowski
2016-12-02  9:49 ` Marcin Nowakowski [this message]
2016-12-09  7:57 ` [PATCH 0/6] Kexec fixes and updates for MIPS platforms Simon Horman

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=1480672151-18503-7-git-send-email-marcin.nowakowski@imgtec.com \
    --to=marcin.nowakowski@imgtec.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.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