Changeset View
Changeset View
Standalone View
Standalone View
sys/powerpc/ofw/ofw_initrd.c
Show All 30 Lines | |||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/pmap.h> | #include <vm/pmap.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <machine/elf.h> | |||||
#include <machine/param.h> | |||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include "opt_md.h" | #include "opt_md.h" | ||||
extern u_char *mfs_root; | extern u_char *mfs_root; | ||||
extern int mfs_root_size; | extern int mfs_root_size; | ||||
static void ofw_initrd_probe_and_attach(void *junk); | static void ofw_initrd_probe_and_attach(void *junk); | ||||
SYSINIT(ofw_initrd_probe_and_attach, SI_SUB_KMEM, SI_ORDER_ANY, | SYSINIT(ofw_initrd_probe_and_attach, SI_SUB_KMEM, SI_ORDER_ANY, | ||||
ofw_initrd_probe_and_attach, NULL); | ofw_initrd_probe_and_attach, NULL); | ||||
static void | static void | ||||
ofw_initrd_probe_and_attach(void *junk) | ofw_initrd_probe_and_attach(void *junk) | ||||
{ | { | ||||
phandle_t chosen; | phandle_t chosen; | ||||
vm_paddr_t start, end; | vm_paddr_t start, end; | ||||
pcell_t cell[2]; | pcell_t cell[2]; | ||||
ssize_t size; | ssize_t size; | ||||
u_char *taste; | |||||
Elf_Ehdr ehdr; | |||||
if (!hw_direct_map) | if (!hw_direct_map) | ||||
return; | return; | ||||
chosen = OF_finddevice("/chosen"); | chosen = OF_finddevice("/chosen"); | ||||
if (chosen <= 0) | if (chosen <= 0) | ||||
return; | return; | ||||
Show All 17 Lines | ofw_initrd_probe_and_attach(void *junk) | ||||
else if (size == 8) | else if (size == 8) | ||||
end = (uint64_t)cell[0] << 32 | cell[1]; | end = (uint64_t)cell[0] << 32 | cell[1]; | ||||
else{ | else{ | ||||
printf("ofw_initrd: Wrong linux,initrd-end size\n"); | printf("ofw_initrd: Wrong linux,initrd-end size\n"); | ||||
return; | return; | ||||
} | } | ||||
if (end - start > 0) { | if (end - start > 0) { | ||||
mfs_root = (u_char *) PHYS_TO_DMAP(start); | taste = (u_char*) PHYS_TO_DMAP(start); | ||||
memcpy(&ehdr, taste, sizeof(ehdr)); | |||||
bdragon: This memcpy is for alignment reasons. | |||||
if (IS_ELF(ehdr)) { | |||||
printf("ofw_initrd: initrd is kernel image!\n"); | |||||
return; | |||||
} | |||||
mfs_root = taste; | |||||
mfs_root_size = end - start; | mfs_root_size = end - start; | ||||
printf("ofw_initrd: initrd loaded at 0x%08lx-0x%08lx\n", | printf("ofw_initrd: initrd loaded at 0x%08lx-0x%08lx\n", | ||||
start, end); | start, end); | ||||
} | } | ||||
} | } | ||||
This memcpy is for alignment reasons.