summaryrefslogtreecommitdiffstats
path: root/src/image/elf.c
diff options
context:
space:
mode:
authorMichael Brown2008-06-09 14:11:46 +0200
committerMichael Brown2008-06-09 14:50:00 +0200
commit77a5cc6b1391df8aa63589c3b4c5efd2627296e9 (patch)
tree5642ceaa317174e15e2f551fa5d0df0edbed7943 /src/image/elf.c
parent[Makefile] Add $(BIN)/undionly.kpxe as default build target (diff)
downloadipxe-77a5cc6b1391df8aa63589c3b4c5efd2627296e9.tar.gz
ipxe-77a5cc6b1391df8aa63589c3b4c5efd2627296e9.tar.xz
ipxe-77a5cc6b1391df8aa63589c3b4c5efd2627296e9.zip
[ELF] Add ability to boot ELF images generated by wraplinux and mkelfImage
Delete ELF as a generic image type. The method for invoking an ELF-based image (as well as any tables that must be set up to allow it to boot) will always depend on the specific architecture. core/elf.c now only provides the elf_load() function, to avoid duplicating functionality between ELF-based image types. Add arch/i386/image/elfboot.c, to handle the generic case of 32-bit x86 ELF images. We don't currently set up any multiboot tables, ELF notes, etc. This seems to be sufficient for loading kernels generated using both wraplinux and coreboot's mkelfImage. Note that while Etherboot 5.4 allowed ELF images to return, we don't. There is no callback mechanism for the loaded image to shut down gPXE, which means that we have to shut down before invoking the image. This means that we lose device state, protection against being trampled on, etc. It is not safe to continue afterwards.
Diffstat (limited to 'src/image/elf.c')
-rw-r--r--src/image/elf.c29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/image/elf.c b/src/image/elf.c
index 75c976ea..b932ff58 100644
--- a/src/image/elf.c
+++ b/src/image/elf.c
@@ -21,6 +21,9 @@
*
* ELF image format
*
+ * A "pure" ELF image is not a bootable image. There are various
+ * bootable formats based upon ELF (e.g. Multiboot), which share
+ * common ELF-related functionality.
*/
#include <errno.h>
@@ -30,23 +33,11 @@
#include <gpxe/image.h>
#include <gpxe/elf.h>
-struct image_type elf_image_type __image_type ( PROBE_NORMAL );
-
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
typedef Elf32_Off Elf_Off;
/**
- * Execute ELF image
- *
- * @v image ELF file
- * @ret rc Return status code
- */
-static int elf_exec ( struct image *image __unused ) {
- return -ENOTSUP;
-}
-
-/**
* Load ELF segment into memory
*
* @v image ELF file
@@ -112,6 +103,9 @@ int elf_load ( struct image *image ) {
unsigned int phnum;
int rc;
+ /* Image type must already have been set by caller */
+ assert ( image->type != NULL );
+
/* Read ELF header */
copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
if ( memcmp ( &ehdr.e_ident[EI_MAG0], ELFMAG, SELFMAG ) != 0 ) {
@@ -119,10 +113,6 @@ int elf_load ( struct image *image ) {
return -ENOEXEC;
}
- /* This is an ELF image, valid or otherwise */
- if ( ! image->type )
- image->type = &elf_image_type;
-
/* Read ELF program headers */
for ( phoff = ehdr.e_phoff , phnum = ehdr.e_phnum ; phnum ;
phoff += ehdr.e_phentsize, phnum-- ) {
@@ -141,10 +131,3 @@ int elf_load ( struct image *image ) {
return 0;
}
-
-/** ELF image type */
-struct image_type elf_image_type __image_type ( PROBE_NORMAL ) = {
- .name = "ELF",
- .load = elf_load,
- .exec = elf_exec,
-};