2007-07-05 16:02:09 +00:00
|
|
|
#define DEBUG
|
2007-07-05 16:01:39 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
2007-07-05 16:01:56 +00:00
|
|
|
#include <command.h>
|
2007-07-05 16:01:39 +00:00
|
|
|
#include <watchdog.h>
|
2007-07-05 16:01:56 +00:00
|
|
|
#include <image.h>
|
2008-02-20 18:01:54 +00:00
|
|
|
#include <init.h>
|
2007-07-05 16:01:56 +00:00
|
|
|
#include <environment.h>
|
|
|
|
#include <asm/global_data.h>
|
|
|
|
#include <asm/bitops.h>
|
2008-02-20 18:01:54 +00:00
|
|
|
#include <boot.h>
|
2007-07-05 16:02:09 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fs.h>
|
2007-07-05 16:01:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
|
|
|
#include <ft_build.h>
|
|
|
|
#endif
|
2007-07-05 16:02:03 +00:00
|
|
|
extern bd_t *bd;
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
static int do_bootm_linux(struct image_data *idata)
|
2007-07-05 16:01:39 +00:00
|
|
|
{
|
|
|
|
ulong sp;
|
2007-07-05 16:02:17 +00:00
|
|
|
ulong initrd_end = 0;
|
2007-07-05 16:01:39 +00:00
|
|
|
ulong cmd_start, cmd_end;
|
|
|
|
ulong initrd_high;
|
|
|
|
int initrd_copy_to_ram = 1;
|
|
|
|
char *cmdline;
|
2007-07-05 16:02:17 +00:00
|
|
|
const char *c;
|
2007-07-05 16:01:39 +00:00
|
|
|
bd_t *kbd;
|
|
|
|
void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
|
|
|
char *of_flat_tree = NULL;
|
|
|
|
#endif
|
2008-02-20 18:01:54 +00:00
|
|
|
image_header_t *os_header = &idata->os->header;
|
2007-07-15 12:02:53 +00:00
|
|
|
image_header_t *initrd_header = NULL;
|
2007-07-05 16:02:09 +00:00
|
|
|
void *os_data = NULL;
|
|
|
|
void *initrd_data = NULL;
|
|
|
|
void *of_data = NULL;
|
2007-07-15 12:02:53 +00:00
|
|
|
struct image_handle *oftree_handle;
|
2007-07-05 16:02:09 +00:00
|
|
|
unsigned long os_len, initrd_len;
|
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
if (idata->initrd)
|
|
|
|
initrd_header = &idata->initrd->header;
|
2007-07-15 12:02:53 +00:00
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
printf("entering %s: os_header: %p initrd_header: %p oftree: %s\n",
|
|
|
|
__FUNCTION__, os_header, initrd_header, idata->oftree);
|
2007-07-05 16:02:09 +00:00
|
|
|
|
|
|
|
if (os_header->ih_type == IH_TYPE_MULTI) {
|
2008-02-20 18:01:54 +00:00
|
|
|
unsigned long *data = (unsigned long *)(idata->os->data);
|
2007-07-05 16:02:09 +00:00
|
|
|
unsigned long len1 = 0, len2 = 0;
|
|
|
|
|
|
|
|
if (!*data) {
|
|
|
|
printf("multifile image with 0 entries???\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
os_len = ntohl(*data); /* first one is the kernel */
|
|
|
|
data++;
|
|
|
|
|
|
|
|
if (*data) {
|
|
|
|
len1 = ntohl(*data); /* could be initrd or oftree */
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*data) {
|
|
|
|
len2 = ntohl(*data); /* could be oftree */
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*data) /* skip all remaining files */
|
|
|
|
data++;
|
|
|
|
|
|
|
|
data++; /* skip terminating zero */
|
|
|
|
|
|
|
|
os_data = (void *)ntohl(data);
|
|
|
|
|
|
|
|
if (len2) {
|
|
|
|
initrd_data = (void *)
|
|
|
|
((unsigned long)data + ((os_len + 3) & ~3));
|
|
|
|
initrd_len = len1;
|
|
|
|
of_data = (void *)
|
|
|
|
((unsigned long)initrd_data + ((initrd_len + 3) & ~3));
|
|
|
|
} else if (len1) {
|
|
|
|
/* We could check here if this is a multifile image
|
2009-12-15 08:11:09 +00:00
|
|
|
* with only a kernel and an oftree. Original barebox
|
2007-07-05 16:02:09 +00:00
|
|
|
* did not do this, so leave it out for now.
|
|
|
|
*/
|
|
|
|
initrd_data = (void *)((unsigned long)data + ((os_len + 3) & ~3));
|
|
|
|
initrd_len = len1;
|
|
|
|
}
|
|
|
|
} else {
|
2008-02-20 18:01:54 +00:00
|
|
|
os_data = idata->os->data;
|
2007-07-05 16:02:09 +00:00
|
|
|
printf("set os_data to %p\n", os_data);
|
|
|
|
}
|
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
if (idata->initrd)
|
|
|
|
initrd_data = idata->initrd->data;
|
2007-07-05 16:02:09 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
2008-02-20 18:01:54 +00:00
|
|
|
if (idata->oftree) {
|
2009-12-15 08:11:09 +00:00
|
|
|
/* The oftree can be given either as an barebox image or as a
|
2007-07-05 16:02:09 +00:00
|
|
|
* binary blob. First try to read it as an image.
|
|
|
|
*/
|
2008-02-20 18:01:54 +00:00
|
|
|
oftree_handle = map_image(idata->oftree, 1);
|
2007-07-15 12:02:53 +00:00
|
|
|
if (oftree_handle) {
|
|
|
|
of_data = oftree_handle->data;
|
2007-07-05 16:02:09 +00:00
|
|
|
} else {
|
2008-02-20 18:01:54 +00:00
|
|
|
of_data = read_file(idata->oftree, 0);
|
2007-07-05 16:02:09 +00:00
|
|
|
if (!of_data) {
|
2008-02-20 18:01:54 +00:00
|
|
|
printf("could not read %s: %s\n", idata->oftree, errno_str());
|
2007-07-05 16:02:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME: check if this is really an oftree */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
printf("loading kernel.\n");
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:02:17 +00:00
|
|
|
if ((c = getenv ("initrd_high")) != NULL) {
|
2007-07-05 16:01:39 +00:00
|
|
|
/* a value of "no" or a similar string will act like 0,
|
|
|
|
* turning the "load high" feature off. This is intentional.
|
|
|
|
*/
|
2007-07-05 16:02:17 +00:00
|
|
|
initrd_high = simple_strtoul(c, NULL, 16);
|
2007-07-05 16:01:39 +00:00
|
|
|
if (initrd_high == ~0)
|
|
|
|
initrd_copy_to_ram = 0;
|
|
|
|
} else { /* not set, no restrictions to load high */
|
|
|
|
initrd_high = ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_LOGBUFFER
|
|
|
|
kbd=gd->bd;
|
|
|
|
/* Prevent initrd from overwriting logbuffer */
|
|
|
|
if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
|
|
|
|
initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
|
|
|
|
debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Booting a (Linux) kernel image
|
|
|
|
*
|
|
|
|
* Allocate space for command line and board info - the
|
|
|
|
* address should be as high as possible within the reach of
|
|
|
|
* the kernel (see CFG_BOOTMAPSZ settings), but in unused
|
|
|
|
* memory, which means far enough below the current stack
|
|
|
|
* pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
asm( "mr %0,1": "=r"(sp) : );
|
|
|
|
|
|
|
|
debug ("## Current stack ends at 0x%08lX ", sp);
|
|
|
|
|
|
|
|
sp -= 2048; /* just to be sure */
|
|
|
|
if (sp > CFG_BOOTMAPSZ)
|
|
|
|
sp = CFG_BOOTMAPSZ;
|
|
|
|
sp &= ~0xF;
|
|
|
|
|
|
|
|
debug ("=> set upper limit to 0x%08lX\n", sp);
|
|
|
|
|
2007-07-05 16:02:03 +00:00
|
|
|
cmdline = (char *)((sp - CONFIG_CBSIZE) & ~0xF);
|
2007-07-05 16:01:39 +00:00
|
|
|
kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
|
|
|
|
|
2007-07-05 16:02:09 +00:00
|
|
|
printf("cmdline: %p kbd: %p\n", cmdline, kbd);
|
|
|
|
|
2007-07-05 16:02:17 +00:00
|
|
|
if ((c = getenv("bootargs")) == NULL)
|
|
|
|
c = "";
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:02:17 +00:00
|
|
|
strcpy (cmdline, c);
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2007-07-05 16:02:09 +00:00
|
|
|
cmd_start = (ulong)cmdline;
|
2007-07-05 16:01:39 +00:00
|
|
|
cmd_end = cmd_start + strlen(cmdline);
|
|
|
|
|
2007-07-05 16:02:09 +00:00
|
|
|
init_board_data(kbd);
|
2007-07-05 16:01:39 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
|
|
|
|
|
2007-07-05 16:02:09 +00:00
|
|
|
// do_bdinfo (NULL, 0, 0, NULL);
|
2007-07-05 16:01:39 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-05 16:02:17 +00:00
|
|
|
if ((c = getenv ("clocks_in_mhz")) != NULL) {
|
2007-07-05 16:01:39 +00:00
|
|
|
/* convert all clock information to MHz */
|
|
|
|
kbd->bi_intfreq /= 1000000L;
|
|
|
|
kbd->bi_busfreq /= 1000000L;
|
|
|
|
#if defined(CONFIG_MPC8220)
|
2007-07-05 16:02:09 +00:00
|
|
|
kbd->bi_inpfreq /= 1000000L;
|
|
|
|
kbd->bi_pcifreq /= 1000000L;
|
|
|
|
kbd->bi_pevfreq /= 1000000L;
|
|
|
|
kbd->bi_flbfreq /= 1000000L;
|
|
|
|
kbd->bi_vcofreq /= 1000000L;
|
2007-07-05 16:01:39 +00:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_CPM2)
|
|
|
|
kbd->bi_cpmfreq /= 1000000L;
|
|
|
|
kbd->bi_brgfreq /= 1000000L;
|
|
|
|
kbd->bi_sccfreq /= 1000000L;
|
|
|
|
kbd->bi_vco /= 1000000L;
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_MPC5xxx)
|
|
|
|
kbd->bi_ipbfreq /= 1000000L;
|
|
|
|
kbd->bi_pcifreq /= 1000000L;
|
|
|
|
#endif /* CONFIG_MPC5xxx */
|
|
|
|
}
|
|
|
|
|
2007-07-05 16:02:10 +00:00
|
|
|
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ntohl(os_header->ih_ep); /* FIXME */
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
if (relocate_image(idata->os, (void *)ntohl(os_header->ih_load)))
|
2007-07-05 16:02:09 +00:00
|
|
|
return -1;
|
2007-07-05 16:01:39 +00:00
|
|
|
|
|
|
|
#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
|
|
|
|
unlock_ram_in_cache();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
|
|
|
/* move of_flat_tree if needed */
|
|
|
|
if (of_data) {
|
|
|
|
ulong of_start, of_len;
|
|
|
|
of_len = ((struct boot_param_header *)of_data)->totalsize;
|
|
|
|
/* provide extra 8k pad */
|
2007-07-05 16:02:09 +00:00
|
|
|
if (initrd_data)
|
|
|
|
of_start = (unsigned long)initrd_data - of_len - 8192;
|
2007-07-05 16:01:39 +00:00
|
|
|
else
|
|
|
|
of_start = (ulong)kbd - of_len - 8192;
|
|
|
|
of_start &= ~(4096 - 1); /* align on page */
|
|
|
|
debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
|
|
|
|
of_data, of_data + of_len - 1, of_len, of_len);
|
|
|
|
|
|
|
|
of_flat_tree = (char *)of_start;
|
|
|
|
printf (" Loading Device Tree to %08lx, end %08lx ... ",
|
|
|
|
of_start, of_start + of_len - 1);
|
|
|
|
memmove ((void *)of_start, (void *)of_data, of_len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Linux Kernel Parameters (passing board info data):
|
|
|
|
* r3: ptr to board info data
|
|
|
|
* r4: initrd_start or 0 if no initrd
|
|
|
|
* r5: initrd_end - unused if r4 is 0
|
|
|
|
* r6: Start of command line string
|
|
|
|
* r7: End of command line string
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
|
|
|
if (!of_flat_tree) /* no device tree; boot old style */
|
|
|
|
#endif
|
2007-07-05 16:02:17 +00:00
|
|
|
(*kernel) (kbd, (ulong)initrd_data, initrd_end, cmd_start, cmd_end);
|
2007-07-05 16:01:39 +00:00
|
|
|
/* does not return */
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF_FLAT_TREE
|
|
|
|
/*
|
|
|
|
* Linux Kernel Parameters (passing device tree):
|
|
|
|
* r3: ptr to OF flat tree, followed by the board info data
|
|
|
|
* r4: physical pointer to the kernel itself
|
|
|
|
* r5: NULL
|
|
|
|
* r6: NULL
|
|
|
|
* r7: NULL
|
|
|
|
*/
|
2007-07-05 16:02:17 +00:00
|
|
|
ft_setup(of_flat_tree, kbd, (long)initrd_data, initrd_end);
|
2007-07-05 16:02:10 +00:00
|
|
|
ft_cpu_setup(of_flat_tree, kbd);
|
2007-07-05 16:01:39 +00:00
|
|
|
|
|
|
|
(*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
|
|
|
|
#endif
|
2007-07-05 19:43:36 +00:00
|
|
|
reset_cpu(0);
|
2007-07-05 16:02:17 +00:00
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
return -1;
|
2007-07-05 16:01:39 +00:00
|
|
|
}
|
|
|
|
|
2008-02-20 18:01:54 +00:00
|
|
|
static struct image_handler handler = {
|
|
|
|
.bootm = do_bootm_linux,
|
|
|
|
.image_type = IH_OS_LINUX,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ppclinux_register_image_handler(void)
|
|
|
|
{
|
|
|
|
return register_image_handler(&handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(ppclinux_register_image_handler);
|
|
|
|
|