*/
static int initrd_init ( void ) {
struct image *image;
- int rc;
/* Do nothing if no initrd was specified */
if ( ! initrd_phys ) {
DBGC ( colour, "RUNTIME found initrd at [%x,%x)\n",
initrd_phys, ( initrd_phys + initrd_len ) );
- /* Allocate image */
- image = alloc_image ( NULL );
+ /* Create initrd image */
+ image = image_memory ( "<INITRD>", phys_to_user ( initrd_phys ),
+ initrd_len );
if ( ! image ) {
- DBGC ( colour, "RUNTIME could not allocate image for "
- "initrd\n" );
- rc = -ENOMEM;
- goto err_alloc_image;
- }
-
- /* Set image name */
- if ( ( rc = image_set_name ( image, "<INITRD>" ) ) != 0 ) {
- DBGC ( colour, "RUNTIME could not set image name: %s\n",
- strerror ( rc ) );
- goto err_set_name;
- }
-
- /* Set image content */
- if ( ( rc = image_set_data ( image, phys_to_user ( initrd_phys ),
- initrd_len ) ) != 0 ) {
- DBGC ( colour, "RUNTIME could not set image data: %s\n",
- strerror ( rc ) );
- goto err_set_data;
+ DBGC ( colour, "RUNTIME could not create initrd image\n" );
+ return -ENOMEM;
}
/* Mark initrd as consumed */
initrd_phys = 0;
- /* Register image */
- if ( ( rc = register_image ( image ) ) != 0 ) {
- DBGC ( colour, "RUNTIME could not register initrd: %s\n",
- strerror ( rc ) );
- goto err_register_image;
- }
-
- /* Drop our reference to the image */
- image_put ( image );
-
return 0;
-
- err_register_image:
- err_set_data:
- err_set_name:
- image_put ( image );
- err_alloc_image:
- return rc;
}
/**
return 0;
}
+
+/**
+ * Create registered image from block of memory
+ *
+ * @v name Name
+ * @v data Image data
+ * @v len Length
+ * @ret image Image, or NULL on error
+ */
+struct image * image_memory ( const char *name, userptr_t data, size_t len ) {
+ struct image *image;
+ int rc;
+
+ /* Allocate image */
+ image = alloc_image ( NULL );
+ if ( ! image ) {
+ rc = -ENOMEM;
+ goto err_alloc_image;
+ }
+
+ /* Set name */
+ if ( ( rc = image_set_name ( image, name ) ) != 0 )
+ goto err_set_name;
+
+ /* Set data */
+ if ( ( rc = image_set_data ( image, data, len ) ) != 0 )
+ goto err_set_data;
+
+ /* Register image */
+ if ( ( rc = register_image ( image ) ) != 0 )
+ goto err_register;
+
+ /* Drop local reference to image */
+ image_put ( image );
+
+ return image;
+
+ err_register:
+ err_set_data:
+ err_set_name:
+ image_put ( image );
+ err_alloc_image:
+ return NULL;
+}
*/
static int imgmem_exec ( int argc, char **argv ) {
struct imgmem_options opts;
- struct image *image;
unsigned int data;
unsigned int len;
int rc;
return rc;
/* Create image */
- if ( ( rc = imgmem ( phys_to_user ( data ), len, opts.name,
- &image ) ) != 0 )
+ if ( ( rc = imgmem ( opts.name, phys_to_user ( data ), len ) ) != 0 )
return rc;
return 0;
extern int image_select ( struct image *image );
extern struct image * image_find_selected ( void );
extern int image_set_trust ( int require_trusted, int permanent );
+extern struct image * image_memory ( const char *name, userptr_t data,
+ size_t len );
extern int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf );
extern int image_asn1 ( struct image *image, size_t offset,
struct asn1_cursor **cursor );
extern int imgacquire ( const char *name, unsigned long timeout,
struct image **image );
extern void imgstat ( struct image *image );
-extern int imgmem ( userptr_t data, size_t len, const char *name,
- struct image **image );
+extern int imgmem ( const char *name, userptr_t data, size_t len );
#endif /* _USR_IMGMGMT_H */
/**
* Create image from block of memory
*
+ * @v name Name
* @v data Image data
* @v len Length
- * @v name Name
- * @v image Image to fill in
* @ret rc Return status code
*/
-int imgmem ( userptr_t data, size_t len, const char *name,
- struct image **image ) {
- int rc;
-
- /* Allocate image */
- *image = alloc_image ( NULL );
- if ( ! *image ) {
- rc = -ENOMEM;
- goto err_alloc_image;
- }
-
- /* Set name */
- if ( ( rc = image_set_name ( *image, name ) ) != 0 )
- goto err_set_name;
+int imgmem ( const char *name, userptr_t data, size_t len ) {
+ struct image *image;
- /* Set data */
- if ( ( rc = image_set_data ( *image, data, len ) ) != 0 ) {
- printf ( "Could not set image data: %s\n", strerror ( rc ) );
- goto err_set_data;
- }
-
- /* Register image */
- if ( ( rc = register_image ( *image ) ) != 0 ) {
- printf ( "Could not register image: %s\n", strerror ( rc ) );
- goto err_register_image;
+ /* Create image */
+ image = image_memory ( name, data, len );
+ if ( ! image ) {
+ printf ( "Could not create image\n" );
+ return -ENOMEM;
}
- err_register_image:
- err_set_data:
- err_set_name:
- image_put ( *image );
- err_alloc_image:
- return rc;
+ return 0;
}