2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <gpxe/image.h>
24 #include <gpxe/umalloc.h>
25 #include <gpxe/download.h>
26 #include <usr/imgmgmt.h>
37 * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
38 * @v name Name for image, or NULL
39 * @ret new_image Newly created image
40 * @ret rc Return status code
42 int imgfetch ( const char *uri_string, const char *name,
43 struct image **new_image ) {
48 /* Allocate new image */
49 image = malloc ( sizeof ( *image ) );
52 memset ( image, 0, sizeof ( *image ) );
54 /* Fill in image name */
56 strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
58 /* Download the file */
59 if ( ( rc = async_block_progress ( &async,
60 start_download ( uri_string, &async,
65 /* Register the image */
66 if ( ( rc = register_image ( image ) ) != 0 )
73 ufree ( image->data );
82 * @ret rc Return status code
84 int imgload ( struct image *image ) {
87 /* Try to load image */
88 if ( ( rc = image_autoload ( image ) ) != 0 )
91 /* If we succeed, move the image to the start of the list */
92 #warning "No longer exists"
93 // promote_image ( image );
102 * @ret rc Return status code
104 int imgexec ( struct image *image ) {
105 return image_exec ( image );
109 * Identify the first loaded image
111 * @ret image Image, or NULL
113 struct image * imgautoselect ( void ) {
116 for_each_image ( image ) {
117 if ( image->flags & IMAGE_LOADED )
125 * Display status of an image
127 * @v image Executable/loadable image
129 void imgstat ( struct image *image ) {
130 printf ( "%s: %zd bytes", image->name, image->len );
132 printf ( " [%s]", image->type->name );
133 if ( image->flags & IMAGE_LOADED )
134 printf ( " [LOADED]" );
135 if ( image->cmdline[0] )
136 printf ( " \"%s\"", image->cmdline );
143 * @v image Executable/loadable image
145 void imgfree ( struct image *image ) {
146 unregister_image ( image );
147 ufree ( image->data );