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_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_exec()

static int sdi_exec ( struct image image)
static

Execute SDI image.

Parameters
imageSDI file
Return values
rcReturn status code

Definition at line 53 of file sdi.c.

53  {
54  const struct sdi_header *sdi;
55  uint32_t sdiptr;
56 
57  /* Sanity check */
58  assert ( image->len >= sizeof ( *sdi ) );
59  sdi = image->data;
60 
61  /* Check that image is bootable */
62  if ( sdi->boot_size == 0 ) {
63  DBGC ( image, "SDI %s is not bootable\n", image->name );
64  return -ENOTTY;
65  }
66  DBGC ( image, "SDI %s image at %08lx+%08zx\n",
67  image->name, virt_to_phys ( image->data ), image->len );
68  DBGC ( image, "SDI %s boot code at %08llx+%llx\n", image->name,
69  ( virt_to_phys ( image->data ) + sdi->boot_offset ),
70  sdi->boot_size );
71 
72  /* Copy boot code */
74  ( image->data + sdi->boot_offset ), sdi->boot_size );
75 
76  /* Jump to boot code */
77  sdiptr = ( virt_to_phys ( image->data ) | SDI_WTF );
78  __asm__ __volatile__ ( REAL_CODE ( "ljmp %0, %1\n\t" )
79  : : "i" ( SDI_BOOT_SEG ),
80  "i" ( SDI_BOOT_OFF ),
81  "d" ( sdiptr ) );
82 
83  /* There is no way for the image to return, since we provide
84  * no return address.
85  */
86  assert ( 0 );
87 
88  return -ECANCELED; /* -EIMPOSSIBLE */
89 }
#define SDI_BOOT_SEG
SDI boot segment.
Definition: sdi.h:31
const void * data
Read-only data.
Definition: image.h:50
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define ECANCELED
Operation canceled.
Definition: errno.h:343
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
uint64_t boot_size
Boot code size.
Definition: sdi.h:23
void * memcpy(void *dest, const void *src, size_t len) __nonnull
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:55
uint64_t boot_offset
Boot code offset.
Definition: sdi.h:21
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned int uint32_t
Definition: stdint.h:12
SDI image header.
Definition: sdi.h:13
__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
#define SDI_BOOT_OFF
SDI boot offset.
Definition: sdi.h:34
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
char * name
Name.
Definition: image.h:37

References __asm__(), __volatile__(), assert(), sdi_header::boot_offset, sdi_header::boot_size, image::data, DBGC, ECANCELED, ENOTTY, image::len, memcpy(), image::name, REAL_CODE, real_to_virt(), SDI_BOOT_OFF, SDI_BOOT_SEG, and SDI_WTF.

◆ sdi_probe()

static int sdi_probe ( struct image image)
static

Probe SDI image.

Parameters
imageSDI file
Return values
rcReturn status code

Definition at line 97 of file sdi.c.

97  {
98  const struct sdi_header *sdi;
99 
100  /* Sanity check */
101  if ( image->len < sizeof ( *sdi ) ) {
102  DBGC ( image, "SDI %s too short for SDI header\n",
103  image->name );
104  return -ENOEXEC;
105  }
106  sdi = image->data;
107 
108  /* Check signature */
109  if ( sdi->magic != SDI_MAGIC ) {
110  DBGC ( image, "SDI %s is not an SDI image\n",
111  image->name );
112  return -ENOEXEC;
113  }
114 
115  return 0;
116 }
const void * data
Read-only data.
Definition: image.h:50
#define ENOEXEC
Exec format error.
Definition: errno.h:519
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
size_t len
Length of raw file image.
Definition: image.h:55
uint32_t magic
Signature.
Definition: sdi.h:15
SDI image header.
Definition: sdi.h:13
#define SDI_MAGIC
SDI image signature.
Definition: sdi.h:27
char * name
Name.
Definition: image.h:37

References image::data, DBGC, ENOEXEC, image::len, sdi_header::magic, image::name, and SDI_MAGIC.

◆ __image_type()

struct image_type sdi_image_type __image_type ( PROBE_NORMAL  )

SDI image type.