Skip to contentSkip to conversation

powerpc32 support with device tree

PATCH New Sebastian Andrzej Siewior 2 participants 8 messages Jan 19, 2010 – Feb 17, 2010

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

I've rebased my old patches on top of current kexec-tools tree and added support for the uImage target. There was no negative feedback the last I have posted as far I remember.

Now that there is uImage support, there is no need for a wrapper around the kernel:
kexec -l uImage --dtb=file.dtb

If the device tree does not contain the current memory size, clocks, mac address, ... the --reuse-node option can be used in order to set the value to the "current" value. This value is obtained from /proc/device-tree so it requires that the kernel exports the device tree.

I'm currently not sure if the --reuse-node option is very convenient to use. Another way to go would be to suck the complete device tree via /proc and only update the command line. Any comments on this?

There are two more things sitting on my todo list: SMP support & initrd.

The patch series is also available in the git repository at:

git://breakpoint.cc/bigeasy/kexec-tools ppc32

Sebastian

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

#1 lore raw

PATCH 1/5 slurpfile: use lseek() on character nodes instead of fstat() for file size

From: Sebastian Andrzej Siewior <[email protected]>

fstat() is used to determine the filesize before read() and it requires a filesystem. That means that it can not be used on character nodes. This makes it impossible to obtains the kernel from a char node like mtd or more likely ubi. We can't use this in every case because files in /proc don't support lseek(). This is required by the powerpc part to read some device-tree entries.

---
 kexec/kexec.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
kexec/kexec.c +21 -2
index a1cec86..6baa2d8 100644
@@ -467,7 +467,7 @@ char *slurp_file(const char *filename, off_t *r_size)
 {
 	int fd;
 	char *buf;
-	off_t size, progress;
+	off_t size, progress, err;
 	ssize_t result;
 	struct stat stats;
 	
@@ -486,7 +486,26 @@ char *slurp_file(const char *filename, off_t *r_size)
 		die("Cannot stat: %s: %s\n",
 			filename, strerror(errno));
 	}
-	size = stats.st_size;
+	/*
+	 * Seek in case the kernel is a character node like /dev/ubi0_0.
+	 * This does not work on regular files which live in /proc and
+	 * we need this for some /proc/device-tree entries
+	 */
+	if (S_ISCHR(stats.st_mode)) {
+
+		size = lseek(fd, 0, SEEK_END);
+		if (size < 0)
+			die("Can not seek file %s: %s\n", filename,
+					strerror(errno));
+
+		err = lseek(fd, 0, SEEK_SET);
+		if (err < 0)
+			die("Can not seek to the begin of file %s: %s\n",
+					filename, strerror(errno));
+	} else {
+		size = stats.st_size;
+	}
+
 	*r_size = size;
 	buf = xmalloc(size);
 	progress = 0;
Signature · 7 lines
1.6.5.2


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

PATCH 2/5 powerpc: dtb and purgatory support for ppc32

In reply to Sebastian Andrzej Siewior

From: Sebastian Andrzej Siewior <[email protected]>

Some code dtb scanning & filling has been borrowed from ppc64. The old behavior is still available if compiled with GameCube, other PowerPC platform use the can purgatory and specify a new dtb.
Booting a self contained elf image (incl. dtb / without the need for a bd sturct or the like) can be booted. The dtb support is currently optional. That means if the elf image does not contain a dtb file then the user has to supply a complete dtb (including mem size, command line, bus freq., mac addr, ...)

---
 kexec/arch/ppc/kexec-elf-ppc.c     |  108 +++++++---
 kexec/arch/ppc/kexec-elf-rel-ppc.c |    4 +
 kexec/arch/ppc/kexec-ppc.c         |  447 +++++++++++++++++++++++++++++++++++-
 kexec/arch/ppc/kexec-ppc.h         |    7 +
 purgatory/arch/ppc/Makefile        |    1 +
 purgatory/arch/ppc/purgatory-ppc.c |    6 +
 purgatory/arch/ppc/v2wrap.S        |   66 ++++++
 7 files changed, 608 insertions(+), 31 deletions(-)
 create mode 100644 purgatory/arch/ppc/v2wrap.S
kexec/arch/ppc/kexec-elf-ppc.c +81 -27
index 530e501..03b8a94 100644
@@ -91,16 +91,6 @@ int elf_ppc_probe(const char *buf, off_t len)
 	return result;
 }
 
-void elf_ppc_usage(void)
-{
-	printf
-	    (
-	     "    --command-line=STRING Set the kernel command line to STRING.\n"
-	     "    --append=STRING       Set the kernel command line to STRING.\n"
-	     "    --gamecube=1|0        Enable/disable support for ELFs with changed\n"
-	     "                          addresses suitable for the GameCube.\n");
-}
-
 static void gamecube_hack_addresses(struct mem_ehdr *ehdr)
 {
 	struct mem_phdr *phdr, *phdr_end;
@@ -122,39 +112,56 @@ static void gamecube_hack_addresses(struct mem_ehdr *ehdr)
 	}
 }
 
+#define OPT_APPEND	(OPT_ARCH_MAX+0)
+#define OPT_GAMECUBE	(OPT_ARCH_MAX+1)
+#define OPT_DTB		(OPT_ARCH_MAX+2)
+static const struct option options[] = {
+	KEXEC_ARCH_OPTIONS
+	{"command-line", 1, 0, OPT_APPEND},
+	{"append",       1, 0, OPT_APPEND},
+	{"gamecube",     1, 0, OPT_GAMECUBE},
+	{"dtb",     1, 0, OPT_DTB},
+	{0, 0, 0, 0},
+};
+static const char short_options[] = KEXEC_ARCH_OPT_STR "d";
+
+void elf_ppc_usage(void)
+{
+	printf(
+	     "    --command-line=STRING Set the kernel command line to STRING.\n"
+	     "    --append=STRING       Set the kernel command line to STRING.\n"
+	     "    --gamecube=1|0        Enable/disable support for ELFs with changed\n"
+	     "                          addresses suitable for the GameCube.\n"
+	     "     --dtb=<filename> Specify device tree blob file.\n"
+	     );
+}
+
 int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len, 
 	struct kexec_info *info)
 {
 	struct mem_ehdr ehdr;
+	char *command_line;
+	int command_line_len;
+	char *dtb;
+	int result;
+#ifdef WITH_GAMECUBE
+	int target_is_gamecube = 1;
 	char *arg_buf;
 	size_t arg_bytes;
 	unsigned long arg_base;
 	struct boot_notes *notes;
 	size_t note_bytes;
-	const char *command_line;
-	int command_line_len;
 	unsigned char *setup_start;
 	uint32_t setup_size;
-	int result;
-#ifdef WITH_GAMECUBE
-	int target_is_gamecube = 1;
 #else
 	int target_is_gamecube = 0;
+	unsigned int addr;
+	unsigned long dtb_addr;
 #endif
 	int opt;
-#define OPT_APPEND	(OPT_ARCH_MAX+0)
-#define OPT_GAMECUBE	(OPT_ARCH_MAX+1)
-	static const struct option options[] = {
-		KEXEC_ARCH_OPTIONS
-		{"command-line", 1, 0, OPT_APPEND},
-		{"append",       1, 0, OPT_APPEND},
-		{"gamecube",     1, 0, OPT_GAMECUBE},
-		{0, 0, 0, 0},
-	};
 
-	static const char short_options[] = KEXEC_ARCH_OPT_STR "d";
-
-	command_line = 0;
+	command_line = NULL;
+	dtb = NULL;
 	while ((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch (opt) {
 		default:
@@ -171,6 +178,10 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 		case OPT_GAMECUBE:
 			target_is_gamecube = atoi(optarg);
 			break;
+
+		case OPT_DTB:
+			dtb = optarg;
+			break;
 		}
 	}
 	command_line_len = 0;
@@ -194,6 +205,12 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 		return result;
 	}
 
+	/*
+	 * In case of a toy we take the hardcoded things and an easy setup via
+	 * one of the assembly startups. Every thing else should be grown up
+	 * and go through the purgatory.
+	 */
+#ifdef WITH_GAMECUBE
 	if (target_is_gamecube) {
 		setup_start = setup_dol_start;
 		setup_size = setup_dol_size;
@@ -220,5 +237,42 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 	notes->hdr.b_checksum = compute_ip_checksum(notes, note_bytes);
 
 	info->entry = (void *)arg_base;
+#else
+	elf_rel_build_load(info, &info->rhdr, (const char *)purgatory,
+			purgatory_size, 0, elf_max_addr(&ehdr), 1, 0);
+
+	if (dtb) {
+		char *blob_buf;
+		off_t blob_size = 0;
+
+		/* Grab device tree from buffer */
+		blob_buf = slurp_file(dtb, &blob_size);
+		dtb_addr = add_buffer(info, blob_buf, blob_size, blob_size, 0, 0,
+				KERNEL_ACCESS_TOP, -1);
+		if (command_line)
+			die("Don't consider command line because dtb is supplied\n");
+	} else {
+		die("Missing dtb.\n");
+	}
+
+	/* set various variables for the purgatory */
+	addr = ehdr.e_entry;
+	elf_rel_set_symbol(&info->rhdr, "kernel", &addr, sizeof(addr));
+
+	addr = dtb_addr;
+	elf_rel_set_symbol(&info->rhdr, "dt_offset", &addr, sizeof(addr));
+
+	addr = rmo_top;
+	elf_rel_set_symbol(&info->rhdr, "mem_size", &addr, sizeof(addr));
+
+#define PUL_STACK_SIZE	(16 * 1024)
+	addr = locate_hole(info, PUL_STACK_SIZE, 0, 0, elf_max_addr(&ehdr), 1);
+	addr += PUL_STACK_SIZE;
+	elf_rel_set_symbol(&info->rhdr, "pul_stack", &addr, sizeof(addr));
+#undef PUL_STACK_SIZE
+
+	addr = elf_rel_get_addr(&info->rhdr, "purgatory_start");
+	info->entry = (void *)addr;
+#endif
 	return 0;
 }
kexec/arch/ppc/kexec-elf-rel-ppc.c +4 -0
index e711f3b..9a66bed 100644
@@ -31,6 +31,10 @@ void machine_apply_elf_rel(struct mem_ehdr *ehdr, unsigned long r_type,
 		*(uint16_t *)location = value;
 		break;
 		
+	case R_PPC_ADDR16_HI:
+		*(uint16_t *)location = (value>>16) & 0xffff;
+		break;
+
 	case R_PPC_ADDR16_HA:
 		/* Sign-adjusted lower 16 bits: PPC ELF ABI says:
 		   (((x >> 16) + ((x & 0x8000) ? 1 : 0))) & 0xFFFF.
kexec/arch/ppc/kexec-ppc.c +443 -4

472 lines not on this page · raw message

kexec/arch/ppc/kexec-ppc.h +7 -0
index 6a40cc8..1b2b015 100644
@@ -10,6 +10,7 @@ extern struct {
 
 extern unsigned char setup_dol_start[];
 extern uint32_t setup_dol_size;
+extern uint64_t rmo_top;
 
 extern struct {
 	uint32_t spr8;
@@ -25,4 +26,10 @@ int dol_ppc_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
 void dol_ppc_usage(void);
 
+/*
+ * During inital setup the kernel does not map the whole memory but a part of
+ * it. On Book-E that is 64MiB, 601 24MiB or 256MiB (if possible).
+ */
+#define KERNEL_ACCESS_TOP (24 * 1024 * 1024)
+
 #endif /* KEXEC_PPC_H */
purgatory/arch/ppc/Makefile +1 -0
index 69fd46c..0dd18b6 100644
@@ -2,6 +2,7 @@
 # Purgatory ppc
 #
 
+ppc_PURGATORY_SRCS += purgatory/arch/ppc/v2wrap.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 +6 -0
index 077f495..01d0f38 100644
@@ -1,6 +1,12 @@
 #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;
+
 void setup_arch(void)
 {
 	/* Nothing for now */
purgatory/arch/ppc/v2wrap.S new file +66 -0

66 lines not on this page · raw message

Signature · 7 lines
1.6.5.2


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

PATCH 3/5 powerpc32: pull in libfdt

In reply to Sebastian Andrzej Siewior

From: Sebastian Andrzej Siewior <[email protected]>

This is v1.2.0 of libfdt from the dtc project which is available at
git://www.jdl.com/software/dtc.git

The other files
- include/page.h
- include/types.h
- libfdt-wrapper.c
- ops.h

are part of the glue code which is used the powerpc boot wrapper code is comming from the Linux kernel v2.6.27-rc6 and has been modified a little to fit.

---
 kexec/arch/ppc/Makefile                 |   11 +-
 kexec/arch/ppc/include/page.h           |   34 +
 kexec/arch/ppc/include/types.h          |   27 +
 kexec/arch/ppc/libfdt-wrapper.c         |  189 ++++++
 kexec/arch/ppc/libfdt/Makefile.libfdt   |    8 +
 kexec/arch/ppc/libfdt/TODO              |    3 +
 kexec/arch/ppc/libfdt/fdt.c             |  201 ++++++
 kexec/arch/ppc/libfdt/fdt.h             |   60 ++
 kexec/arch/ppc/libfdt/fdt_ro.c          |  466 +++++++++++++
 kexec/arch/ppc/libfdt/fdt_rw.c          |  463 +++++++++++++
 kexec/arch/ppc/libfdt/fdt_strerror.c    |   96 +++
 kexec/arch/ppc/libfdt/fdt_sw.c          |  257 ++++++++
 kexec/arch/ppc/libfdt/fdt_wip.c         |  145 +++++
 kexec/arch/ppc/libfdt/libfdt.h          | 1076 +++++++++++++++++++++++++++++++
 kexec/arch/ppc/libfdt/libfdt_env.h      |   23 +
 kexec/arch/ppc/libfdt/libfdt_internal.h |   95 +++
 kexec/arch/ppc/ops.h                    |  151 +++++
 17 files changed, 3304 insertions(+), 1 deletions(-)
 create mode 100644 kexec/arch/ppc/include/page.h
 create mode 100644 kexec/arch/ppc/include/types.h
 create mode 100644 kexec/arch/ppc/libfdt-wrapper.c
 create mode 100644 kexec/arch/ppc/libfdt/Makefile.libfdt
 create mode 100644 kexec/arch/ppc/libfdt/TODO
 create mode 100644 kexec/arch/ppc/libfdt/fdt.c
 create mode 100644 kexec/arch/ppc/libfdt/fdt.h
 create mode 100644 kexec/arch/ppc/libfdt/fdt_ro.c
 create mode 100644 kexec/arch/ppc/libfdt/fdt_rw.c
 create mode 100644 kexec/arch/ppc/libfdt/fdt_strerror.c
 create mode 100644 kexec/arch/ppc/libfdt/fdt_sw.c
 create mode 100644 kexec/arch/ppc/libfdt/fdt_wip.c
 create mode 100644 kexec/arch/ppc/libfdt/libfdt.h
 create mode 100644 kexec/arch/ppc/libfdt/libfdt_env.h
 create mode 100644 kexec/arch/ppc/libfdt/libfdt_internal.h
 create mode 100644 kexec/arch/ppc/ops.h
kexec/arch/ppc/Makefile +10 -1
index 1550c20..90dfa5b 100644
@@ -1,6 +1,8 @@
 #
 # kexec ppc (linux booting linux)
 #
+include kexec/arch/ppc/libfdt/Makefile.libfdt
+
 ppc_KEXEC_SRCS =  kexec/arch/ppc/kexec-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-rel-ppc.c
@@ -8,7 +10,14 @@ ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-dol-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-simple.S
 ppc_KEXEC_SRCS += kexec/arch/ppc/ppc-setup-dol.S
 
+libfdt_SRCS = kexec/arch/ppc/libfdt-wrapper.c
+libfdt_SRCS += kexec/arch/ppc/fixup_dtb.c
+libfdt_SRCS += $(LIBFDT_SRCS:%=kexec/arch/ppc/libfdt/%)
+
+CPPFLAGS+=-I$(srcdir)/kexec/arch/$(ARCH)/libfdt
+
+ppc_KEXEC_SRCS += $(libfdt_SRCS)
+
 dist += kexec/arch/ppc/Makefile $(ppc_KEXEC_SRCS)			\
 	kexec/arch/ppc/kexec-ppc.h kexec/arch/ppc/ppc_asm.h		\
 	kexec/arch/ppc/include/arch/options.h
-
kexec/arch/ppc/include/page.h new file +34 -0
new file mode 100644
index 0000000..14eca30
@@ -0,0 +1,34 @@
+#ifndef _PPC_BOOT_PAGE_H
+#define _PPC_BOOT_PAGE_H
+/*
+ * Copyright (C) 2001 PPC64 Team, IBM Corp
+ *
+ * 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; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifdef __ASSEMBLY__
+#define ASM_CONST(x) x
+#else
+#define __ASM_CONST(x) x##UL
+#define ASM_CONST(x) __ASM_CONST(x)
+#endif
+
+/* PAGE_SHIFT determines the page size */
+#define PAGE_SHIFT	12
+#define PAGE_SIZE	(ASM_CONST(1) << PAGE_SHIFT)
+#define PAGE_MASK	(~(PAGE_SIZE-1))
+
+/* align addr on a size boundary - adjust address up/down if needed */
+#define _ALIGN_UP(addr,size)	(((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN_DOWN(addr,size)	((addr)&(~((size)-1)))
+
+/* align addr on a size boundary - adjust address up if needed */
+#define _ALIGN(addr,size)     _ALIGN_UP(addr,size)
+
+/* to align the pointer to the (next) page boundary */
+#define PAGE_ALIGN(addr)	_ALIGN(addr, PAGE_SIZE)
+
+#endif				/* _PPC_BOOT_PAGE_H */
kexec/arch/ppc/include/types.h new file +27 -0
new file mode 100644
index 0000000..31393d1
@@ -0,0 +1,27 @@
+#ifndef _TYPES_H_
+#define _TYPES_H_
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+typedef unsigned char		u8;
+typedef unsigned short		u16;
+typedef unsigned int		u32;
+typedef unsigned long long	u64;
+typedef signed char		s8;
+typedef short			s16;
+typedef int			s32;
+typedef long long		s64;
+
+#define min(x,y) ({ \
+	typeof(x) _x = (x);	\
+	typeof(y) _y = (y);	\
+	(void) (&_x == &_y);	\
+	_x < _y ? _x : _y; })
+
+#define max(x,y) ({ \
+	typeof(x) _x = (x);	\
+	typeof(y) _y = (y);	\
+	(void) (&_x == &_y);	\
+	_x > _y ? _x : _y; })
+
+#endif /* _TYPES_H_ */
kexec/arch/ppc/libfdt-wrapper.c new file +189 -0

189 lines not on this page · raw message

kexec/arch/ppc/libfdt/Makefile.libfdt new file +8 -0
new file mode 100644
index 0000000..6c42acf
@@ -0,0 +1,8 @@
+# Makefile.libfdt
+#
+# This is not a complete Makefile of itself.  Instead, it is designed to
+# be easily embeddable into other systems of Makefiles.
+#
+LIBFDT_INCLUDES = fdt.h libfdt.h
+LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
+LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
kexec/arch/ppc/libfdt/TODO new file +3 -0
new file mode 100644
index 0000000..288437e
@@ -0,0 +1,3 @@
+- Tree traversal functions
+- Graft function
+- Complete libfdt.h documenting comments
kexec/arch/ppc/libfdt/fdt.c new file +201 -0

201 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt.h new file +60 -0

60 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt_ro.c new file +466 -0

466 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt_rw.c new file +463 -0

463 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt_strerror.c new file +96 -0

96 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt_sw.c new file +257 -0

257 lines not on this page · raw message

kexec/arch/ppc/libfdt/fdt_wip.c new file +145 -0

145 lines not on this page · raw message

kexec/arch/ppc/libfdt/libfdt.h new file +1076 -0

1,028 lines not on this page · raw message

kexec/arch/ppc/libfdt/libfdt_env.h new file +23 -0
new file mode 100644
index 0000000..449bf60

Lines of this file are not shown. View the raw message.

kexec/arch/ppc/libfdt/libfdt_internal.h new file +95 -0

95 lines not on this page · raw message

kexec/arch/ppc/ops.h new file +151 -0

151 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
1.6.5.2


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

Part of the diff is not shown here. View the raw message.

#4 lore raw

PATCH 4/5 powerpc32: add support to fixup the dtb

In reply to Sebastian Andrzej Siewior

From: Sebastian Andrzej Siewior <[email protected]>

A few device nodes are dynamically determined by the bootloader (MAC address, memory size, ..) and are not part of the device tree. The kernel command line is also read from dtb and usually not part of the device tree. With the libfdt it is now easy to add/replace nodes in the device tree. The user may specify "--reuse-node=/memory/reg" to update the memory/reg node to what ever is now. This requires the kernel to export the device tree via the procfs in /proc/device-tree.

---
 kexec/arch/ppc/fixup_dtb.c     |  105 ++++++++++++++++++++++++++++++++++++++++
 kexec/arch/ppc/fixup_dtb.h     |    6 ++
 kexec/arch/ppc/kexec-elf-ppc.c |   29 ++++++++++--
 3 files changed, 136 insertions(+), 4 deletions(-)
 create mode 100644 kexec/arch/ppc/fixup_dtb.c
 create mode 100644 kexec/arch/ppc/fixup_dtb.h
kexec/arch/ppc/fixup_dtb.c new file +105 -0
new file mode 100644
index 0000000..40e9350
@@ -0,0 +1,105 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "../../kexec.h"
+#include <libfdt.h>
+#include "ops.h"
+#include "page.h"
+#include "fixup_dtb.h"
+
+const char proc_dts[] = "/proc/device-tree";
+
+static void fixup_nodes(char *nodes[])
+{
+	int index = 0;
+	char *fname;
+	char *prop_name;
+	char *node_name;
+	void *node;
+	int len;
+	char *content;
+	off_t content_size;
+	int ret;
+
+	while (nodes[index]) {
+
+		len = asprintf(&fname, "%s%s", proc_dts, nodes[index]);
+		if (len < 0)
+			fatal("asprintf() failed\n");
+
+		content = slurp_file(fname, &content_size);
+		if (!content) {
+			fprintf(stderr, "Can't open %s: %s\n",
+					fname, strerror(errno));
+			exit(1);
+		}
+
+		prop_name = fname + len;
+		while (*prop_name != '/')
+			prop_name--;
+
+		*prop_name = '\0';
+		prop_name++;
+
+		node_name = fname + sizeof(proc_dts) - 1;
+
+		node = finddevice(node_name);
+		if (!node)
+			node = create_node(NULL, node_name + 1);
+
+		ret = setprop(node, prop_name, content, content_size);
+		if (ret < 0)
+			fatal("setprop of %s/%s size: %ld failed: %s\n",
+					node_name, prop_name, content_size,
+					fdt_strerror(ret));
+
+		free(content);
+		free(fname);
+		index++;
+	};
+}
+
+/*
+ * command line priority:
+ * - use the supplied command line
+ * - if none available use the command line from .dtb
+ * - if not available use the current command line
+ */
+static void fixup_cmdline(const char *cmdline)
+{
+	void *chosen;
+	char *fixup_cmd_node[] = {
+		"/chosen/bootargs",
+		NULL,
+	};
+
+	chosen = finddevice("/chosen");
+
+	if (!cmdline) {
+		if (!chosen)
+			fixup_nodes(fixup_cmd_node);
+	} else {
+		if (!chosen)
+			chosen = create_node(NULL, "chosen");
+		setprop_str(chosen, "bootargs", cmdline);
+	}
+	return;
+}
+
+char *fixup_dtb_nodes(char *blob_buf, off_t *blob_size, char *nodes[], char *cmdline)
+{
+	fdt_init(blob_buf);
+
+	fixup_nodes(nodes);
+	fixup_cmdline(cmdline);
+
+	blob_buf = (char *)dt_ops.finalize();
+	*blob_size = fdt_totalsize(blob_buf);
+	return blob_buf;
+}
kexec/arch/ppc/fixup_dtb.h new file +6 -0
new file mode 100644
index 0000000..0ff981e
@@ -0,0 +1,6 @@
+#ifndef __FIXUP_DTB_H
+#define __FIXUP_DTB_H
+
+char *fixup_dtb_nodes(char *blob_buf, off_t *blob_size, char *nodes[], char *cmdline);
+
+#endif
kexec/arch/ppc/kexec-elf-ppc.c +25 -4
index 03b8a94..a54a5d5 100644
@@ -25,6 +25,7 @@
 #include <arch/options.h>
 
 #include "config.h"
+#include "fixup_dtb.h"
 
 static const int probe_debug = 0;
 
@@ -115,12 +116,14 @@ static void gamecube_hack_addresses(struct mem_ehdr *ehdr)
 #define OPT_APPEND	(OPT_ARCH_MAX+0)
 #define OPT_GAMECUBE	(OPT_ARCH_MAX+1)
 #define OPT_DTB		(OPT_ARCH_MAX+2)
+#define OPT_NODES	(OPT_ARCH_MAX+3)
 static const struct option options[] = {
 	KEXEC_ARCH_OPTIONS
 	{"command-line", 1, 0, OPT_APPEND},
 	{"append",       1, 0, OPT_APPEND},
 	{"gamecube",     1, 0, OPT_GAMECUBE},
 	{"dtb",     1, 0, OPT_DTB},
+	{"reuse-node",     1, 0, OPT_NODES},
 	{0, 0, 0, 0},
 };
 static const char short_options[] = KEXEC_ARCH_OPT_STR "d";
@@ -132,7 +135,9 @@ void elf_ppc_usage(void)
 	     "    --append=STRING       Set the kernel command line to STRING.\n"
 	     "    --gamecube=1|0        Enable/disable support for ELFs with changed\n"
 	     "                          addresses suitable for the GameCube.\n"
-	     "     --dtb=<filename> Specify device tree blob file.\n"
+	     "     --dtb=<filename>     Specify device tree blob file.\n"
+	     "     --reuse-node=node    Specify nodes which should be taken from /proc/device-tree.\n"
+	     "                          Can be set multiple times.\n"
 	     );
 }
 
@@ -157,6 +162,9 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 	int target_is_gamecube = 0;
 	unsigned int addr;
 	unsigned long dtb_addr;
+#define FIXUP_ENTRYS	(20)
+	char *fixup_nodes[FIXUP_ENTRYS + 1];
+	int cur_fixup = 0;
 #endif
 	int opt;
 
@@ -182,13 +190,25 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 		case OPT_DTB:
 			dtb = optarg;
 			break;
+
+		case OPT_NODES:
+			if (cur_fixup >= FIXUP_ENTRYS) {
+				fprintf(stderr, "The number of entries for the fixup is too large\n");
+				exit(1);
+			}
+			fixup_nodes[cur_fixup] = optarg;
+			cur_fixup++;
+			break;
 		}
 	}
+
 	command_line_len = 0;
 	if (command_line) {
 		command_line_len = strlen(command_line) + 1;
 	}
 
+	fixup_nodes[cur_fixup] = NULL;
+
 	/* Parse the Elf file */
 	result = build_elf_exec_info(buf, len, &ehdr, 0);
 	if (result < 0) {
@@ -247,12 +267,13 @@ int elf_ppc_load(int argc, char **argv,	const char *buf, off_t len,
 
 		/* Grab device tree from buffer */
 		blob_buf = slurp_file(dtb, &blob_size);
+		if (!blob_buf || !blob_size)
+			die("Device tree seems to be an empty file.\n");
+		blob_buf = fixup_dtb_nodes(blob_buf, &blob_size, fixup_nodes, command_line);
 		dtb_addr = add_buffer(info, blob_buf, blob_size, blob_size, 0, 0,
 				KERNEL_ACCESS_TOP, -1);
-		if (command_line)
-			die("Don't consider command line because dtb is supplied\n");
 	} else {
-		die("Missing dtb.\n");
+		dtb_addr = 0;
 	}
 
 	/* set various variables for the purgatory */
Signature · 7 lines
1.6.5.2


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

PATCH 5/5 powerpc32: add support for uImage

In reply to Sebastian Andrzej Siewior

From: Sebastian Andrzej Siewior <[email protected]>

On PowerPC the uImage usually contains the compressed "final" kernel and not a tiny wrapper which relocates itself und uncomprosses the final kernel to its final position. Instead we uncompress the gzip image and put it the its final position.

---
 kexec/arch/ppc/Makefile           |    1 +
 kexec/arch/ppc/kexec-ppc.c        |    1 +
 kexec/arch/ppc/kexec-ppc.h        |    5 +
 kexec/arch/ppc/kexec-uImage-ppc.c |  336 +++++++++++++++++++++++++++++++++++++
 4 files changed, 343 insertions(+), 0 deletions(-)
 create mode 100644 kexec/arch/ppc/kexec-uImage-ppc.c
kexec/arch/ppc/Makefile +1 -0
index 90dfa5b..a6f9a04 100644
@@ -7,6 +7,7 @@ ppc_KEXEC_SRCS =  kexec/arch/ppc/kexec-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-elf-rel-ppc.c
 ppc_KEXEC_SRCS += kexec/arch/ppc/kexec-dol-ppc.c
+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
 
kexec/arch/ppc/kexec-ppc.c +1 -0
index ef22c3d..9708b8c 100644
@@ -485,6 +485,7 @@ int get_memory_ranges(struct memory_range **range, int *ranges,
 struct file_type file_type[] = {
 	{"elf-ppc", elf_ppc_probe, elf_ppc_load, elf_ppc_usage},
 	{"dol-ppc", dol_ppc_probe, dol_ppc_load, dol_ppc_usage},
+	{"uImage-ppc", uImage_ppc_probe, uImage_ppc_load, uImage_ppc_usage },
 };
 int file_types = sizeof(file_type) / sizeof(file_type[0]);
 
kexec/arch/ppc/kexec-ppc.h +5 -0
index 1b2b015..6cec467 100644
@@ -21,6 +21,11 @@ int elf_ppc_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
 void elf_ppc_usage(void);
 
+int uImage_ppc_probe(const char *buf, off_t len);
+int uImage_ppc_load(int argc, char **argv, const char *buf, off_t len,
+	struct kexec_info *info);
+void uImage_ppc_usage(void);
+
 int dol_ppc_probe(const char *buf, off_t len);
 int dol_ppc_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);
kexec/arch/ppc/kexec-uImage-ppc.c new file +336 -0

336 lines not on this page · raw message

Signature · 7 lines
1.6.5.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#6 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 17 lines · Sebastian Andrzej Siewior

I've rebased my old patches on top of current kexec-tools tree and added support for the uImage target. There was no negative feedback the last I have posted as far I remember.

Now that there is uImage support, there is no need for a wrapper around the kernel:
kexec -l uImage --dtb=file.dtb

If the device tree does not contain the current memory size, clocks, mac address, ... the --reuse-node option can be used in order to set the value to the "current" value. This value is obtained from /proc/device-tree so it requires that the kernel exports the device tree.

I'm currently not sure if the --reuse-node option is very convenient to use. Another way to go would be to suck the complete device tree via /proc and only update the command line. Any comments on this?

Quoted 5 lines

There are two more things sitting on my todo list: SMP support & initrd.

The patch series is also available in the git repository at:

git://breakpoint.cc/bigeasy/kexec-tools ppc32

Hi Sebastian,

sorry for taking so long to respond to your email. There are some minor problems with your patchset

1) The last patch breaks the build if zlib isn't installed. Please use HAVE_ZLIB or something similar to resolve this.

2) Patch 3 breaks the built although that is fixed by patch 4. I think I'll let this slip as you're importing code and then fixing it and that seems like a reasonable thing to do in this case.

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

#7 lore raw
Quoted 1 line · * Simon Horman | 2010-02-17 18:54:20 [+1100]:

Hi Sebastian,

Hi Simon,

Quoted 5 lines

sorry for taking so long to respond to your email. There are some minor problems with your patchset

1) The last patch breaks the build if zlib isn't installed. Please use HAVE_ZLIB or something similar to resolve this.

Okay.

Quoted 3 lines

2) Patch 3 breaks the built although that is fixed by patch 4. I think I'll let this slip as you're importing code and then fixing it and that seems like a reasonable thing to do in this case.

I can't think how I break the build and fix it by patch 4 but I will at this.

Sebastian

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