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
);
30 #include <gpxe/uaccess.h>
31 #include <gpxe/image.h>
32 #include <gpxe/segment.h>
33 #include <gpxe/netdevice.h>
34 #include <gpxe/features.h>
36 FEATURE ( FEATURE_IMAGE
, "PXE", DHCP_EB_FEATURE_PXE
, 1 );
38 struct image_type pxe_image_type
__image_type ( PROBE_PXE
);
44 * @ret rc Return status code
46 static int pxe_exec ( struct image
*image
) {
47 struct net_device
*netdev
;
50 /* Arbitrarily pick the most recently opened network device */
51 if ( ( netdev
= last_opened_netdev() ) == NULL
) {
52 DBGC ( image
, "IMAGE %p could not locate PXE net device\n",
58 pxe_activate ( netdev
);
70 * Load PXE image into memory
73 * @ret rc Return status code
75 int pxe_load ( struct image
*image
) {
76 userptr_t buffer
= real_to_user ( 0, 0x7c00 );
77 size_t filesz
= image
->len
;
78 size_t memsz
= image
->len
;
81 /* Images too large to fit in base memory cannot be PXE
82 * images. We include this check to help prevent unrecognised
83 * images from being marked as PXE images, since PXE images
84 * have no signature we can check against.
86 if ( filesz
> ( 0xa0000 - 0x7c00 ) )
89 /* Rejecting zero-length images is also useful, since these
90 * end up looking to the user like bugs in gPXE.
95 /* There are no signature checks for PXE; we will accept anything */
97 image
->type
= &pxe_image_type
;
99 /* Verify and prepare segment */
100 if ( ( rc
= prep_segment ( buffer
, filesz
, memsz
) ) != 0 ) {
101 DBGC ( image
, "IMAGE %p could not prepare segment: %s\n",
102 image
, strerror ( rc
) );
106 /* Copy image to segment */
107 memcpy_user ( buffer
, 0, image
->data
, 0, filesz
);
112 /** PXE image type */
113 struct image_type pxe_image_type
__image_type ( PROBE_PXE
) = {