diff options
author | Michael Brown | 2009-02-16 01:28:30 +0100 |
---|---|---|
committer | Michael Brown | 2009-02-16 01:30:36 +0100 |
commit | 076154a1c6ca987f84450c0225c190c9cdd77c59 (patch) | |
tree | fbe8e2e7ccbd9de5f048894f9a58687df0c975de /src/image | |
parent | [romprefix] Update ROM checksum even if PMM allocation fails (diff) | |
download | ipxe-076154a1c6ca987f84450c0225c190c9cdd77c59.tar.gz ipxe-076154a1c6ca987f84450c0225c190c9cdd77c59.tar.xz ipxe-076154a1c6ca987f84450c0225c190c9cdd77c59.zip |
[image] Allow multiple embedded images
This patch extends the embedded image feature to allow multiple
embedded images instead of just one.
gPXE now always boots the first embedded image on startup instead of
doing the hardcoded DHCP boot (aka autoboot).
Based heavily upon a patch by Stefan Hajnoczi <stefanha@gmail.com>.
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/default.gpxe | 2 | ||||
-rw-r--r-- | src/image/embed.S | 7 | ||||
-rw-r--r-- | src/image/embedded.c | 109 |
3 files changed, 79 insertions, 39 deletions
diff --git a/src/image/default.gpxe b/src/image/default.gpxe new file mode 100644 index 00000000..0b080b58 --- /dev/null +++ b/src/image/default.gpxe @@ -0,0 +1,2 @@ +#!gpxe +autoboot diff --git a/src/image/embed.S b/src/image/embed.S deleted file mode 100644 index ef7d693b..00000000 --- a/src/image/embed.S +++ /dev/null @@ -1,7 +0,0 @@ - .section ".data", "aw", @progbits - .balign 4 - .globl _embedded_image_start -_embedded_image_start: - .incbin EMBEDIMG - .globl _embedded_image_end -_embedded_image_end: diff --git a/src/image/embedded.c b/src/image/embedded.c index 0ce09783..f76ca11b 100644 --- a/src/image/embedded.c +++ b/src/image/embedded.c @@ -1,49 +1,94 @@ /** @file * - * Take a possible embedded image and put it in a struct image - * data structure. + * Embedded image support + * + * Embedded images are images built into the gPXE binary and do not require + * fetching over the network. */ +#include <string.h> #include <gpxe/image.h> -#include <gpxe/malloc.h> #include <gpxe/uaccess.h> -#include <gpxe/umalloc.h> -#include <gpxe/embedded.h> +#include <gpxe/init.h> -extern char _embedded_image_start[], _embedded_image_end[]; +/** + * Free embedded image + * + * @v refcnt Reference counter + */ +static void embedded_image_free ( struct refcnt *refcnt __unused ) { + /* Do nothing */ +} -struct image *embedded_image(void) -{ - static int reclaimed = 0; - struct image *image; - size_t eisize = _embedded_image_end - _embedded_image_start; +/* Raw image data for all embedded images */ +#undef EMBED +#define EMBED( _index, _path, _name ) \ + extern char embedded_image_ ## _index ## _data[]; \ + extern char embedded_image_ ## _index ## _len[]; \ + __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" \ + "\nembedded_image_" #_index "_data:\n\t" \ + ".incbin \"" _path "\"\n\t" \ + "\nembedded_image_" #_index "_end:\n\t" \ + ".equ embedded_image_" #_index "_len, " \ + "( embedded_image_" #_index "_end - " \ + " embedded_image_" #_index "_data )\n\t" \ + ".previous\n\t" ); +EMBED_ALL - if ( !eisize ) - return NULL; /* No embedded image */ +/* Image structures for all embedded images */ +#undef EMBED +#define EMBED( _index, _path, _name ) { \ + .refcnt = { .free = embedded_image_free, }, \ + .name = _name, \ + .data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \ + .len = ( size_t ) embedded_image_ ## _index ## _len, \ +}, +static struct image embedded_images[] = { + EMBED_ALL +}; - if ( reclaimed ) - return NULL; /* Already reclaimed */ +/** + * Register all embedded images + */ +static void embedded_init ( void ) { + unsigned int i; + struct image *image; + void *data; + int rc; - DBG ( "Embedded image: %zd bytes at %p\n", - eisize, _embedded_image_start ); + /* Fix up data pointers and register images */ + for ( i = 0 ; i < ( sizeof ( embedded_images ) / + sizeof ( embedded_images[0] ) ) ; i++ ) { + image = &embedded_images[i]; - image = alloc_image(); - if (!image) - return NULL; + /* virt_to_user() cannot be used in a static + * initialiser, so we cast the pointer to a userptr_t + * in the initialiser and fix it up here. (This will + * actually be a no-op on most platforms.) + */ + data = ( ( void * ) image->data ); + image->data = virt_to_user ( data ); - image->len = eisize; - image->data = umalloc(eisize); - if (image->data == UNULL) { - image_put(image); - return image = NULL; - } - copy_to_user(image->data, 0, _embedded_image_start, eisize); - register_image(image); + DBG ( "Embedded image \"%s\": %zd bytes at %p\n", + image->name, image->len, data ); - /* Reclaim embedded image memory */ - reclaimed = 1; - mpopulate(_embedded_image_start, eisize); + if ( ( rc = register_image ( image ) ) != 0 ) { + DBG ( "Could not register embedded image \"%s\": " + "%s\n", image->name, strerror ( rc ) ); + return; + } + } - return image; + /* Load the first image */ + image = &embedded_images[0]; + if ( ( rc = image_autoload ( image ) ) != 0 ) { + DBG ( "Could not load embedded image \"%s\": %s\n", + image->name, strerror ( rc ) ); + return; + } } +/** Embedded image initialisation function */ +struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = { + .initialise = embedded_init, +}; |