[image] Simplify use of imgdownload()

Allow imgdownload() to be called without first having to allocate (and
so keep track of) an image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2011-03-09 16:55:51 +00:00
parent ae92700fd4
commit 9fa4ac2e9a
10 changed files with 224 additions and 139 deletions

View File

@@ -132,10 +132,9 @@ static int com32_exec_loop ( struct image *image ) {
break;
case COMBOOT_EXIT_RUN_KERNEL:
DBGC ( image, "COM32 %p: exited to run kernel %p\n",
image, comboot_replacement_image );
image->replacement = comboot_replacement_image;
comboot_replacement_image = NULL;
assert ( image->replacement );
DBGC ( image, "COM32 %p: exited to run kernel %s\n",
image, image->replacement->name );
break;
case COMBOOT_EXIT_COMMAND:

View File

@@ -188,10 +188,9 @@ static int comboot_exec_loop ( struct image *image ) {
break;
case COMBOOT_EXIT_RUN_KERNEL:
DBGC ( image, "COMBOOT %p: exited to run kernel %p\n",
image, comboot_replacement_image );
image->replacement = comboot_replacement_image;
comboot_replacement_image = NULL;
assert ( image->replacement );
DBGC ( image, "COMBOOT %p: exited to run kernel %s\n",
image, image->replacement->name );
break;
case COMBOOT_EXIT_COMMAND:

View File

@@ -161,9 +161,6 @@ extern int comboot_resolv ( const char *name, struct in_addr *address );
/* setjmp/longjmp context buffer used to return after loading an image */
extern rmjmp_buf comboot_return;
/* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
extern struct image *comboot_replacement_image;
extern void *com32_external_esp;
#define COMBOOT_EXIT 1

View File

@@ -81,9 +81,6 @@ extern void int22_wrapper ( void );
/* setjmp/longjmp context buffer used to return after loading an image */
rmjmp_buf comboot_return;
/* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
struct image *comboot_replacement_image;
/* Mode flags set by INT 22h AX=0017h */
static uint16_t comboot_graphics_mode = 0;
@@ -169,8 +166,6 @@ void comboot_force_text_mode ( void ) {
* Fetch kernel and optional initrd
*/
static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
struct image *kernel = NULL;
struct image *initrd = NULL;
char *initrd_file;
int rc;
@@ -188,18 +183,12 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
/* Allocate and fetch initrd */
initrd = alloc_image();
if ( ! initrd ) {
DBG ( "COMBOOT: could not allocate initrd\n" );
rc = -ENOMEM;
goto out;
}
if ( ( rc = imgfetch ( initrd, initrd_file,
register_image ) ) != 0 ) {
/* Fetch initrd */
if ( ( rc = imgdownload_string ( initrd_file, NULL, NULL,
register_and_put_image ))!=0){
DBG ( "COMBOOT: could not fetch initrd: %s\n",
strerror ( rc ) );
goto out;
return rc;
}
/* Restore space after initrd name, if applicable */
@@ -210,36 +199,14 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
/* Allocate and fetch kernel */
kernel = alloc_image();
if ( ! kernel ) {
DBG ( "COMBOOT: could not allocate kernel\n" );
rc = -ENOMEM;
goto out;
}
if ( ( rc = imgfetch ( kernel, kernel_file,
register_and_select_image ) ) != 0 ) {
if ( ( rc = imgdownload_string ( kernel_file, NULL, cmdline,
register_and_replace_image ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch kernel: %s\n",
strerror ( rc ) );
goto out;
}
if ( ( rc = image_set_cmdline ( kernel, cmdline ) ) != 0 ) {
DBG ( "COMBOOT: could not set kernel command line: %s\n",
strerror ( rc ) );
goto out;
return rc;
}
/* Store kernel as replacement image */
assert ( comboot_replacement_image == NULL );
comboot_replacement_image = image_get ( kernel );
out:
/* Drop image references unconditionally; either we want to
* discard them, or they have been registered and we should
* drop out local reference.
*/
image_put ( kernel );
image_put ( initrd );
return rc;
return 0;
}