iPXE
Functions
sdi.c File Reference

System Deployment Image (SDI) More...

#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <realmode.h>
#include <sdi.h>
#include <ipxe/image.h>
#include <ipxe/features.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FEATURE (FEATURE_IMAGE, "SDI", DHCP_EB_FEATURE_SDI, 1)
 
static int sdi_parse_header (struct image *image, struct sdi_header *sdi)
 Parse SDI image header. More...
 
static int sdi_exec (struct image *image)
 Execute SDI image. More...
 
static int sdi_probe (struct image *image)
 Probe SDI image. More...
 
struct image_type sdi_image_type __image_type (PROBE_NORMAL)
 SDI image type. More...
 

Detailed Description

System Deployment Image (SDI)

Based on the MSDN article "RAM boot using SDI in Windows XP Embedded with Service Pack 1", available at the time of writing from:

http://msdn.microsoft.com/en-us/library/ms838543.aspx

Definition in file sdi.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FEATURE()

FEATURE ( FEATURE_IMAGE  ,
"SDI"  ,
DHCP_EB_FEATURE_SDI  ,
 
)

◆ sdi_parse_header()

static int sdi_parse_header ( struct image image,
struct sdi_header sdi 
)
static

Parse SDI image header.

Parameters
imageSDI file
sdiSDI header to fill in
Return values
rcReturn status code

Definition at line 54 of file sdi.c.

54  {
55 
56  /* Sanity check */
57  if ( image->len < sizeof ( *sdi ) ) {
58  DBGC ( image, "SDI %p too short for SDI header\n", image );
59  return -ENOEXEC;
60  }
61 
62  /* Read in header */
63  copy_from_user ( sdi, image->data, 0, sizeof ( *sdi ) );
64 
65  /* Check signature */
66  if ( sdi->magic != SDI_MAGIC ) {
67  DBGC ( image, "SDI %p is not an SDI image\n", image );
68  return -ENOEXEC;
69  }
70 
71  return 0;
72 }
userptr_t data
Raw file image.
Definition: image.h:41
#define ENOEXEC
Exec format error.
Definition: errno.h:519
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
An executable image.
Definition: image.h:24
size_t len
Length of raw file image.
Definition: image.h:43
uint32_t magic
Signature.
Definition: sdi.h:15
#define SDI_MAGIC
SDI image signature.
Definition: sdi.h:27

References copy_from_user(), image::data, DBGC, ENOEXEC, image::len, sdi_header::magic, and SDI_MAGIC.

Referenced by sdi_exec(), and sdi_probe().

◆ sdi_exec()

static int sdi_exec ( struct image image)
static

Execute SDI image.

Parameters
imageSDI file
Return values
rcReturn status code

Definition at line 80 of file sdi.c.

80  {
81  struct sdi_header sdi;
82  uint32_t sdiptr;
83  int rc;
84 
85  /* Parse image header */
86  if ( ( rc = sdi_parse_header ( image, &sdi ) ) != 0 )
87  return rc;
88 
89  /* Check that image is bootable */
90  if ( sdi.boot_size == 0 ) {
91  DBGC ( image, "SDI %p is not bootable\n", image );
92  return -ENOTTY;
93  }
94  DBGC ( image, "SDI %p image at %08lx+%08zx\n",
95  image, user_to_phys ( image->data, 0 ), image->len );
96  DBGC ( image, "SDI %p boot code at %08lx+%llx\n", image,
97  user_to_phys ( image->data, sdi.boot_offset ), sdi.boot_size );
98 
99  /* Copy boot code */
101  image->data, sdi.boot_offset, sdi.boot_size );
102 
103  /* Jump to boot code */
104  sdiptr = ( user_to_phys ( image->data, 0 ) | SDI_WTF );
105  __asm__ __volatile__ ( REAL_CODE ( "ljmp %0, %1\n\t" )
106  : : "i" ( SDI_BOOT_SEG ),
107  "i" ( SDI_BOOT_OFF ),
108  "d" ( sdiptr ) );
109 
110  /* There is no way for the image to return, since we provide
111  * no return address.
112  */
113  assert ( 0 );
114 
115  return -ECANCELED; /* -EIMPOSSIBLE */
116 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SDI_BOOT_SEG
SDI boot segment.
Definition: sdi.h:31
userptr_t data
Raw file image.
Definition: image.h:41
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define ECANCELED
Operation canceled.
Definition: errno.h:343
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define SDI_WTF
Constant to binary-OR with physical address of SDI image.
Definition: sdi.h:37
size_t len
Length of raw file image.
Definition: image.h:43
unsigned int uint32_t
Definition: stdint.h:12
SDI image header.
Definition: sdi.h:13
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
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 SDI_BOOT_OFF
SDI boot offset.
Definition: sdi.h:34
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
static int sdi_parse_header(struct image *image, struct sdi_header *sdi)
Parse SDI image header.
Definition: sdi.c:54
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.

References __asm__(), __volatile__(), assert(), sdi_header::boot_offset, sdi_header::boot_size, image::data, DBGC, ECANCELED, ENOTTY, image::len, memcpy_user(), rc, REAL_CODE, real_to_user(), SDI_BOOT_OFF, SDI_BOOT_SEG, sdi_parse_header(), SDI_WTF, and user_to_phys().

◆ sdi_probe()

static int sdi_probe ( struct image image)
static

Probe SDI image.

Parameters
imageSDI file
Return values
rcReturn status code

Definition at line 124 of file sdi.c.

124  {
125  struct sdi_header sdi;
126  int rc;
127 
128  /* Parse image */
129  if ( ( rc = sdi_parse_header ( image, &sdi ) ) != 0 )
130  return rc;
131 
132  return 0;
133 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:24
SDI image header.
Definition: sdi.h:13
static int sdi_parse_header(struct image *image, struct sdi_header *sdi)
Parse SDI image header.
Definition: sdi.c:54

References rc, and sdi_parse_header().

◆ __image_type()

struct image_type sdi_image_type __image_type ( PROBE_NORMAL  )

SDI image type.