summaryrefslogtreecommitdiffstats
path: root/arch/mips/boot
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2012-12-12 23:24:46 +0400
committerSascha Hauer <s.hauer@pengutronix.de>2012-12-14 08:34:33 +0100
commitf369f64ed1b29451c82c69c698da60ed8a8eb28f (patch)
tree3dfcdca076f6dbc817b00a65a7b2d695e4b134f6 /arch/mips/boot
parent0ccb9aebcd98d99fdc22d938240c65c7466e8146 (diff)
downloadbarebox-f369f64ed1b29451c82c69c698da60ed8a8eb28f.tar.gz
barebox-f369f64ed1b29451c82c69c698da60ed8a8eb28f.tar.xz
MIPS: add pre-bootloader (pbl) image support
This patch is based on ARM pbl support and allows creating a pre-bootloader binary for compressed image. For different MIPS SoCs (or even for different boards based on the same SoC) the operations carried on in start-pbl.S can be very different. The additional constraints can be imposed on the size of the boot code or the special magic labels in the beginning of the boot code; In some cases it could be necessary to show CPU is alive as early as possible (transmit a char via UART or blink a LED). So the demands for pbl start operation can be very different. E.g. malta board store boot code at the NOR flash mapped to the MIPS power-on address (0xbfc00000); it is the most simple case: we need just copy pbl image from direct-mapped flash to RAM and jump there. The XBurst-powered boards store boot code in the beginning of a NAND flash or in the beginning of SD/MMC card. In this case we must use simple and short NAND or SD/MMC access routines to copy pbl image to RAM. To meet so different demands a simple technique is selected: * MIPS pbl entry point located in file arch/mips/boot/start-pbl.S. * MIPS pbl code (see start-pbl.S) assumes that every pbl-enabled board has a arch/mips/boards/<BOARD>/include/board/board_pbl_start.h header file. This file must contain definition of the board_pbl_start macro. This macro is used as start of pbl image; * the most popular asm routines (stack setup, relocation to link address, NS16550 initialization (WIP) and so on) are containt in the arch/mips/include/asm/pbl_macros.h header file. So board pbl macro can use it if necessary. It is possible to create similar headers with macros for each specific SoC; so even if we have many different boards based on the same SoC the board_pbl_start macro for every board can be short and clear. * after board-specific initialization the stack pointer is initialized and pbl C code is started. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/mips/boot')
-rw-r--r--arch/mips/boot/Makefile2
-rw-r--r--arch/mips/boot/main_entry-pbl.c87
-rw-r--r--arch/mips/boot/start-pbl.S46
3 files changed, 135 insertions, 0 deletions
diff --git a/arch/mips/boot/Makefile b/arch/mips/boot/Makefile
index d6d28ce652..6b093f1e0e 100644
--- a/arch/mips/boot/Makefile
+++ b/arch/mips/boot/Makefile
@@ -1,2 +1,4 @@
obj-y += start.o
obj-y += main_entry.o
+
+pbl-y += start-pbl.o main_entry-pbl.o
diff --git a/arch/mips/boot/main_entry-pbl.c b/arch/mips/boot/main_entry-pbl.c
new file mode 100644
index 0000000000..f39e9360b1
--- /dev/null
+++ b/arch/mips/boot/main_entry-pbl.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2012 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * 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 as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <init.h>
+#include <sizes.h>
+#include <string.h>
+#include <asm/sections.h>
+#include <asm-generic/memory_layout.h>
+#include <debug_ll.h>
+
+extern void *input_data;
+extern void *input_data_end;
+
+unsigned long free_mem_ptr;
+unsigned long free_mem_end_ptr;
+
+#define STATIC static
+
+#ifdef CONFIG_IMAGE_COMPRESSION_LZO
+#include "../../../lib/decompress_unlzo.c"
+#endif
+
+#ifdef CONFIG_IMAGE_COMPRESSION_GZIP
+#include "../../../lib/decompress_inflate.c"
+#endif
+
+void pbl_main_entry(void);
+
+static unsigned long *ttb;
+
+static noinline void errorfn(char *error)
+{
+ PUTS_LL(error);
+ PUTC_LL('\n');
+
+ unreachable();
+}
+
+static void barebox_uncompress(void *compressed_start, unsigned int len)
+{
+ /* set 128 KiB at the end of the MALLOC_BASE for early malloc */
+ free_mem_ptr = MALLOC_BASE + MALLOC_SIZE - SZ_128K;
+ free_mem_end_ptr = free_mem_ptr + SZ_128K;
+
+ ttb = (void *)((free_mem_ptr - 0x4000) & ~0x3fff);
+
+ decompress((void *)compressed_start,
+ len,
+ NULL, NULL,
+ (void *)TEXT_BASE, NULL, errorfn);
+}
+
+void __section(.text_entry) pbl_main_entry(void)
+{
+ u32 pg_start, pg_end, pg_len;
+ void (*barebox)(void);
+
+ PUTS_LL("pbl_main_entry()\n");
+
+ /* clear bss */
+ memset(__bss_start, 0, __bss_stop - __bss_start);
+
+ pg_start = (u32)&input_data;
+ pg_end = (u32)&input_data_end;
+ pg_len = pg_end - pg_start;
+
+ barebox_uncompress(&input_data, pg_len);
+
+ barebox = (void *)TEXT_BASE;
+ barebox();
+}
diff --git a/arch/mips/boot/start-pbl.S b/arch/mips/boot/start-pbl.S
new file mode 100644
index 0000000000..702e29168a
--- /dev/null
+++ b/arch/mips/boot/start-pbl.S
@@ -0,0 +1,46 @@
+/*
+ * Startup Code for MIPS CPU
+ *
+ * Copyright (C) 2011, 2012 Antony Pavlov <antonynpavlov@gmail.com>
+ * ADR macro copyrighted (C) 2009 by Shinya Kuribayashi <skuribay@pobox.com>
+ *
+ * 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.
+ *
+ */
+
+#include <asm/regdef.h>
+#include <asm/mipsregs.h>
+#include <asm/asm.h>
+
+#include <asm/pbl_macros.h>
+#include <board/board_pbl_start.h>
+
+ .set noreorder
+ .text
+ .section ".text_head_entry"
+ .align 4
+
+EXPORT(pbl_start)
+
+ board_pbl_start
+
+ stack_setup
+
+ la v0, pbl_main_entry
+ jal v0
+ nop
+
+ /* No return */
+__error:
+ b __error
+ nop