iPXE
bzimage.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /**
27  * @file
28  *
29  * Linux bzImage image format
30  *
31  */
32 
33 #include <stdint.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <assert.h>
38 #include <realmode.h>
39 #include <bzimage.h>
40 #include <initrd.h>
41 #include <ipxe/uaccess.h>
42 #include <ipxe/image.h>
43 #include <ipxe/segment.h>
44 #include <ipxe/init.h>
45 #include <ipxe/cpio.h>
46 #include <ipxe/features.h>
47 
49 
50 /**
51  * bzImage context
52  */
54  /** Boot protocol version */
55  unsigned int version;
56  /** Real-mode kernel portion load segment address */
57  unsigned int rm_kernel_seg;
58  /** Real-mode kernel portion load address */
60  /** Real-mode kernel portion file size */
61  size_t rm_filesz;
62  /** Real-mode heap top (offset from rm_kernel) */
63  size_t rm_heap;
64  /** Command line (offset from rm_kernel) */
65  size_t rm_cmdline;
66  /** Command line maximum length */
67  size_t cmdline_size;
68  /** Real-mode kernel portion total memory size */
69  size_t rm_memsz;
70  /** Non-real-mode kernel portion load address */
72  /** Non-real-mode kernel portion file and memory size */
73  size_t pm_sz;
74  /** Video mode */
75  unsigned int vid_mode;
76  /** Memory limit */
78  /** Initrd address */
80  /** Initrd size */
82 
83  /** Command line magic block */
85  /** bzImage header */
87 };
88 
89 /**
90  * Parse bzImage header
91  *
92  * @v image bzImage file
93  * @v bzimg bzImage context
94  * @v src bzImage to parse
95  * @ret rc Return status code
96  */
97 static int bzimage_parse_header ( struct image *image,
98  struct bzimage_context *bzimg,
99  userptr_t src ) {
100  unsigned int syssize;
101  int is_bzimage;
102 
103  /* Sanity check */
104  if ( image->len < ( BZI_HDR_OFFSET + sizeof ( bzimg->bzhdr ) ) ) {
105  DBGC ( image, "bzImage %p too short for kernel header\n",
106  image );
107  return -ENOEXEC;
108  }
109 
110  /* Read in header structures */
111  memset ( bzimg, 0, sizeof ( *bzimg ) );
113  sizeof ( bzimg->cmdline_magic ) );
115  sizeof ( bzimg->bzhdr ) );
116 
117  /* Calculate size of real-mode portion */
118  bzimg->rm_filesz = ( ( ( bzimg->bzhdr.setup_sects ?
119  bzimg->bzhdr.setup_sects : 4 ) + 1 ) << 9 );
120  if ( bzimg->rm_filesz > image->len ) {
121  DBGC ( image, "bzImage %p too short for %zd byte of setup\n",
122  image, bzimg->rm_filesz );
123  return -ENOEXEC;
124  }
125  bzimg->rm_memsz = BZI_ASSUMED_RM_SIZE;
126 
127  /* Calculate size of protected-mode portion */
128  bzimg->pm_sz = ( image->len - bzimg->rm_filesz );
129  syssize = ( ( bzimg->pm_sz + 15 ) / 16 );
130 
131  /* Check for signatures and determine version */
132  if ( bzimg->bzhdr.boot_flag != BZI_BOOT_FLAG ) {
133  DBGC ( image, "bzImage %p missing 55AA signature\n", image );
134  return -ENOEXEC;
135  }
136  if ( bzimg->bzhdr.header == BZI_SIGNATURE ) {
137  /* 2.00+ */
138  bzimg->version = bzimg->bzhdr.version;
139  } else {
140  /* Pre-2.00. Check that the syssize field is correct,
141  * as a guard against accepting arbitrary binary data,
142  * since the 55AA check is pretty lax. Note that the
143  * syssize field is unreliable for protocols between
144  * 2.00 and 2.03 inclusive, so we should not always
145  * check this field.
146  */
147  bzimg->version = 0x0100;
148  if ( bzimg->bzhdr.syssize != syssize ) {
149  DBGC ( image, "bzImage %p bad syssize %x (expected "
150  "%x)\n", image, bzimg->bzhdr.syssize, syssize );
151  return -ENOEXEC;
152  }
153  }
154 
155  /* Determine image type */
156  is_bzimage = ( ( bzimg->version >= 0x0200 ) ?
157  ( bzimg->bzhdr.loadflags & BZI_LOAD_HIGH ) : 0 );
158 
159  /* Calculate load address of real-mode portion */
160  bzimg->rm_kernel_seg = ( is_bzimage ? 0x1000 : 0x9000 );
161  bzimg->rm_kernel = real_to_user ( bzimg->rm_kernel_seg, 0 );
162 
163  /* Allow space for the stack and heap */
164  bzimg->rm_memsz += BZI_STACK_SIZE;
165  bzimg->rm_heap = bzimg->rm_memsz;
166 
167  /* Allow space for the command line */
168  bzimg->rm_cmdline = bzimg->rm_memsz;
169  bzimg->rm_memsz += BZI_CMDLINE_SIZE;
170 
171  /* Calculate load address of protected-mode portion */
172  bzimg->pm_kernel = phys_to_user ( is_bzimage ? BZI_LOAD_HIGH_ADDR
173  : BZI_LOAD_LOW_ADDR );
174 
175  /* Extract video mode */
176  bzimg->vid_mode = bzimg->bzhdr.vid_mode;
177 
178  /* Extract memory limit */
179  bzimg->mem_limit = ( ( bzimg->version >= 0x0203 ) ?
181 
182  /* Extract command line size */
183  bzimg->cmdline_size = ( ( bzimg->version >= 0x0206 ) ?
185 
186  DBGC ( image, "bzImage %p version %04x RM %#lx+%#zx PM %#lx+%#zx "
187  "cmdlen %zd\n", image, bzimg->version,
188  user_to_phys ( bzimg->rm_kernel, 0 ), bzimg->rm_filesz,
189  user_to_phys ( bzimg->pm_kernel, 0 ), bzimg->pm_sz,
190  bzimg->cmdline_size );
191 
192  return 0;
193 }
194 
195 /**
196  * Update bzImage header in loaded kernel
197  *
198  * @v image bzImage file
199  * @v bzimg bzImage context
200  * @v dst bzImage to update
201  */
202 static void bzimage_update_header ( struct image *image,
203  struct bzimage_context *bzimg,
204  userptr_t dst ) {
205 
206  /* Set loader type */
207  if ( bzimg->version >= 0x0200 )
209 
210  /* Set heap end pointer */
211  if ( bzimg->version >= 0x0201 ) {
212  bzimg->bzhdr.heap_end_ptr = ( bzimg->rm_heap - 0x200 );
213  bzimg->bzhdr.loadflags |= BZI_CAN_USE_HEAP;
214  }
215 
216  /* Set command line */
217  if ( bzimg->version >= 0x0202 ) {
218  bzimg->bzhdr.cmd_line_ptr = user_to_phys ( bzimg->rm_kernel,
219  bzimg->rm_cmdline );
220  } else {
222  bzimg->cmdline_magic.offset = bzimg->rm_cmdline;
223  if ( bzimg->version >= 0x0200 )
224  bzimg->bzhdr.setup_move_size = bzimg->rm_memsz;
225  }
226 
227  /* Set video mode */
228  bzimg->bzhdr.vid_mode = bzimg->vid_mode;
229 
230  /* Set initrd address */
231  if ( bzimg->version >= 0x0200 ) {
232  bzimg->bzhdr.ramdisk_image = bzimg->ramdisk_image;
233  bzimg->bzhdr.ramdisk_size = bzimg->ramdisk_size;
234  }
235 
236  /* Write out header structures */
238  sizeof ( bzimg->cmdline_magic ) );
239  copy_to_user ( dst, BZI_HDR_OFFSET, &bzimg->bzhdr,
240  sizeof ( bzimg->bzhdr ) );
241 
242  DBGC ( image, "bzImage %p vidmode %d\n", image, bzimg->vid_mode );
243 }
244 
245 /**
246  * Parse kernel command line for bootloader parameters
247  *
248  * @v image bzImage file
249  * @v bzimg bzImage context
250  * @ret rc Return status code
251  */
252 static int bzimage_parse_cmdline ( struct image *image,
253  struct bzimage_context *bzimg ) {
254  const char *vga;
255  const char *mem;
256  char *sep;
257  char *end;
258 
259  /* Look for "vga=" */
260  if ( ( vga = image_argument ( image, "vga=" ) ) ) {
261  sep = strchr ( vga, ' ' );
262  if ( sep )
263  *sep = '\0';
264  if ( strcmp ( vga, "normal" ) == 0 ) {
265  bzimg->vid_mode = BZI_VID_MODE_NORMAL;
266  } else if ( strcmp ( vga, "ext" ) == 0 ) {
267  bzimg->vid_mode = BZI_VID_MODE_EXT;
268  } else if ( strcmp ( vga, "ask" ) == 0 ) {
269  bzimg->vid_mode = BZI_VID_MODE_ASK;
270  } else {
271  bzimg->vid_mode = strtoul ( vga, &end, 0 );
272  if ( *end ) {
273  DBGC ( image, "bzImage %p strange \"vga=\" "
274  "terminator '%c'\n", image, *end );
275  }
276  }
277  if ( sep )
278  *sep = ' ';
279  }
280 
281  /* Look for "mem=" */
282  if ( ( mem = image_argument ( image, "mem=" ) ) ) {
283  bzimg->mem_limit = strtoul ( mem, &end, 0 );
284  switch ( *end ) {
285  case 'G':
286  case 'g':
287  bzimg->mem_limit <<= 10;
288  /* Fall through */
289  case 'M':
290  case 'm':
291  bzimg->mem_limit <<= 10;
292  /* Fall through */
293  case 'K':
294  case 'k':
295  bzimg->mem_limit <<= 10;
296  break;
297  case '\0':
298  case ' ':
299  break;
300  default:
301  DBGC ( image, "bzImage %p strange \"mem=\" "
302  "terminator '%c'\n", image, *end );
303  break;
304  }
305  bzimg->mem_limit -= 1;
306  }
307 
308  return 0;
309 }
310 
311 /**
312  * Set command line
313  *
314  * @v image bzImage image
315  * @v bzimg bzImage context
316  */
317 static void bzimage_set_cmdline ( struct image *image,
318  struct bzimage_context *bzimg ) {
319  const char *cmdline = ( image->cmdline ? image->cmdline : "" );
320  size_t cmdline_len;
321 
322  /* Copy command line down to real-mode portion */
323  cmdline_len = ( strlen ( cmdline ) + 1 );
324  if ( cmdline_len > bzimg->cmdline_size )
325  cmdline_len = bzimg->cmdline_size;
326  copy_to_user ( bzimg->rm_kernel, bzimg->rm_cmdline,
327  cmdline, cmdline_len );
328  DBGC ( image, "bzImage %p command line \"%s\"\n", image, cmdline );
329 }
330 
331 /**
332  * Align initrd length
333  *
334  * @v len Length
335  * @ret len Length rounded up to INITRD_ALIGN
336  */
337 static inline size_t bzimage_align ( size_t len ) {
338 
339  return ( ( len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) );
340 }
341 
342 /**
343  * Load initrd
344  *
345  * @v image bzImage image
346  * @v initrd initrd image
347  * @v address Address at which to load, or UNULL
348  * @ret len Length of loaded image, excluding zero-padding
349  */
350 static size_t bzimage_load_initrd ( struct image *image,
351  struct image *initrd,
352  userptr_t address ) {
353  const char *filename = cpio_name ( initrd );
354  struct cpio_header cpio;
355  size_t offset;
356  size_t pad_len;
357 
358  /* Skip hidden images */
359  if ( initrd->flags & IMAGE_HIDDEN )
360  return 0;
361 
362  /* Create cpio header for non-prebuilt images */
363  offset = cpio_header ( initrd, &cpio );
364 
365  /* Copy in initrd image body (and cpio header if applicable) */
366  if ( address ) {
367  memmove_user ( address, offset, initrd->data, 0, initrd->len );
368  if ( offset ) {
369  memset_user ( address, 0, 0, offset );
370  copy_to_user ( address, 0, &cpio, sizeof ( cpio ) );
371  copy_to_user ( address, sizeof ( cpio ), filename,
372  cpio_name_len ( initrd ) );
373  }
374  DBGC ( image, "bzImage %p initrd %p [%#08lx,%#08lx,%#08lx)"
375  "%s%s\n", image, initrd, user_to_phys ( address, 0 ),
377  user_to_phys ( address, ( offset + initrd->len ) ),
378  ( filename ? " " : "" ), ( filename ? filename : "" ) );
380  user_to_virt ( address, offset ), initrd->len );
381  }
382  offset += initrd->len;
383 
384  /* Zero-pad to next INITRD_ALIGN boundary */
385  pad_len = ( ( -offset ) & ( INITRD_ALIGN - 1 ) );
386  if ( address )
388 
389  return offset;
390 }
391 
392 /**
393  * Check that initrds can be loaded
394  *
395  * @v image bzImage image
396  * @v bzimg bzImage context
397  * @ret rc Return status code
398  */
399 static int bzimage_check_initrds ( struct image *image,
400  struct bzimage_context *bzimg ) {
401  struct image *initrd;
403  size_t len = 0;
404  int rc;
405 
406  /* Calculate total loaded length of initrds */
407  for_each_image ( initrd ) {
408 
409  /* Calculate length */
410  len += bzimage_load_initrd ( image, initrd, UNULL );
411  len = bzimage_align ( len );
412 
413  DBGC ( image, "bzImage %p initrd %p from [%#08lx,%#08lx)%s%s\n",
414  image, initrd, user_to_phys ( initrd->data, 0 ),
415  user_to_phys ( initrd->data, initrd->len ),
416  ( initrd->cmdline ? " " : "" ),
417  ( initrd->cmdline ? initrd->cmdline : "" ) );
418  DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ),
419  user_to_virt ( initrd->data, 0 ), initrd->len );
420  }
421 
422  /* Calculate lowest usable address */
423  bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz );
424 
425  /* Check that total length fits within space available for
426  * reshuffling. This is a conservative check, since CPIO
427  * headers are not present during reshuffling, but this
428  * doesn't hurt and keeps the code simple.
429  */
430  if ( ( rc = initrd_reshuffle_check ( len, bottom ) ) != 0 ) {
431  DBGC ( image, "bzImage %p failed reshuffle check: %s\n",
432  image, strerror ( rc ) );
433  return rc;
434  }
435 
436  /* Check that total length fits within kernel's memory limit */
437  if ( user_to_phys ( bottom, len ) > bzimg->mem_limit ) {
438  DBGC ( image, "bzImage %p not enough space for initrds\n",
439  image );
440  return -ENOBUFS;
441  }
442 
443  return 0;
444 }
445 
446 /**
447  * Load initrds, if any
448  *
449  * @v image bzImage image
450  * @v bzimg bzImage context
451  */
452 static void bzimage_load_initrds ( struct image *image,
453  struct bzimage_context *bzimg ) {
454  struct image *initrd;
455  struct image *highest = NULL;
456  struct image *other;
457  userptr_t top;
458  userptr_t dest;
459  size_t offset;
460  size_t len;
461 
462  /* Reshuffle initrds into desired order */
463  initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) );
464 
465  /* Find highest initrd */
466  for_each_image ( initrd ) {
467  if ( ( highest == NULL ) ||
468  ( userptr_sub ( initrd->data, highest->data ) > 0 ) ) {
469  highest = initrd;
470  }
471  }
472 
473  /* Do nothing if there are no initrds */
474  if ( ! highest )
475  return;
476 
477  /* Find highest usable address */
478  top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
479  if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
480  top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
481  ~( INITRD_ALIGN - 1 ) );
482  }
483  DBGC ( image, "bzImage %p loading initrds from %#08lx downwards\n",
484  image, user_to_phys ( top, -1 ) );
485 
486  /* Load initrds in order */
487  for_each_image ( initrd ) {
488 
489  /* Calculate cumulative length of following
490  * initrds (including padding).
491  */
492  offset = 0;
493  for_each_image ( other ) {
494  if ( other == initrd )
495  offset = 0;
496  offset += bzimage_load_initrd ( image, other, UNULL );
498  }
499 
500  /* Load initrd at this address */
501  dest = userptr_add ( top, -offset );
502  len = bzimage_load_initrd ( image, initrd, dest );
503 
504  /* Record initrd location */
505  if ( ! bzimg->ramdisk_image )
506  bzimg->ramdisk_image = user_to_phys ( dest, 0 );
507  bzimg->ramdisk_size = ( user_to_phys ( dest, len ) -
508  bzimg->ramdisk_image );
509  }
510  DBGC ( image, "bzImage %p initrds at [%#08lx,%#08lx)\n",
511  image, bzimg->ramdisk_image,
512  ( bzimg->ramdisk_image + bzimg->ramdisk_size ) );
513 }
514 
515 /**
516  * Execute bzImage image
517  *
518  * @v image bzImage image
519  * @ret rc Return status code
520  */
521 static int bzimage_exec ( struct image *image ) {
522  struct bzimage_context bzimg;
523  int rc;
524 
525  /* Read and parse header from image */
526  if ( ( rc = bzimage_parse_header ( image, &bzimg,
527  image->data ) ) != 0 )
528  return rc;
529 
530  /* Prepare segments */
531  if ( ( rc = prep_segment ( bzimg.rm_kernel, bzimg.rm_filesz,
532  bzimg.rm_memsz ) ) != 0 ) {
533  DBGC ( image, "bzImage %p could not prepare RM segment: %s\n",
534  image, strerror ( rc ) );
535  return rc;
536  }
537  if ( ( rc = prep_segment ( bzimg.pm_kernel, bzimg.pm_sz,
538  bzimg.pm_sz ) ) != 0 ) {
539  DBGC ( image, "bzImage %p could not prepare PM segment: %s\n",
540  image, strerror ( rc ) );
541  return rc;
542  }
543 
544  /* Parse command line for bootloader parameters */
545  if ( ( rc = bzimage_parse_cmdline ( image, &bzimg ) ) != 0)
546  return rc;
547 
548  /* Check that initrds can be loaded */
549  if ( ( rc = bzimage_check_initrds ( image, &bzimg ) ) != 0 )
550  return rc;
551 
552  /* Remove kernel from image list (without invalidating image pointer) */
554 
555  /* Load segments */
556  memcpy_user ( bzimg.rm_kernel, 0, image->data,
557  0, bzimg.rm_filesz );
558  memcpy_user ( bzimg.pm_kernel, 0, image->data,
559  bzimg.rm_filesz, bzimg.pm_sz );
560 
561  /* Store command line */
562  bzimage_set_cmdline ( image, &bzimg );
563 
564  /* Prepare for exiting. Must do this before loading initrds,
565  * since loading the initrds will corrupt the external heap.
566  */
567  shutdown_boot();
568 
569  /* Load any initrds */
570  bzimage_load_initrds ( image, &bzimg );
571 
572  /* Update kernel header */
573  bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
574 
575  DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
576  "(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),
577  bzimg.rm_kernel_seg, bzimg.rm_heap );
578 
579  /* Jump to the kernel */
580  __asm__ __volatile__ ( REAL_CODE ( "movw %w0, %%ds\n\t"
581  "movw %w0, %%es\n\t"
582  "movw %w0, %%fs\n\t"
583  "movw %w0, %%gs\n\t"
584  "movw %w0, %%ss\n\t"
585  "movw %w1, %%sp\n\t"
586  "pushw %w2\n\t"
587  "pushw $0\n\t"
588  "lret\n\t" )
589  : : "R" ( bzimg.rm_kernel_seg ),
590  "R" ( bzimg.rm_heap ),
591  "R" ( bzimg.rm_kernel_seg + 0x20 ) );
592 
593  /* There is no way for the image to return, since we provide
594  * no return address.
595  */
596  assert ( 0 );
597 
598  return -ECANCELED; /* -EIMPOSSIBLE */
599 }
600 
601 /**
602  * Probe bzImage image
603  *
604  * @v image bzImage file
605  * @ret rc Return status code
606  */
607 int bzimage_probe ( struct image *image ) {
608  struct bzimage_context bzimg;
609  int rc;
610 
611  /* Read and parse header from image */
612  if ( ( rc = bzimage_parse_header ( image, &bzimg,
613  image->data ) ) != 0 )
614  return rc;
615 
616  return 0;
617 }
618 
619 /** Linux bzImage image type */
620 struct image_type bzimage_image_type __image_type ( PROBE_NORMAL ) = {
621  .name = "bzImage",
622  .probe = bzimage_probe,
623  .exec = bzimage_exec,
624 };
static void bzimage_load_initrds(struct image *image, struct bzimage_context *bzimg)
Load initrds, if any.
Definition: bzimage.c:452
static int bzimage_exec(struct image *image)
Execute bzImage image.
Definition: bzimage.c:521
unsigned int flags
Flags.
Definition: image.h:36
#define BZI_CMDLINE_MAGIC
bzImage command line present magic marker value
Definition: bzimage.h:131
size_t cpio_name_len(struct image *image)
Get CPIO image filename.
Definition: cpio.c:56
FEATURE(FEATURE_IMAGE, "bzImage", DHCP_EB_FEATURE_BZIMAGE, 1)
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
size_t rm_heap
Real-mode heap top (offset from rm_kernel)
Definition: bzimage.c:63
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:471
A CPIO archive header.
Definition: cpio.h:19
#define BZI_CMDLINE_SIZE
Maximum size of command line.
Definition: bzimage.h:140
Error codes.
physaddr_t ramdisk_size
Initrd size.
Definition: bzimage.c:81
static void const void void * dst
Definition: crypto.h:244
uint64_t address
Base address.
Definition: ena.h:24
#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
size_t rm_cmdline
Command line (offset from rm_kernel)
Definition: bzimage.c:65
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition: image.h:218
static void const void * src
Definition: crypto.h:244
size_t rm_filesz
Real-mode kernel portion file size.
Definition: bzimage.c:61
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 type.
Definition: image.h:76
size_t rm_memsz
Real-mode kernel portion total memory size.
Definition: bzimage.c:69
void initrd_reshuffle(userptr_t bottom)
Reshuffle initrds into desired order at top of memory.
Definition: initrd.c:230
#define PROBE_NORMAL
Normal image probe priority.
Definition: image.h:137
unsigned long long uint64_t
Definition: stdint.h:13
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
static size_t bzimage_load_initrd(struct image *image, struct image *initrd, userptr_t address)
Load initrd.
Definition: bzimage.c:350
static userptr_t bottom
Bottom of heap (current lowest allocated block)
An executable image.
Definition: image.h:24
#define FEATURE_IMAGE
Image formats.
Definition: features.h:22
#define BZI_CMDLINE_OFFSET
Offset of bzImage command-line structure within kernel image.
Definition: bzimage.h:128
#define DBGC2_MD5A(...)
Definition: compiler.h:525
int bzimage_probe(struct image *image)
Probe bzImage image.
Definition: bzimage.c:607
Access to external ("user") memory.
#define ECANCELED
Operation canceled.
Definition: errno.h:343
char * name
Name of this image type.
Definition: image.h:78
CPIO archives.
char * cmdline
Command line to pass to image.
Definition: image.h:39
#define BZI_VID_MODE_ASK
bzImage special video mode "ask"
Definition: bzimage.h:114
#define DHCP_EB_FEATURE_BZIMAGE
bzImage format
Definition: features.h:44
off_t userptr_sub(userptr_t userptr, userptr_t subtrahend)
Subtract user pointers.
Executable image segments.
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
uint32_t ramdisk_size
initrd size (set by boot loader)
Definition: bzimage.h:56
uint16_t version
Boot protocol version supported.
Definition: bzimage.h:38
#define BZI_SIGNATURE
bzImage magic signature value
Definition: bzimage.h:84
userptr_t userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
#define BZI_LOAD_HIGH_ADDR
Load address for high-loaded kernels.
Definition: bzimage.h:99
#define BZI_CAN_USE_HEAP
bzImage "kernel can use heap" flag
Definition: bzimage.h:105
physaddr_t ramdisk_image
Initrd address.
Definition: bzimage.c:79
#define BZI_LOAD_LOW_ADDR
Load address for low-loaded kernels.
Definition: bzimage.h:102
uint32_t initrd_addr_max
Highest legal initrd address.
Definition: bzimage.h:66
Assertions.
uint32_t ramdisk_image
initrd load address (set by boot loader)
Definition: bzimage.h:54
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int prep_segment(userptr_t segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition: segment.c:60
Executable images.
static int bzimage_parse_header(struct image *image, struct bzimage_context *bzimg, userptr_t src)
Parse bzImage header.
Definition: bzimage.c:97
userptr_t pm_kernel
Non-real-mode kernel portion load address.
Definition: bzimage.c:71
unsigned int rm_kernel_seg
Real-mode kernel portion load segment address.
Definition: bzimage.c:57
static int bzimage_parse_cmdline(struct image *image, struct bzimage_context *bzimg)
Parse kernel command line for bootloader parameters.
Definition: bzimage.c:252
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define BZI_STACK_SIZE
Amount of stack space to provide.
Definition: bzimage.h:137
static void bzimage_set_cmdline(struct image *image, struct bzimage_context *bzimg)
Set command line.
Definition: bzimage.c:317
#define BZI_LOADER_TYPE_IPXE
bzImage boot loader identifier for iPXE
Definition: bzimage.h:93
Feature list.
size_t cmdline_size
Command line maximum length.
Definition: bzimage.c:67
#define BZI_HDR_OFFSET
Offset of bzImage header within kernel image.
Definition: bzimage.h:78
struct bzimage_header bzhdr
bzImage header
Definition: bzimage.c:86
static int bzimage_check_initrds(struct image *image, struct bzimage_context *bzimg)
Check that initrds can be loaded.
Definition: bzimage.c:399
static void * dest
Definition: strings.h:176
uint16_t heap_end_ptr
Free memory after setup end.
Definition: bzimage.h:60
#define BZI_BOOT_FLAG
bzImage boot flag value
Definition: bzimage.h:81
struct image_type bzimage_image_type __image_type(PROBE_NORMAL)
Linux bzImage image type.
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:172
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint8_t type_of_loader
Boot loader identifier.
Definition: bzimage.h:46
uint16_t syssize
DO NOT USE - for bootsect.S use only.
Definition: bzimage.h:22
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
size_t len
Length of raw file image.
Definition: image.h:43
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
static void bzimage_update_header(struct image *image, struct bzimage_context *bzimg, userptr_t dst)
Update bzImage header in loaded kernel.
Definition: bzimage.c:202
static userptr_t top
Top of heap.
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition: image.h:73
static __always_inline void copy_to_user(userptr_t dest, off_t dest_off, const void *src, size_t len)
Copy data to user buffer.
Definition: uaccess.h:324
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
#define BZI_VID_MODE_EXT
bzImage special video mode "ext"
Definition: bzimage.h:111
uint16_t setup_move_size
Move to high memory size (used with hooks)
Definition: bzimage.h:50
uint32_t cmdline_size
Maximum size of the kernel command line.
Definition: bzimage.h:74
uint16_t magic
Magic signature.
Definition: bzimage.h:122
uint32_t cmd_line_ptr
32-bit pointer to the kernel command line
Definition: bzimage.h:64
bzImage context
Definition: bzimage.c:53
#define BZI_INITRD_MAX
bzImage maximum initrd address for versions < 2.03
Definition: bzimage.h:117
static size_t bzimage_align(size_t len)
Align initrd length.
Definition: bzimage.c:337
unsigned long physaddr_t
Definition: stdint.h:20
uint32_t header
Magic signature "HdrS".
Definition: bzimage.h:36
long pad_len
Definition: bigint.h:30
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:300
Initial ramdisk (initrd) reshuffling.
#define INITRD_ALIGN
Alignment for CPIO archives within an initrd.
Definition: cpio.h:57
__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 UNULL
Equivalent of NULL for user pointers.
Definition: uaccess.h:36
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
unsigned int vid_mode
Video mode.
Definition: bzimage.c:75
uint16_t offset
Offset to command line.
Definition: bzimage.h:124
userptr_t rm_kernel
Real-mode kernel portion load address.
Definition: bzimage.c:59
int initrd_reshuffle_check(size_t len, userptr_t bottom)
Check that there is enough space to reshuffle initrds.
Definition: initrd.c:267
const char * image_argument(struct image *image, const char *key)
Find argument within image command line.
Definition: image.c:590
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint16_t syssize
DO NOT USE - for bootsect.S use only.
Definition: bzimage.h:13
size_t pm_sz
Non-real-mode kernel portion file and memory size.
Definition: bzimage.c:73
#define BZI_ASSUMED_RM_SIZE
Assumed size of real-mode portion (including .bss)
Definition: bzimage.h:134
void memmove_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers, allowing for overlap.
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
struct bzimage_cmdline cmdline_magic
Command line magic block.
Definition: bzimage.c:84
#define BZI_LOAD_HIGH
bzImage "load high" flag
Definition: bzimage.h:96
#define BZI_VID_MODE_NORMAL
bzImage special video mode "normal"
Definition: bzimage.h:108
bzImage command-line structure used by older kernels
Definition: bzimage.h:120
uint32_t cmdline
Definition: multiboot.h:16
unsigned int version
Boot protocol version.
Definition: bzimage.c:55
static void shutdown_boot(void)
Shut down system for OS boot.
Definition: init.h:76
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
uint16_t vid_mode
Video mode control.
Definition: bzimage.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t loadflags
Boot protocol option flags.
Definition: bzimage.h:48
String functions.
uint8_t setup_sects
The size of the setup in sectors.
Definition: bzimage.h:18
A bzImage header.
Definition: bzimage.h:13
uint64_t mem_limit
Memory limit.
Definition: bzimage.c:77
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
uint16_t boot_flag
0xAA55 magic number
Definition: bzimage.h:32
void * memset(void *dest, int character, size_t len) __nonnull
size_t cpio_header(struct image *image, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
Definition: cpio.c:102
static const char * cpio_name(struct image *image)
Get CPIO image name.
Definition: cpio.h:66