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.
28 #include <gpxe/uaccess.h>
29 #include <gpxe/image.h>
30 #include <gpxe/segment.h>
31 #include <gpxe/netdevice.h>
32 #include <gpxe/features.h>
34 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
36 struct image_type pxe_image_type __image_type ( PROBE_PXE );
42 * @ret rc Return status code
44 static int pxe_exec ( struct image *image ) {
47 /* Ensure that PXE stack is ready to use */
48 pxe_init_structures();
51 /* Arbitrarily pick the most recently opened network device */
52 pxe_set_netdev ( last_opened_netdev() );
54 /* Many things will break if pxe_netdev is NULL */
56 DBGC ( image, "IMAGE %p could not locate PXE net device\n",
65 pxe_set_netdev ( NULL );
72 * Load PXE image into memory
75 * @ret rc Return status code
77 int pxe_load ( struct image *image ) {
78 userptr_t buffer = real_to_user ( 0, 0x7c00 );
79 size_t filesz = image->len;
80 size_t memsz = image->len;
83 /* Images too large to fit in base memory cannot be PXE
84 * images. We include this check to help prevent unrecognised
85 * images from being marked as PXE images, since PXE images
86 * have no signature we can check against.
88 if ( filesz > ( 0xa0000 - 0x7c00 ) )
91 /* There are no signature checks for PXE; we will accept anything */
93 image->type = &pxe_image_type;
95 /* Verify and prepare segment */
96 if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
97 DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
98 image, strerror ( rc ) );
102 /* Copy image to segment */
103 memcpy_user ( buffer, 0, image->data, 0, filesz );
108 /** PXE image type */
109 struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {