mirror of https://github.com/ipxe/ipxe.git
[image] Provide image_set_data()
Extract part of the logic in initrd_init() to a standalone function image_set_data(). Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/224/head
parent
ae73fb5aa0
commit
99ac69b8a9
|
@ -38,7 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
#include <ipxe/init.h>
|
#include <ipxe/init.h>
|
||||||
#include <ipxe/image.h>
|
#include <ipxe/image.h>
|
||||||
#include <ipxe/script.h>
|
#include <ipxe/script.h>
|
||||||
#include <ipxe/umalloc.h>
|
|
||||||
#include <realmode.h>
|
#include <realmode.h>
|
||||||
|
|
||||||
/** Command line physical address
|
/** Command line physical address
|
||||||
|
@ -202,23 +201,21 @@ static int initrd_init ( void ) {
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_alloc_image;
|
goto err_alloc_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set image name */
|
||||||
if ( ( rc = image_set_name ( image, "<INITRD>" ) ) != 0 ) {
|
if ( ( rc = image_set_name ( image, "<INITRD>" ) ) != 0 ) {
|
||||||
DBGC ( colour, "RUNTIME could not set image name: %s\n",
|
DBGC ( colour, "RUNTIME could not set image name: %s\n",
|
||||||
strerror ( rc ) );
|
strerror ( rc ) );
|
||||||
goto err_set_name;
|
goto err_set_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate and copy initrd content */
|
/* Set image content */
|
||||||
image->data = umalloc ( initrd_len );
|
if ( ( rc = image_set_data ( image, phys_to_user ( initrd_phys ),
|
||||||
if ( ! image->data ) {
|
initrd_len ) ) != 0 ) {
|
||||||
DBGC ( colour, "RUNTIME could not allocate %d bytes for "
|
DBGC ( colour, "RUNTIME could not set image data: %s\n",
|
||||||
"initrd\n", initrd_len );
|
strerror ( rc ) );
|
||||||
rc = -ENOMEM;
|
goto err_set_data;
|
||||||
goto err_umalloc;
|
|
||||||
}
|
}
|
||||||
image->len = initrd_len;
|
|
||||||
memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
|
|
||||||
initrd_len );
|
|
||||||
|
|
||||||
/* Mark initrd as consumed */
|
/* Mark initrd as consumed */
|
||||||
initrd_phys = 0;
|
initrd_phys = 0;
|
||||||
|
@ -236,7 +233,7 @@ static int initrd_init ( void ) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_register_image:
|
err_register_image:
|
||||||
err_umalloc:
|
err_set_data:
|
||||||
err_set_name:
|
err_set_name:
|
||||||
image_put ( image );
|
image_put ( image );
|
||||||
err_alloc_image:
|
err_alloc_image:
|
||||||
|
|
|
@ -175,6 +175,30 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set image data
|
||||||
|
*
|
||||||
|
* @v image Image
|
||||||
|
* @v data Image data
|
||||||
|
* @v len Length of image data
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int image_set_data ( struct image *image, userptr_t data, size_t len ) {
|
||||||
|
userptr_t new;
|
||||||
|
|
||||||
|
/* (Re)allocate image data */
|
||||||
|
new = urealloc ( image->data, len );
|
||||||
|
if ( ! new )
|
||||||
|
return -ENOMEM;
|
||||||
|
image->data = new;
|
||||||
|
|
||||||
|
/* Copy in new image data */
|
||||||
|
memcpy_user ( image->data, 0, data, 0, len );
|
||||||
|
image->len = len;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine image type
|
* Determine image type
|
||||||
*
|
*
|
||||||
|
|
|
@ -175,6 +175,7 @@ extern struct image * alloc_image ( struct uri *uri );
|
||||||
extern int image_set_uri ( struct image *image, struct uri *uri );
|
extern int image_set_uri ( struct image *image, struct uri *uri );
|
||||||
extern int image_set_name ( struct image *image, const char *name );
|
extern int image_set_name ( struct image *image, const char *name );
|
||||||
extern int image_set_cmdline ( struct image *image, const char *cmdline );
|
extern int image_set_cmdline ( struct image *image, const char *cmdline );
|
||||||
|
extern int image_set_data ( struct image *image, userptr_t data, size_t len );
|
||||||
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 );
|
||||||
struct image * find_image ( const char *name );
|
struct image * find_image ( const char *name );
|
||||||
|
|
Loading…
Reference in New Issue