2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) Paul Mackerras 1997.
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
2005-08-08 11:24:38 +08:00
|
|
|
#include <stddef.h>
|
2006-09-19 12:05:08 +08:00
|
|
|
#include "types.h"
|
|
|
|
#include "elf.h"
|
2005-08-08 11:24:38 +08:00
|
|
|
#include "string.h"
|
|
|
|
#include "stdio.h"
|
2006-09-19 12:05:08 +08:00
|
|
|
#include "page.h"
|
|
|
|
#include "ops.h"
|
2005-06-08 13:12:00 +08:00
|
|
|
|
2007-06-13 12:52:54 +08:00
|
|
|
#include "of.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-19 12:05:08 +08:00
|
|
|
/* Value picked to match that used by yaboot */
|
|
|
|
#define PROG_START 0x01400000 /* only used on 64-bit systems */
|
|
|
|
#define RAM_END (512<<20) /* Fixme: use OF */
|
|
|
|
#define ONE_MB 0x100000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long claim_base;
|
|
|
|
|
2013-09-24 14:10:38 +08:00
|
|
|
void epapr_platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
|
|
|
|
unsigned long r6, unsigned long r7);
|
|
|
|
|
2007-04-18 17:24:12 +08:00
|
|
|
static void *of_try_claim(unsigned long size)
|
2006-09-19 12:05:08 +08:00
|
|
|
{
|
|
|
|
unsigned long addr = 0;
|
|
|
|
|
2006-10-05 12:18:46 +08:00
|
|
|
if (claim_base == 0)
|
2006-09-19 12:05:08 +08:00
|
|
|
claim_base = _ALIGN_UP((unsigned long)_end, ONE_MB);
|
|
|
|
|
|
|
|
for(; claim_base < RAM_END; claim_base += ONE_MB) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf(" trying: 0x%08lx\n\r", claim_base);
|
|
|
|
#endif
|
2014-04-24 15:23:30 +08:00
|
|
|
addr = (unsigned long) of_claim(claim_base, size, 0);
|
|
|
|
if (addr != PROM_ERROR)
|
2006-09-19 12:05:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (addr == 0)
|
|
|
|
return NULL;
|
|
|
|
claim_base = PAGE_ALIGN(claim_base + size);
|
|
|
|
return (void *)addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void of_image_hdr(const void *hdr)
|
|
|
|
{
|
|
|
|
const Elf64_Ehdr *elf64 = hdr;
|
|
|
|
|
|
|
|
if (elf64->e_ident[EI_CLASS] == ELFCLASS64) {
|
|
|
|
/*
|
|
|
|
* Maintain a "magic" minimum address. This keeps some older
|
|
|
|
* firmware platforms running.
|
|
|
|
*/
|
|
|
|
if (claim_base < PROG_START)
|
|
|
|
claim_base = PROG_START;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:10:38 +08:00
|
|
|
static void of_platform_init(unsigned long a1, unsigned long a2, void *promptr)
|
2006-09-19 12:05:08 +08:00
|
|
|
{
|
|
|
|
platform_ops.image_hdr = of_image_hdr;
|
|
|
|
platform_ops.malloc = of_try_claim;
|
|
|
|
platform_ops.exit = of_exit;
|
2007-03-05 11:24:52 +08:00
|
|
|
platform_ops.vmlinux_alloc = of_vmlinux_alloc;
|
2006-09-19 12:05:08 +08:00
|
|
|
|
|
|
|
dt_ops.finddevice = of_finddevice;
|
|
|
|
dt_ops.getprop = of_getprop;
|
|
|
|
dt_ops.setprop = of_setprop;
|
|
|
|
|
2007-06-13 12:52:54 +08:00
|
|
|
of_console_init();
|
2006-09-19 12:05:08 +08:00
|
|
|
|
2007-06-13 12:52:54 +08:00
|
|
|
of_init(promptr);
|
[POWERPC] zImage: Cleanup and improve zImage entry point
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>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 11:24:52 +08:00
|
|
|
loader_info.promptr = promptr;
|
2007-04-13 08:46:21 +08:00
|
|
|
if (a1 && a2 && a2 != 0xdeadbeef) {
|
|
|
|
loader_info.initrd_addr = a1;
|
|
|
|
loader_info.initrd_size = a2;
|
|
|
|
}
|
2006-09-19 12:05:08 +08:00
|
|
|
}
|
2013-09-24 14:10:38 +08:00
|
|
|
|
|
|
|
void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
|
|
|
|
unsigned long r6, unsigned long r7)
|
|
|
|
{
|
|
|
|
/* Detect OF vs. ePAPR boot */
|
|
|
|
if (r5)
|
|
|
|
of_platform_init(r3, r4, (void *)r5);
|
|
|
|
else
|
|
|
|
epapr_platform_init(r3, r4, r5, r6, r7);
|
|
|
|
}
|
|
|
|
|