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 promote_image ( image
);
101 * @ret rc Return status code
103 int imgexec ( struct image
*image
) {
104 return image_exec ( image
);
108 * Identify the first loaded image
110 * @ret image Image, or NULL
112 struct image
* imgautoselect ( void ) {
115 for_each_image ( image
) {
116 if ( image
->flags
& IMAGE_LOADED
)
124 * Display status of an image
126 * @v image Executable/loadable image
128 void imgstat ( struct image
*image
) {
129 printf ( "%s: %zd bytes", image
->name
, image
->len
);
131 printf ( " [%s]", image
->type
->name
);
132 if ( image
->flags
& IMAGE_LOADED
)
133 printf ( " [LOADED]" );
134 if ( image
->cmdline
[0] )
135 printf ( " \"%s\"", image
->cmdline
);
142 * @v image Executable/loadable image
144 void imgfree ( struct image
*image
) {
145 unregister_image ( image
);
146 ufree ( image
->data
);