2006-04-26 15:08:19 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#undef BOOTSTRAP
|
2010-03-14 17:19:58 +00:00
|
|
|
#include "config.h"
|
2010-03-14 15:05:53 +00:00
|
|
|
#include "libopenbios/bindings.h"
|
|
|
|
|
#include "libopenbios/elfload.h"
|
2010-03-14 20:34:01 +00:00
|
|
|
#include "arch/common/nvram.h"
|
2006-04-26 15:08:19 +00:00
|
|
|
#include "libc/diskio.h"
|
|
|
|
|
|
|
|
|
|
void boot(void);
|
|
|
|
|
void *load_elf(char *spec);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
*load_elf(char *spec)
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
int fd;
|
|
|
|
|
void *entry=NULL;
|
|
|
|
|
int i, lszz_offs, elf_offs;
|
|
|
|
|
char buf[128]; // , *addr;
|
|
|
|
|
Elf_ehdr ehdr;
|
|
|
|
|
Elf_phdr *phdr;
|
|
|
|
|
size_t s;
|
|
|
|
|
|
|
|
|
|
if( (fd=open_io(spec)) == -1 )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
if( (elf_offs=find_elf(fd)) < 0 ) {
|
|
|
|
|
printk("----> %s is not an ELF image\n", buf );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !(phdr=elf_readhdrs(fd, 0, &ehdr)) ) {
|
|
|
|
|
printk("elf32_readhdrs failed\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(ullong *)entry = ehdr.e_entry;
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-04-26 15:08:19 +00:00
|
|
|
lszz_offs = elf_offs;
|
|
|
|
|
for( i=0; i<ehdr.e_phnum; i++ ) {
|
|
|
|
|
s = MIN( phdr[i].p_filesz, phdr[i].p_memsz );
|
|
|
|
|
seek_io( fd, elf_offs + phdr[i].p_offset );
|
2008-12-11 20:30:53 +00:00
|
|
|
/* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n",
|
2006-04-26 15:08:19 +00:00
|
|
|
phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset,
|
|
|
|
|
phdr[i].p_vaddr ); */
|
|
|
|
|
if( phdr[i].p_vaddr != phdr[i].p_paddr )
|
|
|
|
|
printk("WARNING: ELF segment virtual addr != physical addr\n");
|
|
|
|
|
lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz );
|
|
|
|
|
if( !s )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
printk("ELF ROM-section loaded at %08lX (size %08lX)\n",
|
|
|
|
|
(ulong)phdr[i].p_vaddr, (ulong)phdr[i].p_memsz);
|
|
|
|
|
}
|
|
|
|
|
free( phdr );
|
|
|
|
|
return entry;
|
2008-12-11 20:30:53 +00:00
|
|
|
#else
|
2006-04-26 15:08:19 +00:00
|
|
|
return NULL;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
boot( void )
|
|
|
|
|
{
|
|
|
|
|
char *path=pop_fstr_copy();
|
|
|
|
|
void *entry;
|
2008-12-11 20:30:53 +00:00
|
|
|
|
2006-04-26 15:08:19 +00:00
|
|
|
if(!path) {
|
|
|
|
|
printk("[unix] Booting default not supported.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printk("[unix] Booting '%s'\n",path);
|
|
|
|
|
entry=load_elf(path);
|
|
|
|
|
if(entry)
|
2009-01-06 19:06:58 +00:00
|
|
|
printk("successfully loaded client at %llx.\n", (unsigned long long)(ucell)entry);
|
2006-04-26 15:08:19 +00:00
|
|
|
else
|
|
|
|
|
printk("failed.\n");
|
|
|
|
|
}
|