Skip to contentSkip to conversation

add ELF support

RFC In review Antony Pavlov 2 participants 10 messages Dec 19, 2012 – Dec 21, 2012 2 messages not in the archive

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

cover add ELF support

This __PRELIMINARY__ patch series introduces ELF files support in barebox for MIPS architecture, but there is no barriers to adapt it for other architectures.
The two last patches make possible to start linux from barebox on qemu's mips malta board.

ELF support uses a relocator and makes possible to load ELF files, that use the same address ranges that uses barebox, e.g. it make possible to start barebox from barebox.

ELF support is based on kexec (git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git),
but I have discovered some problems with it:
* kexec tryes to duplicate the functions of the existing
barebox image handling framework so IMHO there is no reasons to import
kexec to barebox "as is".
* kexec introduces own data structures for memory regions handling,
but we already have 'struct resource'. So we have no need to import
this part either.
* kexec has coding style errors.

ELF-loader use the following algorithm:
1. it loads entire ELF-file to RAM;
2. it parses the ELF header and choose the loadable segments; (from kexec);
3. it traverses the available memory banks and checks that ELF segments can be loaded;
4. it collects all used by barebox memory ranges (thanks to request_sdram_region() we can do it), in addition it collects all memory ranges that WILL be used after ELF segments relocation. So we can determine all unused in any case memory ranges.
5. The relocation code copy all ELF segments to the unused memory. Also it copy to the unsed memory the table of ELF segments. At last it copy the relocatable "reboot code" to the unused memory. The "reboot code" is written in ASM it can be started from any address.
It takes the address of the table of ELF segments and ELF entry point. The "reboot code" use table to relocate segments and transfer the control to the ELF entry point. (this part is based on mips linux kernel kexec part).

ISSUES

* the relocator is always used;
* some checks from original kexec are skipped;
* just now there is no cache support for MIPS, so there are many conversions to KSEG1;
* check_room_for_elf() uses virt_to_phys();
* unused memory region for storing relocated data segments is selected trivialy: it is the biggest unused region; but we must check the size of the region, and, if necesssary try to find next region;
* some naming cleenup is needed;
* MIPS: linux cmdline handling is missing.

USAGE

barebox:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x1e000000 - 0x1e3fffff (size 0x00400000) cfi_flash0 0xa0000000 - 0xafffffff (size 0x10000000) ram0

    0xa17f9000 - 0xa17fffff (size 0x00007000) stack
    0xa1800000 - 0xa27fffff (size 0x01000000) malloc space
    0xa2800000 - 0xa2d4e464 (size 0x0054e465) barebox
    0xa2d50114 - 0xa2d56bb0 (size 0x00006a9d) bss

0xb80003f8 - 0xb80003ff (size 0x00000008) ns16550_serial0
barebox:/ bootm env/vmlinux.qemu-malta-be
handler failed with No error
barebox:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x1e000000 - 0x1e3fffff (size 0x00400000) cfi_flash0 0xa0000000 - 0xafffffff (size 0x10000000) ram0

    0xa17f9000 - 0xa17fffff (size 0x00007000) stack
    0xa1800000 - 0xa27fffff (size 0x01000000) malloc space
    0xa2800000 - 0xa2d4e464 (size 0x0054e465) barebox
    0xa2d50114 - 0xa2d56bb0 (size 0x00006a9d) bss
    0xa2d56bc0 - 0xa316f29b (size 0x004186dc) kexec relocatable segments
    0xa316f2a0 - 0xa316f307 (size 0x00000068) kexec relocator
    0xa316f310 - 0xa316f31f (size 0x00000010) kexec control segments

0xb80003f8 - 0xb80003ff (size 0x00000008) ns16550_serial0
barebox:/ go 0xa316f2a0
## Starting application at 0xa316f2a0 ...
Linux version 2.6.38.8-malta (antony@luz) (gcc version 4.4.6 (crosstool-NG 1.13.0) ) #1 Fri Oct 28 14:45:36 MSK 2011 memsize not set in boot prom, set to default (32Mb)
Config serial console: console=ttyS0,38400n8r
bootconsole [early0] enabled
CPU revision is: 00019300 (MIPS 24Kc)
FPU revision is: 00000000
...

[RFC 1/5] resource: add create_resource() helper function [RFC 2/5] bootm: add very basic ELF support (stolen from kexec) [RFC 3/5] MIPS: add ELF support
[RFC 4/5] MIPS: qemu-malta: add board label
[RFC 5/5] MIPS: qemu-malta: add YAMON-style GT64120 memory map

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

#1 lore raw

RFC 1/5 resource: add create_resource() helper function

---
 common/resource.c      |   15 +++++++++++++++
 include/linux/ioport.h |    2 ++
 2 files changed, 17 insertions(+)
common/resource.c +15 -0
index ea6abe8..a493e70 100644
@@ -113,3 +113,18 @@ struct resource *request_iomem_region(const char *name,
 {
 	return request_region(&iomem_resource, name, start, end);
 }
+
+struct resource *create_resource(const char *name,
+	resource_size_t start, resource_size_t end)
+{
+	struct resource *t;
+
+	t = xzalloc(sizeof *t);
+	INIT_LIST_HEAD(&t->children);
+	t->parent = NULL;
+	t->name = xstrdup(name);
+	t->start = start;
+	t->end = end;
+
+	return t;
+}
include/linux/ioport.h +2 -0
index 6d6cd68..0a282ae 100644
@@ -128,6 +128,8 @@ struct resource *request_region(struct resource *parent,
 		resource_size_t size);
 
 int release_region(struct resource *res);
+struct resource *create_resource(const char *name,
+	resource_size_t start, resource_size_t end);
 
 extern struct resource iomem_resource;
 
Signature · 7 lines
1.7.10.4


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

RFC 2/5 bootm: add very basic ELF support (stolen from kexec)

In reply to Antony Pavlov
---
 commands/Kconfig           |    7 +
 common/Kconfig             |    3 +
 common/filetype.c          |    5 +
 include/filetype.h         |    1 +
 lib/Makefile               |    1 +
 lib/kexec/Makefile         |    1 +
 lib/kexec/kexec-elf-exec.c |   85 ++++
 lib/kexec/kexec-elf.c      |  927 ++++++++++++++++++++++++++++++++++++++++++++
 lib/kexec/kexec-elf.h      |  110 ++++++
 lib/kexec/kexec.c          |  251 ++++++++++++
 lib/kexec/kexec.h          |  117 ++++++
 11 files changed, 1508 insertions(+)
 create mode 100644 lib/kexec/Makefile
 create mode 100644 lib/kexec/kexec-elf-exec.c
 create mode 100644 lib/kexec/kexec-elf.c
 create mode 100644 lib/kexec/kexec-elf.h
 create mode 100644 lib/kexec/kexec.c
 create mode 100644 lib/kexec/kexec.h
commands/Kconfig +7 -0
index 75ebfb8..aef4ecb 100644
@@ -403,6 +403,13 @@ config CMD_BOOTM_AIMAGE
 	help
 	  Support using Android Images.
 
+config KEXEC
+	bool
+	prompt "bootm ELF image support"
+	depends on CMD_BOOTM && HAS_KEXEC
+	help
+	  Support using ELF Images.
+
 config CMD_UIMAGE
 	select UIMAGE
 	tristate
common/Kconfig +3 -0
index b60b78b..84cfc70 100644
@@ -674,3 +674,6 @@ endmenu
 
 config HAS_DEBUG_LL
 	bool
+
+config HAS_KEXEC
+	bool
common/filetype.c +5 -0
index 748e364..1bb9cac 100644
@@ -23,6 +23,7 @@
 #include <fs.h>
 #include <malloc.h>
 #include <errno.h>
+#include <elf.h>
 
 struct filetype_str {
 	const char *name;	/* human readable filetype */
@@ -48,6 +49,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_elf] = { "ELF", "elf" },
 };
 
 const char *file_type_to_string(enum filetype f)
@@ -169,6 +171,9 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
 	if (buf16[512 + 28] == le16_to_cpu(0xef53))
 		return filetype_ext;
 
+	if (strncmp(buf8, ELFMAG, 4) == 0)
+		return filetype_elf;
+
 	return filetype_unknown;
 }
 
include/filetype.h +1 -0
index 91139db..d7c9c03 100644
@@ -23,6 +23,7 @@ enum filetype {
 	filetype_bmp,
 	filetype_png,
 	filetype_ext,
+	filetype_elf,
 	filetype_max,
 };
 
lib/Makefile +1 -0
index 635d52e..10465ee 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_QSORT)	+= qsort.o
 obj-y			+= gui/
 obj-$(CONFIG_XYMODEM)	+= xymodem.o
 obj-y			+= unlink-recursive.o
+obj-$(CONFIG_KEXEC)	+= kexec/
lib/kexec/Makefile new file +1 -0
new file mode 100644
index 0000000..6d84858
@@ -0,0 +1 @@
+obj-y	+= kexec-elf-exec.o kexec-elf.o kexec.o
lib/kexec/kexec-elf-exec.c new file +85 -0

85 lines not on this page · raw message

lib/kexec/kexec-elf.c new file +927 -0

927 lines not on this page · raw message

lib/kexec/kexec-elf.h new file +110 -0

110 lines not on this page · raw message

lib/kexec/kexec.c new file +251 -0

251 lines not on this page · raw message

lib/kexec/kexec.h new file +117 -0

117 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


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

Re: [RFC 2/5] bootm: add very basic ELF support (stolen from kexec)

Quoted 71 lines · Antony Pavlov
---
 commands/Kconfig           |    7 +
 common/Kconfig             |    3 +
 common/filetype.c          |    5 +
 include/filetype.h         |    1 +
 lib/Makefile               |    1 +
 lib/kexec/Makefile         |    1 +
 lib/kexec/kexec-elf-exec.c |   85 ++++
 lib/kexec/kexec-elf.c      |  927 ++++++++++++++++++++++++++++++++++++++++++++
 lib/kexec/kexec-elf.h      |  110 ++++++
 lib/kexec/kexec.c          |  251 ++++++++++++
 lib/kexec/kexec.h          |  117 ++++++
 11 files changed, 1508 insertions(+)
 create mode 100644 lib/kexec/Makefile
 create mode 100644 lib/kexec/kexec-elf-exec.c
 create mode 100644 lib/kexec/kexec-elf.c
 create mode 100644 lib/kexec/kexec-elf.h
 create mode 100644 lib/kexec/kexec.c
 create mode 100644 lib/kexec/kexec.h
commands/Kconfig +7 -0
index 75ebfb8..aef4ecb 100644
@@ -403,6 +403,13 @@ config CMD_BOOTM_AIMAGE
 	help
 	  Support using Android Images.
 
+config KEXEC
+	bool
+	prompt "bootm ELF image support"
+	depends on CMD_BOOTM && HAS_KEXEC
+	help
+	  Support using ELF Images.
+
 config CMD_UIMAGE
 	select UIMAGE
 	tristate
common/Kconfig +3 -0
index b60b78b..84cfc70 100644
@@ -674,3 +674,6 @@ endmenu
 
 config HAS_DEBUG_LL
 	bool
+
+config HAS_KEXEC
+	bool
common/filetype.c +2 -0
index 748e364..1bb9cac 100644
@@ -23,6 +23,7 @@
 #include <fs.h>
 #include <malloc.h>
 #include <errno.h>
+#include <elf.h>
 
 struct filetype_str {
 	const char *name;	/* human readable filetype */
@@ -48,6 +49,7 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_bmp] = { "BMP image", "bmp" },
 	[filetype_png] = { "PNG image", "png" },
 	[filetype_ext] = { "ext filesystem", "ext" },
+	[filetype_elf] = { "ELF", "elf" },
 };
 
 const char *file_type_to_string(enum filetype f)

common/filetype.c enum filetype file_detect_type(void *_buf, size_t bufsize) · line 176

Quoted 6 lines
common/filetype.c +3 -0
@@ -169,6 +171,9 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
 	if (buf16[512 + 28] == le16_to_cpu(0xef53))
 		return filetype_ext;
 
+	if (strncmp(buf8, ELFMAG, 4) == 0)
+		return filetype_elf;
+

The filetypes are sorted by size in this function. I think this should go some positions up.

Quoted 76 lines
common/filetype.c +76 -0
+/*
+ *	Load the new kernel
+ */
+static int my_load(char *kernel, unsigned long kexec_flags)
+{
+	char *kernel_buf;
+	off_t kernel_size;
+	int i = 0;
+	int result;
+	struct kexec_info info;
+	long native_arch;
+
+	memset(&info, 0, sizeof(info));
+	info.segment = NULL;
+	info.nr_segments = 0;
+	info.entry = NULL;
+	info.kexec_flags = kexec_flags;
+
+	result = 0;
+	/* slurp in the input kernel */
+	/* FIXME: add a decompresion routines insted of read_file() */
+	kernel_buf = read_file(kernel, &kernel_size);
+
+	for (i = 0; i < kexec_file_types; i++) {
+		if (kexec_file_type[i].probe(kernel_buf, kernel_size) >= 0)
+			break;
+	}
+
+	if (i == kexec_file_types) {
+		printf("Cannot determine the file type "
+				"of %s\n", kernel);
+		return -1;
+	}
+
+	/* Figure out our native architecture before load */
+#if 0
+	native_arch = physical_arch();
+	if (native_arch < 0) {
+		return -1;
+	}
+#endif
+	native_arch = 0;
+	info.kexec_flags |= native_arch;
+
+	result = kexec_file_type[i].load(kernel_buf, kernel_size, &info);
+	if (result < 0) {
+		switch (result) {
+		case EFAILED:
+		default:
+			printf("Cannot load %s\n", kernel);
+			break;
+		}
+		return result;
+	}
+
+	/* Verify all of the segments load to a valid location in memory */
+
+	/* Sort the segments and verify we don't have overlaps */
+	if (sort_segments(&info) < 0) {
+		return -1;
+	}
+
+	result = kexec_load(info.entry,
+		info.nr_segments, info.segment, info.kexec_flags);
+
+	if (result != 0) {
+		/* The load failed, print some debugging information */
+		printf("kexec_load failed: %s\n",
+			strerror(errno));
+		printf("entry       = %p flags = %lx\n",
+			info.entry, info.kexec_flags);
+		print_segments(&info);
+	}
+
+	return result;
+}

common/filetype.c enum filetype file_detect_type(void *_buf, size_t bufsize)

Quoted 10 lines
common/filetype.c +10 -0
+
+#include <boot.h>
+#include <init.h>
+#include <binfmt.h>
+
+static int do_bootm_elf(struct image_data *data)
+{
+	my_load(data->os_file, 0);
+
+	/* unreachable(); */

This is not unreachable. my_load can return errors. Unfortunately they are all -1 (which would be nice to have fixed)

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

A message that is not in the archive (sent off-list or not yet received): CAA4bVAGk02KAHJH6mOfzoa0-5C=P7_7ADEMtg9jXPSk-Fr5UVw@mail.gmail.com

#5 lore raw

Re: [RFC 2/5] bootm: add very basic ELF support (stolen from kexec)

Quoted 163 lines · Sascha Hauer
Quoted 71 lines · Antony Pavlov
---
 commands/Kconfig           |    7 +
 common/Kconfig             |    3 +
 common/filetype.c          |    5 +
 include/filetype.h         |    1 +
 lib/Makefile               |    1 +
 lib/kexec/Makefile         |    1 +
 lib/kexec/kexec-elf-exec.c |   85 ++++
 lib/kexec/kexec-elf.c      |  927 ++++++++++++++++++++++++++++++++++++++++++++
 lib/kexec/kexec-elf.h      |  110 ++++++
 lib/kexec/kexec.c          |  251 ++++++++++++
 lib/kexec/kexec.h          |  117 ++++++
 11 files changed, 1508 insertions(+)
 create mode 100644 lib/kexec/Makefile
 create mode 100644 lib/kexec/kexec-elf-exec.c
 create mode 100644 lib/kexec/kexec-elf.c
 create mode 100644 lib/kexec/kexec-elf.h
 create mode 100644 lib/kexec/kexec.c
 create mode 100644 lib/kexec/kexec.h
commands/Kconfig +7 -0
index 75ebfb8..aef4ecb 100644
@@ -403,6 +403,13 @@ config CMD_BOOTM_AIMAGE
      help
        Support using Android Images.
 
+config KEXEC
+     bool
+     prompt "bootm ELF image support"
+     depends on CMD_BOOTM && HAS_KEXEC
+     help
+       Support using ELF Images.
+
 config CMD_UIMAGE
      select UIMAGE
      tristate
common/Kconfig +3 -0
index b60b78b..84cfc70 100644
@@ -674,3 +674,6 @@ endmenu
 
 config HAS_DEBUG_LL
      bool
+
+config HAS_KEXEC
+     bool
common/filetype.c +2 -0
index 748e364..1bb9cac 100644
@@ -23,6 +23,7 @@
 #include <fs.h>
 #include <malloc.h>
 #include <errno.h>
+#include <elf.h>
 
 struct filetype_str {
      const char *name;       /* human readable filetype */
@@ -48,6 +49,7 @@ static const struct filetype_str filetype_str[] = {
      [filetype_bmp] = { "BMP image", "bmp" },
      [filetype_png] = { "PNG image", "png" },
      [filetype_ext] = { "ext filesystem", "ext" },
+     [filetype_elf] = { "ELF", "elf" },
 };
 
 const char *file_type_to_string(enum filetype f)

common/filetype.c enum filetype file_detect_type(void *_buf, size_t bufsize) · line 176

Quoted 6 lines
common/filetype.c +3 -0
@@ -169,6 +171,9 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
      if (buf16[512 + 28] == le16_to_cpu(0xef53))
              return filetype_ext;
 
+     if (strncmp(buf8, ELFMAG, 4) == 0)
+             return filetype_elf;
+

The filetypes are sorted by size in this function. I think this should go some positions up.

Quoted 81 lines
common/filetype.c +81 -0
+/*
+ *   Load the new kernel
+ */
+static int my_load(char *kernel, unsigned long kexec_flags)
+{
+     char *kernel_buf;
+     off_t kernel_size;
+     int i = 0;
+     int result;
+     struct kexec_info info;
+     long native_arch;
+
+     memset(&info, 0, sizeof(info));
+     info.segment = NULL;
+     info.nr_segments = 0;
+     info.entry = NULL;
+     info.kexec_flags = kexec_flags;
+
+     result = 0;
+     /* slurp in the input kernel */
+     /* FIXME: add a decompresion routines insted of read_file() */
+     kernel_buf = read_file(kernel, &kernel_size);
+
+     for (i = 0; i < kexec_file_types; i++) {
+             if (kexec_file_type[i].probe(kernel_buf, kernel_size) >= 0)
+                     break;
+     }
+
+     if (i == kexec_file_types) {
+             printf("Cannot determine the file type "
+                             "of %s\n", kernel);
+             return -1;
+     }
+
+     /* Figure out our native architecture before load */
+#if 0
+     native_arch = physical_arch();
+     if (native_arch < 0) {
+             return -1;
+     }
+#endif
+     native_arch = 0;
+     info.kexec_flags |= native_arch;
+
+     result = kexec_file_type[i].load(kernel_buf, kernel_size, &info);
+     if (result < 0) {
+             switch (result) {
+             case EFAILED:
+             default:
+                     printf("Cannot load %s\n", kernel);
+                     break;
+             }
+             return result;
+     }
+
+     /* Verify all of the segments load to a valid location in memory */
+
+     /* Sort the segments and verify we don't have overlaps */
+     if (sort_segments(&info) < 0) {
+             return -1;
+     }
+
+     result = kexec_load(info.entry,
+             info.nr_segments, info.segment, info.kexec_flags);
+
+     if (result != 0) {
+             /* The load failed, print some debugging information */
+             printf("kexec_load failed: %s\n",
+                     strerror(errno));
+             printf("entry       = %p flags = %lx\n",
+                     info.entry, info.kexec_flags);
+             print_segments(&info);
+     }
+
+     return result;
+}
+
+#include <boot.h>
+#include <init.h>
+#include <binfmt.h>
+
Quoted 8 lines

common/filetype.c

Quoted 5 lines
common/filetype.c +5 -0
+static int do_bootm_elf(struct image_data *data)
+{
+     my_load(data->os_file, 0);
+
+     /* unreachable(); */

This is not unreachable. my_load can return errors. Unfortunately they are all -1 (which would be nice to have fixed)

I agree.

Just now I use debug mode then bootm loads elf to unused memory regions for relocation and returns control to shell, so one can check memory map via 'iomem'. See this example from my [RFC 0/5]:

barebox:/ bootm env/vmlinux.qemu-malta-be
handler failed with No error

barebox:/ iomem
0x00000000 - 0xffffffff (size 0x00000000) iomem
0x1e000000 - 0x1e3fffff (size 0x00400000) cfi_flash0 0xa0000000 - 0xafffffff (size 0x10000000) ram0

    0xa17f9000 - 0xa17fffff (size 0x00007000) stack
    0xa1800000 - 0xa27fffff (size 0x01000000) malloc space
    0xa2800000 - 0xa2d4e464 (size 0x0054e465) barebox
    0xa2d50114 - 0xa2d56bb0 (size 0x00006a9d) bss
    0xa2d56bc0 - 0xa316f29b (size 0x004186dc) kexec relocatable segments
    0xa316f2a0 - 0xa316f307 (size 0x00000068) kexec relocator
    0xa316f310 - 0xa316f31f (size 0x00000010) kexec control segments

0xb80003f8 - 0xb80003ff (size 0x00000008) ns16550_serial0

barebox:/ go 0xa316f2a0

In this sample I use 'go' to jump to the start of the kexec relocator.

Of cause this behavour will be changed in the future.

Quoted 6 lines

--

Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Signature · 7 lines
Best regards,
  Antony Pavlov

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

RFC 3/5 MIPS: add ELF support

In reply to Antony Pavlov
---
 arch/mips/Kconfig               |    1 +
 arch/mips/include/asm/elf.h     |    8 ++-
 arch/mips/include/asm/io.h      |   18 ++++++
 arch/mips/lib/Makefile          |    3 +
 arch/mips/lib/kexec-elf-mips.c  |   83 +++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.c      |  130 +++++++++++++++++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.h      |   24 ++++++++
 arch/mips/lib/relocate_kernel.S |   77 +++++++++++++++++++++++
 8 files changed, 343 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/lib/kexec-elf-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.h
 create mode 100644 arch/mips/lib/relocate_kernel.S
arch/mips/Kconfig +1 -0
index 947edcf..3a7f775 100644
@@ -6,6 +6,7 @@ config MIPS
 	select HAS_KALLSYMS
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
 	select HAVE_CONFIGURABLE_TEXT_BASE
+	select HAS_KEXEC
 	default y
 
 config SYS_SUPPORTS_BIG_ENDIAN
arch/mips/include/asm/elf.h +7 -1
index b8b8219..bf974f5 100644
@@ -17,12 +17,18 @@
 
 #ifndef ELF_ARCH
 
+/* Legal values for e_machine (architecture).  */
+
+#define EM_MIPS		 8		/* MIPS R3000 big-endian */
+#define EM_MIPS_RS4_BE	10		/* MIPS R4000 big-endian */
+
 #ifdef CONFIG_32BIT
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)						\
+#define elf_check_arch(x) ((x)->e_machine == EM_MIPS)
+
 /*
  * These are used to set parameters in the core dumps.
  */
arch/mips/include/asm/io.h +18 -0
index 4100e1e..f22ef6f 100644
@@ -14,6 +14,24 @@
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
+/*
+ *     virt_to_phys    -       map virtual addresses to physical
+ *     @address: address to remap
+ *
+ *     The returned physical address is the physical (CPU) mapping for
+ *     the memory address given. It is only valid to use this function on
+ *     addresses directly mapped or allocated via kmalloc.
+ *
+ *     This function does not give bus mappings for DMA transfers. In
+ *     almost all conceivable cases a device driver should not be using
+ *     this function
+ */
+static inline unsigned long virt_to_phys(volatile const void *address)
+{
+	//return (unsigned long)address - PAGE_OFFSET + PHYS_OFFSET;
+	return (unsigned long)address & 0x1fffffff;
+}
+
 /*****************************************************************************/
 /*
  * readX/writeX() are used to access memory mapped devices. On some
arch/mips/lib/Makefile +3 -0
index a31046b..fa16748 100644
@@ -13,3 +13,6 @@ obj-$(CONFIG_CPU_MIPS64) += c-r4k.o
 
 obj-$(CONFIG_CMD_MIPS_CPUINFO) += cpuinfo.o
 obj-$(CONFIG_CMD_BOOTM)	+= bootm.o
+
+obj-$(CONFIG_KEXEC) += kexec-mips.o kexec-elf-mips.o
+obj-$(CONFIG_KEXEC) += relocate_kernel.o
arch/mips/lib/kexec-elf-mips.c new file +83 -0

83 lines not on this page · raw message

arch/mips/lib/kexec-mips.c new file +130 -0

130 lines not on this page · raw message

arch/mips/lib/kexec-mips.h new file +24 -0
new file mode 100644
index 0000000..af1c529
@@ -0,0 +1,24 @@
+#ifndef KEXEC_MIPS_H
+#define KEXEC_MIPS_H
+
+#define MAX_MEMORY_RANGES  64
+
+#define CORE_TYPE_ELF32 1
+#define CORE_TYPE_ELF64 2
+extern unsigned char setup_simple_start[];
+extern uint32_t setup_simple_size;
+
+extern struct {
+	uint32_t spr8;
+	uint32_t spr9;
+} setup_simple_regs;
+
+int elf_mips_probe(const char *buf, off_t len);
+int elf_mips_load(/*int argc, char **argv,*/ const char *buf, off_t len,
+	struct kexec_info *info);
+
+struct arch_options_t {
+	int      core_header_type;
+};
+
+#endif /* KEXEC_MIPS_H */
arch/mips/lib/relocate_kernel.S new file +77 -0

77 lines not on this page · raw message

Signature · 7 lines
1.7.10.4


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

Re: [RFC 3/5] MIPS: add ELF support

Quoted 66 lines · Antony Pavlov
---
 arch/mips/Kconfig               |    1 +
 arch/mips/include/asm/elf.h     |    8 ++-
 arch/mips/include/asm/io.h      |   18 ++++++
 arch/mips/lib/Makefile          |    3 +
 arch/mips/lib/kexec-elf-mips.c  |   83 +++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.c      |  130 +++++++++++++++++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.h      |   24 ++++++++
 arch/mips/lib/relocate_kernel.S |   77 +++++++++++++++++++++++
 8 files changed, 343 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/lib/kexec-elf-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.h
 create mode 100644 arch/mips/lib/relocate_kernel.S
arch/mips/Kconfig +1 -0
index 947edcf..3a7f775 100644
@@ -6,6 +6,7 @@ config MIPS
 	select HAS_KALLSYMS
 	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
 	select HAVE_CONFIGURABLE_TEXT_BASE
+	select HAS_KEXEC
 	default y
 
 config SYS_SUPPORTS_BIG_ENDIAN
arch/mips/include/asm/elf.h +7 -1
index b8b8219..bf974f5 100644
@@ -17,12 +17,18 @@
 
 #ifndef ELF_ARCH
 
+/* Legal values for e_machine (architecture).  */
+
+#define EM_MIPS		 8		/* MIPS R3000 big-endian */
+#define EM_MIPS_RS4_BE	10		/* MIPS R4000 big-endian */
+
 #ifdef CONFIG_32BIT
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)						\
+#define elf_check_arch(x) ((x)->e_machine == EM_MIPS)
+
 /*
  * These are used to set parameters in the core dumps.
  */
arch/mips/include/asm/io.h +6 -0
index 4100e1e..f22ef6f 100644
@@ -14,6 +14,24 @@
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
+/*
+ *     virt_to_phys    -       map virtual addresses to physical
+ *     @address: address to remap
+ *
+ *     The returned physical address is the physical (CPU) mapping for
+ *     the memory address given. It is only valid to use this function on

arch/mips/include/asm/io.h line 32

Quoted 10 lines
arch/mips/include/asm/io.h +10 -0
+ *     addresses directly mapped or allocated via kmalloc.
+ *
+ *     This function does not give bus mappings for DMA transfers. In
+ *     almost all conceivable cases a device driver should not be using
+ *     this function
+ */
+static inline unsigned long virt_to_phys(volatile const void *address)
+{
+	//return (unsigned long)address - PAGE_OFFSET + PHYS_OFFSET;
+	return (unsigned long)address & 0x1fffffff;

Why this? I would assume that you have a 1:1 mapping on Mips?

arch/mips/include/asm/io.h

Quoted 12 lines
arch/mips/include/asm/io.h +12 -0
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <linux/types.h>
+#include <fcntl.h>
+#include <elf.h>
+#include "../../../lib/kexec/kexec.h"
+#include "../../../lib/kexec/kexec-elf.h"

So the they should be better in include/kexec/

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

A message that is not in the archive (sent off-list or not yet received): CAA4bVAGki1VfbFXNRpMj+-pcM70W_yZvMCFhDGgbpKAXE6Taag@mail.gmail.com

#9 lore raw

RFC 3/5 MIPS: add ELF support

Quoted 71 lines · Sascha Hauer
Quoted 70 lines · Antony Pavlov
---
 arch/mips/Kconfig               |    1 +
 arch/mips/include/asm/elf.h     |    8 ++-
 arch/mips/include/asm/io.h      |   18 ++++++
 arch/mips/lib/Makefile          |    3 +
 arch/mips/lib/kexec-elf-mips.c  |   83 +++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.c      |  130 +++++++++++++++++++++++++++++++++++++++
 arch/mips/lib/kexec-mips.h      |   24 ++++++++
 arch/mips/lib/relocate_kernel.S |   77 +++++++++++++++++++++++
 8 files changed, 343 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/lib/kexec-elf-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.c
 create mode 100644 arch/mips/lib/kexec-mips.h
 create mode 100644 arch/mips/lib/relocate_kernel.S
arch/mips/Kconfig +1 -0
index 947edcf..3a7f775 100644
@@ -6,6 +6,7 @@ config MIPS
      select HAS_KALLSYMS
      select HAVE_CONFIGURABLE_MEMORY_LAYOUT
      select HAVE_CONFIGURABLE_TEXT_BASE
+     select HAS_KEXEC
      default y
 
 config SYS_SUPPORTS_BIG_ENDIAN
arch/mips/include/asm/elf.h +7 -1
index b8b8219..bf974f5 100644
@@ -17,12 +17,18 @@
 
 #ifndef ELF_ARCH
 
+/* Legal values for e_machine (architecture).  */
+
+#define EM_MIPS               8              /* MIPS R3000 big-endian */
+#define EM_MIPS_RS4_BE       10              /* MIPS R4000 big-endian */
+
 #ifdef CONFIG_32BIT
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(hdr)                                          \
+#define elf_check_arch(x) ((x)->e_machine == EM_MIPS)
+
 /*
  * These are used to set parameters in the core dumps.
  */
arch/mips/include/asm/io.h +10 -0
index 4100e1e..f22ef6f 100644
@@ -14,6 +14,24 @@
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
+/*
+ *     virt_to_phys    -       map virtual addresses to physical
+ *     @address: address to remap
+ *
+ *     The returned physical address is the physical (CPU) mapping for
+ *     the memory address given. It is only valid to use this function on
+ *     addresses directly mapped or allocated via kmalloc.
+ *
+ *     This function does not give bus mappings for DMA transfers. In
+ *     almost all conceivable cases a device driver should not be using
Quoted 8 lines

arch/mips/include/asm/io.h line 32

Quoted 6 lines
arch/mips/include/asm/io.h +6 -0
+ *     this function
+ */
+static inline unsigned long virt_to_phys(volatile const void *address)
+{
+     //return (unsigned long)address - PAGE_OFFSET + PHYS_OFFSET;
+     return (unsigned long)address & 0x1fffffff;

Why this? I would assume that you have a 1:1 mapping on Mips?

No.
On MIPS virtual address, used by programmer just always differ from physical address.
Just now mips barebox work in KSEG1 (uncached) memory region (0xa0000000 --- 0xc0000000), after cache support adding mips barebox will work in KSEG0 (cached) memory region (0x80000000 --- 0xa0000000). Both memory regions (KSEG1 and KSEG0) map to the same physical addresses (0x00000000 --- 0x20000000).

Quoted 6 lines
Quoted 6 lines
arch/mips/include/asm/io.h +6 -0
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
Quoted 8 lines

arch/mips/include/asm/io.h

Quoted 6 lines
arch/mips/include/asm/io.h +6 -0
+#include <asm/io.h>
+#include <linux/types.h>
+#include <fcntl.h>
+#include <elf.h>
+#include "../../../lib/kexec/kexec.h"
+#include "../../../lib/kexec/kexec-elf.h"

So the they should be better in include/kexec/

ok

Quoted 7 lines

Sascha

--

Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

--
Best regards,
Antony Pavlov

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

#10 lore raw

RFC 4/5 MIPS: qemu-malta: add board label

In reply to Antony Pavlov

Put special Board ID at the start of bootrom (as qemu does).

The linux kernel use this board ID to determine the MIPS board family and version, so we need this Board ID to run linux kernel successfully.

---
 .../boards/qemu-malta/include/board/board_pbl_start.h    |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/mips/boards/qemu-malta/include/board/board_pbl_start.h +14 -0
index 5b06770..a6c55c7 100644
@@ -23,6 +23,20 @@
 	.set	push
 	.set	noreorder
 
+	b       __start
+	 nop
+
+	/*
+	   MIPS_REVISION_REG located at 0x1fc00010
+	   see the MIPS_REVISION_CORID macro in linux kernel sources
+	   set up it to 0x420 (Malta Board with CoreLV) as qemu does
+	*/
+	.org    0x10
+	.word   0x00000420
+
+	.align 4
+__start:
+
 	mips_disable_interrupts
 
 	/* cpu specific setup ... */
Signature · 7 lines
1.7.10.4


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

RFC 5/5 MIPS: qemu-malta: add YAMON-style GT64120 memory map

In reply to Antony Pavlov

YAMON-style GT64120 memory map make move UART to the new position.

We need YAMON-style GT64120 memory for running Linux kernel from barebox.

---
 .../qemu-malta/include/board/board_pbl_start.h     |   42 ++++++++++++++++++++
 arch/mips/mach-malta/include/mach/hardware.h       |    2 +-
 2 files changed, 43 insertions(+), 1 deletion(-)
arch/mips/boards/qemu-malta/include/board/board_pbl_start.h +42 -0
index a6c55c7..d993c2f 100644
@@ -19,6 +19,15 @@
 
 #include <asm/pbl_macros.h>
 
+#define GT_PCI0IOLD_OFS		0x048
+#define GT_PCI0IOHD_OFS		0x050
+#define GT_PCI0M0LD_OFS		0x058
+#define GT_PCI0M0HD_OFS		0x060
+#define GT_ISD_OFS		0x068
+
+#define GT_PCI0M1LD_OFS		0x080
+#define GT_PCI0M1HD_OFS		0x088
+
 	.macro	board_pbl_start
 	.set	push
 	.set	noreorder
@@ -39,6 +48,39 @@ __start:
 
 	mips_disable_interrupts
 
+	/*
+	 * Load BAR registers of GT64120 as done by YAMON
+	 *
+	 * based on write_bootloader() in qemu.git/hw/mips_malta.c
+	 * see GT64120 manual and qemu.git/hw/gt64xxx.c for details
+	 *
+	 * This is big-endian version of code!
+	 */
+
+	/* move GT64120 registers to 0x1be00000 */
+	li	t1, 0xb4000000
+	li	t0, 0xdf000000
+	sw	t0, GT_ISD_OFS(t1)
+
+	/* setup MEM-to-PCI0 mapping */
+	li	t1, 0xbbe00000
+
+	/* setup PCI0 io window to 0x18000000-0x181fffff */
+	li	t0, 0xc0000000
+	sw	t0, GT_PCI0IOLD_OFS(t1)
+	li	t0, 0x40000000
+	sw	t0, GT_PCI0IOHD_OFS(t1)
+
+	/* setup PCI0 mem windows */
+	li	t0, 0x80000000
+	sw	t0, GT_PCI0M0LD_OFS(t1)
+	li	t0, 0x3f000000
+	sw	t0, GT_PCI0M0HD_OFS(t1)
+	li	t0, 0xc1000000
+	sw	t0, GT_PCI0M1LD_OFS(t1)
+	li	t0, 0x5e000000
+	sw	t0, GT_PCI0M1HD_OFS(t1)
+
 	/* cpu specific setup ... */
 	/* ... absent */
 
arch/mips/mach-malta/include/mach/hardware.h +1 -1
index 5e8e276..f6294b2 100644
@@ -18,7 +18,7 @@
 #ifndef __INCLUDE_ARCH_HARDWARE_H__
 #define   __INCLUDE_ARCH_HARDWARE_H__
 
-#define DEBUG_LL_UART_ADDR	0xb00003f8
+#define DEBUG_LL_UART_ADDR	0xb80003f8
 #define DEBUG_LL_UART_SHIFT	0
 
 /*
Signature · 7 lines
1.7.10.4


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