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 ( &async, start_download ( uri_string, &async,
64 /* Register the image */
65 if ( ( rc = register_image ( image ) ) != 0 )
72 ufree ( image->data );
81 * @ret rc Return status code
83 int imgload ( struct image *image ) {
86 /* Try to load image */
87 if ( ( rc = image_autoload ( image ) ) != 0 )
90 /* If we succeed, move the image to the start of the list */
91 promote_image ( image );
100 * @ret rc Return status code
102 int imgexec ( struct image *image ) {
103 return image_exec ( image );
107 * Identify the first loaded image
109 * @ret image Image, or NULL
111 struct image * imgautoselect ( void ) {
114 for_each_image ( image ) {
115 if ( image->flags & IMAGE_LOADED )
123 * Display status of an image
125 * @v image Executable/loadable image
127 void imgstat ( struct image *image ) {
128 printf ( "%s: %zd bytes", image->name, image->len );
130 printf ( " [%s]", image->type->name );
131 if ( image->flags & IMAGE_LOADED )
132 printf ( " [LOADED]" );
133 if ( image->cmdline[0] )
134 printf ( " \"%s\"", image->cmdline );
141 * @v image Executable/loadable image
143 void imgfree ( struct image *image ) {
144 unregister_image ( image );
145 ufree ( image->data );