mirror of
https://github.com/ipxe/ipxe
synced 2025-12-21 12:30:20 +03:00
Quick hack to get image booting working again
This commit is contained in:
@@ -72,19 +72,20 @@ static void imgfetch_core_syntax ( char **argv, int load ) {
|
|||||||
/**
|
/**
|
||||||
* The "imgfetch"/"module"/"kernel" command body
|
* The "imgfetch"/"module"/"kernel" command body
|
||||||
*
|
*
|
||||||
|
* @v image_type Image type to assign (or NULL)
|
||||||
|
* @v load Image will be automatically loaded after fetching
|
||||||
* @v argc Argument count
|
* @v argc Argument count
|
||||||
* @v argv Argument list
|
* @v argv Argument list
|
||||||
* @v load Image will be automatically loaded after fetching
|
|
||||||
* @ret image Fetched image
|
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int imgfetch_core_exec ( int argc, char **argv, int load,
|
static int imgfetch_core_exec ( struct image_type *image_type, int load,
|
||||||
struct image **image ) {
|
int argc, char **argv ) {
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{ "help", 0, NULL, 'h' },
|
{ "help", 0, NULL, 'h' },
|
||||||
{ "name", required_argument, NULL, 'n' },
|
{ "name", required_argument, NULL, 'n' },
|
||||||
{ NULL, 0, NULL, 0 },
|
{ NULL, 0, NULL, 0 },
|
||||||
};
|
};
|
||||||
|
struct image *image;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
char *filename;
|
char *filename;
|
||||||
int c;
|
int c;
|
||||||
@@ -116,15 +117,33 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
|
|||||||
if ( ! name )
|
if ( ! name )
|
||||||
name = basename ( filename );
|
name = basename ( filename );
|
||||||
|
|
||||||
|
/* Allocate image */
|
||||||
|
image = alloc_image();
|
||||||
|
if ( ! image ) {
|
||||||
|
printf ( "%s\n", strerror ( -ENOMEM ) );
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fill in image name */
|
||||||
|
if ( name )
|
||||||
|
strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
|
||||||
|
|
||||||
|
/* Set image type (if specified) */
|
||||||
|
image->type = image_type;
|
||||||
|
|
||||||
|
/* Fill in command line */
|
||||||
|
imgfill_cmdline ( image, ( argc - optind ), &argv[optind] );
|
||||||
|
|
||||||
|
printf ( "name = %s, filename = %s\n", name, filename );
|
||||||
|
|
||||||
/* Fetch the image */
|
/* Fetch the image */
|
||||||
if ( ( rc = imgfetch ( filename, name, image ) ) != 0 ) {
|
if ( ( rc = imgfetch ( image, filename, load ) ) != 0 ) {
|
||||||
printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
|
printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
|
||||||
|
image_put ( image );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in command line */
|
image_put ( image );
|
||||||
imgfill_cmdline ( *image, ( argc - optind ), &argv[optind] );
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +155,10 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
|
|||||||
* @ret rc Exit code
|
* @ret rc Exit code
|
||||||
*/
|
*/
|
||||||
static int imgfetch_exec ( int argc, char **argv ) {
|
static int imgfetch_exec ( int argc, char **argv ) {
|
||||||
struct image *image;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
|
if ( ( rc = imgfetch_core_exec ( NULL, 0, argc, argv ) ) != 0 )
|
||||||
return 1;
|
return rc;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -153,18 +171,10 @@ static int imgfetch_exec ( int argc, char **argv ) {
|
|||||||
* @ret rc Exit code
|
* @ret rc Exit code
|
||||||
*/
|
*/
|
||||||
static int kernel_exec ( int argc, char **argv ) {
|
static int kernel_exec ( int argc, char **argv ) {
|
||||||
struct image *image;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if ( ( rc = imgfetch_core_exec ( argc, argv, 1, &image ) ) != 0 )
|
if ( ( rc = imgfetch_core_exec ( NULL, 1, argc, argv ) ) != 0 )
|
||||||
return 1;
|
return rc;
|
||||||
|
|
||||||
/* Load image */
|
|
||||||
if ( ( rc = imgload ( image ) ) != 0 ) {
|
|
||||||
printf ( "Could not load %s: %s\n", image->name,
|
|
||||||
strerror ( rc ) );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -177,14 +187,11 @@ static int kernel_exec ( int argc, char **argv ) {
|
|||||||
* @ret rc Exit code
|
* @ret rc Exit code
|
||||||
*/
|
*/
|
||||||
static int initrd_exec ( int argc, char **argv ) {
|
static int initrd_exec ( int argc, char **argv ) {
|
||||||
struct image *image;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
|
if ( ( rc = imgfetch_core_exec ( &initrd_image_type, 0,
|
||||||
return 1;
|
argc, argv ) ) != 0 )
|
||||||
|
return rc;
|
||||||
/* Mark image as an intird */
|
|
||||||
image->type = &initrd_image_type;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -246,7 +253,7 @@ static int imgload_exec ( int argc, char **argv ) {
|
|||||||
}
|
}
|
||||||
if ( ( rc = imgload ( image ) ) != 0 ) {
|
if ( ( rc = imgload ( image ) ) != 0 ) {
|
||||||
printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
|
printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
|
||||||
return 1;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ extern struct list_head images;
|
|||||||
#define for_each_image( image ) \
|
#define for_each_image( image ) \
|
||||||
list_for_each_entry ( (image), &images, list )
|
list_for_each_entry ( (image), &images, list )
|
||||||
|
|
||||||
|
extern struct image * alloc_image ( void );
|
||||||
extern int register_image ( struct image *image );
|
extern int register_image ( struct image *image );
|
||||||
extern void unregister_image ( struct image *image );
|
extern void unregister_image ( struct image *image );
|
||||||
extern void promote_image ( struct image *image );
|
extern void promote_image ( struct image *image );
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
|
|
||||||
struct image;
|
struct image;
|
||||||
|
|
||||||
extern int imgfetch ( const char *filename, const char *name,
|
extern int imgfetch ( struct image *image, const char *filename, int load );
|
||||||
struct image **new_image );
|
|
||||||
extern int imgload ( struct image *image );
|
extern int imgload ( struct image *image );
|
||||||
extern int imgexec ( struct image *image );
|
extern int imgexec ( struct image *image );
|
||||||
extern struct image * imgautoselect ( void );
|
extern struct image * imgautoselect ( void );
|
||||||
|
|||||||
@@ -99,19 +99,27 @@ void netboot ( struct net_device *netdev ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf ( "Booting \"%s\"\n", filename );
|
printf ( "Booting \"%s\"\n", filename );
|
||||||
if ( ( rc = imgfetch ( filename, NULL, &image ) ) != 0 ) {
|
image = alloc_image();
|
||||||
|
if ( ! image ) {
|
||||||
|
printf ( "Out of memory\n" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( ( rc = imgfetch ( image, filename, 0 ) ) != 0 ) {
|
||||||
printf ( "Could not retrieve %s: %s\n",
|
printf ( "Could not retrieve %s: %s\n",
|
||||||
filename, strerror ( rc ) );
|
filename, strerror ( rc ) );
|
||||||
|
image_put ( image );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( ( rc = imgload ( image ) ) != 0 ) {
|
if ( ( rc = imgload ( image ) ) != 0 ) {
|
||||||
printf ( "Could not load %s: %s\n", image->name,
|
printf ( "Could not load %s: %s\n", image->name,
|
||||||
strerror ( rc ) );
|
strerror ( rc ) );
|
||||||
|
image_put ( image );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( ( rc = imgexec ( image ) ) != 0 ) {
|
if ( ( rc = imgexec ( image ) ) != 0 ) {
|
||||||
printf ( "Could not execute %s: %s\n", image->name,
|
printf ( "Could not execute %s: %s\n", image->name,
|
||||||
strerror ( rc ) );
|
strerror ( rc ) );
|
||||||
|
image_put ( image );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <gpxe/image.h>
|
#include <gpxe/image.h>
|
||||||
#include <gpxe/umalloc.h>
|
#include <gpxe/downloader.h>
|
||||||
#include <gpxe/download.h>
|
#include <gpxe/monojob.h>
|
||||||
|
#include <gpxe/open.h>
|
||||||
#include <usr/imgmgmt.h>
|
#include <usr/imgmgmt.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
@@ -31,6 +32,18 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int imgfetch_autoload ( struct image *image ) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if ( ( rc = register_image ( image ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if ( ( rc = image_autoload ( image ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch an image
|
* Fetch an image
|
||||||
*
|
*
|
||||||
@@ -39,39 +52,18 @@
|
|||||||
* @ret new_image Newly created image
|
* @ret new_image Newly created image
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int imgfetch ( const char *uri_string, const char *name,
|
int imgfetch ( struct image *image, const char *uri_string, int load ) {
|
||||||
struct image **new_image ) {
|
|
||||||
struct image *image;
|
|
||||||
struct async async;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Allocate new image */
|
printf ( "uri_string = %s\n", uri_string );
|
||||||
image = malloc ( sizeof ( *image ) );
|
|
||||||
if ( ! image )
|
|
||||||
return -ENOMEM;
|
|
||||||
memset ( image, 0, sizeof ( *image ) );
|
|
||||||
|
|
||||||
/* Fill in image name */
|
if ( ( rc = create_downloader ( &monojob, image,
|
||||||
if ( name )
|
( load ? imgfetch_autoload :
|
||||||
strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
|
register_image ),
|
||||||
|
LOCATION_URI_STRING,
|
||||||
|
uri_string ) ) == 0 )
|
||||||
|
rc = monojob_wait();
|
||||||
|
|
||||||
/* Download the file */
|
|
||||||
if ( ( rc = async_block_progress ( &async,
|
|
||||||
start_download ( uri_string, &async,
|
|
||||||
&image->data,
|
|
||||||
&image->len )))!=0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Register the image */
|
|
||||||
if ( ( rc = register_image ( image ) ) != 0 )
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
*new_image = image;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err:
|
|
||||||
ufree ( image->data );
|
|
||||||
free ( image );
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,10 +80,6 @@ int imgload ( struct image *image ) {
|
|||||||
if ( ( rc = image_autoload ( image ) ) != 0 )
|
if ( ( rc = image_autoload ( image ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* If we succeed, move the image to the start of the list */
|
|
||||||
#warning "No longer exists"
|
|
||||||
// promote_image ( image );
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +132,4 @@ void imgstat ( struct image *image ) {
|
|||||||
*/
|
*/
|
||||||
void imgfree ( struct image *image ) {
|
void imgfree ( struct image *image ) {
|
||||||
unregister_image ( image );
|
unregister_image ( image );
|
||||||
ufree ( image->data );
|
|
||||||
free ( image );
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user