pxe_image.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 /**
00022  * @file
00023  *
00024  * PXE image format
00025  *
00026  */
00027 
00028 #include <pxe.h>
00029 #include <pxe_call.h>
00030 #include <gpxe/uaccess.h>
00031 #include <gpxe/image.h>
00032 #include <gpxe/segment.h>
00033 #include <gpxe/netdevice.h>
00034 #include <gpxe/features.h>
00035 
00036 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
00037 
00038 struct image_type pxe_image_type __image_type ( PROBE_PXE );
00039 
00040 /**
00041  * Execute PXE image
00042  *
00043  * @v image             PXE image
00044  * @ret rc              Return status code
00045  */
00046 static int pxe_exec ( struct image *image ) {
00047         struct net_device *netdev;
00048         int rc;
00049 
00050         /* Arbitrarily pick the most recently opened network device */
00051         if ( ( netdev = last_opened_netdev() ) == NULL ) {
00052                 DBGC ( image, "IMAGE %p could not locate PXE net device\n",
00053                        image );
00054                 return -ENODEV;
00055         }
00056 
00057         /* Activate PXE */
00058         pxe_activate ( netdev );
00059 
00060         /* Start PXE NBP */
00061         rc = pxe_start_nbp();
00062 
00063         /* Deactivate PXE */
00064         pxe_deactivate();
00065 
00066         return rc;
00067 }
00068 
00069 /**
00070  * Load PXE image into memory
00071  *
00072  * @v image             PXE file
00073  * @ret rc              Return status code
00074  */
00075 int pxe_load ( struct image *image ) {
00076         userptr_t buffer = real_to_user ( 0, 0x7c00 );
00077         size_t filesz = image->len;
00078         size_t memsz = image->len;
00079         int rc;
00080 
00081         /* Images too large to fit in base memory cannot be PXE
00082          * images.  We include this check to help prevent unrecognised
00083          * images from being marked as PXE images, since PXE images
00084          * have no signature we can check against.
00085          */
00086         if ( filesz > ( 0xa0000 - 0x7c00 ) )
00087                 return -ENOEXEC;
00088 
00089         /* Rejecting zero-length images is also useful, since these
00090          * end up looking to the user like bugs in gPXE.
00091          */
00092         if ( ! filesz )
00093                 return -ENOEXEC;
00094 
00095         /* There are no signature checks for PXE; we will accept anything */
00096         if ( ! image->type )
00097                 image->type = &pxe_image_type;
00098 
00099         /* Verify and prepare segment */
00100         if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
00101                 DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
00102                        image, strerror ( rc ) );
00103                 return rc;
00104         }
00105 
00106         /* Copy image to segment */
00107         memcpy_user ( buffer, 0, image->data, 0, filesz );
00108 
00109         return 0;
00110 }
00111 
00112 /** PXE image type */
00113 struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
00114         .name = "PXE",
00115         .load = pxe_load,
00116         .exec = pxe_exec,
00117 };

Generated on Tue Apr 6 20:00:50 2010 for gPXE by  doxygen 1.5.7.1