iPXE
Data Structures | Functions
bzimage.c File Reference

Linux bzImage image format. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <bzimage.h>
#include <initrd.h>
#include <ipxe/uaccess.h>
#include <ipxe/image.h>
#include <ipxe/segment.h>
#include <ipxe/init.h>
#include <ipxe/cpio.h>
#include <ipxe/features.h>

Go to the source code of this file.

Data Structures

struct  bzimage_context
 bzImage context More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_IMAGE,"bzImage", DHCP_EB_FEATURE_BZIMAGE, 1)
static int bzimage_parse_header (struct image *image, struct bzimage_context *bzimg, userptr_t src)
 Parse bzImage header.
static void bzimage_update_header (struct image *image, struct bzimage_context *bzimg, userptr_t dst)
 Update bzImage header in loaded kernel.
static int bzimage_parse_cmdline (struct image *image, struct bzimage_context *bzimg, const char *cmdline)
 Parse kernel command line for bootloader parameters.
static void bzimage_set_cmdline (struct image *image, struct bzimage_context *bzimg, const char *cmdline)
 Set command line.
static void bzimage_parse_cpio_cmdline (struct image *image, struct cpio_header *cpio, const char *cmdline)
 Parse standalone image command line for cpio parameters.
static size_t bzimage_align (size_t len)
 Align initrd length.
static size_t bzimage_load_initrd (struct image *image, struct image *initrd, userptr_t address)
 Load initrd.
static int bzimage_check_initrds (struct image *image, struct bzimage_context *bzimg)
 Check that initrds can be loaded.
static void bzimage_load_initrds (struct image *image, struct bzimage_context *bzimg)
 Load initrds, if any.
static int bzimage_exec (struct image *image)
 Execute bzImage image.
int bzimage_probe (struct image *image)
 Probe bzImage image.
struct image_type
bzimage_image_type 
__image_type (PROBE_NORMAL)
 Linux bzImage image type.

Detailed Description

Linux bzImage image format.

Definition in file bzimage.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
FEATURE ( FEATURE_IMAGE  ,
"bzImage"  ,
DHCP_EB_FEATURE_BZIMAGE  ,
 
)
static int bzimage_parse_header ( struct image image,
struct bzimage_context bzimg,
userptr_t  src 
) [static]

Parse bzImage header.

Parameters:
imagebzImage file
bzimgbzImage context
srcbzImage to parse
Return values:
rcReturn status code

Definition at line 97 of file bzimage.c.

References bzimage_header::boot_flag, bzimage_context::bzhdr, BZI_ASSUMED_RM_SIZE, BZI_BOOT_FLAG, BZI_CMDLINE_OFFSET, BZI_CMDLINE_SIZE, BZI_HDR_OFFSET, BZI_INITRD_MAX, BZI_LOAD_HIGH, BZI_LOAD_HIGH_ADDR, BZI_LOAD_LOW_ADDR, BZI_SIGNATURE, BZI_STACK_SIZE, bzimage_context::cmdline_magic, bzimage_context::cmdline_size, bzimage_header::cmdline_size, copy_from_user(), DBGC, ENOEXEC, bzimage_header::header, bzimage_header::initrd_addr_max, image::len, bzimage_header::loadflags, bzimage_context::mem_limit, memset(), phys_to_user(), bzimage_context::pm_kernel, bzimage_context::pm_sz, real_to_user(), bzimage_context::rm_cmdline, bzimage_context::rm_filesz, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_kernel_seg, bzimage_context::rm_memsz, bzimage_header::setup_sects, bzimage_header::syssize, syssize, user_to_phys(), bzimage_header::version, bzimage_context::version, bzimage_header::vid_mode, and bzimage_context::vid_mode.

Referenced by bzimage_exec(), and bzimage_probe().

                                                  {
        unsigned int syssize;
        int is_bzimage;

        /* Sanity check */
        if ( image->len < ( BZI_HDR_OFFSET + sizeof ( bzimg->bzhdr ) ) ) {
                DBGC ( image, "bzImage %p too short for kernel header\n",
                       image );
                return -ENOEXEC;
        }

        /* Read in header structures */
        memset ( bzimg, 0, sizeof ( *bzimg ) );
        copy_from_user ( &bzimg->cmdline_magic, src, BZI_CMDLINE_OFFSET,
                         sizeof ( bzimg->cmdline_magic ) );
        copy_from_user ( &bzimg->bzhdr, src, BZI_HDR_OFFSET,
                         sizeof ( bzimg->bzhdr ) );

        /* Calculate size of real-mode portion */
        bzimg->rm_filesz = ( ( ( bzimg->bzhdr.setup_sects ?
                                 bzimg->bzhdr.setup_sects : 4 ) + 1 ) << 9 );
        if ( bzimg->rm_filesz > image->len ) {
                DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
                       image, bzimg->rm_filesz );
                return -ENOEXEC;
        }
        bzimg->rm_memsz = BZI_ASSUMED_RM_SIZE;

        /* Calculate size of protected-mode portion */
        bzimg->pm_sz = ( image->len - bzimg->rm_filesz );
        syssize = ( ( bzimg->pm_sz + 15 ) / 16 );

        /* Check for signatures and determine version */
        if ( bzimg->bzhdr.boot_flag != BZI_BOOT_FLAG ) {
                DBGC ( image, "bzImage %p missing 55AA signature\n", image );
                return -ENOEXEC;
        }
        if ( bzimg->bzhdr.header == BZI_SIGNATURE ) {
                /* 2.00+ */
                bzimg->version = bzimg->bzhdr.version;
        } else {
                /* Pre-2.00.  Check that the syssize field is correct,
                 * as a guard against accepting arbitrary binary data,
                 * since the 55AA check is pretty lax.  Note that the
                 * syssize field is unreliable for protocols between
                 * 2.00 and 2.03 inclusive, so we should not always
                 * check this field.
                 */
                bzimg->version = 0x0100;
                if ( bzimg->bzhdr.syssize != syssize ) {
                        DBGC ( image, "bzImage %p bad syssize %x (expected "
                               "%x)\n", image, bzimg->bzhdr.syssize, syssize );
                        return -ENOEXEC;
                }
        }

        /* Determine image type */
        is_bzimage = ( ( bzimg->version >= 0x0200 ) ?
                       ( bzimg->bzhdr.loadflags & BZI_LOAD_HIGH ) : 0 );

        /* Calculate load address of real-mode portion */
        bzimg->rm_kernel_seg = ( is_bzimage ? 0x1000 : 0x9000 );
        bzimg->rm_kernel = real_to_user ( bzimg->rm_kernel_seg, 0 );

        /* Allow space for the stack and heap */
        bzimg->rm_memsz += BZI_STACK_SIZE;
        bzimg->rm_heap = bzimg->rm_memsz;

        /* Allow space for the command line */
        bzimg->rm_cmdline = bzimg->rm_memsz;
        bzimg->rm_memsz += BZI_CMDLINE_SIZE;

        /* Calculate load address of protected-mode portion */
        bzimg->pm_kernel = phys_to_user ( is_bzimage ? BZI_LOAD_HIGH_ADDR
                                        : BZI_LOAD_LOW_ADDR );

        /* Extract video mode */
        bzimg->vid_mode = bzimg->bzhdr.vid_mode;

        /* Extract memory limit */
        bzimg->mem_limit = ( ( bzimg->version >= 0x0203 ) ?
                             bzimg->bzhdr.initrd_addr_max : BZI_INITRD_MAX );

        /* Extract command line size */
        bzimg->cmdline_size = ( ( bzimg->version >= 0x0206 ) ?
                                bzimg->bzhdr.cmdline_size : BZI_CMDLINE_SIZE );

        DBGC ( image, "bzImage %p version %04x RM %#lx+%#zx PM %#lx+%#zx "
               "cmdlen %zd\n", image, bzimg->version,
               user_to_phys ( bzimg->rm_kernel, 0 ), bzimg->rm_filesz,
               user_to_phys ( bzimg->pm_kernel, 0 ), bzimg->pm_sz,
               bzimg->cmdline_size );

        return 0;
}
static void bzimage_update_header ( struct image image,
struct bzimage_context bzimg,
userptr_t  dst 
) [static]

Update bzImage header in loaded kernel.

Parameters:
imagebzImage file
bzimgbzImage context
dstbzImage to update

Definition at line 202 of file bzimage.c.

References bzimage_context::bzhdr, BZI_CAN_USE_HEAP, BZI_CMDLINE_MAGIC, BZI_CMDLINE_OFFSET, BZI_HDR_OFFSET, BZI_LOADER_TYPE_IPXE, bzimage_header::cmd_line_ptr, bzimage_context::cmdline_magic, copy_to_user(), DBGC, bzimage_header::heap_end_ptr, bzimage_header::loadflags, bzimage_cmdline::magic, bzimage_cmdline::offset, bzimage_header::ramdisk_image, bzimage_context::ramdisk_image, bzimage_header::ramdisk_size, bzimage_context::ramdisk_size, bzimage_context::rm_cmdline, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_memsz, bzimage_header::setup_move_size, bzimage_header::type_of_loader, user_to_phys(), bzimage_context::version, bzimage_header::vid_mode, and bzimage_context::vid_mode.

Referenced by bzimage_exec().

                                                    {

        /* Set loader type */
        if ( bzimg->version >= 0x0200 )
                bzimg->bzhdr.type_of_loader = BZI_LOADER_TYPE_IPXE;

        /* Set heap end pointer */
        if ( bzimg->version >= 0x0201 ) {
                bzimg->bzhdr.heap_end_ptr = ( bzimg->rm_heap - 0x200 );
                bzimg->bzhdr.loadflags |= BZI_CAN_USE_HEAP;
        }

        /* Set command line */
        if ( bzimg->version >= 0x0202 ) {
                bzimg->bzhdr.cmd_line_ptr = user_to_phys ( bzimg->rm_kernel,
                                                           bzimg->rm_cmdline );
        } else {
                bzimg->cmdline_magic.magic = BZI_CMDLINE_MAGIC;
                bzimg->cmdline_magic.offset = bzimg->rm_cmdline;
                if ( bzimg->version >= 0x0200 )
                        bzimg->bzhdr.setup_move_size = bzimg->rm_memsz;
        }

        /* Set video mode */
        bzimg->bzhdr.vid_mode = bzimg->vid_mode;

        /* Set initrd address */
        if ( bzimg->version >= 0x0200 ) {
                bzimg->bzhdr.ramdisk_image = bzimg->ramdisk_image;
                bzimg->bzhdr.ramdisk_size = bzimg->ramdisk_size;
        }

        /* Write out header structures */
        copy_to_user ( dst, BZI_CMDLINE_OFFSET, &bzimg->cmdline_magic,
                       sizeof ( bzimg->cmdline_magic ) );
        copy_to_user ( dst, BZI_HDR_OFFSET, &bzimg->bzhdr,
                       sizeof ( bzimg->bzhdr ) );

        DBGC ( image, "bzImage %p vidmode %d\n", image, bzimg->vid_mode );
}
static int bzimage_parse_cmdline ( struct image image,
struct bzimage_context bzimg,
const char *  cmdline 
) [static]

Parse kernel command line for bootloader parameters.

Parameters:
imagebzImage file
bzimgbzImage context
cmdlineKernel command line
Return values:
rcReturn status code

Definition at line 253 of file bzimage.c.

References BZI_VID_MODE_ASK, BZI_VID_MODE_EXT, BZI_VID_MODE_NORMAL, DBGC, bzimage_context::mem_limit, strcmp(), strstr(), strtoul(), and bzimage_context::vid_mode.

Referenced by bzimage_exec().

                                                         {
        char *vga;
        char *mem;

        /* Look for "vga=" */
        if ( ( vga = strstr ( cmdline, "vga=" ) ) ) {
                vga += 4;
                if ( strcmp ( vga, "normal" ) == 0 ) {
                        bzimg->vid_mode = BZI_VID_MODE_NORMAL;
                } else if ( strcmp ( vga, "ext" ) == 0 ) {
                        bzimg->vid_mode = BZI_VID_MODE_EXT;
                } else if ( strcmp ( vga, "ask" ) == 0 ) {
                        bzimg->vid_mode = BZI_VID_MODE_ASK;
                } else {
                        bzimg->vid_mode = strtoul ( vga, &vga, 0 );
                        if ( *vga && ( *vga != ' ' ) ) {
                                DBGC ( image, "bzImage %p strange \"vga=\""
                                       "terminator '%c'\n", image, *vga );
                        }
                }
        }

        /* Look for "mem=" */
        if ( ( mem = strstr ( cmdline, "mem=" ) ) ) {
                mem += 4;
                bzimg->mem_limit = strtoul ( mem, &mem, 0 );
                switch ( *mem ) {
                case 'G':
                case 'g':
                        bzimg->mem_limit <<= 10;
                        /* Fall through */
                case 'M':
                case 'm':
                        bzimg->mem_limit <<= 10;
                        /* Fall through */
                case 'K':
                case 'k':
                        bzimg->mem_limit <<= 10;
                        break;
                case '\0':
                case ' ':
                        break;
                default:
                        DBGC ( image, "bzImage %p strange \"mem=\" "
                               "terminator '%c'\n", image, *mem );
                        break;
                }
                bzimg->mem_limit -= 1;
        }

        return 0;
}
static void bzimage_set_cmdline ( struct image image,
struct bzimage_context bzimg,
const char *  cmdline 
) [static]

Set command line.

Parameters:
imagebzImage image
bzimgbzImage context
cmdlineKernel command line

Definition at line 315 of file bzimage.c.

References bzimage_context::cmdline_size, copy_to_user(), DBGC, bzimage_context::rm_cmdline, bzimage_context::rm_kernel, and strlen().

Referenced by bzimage_exec().

                                                        {
        size_t cmdline_len;

        /* Copy command line down to real-mode portion */
        cmdline_len = ( strlen ( cmdline ) + 1 );
        if ( cmdline_len > bzimg->cmdline_size )
                cmdline_len = bzimg->cmdline_size;
        copy_to_user ( bzimg->rm_kernel, bzimg->rm_cmdline,
                       cmdline, cmdline_len );
        DBGC ( image, "bzImage %p command line \"%s\"\n", image, cmdline );
}
static void bzimage_parse_cpio_cmdline ( struct image image,
struct cpio_header cpio,
const char *  cmdline 
) [static]

Parse standalone image command line for cpio parameters.

Parameters:
imagebzImage file
cpioCPIO header
cmdlineCommand line

Definition at line 336 of file bzimage.c.

References cpio_header::c_mode, cpio_set_field(), DBGC, end, strstr(), and strtoul().

Referenced by bzimage_load_initrd().

                                                               {
        char *arg;
        char *end;
        unsigned int mode;

        /* Look for "mode=" */
        if ( ( arg = strstr ( cmdline, "mode=" ) ) ) {
                arg += 5;
                mode = strtoul ( arg, &end, 8 /* Octal for file mode */ );
                if ( *end && ( *end != ' ' ) ) {
                        DBGC ( image, "bzImage %p strange \"mode=\""
                               "terminator '%c'\n", image, *end );
                }
                cpio_set_field ( cpio->c_mode, ( 0100000 | mode ) );
        }
}
static size_t bzimage_align ( size_t  len) [inline, static]

Align initrd length.

Parameters:
lenLength
Return values:
lenLength rounded up to INITRD_ALIGN

Definition at line 361 of file bzimage.c.

References INITRD_ALIGN.

Referenced by bzimage_check_initrds(), and bzimage_load_initrds().

                                                  {

        return ( ( len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) );
}
static size_t bzimage_load_initrd ( struct image image,
struct image initrd,
userptr_t  address 
) [static]

Load initrd.

Parameters:
imagebzImage image
initrdinitrd image
addressAddress at which to load, or UNULL
Return values:
lenLength of loaded image, excluding zero-padding

Definition at line 374 of file bzimage.c.

References bzimage_parse_cpio_cmdline(), cpio_header::c_filesize, cpio_header::c_magic, cpio_header::c_mode, cpio_header::c_namesize, cpio_header::c_nlink, image::cmdline, cmdline, copy_to_user(), CPIO_MAGIC, cpio_set_field(), image::data, DBGC, DBGC2_MD5A, INITRD_ALIGN, image::len, memcpy(), memmove_user(), memset(), memset_user(), offset, strchr(), strlen(), user_to_phys(), and user_to_virt().

Referenced by bzimage_check_initrds(), and bzimage_load_initrds().

                                                        {
        char *filename = initrd->cmdline;
        char *cmdline;
        struct cpio_header cpio;
        size_t offset;
        size_t name_len;
        size_t pad_len;

        /* Do not include kernel image itself as an initrd */
        if ( initrd == image )
                return 0;

        /* Create cpio header for non-prebuilt images */
        if ( filename && filename[0] ) {
                cmdline = strchr ( filename, ' ' );
                name_len = ( ( cmdline ? ( ( size_t ) ( cmdline - filename ) )
                               : strlen ( filename ) ) + 1 /* NUL */ );
                memset ( &cpio, '0', sizeof ( cpio ) );
                memcpy ( cpio.c_magic, CPIO_MAGIC, sizeof ( cpio.c_magic ) );
                cpio_set_field ( cpio.c_mode, 0100644 );
                cpio_set_field ( cpio.c_nlink, 1 );
                cpio_set_field ( cpio.c_filesize, initrd->len );
                cpio_set_field ( cpio.c_namesize, name_len );
                if ( cmdline ) {
                        bzimage_parse_cpio_cmdline ( image, &cpio,
                                                     ( cmdline + 1 /* ' ' */ ));
                }
                offset = ( ( sizeof ( cpio ) + name_len + 0x03 ) & ~0x03 );
        } else {
                offset = 0;
                name_len = 0;
        }

        /* Copy in initrd image body (and cpio header if applicable) */
        if ( address ) {
                memmove_user ( address, offset, initrd->data, 0, initrd->len );
                if ( offset ) {
                        memset_user ( address, 0, 0, offset );
                        copy_to_user ( address, 0, &cpio, sizeof ( cpio ) );
                        copy_to_user ( address, sizeof ( cpio ), filename,
                                       ( name_len - 1 /* NUL (or space) */ ) );
                }
                DBGC ( image, "bzImage %p initrd %p [%#08lx,%#08lx,%#08lx)"
                       "%s%s\n", image, initrd, user_to_phys ( address, 0 ),
                       user_to_phys ( address, offset ),
                       user_to_phys ( address, ( offset + initrd->len ) ),
                       ( filename ? " " : "" ), ( filename ? filename : "" ) );
                DBGC2_MD5A ( image, user_to_phys ( address, offset ),
                             user_to_virt ( address, offset ), initrd->len );
        }
        offset += initrd->len;

        /* Zero-pad to next INITRD_ALIGN boundary */
        pad_len = ( ( -offset ) & ( INITRD_ALIGN - 1 ) );
        if ( address )
                memset_user ( address, offset, 0, pad_len );

        return offset;
}
static int bzimage_check_initrds ( struct image image,
struct bzimage_context bzimg 
) [static]

Check that initrds can be loaded.

Parameters:
imagebzImage image
bzimgbzImage context
Return values:
rcReturn status code

Definition at line 443 of file bzimage.c.

References bottom, bzimage_align(), bzimage_load_initrd(), image::cmdline, image::data, DBGC, DBGC2_MD5A, ENOBUFS, for_each_image, initrd_reshuffle_check(), image::len, len, bzimage_context::mem_limit, bzimage_context::pm_kernel, bzimage_context::pm_sz, rc, strerror(), UNULL, user_to_phys(), user_to_virt(), and userptr_add().

Referenced by bzimage_exec().

                                                                   {
        struct image *initrd;
        userptr_t bottom;
        size_t len = 0;
        int rc;

        /* Calculate total loaded length of initrds */
        for_each_image ( initrd ) {

                /* Skip kernel */
                if ( initrd == image )
                        continue;

                /* Calculate length */
                len += bzimage_load_initrd ( image, initrd, UNULL );
                len = bzimage_align ( len );

                DBGC ( image, "bzImage %p initrd %p from [%#08lx,%#08lx)%s%s\n",
                       image, initrd, user_to_phys ( initrd->data, 0 ),
                       user_to_phys ( initrd->data, initrd->len ),
                       ( initrd->cmdline ? " " : "" ),
                       ( initrd->cmdline ? initrd->cmdline : "" ) );
                DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ),
                             user_to_virt ( initrd->data, 0 ), initrd->len );
        }

        /* Calculate lowest usable address */
        bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz );

        /* Check that total length fits within space available for
         * reshuffling.  This is a conservative check, since CPIO
         * headers are not present during reshuffling, but this
         * doesn't hurt and keeps the code simple.
         */
        if ( ( rc = initrd_reshuffle_check ( len, bottom ) ) != 0 ) {
                DBGC ( image, "bzImage %p failed reshuffle check: %s\n",
                       image, strerror ( rc ) );
                return rc;
        }

        /* Check that total length fits within kernel's memory limit */
        if ( user_to_phys ( bottom, len ) > bzimg->mem_limit ) {
                DBGC ( image, "bzImage %p not enough space for initrds\n",
                       image );
                return -ENOBUFS;
        }

        return 0;
}
static void bzimage_load_initrds ( struct image image,
struct bzimage_context bzimg 
) [static]

Load initrds, if any.

Parameters:
imagebzImage image
bzimgbzImage context

Definition at line 500 of file bzimage.c.

References bzimage_align(), bzimage_load_initrd(), image::data, DBGC, dest, for_each_image, INITRD_ALIGN, initrd_reshuffle(), image::len, len, bzimage_context::mem_limit, NULL, offset, phys_to_user(), bzimage_context::pm_kernel, bzimage_context::pm_sz, bzimage_context::ramdisk_image, bzimage_context::ramdisk_size, top, UNULL, user_to_phys(), userptr_add(), and userptr_sub().

Referenced by bzimage_exec().

                                                                   {
        struct image *initrd;
        struct image *highest = NULL;
        struct image *other;
        userptr_t top;
        userptr_t dest;
        size_t offset;
        size_t len;

        /* Reshuffle initrds into desired order */
        initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) );

        /* Find highest initrd */
        for_each_image ( initrd ) {
                if ( ( highest == NULL ) ||
                     ( userptr_sub ( initrd->data, highest->data ) > 0 ) ) {
                        highest = initrd;
                }
        }

        /* Do nothing if there are no initrds */
        if ( ! highest )
                return;

        /* Find highest usable address */
        top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
        if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
                top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
                                     ~( INITRD_ALIGN - 1 ) );
        }
        DBGC ( image, "bzImage %p loading initrds from %#08lx downwards\n",
               image, user_to_phys ( top, -1 ) );

        /* Load initrds in order */
        for_each_image ( initrd ) {

                /* Calculate cumulative length of following
                 * initrds (including padding).
                 */
                offset = 0;
                for_each_image ( other ) {
                        if ( other == initrd )
                                offset = 0;
                        offset += bzimage_load_initrd ( image, other, UNULL );
                        offset = bzimage_align ( offset );
                }

                /* Load initrd at this address */
                dest = userptr_add ( top, -offset );
                len = bzimage_load_initrd ( image, initrd, dest );

                /* Record initrd location */
                if ( ! bzimg->ramdisk_image )
                        bzimg->ramdisk_image = user_to_phys ( dest, 0 );
                bzimg->ramdisk_size = ( user_to_phys ( dest, len ) -
                                        bzimg->ramdisk_image );
        }
        DBGC ( image, "bzImage %p initrds at [%#08lx,%#08lx)\n",
               image, bzimg->ramdisk_image,
               ( bzimg->ramdisk_image + bzimg->ramdisk_size ) );
}
static int bzimage_exec ( struct image image) [static]

Execute bzImage image.

Parameters:
imagebzImage image
Return values:
rcReturn status code

Definition at line 569 of file bzimage.c.

References __asm__(), assert, bzimage_check_initrds(), bzimage_load_initrds(), bzimage_parse_cmdline(), bzimage_parse_header(), bzimage_set_cmdline(), bzimage_update_header(), image::cmdline, cmdline, image::data, DBGC, ECANCELED, image_get(), memcpy_user(), bzimage_context::pm_kernel, bzimage_context::pm_sz, prep_segment(), rc, REAL_CODE, bzimage_context::rm_filesz, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_kernel_seg, bzimage_context::rm_memsz, shutdown_boot(), strerror(), and unregister_image().

                                                {
        struct bzimage_context bzimg;
        const char *cmdline = ( image->cmdline ? image->cmdline : "" );
        int rc;

        /* Read and parse header from image */
        if ( ( rc = bzimage_parse_header ( image, &bzimg,
                                           image->data ) ) != 0 )
                return rc;

        /* Prepare segments */
        if ( ( rc = prep_segment ( bzimg.rm_kernel, bzimg.rm_filesz,
                                   bzimg.rm_memsz ) ) != 0 ) {
                DBGC ( image, "bzImage %p could not prepare RM segment: %s\n",
                       image, strerror ( rc ) );
                return rc;
        }
        if ( ( rc = prep_segment ( bzimg.pm_kernel, bzimg.pm_sz,
                                   bzimg.pm_sz ) ) != 0 ) {
                DBGC ( image, "bzImage %p could not prepare PM segment: %s\n",
                       image, strerror ( rc ) );
                return rc;
        }

        /* Parse command line for bootloader parameters */
        if ( ( rc = bzimage_parse_cmdline ( image, &bzimg, cmdline ) ) != 0)
                return rc;

        /* Check that initrds can be loaded */
        if ( ( rc = bzimage_check_initrds ( image, &bzimg ) ) != 0 )
                return rc;

        /* Remove kernel from image list (without invalidating image pointer) */
        unregister_image ( image_get ( image ) );

        /* Load segments */
        memcpy_user ( bzimg.rm_kernel, 0, image->data,
                      0, bzimg.rm_filesz );
        memcpy_user ( bzimg.pm_kernel, 0, image->data,
                      bzimg.rm_filesz, bzimg.pm_sz );

        /* Store command line */
        bzimage_set_cmdline ( image, &bzimg, cmdline );

        /* Prepare for exiting.  Must do this before loading initrds,
         * since loading the initrds will corrupt the external heap.
         */
        shutdown_boot();

        /* Load any initrds */
        bzimage_load_initrds ( image, &bzimg );

        /* Update kernel header */
        bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );

        DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
               "(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),
               bzimg.rm_kernel_seg, bzimg.rm_heap );

        /* Jump to the kernel */
        __asm__ __volatile__ ( REAL_CODE ( "movw %w0, %%ds\n\t"
                                           "movw %w0, %%es\n\t"
                                           "movw %w0, %%fs\n\t"
                                           "movw %w0, %%gs\n\t"
                                           "movw %w0, %%ss\n\t"
                                           "movw %w1, %%sp\n\t"
                                           "pushw %w2\n\t"
                                           "pushw $0\n\t"
                                           "lret\n\t" )
                               : : "R" ( bzimg.rm_kernel_seg ),
                                   "R" ( bzimg.rm_heap ),
                                   "R" ( bzimg.rm_kernel_seg + 0x20 ) );

        /* There is no way for the image to return, since we provide
         * no return address.
         */
        assert ( 0 );

        return -ECANCELED; /* -EIMPOSSIBLE */
}
int bzimage_probe ( struct image image)

Probe bzImage image.

Parameters:
imagebzImage file
Return values:
rcReturn status code

Definition at line 656 of file bzimage.c.

References bzimage_parse_header(), image::data, and rc.

                                          {
        struct bzimage_context bzimg;
        int rc;

        /* Read and parse header from image */
        if ( ( rc = bzimage_parse_header ( image, &bzimg,
                                           image->data ) ) != 0 )
                return rc;

        return 0;
}
struct image_type bzimage_image_type __image_type ( PROBE_NORMAL  ) [read]

Linux bzImage image type.