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.
19 FILE_LICENCE ( GPL2_OR_LATER
);
25 #include <gpxe/image.h>
26 #include <gpxe/downloader.h>
27 #include <gpxe/monojob.h>
28 #include <gpxe/open.h>
30 #include <usr/imgmgmt.h>
41 * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
42 * @v name Name for image, or NULL
43 * @v register_image Image registration routine
44 * @ret rc Return status code
46 int imgfetch ( struct image
*image
, const char *uri_string
,
47 int ( * image_register
) ( struct image
*image
) ) {
48 char uri_string_redacted
[ strlen ( uri_string
) + 3 /* "***" */
54 if ( ! ( uri
= parse_uri ( uri_string
) ) )
57 image_set_uri ( image
, uri
);
59 /* Redact password portion of URI, if necessary */
60 password
= uri
->password
;
62 uri
->password
= "***";
63 unparse_uri ( uri_string_redacted
, sizeof ( uri_string_redacted
),
65 uri
->password
= password
;
67 if ( ( rc
= create_downloader ( &monojob
, image
, image_register
,
68 LOCATION_URI
, uri
) ) == 0 )
69 rc
= monojob_wait ( uri_string_redacted
);
79 * @ret rc Return status code
81 int imgload ( struct image
*image
) {
84 /* Try to load image */
85 if ( ( rc
= image_autoload ( image
) ) != 0 )
95 * @ret rc Return status code
97 int imgexec ( struct image
*image
) {
98 return image_exec ( image
);
102 * Identify the only loaded image
104 * @ret image Image, or NULL if 0 or >1 images are loaded
106 struct image
* imgautoselect ( void ) {
108 struct image
*selected_image
= NULL
;
109 int flagged_images
= 0;
111 for_each_image ( image
) {
112 if ( image
->flags
& IMAGE_LOADED
) {
113 selected_image
= image
;
118 return ( ( flagged_images
== 1 ) ? selected_image
: NULL
);
122 * Display status of an image
124 * @v image Executable/loadable image
126 void imgstat ( struct image
*image
) {
127 printf ( "%s: %zd bytes", image
->name
, image
->len
);
129 printf ( " [%s]", image
->type
->name
);
130 if ( image
->flags
& IMAGE_LOADED
)
131 printf ( " [LOADED]" );
132 if ( image
->cmdline
)
133 printf ( " \"%s\"", image
->cmdline
);
140 * @v image Executable/loadable image
142 void imgfree ( struct image
*image
) {
143 unregister_image ( image
);