These modules allow a bootloader to load a kernel from multiple sources
(ie cramfs, jffs, straight from flash etc). It always load the file
"/linux" right now. Currently included are modules for cramfs, jffs2 and
zImage straight from flash. Currently, the interface is:

struct kernel_loader {
        
        /* Return true if there is a kernel contained at src */
        int (* check_magic)(struct part_info *part);
        
        /* load the kernel from the partition part to dst, return the number
         * of bytes copied if successful, zero if not */
        u32 (* load_kernel)(u32 *dst, struct part_info *part);

        /* A brief description of the module (ie, "cramfs") */
        char *name;
};


The bootloader can cycle through the available modules until it finds
one with a matching kernel, at which point it attempts to load the
kernel by that message.

For the decompressors to function at a decent speed, your bootloader
should enable the i-cache and set flash timings properly. The modules
were written around blob, but should be easily inserted into any
boot_loader, the only file needing specific editing for the boot loader
is load_kernel.c (and possibly some types.h issues).

Example code for within the bootloader below:

void load_kernel(blobStatus *status)
{
        int i;
        unsigned long size;
        struct part_info part;
        
        part.erasesize = MAIN_BLOCK_SIZE;
        part.size = KERNEL_LEN;
        part.offset = (char *) KERNEL_START;
        for (i = 0; loader[i] && !loader[i]->check_magic(&part); i++);
        if (!loader[i]) {
                        SerialOutputString("unable to find kernel, loading raw "
        "data and hoping for the best!\rloading");
                        size = KERNEL_LEN;
                        MyMemCpy((u32 *)KERNEL_RAM_BASE,
                 (u32 *)KERNEL_START, size >> 2);
                
        } else {
                        SerialOutputString("loading kernel from ");
                        SerialOutputString(loader[i]->name);
                        if ((size = loader[i]->load_kernel((u32 *)KERNEL_RAM_BASE,     
                 
        &part)) == 0) {
                                SerialOutputString(" error loading kernel!\r");
                                return;
                        }
        }
        SerialOutputString("loaded 0x");
        SerialOutputHex(size);
        SerialOutputString(" bytes\r");
        status->kernelSize = size;
        status->kernelType = fromFlash;
}


Current issues (release early, release often)

the cramfs module doesn't follow symlinks when looking for /linux (jffs2
*does* follow symlinks though)

jffs2 currently doesn't check crc's, something I'll add monday, but I
decided to release this now to give people something to play with for
hte weekend.

future ideas:

if we can load the kernel from a fs image, why not other things, like a
config, with bootloader parameters (whether or not to load a ramdisk,
etc) as well as append= parameters for the kernel.

I'll also email a patch agoinst blob-1.0.8-pre2 on the lart list.

load_kernel.tar.bz2

Reply via email to