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/emalloc.h>
25 #include <usr/fetch.h>
26 #include <usr/imgmgmt.h>
37 * @v filename Filename for image
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 *filename, const char *name,
43 struct image **new_image ) {
47 /* Allocate new image */
48 image = malloc ( sizeof ( *image ) );
51 memset ( image, 0, sizeof ( *image ) );
53 /* Fill in image name */
55 strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
58 if ( ( rc = fetch ( filename, &image->data, &image->len ) ) != 0 )
61 /* Register the image */
62 if ( ( rc = register_image ( image ) ) != 0 )
69 efree ( image->data );
78 * @ret rc Return status code
80 int imgload ( struct image *image ) {
83 /* Try to load image */
84 if ( ( rc = image_autoload ( image ) ) != 0 )
87 /* If we succeed, move the image to the start of the list */
88 promote_image ( image );
97 * @ret rc Return status code
99 int imgexec ( struct image *image ) {
100 return image_exec ( image );
104 * Identify the first loaded image
106 * @ret image Image, or NULL
108 struct image * imgautoselect ( void ) {
111 for_each_image ( image ) {
112 if ( image->flags & IMAGE_LOADED )
120 * Display status of an image
122 * @v image Executable/loadable image
124 void imgstat ( struct image *image ) {
125 printf ( "%s: %zd bytes", image->name, image->len );
127 printf ( " [%s]", image->type->name );
128 if ( image->flags & IMAGE_LOADED )
129 printf ( " [LOADED]" );
130 if ( image->cmdline[0] )
131 printf ( " \"%s\"", image->cmdline );
138 * @v image Executable/loadable image
140 void imgfree ( struct image *image ) {
141 unregister_image ( image );
142 efree ( image->data );