david/ipxe
david
/
ipxe
Archived
1
0
Fork 0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
ipxe/src/core/image.c

86 lines
1.7 KiB
C
Raw Normal View History

2005-05-17 15:38:24 +02:00
#include "dev.h"
#include <gpxe/buffer.h>
2006-06-29 21:04:25 +02:00
#include <console.h>
2005-05-09 20:01:50 +02:00
#if 0
2005-05-17 15:38:24 +02:00
static struct image images[0] __image_start;
2005-05-09 20:01:50 +02:00
static struct image images_end[0] __image_end;
2005-05-17 15:38:24 +02:00
/*
* Print all images
*
*/
void print_images ( void ) {
struct image *image;
for ( image = images ; image < images_end ; image++ ) {
printf ( "%s ", image->name );
}
}
2005-05-09 20:01:50 +02:00
/*
* Identify the image format
*
*/
2005-05-17 15:38:24 +02:00
static struct image * identify_image ( physaddr_t start, physaddr_t len,
void **context ) {
2005-05-09 20:01:50 +02:00
struct image *image;
2005-05-17 15:38:24 +02:00
for ( image = images ; image < images_end ; image++ ) {
if ( image->probe ( start, len, context ) )
2005-05-09 20:01:50 +02:00
return image;
}
return NULL;
}
/*
2005-05-17 15:38:24 +02:00
* Load an image into memory at a location determined by the image
* format
2005-05-09 20:01:50 +02:00
*
*/
2005-05-17 15:38:24 +02:00
int autoload ( struct dev *dev, struct image **image, void **context ) {
struct buffer buffer;
int rc = 0;
/* Prepare the load buffer */
if ( ! init_load_buffer ( &buffer ) ) {
DBG ( "IMAGE could not initialise load buffer\n" );
goto out;
}
/* Load the image into the load buffer */
if ( ! load ( dev, &buffer ) ) {
DBG ( "IMAGE could not load image\n" );
goto out_free;
}
/* Shrink the load buffer */
trim_load_buffer ( &buffer );
/* Identify the image type */
*image = identify_image ( buffer.start, buffer.fill, context );
if ( ! *image ) {
DBG ( "IMAGE could not identify image type\n" );
goto out_free;
}
2005-05-09 20:01:50 +02:00
2005-05-17 15:38:24 +02:00
/* Move the image into the target location */
if ( ! (*image)->load ( buffer.start, buffer.fill, *context ) ) {
DBG ( "IMAGE could not move to target location\n" );
goto out_free;
2005-05-09 20:01:50 +02:00
}
2005-05-17 15:38:24 +02:00
/* Return success */
rc = 1;
2005-05-09 20:01:50 +02:00
2005-05-17 15:38:24 +02:00
out_free:
/* Free the load buffer */
done_load_buffer ( &buffer );
out:
return rc;
2005-05-09 20:01:50 +02:00
}
#endif