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/downloader.h>
25 #include <gpxe/monojob.h>
26 #include <gpxe/open.h>
27 #include <usr/imgmgmt.h>
35 static int imgfetch_autoload ( struct image *image ) {
38 if ( ( rc = register_image ( image ) ) != 0 )
41 if ( ( rc = image_autoload ( image ) ) != 0 )
50 * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
51 * @v name Name for image, or NULL
52 * @ret new_image Newly created image
53 * @ret rc Return status code
55 int imgfetch ( struct image *image, const char *uri_string, int load ) {
58 if ( ( rc = create_downloader ( &monojob, image,
59 ( load ? imgfetch_autoload :
72 * @ret rc Return status code
74 int imgload ( struct image *image ) {
77 /* Try to load image */
78 if ( ( rc = image_autoload ( image ) ) != 0 )
88 * @ret rc Return status code
90 int imgexec ( struct image *image ) {
91 return image_exec ( image );
95 * Identify the first loaded image
97 * @ret image Image, or NULL
99 struct image * imgautoselect ( void ) {
102 for_each_image ( image ) {
103 if ( image->flags & IMAGE_LOADED )
111 * Display status of an image
113 * @v image Executable/loadable image
115 void imgstat ( struct image *image ) {
116 printf ( "%s: %zd bytes", image->name, image->len );
118 printf ( " [%s]", image->type->name );
119 if ( image->flags & IMAGE_LOADED )
120 printf ( " [LOADED]" );
121 if ( image->cmdline[0] )
122 printf ( " \"%s\"", image->cmdline );
129 * @v image Executable/loadable image
131 void imgfree ( struct image *image ) {
132 unregister_image ( image );