iPXE
Data Structures | Macros | Functions
nbi.c File Reference

NBI image format. More...

#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <memsizes.h>
#include <basemem_packet.h>
#include <ipxe/uaccess.h>
#include <ipxe/segment.h>
#include <ipxe/init.h>
#include <ipxe/netdevice.h>
#include <ipxe/fakedhcp.h>
#include <ipxe/image.h>
#include <ipxe/features.h>
#include <ipxe/version.h>

Go to the source code of this file.

Data Structures

struct  imgheader
 An NBI image header. More...
 
struct  segheader
 An NBI segment header. More...
 
struct  ebinfo
 

Macros

#define NBI_MAGIC   0x1B031336UL
 NBI magic number. More...
 
#define NBI_NONVENDOR_LENGTH(len)   ( ( (len) & 0x0f ) << 2 )
 
#define NBI_VENDOR_LENGTH(len)   ( ( (len) & 0xf0 ) >> 2 )
 
#define NBI_LENGTH(len)   ( NBI_NONVENDOR_LENGTH(len) + NBI_VENDOR_LENGTH(len) )
 
#define NBI_PROGRAM_RETURNS(flags)   ( (flags) & ( 1 << 8 ) )
 
#define NBI_LINEAR_EXEC_ADDR(flags)   ( (flags) & ( 1 << 31 ) )
 
#define NBI_HEADER_LENGTH   512
 NBI header length. More...
 
#define NBI_LOADADDR_FLAGS(flags)   ( (flags) & 0x03 )
 
#define NBI_LOADADDR_ABS   0x00
 
#define NBI_LOADADDR_AFTER   0x01
 
#define NBI_LOADADDR_END   0x02
 
#define NBI_LOADADDR_BEFORE   0x03
 
#define NBI_LAST_SEGHEADER(flags)   ( (flags) & ( 1 << 2 ) )
 

Functions

 FEATURE (FEATURE_IMAGE, "NBI", DHCP_EB_FEATURE_NBI, 1)
 
static int nbi_prepare_segment (struct image *image, size_t offset __unused, userptr_t dest, size_t filesz, size_t memsz)
 Prepare a segment for an NBI image. More...
 
static int nbi_load_segment (struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz __unused)
 Load a segment for an NBI image. More...
 
static int nbi_process_segments (struct image *image, struct imgheader *imgheader, int(*process)(struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz))
 Process segments of an NBI image. More...
 
static int nbi_boot16 (struct image *image, struct imgheader *imgheader)
 Boot a 16-bit NBI image. More...
 
static int nbi_boot32 (struct image *image, struct imgheader *imgheader)
 Boot a 32-bit NBI image. More...
 
static int nbi_prepare_dhcp (struct image *image)
 Prepare DHCP parameter block for NBI image. More...
 
static int nbi_exec (struct image *image)
 Execute a loaded NBI image. More...
 
static int nbi_probe (struct image *image)
 Probe NBI image. More...
 
struct image_type nbi_image_type __image_type (PROBE_NORMAL)
 NBI image type. More...
 

Detailed Description

NBI image format.

The Net Boot Image format is defined by the "Draft Net Boot Image Proposal 0.3" by Jamie Honan, Gero Kuhlmann and Ken Yap. It is now considered to be a legacy format, but it still included because a large amount of software (e.g. nymph, LTSP) makes use of NBI files.

Etherboot does not implement the INT 78 callback interface described by the NBI specification. For a callback interface on x86 architecture, use PXE.

Definition in file nbi.c.

Macro Definition Documentation

◆ NBI_MAGIC

#define NBI_MAGIC   0x1B031336UL

NBI magic number.

Definition at line 53 of file nbi.c.

◆ NBI_NONVENDOR_LENGTH

#define NBI_NONVENDOR_LENGTH (   len)    ( ( (len) & 0x0f ) << 2 )

Definition at line 56 of file nbi.c.

◆ NBI_VENDOR_LENGTH

#define NBI_VENDOR_LENGTH (   len)    ( ( (len) & 0xf0 ) >> 2 )

Definition at line 57 of file nbi.c.

◆ NBI_LENGTH

#define NBI_LENGTH (   len)    ( NBI_NONVENDOR_LENGTH(len) + NBI_VENDOR_LENGTH(len) )

Definition at line 58 of file nbi.c.

◆ NBI_PROGRAM_RETURNS

#define NBI_PROGRAM_RETURNS (   flags)    ( (flags) & ( 1 << 8 ) )

Definition at line 61 of file nbi.c.

◆ NBI_LINEAR_EXEC_ADDR

#define NBI_LINEAR_EXEC_ADDR (   flags)    ( (flags) & ( 1 << 31 ) )

Definition at line 62 of file nbi.c.

◆ NBI_HEADER_LENGTH

#define NBI_HEADER_LENGTH   512

NBI header length.

Definition at line 65 of file nbi.c.

◆ NBI_LOADADDR_FLAGS

#define NBI_LOADADDR_FLAGS (   flags)    ( (flags) & 0x03 )

Definition at line 85 of file nbi.c.

◆ NBI_LOADADDR_ABS

#define NBI_LOADADDR_ABS   0x00

Definition at line 86 of file nbi.c.

◆ NBI_LOADADDR_AFTER

#define NBI_LOADADDR_AFTER   0x01

Definition at line 87 of file nbi.c.

◆ NBI_LOADADDR_END

#define NBI_LOADADDR_END   0x02

Definition at line 88 of file nbi.c.

◆ NBI_LOADADDR_BEFORE

#define NBI_LOADADDR_BEFORE   0x03

Definition at line 89 of file nbi.c.

◆ NBI_LAST_SEGHEADER

#define NBI_LAST_SEGHEADER (   flags)    ( (flags) & ( 1 << 2 ) )

Definition at line 90 of file nbi.c.

Function Documentation

◆ FEATURE()

FEATURE ( FEATURE_IMAGE  ,
"NBI"  ,
DHCP_EB_FEATURE_NBI  ,
 
)

◆ nbi_prepare_segment()

static int nbi_prepare_segment ( struct image image,
size_t offset  __unused,
userptr_t  dest,
size_t  filesz,
size_t  memsz 
)
static

Prepare a segment for an NBI image.

Parameters
imageNBI image
offsetOffset within NBI image
fileszLength of initialised-data portion of the segment
memszTotal length of the segment
srcSource for initialised data
Return values
rcReturn status code

Definition at line 108 of file nbi.c.

109  {
110  int rc;
111 
112  if ( ( rc = prep_segment ( dest, filesz, memsz ) ) != 0 ) {
113  DBGC ( image, "NBI %p could not prepare segment: %s\n",
114  image, strerror ( rc ) );
115  return rc;
116  }
117 
118  return 0;
119 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
int prep_segment(userptr_t segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition: segment.c:60
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150

References DBGC, dest, prep_segment(), rc, and strerror().

Referenced by nbi_exec().

◆ nbi_load_segment()

static int nbi_load_segment ( struct image image,
size_t  offset,
userptr_t  dest,
size_t  filesz,
size_t memsz  __unused 
)
static

Load a segment for an NBI image.

Parameters
imageNBI image
offsetOffset within NBI image
fileszLength of initialised-data portion of the segment
memszTotal length of the segment
srcSource for initialised data
Return values
rcReturn status code

Definition at line 131 of file nbi.c.

133  {
134  memcpy_user ( dest, 0, image->data, offset, filesz );
135  return 0;
136 }
userptr_t data
Raw file image.
Definition: image.h:41
An executable image.
Definition: image.h:24
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
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 image::data, dest, memcpy_user(), and offset.

Referenced by nbi_exec().

◆ nbi_process_segments()

static int nbi_process_segments ( struct image image,
struct imgheader imgheader,
int(*)(struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz)  process 
)
static

Process segments of an NBI image.

Parameters
imageNBI image
imgheaderImage header information
processFunction to call for each segment
Return values
rcReturn status code

Definition at line 146 of file nbi.c.

152  {
153  struct segheader sh;
154  size_t offset = 0;
155  size_t sh_off;
156  userptr_t dest;
157  size_t filesz;
158  size_t memsz;
159  int rc;
160 
161  /* Copy image header to target location */
164  filesz = memsz = NBI_HEADER_LENGTH;
165  if ( ( rc = process ( image, offset, dest, filesz, memsz ) ) != 0 )
166  return rc;
167  offset += filesz;
168 
169  /* Process segments in turn */
170  sh_off = NBI_LENGTH ( imgheader->length );
171  do {
172  /* Read segment header */
173  copy_from_user ( &sh, image->data, sh_off, sizeof ( sh ) );
174  if ( sh.length == 0 ) {
175  /* Avoid infinite loop? */
176  DBGC ( image, "NBI %p invalid segheader length 0\n",
177  image );
178  return -ENOEXEC;
179  }
180 
181  /* Calculate segment load address */
182  switch ( NBI_LOADADDR_FLAGS ( sh.flags ) ) {
183  case NBI_LOADADDR_ABS:
184  dest = phys_to_user ( sh.loadaddr );
185  break;
186  case NBI_LOADADDR_AFTER:
187  dest = userptr_add ( dest, memsz + sh.loadaddr );
188  break;
189  case NBI_LOADADDR_BEFORE:
190  dest = userptr_add ( dest, -sh.loadaddr );
191  break;
192  case NBI_LOADADDR_END:
193  /* Not correct according to the spec, but
194  * maintains backwards compatibility with
195  * previous versions of Etherboot.
196  */
197  dest = phys_to_user ( ( extmemsize() + 1024 ) * 1024
198  - sh.loadaddr );
199  break;
200  default:
201  /* Cannot be reached */
202  assert ( 0 );
203  }
204 
205  /* Process this segment */
206  filesz = sh.imglength;
207  memsz = sh.memlength;
208  if ( ( offset + filesz ) > image->len ) {
209  DBGC ( image, "NBI %p segment outside file\n", image );
210  return -ENOEXEC;
211  }
212  if ( ( rc = process ( image, offset, dest,
213  filesz, memsz ) ) != 0 ) {
214  return rc;
215  }
216  offset += filesz;
217 
218  /* Next segheader */
219  sh_off += NBI_LENGTH ( sh.length );
220  if ( sh_off >= NBI_HEADER_LENGTH ) {
221  DBGC ( image, "NBI %p header overflow\n", image );
222  return -ENOEXEC;
223  }
224 
225  } while ( ! NBI_LAST_SEGHEADER ( sh.flags ) );
226 
227  if ( offset != image->len ) {
228  DBGC ( image, "NBI %p length wrong (file %zd, metadata %zd)\n",
229  image, image->len, offset );
230  return -ENOEXEC;
231  }
232 
233  return 0;
234 }
uint16_t segment
Definition: registers.h:193
A process.
Definition: process.h:17
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
#define NBI_LOADADDR_AFTER
Definition: nbi.c:87
An NBI image header.
Definition: nbi.c:39
#define NBI_LOADADDR_ABS
Definition: nbi.c:86
#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:411
#define DBGC(...)
Definition: compiler.h:505
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
An executable image.
Definition: image.h:24
#define NBI_LOADADDR_FLAGS(flags)
Definition: nbi.c:85
#define NBI_LAST_SEGHEADER(flags)
Definition: nbi.c:90
#define NBI_LOADADDR_BEFORE
Definition: nbi.c:89
userptr_t userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
#define NBI_HEADER_LENGTH
NBI header length.
Definition: nbi.c:65
uint32_t userptr_t
A pointer to a user buffer.
Definition: libkir.h:159
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int extmemsize(void)
Get size of extended memory.
Definition: memmap.c:156
uint16_t offset
Definition: registers.h:192
An NBI segment header.
Definition: nbi.c:74
size_t len
Length of raw file image.
Definition: image.h:43
segoff_t location
16-bit seg:off header location
Definition: nbi.c:45
#define NBI_LENGTH(len)
Definition: nbi.c:58
#define NBI_LOADADDR_END
Definition: nbi.c:88
unsigned char length
Nibble-coded header length.
Definition: nbi.c:42
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

References assert(), copy_from_user(), image::data, DBGC, dest, ENOEXEC, extmemsize(), segheader::flags, segheader::imglength, image::len, imgheader::length, segheader::length, segheader::loadaddr, imgheader::location, segheader::memlength, NBI_HEADER_LENGTH, NBI_LAST_SEGHEADER, NBI_LENGTH, NBI_LOADADDR_ABS, NBI_LOADADDR_AFTER, NBI_LOADADDR_BEFORE, NBI_LOADADDR_END, NBI_LOADADDR_FLAGS, offset, segoff::offset, phys_to_user(), rc, real_to_user(), segoff::segment, and userptr_add().

Referenced by nbi_exec().

◆ nbi_boot16()

static int nbi_boot16 ( struct image image,
struct imgheader imgheader 
)
static

Boot a 16-bit NBI image.

Parameters
imgheaderImage header information
Return values
rcReturn status code, if image returns

Definition at line 242 of file nbi.c.

242  {
243  int discard_D, discard_S, discard_b;
244  int32_t rc;
245 
246  DBGC ( image, "NBI %p executing 16-bit image at %04x:%04x\n", image,
249 
251  REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
252  "pushw %%ds\n\t" /* far pointer to bootp data */
253  "pushw %%bx\n\t"
254  "pushl %%esi\n\t" /* location */
255  "pushw %%cs\n\t" /* lcall execaddr */
256  "call 1f\n\t"
257  "jmp 2f\n\t"
258  "\n1:\n\t"
259  "pushl %%edi\n\t"
260  "lret\n\t"
261  "\n2:\n\t"
262  "addw $8,%%sp\n\t" /* clean up stack */
263  "popl %%ebp\n\t" /* gcc bug */ )
264  : "=a" ( rc ), "=D" ( discard_D ), "=S" ( discard_S ),
265  "=b" ( discard_b )
266  : "D" ( imgheader->execaddr.segoff ),
267  "S" ( imgheader->location ),
268  "b" ( __from_data16 ( basemem_packet ) )
269  : "ecx", "edx" );
270 
271  return rc;
272 }
uint16_t segment
Definition: registers.h:193
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An NBI image header.
Definition: nbi.c:39
void * discard_S
Definition: bigint.h:62
union imgheader::@444 execaddr
#define DBGC(...)
Definition: compiler.h:505
segoff_t segoff
16-bit seg:off entry point
Definition: nbi.c:47
An executable image.
Definition: image.h:24
uint16_t offset
Definition: registers.h:192
#define basemem_packet
segoff_t location
16-bit seg:off header location
Definition: nbi.c:45
__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))
void * discard_D
Definition: bigint.h:31
__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")
signed int int32_t
Definition: stdint.h:17
#define __from_data16(pointer)
Definition: libkir.h:22
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226

References __asm__(), __from_data16, __volatile__(), basemem_packet, DBGC, discard_D, discard_S, imgheader::execaddr, imgheader::location, segoff::offset, rc, REAL_CODE, segoff::segment, and imgheader::segoff.

Referenced by nbi_exec().

◆ nbi_boot32()

static int nbi_boot32 ( struct image image,
struct imgheader imgheader 
)
static

Boot a 32-bit NBI image.

Parameters
imgheaderImage header information
Return values
rcReturn status code, if image returns

Definition at line 280 of file nbi.c.

280  {
281  struct ebinfo loaderinfo = {
283  0
284  };
285  int discard_D, discard_S, discard_b;
286  int32_t rc;
287 
288  DBGC ( image, "NBI %p executing 32-bit image at %lx\n",
290 
291  /* Jump to OS with flat physical addressing */
293  PHYS_CODE ( "pushl %%ebp\n\t" /* gcc bug */
294  "pushl %%ebx\n\t" /* bootp data */
295  "pushl %%esi\n\t" /* imgheader */
296  "pushl %%eax\n\t" /* loaderinfo */
297  "call *%%edi\n\t"
298  "addl $12, %%esp\n\t" /* clean up stack */
299  "popl %%ebp\n\t" /* gcc bug */ )
300  : "=a" ( rc ), "=D" ( discard_D ), "=S" ( discard_S ),
301  "=b" ( discard_b )
302  : "D" ( imgheader->execaddr.linear ),
303  "S" ( ( imgheader->location.segment << 4 ) +
305  "b" ( virt_to_phys ( basemem_packet ) ),
306  "a" ( virt_to_phys ( &loaderinfo ) )
307  : "ecx", "edx", "memory" );
308 
309  return rc;
310 }
uint16_t segment
Definition: registers.h:193
#define PHYS_CODE(asm_code_str)
Definition: librm.h:281
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An NBI image header.
Definition: nbi.c:39
void * discard_S
Definition: bigint.h:62
union imgheader::@444 execaddr
Definition: nbi.c:93
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:361
uint16_t offset
Definition: registers.h:192
#define basemem_packet
segoff_t location
16-bit seg:off header location
Definition: nbi.c:45
__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))
void * discard_D
Definition: bigint.h:31
const int product_major_version
Product major version.
Definition: version.c:64
__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")
signed int int32_t
Definition: stdint.h:17
unsigned long linear
32-bit entry point
Definition: nbi.c:48
const int product_minor_version
Product minor version.
Definition: version.c:67

References __asm__(), __volatile__(), basemem_packet, DBGC, discard_D, discard_S, imgheader::execaddr, imgheader::linear, imgheader::location, segoff::offset, PHYS_CODE, product_major_version, product_minor_version, rc, segoff::segment, and virt_to_phys().

Referenced by nbi_exec().

◆ nbi_prepare_dhcp()

static int nbi_prepare_dhcp ( struct image image)
static

Prepare DHCP parameter block for NBI image.

Parameters
imageNBI image
Return values
rcReturn status code

Definition at line 318 of file nbi.c.

318  {
319  struct net_device *boot_netdev;
320  int rc;
321 
322  boot_netdev = last_opened_netdev();
323  if ( ! boot_netdev ) {
324  DBGC ( image, "NBI %p could not identify a network device\n",
325  image );
326  return -ENODEV;
327  }
328 
329  if ( ( rc = create_fakedhcpack ( boot_netdev, basemem_packet,
330  sizeof ( basemem_packet ) ) ) != 0 ) {
331  DBGC ( image, "NBI %p failed to build DHCP packet\n", image );
332  return rc;
333  }
334 
335  return 0;
336 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int create_fakedhcpack(struct net_device *netdev, void *data, size_t max_len)
Create fake DHCPACK packet.
Definition: fakedhcp.c:136
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:1047
#define basemem_packet
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509

References basemem_packet, create_fakedhcpack(), DBGC, ENODEV, last_opened_netdev(), and rc.

Referenced by nbi_exec().

◆ nbi_exec()

static int nbi_exec ( struct image image)
static

Execute a loaded NBI image.

Parameters
imageNBI image
Return values
rcReturn status code

Definition at line 344 of file nbi.c.

344  {
345  struct imgheader imgheader;
346  int may_return;
347  int rc;
348 
349  /* Retrieve image header */
350  copy_from_user ( &imgheader, image->data, 0, sizeof ( imgheader ) );
351 
352  DBGC ( image, "NBI %p placing header at %hx:%hx\n", image,
354 
355  /* NBI files can have overlaps between segments; the bss of
356  * one segment may overlap the initialised data of another. I
357  * assume this is a design flaw, but there are images out
358  * there that we need to work with. We therefore do two
359  * passes: first to initialise the segments, then to copy the
360  * data. This avoids zeroing out already-copied data.
361  */
362  if ( ( rc = nbi_process_segments ( image, &imgheader,
363  nbi_prepare_segment ) ) != 0 )
364  return rc;
365  if ( ( rc = nbi_process_segments ( image, &imgheader,
366  nbi_load_segment ) ) != 0 )
367  return rc;
368 
369  /* Prepare DHCP option block */
370  if ( ( rc = nbi_prepare_dhcp ( image ) ) != 0 )
371  return rc;
372 
373  /* Shut down now if NBI image will not return */
374  may_return = NBI_PROGRAM_RETURNS ( imgheader.flags );
375  if ( ! may_return )
376  shutdown_boot();
377 
378  /* Execute NBI image */
380  rc = nbi_boot32 ( image, &imgheader );
381  } else {
382  rc = nbi_boot16 ( image, &imgheader );
383  }
384 
385  if ( ! may_return ) {
386  /* Cannot continue after shutdown() called */
387  DBGC ( image, "NBI %p returned %d from non-returnable image\n",
388  image, rc );
389  while ( 1 ) {}
390  }
391 
392  DBGC ( image, "NBI %p returned %d\n", image, rc );
393 
394  return rc;
395 }
uint16_t segment
Definition: registers.h:193
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
An NBI image header.
Definition: nbi.c:39
static int nbi_boot32(struct image *image, struct imgheader *imgheader)
Boot a 32-bit NBI image.
Definition: nbi.c:280
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:411
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
static int nbi_boot16(struct image *image, struct imgheader *imgheader)
Boot a 16-bit NBI image.
Definition: nbi.c:242
#define NBI_PROGRAM_RETURNS(flags)
Definition: nbi.c:61
static int nbi_prepare_dhcp(struct image *image)
Prepare DHCP parameter block for NBI image.
Definition: nbi.c:318
#define NBI_LINEAR_EXEC_ADDR(flags)
Definition: nbi.c:62
uint16_t offset
Definition: registers.h:192
segoff_t location
16-bit seg:off header location
Definition: nbi.c:45
static int nbi_prepare_segment(struct image *image, size_t offset __unused, userptr_t dest, size_t filesz, size_t memsz)
Prepare a segment for an NBI image.
Definition: nbi.c:108
unsigned long flags
Image flags.
Definition: nbi.c:43
static int nbi_load_segment(struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz __unused)
Load a segment for an NBI image.
Definition: nbi.c:131
static int nbi_process_segments(struct image *image, struct imgheader *imgheader, int(*process)(struct image *image, size_t offset, userptr_t dest, size_t filesz, size_t memsz))
Process segments of an NBI image.
Definition: nbi.c:146
static void shutdown_boot(void)
Shut down system for OS boot.
Definition: init.h:76

References copy_from_user(), image::data, DBGC, imgheader::flags, imgheader::location, nbi_boot16(), nbi_boot32(), NBI_LINEAR_EXEC_ADDR, nbi_load_segment(), nbi_prepare_dhcp(), nbi_prepare_segment(), nbi_process_segments(), NBI_PROGRAM_RETURNS, segoff::offset, rc, segoff::segment, and shutdown_boot().

◆ nbi_probe()

static int nbi_probe ( struct image image)
static

Probe NBI image.

Parameters
imageNBI image
Return values
rcReturn status code

Definition at line 403 of file nbi.c.

403  {
404  struct imgheader imgheader;
405 
406  /* If we don't have enough data give up */
407  if ( image->len < NBI_HEADER_LENGTH ) {
408  DBGC ( image, "NBI %p too short for an NBI image\n", image );
409  return -ENOEXEC;
410  }
411 
412  /* Check image header */
413  copy_from_user ( &imgheader, image->data, 0, sizeof ( imgheader ) );
414  if ( imgheader.magic != NBI_MAGIC ) {
415  DBGC ( image, "NBI %p has no NBI signature\n", image );
416  return -ENOEXEC;
417  }
418 
419  return 0;
420 }
unsigned long magic
Magic number (NBI_MAGIC)
Definition: nbi.c:40
userptr_t data
Raw file image.
Definition: image.h:41
An NBI image header.
Definition: nbi.c:39
#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:411
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define NBI_HEADER_LENGTH
NBI header length.
Definition: nbi.c:65
size_t len
Length of raw file image.
Definition: image.h:43
#define NBI_MAGIC
NBI magic number.
Definition: nbi.c:53

References copy_from_user(), image::data, DBGC, ENOEXEC, image::len, imgheader::magic, NBI_HEADER_LENGTH, and NBI_MAGIC.

◆ __image_type()

struct image_type nbi_image_type __image_type ( PROBE_NORMAL  )

NBI image type.