diff --git a/src/arch/i386/image/bzimage.c b/src/arch/i386/image/bzimage.c new file mode 100644 index 00000000..769c838d --- /dev/null +++ b/src/arch/i386/image/bzimage.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/** + * @file + * + * Linux bzImage image format + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct image_type bzimage_image_type __image_type ( PROBE_NORMAL ); + +/** + * Execute bzImage image + * + * @v image bzImage image + * @ret rc Return status code + */ +static int bzimage_exec ( struct image *image ) { +} + +/** + * Load bzImage image into memory + * + * @v image bzImage file + * @ret rc Return status code + */ +int bzimage_load ( struct image *image ) { + struct bzimage_header bzhdr; + + /* Sanity check */ + if ( image->len < ( BZHDR_OFFSET + sizeof ( bzhdr ) ) ) { + DBGC ( image, "BZIMAGE %p too short\n", image ); + return -ENOEXEC; + } + + /* Read and verify header */ + copy_from_user ( &bzhdr, image->data, BZHDR_OFFSET, sizeof ( bzhdr ) ); + if ( bzhdr.header != BZIMAGE_SIGNATURE ) { + DBGC ( image, "BZIMAGE %p not a bzImage\n", image ); + return -ENOEXEC; + } + + /* This is a bzImage image, valid or otherwise */ + if ( ! image->type ) + image->type = &bzimage_image_type; + + return 0; +} + +/** Linux bzImage image type */ +struct image_type bzimage_image_type __image_type ( PROBE_NORMAL ) = { + .name = "bzImage", + .load = bzimage_load, + .exec = bzimage_exec, +}; diff --git a/src/arch/i386/include/bzimage.h b/src/arch/i386/include/bzimage.h new file mode 100644 index 00000000..4b6c1cf3 --- /dev/null +++ b/src/arch/i386/include/bzimage.h @@ -0,0 +1,73 @@ +#ifndef _BZIMAGE_H +#define _BZIMAGE_H + +#include + +/** + * A bzImage header + * + * As documented in Documentation/i386/boot.txt + */ +struct bzimage_header { + /** The size of the setup in sectors + * + * If this field contains 0, assume it contains 4. + */ + uint8_t setup_sects; + /** If set, the root is mounted readonly */ + uint16_t root_flags; + /** DO NOT USE - for bootsect.S use only */ + uint16_t syssize; + /** DO NOT USE - obsolete */ + uint16_t swap_dev; + /** DO NOT USE - for bootsect.S use only */ + uint16_t ram_size; + /** Video mode control */ + uint16_t vid_mode; + /** Default root device number */ + uint16_t root_dev; + /** 0xAA55 magic number */ + uint16_t boot_flag; + /** Jump instruction */ + uint16_t jump; + /** Magic signature "HdrS" */ + uint32_t header; + /** Boot protocol version supported */ + uint16_t version; + /** Boot loader hook (see below) */ + uint32_t realmode_swtch; + /** The load-low segment (0x1000) (obsolete) */ + uint16_t start_sys; + /** Pointer to kernel version string */ + uint16_t kernel_version; + /** Boot loader identifier */ + uint8_t type_of_loader; + /** Boot protocol option flags */ + uint8_t loadflags; + /** Move to high memory size (used with hooks) */ + uint16_t setup_move_size; + /** Boot loader hook (see below) */ + uint32_t code32_start; + /** initrd load address (set by boot loader) */ + uint32_t ramdisk_image; + /** initrd size (set by boot loader) */ + uint32_t ramdisk_size; + /** DO NOT USE - for bootsect.S use only */ + uint32_t bootsect_kludge; + /** Free memory after setup end */ + uint16_t heap_end_ptr; + /** Unused */ + uint16_t pad1; + /** 32-bit pointer to the kernel command line */ + uint32_t cmd_line_ptr; + /** Highest legal initrd address */ + uint32_t initrd_addr_max; +} __attribute__ (( packed )); + +/** Offset of bzImage header within kernel image */ +#define BZHDR_OFFSET 0x1f1 + +/** bzImage magic signature value */ +#define BZIMAGE_SIGNATURE 0x53726448 + +#endif /* _BZIMAGE_H */ diff --git a/src/config.h b/src/config.h index 3748a4c0..4c1af385 100644 --- a/src/config.h +++ b/src/config.h @@ -108,6 +108,7 @@ #undef IMAGE_WINCE /* WinCE image support */ #define IMAGE_PXE /* PXE image support */ #define IMAGE_SCRIPT /* gPXE script image support */ +#define IMAGE_BZIMAGE /* Linux bzImage image support */ /* @END general.h */ diff --git a/src/core/config.c b/src/core/config.c index 31ae8d5a..e27917a6 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -140,6 +140,9 @@ REQUIRE_OBJECT ( pxe_image ); #ifdef IMAGE_SCRIPT REQUIRE_OBJECT ( script ); #endif +#ifdef IMAGE_BZIMAGE +REQUIRE_OBJECT ( bzimage ); +#endif /* * Drag in all requested commands