Skip to contentSkip to conversation

Fix kexec on powerpc32

PATCH In review Maxim Uvarov 4 participants 5 messages May 12, 2010 – May 13, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 Fix kexec on powerpc32

Hello everybody,

Changes from previous version:
- removed bogus hyphen from the patch;
- move ifdefs to crt.S instead of Makefile

Please find here patch for user land kexec-tools application. Following patch makes kexec-tools work for both kexec and kdump. I tested it with git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with mpc83xx_defconfig kernel config.

kexec:
kexec -l vmlinux --command-line="console= ... etc" kexec -e

kdump:
kexec -p vmlinux_dump --command-line="console=... etc" echo c > /proc/sysrq-trigger

I also think that is is reasonable:
- put GAME_CUBE specific code to separate files;
- combine ppc and ppc64 to powerpc directory (I'm planning to do it. And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

From: Maxim Uvarov <[email protected]>

---

 kexec/arch/ppc/Makefile            |    2 
 kexec/arch/ppc/crashdump-powerpc.c |  439 ++++++++++++++++++++++++++++++++++
 kexec/arch/ppc/crashdump-powerpc.h |   38 +++
 kexec/arch/ppc/fs2dt.c             |  460 ++++++++++++++++++++++++++++++++++++
 kexec/arch/ppc/kexec-elf-ppc.c     |  186 +++++++++++++--
 kexec/arch/ppc/kexec-ppc.c         |  275 ++++++++++++++++++++--
 kexec/arch/ppc/kexec-ppc.h         |   32 +++
 purgatory/arch/ppc/Makefile        |    2 
 purgatory/arch/ppc/purgatory-ppc.c |   38 ++-
 purgatory/arch/ppc/purgatory-ppc.h |    4 
 purgatory/arch/ppc/v2wrap.S        |   66 -----
 purgatory/arch/ppc/v2wrap_32.S     |   91 +++++++
 12 files changed, 1524 insertions(+), 109 deletions(-)
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.c
 create mode 100644 kexec/arch/ppc/crashdump-powerpc.h
 create mode 100644 kexec/arch/ppc/fs2dt.c
 delete mode 100644 purgatory/arch/ppc/v2wrap.S
 create mode 100644 purgatory/arch/ppc/v2wrap_32.S
kexec/arch/ppc/Makefile +2 -0
index 1c7441c..5988213 100644
@@ -11,6 +11,8 @@ ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-uImage-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/fixup_dtb.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/fs2dt.c
+ppc_KEXEC_SRCS += kexec/arch/ppc/crashdump-powerpc.c
 ppc_KEXEC_SRCS += kexec/kexec-uImage.c
 
 libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c
kexec/arch/ppc/crashdump-powerpc.c new file +439 -0

439 lines not on this page · raw message

kexec/arch/ppc/crashdump-powerpc.h new file +38 -0
new file mode 100644
index 0000000..dc2772d
@@ -0,0 +1,38 @@
+#ifndef CRASHDUMP_POWERPC_H
+#define CRASHDUMP_POWERPC_H
+
+struct kexec_info;
+int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
+				unsigned long max_addr, unsigned long min_base);
+void add_usable_mem_rgns(unsigned long long base, unsigned long long size);
+
+extern struct arch_options_t arch_options;
+
+#ifdef CONFIG_PPC64
+#define PAGE_OFFSET	0xC000000000000000UL
+#define VMALLOCBASE	0xD000000000000000UL
+#define MAXMEM		(-KERNELBASE-VMALLOCBASE)
+#else
+#define PAGE_OFFSET	0xC0000000
+#define MAXMEM		0x30000000 /* Use CONFIG_LOWMEM_SIZE from kernel */
+#endif
+
+#define KERNELBASE	PAGE_OFFSET
+#define __pa(x)		((unsigned long)(x)-PAGE_OFFSET)
+
+#define COMMAND_LINE_SIZE	512 /* from kernel */
+/* Backup Region, First 64K of System RAM. */
+#define BACKUP_SRC_START	0x0000
+#define BACKUP_SRC_END		0xffff
+#define BACKUP_SRC_SIZE		(BACKUP_SRC_END - BACKUP_SRC_START + 1)
+
+#define KDUMP_BACKUP_LIMIT	BACKUP_SRC_SIZE
+#define _ALIGN_UP(addr, size)	(((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN_DOWN(addr, size)	((addr)&(~((size)-1)))
+
+extern unsigned long long crash_base;
+extern unsigned long long crash_size;
+extern unsigned int rtas_base;
+extern unsigned int rtas_size;
+
+#endif /* CRASHDUMP_POWERPC_H */
kexec/arch/ppc/fs2dt.c new file +460 -0

460 lines not on this page · raw message

kexec/arch/ppc/kexec-elf-ppc.c +169 -17

277 lines not on this page · raw message

kexec/arch/ppc/kexec-ppc.c +260 -15

366 lines not on this page · raw message

kexec/arch/ppc/kexec-ppc.h +32 -0
index 6cec467..fc0471f 100644
@@ -1,6 +1,11 @@
 #ifndef KEXEC_PPC_H
 #define KEXEC_PPC_H
 
+#define MAXBYTES	128
+#define MAX_LINE	160
+#define CORE_TYPE_ELF32	1
+#define CORE_TYPE_ELF64	2
+
 extern unsigned char setup_simple_start[];
 extern uint32_t setup_simple_size;
 
@@ -16,6 +21,8 @@ extern struct {
 	uint32_t spr8;
 } setup_dol_regs;
 
+#define SIZE_16M	(16*1024*1024UL)
+
 int elf_ppc_probe(const char *buf, off_t len);
 int elf_ppc_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
@@ -37,4 +44,29 @@ void dol_ppc_usage(void);
  */
 #define KERNEL_ACCESS_TOP (24 * 1024 * 1024)
 
+/* boot block version 17 as defined by the linux kernel */
+struct bootblock {
+	unsigned magic,
+		totalsize,
+		off_dt_struct,
+		off_dt_strings,
+		off_mem_rsvmap,
+		version,
+		last_comp_version,
+		boot_physid,
+		dt_strings_size,
+		dt_struct_size;
+};
+
+typedef struct mem_rgns {
+	unsigned int size;
+	struct memory_range *ranges;
+} mem_rgns_t;
+extern mem_rgns_t usablemem_rgns;
+extern int max_memory_ranges;
+extern unsigned long long initrd_base, initrd_size;
+extern unsigned char reuse_initrd;
+#define COMMAND_LINE_SIZE	512 /* from kernel */
+/*fs2dt*/
+void reserve(unsigned long long where, unsigned long long length);
 #endif /* KEXEC_PPC_H */
purgatory/arch/ppc/Makefile +1 -1
index 0dd18b6..72289a0 100644
@@ -2,7 +2,7 @@
 # Purgatory ppc
 #
 
-ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap.S
+ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c
purgatory/arch/ppc/purgatory-ppc.c +30 -8
index 01d0f38..3d7d484 100644
@@ -1,19 +1,41 @@
+/*
+ * kexec: Linux boots Linux
+ *
+ * Created by: Mohan Kumar M ([email protected])
+ *
+ * Copyright (C) IBM Corporation, 2005. All rights reserved
+ *
+ * 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.
+ */
+
 #include <purgatory.h>
 #include "purgatory-ppc.h"
 
-unsigned int pul_stack = 0;
-unsigned int dt_offset = 0;
-unsigned int kernel = 0;
-unsigned int epapr_magic = 0;
-unsigned int mem_size = 0;
+unsigned int panic_kernel = 0;
+unsigned long backup_start = 0;
+unsigned long stack = 0;
+unsigned long dt_offset = 0;
+unsigned long my_toc = 0;
+unsigned long kernel = 0;
 
 void setup_arch(void)
 {
-	/* Nothing for now */
+	return;
 }
 
-/* This function can be used to execute after the SHA256 verification. */
 void post_verification_setup_arch(void)
 {
-	/* Nothing for now */
+	if (panic_kernel)
+		crashdump_backup_memory();
 }
purgatory/arch/ppc/purgatory-ppc.h +2 -2
index e931cae..7eff8aa 100644
@@ -1,6 +1,6 @@
 #ifndef PURGATORY_PPC_H
 #define PURGATORY_PPC_H
 
-/* nothing yet */
-
+void crashdump_backup_memory(void);
+void post_verification_setup_arch(void);
 #endif /* PURGATORY_PPC_H */
purgatory/arch/ppc/v2wrap.S deleted +0 -66

66 lines not on this page · raw message

purgatory/arch/ppc/v2wrap_32.S new file +91 -0

91 lines not on this page · raw message

#1 lore raw

PATCH v2 2/2 powerpc new toolchains fix (crt.S)

Hello everybody,

Changes from previous version:
- removed bogus hyphen from the patch;
- move ifdefs to crt.S instead of Makefile

Please find here patch for user land kexec-tools application. Following patch makes kexec-tools work for both kexec and kdump. I tested it with git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with mpc83xx_defconfig kernel config.

kexec:
kexec -l vmlinux --command-line="console= ... etc" kexec -e

kdump:
kexec -p vmlinux_dump --command-line="console=... etc" echo c > /proc/sysrq-trigger

I also think that is is reasonable:
- put GAME_CUBE specific code to separate files;
- combine ppc and ppc64 to powerpc directory (I'm planning to do it. And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

From: Maxim Uvarov <[email protected]>

Linker does not provide some vital functions when building freestanding applications with a new toolchain, so we have to provide our own CRT.

p.s.
Without the CRT we won't see any build errors (since the purgatory is linked with --no-undefined), but the purgatory code won't work, 'kexec -e' will just hang the board.

I added option to configure to keep code buildable for old toolchais. But there should be way to do this automatically.

Author: Anton Vorontsov <[email protected]>

---

 configure.ac                |    9 +
 purgatory/arch/ppc/Makefile |    1 
 purgatory/arch/ppc/crt.S    |  263 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 273 insertions(+), 0 deletions(-)
 create mode 100644 purgatory/arch/ppc/crt.S
configure.ac +9 -0
index fcf50e4..63606bc 100644
@@ -159,6 +159,15 @@ if test "$with_xen" = yes ; then
 		AC_MSG_NOTICE([Xen support disabled])))
 fi
 
+dnl new toolchains
+if test "$ARCH" = ppc; then
+AC_ARG_WITH([oldtoolchain],
+		AC_HELP_STRING([--with-oldtoolchain],[compile without crt.S
+			required for new toolchains]),
+		AC_DEFINE(PPC_OLDTOOLCHAIN, 1,
+			[Define to compile with old toolchains]))
+fi
+
 dnl ---Sanity checks
 if test "$CC"      = "no"; then AC_MSG_ERROR([cc not found]); fi
 if test "$CPP"     = "no"; then AC_MSG_ERROR([cpp not found]); fi
purgatory/arch/ppc/Makefile +1 -0
index 72289a0..4020778 100644
@@ -6,6 +6,7 @@ ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap_32.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/misc.S
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/purgatory-ppc.c
 ppc_PURGATORY_SRCS += purgatory/arch/ppc/console-ppc.c
+ppc_PURGATORY_SRCS += purgatory/arch/ppc/crt.S
 
 dist += purgatory/arch/ppc/Makefile $(ppc_PURGATORY_SRCS)		\
 	purgatory/arch/ppc/purgatory-ppc.h purgatory/arch/ppc/ppc_asm.h
purgatory/arch/ppc/crt.S new file +263 -0

263 lines not on this page · raw message

#2 lore raw

Re: [PATCH v2 2/2] powerpc new toolchains fix (crt.S)

Quoted 21 lines · Maxim Uvarov

Hello everybody,

Changes from previous version:
- removed bogus hyphen from the patch;
- move ifdefs to crt.S instead of Makefile

Please find here patch for user land kexec-tools application. Following patch makes kexec-tools work for both kexec and kdump. I tested it with git kernel (linus-tree) and Freescale/Logic MPC8360ERDK board with mpc83xx_defconfig kernel config.

kexec:
kexec -l vmlinux --command-line="console= ... etc" kexec -e

kdump:
kexec -p vmlinux_dump --command-line="console=... etc" echo c > /proc/sysrq-trigger

Quoted 7 lines

I also think that is is reasonable:
- put GAME_CUBE specific code to separate files;
- combine ppc and ppc64 to powerpc directory (I'm planning to do it. And that why in some places my patch have ifdefs for PPC64);

Best regards,
Maxim Uvarov.

Thanks,

I'm assuming that the silence that this patch set received,
in contrast to the first revision where there was some quick discussion, means that everyone is ok with these changes. So I've gone ahead and pushed them into the tree.

Quoted 5 lines

From: Maxim Uvarov <[email protected]>

Linker does not provide some vital functions when building freestanding applications with a new toolchain, so we have to provide our own CRT.

Quoted 8 lines

p.s.
Without the CRT we won't see any build errors (since the purgatory is linked with --no-undefined), but the purgatory code won't work, 'kexec -e' will just hang the board.

I added option to configure to keep code buildable for old toolchais. But there should be way to do this automatically.

I seem to have an old toolchain :-)

Quoted 3 lines

Author: Anton Vorontsov <[email protected]>

#3 lore raw

Re: [PATCH v2 2/2] powerpc new toolchains fix (crt.S)

In reply to Maxim Uvarov
Quoted 2 lines

Linker does not provide some vital functions when building freestanding applications with a new toolchain,

That's because the compiler provides those functions, not the linker.

Quoted 1 line

so we have to provide our own CRT.

...in libgcc. Why don't you link against that?

Quoted 3 lines

p.s.
Without the CRT we won't see any build errors (since the purgatory is linked with --no-undefined), but the purgatory code won't work,

It would be nice if the build would check if anything unexpectedly undefined is left.

Segher

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

Re: [PATCH v2 2/2] powerpc new toolchains fix (crt.S)

Quoted 9 lines · Segher Boessenkool
Quoted 3 lines

Linker does not provide some vital functions when building freestanding
applications with a new toolchain,

That's because the compiler provides those functions, not the linker.

Quoted 1 line

so we have to provide our own CRT.

...in libgcc. Why don't you link against that?

For the same reason we don't link kernel against libgcc? I.e. just a matter of taste. There are two camps: those who argue against libgcc, and those who argue for libgcc.

Hey! You were in this thread! :-)

http://www.mail-archive.com/[email protected]/msg17224.html

Purgatory is just a small (tiny) piece of code that runs between kernels. Whether use libgcc or not, personally, I have no strong opinion. Kexec didn't use it, so we kept it the same way.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2