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 <usr/fetch.h>
25 #include <usr/imgmgmt.h>
36 * @v filename Filename for image
37 * @v name Name for image, or NULL
38 * @ret new_image Newly created image
39 * @ret rc Return status code
41 int imgfetch ( const char *filename, const char *name,
42 struct image **new_image ) {
46 /* Allocate new image */
47 image = malloc ( sizeof ( *image ) );
50 memset ( image, 0, sizeof ( *image ) );
52 /* Fill in image name */
54 strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
57 if ( ( rc = fetch ( image, filename ) ) != 0 )
60 /* Register the image */
61 if ( ( rc = register_image ( image ) ) != 0 )
77 * @ret rc Return status code
79 int imgload ( struct image *image ) {
80 return image_autoload ( image );
87 * @ret rc Return status code
89 int imgexec ( struct image *image ) {
90 return image_exec ( image );
94 * Display status of an image
96 * @v image Executable/loadable image
98 void imgstat ( struct image *image ) {
99 printf ( "%s: %zd bytes", image->name, image->len );
101 printf ( " [%s]", image->type->name );
102 if ( image->flags & IMAGE_LOADED )
103 printf ( " [LOADED]" );
104 if ( image->cmdline[0] )
105 printf ( " \"%s\"", image->cmdline );
112 * @v image Executable/loadable image
114 void imgfree ( struct image *image ) {
115 unregister_image ( image );
116 free_image ( image );