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., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
31 #include <ipxe/uaccess.h>
32 #include <ipxe/image.h>
33 #include <ipxe/segment.h>
34 #include <ipxe/netdevice.h>
35 #include <ipxe/features.h>
36 #include <ipxe/console.h>
38 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
40 /** PXE command line */
41 const char *pxe_cmdline;
47 * @ret rc Return status code
49 static int pxe_exec ( struct image *image ) {
50 userptr_t buffer = real_to_user ( 0, 0x7c00 );
51 struct net_device *netdev;
54 /* Verify and prepare segment */
55 if ( ( rc = prep_segment ( buffer, image->len, image->len ) ) != 0 ) {
56 DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
57 image, strerror ( rc ) );
61 /* Copy image to segment */
62 memcpy_user ( buffer, 0, image->data, 0, image->len );
64 /* Arbitrarily pick the most recently opened network device */
65 if ( ( netdev = last_opened_netdev() ) == NULL ) {
66 DBGC ( image, "IMAGE %p could not locate PXE net device\n",
70 netdev_get ( netdev );
73 pxe_activate ( netdev );
75 /* Set PXE command line */
76 pxe_cmdline = image->cmdline;
78 /* Reset console since PXE NBP will probably use it */
84 /* Clear PXE command line */
90 /* Try to reopen network device. Ignore errors, since the NBP
91 * may have called PXENV_STOP_UNDI.
93 netdev_open ( netdev );
94 netdev_put ( netdev );
103 * @ret rc Return status code
105 int pxe_probe ( struct image *image ) {
107 /* Images too large to fit in base memory cannot be PXE
108 * images. We include this check to help prevent unrecognised
109 * images from being marked as PXE images, since PXE images
110 * have no signature we can check against.
112 if ( image->len > ( 0xa0000 - 0x7c00 ) )
115 /* Rejecting zero-length images is also useful, since these
116 * end up looking to the user like bugs in iPXE.
124 /** PXE image type */
125 struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {