From e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 28 Aug 2015 09:58:54 +0800 Subject: Add qemu 2.4.0 Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang --- qemu/roms/ipxe/src/arch/i386/image/pxe_image.c | 129 +++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 qemu/roms/ipxe/src/arch/i386/image/pxe_image.c (limited to 'qemu/roms/ipxe/src/arch/i386/image/pxe_image.c') diff --git a/qemu/roms/ipxe/src/arch/i386/image/pxe_image.c b/qemu/roms/ipxe/src/arch/i386/image/pxe_image.c new file mode 100644 index 000000000..dc28f6082 --- /dev/null +++ b/qemu/roms/ipxe/src/arch/i386/image/pxe_image.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2007 Michael Brown . + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +/** + * @file + * + * PXE image format + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 ); + +/** PXE command line */ +const char *pxe_cmdline; + +/** + * Execute PXE image + * + * @v image PXE image + * @ret rc Return status code + */ +static int pxe_exec ( struct image *image ) { + userptr_t buffer = real_to_user ( 0, 0x7c00 ); + struct net_device *netdev; + int rc; + + /* Verify and prepare segment */ + if ( ( rc = prep_segment ( buffer, image->len, image->len ) ) != 0 ) { + DBGC ( image, "IMAGE %p could not prepare segment: %s\n", + image, strerror ( rc ) ); + return rc; + } + + /* Copy image to segment */ + memcpy_user ( buffer, 0, image->data, 0, image->len ); + + /* Arbitrarily pick the most recently opened network device */ + if ( ( netdev = last_opened_netdev() ) == NULL ) { + DBGC ( image, "IMAGE %p could not locate PXE net device\n", + image ); + return -ENODEV; + } + netdev_get ( netdev ); + + /* Activate PXE */ + pxe_activate ( netdev ); + + /* Set PXE command line */ + pxe_cmdline = image->cmdline; + + /* Reset console since PXE NBP will probably use it */ + console_reset(); + + /* Start PXE NBP */ + rc = pxe_start_nbp(); + + /* Clear PXE command line */ + pxe_cmdline = NULL; + + /* Deactivate PXE */ + pxe_deactivate(); + + /* Try to reopen network device. Ignore errors, since the NBP + * may have called PXENV_STOP_UNDI. + */ + netdev_open ( netdev ); + netdev_put ( netdev ); + + return rc; +} + +/** + * Probe PXE image + * + * @v image PXE file + * @ret rc Return status code + */ +int pxe_probe ( struct image *image ) { + + /* Images too large to fit in base memory cannot be PXE + * images. We include this check to help prevent unrecognised + * images from being marked as PXE images, since PXE images + * have no signature we can check against. + */ + if ( image->len > ( 0xa0000 - 0x7c00 ) ) + return -ENOEXEC; + + /* Rejecting zero-length images is also useful, since these + * end up looking to the user like bugs in iPXE. + */ + if ( ! image->len ) + return -ENOEXEC; + + return 0; +} + +/** PXE image type */ +struct image_type pxe_image_type __image_type ( PROBE_PXE ) = { + .name = "PXE", + .probe = pxe_probe, + .exec = pxe_exec, +}; -- cgit 1.2.3-korg