iPXE
Functions | Variables
pxe_image.c File Reference

PXE image format. More...

#include <pxe.h>
#include <pxe_call.h>
#include <pic8259.h>
#include <ipxe/uaccess.h>
#include <ipxe/image.h>
#include <ipxe/segment.h>
#include <ipxe/netdevice.h>
#include <ipxe/features.h>
#include <ipxe/console.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/IndustryStandard/PeImage.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_IMAGE,"PXE", DHCP_EB_FEATURE_PXE, 1)
static int pxe_exec (struct image *image)
 Execute PXE image.
int pxe_probe (struct image *image)
 Probe PXE image.
int pxe_probe_no_mz (struct image *image)
 Probe PXE image (with rejection of potential EFI images)
struct image_type pxe_image_type[] __image_type (PROBE_PXE)
 PXE image type.

Variables

const char * pxe_cmdline
 PXE command line.

Detailed Description

PXE image format.

Definition in file pxe_image.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
FEATURE ( FEATURE_IMAGE  ,
"PXE"  ,
DHCP_EB_FEATURE_PXE  ,
 
)
static int pxe_exec ( struct image image) [static]

Execute PXE image.

Parameters:
imagePXE image
Return values:
rcReturn status code

Definition at line 56 of file pxe_image.c.

References buffer, image::cmdline, console_reset(), image::data, DBGC, device::desc, net_device::dev, ENODEV, device_description::irq, last_opened_netdev(), image::len, memcpy_user(), netdev, netdev_get(), netdev_irq_supported(), netdev_open(), netdev_put(), NULL, prep_segment(), pxe_activate(), pxe_cmdline, pxe_deactivate(), pxe_fake_cached_info(), pxe_start_nbp(), rc, real_to_user(), and strerror().

                                            {
        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 );

        /* Construct fake DHCP packets */
        pxe_fake_cached_info();

        /* Set PXE command line */
        pxe_cmdline = image->cmdline;

        /* Reset console since PXE NBP will probably use it */
        console_reset();

        /* Disable IRQ, if applicable */
        if ( netdev_irq_supported ( netdev ) && netdev->dev->desc.irq )
                disable_irq ( netdev->dev->desc.irq );

        /* 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;
}
int pxe_probe ( struct image image)

Probe PXE image.

Parameters:
imagePXE file
Return values:
rcReturn status code

Definition at line 119 of file pxe_image.c.

References ENOEXEC, and image::len.

Referenced by pxe_probe_no_mz().

                                      {

        /* 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;
}
int pxe_probe_no_mz ( struct image image)

Probe PXE image (with rejection of potential EFI images)

Parameters:
imagePXE file
Return values:
rcReturn status code

Definition at line 144 of file pxe_image.c.

References copy_from_user(), cpu_to_le16, image::data, DBGC, EFI_IMAGE_DOS_SIGNATURE, ENOTTY, image::len, magic, pxe_probe(), and rc.

                                            {
        uint16_t magic;
        int rc;

        /* Probe PXE image */
        if ( ( rc = pxe_probe ( image ) ) != 0 )
                return rc;

        /* Reject image with an "MZ" signature which may indicate an
         * EFI image incorrectly handed out to a BIOS system.
         */
        if ( image->len >= sizeof ( magic ) ) {
                copy_from_user ( &magic, image->data, 0, sizeof ( magic ) );
                if ( magic == cpu_to_le16 ( EFI_IMAGE_DOS_SIGNATURE ) ) {
                        DBGC ( image, "IMAGE %p may be an EFI image\n",
                               image );
                        return -ENOTTY;
                }
        }

        return 0;
}
struct image_type pxe_image_type [] __image_type ( PROBE_PXE  ) [read]

PXE image type.


Variable Documentation

const char* pxe_cmdline

PXE command line.

Definition at line 48 of file pxe_image.c.

Referenced by pxe_exec(), and pxenv_file_cmdline().