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. More...
 
int pxe_probe (struct image *image)
 Probe PXE image. More...
 
int pxe_probe_no_mz (struct image *image)
 Probe PXE image (with rejection of potential EFI images) More...
 
struct image_type pxe_image_type [] __image_type (PROBE_PXE)
 PXE image type. More...
 

Variables

const char * pxe_cmdline
 PXE command line. More...
 

Detailed Description

PXE image format.

Definition in file pxe_image.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FEATURE()

FEATURE ( FEATURE_IMAGE  ,
"PXE"  ,
DHCP_EB_FEATURE_PXE  ,
 
)

◆ pxe_exec()

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.

56  {
57  userptr_t buffer = real_to_user ( 0, 0x7c00 );
58  struct net_device *netdev;
59  int rc;
60 
61  /* Verify and prepare segment */
62  if ( ( rc = prep_segment ( buffer, image->len, image->len ) ) != 0 ) {
63  DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
64  image, strerror ( rc ) );
65  return rc;
66  }
67 
68  /* Copy image to segment */
69  memcpy_user ( buffer, 0, image->data, 0, image->len );
70 
71  /* Arbitrarily pick the most recently opened network device */
72  if ( ( netdev = last_opened_netdev() ) == NULL ) {
73  DBGC ( image, "IMAGE %p could not locate PXE net device\n",
74  image );
75  return -ENODEV;
76  }
77  netdev_get ( netdev );
78 
79  /* Activate PXE */
80  pxe_activate ( netdev );
81 
82  /* Construct fake DHCP packets */
84 
85  /* Set PXE command line */
87 
88  /* Reset console since PXE NBP will probably use it */
89  console_reset();
90 
91  /* Disable IRQ, if applicable */
94 
95  /* Start PXE NBP */
96  rc = pxe_start_nbp();
97 
98  /* Clear PXE command line */
99  pxe_cmdline = NULL;
100 
101  /* Deactivate PXE */
102  pxe_deactivate();
103 
104  /* Try to reopen network device. Ignore errors, since the NBP
105  * may have called PXENV_STOP_UNDI.
106  */
107  netdev_open ( netdev );
108  netdev_put ( netdev );
109 
110  return rc;
111 }
void pxe_activate(struct net_device *netdev)
Activate PXE stack.
Definition: pxe_call.c:276
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
#define DBGC(...)
Definition: compiler.h:505
#define disable_irq(x)
Definition: pic8259.h:52
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
An executable image.
Definition: image.h:24
char * cmdline
Command line to pass to image.
Definition: image.h:39
void pxe_fake_cached_info(void)
Construct cached DHCP packets.
Definition: pxe_preboot.c:135
int pxe_deactivate(void)
Deactivate PXE stack.
Definition: pxe_call.c:307
int prep_segment(userptr_t segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition: segment.c:60
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
unsigned int irq
IRQ.
Definition: device.h:39
const char * pxe_cmdline
PXE command line.
Definition: pxe_image.c:48
static struct net_device * netdev
Definition: gdbudp.c:52
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:973
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
size_t len
Length of raw file image.
Definition: image.h:43
int pxe_start_nbp(void)
Start PXE NBP at 0000:7c00.
Definition: pxe_call.c:337
A network device.
Definition: netdevice.h:348
#define ENODEV
No such device.
Definition: errno.h:509
static void console_reset(void)
Reset console.
Definition: console.h:214
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
struct device_description desc
Device description.
Definition: device.h:79
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:663
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:767
void memcpy_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers.
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References buffer, image::cmdline, console_reset(), image::data, DBGC, device::desc, net_device::dev, disable_irq, 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().

◆ pxe_probe()

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.

119  {
120 
121  /* Images too large to fit in base memory cannot be PXE
122  * images. We include this check to help prevent unrecognised
123  * images from being marked as PXE images, since PXE images
124  * have no signature we can check against.
125  */
126  if ( image->len > ( 0xa0000 - 0x7c00 ) )
127  return -ENOEXEC;
128 
129  /* Rejecting zero-length images is also useful, since these
130  * end up looking to the user like bugs in iPXE.
131  */
132  if ( ! image->len )
133  return -ENOEXEC;
134 
135  return 0;
136 }
#define ENOEXEC
Exec format error.
Definition: errno.h:519
An executable image.
Definition: image.h:24
size_t len
Length of raw file image.
Definition: image.h:43

References ENOEXEC, and image::len.

Referenced by pxe_probe_no_mz().

◆ pxe_probe_no_mz()

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.

144  {
145  uint16_t magic;
146  int rc;
147 
148  /* Probe PXE image */
149  if ( ( rc = pxe_probe ( image ) ) != 0 )
150  return rc;
151 
152  /* Reject image with an "MZ" signature which may indicate an
153  * EFI image incorrectly handed out to a BIOS system.
154  */
155  if ( image->len >= sizeof ( magic ) ) {
156  copy_from_user ( &magic, image->data, 0, sizeof ( magic ) );
158  DBGC ( image, "IMAGE %p may be an EFI image\n",
159  image );
160  return -ENOTTY;
161  }
162  }
163 
164  return 0;
165 }
int pxe_probe(struct image *image)
Probe PXE image.
Definition: pxe_image.c:119
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
userptr_t data
Raw file image.
Definition: image.h:41
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define DBGC(...)
Definition: compiler.h:505
uint32_t magic
Magic signature.
Definition: fdt.h:12
#define EFI_IMAGE_DOS_SIGNATURE
Definition: PeImage.h:49
An executable image.
Definition: image.h:24
size_t len
Length of raw file image.
Definition: image.h:43
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define cpu_to_le16(value)
Definition: byteswap.h:106

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

◆ __image_type()

struct image_type pxe_image_type [] __image_type ( PROBE_PXE  )

PXE image type.

Variable Documentation

◆ pxe_cmdline

const char* pxe_cmdline

PXE command line.

Definition at line 48 of file pxe_image.c.

Referenced by pxe_exec(), and pxenv_file_cmdline().