All of lore.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: kexec@lists.infradead.org
Cc: horms@verge.net.au, Magnus Damm <magnus.damm@gmail.com>
Subject: [PATCH 06/06] sh: Add vmlinux support
Date: Tue, 26 Aug 2008 20:12:32 +0900	[thread overview]
Message-ID: <20080826111232.615.24048.sendpatchset@rx1.opensource.se> (raw)
In-Reply-To: <20080826111150.615.97501.sendpatchset@rx1.opensource.se>

From: Magnus Damm <damm@igel.co.jp>

Add SuperH vmlinux support through a zero-page aware elf loader. Only for
kexec at this point, in the future kdump support will be added.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 kexec/arch/sh/Makefile       |    1 
 kexec/arch/sh/kexec-elf-sh.c |  114 ++++++++++++++++++++++++++++++++++++++++++
 kexec/arch/sh/kexec-sh.c     |    1 
 kexec/arch/sh/kexec-sh.h     |    5 +
 4 files changed, 121 insertions(+)

--- 0004/kexec/arch/sh/Makefile
+++ work/kexec/arch/sh/Makefile	2008-08-22 13:17:18.000000000 +0900
@@ -4,6 +4,7 @@
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-zImage-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-netbsd-sh.c
+sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-rel-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/netbsd_booter.S
 
--- /dev/null
+++ work/kexec/arch/sh/kexec-elf-sh.c	2008-08-22 14:24:31.000000000 +0900
@@ -0,0 +1,114 @@
+/*
+ * kexec: Linux boots Linux
+ *
+ * Copyright (C) 2008  Magnus Damm
+ *
+ * Based on x86 implementation,
+ * Copyright (C) 2003-2005  Eric Biederman (ebiederm@xmission.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation (version 2 of the License).
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <elf.h>
+#include "../../kexec.h"
+#include "../../kexec-syscall.h"
+#include "../../kexec-elf.h"
+#include "../../kexec-elf-boot.h"
+#include <arch/options.h>
+#include "kexec-sh.h"
+
+int elf_sh_probe(const char *buf, off_t len)
+{
+	struct mem_ehdr ehdr;
+	int result;
+	result = build_elf_exec_info(buf, len, &ehdr, 0);
+	if (result < 0)
+		goto out;
+
+	/* Verify the architecuture specific bits */
+	if (ehdr.e_machine != EM_SH) {
+		result = -1;
+		goto out;
+	}
+
+	result = 0;
+ out:
+	free_elf_info(&ehdr);
+	return result;
+}
+
+void elf_sh_usage(void)
+{
+	printf("  --append=STRING       Set the kernel command line to STRING\n"
+		);
+}
+
+int elf_sh_load(int argc, char **argv, const char *buf, off_t len, 
+	struct kexec_info *info)
+{
+	struct mem_ehdr ehdr;
+	const char *command_line;
+	struct mem_sym sym;
+	int opt;
+	static const struct option options[] = {
+		KEXEC_ARCH_OPTIONS
+		{ 0, 			0, NULL, 0 },
+	};
+
+	static const char short_options[] = KEXEC_OPT_STR "";
+
+	/*
+	 * Parse the command line arguments
+	 */
+	command_line = 0;
+	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
+		switch(opt) {
+		default:
+			/* Ignore core options */
+			if (opt < OPT_ARCH_MAX) {
+				break;
+			}
+		case '?':
+			usage();
+			return -1;
+		case OPT_APPEND:
+			command_line = optarg;
+			break;
+		}
+	}
+
+	/* Load the ELF executable */
+	elf_exec_build_load(info, &ehdr, buf, len, 0);
+	info->entry = (void *)ehdr.e_entry;
+
+	/* If we're booting a vmlinux then fill in empty_zero_page */
+	if (elf_rel_find_symbol(&ehdr, "empty_zero_page", &sym) == 0) {
+		unsigned char *zp = (void *)ehdr.e_shdr[sym.st_shndx].sh_data;
+
+		kexec_sh_setup_zero_page(zp, 4096, command_line);
+	}
+
+	return 0;
+}
--- 0005/kexec/arch/sh/kexec-sh.c
+++ work/kexec/arch/sh/kexec-sh.c	2008-08-22 13:17:18.000000000 +0900
@@ -53,6 +53,7 @@ int get_memory_ranges(struct memory_rang
 /* Supported file types and callbacks */
 struct file_type file_type[] = {
        {"zImage-sh", zImage_sh_probe, zImage_sh_load, zImage_sh_usage},
+       {"elf-sh", elf_sh_probe, elf_sh_load, elf_sh_usage},
        {"netbsd-sh", netbsd_sh_probe, netbsd_sh_load, netbsd_sh_usage},
 };
 int file_types = sizeof(file_type) / sizeof(file_type[0]);
--- 0005/kexec/arch/sh/kexec-sh.h
+++ work/kexec/arch/sh/kexec-sh.h	2008-08-22 13:17:18.000000000 +0900
@@ -6,6 +6,11 @@ int zImage_sh_load(int argc, char **argv
 	struct kexec_info *info);
 void zImage_sh_usage(void);
 
+int elf_sh_probe(const char *buf, off_t len);
+int elf_sh_load(int argc, char **argv, const char *buf, off_t len,
+	struct kexec_info *info);
+void elf_sh_usage(void);
+
 int netbsd_sh_probe(const char *buf, off_t len);
 int netbsd_sh_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);

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

  parent reply	other threads:[~2008-08-26 11:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-26 11:11 [PATCH 00/06] sh: Improved kexec support for SuperH Magnus Damm
2008-08-26 11:11 ` [PATCH 01/06] sh: Add support for sh4al-dsp processors Magnus Damm
2008-08-26 11:12 ` [PATCH 02/06] sh: Get system memory ranges from /proc/iomem Magnus Damm
2008-08-26 11:12 ` [PATCH 03/06] sh: Add virtual addresses support Magnus Damm
2008-08-26 11:12 ` [PATCH 04/06] sh: Autodetect zImage zero page address Magnus Damm
2008-08-26 11:12 ` [PATCH 05/06] sh: Use dynamic zImage load address Magnus Damm
2008-08-26 11:12 ` Magnus Damm [this message]
2008-08-27  2:39   ` [PATCH 06/06] sh: Add vmlinux support Simon Horman
2008-08-27  4:10     ` Magnus Damm
2008-08-27  5:40       ` Simon Horman
2008-08-27  6:55         ` Magnus Damm
2008-08-27  7:35           ` Simon Horman
2008-08-27  7:05 ` [PATCH 00/06] sh: Improved kexec support for SuperH Paul Mundt

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=20080826111232.615.24048.sendpatchset@rx1.opensource.se \
    --to=magnus.damm@gmail.com \
    --cc=horms@verge.net.au \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.