Skip to contentSkip to conversation

kexec support for ppc32 (v2)

PATCH Superseded Sebastian Andrzej Siewior 2 participants 9 messages Nov 3, 2008 – Nov 4, 2008

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

The patches:
1: not ppc32 related, noticed while I tried to load dtb/kernel from an ubi
device node.
2: the second version of purgatory & dtb support for ppc32.
Changelog:
v1: removed run time change between dreamcast and device tree aware
arch and switched to ifdef
3: libfdt. This library is used for device tree handling and is not
packaged. I'm not sure if upstream wants to support shared libraries and maintain a stable api. This whole patch has 109KiB and is available at [1] I did not want to spam the list.
PPC64 is creating the nodes by hand and they can't replaces nodes.
4: Uses the libfdt to replaces some nodes. Usually the bootloader sets
some properties which are auto enabled like clock speed or MAC address. This patch allows to take an almost complete device tree and update the missing nodes from the actual device tree.

[1] http://download.breakpoint.cc/0003-powerpc32-pull-in-libfdt.patch

Sebastian

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

#1 lore raw

PATCH 1/4 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 it means 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 |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
kexec/kexec.c +20 -2
index 0616091..3c3f73e 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,25 @@ 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.0.2


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

Re: [PATCH 1/4] slurpfile: use lseek() on character nodes instead of fstat() for file size

Quoted 38 lines · Sebastian Andrzej Siewior

From: Sebastian Andrzej Siewior <[email protected]>

fstat() is used to determine the filesize before read() and it requires a filesystem. That it means 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 |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
kexec/kexec.c +6 -2
index 0616091..3c3f73e 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,25 @@ 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
+	 */

kexec/kexec.c char *slurp_file(const char *filename, off_t *r_size) · line 503

Quoted 10 lines
kexec/kexec.c +10 -0
+	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));

Please reformat these lines so they are <= 80 columns wide.

Quoted 15 lines
kexec/kexec.c +4 -0
+	} else {
+		size = stats.st_size;
+	}
+
 	*r_size = size;
 	buf = xmalloc(size);
 	progress = 0;
Signature · 7 lines
1.6.0.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Signature · 9 lines
Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/             W: www.valinux.co.jp/en


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

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

fstat() is used to determine the filesize before read() and it requires a filesystem. That it means 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 0616091..6f1cb76 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.5.6.5


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

PATCH 2/4 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 containd cuImage (incl. dtb / without the need for a bd sturct) can be booted. The dtb support is currently optional and will be better supported soon.

---
 kexec/arch/ppc/kexec-elf-ppc.c     |  118 +++++++--
 kexec/arch/ppc/kexec-elf-rel-ppc.c |    4 +
 kexec/arch/ppc/kexec-ppc.c         |  468 +++++++++++++++++++++++++++++++++++-
 kexec/arch/ppc/kexec-ppc.h         |    1 +
 purgatory/arch/ppc/Makefile        |    1 +
 purgatory/arch/ppc/purgatory-ppc.c |    6 +
 purgatory/arch/ppc/v2wrap.S        |   66 +++++
 7 files changed, 633 insertions(+), 31 deletions(-)
 create mode 100644 purgatory/arch/ppc/v2wrap.S
kexec/arch/ppc/kexec-elf-ppc.c +91 -27
index 530e501..d58c4b5 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,52 @@ 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,
+				elf_max_addr(&ehdr), -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;
+#if 0
+	elf_rel_get_symbol(&info->rhdr, "pul_stack", &addr, sizeof(addr));
+	printf("Stack is: %08x\n", addr);
+	elf_rel_get_symbol(&info->rhdr, "kernel", &addr, sizeof(addr));
+	printf("Kernel is entry: %08x\n", addr);
+	elf_rel_get_symbol(&info->rhdr, "dt_offset", &addr, sizeof(addr));
+	printf("dtb is: %08x\n", addr);
+	elf_rel_get_symbol(&info->rhdr, "mem_size", &addr, sizeof(addr));
+	printf("imma is: %08x\n", addr);
+#endif
+#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 +464 -4

493 lines not on this page · raw message

kexec/arch/ppc/kexec-ppc.h +1 -0
index 6a40cc8..7ef90b3 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;
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.0.2


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

PATCH 3/4 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 mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Re: [PATCH 3/4] powerpc32: pull in libfdt

Quoted 11 lines · 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

Quoted 5 lines

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.

The diff seems to be missing :-)

Quoted 41 lines
---
 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 mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Signature · 9 lines
Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/             W: www.valinux.co.jp/en


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

Re: [PATCH 3/4] powerpc32: pull in libfdt

Quoted 12 lines · * Simon Horman | 2008-11-04 10:19:53 [+1100]:
Quoted 11 lines · 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

Quoted 7 lines
Quoted 5 lines

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.

The diff seems to be missing :-)

As I wrote in 0/4 I omited it on purpose. If you insists, here it is :)
---

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.0.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.

#8 lore raw

PATCH 4/4 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.

---
 kexec/arch/ppc/fixup_dtb.c     |  105 ++++++++++++++++++++++++++++++++++++++++
 kexec/arch/ppc/fixup_dtb.h     |    6 ++
 kexec/arch/ppc/kexec-elf-ppc.c |   38 +++++++++++++--
 3 files changed, 145 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..24e7e82
@@ -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++;
+	};
+}
+
+static void fixup_cmdline(const char *cmdline)
+{
+	void *chosen;
+
+	if (!cmdline)
+		return;
+
+	chosen = finddevice("/chosen");
+	if (!chosen)
+		chosen = create_node(NULL, "chosen");
+
+	setprop_str(chosen, "bootargs", cmdline);
+}
+
+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);
+#if 0
+	{
+		int fd;
+
+		fd = open("out.dtb", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+		if (fd < 0)
+			fatal("Can't create file: %s\n", strerror(errno));
+
+		write(fd, blob_buf, *blob_size);
+		close(fd);
+	}
+#endif
+	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 +34 -4
index d58c4b5..ae72a8f 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,34 @@ 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;
 	}
 
+	if (!command_line) {
+		if (cur_fixup >= FIXUP_ENTRYS) {
+			fprintf(stderr, "Need one fixup entry for command line\n");
+			exit(1);
+		}
+		fixup_nodes[cur_fixup] = "/chosen/bootargs";
+		cur_fixup++;
+	}
+
+	fixup_nodes[cur_fixup] = NULL;
+
 	/* Parse the Elf file */
 	result = build_elf_exec_info(buf, len, &ehdr, 0);
 	if (result < 0) {
@@ -247,12 +276,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,
 				elf_max_addr(&ehdr), -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.0.2


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