summaryrefslogtreecommitdiffstats
path: root/src/usr
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr')
-rw-r--r--src/usr/autoboot.c10
-rw-r--r--src/usr/imgmgmt.c60
2 files changed, 32 insertions, 38 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 5d017229d..3936e4ca5 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -99,19 +99,27 @@ void netboot ( struct net_device *netdev ) {
return;
}
printf ( "Booting \"%s\"\n", filename );
- if ( ( rc = imgfetch ( filename, NULL, &image ) ) != 0 ) {
+ image = alloc_image();
+ if ( ! image ) {
+ printf ( "Out of memory\n" );
+ return;
+ }
+ if ( ( rc = imgfetch ( image, filename, 0 ) ) != 0 ) {
printf ( "Could not retrieve %s: %s\n",
filename, strerror ( rc ) );
+ image_put ( image );
return;
}
if ( ( rc = imgload ( image ) ) != 0 ) {
printf ( "Could not load %s: %s\n", image->name,
strerror ( rc ) );
+ image_put ( image );
return;
}
if ( ( rc = imgexec ( image ) ) != 0 ) {
printf ( "Could not execute %s: %s\n", image->name,
strerror ( rc ) );
+ image_put ( image );
return;
}
}
diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c
index 9fe2e1493..df2519552 100644
--- a/src/usr/imgmgmt.c
+++ b/src/usr/imgmgmt.c
@@ -21,8 +21,9 @@
#include <stdio.h>
#include <errno.h>
#include <gpxe/image.h>
-#include <gpxe/umalloc.h>
-#include <gpxe/download.h>
+#include <gpxe/downloader.h>
+#include <gpxe/monojob.h>
+#include <gpxe/open.h>
#include <usr/imgmgmt.h>
/** @file
@@ -31,6 +32,18 @@
*
*/
+static int imgfetch_autoload ( struct image *image ) {
+ int rc;
+
+ if ( ( rc = register_image ( image ) ) != 0 )
+ return rc;
+
+ if ( ( rc = image_autoload ( image ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
/**
* Fetch an image
*
@@ -39,39 +52,18 @@
* @ret new_image Newly created image
* @ret rc Return status code
*/
-int imgfetch ( const char *uri_string, const char *name,
- struct image **new_image ) {
- struct image *image;
- struct async async;
+int imgfetch ( struct image *image, const char *uri_string, int load ) {
int rc;
- /* Allocate new image */
- image = malloc ( sizeof ( *image ) );
- if ( ! image )
- return -ENOMEM;
- memset ( image, 0, sizeof ( *image ) );
+ printf ( "uri_string = %s\n", uri_string );
- /* Fill in image name */
- if ( name )
- strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
+ if ( ( rc = create_downloader ( &monojob, image,
+ ( load ? imgfetch_autoload :
+ register_image ),
+ LOCATION_URI_STRING,
+ uri_string ) ) == 0 )
+ rc = monojob_wait();
- /* Download the file */
- if ( ( rc = async_block_progress ( &async,
- start_download ( uri_string, &async,
- &image->data,
- &image->len )))!=0)
- goto err;
-
- /* Register the image */
- if ( ( rc = register_image ( image ) ) != 0 )
- goto err;
-
- *new_image = image;
- return 0;
-
- err:
- ufree ( image->data );
- free ( image );
return rc;
}
@@ -88,10 +80,6 @@ int imgload ( struct image *image ) {
if ( ( rc = image_autoload ( image ) ) != 0 )
return rc;
- /* If we succeed, move the image to the start of the list */
-#warning "No longer exists"
- // promote_image ( image );
-
return 0;
}
@@ -144,6 +132,4 @@ void imgstat ( struct image *image ) {
*/
void imgfree ( struct image *image ) {
unregister_image ( image );
- ufree ( image->data );
- free ( image );
}