add very basic ELF support on MIPS
Subsystems (4)
This patch series introduces the basic ELF files support for bootm command on MIPS based on kexec.
The goal of this work is ELF linux kernel loading for MIPS.
The patches 1-3 used to introduce per-arch low-level init for MIPS.
The patch 4 adds the nessesary low-level initialisation for qemu-malta suitable for Linux kernel.
Just now barebox for MIPS32 has no support for cache, so this patch series tries to overcome this disadvantage in patch 5.
The patch 6 introduce memory region for loading ELFs on qemu-malta.
At last the patch 7 introduces kexec infrastructure for ELF loading.
Current problems:
* there is no Linux kernel cmdline support;
* the code is not clean (e.g. there are some '#if 0' and some unused declarations);
* barebox already has ELF support for modules, but this patch series just has no integration with it.
This patch series and one additional huge patch with sample Linux ELF image for malta can be found at
https://github.com/frantony/barebox/tree/next.mips-malta-elf-linux.20120720
[RFC 1/7] MIPS: move start.S code to .text_entry section [RFC 2/7] MIPS: add the initial support for lowlevel init [RFC 3/7] MIPS: malta: add bogus lowlevel init
[RFC 4/7] MIPS: malta: add YAMON-style GT64120 memory map [RFC 5/7] MIPS: malta: make KSEG0 uncached
[RFC 6/7] MIPS: qemu-malta: add KSEG0 memory region [RFC 7/7] bootm: add very basic ELF support on MIPS (stealed from
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
RFC 1/7 MIPS: move start.S code to .text_entry section
This commit make possible lowlevel initialisation code in the text_bare_init section.
--- arch/mips/boot/start.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/boot/start.S +1 -1
@@ -50,7 +50,7 @@ _pc: addiu \rd, ra, \label - _pc # label is assumed to be .set noreorder .text - .section ".text_bare_init" + .section ".text_entry" .align 4 EXPORT(_start)
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 2/7 MIPS: add the initial support for lowlevel init
In reply to Antony PavlovThis commit introduce the initial support for
machine specific lowlevel initialization
(e.g. RAM controller or cache memory).
To return from mach_init_lowlevel() it uses explicit mach_init_lowlevel_return label.
This saves ra register for using inside mach_init_lowlevel()
--- arch/mips/boot/start.S | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/mips/boot/start.S +8 -0
@@ -74,6 +74,14 @@ __start: and k0, k1 mtc0 k0, CP0_STATUS +#ifdef CONFIG_MACH_DO_LOWLEVEL_INIT + b mach_init_lowlevel + nop + +mach_init_lowlevel_return: +EXPORT(mach_init_lowlevel_return) +#endif + /* copy barebox to link location */ ADR a0, _start, t1 /* a0 <- pc-relative position of _start */
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 3/7 MIPS: malta: add bogus lowlevel init
In reply to Antony Pavlov--- arch/mips/Kconfig | 1 + arch/mips/mach-malta/Makefile | 1 + arch/mips/mach-malta/lowlevel_init.S | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 arch/mips/mach-malta/lowlevel_init.S
arch/mips/Kconfig +1 -0
@@ -36,6 +36,7 @@ config MACH_MIPS_MALTA select SYS_SUPPORTS_32BIT_KERNEL select SYS_SUPPORTS_BIG_ENDIAN select HAS_DEBUG_LL + select MACH_HAS_LOWLEVEL_INIT config MACH_MIPS_BCM47XX bool "Broadcom BCM47xx-based boards"
arch/mips/mach-malta/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += reset.o +obj-$(CONFIG_MACH_DO_LOWLEVEL_INIT) += lowlevel_init.o
arch/mips/mach-malta/lowlevel_init.S new file +37 -0
@@ -0,0 +1,37 @@ +/* + * Lowlevel init code for MIPS malta + * + * Copyright (C) 2012 Antony Pavlov <[email protected]> + * + * This file is part of barebox. + * See file CREDITS for list of people who contributed to this project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <config.h> +#include <asm/asm.h> +#include <asm/regdef.h> +#include <asm/mipsregs.h> + + .section ".text_bare_init" + +LEAF(mach_init_lowlevel) + + /* nothing special yet */ + + /* return */ + b mach_init_lowlevel_return + nop +END(mach_init_lowlevel)
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 4/7 MIPS: malta: add YAMON-style GT64120 memory map
In reply to Antony PavlovYAMON-style GT64120 memory map make move UART to the new position.
We need YAMON-style GT64120 memory for running Linux kernel from barebox.
WARNING! WIP! We need add some more effor for compartability with qemu embedded YAMON.
E.g. we need put special Board ID at the start of bootrom:
arch/mips/boot/start.S +4 -0
@@ -59,6 +59,10 @@ EXPORT(_start) nop .org 0x10 +#if 1 + /* Board ID = 0x420 (Malta Board with CoreLV) */ + .word 0x00000420 +#endif
--- arch/mips/mach-malta/include/mach/hardware.h | 2 +- arch/mips/mach-malta/lowlevel_init.S | 33 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-)
arch/mips/mach-malta/include/mach/hardware.h +1 -1
@@ -21,7 +21,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/*
arch/mips/mach-malta/lowlevel_init.S +32 -1
@@ -29,7 +29,38 @@ LEAF(mach_init_lowlevel) - /* nothing special yet */ + /* + * 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 */ + lui t1, 0xb400 + lui t0, 0xdf00 + sw t0, 104(t1) + + /* setup MEM-to-PCI0 mapping */ + lui t1, 0xbbe0 + + /* setup PCI0 io window to 18000000-181fffff */ + lui t0, 0xc000 + sw t0, 72(t1) /* GT_PCI0IOLD */ + lui t0, 0x4000 + sw t0, 80(t1) /* GT_PCI0IOHD */ + + /* setup PCI0 mem windows */ + lui t0, 0x8000 + sw t0, 88(t1) /* GT_PCI0M0LD */ + lui t0, 0x3f00 + sw t0, 96(t1) /* GT_PCI0M0HD */ + lui t0, 0xc100 + sw t0, 128(t1) /* GT_PCI0M1LD */ + lui t0, 0x5e00 + sw t0, 136(t1) /* GT_PCI0M1HD */ /* return */ b mach_init_lowlevel_return
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 5/7 MIPS: malta: make KSEG0 uncached
In reply to Antony PavlovOn MIPS as usual KSEG0 segment used for cached memory access, and Linux kernel linked to KSEG0.
As just now we don't have cache memory support on MIPS, we can change the KSEG0 mode (make it uncached) and use it without any danger.
--- arch/mips/mach-malta/lowlevel_init.S | 4 ++++ 1 file changed, 4 insertions(+)
arch/mips/mach-malta/lowlevel_init.S +4 -0
@@ -62,6 +62,10 @@ LEAF(mach_init_lowlevel) lui t0, 0x5e00 sw t0, 136(t1) /* GT_PCI0M1HD */ + /* make KSEG0 uncached */ + li t0, CONF_CM_UNCACHED + mtc0 t0, CP0_CONFIG + /* return */ b mach_init_lowlevel_return nop
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 6/7 MIPS: qemu-malta: add KSEG0 memory region
In reply to Antony PavlovAs most of ELF files are linked to KSEG0,
we need declaration for memory region (KSEG0)
for loading ELF files.
--- arch/mips/boards/qemu-malta/init.c | 1 + 1 file changed, 1 insertion(+)
arch/mips/boards/qemu-malta/init.c +1 -0
@@ -34,6 +34,7 @@static int malta_mem_init (void ) {barebox_add_memory_bank ("ram0" ,0xa0000000 ,SZ_256M ); +barebox_add_memory_bank ("cram0" ,0x80000000 ,SZ_256M );return 0 ; }
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
RFC 7/7 bootm: add very basic ELF support on MIPS (stealed from kexec)
In reply to Antony Pavlov--- arch/mips/include/asm/elf.h | 8 +- arch/mips/lib/Makefile | 2 + arch/mips/lib/kexec-elf-mips.c | 85 +++++ arch/mips/lib/kexec-mips.c | 66 ++++ arch/mips/lib/kexec-mips.h | 26 ++ common/filetype.c | 4 + include/filetype.h | 1 + lib/Makefile | 1 + lib/kexec/Makefile | 1 + lib/kexec/kexec-elf-core.c | 30 ++ lib/kexec/kexec-elf-exec.c | 182 +++++++++ lib/kexec/kexec-elf.c | 796 ++++++++++++++++++++++++++++++++++++++++ lib/kexec/kexec-elf.h | 132 +++++++ lib/kexec/kexec.c | 299 +++++++++++++++ lib/kexec/kexec.h | 188 ++++++++++ lib/kexec/unused.h | 15 + 16 files changed, 1835 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 lib/kexec/Makefile create mode 100644 lib/kexec/kexec-elf-core.c 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 create mode 100644 lib/kexec/unused.h
arch/mips/include/asm/elf.h +7 -1
@@ -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/lib/Makefile +2 -0
@@ -11,3 +11,5 @@ obj-$(CONFIG_CPU_MIPS64) += c-r4k.o obj-$(CONFIG_CMD_MIPS_CPUINFO) += cpuinfo.o obj-$(CONFIG_CMD_BOOTM) += bootm.o + +obj-y += kexec-mips.o kexec-elf-mips.o
arch/mips/lib/kexec-elf-mips.c new file +85 -0
85 lines not on this page · raw message
arch/mips/lib/kexec-mips.c new file +66 -0
66 lines not on this page · raw message
arch/mips/lib/kexec-mips.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef KEXEC_MIPS_H +#define KEXEC_MIPS_H + +#define MAX_MEMORY_RANGES 64 +#define MAX_LINE 160 + +#define CORE_TYPE_ELF32 1 +#define CORE_TYPE_ELF64 2 +extern unsigned char setup_simple_start[]; +extern uint32_t setup_simple_size; + +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); +void elf_mips_usage (void ); + +struct arch_options_t { +int core_header_type; +}; + +#endif /* KEXEC_MIPS_H */
common/filetype.c +4 -0
@@ -25,6 +25,7 @@#include <fcntl.h> #include <fs.h> #include <malloc.h> +#include <elf.h> static const char *filetype_str[] = { [filetype_unknown] ="unknown" ,
@@ -40,6 +41,7 @@ static const char *filetype_str[] = { [filetype_aimage] = "Android boot image", [filetype_sh] = "Bourne Shell", [filetype_mips_barebox] = "MIPS barebox image", + [filetype_elf] = "ELF", };const char *file_type_to_string (enum filetype f)
@@ -81,6 +83,8 @@ enum filetype file_detect_type(void *_buf)return filetype_aimage;if (strncmp (buf8 +0x10 ,"barebox" ,7 ) ==0 )return filetype_mips_barebox; +if (strncmp (buf8,ELFMAG ,4 ) ==0 ) +return filetype_elf;return filetype_unknown; }
include/filetype.h +1 -0
@@ -18,6 +18,7 @@ enum filetype { filetype_aimage, filetype_sh, filetype_mips_barebox, + filetype_elf, };const char *file_type_to_string (enum filetype f);
lib/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_UNCOMPRESS) += uncompress.o obj-$(CONFIG_BCH) += bch.o obj-$(CONFIG_BITREV) += bitrev.o obj-$(CONFIG_QSORT) += qsort.o +obj-y += kexec/
lib/kexec/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += kexec-elf-exec.o kexec-elf.o kexec-elf-core.o kexec.o
lib/kexec/kexec-elf-core.c new file +30 -0
@@ -0,0 +1,30 @@ +#include <common.h> +#include <linux/types.h> + +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include "elf.h" +#include "kexec-elf.h" + +int build_elf_core_info (const char *buf,off_t len,struct mem_ehdr *ehdr, +uint32_t flags) +{ +int result; + result =build_elf_info (buf, len, ehdr, flags); +if (result <0 ) { +return result; + } +if ((ehdr->e_type !=ET_CORE )) { +/* not an ELF Core */ +fprintf (stderr,"Not ELF type ET_CORE\n" ); +return -1 ; + } +if (!ehdr->e_phdr) { +/* No program header */ +fprintf (stderr,"No ELF program header\n" ); +return -1 ; + } + +return 0 ; +}
lib/kexec/kexec-elf-exec.c new file +182 -0
182 lines not on this page · raw message
lib/kexec/kexec-elf.c new file +796 -0
796 lines not on this page · raw message
lib/kexec/kexec-elf.h new file +132 -0
132 lines not on this page · raw message
lib/kexec/kexec.c new file +299 -0
299 lines not on this page · raw message
lib/kexec/kexec.h new file +188 -0
188 lines not on this page · raw message
lib/kexec/unused.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef UNUSED_H +#define UNUSED_H + +/* http://sourcefrog.net/weblog/software/languages/C/unused.html */ + +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED (x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCLINT__) +# define UNUSED (x)/*@unused@*/ x +#else +# define UNUSED (x) x +#endif + +#endif
Signature · 7 lines
1.7.10 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [RFC 4/7] MIPS: malta: add YAMON-style GT64120 memory map
In reply to Antony PavlovSorry, this patch can't be applied!
It cites diff-formatted text in the comment. adding extra spaces to this cited text fixes the problem.
Quoted 87 lines · 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.
WARNING! WIP! We need add some more effor for compartability with qemu embedded YAMON.
E.g. we need put special Board ID at the start of bootrom:
arch/mips/boot/start.S +4
-0@@ -59,6 +59,10 @@ EXPORT(_start) nop .org 0x10 +#if 1 + /* Board ID = 0x420 (Malta Board with CoreLV) */ + .word 0x00000420 +#endifSigned-off-by Antony Pavlov <[email protected]>--- arch/mips/mach-malta/include/mach/hardware.h | 2 +- arch/mips/mach-malta/lowlevel_init.S | 33 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-)arch/mips/mach-malta/include/mach/hardware.h +1
-1@@ -21,7 +21,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/* arch/mips/mach-malta/lowlevel_init.S +32
-2@@ -29,7 +29,38 @@ LEAF(mach_init_lowlevel) - /* nothing special yet */ + /* + * 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 */ + lui t1, 0xb400 + lui t0, 0xdf00 + sw t0, 104(t1) + + /* setup MEM-to-PCI0 mapping */ + lui t1, 0xbbe0 + + /* setup PCI0 io window to 18000000-181fffff */ + lui t0, 0xc000 + sw t0, 72(t1) /* GT_PCI0IOLD */ + lui t0, 0x4000 + sw t0, 80(t1) /* GT_PCI0IOHD */ + + /* setup PCI0 mem windows */ + lui t0, 0x8000 + sw t0, 88(t1) /* GT_PCI0M0LD */ + lui t0, 0x3f00 + sw t0, 96(t1) /* GT_PCI0M0HD */ + lui t0, 0xc100 + sw t0, 128(t1) /* GT_PCI0M1LD */ + lui t0, 0x5e00 + sw t0, 136(t1) /* GT_PCI0M1HD */ /* return */ b mach_init_lowlevel_return --1.7.10
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox