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>
28 #include <usr/imgmgmt.h>
39 * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
40 * @v name Name for image, or NULL
41 * @v register_image Image registration routine
42 * @ret rc Return status code
44 int imgfetch ( struct image
*image
, const char *uri_string
,
45 int ( * image_register
) ( struct image
*image
) ) {
49 if ( ! ( uri
= parse_uri ( uri_string
) ) )
52 image_set_uri ( image
, uri
);
54 if ( ( rc
= create_downloader ( &monojob
, image
, image_register
,
55 LOCATION_URI
, uri
) ) == 0 )
56 rc
= monojob_wait ( uri_string
);
66 * @ret rc Return status code
68 int imgload ( struct image
*image
) {
71 /* Try to load image */
72 if ( ( rc
= image_autoload ( image
) ) != 0 )
82 * @ret rc Return status code
84 int imgexec ( struct image
*image
) {
85 return image_exec ( image
);
89 * Identify the first loaded image
91 * @ret image Image, or NULL
93 struct image
* imgautoselect ( void ) {
96 for_each_image ( image
) {
97 if ( image
->flags
& IMAGE_LOADED
)
105 * Display status of an image
107 * @v image Executable/loadable image
109 void imgstat ( struct image
*image
) {
110 printf ( "%s: %zd bytes", image
->name
, image
->len
);
112 printf ( " [%s]", image
->type
->name
);
113 if ( image
->flags
& IMAGE_LOADED
)
114 printf ( " [LOADED]" );
115 if ( image
->cmdline
)
116 printf ( " \"%s\"", image
->cmdline
);
123 * @v image Executable/loadable image
125 void imgfree ( struct image
*image
) {
126 unregister_image ( image
);