From: David Gibson <david@gibson.dropbear.id.au>
To: <linuxppc-dev@ozlabs.org>
Subject: [PATCH 8/15] zImage: Cleanup and improve zImage entry point
Date: Mon, 5 Mar 2007 14:24:52 +1100 (EST) [thread overview]
Message-ID: <20070305032452.810C1DDF1B@ozlabs.org> (raw)
In-Reply-To: <20070305032307.GB31417@localhost.localdomain>
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
---
arch/powerpc/boot/Makefile | 6 +++---
arch/powerpc/boot/crt0.S | 32 +++++++++++++++++++++++++++++---
arch/powerpc/boot/main.c | 18 +++++++-----------
arch/powerpc/boot/of.c | 6 ++++--
arch/powerpc/boot/ops.h | 12 +++++++++++-
arch/powerpc/boot/wrapper | 6 ++++--
arch/powerpc/boot/zImage.coff.lds.S | 3 ++-
arch/powerpc/boot/zImage.lds.S | 1 +
8 files changed, 61 insertions(+), 23 deletions(-)
Index: working-2.6/arch/powerpc/boot/crt0.S
===================================================================
--- working-2.6.orig/arch/powerpc/boot/crt0.S 2007-02-19 14:00:50.000000000 +1100
+++ working-2.6/arch/powerpc/boot/crt0.S 2007-02-19 14:01:43.000000000 +1100
@@ -16,6 +16,7 @@
_zimage_start_opd:
.long _zimage_start, 0, 0, 0
+ .weak _zimage_start
.globl _zimage_start
_zimage_start:
/* Work out the offset between the address we were linked at
@@ -44,7 +45,7 @@ _zimage_start:
addi r9,r9,4
bdnz 2b
- /* Do a cache flush for our text, in case OF didn't */
+ /* Do a cache flush for our text, in case the loader didn't */
3: lis r9,_start@ha
addi r9,r9,_start@l
add r9,r0,r9
@@ -59,6 +60,31 @@ _zimage_start:
sync
isync
- mr r6,r1
- b start
+ /* Clear the BSS */
+ lis r9,__bss_start@ha
+ addi r9,r9,__bss_start@l
+ lis r8,_end@ha
+ addi r8,r8,_end@l
+ li r0,0
+5: stw r0,0(r9)
+ addi r9,r9,4
+ cmplw cr0,r9,r8
+ blt 5b
+ /* Possibly set up a custom stack */
+.weak _platform_stack_top
+ lis r8,_platform_stack_top@ha
+ addi r8,r8,_platform_stack_top@l
+ cmpwi r8,0
+ beq 6f
+ lwz r1,0(r8)
+ li r0,0
+ stwu r0,-16(r1) /* establish a stack frame */
+6:
+
+ /* Call platform_init() */
+ bl platform_init
+
+ /* Call start */
+ mr r3,r1
+ b start
Index: working-2.6/arch/powerpc/boot/ops.h
===================================================================
--- working-2.6.orig/arch/powerpc/boot/ops.h 2007-02-19 14:01:38.000000000 +1100
+++ working-2.6/arch/powerpc/boot/ops.h 2007-02-19 14:01:43.000000000 +1100
@@ -59,7 +59,13 @@ struct serial_console_data {
void (*close)(void);
};
-int platform_init(void *promptr, char *dt_blob_start, char *dt_blob_end);
+struct loader_info {
+ void *promptr;
+ unsigned long initrd_addr, initrd_size;
+};
+extern struct loader_info loader_info;
+
+void start(void *sp);
int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device);
int serial_console_init(void);
int ns16550_console_init(void *devp, struct serial_console_data *scdp);
@@ -100,4 +106,8 @@ static inline void exit(void)
for(;;);
}
+#define BSS_STACK(size) \
+ static char _bss_stack[size]; \
+ void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
+
#endif /* _PPC_BOOT_OPS_H_ */
Index: working-2.6/arch/powerpc/boot/main.c
===================================================================
--- working-2.6.orig/arch/powerpc/boot/main.c 2007-02-19 14:01:38.000000000 +1100
+++ working-2.6/arch/powerpc/boot/main.c 2007-02-19 14:01:43.000000000 +1100
@@ -254,21 +254,15 @@ static void set_cmdline(char *buf)
struct platform_ops platform_ops;
struct dt_ops dt_ops;
struct console_ops console_ops;
+struct loader_info loader_info;
-void start(unsigned long a1, unsigned long a2, void *promptr, void *sp)
+void start(void *sp)
{
struct addr_range vmlinux, initrd;
kernel_entry_t kentry;
char cmdline[COMMAND_LINE_SIZE];
unsigned long ft_addr = 0;
- memset(__bss_start, 0, _end - __bss_start);
- memset(&platform_ops, 0, sizeof(platform_ops));
- memset(&dt_ops, 0, sizeof(dt_ops));
- memset(&console_ops, 0, sizeof(console_ops));
-
- if (platform_init(promptr, _dtb_start, _dtb_end))
- exit();
if (console_ops.open && (console_ops.open() < 0))
exit();
if (platform_ops.fixups)
@@ -278,7 +272,8 @@ void start(unsigned long a1, unsigned lo
_start, sp);
vmlinux = prep_kernel();
- initrd = prep_initrd(vmlinux, a1, a2);
+ initrd = prep_initrd(vmlinux, loader_info.initrd_addr,
+ loader_info.initrd_size);
/* If cmdline came from zimage wrapper or if we can edit the one
* in the dt, print it out and edit it, if possible.
@@ -298,7 +293,7 @@ void start(unsigned long a1, unsigned lo
if (ft_addr)
printf(" flat tree at 0x%lx\n\r", ft_addr);
else
- printf(" using OF tree (promptr=%p)\n\r", promptr);
+ printf(" using OF tree (promptr=%p)\n\r", loader_info.promptr);
if (console_ops.close)
console_ops.close();
@@ -307,7 +302,8 @@ void start(unsigned long a1, unsigned lo
if (ft_addr)
kentry(ft_addr, 0, NULL);
else
- kentry((unsigned long)initrd.addr, initrd.size, promptr);
+ kentry((unsigned long)initrd.addr, initrd.size,
+ loader_info.promptr);
/* console closed so printf below may not work */
printf("Error: Linux kernel returned to zImage boot wrapper!\n\r");
Index: working-2.6/arch/powerpc/boot/of.c
===================================================================
--- working-2.6.orig/arch/powerpc/boot/of.c 2007-02-19 14:01:38.000000000 +1100
+++ working-2.6/arch/powerpc/boot/of.c 2007-02-19 14:01:43.000000000 +1100
@@ -267,7 +267,7 @@ static void of_console_write(char *buf,
call_prom("write", 3, 1, of_stdout_handle, buf, len);
}
-int platform_init(void *promptr, char *dt_blob_start, char *dt_blob_end)
+void platform_init(unsigned long a1, unsigned long a2, void *promptr)
{
platform_ops.image_hdr = of_image_hdr;
platform_ops.malloc = of_try_claim;
@@ -282,5 +282,7 @@ int platform_init(void *promptr, char *d
console_ops.write = of_console_write;
prom = (int (*)(void *))promptr;
- return 0;
+ loader_info.promptr = promptr;
+ loader_info.initrd_addr = a1;
+ loader_info.initrd_size = a2;
}
Index: working-2.6/arch/powerpc/boot/Makefile
===================================================================
--- working-2.6.orig/arch/powerpc/boot/Makefile 2007-02-19 14:00:50.000000000 +1100
+++ working-2.6/arch/powerpc/boot/Makefile 2007-02-19 14:01:43.000000000 +1100
@@ -40,11 +40,11 @@ zliblinuxheader := zlib.h zconf.h zutil.
$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) \
$(addprefix $(obj)/,$(zlibheader))
-src-wlib := string.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
+src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
ns16550.c serial.c simple_alloc.c div64.S util.S \
gunzip_util.c $(zlib)
src-plat := of.c
-src-boot := crt0.S $(src-wlib) $(src-plat) empty.c
+src-boot := $(src-wlib) $(src-plat) empty.c
src-boot := $(addprefix $(obj)/, $(src-boot))
obj-boot := $(addsuffix .o, $(basename $(src-boot)))
@@ -97,7 +97,7 @@ $(obj)/wrapper.a: $(obj-wlib)
hostprogs-y := addnote addRamDisk hack-coff mktree
-extra-y := $(obj)/crt0.o $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
+extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
$(obj)/zImage.lds $(obj)/zImage.coff.lds
wrapper :=$(srctree)/$(src)/wrapper
Index: working-2.6/arch/powerpc/boot/wrapper
===================================================================
--- working-2.6.orig/arch/powerpc/boot/wrapper 2007-02-19 14:00:50.000000000 +1100
+++ working-2.6/arch/powerpc/boot/wrapper 2007-02-19 14:01:43.000000000 +1100
@@ -191,7 +191,7 @@ fi
if [ "$platform" != "miboot" ]; then
${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
- $object/crt0.o $platformo $tmp $object/wrapper.a
+ $platformo $tmp $object/wrapper.a
rm $tmp
fi
@@ -201,7 +201,9 @@ pseries|chrp)
$object/addnote "$ofile"
;;
pmaccoff)
- ${CROSS}objcopy -O aixcoff-rs6000 --set-start 0x500000 "$ofile"
+ entry=`objdump -f "$ofile" | grep '^start address ' | \
+ cut -d' ' -f3`
+ ${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
$object/hack-coff "$ofile"
;;
esac
Index: working-2.6/arch/powerpc/boot/zImage.lds.S
===================================================================
--- working-2.6.orig/arch/powerpc/boot/zImage.lds.S 2007-02-19 14:00:50.000000000 +1100
+++ working-2.6/arch/powerpc/boot/zImage.lds.S 2007-02-19 14:01:43.000000000 +1100
@@ -1,5 +1,6 @@
OUTPUT_ARCH(powerpc:common)
ENTRY(_zimage_start)
+EXTERN(_zimage_start)
SECTIONS
{
. = (4*1024*1024);
Index: working-2.6/arch/powerpc/boot/zImage.coff.lds.S
===================================================================
--- working-2.6.orig/arch/powerpc/boot/zImage.coff.lds.S 2007-02-19 14:00:50.000000000 +1100
+++ working-2.6/arch/powerpc/boot/zImage.coff.lds.S 2007-02-19 14:01:43.000000000 +1100
@@ -1,5 +1,6 @@
OUTPUT_ARCH(powerpc:common)
-ENTRY(_start)
+ENTRY(_zimage_start_opd)
+EXTERN(_zimage_start_opd)
SECTIONS
{
. = (5*1024*1024);
next prev parent reply other threads:[~2007-03-05 3:24 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-05 3:23 [0/15] Ebony support, spin 3 David Gibson
2007-03-05 3:24 ` [PATCH 1/15] powerpc: Allow duplicate lmb_reserve() calls David Gibson
2007-03-05 3:24 ` [PATCH 2/15] Automatically lmb_reserve() initrd David Gibson
2007-04-18 11:43 ` Uytterhoeven, Geert
2007-03-05 3:24 ` [PATCH 3/15] Define FIXED_PORT flag for serial_core David Gibson
2007-03-05 3:24 ` [PATCH 7/15] zImage: Cleanup and improve prep_kernel() David Gibson
2007-03-05 3:24 ` [PATCH 5/15] Re-organize Kconfig code for 4xx in arch/powerpc David Gibson
2007-03-05 3:24 ` [PATCH 11/15] zImage wrapper for Ebony David Gibson
2007-03-05 17:10 ` Mark A. Greer
2007-03-06 0:09 ` David Gibson
2007-03-07 19:47 ` Scott Wood
2007-03-08 0:24 ` David Gibson
2007-03-08 0:54 ` Mark A. Greer
2007-03-08 1:35 ` Josh Boyer
2007-03-09 17:50 ` Josh Boyer
2007-03-10 4:08 ` David Gibson
2007-03-05 3:24 ` [PATCH 4/15] Use resource_size_t for serial port IO addresses David Gibson
2007-03-05 3:24 ` David Gibson [this message]
2007-03-15 22:35 ` [PATCH 8/15] zImage: Cleanup and improve zImage entry point Mark A. Greer
2007-03-16 0:14 ` David Gibson
2007-03-16 1:01 ` Mark A. Greer
2007-03-16 1:50 ` David Gibson
2007-03-16 3:36 ` Mark A. Greer
2007-03-20 20:20 ` Mark A. Greer
2007-03-15 23:02 ` Mark A. Greer
2007-03-16 0:18 ` David Gibson
2007-03-16 0:47 ` Mark A. Greer
2007-03-16 0:50 ` David Gibson
2007-03-16 3:45 ` Mark A. Greer
2007-03-16 4:02 ` David Gibson
2007-03-16 16:21 ` Scott Wood
2007-03-17 1:38 ` David Gibson
2007-03-17 3:15 ` Geoff Levand
2007-03-19 15:06 ` Scott Wood
2007-03-20 0:45 ` David Gibson
2007-03-05 3:24 ` [PATCH 9/15] Add arch/powerpc driver for UIC, PPC4xx interrupt controller David Gibson
2007-03-05 3:24 ` [PATCH 6/15] zImage: Add more flexible gunzip convenience functions David Gibson
2007-03-16 16:24 ` Geoff Levand
2007-03-17 12:59 ` David Gibson
2007-03-05 3:24 ` [PATCH 10/15] Add device tree for Ebony David Gibson
2007-03-05 14:23 ` Josh Boyer
2007-03-06 0:04 ` David Gibson
2007-03-05 3:24 ` [PATCH 13/15] Port 44x MMU definitions to ARCH=powerpc David Gibson
2007-03-05 3:24 ` [PATCH 12/15] Support for Ebony in arch/powerpc David Gibson
2007-03-05 3:24 ` [PATCH 14/15] Early serial debug support for PPC44x David Gibson
2007-03-08 19:44 ` Josh Boyer
2007-03-09 17:42 ` Josh Boyer
2007-03-09 23:43 ` David Gibson
2007-03-05 3:24 ` [PATCH 15/15] Add support for reset on Ebony David Gibson
2007-03-05 8:02 ` Real time clock support in arch/powerpc Zang Roy-r61911
2007-03-05 15:10 ` Kumar Gala
2007-03-05 17:04 ` Mark A. Greer
2007-03-05 13:57 ` [0/15] Ebony support, spin 3 Josh Boyer
[not found] <20070317013859.GJ3969%40localhost.localdomain>
2007-03-19 21:16 ` [PATCH 8/15] zImage: Cleanup and improve zImage entry point Milton Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070305032452.810C1DDF1B@ozlabs.org \
--to=david@gibson.dropbear.id.au \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).