Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Fenkart <afenkart@gmail.com>
To: kexec@lists.infradead.org
Cc: Andreas Fenkart <andreas.fenkart@dev.digitalstrom.org>,
	Andreas Fenkart <afenkart@gmail.com>
Subject: [PATCH 1/2] kexex: arm: create ATAGS_MEM tag from devicetree memory node
Date: Mon, 16 Nov 2015 13:56:54 +0100	[thread overview]
Message-ID: <1447678615-16987-1-git-send-email-andreas.fenkart@dev.digitalstrom.org> (raw)

From: Andreas Fenkart <afenkart@gmail.com>

booting a non-devicetree kernel from a devicetree kernel failed,
since the memory layout wasn't passed.

Signed-off-by: Andreas Fenkart <andreas.fenkart@dev.digitalstrom.org>
---
 kexec/arch/arm/kexec-zImage-arm.c | 43 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c
index ff4e38d..f460ba7 100644
--- a/kexec/arch/arm/kexec-zImage-arm.c
+++ b/kexec/arch/arm/kexec-zImage-arm.c
@@ -4,6 +4,7 @@
  */
 #define _GNU_SOURCE
 #define _XOPEN_SOURCE
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -139,6 +140,42 @@ struct tag * atag_read_tags(void)
 	return (struct tag *) buf;
 }
 
+static
+int create_mem32_tag(struct tag_mem32 *tag_mem32)
+{
+	const char fn[]= "/proc/device-tree/memory/reg";
+	FILE *fp;
+	uint32_t tmp[2];
+	int ret = 0;
+
+	assert(tag_mem32);
+	fp = fopen(fn, "r");
+	if (!fp) {
+		ret = errno;
+		fprintf(stderr, "Cannot open %s: %m\n", fn);
+		return ret;
+	}
+
+	if (!fread(tmp, sizeof(tmp[0]), 2, fp)) {
+		ret = ENOENT;
+		fprintf(stderr, "Short read %s\n", fn);
+		goto out;
+	}
+
+	if (ferror(fp)) {
+		ret = errno;
+		fprintf(stderr, "Cannot read %s: %m\n", fn);
+		goto out;
+	}
+
+	/* atags_mem32 has base/size fields reversed! */
+	tag_mem32->size = be32_to_cpu(tmp[1]);
+	tag_mem32->start = be32_to_cpu(tmp[0]);
+
+out:
+	fclose(fp);
+	return ret;
+}
 
 static
 int atag_arm_load(struct kexec_info *info, unsigned long base,
@@ -182,6 +219,12 @@ int atag_arm_load(struct kexec_info *info, unsigned long base,
 		params->hdr.size = 2;
 		params->hdr.tag = ATAG_CORE;
 		params = tag_next(params);
+
+		if (!create_mem32_tag(&params->u.mem)) {
+			params->hdr.size = 4;
+			params->hdr.tag = ATAG_MEM;
+			params = tag_next(params);
+		}
 	}
 
 	if (initrd) {
-- 
2.6.1


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

             reply	other threads:[~2015-11-16 12:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 12:56 Andreas Fenkart [this message]
2015-11-16 12:56 ` [PATCH 2/2] uImage: fix pointer-sign warning Andreas Fenkart
2015-11-17 17:30   ` Simon Horman
2015-11-17 17:29 ` [PATCH 1/2] kexex: arm: create ATAGS_MEM tag from devicetree memory node 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=1447678615-16987-1-git-send-email-andreas.fenkart@dev.digitalstrom.org \
    --to=afenkart@gmail.com \
    --cc=andreas.fenkart@dev.digitalstrom.org \
    --cc=kexec@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