FreeBSD/sys/boot/powerpc/ofw/metadata.c
/*
 * Load the information expected by a powerpc kernel.
 *
 * - The 'boothowto' argument is constructed
 * - The 'bootdev' argument is constructed
 * - The kernel environment is copied into kernel space.
 * - Module metadata are formatted and placed in kernel space.
 */
Load the information expected by a powerpc kernel.
- The 'boothowto' argument is constructed
- The 'bootdev' argument is constructed
- The kernel environment is copied into kernel space.
- Module metadata are formatted and placed in kernel space.
Load the information expected by a powerpc kernel . - The ' boothowto ' argument is constructed - The ' bootdev ' argument is constructed - The kernel environment is copied into kernel space . - Module metadata are formatted and placed in kernel space .
int
md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64)
{
    struct preloaded_file	*kfp;
    struct preloaded_file	*xp;
    struct file_metadata	*md;
    vm_offset_t			kernend;
    vm_offset_t			addr;
    vm_offset_t			envp;
    vm_offset_t			fdtp;
    vm_offset_t			size;
    uint64_t			scratch64;
    char			*rootdevname;
    int				howto;
    align = kern64 ? 8 : 4;
    howto = md_getboothowto(args);
    rootdevname = getenv("rootdev");
    if (rootdevname == NULL)
	    rootdevname = getenv("currdev");
    getrootmount(rootdevname);
    addr = 0;
    for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
	if (addr < (xp->f_addr + xp->f_size))
	    addr = xp->f_addr + xp->f_size;
    }
    addr = roundup(addr, PAGE_SIZE);
    envp = addr;
    addr = md_copyenv(addr);
    addr = roundup(addr, PAGE_SIZE);
    *dtb = fdtp = 0;
    if (getenv("usefdt") != NULL) {
        size = fdt_copy(addr);
        *dtb = fdtp = addr;
        addr = roundup(addr + size, PAGE_SIZE);
    }
    kernend = 0;
    kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel");
    if (kfp == NULL)
	kfp = file_findfile(NULL, "elf kernel");
    if (kfp == NULL)
	panic("can't find kernel file");
    file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto);
    if (kern64) {
	scratch64 = envp;
	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof scratch64, &scratch64);
        if (fdtp != 0) {
	    scratch64 = fdtp;
	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof scratch64, &scratch64);
        }
	scratch64 = kernend;
	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof scratch64, &scratch64);
    } else {
	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
        if (fdtp != 0)
	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof fdtp, &fdtp);
	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
    }
    *modulep = addr;
    size = md_copymodules(0, kern64);
    kernend = roundup(addr + size, PAGE_SIZE);
    md = file_findmetadata(kfp, MODINFOMD_KERNEND);
    if (kern64) {
	scratch64 = kernend;
	bcopy(&scratch64, md->md_data, sizeof scratch64);
    } else {
	bcopy(&kernend, md->md_data, sizeof kernend);
    }
    (void)md_copymodules(addr, kern64);
    return(0);
}
int md_load_dual ( char * args , vm_offset_t * modulep , vm_offset_t * dtb , int kern64 ) { struct preloaded_file * kfp ; struct preloaded_file * xp ; struct file_metadata * md ; vm_offset_t kernend ; vm_offset_t addr ; vm_offset_t envp ; vm_offset_t fdtp ; vm_offset_t size ; uint64_t scratch64 ; char * rootdevname ; int howto ; align = kern64 ? 8 : 4 ; howto = md_getboothowto ( args ) ; rootdevname = getenv ( " " ) ; if ( rootdevname == NULL ) rootdevname = getenv ( " " ) ; getrootmount ( rootdevname ) ; addr = 0 ; for ( xp = file_findfile ( NULL , NULL ) ; xp != NULL ; xp = xp -> f_next ) { if ( addr < ( xp -> f_addr + xp -> f_size ) ) addr = xp -> f_addr + xp -> f_size ; } addr = roundup ( addr , PAGE_SIZE ) ; envp = addr ; addr = md_copyenv ( addr ) ; addr = roundup ( addr , PAGE_SIZE ) ; * dtb = fdtp = 0 ; if ( getenv ( " " ) != NULL ) { size = fdt_copy ( addr ) ; * dtb = fdtp = addr ; addr = roundup ( addr + size , PAGE_SIZE ) ; } kernend = 0 ; kfp = file_findfile ( NULL , kern64 ? " " : " " ) ; if ( kfp == NULL ) kfp = file_findfile ( NULL , " " ) ; if ( kfp == NULL ) panic ( " " ) ; file_addmetadata ( kfp , MODINFOMD_HOWTO , sizeof howto , & howto ) ; if ( kern64 ) { scratch64 = envp ; file_addmetadata ( kfp , MODINFOMD_ENVP , sizeof scratch64 , & scratch64 ) ; if ( fdtp != 0 ) { scratch64 = fdtp ; file_addmetadata ( kfp , MODINFOMD_DTBP , sizeof scratch64 , & scratch64 ) ; } scratch64 = kernend ; file_addmetadata ( kfp , MODINFOMD_KERNEND , sizeof scratch64 , & scratch64 ) ; } else { file_addmetadata ( kfp , MODINFOMD_ENVP , sizeof envp , & envp ) ; if ( fdtp != 0 ) file_addmetadata ( kfp , MODINFOMD_DTBP , sizeof fdtp , & fdtp ) ; file_addmetadata ( kfp , MODINFOMD_KERNEND , sizeof kernend , & kernend ) ; } * modulep = addr ; size = md_copymodules ( 0 , kern64 ) ; kernend = roundup ( addr + size , PAGE_SIZE ) ; md = file_findmetadata ( kfp , MODINFOMD_KERNEND ) ; if ( kern64 ) { scratch64 = kernend ; bcopy ( & scratch64 , md -> md_data , sizeof scratch64 ) ; } else { bcopy ( & kernend , md -> md_data , sizeof kernend ) ; } ( void ) md_copymodules ( addr , kern64 ) ; return ( 0 ) ; }
Load the information expected by a powerpc kernel.
Load the information expected by a powerpc kernel .
/* 
     * Allow the environment variable 'rootdev' to override the supplied device 
     * This should perhaps go to MI code and/or have $rootdev tested/set by
     * MI code before launching the kernel.
     */ /* Try reading the /etc/fstab file to select the root device */ /* find the last module in the chain */ /* pad to a page boundary */ /* copy our environment */ /* pad to a page boundary */ /* Copy out FDT */