summaryrefslogtreecommitdiffstats
path: root/src/core/image.c
diff options
context:
space:
mode:
authorMichael Brown2021-01-25 17:18:28 +0100
committerMichael Brown2021-01-25 18:03:56 +0100
commit989a7a8032db02eb0524bd78a674d3b087dea3a6 (patch)
tree3ead7f99b466e3274d29dbeb0df7374905ff92d5 /src/core/image.c
parent[travis] Update to current default build environment (diff)
downloadipxe-989a7a8032db02eb0524bd78a674d3b087dea3a6.tar.gz
ipxe-989a7a8032db02eb0524bd78a674d3b087dea3a6.tar.xz
ipxe-989a7a8032db02eb0524bd78a674d3b087dea3a6.zip
[image] Provide image_memory()
Consolidate the remaining logic common to initrd_init() and imgmem() into a shared image_memory() function. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/image.c')
-rw-r--r--src/core/image.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/core/image.c b/src/core/image.c
index 54b99802..9fe77c54 100644
--- a/src/core/image.c
+++ b/src/core/image.c
@@ -505,3 +505,47 @@ int image_set_trust ( int require_trusted, int permanent ) {
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;
+}