Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>.
- Loading branch information
Michael Brown
committed
Feb 16, 2009
1 parent
f16668d
commit 076154a
Showing
12 changed files
with
138 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!gpxe | ||
dhcp net0 | ||
imgload img1 | ||
boot img1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!gpxe | ||
ifopen net0 | ||
set net0/ip 10.0.2.15 | ||
set net0/netmask 255.255.255.0 | ||
set net0/gateway 10.0.2.2 | ||
set net0/dns 10.0.2.3 | ||
kernel http://etherboot.org/gtest/gtest.gpxe | ||
boot gtest.gpxe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,3 +218,4 @@ REQUIRE_OBJECT ( gdbstub_cmd ); | |
* | ||
*/ | ||
REQUIRE_OBJECT ( device ); | ||
REQUIRE_OBJECT ( embedded ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!gpxe | ||
autoboot |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* | ||
*/ | ||
|
||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <gpxe/refcnt.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters