Added print_images() and autoload().
This commit is contained in:
parent
9968c9513e
commit
0571dcdb05
|
@ -1,28 +1,33 @@
|
||||||
|
#include "dev.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
#include "load_buffer.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
static struct image images_start[0] __image_start;
|
static struct image images[0] __image_start;
|
||||||
static struct image images_end[0] __image_end;
|
static struct image images_end[0] __image_end;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print all images
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void print_images ( void ) {
|
||||||
|
struct image *image;
|
||||||
|
|
||||||
|
for ( image = images ; image < images_end ; image++ ) {
|
||||||
|
printf ( "%s ", image->name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Identify the image format
|
* Identify the image format
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static struct image * identify_image ( struct buffer *buffer ) {
|
static struct image * identify_image ( physaddr_t start, physaddr_t len,
|
||||||
struct image_header header;
|
void **context ) {
|
||||||
int header_len = sizeof ( header );
|
|
||||||
off_t len;
|
|
||||||
struct image *image;
|
struct image *image;
|
||||||
|
|
||||||
/* Copy first (up to) 512 bytes of image to easily-accessible
|
for ( image = images ; image < images_end ; image++ ) {
|
||||||
* buffer.
|
if ( image->probe ( start, len, context ) )
|
||||||
*/
|
|
||||||
len = buffer->fill;
|
|
||||||
copy_from_phys ( &header, buffer->start,
|
|
||||||
len < header_len ? len : header_len );
|
|
||||||
|
|
||||||
for ( image = images_start ; image < images_end ; image++ ) {
|
|
||||||
if ( image->probe ( &header, len ) )
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,20 +35,48 @@ static struct image * identify_image ( struct buffer *buffer ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Boot a loaded image
|
* Load an image into memory at a location determined by the image
|
||||||
|
* format
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int boot_image ( struct buffer *buffer ) {
|
int autoload ( struct dev *dev, struct image **image, void **context ) {
|
||||||
struct image *image;
|
struct buffer buffer;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
image = identify_image ( buffer );
|
/* Prepare the load buffer */
|
||||||
if ( ! image ) {
|
if ( ! init_load_buffer ( &buffer ) ) {
|
||||||
DBG ( "IMAGE could not identify image format\n" );
|
DBG ( "IMAGE could not initialise load buffer\n" );
|
||||||
return 0;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG ( "IMAGE found %s image (length %d)\n",
|
/* Load the image into the load buffer */
|
||||||
image->name, buffer->fill );
|
if ( ! load ( dev, &buffer ) ) {
|
||||||
|
DBG ( "IMAGE could not load image\n" );
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
return image->boot ( buffer->start, buffer->fill );
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return success */
|
||||||
|
rc = 1;
|
||||||
|
|
||||||
|
out_free:
|
||||||
|
/* Free the load buffer */
|
||||||
|
done_load_buffer ( &buffer );
|
||||||
|
out:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,13 @@
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
#include "dev.h"
|
||||||
#define IMAGE_HEADER_SIZE 512
|
|
||||||
|
|
||||||
struct image_header {
|
|
||||||
char data[IMAGE_HEADER_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct image {
|
struct image {
|
||||||
char *name;
|
char *name;
|
||||||
int ( * probe ) ( struct image_header *header, off_t len );
|
int ( * probe ) ( physaddr_t data, off_t len, void **context );
|
||||||
int ( * boot ) ( physaddr_t start, off_t len );
|
int ( * load ) ( physaddr_t data, off_t len, void *context );
|
||||||
|
int ( * boot ) ( void *context );
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __image_start __table_start(image)
|
#define __image_start __table_start(image)
|
||||||
|
@ -22,4 +18,9 @@ struct image {
|
||||||
#define __default_image __table(image,02)
|
#define __default_image __table(image,02)
|
||||||
#define __image_end __table_end(image)
|
#define __image_end __table_end(image)
|
||||||
|
|
||||||
|
/* Functions in image.c */
|
||||||
|
|
||||||
|
extern void print_images ( void );
|
||||||
|
extern int autoload ( struct dev *dev, struct image **image, void **context );
|
||||||
|
|
||||||
#endif /* IMAGE_H */
|
#endif /* IMAGE_H */
|
||||||
|
|
Reference in New Issue