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  * @v cmdline Kernel command line
251  * @ret rc Return status code
252  */
253 static int bzimage_parse_cmdline ( struct image *image,
254  struct bzimage_context *bzimg,
255  const char *cmdline ) {
256  char *vga;
257  char *mem;
258 
259  /* Look for "vga=" */
260  if ( ( vga = strstr ( cmdline, "vga=" ) ) ) {
261  vga += 4;
262  if ( strcmp ( vga, "normal" ) == 0 ) {
263  bzimg->vid_mode = BZI_VID_MODE_NORMAL;
264  } else if ( strcmp ( vga, "ext" ) == 0 ) {
265  bzimg->vid_mode = BZI_VID_MODE_EXT;
266  } else if ( strcmp ( vga, "ask" ) == 0 ) {
267  bzimg->vid_mode = BZI_VID_MODE_ASK;
268  } else {
269  bzimg->vid_mode = strtoul ( vga, &vga, 0 );
270  if ( *vga && ( *vga != ' ' ) ) {
271  DBGC ( image, "bzImage %p strange \"vga=\""
272  "terminator '%c'\n", image, *vga );
273  }
274  }
275  }
276 
277  /* Look for "mem=" */
278  if ( ( mem = strstr ( cmdline, "mem=" ) ) ) {
279  mem += 4;
280  bzimg->mem_limit = strtoul ( mem, &mem, 0 );
281  switch ( *mem ) {
282  case 'G':
283  case 'g':
284  bzimg->mem_limit <<= 10;
285  /* Fall through */
286  case 'M':
287  case 'm':
288  bzimg->mem_limit <<= 10;
289  /* Fall through */
290  case 'K':
291  case 'k':
292  bzimg->mem_limit <<= 10;
293  break;
294  case '\0':
295  case ' ':
296  break;
297  default:
298  DBGC ( image, "bzImage %p strange \"mem=\" "
299  "terminator '%c'\n", image, *mem );
300  break;
301  }
302  bzimg->mem_limit -= 1;
303  }
304 
305  return 0;
306 }
307 
308 /**
309  * Set command line
310  *
311  * @v image bzImage image
312  * @v bzimg bzImage context
313  * @v cmdline Kernel command line
314  */
315 static void bzimage_set_cmdline ( struct image *image,
316  struct bzimage_context *bzimg,
317  const char *cmdline ) {
318  size_t cmdline_len;
319 
320  /* Copy command line down to real-mode portion */
321  cmdline_len = ( strlen ( cmdline ) + 1 );
322  if ( cmdline_len > bzimg->cmdline_size )
323  cmdline_len = bzimg->cmdline_size;
324  copy_to_user ( bzimg->rm_kernel, bzimg->rm_cmdline,
325  cmdline, cmdline_len );
326  DBGC ( image, "bzImage %p command line \"%s\"\n", image, cmdline );
327 }
328 
329 /**
330  * Align initrd length
331  *
332  * @v len Length
333  * @ret len Length rounded up to INITRD_ALIGN
334  */
335 static inline size_t bzimage_align ( size_t len ) {
336 
337  return ( ( len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) );
338 }
339 
340 /**
341  * Load initrd
342  *
343  * @v image bzImage image
344  * @v initrd initrd image
345  * @v address Address at which to load, or UNULL
346  * @ret len Length of loaded image, excluding zero-padding
347  */
348 static size_t bzimage_load_initrd ( struct image *image,
349  struct image *initrd,
350  userptr_t address ) {
351  const char *filename = cpio_name ( initrd );
352  struct cpio_header cpio;
353  size_t offset;
354  size_t pad_len;
355 
356  /* Do not include kernel image itself as an initrd */
357  if ( initrd == image )
358  return 0;
359 
360  /* Create cpio header for non-prebuilt images */
361  offset = cpio_header ( initrd, &cpio );
362 
363  /* Copy in initrd image body (and cpio header if applicable) */
364  if ( address ) {
365  memmove_user ( address, offset, initrd->data, 0, initrd->len );
366  if ( offset ) {
367  memset_user ( address, 0, 0, offset );
368  copy_to_user ( address, 0, &cpio, sizeof ( cpio ) );
369  copy_to_user ( address, sizeof ( cpio ), filename,
370  cpio_name_len ( initrd ) );
371  }
372  DBGC ( image, "bzImage %p initrd %p [%#08lx,%#08lx,%#08lx)"
373  "%s%s\n", image, initrd, user_to_phys ( address, 0 ),
375  user_to_phys ( address, ( offset + initrd->len ) ),
376  ( filename ? " " : "" ), ( filename ? filename : "" ) );
378  user_to_virt ( address, offset ), initrd->len );
379  }
380  offset += initrd->len;
381 
382  /* Zero-pad to next INITRD_ALIGN boundary */
383  pad_len = ( ( -offset ) & ( INITRD_ALIGN - 1 ) );
384  if ( address )
386 
387  return offset;
388 }
389 
390 /**
391  * Check that initrds can be loaded
392  *
393  * @v image bzImage image
394  * @v bzimg bzImage context
395  * @ret rc Return status code
396  */
397 static int bzimage_check_initrds ( struct image *image,
398  struct bzimage_context *bzimg ) {
399  struct image *initrd;
401  size_t len = 0;
402  int rc;
403 
404  /* Calculate total loaded length of initrds */
405  for_each_image ( initrd ) {
406 
407  /* Skip kernel */
408  if ( initrd == image )
409  continue;
410 
411  /* Calculate length */
412  len += bzimage_load_initrd ( image, initrd, UNULL );
413  len = bzimage_align ( len );
414 
415  DBGC ( image, "bzImage %p initrd %p from [%#08lx,%#08lx)%s%s\n",
416  image, initrd, user_to_phys ( initrd->data, 0 ),
417  user_to_phys ( initrd->data, initrd->len ),
418  ( initrd->cmdline ? " " : "" ),
419  ( initrd->cmdline ? initrd->cmdline : "" ) );
420  DBGC2_MD5A ( image, user_to_phys ( initrd->data, 0 ),
421  user_to_virt ( initrd->data, 0 ), initrd->len );
422  }
423 
424  /* Calculate lowest usable address */
425  bottom = userptr_add ( bzimg->pm_kernel, bzimg->pm_sz );
426 
427  /* Check that total length fits within space available for
428  * reshuffling. This is a conservative check, since CPIO
429  * headers are not present during reshuffling, but this
430  * doesn't hurt and keeps the code simple.
431  */
432  if ( ( rc = initrd_reshuffle_check ( len, bottom ) ) != 0 ) {
433  DBGC ( image, "bzImage %p failed reshuffle check: %s\n",
434  image, strerror ( rc ) );
435  return rc;
436  }
437 
438  /* Check that total length fits within kernel's memory limit */
439  if ( user_to_phys ( bottom, len ) > bzimg->mem_limit ) {
440  DBGC ( image, "bzImage %p not enough space for initrds\n",
441  image );
442  return -ENOBUFS;
443  }
444 
445  return 0;
446 }
447 
448 /**
449  * Load initrds, if any
450  *
451  * @v image bzImage image
452  * @v bzimg bzImage context
453  */
454 static void bzimage_load_initrds ( struct image *image,
455  struct bzimage_context *bzimg ) {
456  struct image *initrd;
457  struct image *highest = NULL;
458  struct image *other;
459  userptr_t top;
460  userptr_t dest;
461  size_t offset;
462  size_t len;
463 
464  /* Reshuffle initrds into desired order */
465  initrd_reshuffle ( userptr_add ( bzimg->pm_kernel, bzimg->pm_sz ) );
466 
467  /* Find highest initrd */
468  for_each_image ( initrd ) {
469  if ( ( highest == NULL ) ||
470  ( userptr_sub ( initrd->data, highest->data ) > 0 ) ) {
471  highest = initrd;
472  }
473  }
474 
475  /* Do nothing if there are no initrds */
476  if ( ! highest )
477  return;
478 
479  /* Find highest usable address */
480  top = userptr_add ( highest->data, bzimage_align ( highest->len ) );
481  if ( user_to_phys ( top, -1 ) > bzimg->mem_limit ) {
482  top = phys_to_user ( ( bzimg->mem_limit + 1 ) &
483  ~( INITRD_ALIGN - 1 ) );
484  }
485  DBGC ( image, "bzImage %p loading initrds from %#08lx downwards\n",
486  image, user_to_phys ( top, -1 ) );
487 
488  /* Load initrds in order */
489  for_each_image ( initrd ) {
490 
491  /* Calculate cumulative length of following
492  * initrds (including padding).
493  */
494  offset = 0;
495  for_each_image ( other ) {
496  if ( other == initrd )
497  offset = 0;
498  offset += bzimage_load_initrd ( image, other, UNULL );
500  }
501 
502  /* Load initrd at this address */
503  dest = userptr_add ( top, -offset );
504  len = bzimage_load_initrd ( image, initrd, dest );
505 
506  /* Record initrd location */
507  if ( ! bzimg->ramdisk_image )
508  bzimg->ramdisk_image = user_to_phys ( dest, 0 );
509  bzimg->ramdisk_size = ( user_to_phys ( dest, len ) -
510  bzimg->ramdisk_image );
511  }
512  DBGC ( image, "bzImage %p initrds at [%#08lx,%#08lx)\n",
513  image, bzimg->ramdisk_image,
514  ( bzimg->ramdisk_image + bzimg->ramdisk_size ) );
515 }
516 
517 /**
518  * Execute bzImage image
519  *
520  * @v image bzImage image
521  * @ret rc Return status code
522  */
523 static int bzimage_exec ( struct image *image ) {
524  struct bzimage_context bzimg;
525  const char *cmdline = ( image->cmdline ? image->cmdline : "" );
526  int rc;
527 
528  /* Read and parse header from image */
529  if ( ( rc = bzimage_parse_header ( image, &bzimg,
530  image->data ) ) != 0 )
531  return rc;
532 
533  /* Prepare segments */
534  if ( ( rc = prep_segment ( bzimg.rm_kernel, bzimg.rm_filesz,
535  bzimg.rm_memsz ) ) != 0 ) {
536  DBGC ( image, "bzImage %p could not prepare RM segment: %s\n",
537  image, strerror ( rc ) );
538  return rc;
539  }
540  if ( ( rc = prep_segment ( bzimg.pm_kernel, bzimg.pm_sz,
541  bzimg.pm_sz ) ) != 0 ) {
542  DBGC ( image, "bzImage %p could not prepare PM segment: %s\n",
543  image, strerror ( rc ) );
544  return rc;
545  }
546 
547  /* Parse command line for bootloader parameters */
548  if ( ( rc = bzimage_parse_cmdline ( image, &bzimg, cmdline ) ) != 0)
549  return rc;
550 
551  /* Check that initrds can be loaded */
552  if ( ( rc = bzimage_check_initrds ( image, &bzimg ) ) != 0 )
553  return rc;
554 
555  /* Remove kernel from image list (without invalidating image pointer) */
557 
558  /* Load segments */
559  memcpy_user ( bzimg.rm_kernel, 0, image->data,
560  0, bzimg.rm_filesz );
561  memcpy_user ( bzimg.pm_kernel, 0, image->data,
562  bzimg.rm_filesz, bzimg.pm_sz );
563 
564  /* Store command line */
565  bzimage_set_cmdline ( image, &bzimg, cmdline );
566 
567  /* Prepare for exiting. Must do this before loading initrds,
568  * since loading the initrds will corrupt the external heap.
569  */
570  shutdown_boot();
571 
572  /* Load any initrds */
573  bzimage_load_initrds ( image, &bzimg );
574 
575  /* Update kernel header */
576  bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
577 
578  DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
579  "(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),
580  bzimg.rm_kernel_seg, bzimg.rm_heap );
581 
582  /* Jump to the kernel */
583  __asm__ __volatile__ ( REAL_CODE ( "movw %w0, %%ds\n\t"
584  "movw %w0, %%es\n\t"
585  "movw %w0, %%fs\n\t"
586  "movw %w0, %%gs\n\t"
587  "movw %w0, %%ss\n\t"
588  "movw %w1, %%sp\n\t"
589  "pushw %w2\n\t"
590  "pushw $0\n\t"
591  "lret\n\t" )
592  : : "R" ( bzimg.rm_kernel_seg ),
593  "R" ( bzimg.rm_heap ),
594  "R" ( bzimg.rm_kernel_seg + 0x20 ) );
595 
596  /* There is no way for the image to return, since we provide
597  * no return address.
598  */
599  assert ( 0 );
600 
601  return -ECANCELED; /* -EIMPOSSIBLE */
602 }
603 
604 /**
605  * Probe bzImage image
606  *
607  * @v image bzImage file
608  * @ret rc Return status code
609  */
610 int bzimage_probe ( struct image *image ) {
611  struct bzimage_context bzimg;
612  int rc;
613 
614  /* Read and parse header from image */
615  if ( ( rc = bzimage_parse_header ( image, &bzimg,
616  image->data ) ) != 0 )
617  return rc;
618 
619  return 0;
620 }
621 
622 /** Linux bzImage image type */
623 struct image_type bzimage_image_type __image_type ( PROBE_NORMAL ) = {
624  .name = "bzImage",
625  .probe = bzimage_probe,
626  .exec = bzimage_exec,
627 };
static void bzimage_load_initrds(struct image *image, struct bzimage_context *bzimg)
Load initrds, if any.
Definition: bzimage.c:454
static int bzimage_exec(struct image *image)
Execute bzImage image.
Definition: bzimage.c:523
#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 bzimage_set_cmdline(struct image *image, struct bzimage_context *bzimg, const char *cmdline)
Set command line.
Definition: bzimage.c:315
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:211
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:348
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:610
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.
char * strstr(const char *haystack, const char *needle)
Find substring.
Definition: string.c:309
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 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
#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:397
static void * dest
Definition: strings.h:176
uint16_t heap_end_ptr
Free memory after setup end.
Definition: bzimage.h:60
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
#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:157
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
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.
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:335
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:293
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
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
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
static int bzimage_parse_cmdline(struct image *image, struct bzimage_context *bzimg, const char *cmdline)
Parse kernel command line for bootloader parameters.
Definition: bzimage.c:253
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:362
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:107
static const char * cpio_name(struct image *image)
Get CPIO image name.
Definition: cpio.h:66