iPXE
pxe_image.c File Reference

PXE image format. More...

#include <string.h>
#include <pxe.h>
#include <pxe_call.h>
#include <pic8259.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()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FEATURE()

FEATURE ( FEATURE_IMAGE ,
"PXE" ,
DHCP_EB_FEATURE_PXE ,
1  )

◆ pxe_exec()

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 void *buffer = real_to_virt ( 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 %s could not prepare segment: %s\n",
64 image->name, strerror ( rc ) );
65 return rc;
66 }
67
68 /* Copy image to segment */
70
71 /* Arbitrarily pick the most recently opened network device */
72 if ( ( netdev = last_opened_netdev() ) == NULL ) {
73 DBGC ( image, "IMAGE %s could not locate PXE net device\n",
74 image->name );
75 return -ENODEV;
76 }
78
79 /* Activate PXE */
81
82 /* Construct fake DHCP packets */
84
85 /* Set PXE command line */
87
88 /* Reset console since PXE NBP will probably use it */
90
91 /* Disable IRQ, if applicable */
92 if ( netdev_irq_supported ( netdev ) && netdev->dev->desc.irq )
93 disable_irq ( netdev->dev->desc.irq );
94
95 /* Start PXE NBP */
96 rc = pxe_start_nbp();
97
98 /* Clear PXE command line */
100
101 /* Deactivate PXE */
103
104 /* Try to reopen network device. Ignore errors, since the NBP
105 * may have called PXENV_STOP_UNDI.
106 */
108 netdev_put ( netdev );
109
110 return rc;
111}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGC(...)
Definition compiler.h:505
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define ENODEV
No such device.
Definition errno.h:510
static void console_reset(void)
Reset console.
Definition console.h:215
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition netdevice.c:1048
int netdev_open(struct net_device *netdev)
Open network device.
Definition netdevice.c:862
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:565
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition netdevice.h:673
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
void pxe_activate(struct net_device *netdev)
Activate PXE stack.
Definition pxe_call.c:269
int pxe_start_nbp(void)
Start PXE NBP at 0000:7c00.
Definition pxe_call.c:330
int pxe_deactivate(void)
Deactivate PXE stack.
Definition pxe_call.c:300
const char * pxe_cmdline
PXE command line.
Definition pxe_image.c:48
void pxe_fake_cached_info(void)
Construct cached DHCP packets.
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition realmode.h:77
int prep_segment(void *segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition segment.c:61
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An executable image.
Definition image.h:24
const void * data
Read-only data.
Definition image.h:51
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56
char * cmdline
Command line to pass to image.
Definition image.h:43
A network device.
Definition netdevice.h:353

References buffer, image::cmdline, console_reset(), image::data, DBGC, ENODEV, last_opened_netdev(), image::len, memcpy(), image::name, 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_virt(), and strerror().

Referenced by __image_type().

◆ 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:520

References ENOEXEC, and image::len.

Referenced by __image_type(), and 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 const 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 magic = image->data;
158 DBGC ( image, "IMAGE %s may be an EFI image\n",
159 image->name );
160 return -ENOTTY;
161 }
162 }
163
164 return 0;
165}
#define EFI_IMAGE_DOS_SIGNATURE
Definition PeImage.h:50
unsigned short uint16_t
Definition stdint.h:11
uint16_t magic
Magic signature.
Definition bzimage.h:1
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:595
#define cpu_to_le16(value)
Definition byteswap.h:107
int pxe_probe(struct image *image)
Probe PXE image.
Definition pxe_image.c:119

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

Referenced by __image_type().

◆ __image_type()

struct image_type pxe_image_type[] __image_type ( PROBE_PXE )

PXE image type.

References __image_type, PROBE_PXE, pxe_exec(), pxe_probe(), and pxe_probe_no_mz().

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().