iPXE
bzimage.c File Reference

Linux bzImage image format. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <bzimage.h>
#include <ipxe/initrd.h>
#include <ipxe/uaccess.h>
#include <ipxe/image.h>
#include <ipxe/segment.h>
#include <ipxe/init.h>
#include <ipxe/cpio.h>
#include <ipxe/features.h>

Go to the source code of this file.

Data Structures

struct  bzimage_context
 bzImage context More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_IMAGE, "bzImage", DHCP_EB_FEATURE_BZIMAGE, 1)
static int bzimage_parse_header (struct image *image, struct bzimage_context *bzimg)
 Parse bzImage header.
static void bzimage_update_header (struct image *image, struct bzimage_context *bzimg)
 Update bzImage header in loaded kernel.
static int bzimage_parse_cmdline (struct image *image, struct bzimage_context *bzimg)
 Parse kernel command line for bootloader parameters.
static void bzimage_set_cmdline (struct image *image, struct bzimage_context *bzimg)
 Set command line.
static int bzimage_check_initrds (struct image *image, struct bzimage_context *bzimg)
 Check that initrds can be loaded.
static void bzimage_load_initrds (struct image *image, struct bzimage_context *bzimg)
 Load initrds, if any.
static int bzimage_exec (struct image *image)
 Execute bzImage image.
int bzimage_probe (struct image *image)
 Probe bzImage image.
struct image_type bzimage_image_type __image_type (PROBE_NORMAL)
 Linux bzImage image type.

Detailed Description

Linux bzImage image format.

Definition in file bzimage.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FEATURE()

FEATURE ( FEATURE_IMAGE ,
"bzImage" ,
DHCP_EB_FEATURE_BZIMAGE ,
1  )

◆ bzimage_parse_header()

int bzimage_parse_header ( struct image * image,
struct bzimage_context * bzimg )
static

Parse bzImage header.

Parameters
imagebzImage file
bzimgbzImage context
Return values
rcReturn status code

Definition at line 92 of file bzimage.c.

93 {
94 const struct bzimage_header *bzhdr;
95 unsigned int syssize;
96 int is_bzimage;
97
98 /* Initialise context */
99 memset ( bzimg, 0, sizeof ( *bzimg ) );
100
101 /* Sanity check */
102 if ( image->len < ( BZI_HDR_OFFSET + sizeof ( *bzhdr ) ) ) {
103 DBGC ( image, "bzImage %s too short for kernel header\n",
104 image->name );
105 return -ENOEXEC;
106 }
107 bzhdr = ( image->data + BZI_HDR_OFFSET );
108
109 /* Calculate size of real-mode portion */
110 bzimg->rm_filesz = ( ( ( bzhdr->setup_sects ?
111 bzhdr->setup_sects : 4 ) + 1 ) << 9 );
112 if ( bzimg->rm_filesz > image->len ) {
113 DBGC ( image, "bzImage %s too short for %zd byte of setup\n",
114 image->name, bzimg->rm_filesz );
115 return -ENOEXEC;
116 }
118
119 /* Calculate size of protected-mode portion */
120 bzimg->pm_sz = ( image->len - bzimg->rm_filesz );
121 syssize = ( ( bzimg->pm_sz + 15 ) / 16 );
122
123 /* Check for signatures and determine version */
124 if ( bzhdr->boot_flag != BZI_BOOT_FLAG ) {
125 DBGC ( image, "bzImage %s missing 55AA signature\n",
126 image->name );
127 return -ENOEXEC;
128 }
129 if ( bzhdr->header == BZI_SIGNATURE ) {
130 /* 2.00+ */
131 bzimg->version = bzhdr->version;
132 } else {
133 /* Pre-2.00. Check that the syssize field is correct,
134 * as a guard against accepting arbitrary binary data,
135 * since the 55AA check is pretty lax. Note that the
136 * syssize field is unreliable for protocols between
137 * 2.00 and 2.03 inclusive, so we should not always
138 * check this field.
139 */
140 bzimg->version = 0x0100;
141 if ( bzhdr->syssize != syssize ) {
142 DBGC ( image, "bzImage %s bad syssize %x (expected "
143 "%x)\n", image->name, bzhdr->syssize,
144 syssize );
145 return -ENOEXEC;
146 }
147 }
148
149 /* Determine image type */
150 is_bzimage = ( ( bzimg->version >= 0x0200 ) ?
151 ( bzhdr->loadflags & BZI_LOAD_HIGH ) : 0 );
152
153 /* Calculate load address of real-mode portion */
154 bzimg->rm_kernel_seg = ( is_bzimage ? 0x1000 : 0x9000 );
155 bzimg->rm_kernel = real_to_virt ( bzimg->rm_kernel_seg, 0 );
156
157 /* Allow space for the stack and heap */
158 bzimg->rm_memsz += BZI_STACK_SIZE;
159 bzimg->rm_heap = bzimg->rm_memsz;
160
161 /* Allow space for the command line */
162 bzimg->rm_cmdline = bzimg->rm_memsz;
163 bzimg->rm_memsz += BZI_CMDLINE_SIZE;
164
165 /* Calculate load address of protected-mode portion */
166 bzimg->pm_kernel = phys_to_virt ( is_bzimage ? BZI_LOAD_HIGH_ADDR
168
169 /* Extract video mode */
170 bzimg->vid_mode = bzhdr->vid_mode;
171
172 /* Extract memory limit */
173 bzimg->mem_limit = ( ( bzimg->version >= 0x0203 ) ?
175
176 /* Extract command line size */
177 bzimg->cmdline_size = ( ( bzimg->version >= 0x0206 ) ?
179
180 DBGC ( image, "bzImage %s version %04x RM %#lx+%#zx PM %#lx+%#zx "
181 "cmdlen %zd\n", image->name, bzimg->version,
182 virt_to_phys ( bzimg->rm_kernel ), bzimg->rm_filesz,
183 virt_to_phys ( bzimg->pm_kernel ), bzimg->pm_sz,
184 bzimg->cmdline_size );
185
186 return 0;
187}
#define BZI_CMDLINE_SIZE
Maximum size of command line.
Definition bzimage.h:140
#define BZI_LOAD_HIGH
bzImage "load high" flag
Definition bzimage.h:96
#define BZI_INITRD_MAX
bzImage maximum initrd address for versions < 2.03
Definition bzimage.h:117
#define BZI_BOOT_FLAG
bzImage boot flag value
Definition bzimage.h:81
#define BZI_LOAD_HIGH_ADDR
Load address for high-loaded kernels.
Definition bzimage.h:99
#define BZI_ASSUMED_RM_SIZE
Assumed size of real-mode portion (including .bss)
Definition bzimage.h:134
uint16_t syssize
DO NOT USE - for bootsect.S use only.
Definition bzimage.h:8
#define BZI_LOAD_LOW_ADDR
Load address for low-loaded kernels.
Definition bzimage.h:102
#define BZI_SIGNATURE
bzImage magic signature value
Definition bzimage.h:84
#define BZI_HDR_OFFSET
Offset of bzImage header within kernel image.
Definition bzimage.h:78
#define BZI_STACK_SIZE
Amount of stack space to provide.
Definition bzimage.h:137
#define DBGC(...)
Definition compiler.h:505
#define ENOEXEC
Exec format error.
Definition errno.h:520
void * memset(void *dest, int character, size_t len) __nonnull
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition realmode.h:77
size_t rm_cmdline
Command line (offset from rm_kernel)
Definition bzimage.c:66
size_t cmdline_size
Command line maximum length.
Definition bzimage.c:68
void * pm_kernel
Non-real-mode kernel portion load address.
Definition bzimage.c:72
size_t rm_filesz
Real-mode kernel portion file size.
Definition bzimage.c:62
uint64_t mem_limit
Memory limit.
Definition bzimage.c:78
size_t pm_sz
Non-real-mode kernel portion file and memory size.
Definition bzimage.c:74
size_t rm_heap
Real-mode heap top (offset from rm_kernel)
Definition bzimage.c:64
unsigned int rm_kernel_seg
Real-mode kernel portion load segment address.
Definition bzimage.c:58
void * rm_kernel
Real-mode kernel portion load address.
Definition bzimage.c:60
size_t rm_memsz
Real-mode kernel portion total memory size.
Definition bzimage.c:70
unsigned int version
Boot protocol version.
Definition bzimage.c:56
unsigned int vid_mode
Video mode.
Definition bzimage.c:76
A bzImage header.
Definition bzimage.h:13
uint32_t initrd_addr_max
Highest legal initrd address.
Definition bzimage.h:66
uint16_t syssize
DO NOT USE - for bootsect.S use only.
Definition bzimage.h:22
uint16_t version
Boot protocol version supported.
Definition bzimage.h:38
uint8_t setup_sects
The size of the setup in sectors.
Definition bzimage.h:18
uint32_t header
Magic signature "HdrS".
Definition bzimage.h:36
uint16_t boot_flag
0xAA55 magic number
Definition bzimage.h:32
uint32_t cmdline_size
Maximum size of the kernel command line.
Definition bzimage.h:74
uint8_t loadflags
Boot protocol option flags.
Definition bzimage.h:48
uint16_t vid_mode
Video mode control.
Definition bzimage.h:28
An executable image.
Definition image.h:24
const void * data
Read-only data.
Definition image.h:51
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56

References bzimage_header::boot_flag, BZI_ASSUMED_RM_SIZE, BZI_BOOT_FLAG, BZI_CMDLINE_SIZE, BZI_HDR_OFFSET, BZI_INITRD_MAX, BZI_LOAD_HIGH, BZI_LOAD_HIGH_ADDR, BZI_LOAD_LOW_ADDR, BZI_SIGNATURE, BZI_STACK_SIZE, bzimage_context::cmdline_size, bzimage_header::cmdline_size, image::data, DBGC, ENOEXEC, bzimage_header::header, bzimage_header::initrd_addr_max, image::len, bzimage_header::loadflags, bzimage_context::mem_limit, memset(), image::name, bzimage_context::pm_kernel, bzimage_context::pm_sz, real_to_virt(), bzimage_context::rm_cmdline, bzimage_context::rm_filesz, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_kernel_seg, bzimage_context::rm_memsz, bzimage_header::setup_sects, bzimage_header::syssize, syssize, bzimage_context::version, bzimage_header::version, bzimage_context::vid_mode, and bzimage_header::vid_mode.

Referenced by bzimage_exec(), and bzimage_probe().

◆ bzimage_update_header()

void bzimage_update_header ( struct image * image,
struct bzimage_context * bzimg )
static

Update bzImage header in loaded kernel.

Parameters
imagebzImage file
bzimgbzImage context

Definition at line 195 of file bzimage.c.

196 {
197 struct bzimage_header *bzhdr = ( bzimg->rm_kernel + BZI_HDR_OFFSET );
198 struct bzimage_cmdline *cmdline;
199
200 /* Set loader type */
201 if ( bzimg->version >= 0x0200 )
203
204 /* Set heap end pointer */
205 if ( bzimg->version >= 0x0201 ) {
206 bzhdr->heap_end_ptr = ( bzimg->rm_heap - 0x200 );
207 bzhdr->loadflags |= BZI_CAN_USE_HEAP;
208 }
209
210 /* Set command line */
211 if ( bzimg->version >= 0x0202 ) {
212 bzhdr->cmd_line_ptr = ( virt_to_phys ( bzimg->rm_kernel )
213 + bzimg->rm_cmdline );
214 } else {
215 cmdline = ( bzimg->rm_kernel + BZI_CMDLINE_OFFSET );
216 cmdline->magic = BZI_CMDLINE_MAGIC;
217 cmdline->offset = bzimg->rm_cmdline;
218 if ( bzimg->version >= 0x0200 )
219 bzhdr->setup_move_size = bzimg->rm_memsz;
220 }
221
222 /* Set video mode */
223 bzhdr->vid_mode = bzimg->vid_mode;
224 DBGC ( image, "bzImage %s vidmode %d\n",
225 image->name, bzhdr->vid_mode );
226
227 /* Set initrd address */
228 if ( bzimg->version >= 0x0200 ) {
229 bzhdr->ramdisk_image = virt_to_phys ( bzimg->initrd );
230 bzhdr->ramdisk_size = bzimg->initrd_size;
231 }
232}
#define BZI_LOADER_TYPE_IPXE
bzImage boot loader identifier for iPXE
Definition bzimage.h:93
#define BZI_CMDLINE_MAGIC
bzImage command line present magic marker value
Definition bzimage.h:131
#define BZI_CMDLINE_OFFSET
Offset of bzImage command-line structure within kernel image.
Definition bzimage.h:128
#define BZI_CAN_USE_HEAP
bzImage "kernel can use heap" flag
Definition bzimage.h:105
uint32_t cmdline
Definition multiboot.h:4
bzImage command-line structure used by older kernels
Definition bzimage.h:120
physaddr_t initrd_size
Initrd size.
Definition bzimage.c:82
void * initrd
Initrd address.
Definition bzimage.c:80
uint16_t setup_move_size
Move to high memory size (used with hooks)
Definition bzimage.h:50
uint8_t type_of_loader
Boot loader identifier.
Definition bzimage.h:46
uint32_t ramdisk_image
initrd load address (set by boot loader)
Definition bzimage.h:54
uint32_t cmd_line_ptr
32-bit pointer to the kernel command line
Definition bzimage.h:64
uint32_t ramdisk_size
initrd size (set by boot loader)
Definition bzimage.h:56
uint16_t heap_end_ptr
Free memory after setup end.
Definition bzimage.h:60

References BZI_CAN_USE_HEAP, BZI_CMDLINE_MAGIC, BZI_CMDLINE_OFFSET, BZI_HDR_OFFSET, BZI_LOADER_TYPE_IPXE, bzimage_header::cmd_line_ptr, cmdline, DBGC, bzimage_header::heap_end_ptr, bzimage_context::initrd, bzimage_context::initrd_size, bzimage_header::loadflags, image::name, bzimage_header::ramdisk_image, bzimage_header::ramdisk_size, bzimage_context::rm_cmdline, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_memsz, bzimage_header::setup_move_size, bzimage_header::type_of_loader, bzimage_context::version, bzimage_context::vid_mode, and bzimage_header::vid_mode.

Referenced by bzimage_exec().

◆ bzimage_parse_cmdline()

int bzimage_parse_cmdline ( struct image * image,
struct bzimage_context * bzimg )
static

Parse kernel command line for bootloader parameters.

Parameters
imagebzImage file
bzimgbzImage context
Return values
rcReturn status code

Definition at line 241 of file bzimage.c.

242 {
243 const char *vga;
244 const char *mem;
245 char *sep;
246 char *end;
247
248 /* Look for "vga=" */
249 if ( ( vga = image_argument ( image, "vga=" ) ) ) {
250 sep = strchr ( vga, ' ' );
251 if ( sep )
252 *sep = '\0';
253 if ( strcmp ( vga, "normal" ) == 0 ) {
255 } else if ( strcmp ( vga, "ext" ) == 0 ) {
256 bzimg->vid_mode = BZI_VID_MODE_EXT;
257 } else if ( strcmp ( vga, "ask" ) == 0 ) {
258 bzimg->vid_mode = BZI_VID_MODE_ASK;
259 } else {
260 bzimg->vid_mode = strtoul ( vga, &end, 0 );
261 if ( *end ) {
262 DBGC ( image, "bzImage %s strange \"vga=\" "
263 "terminator '%c'\n",
264 image->name, *end );
265 }
266 }
267 if ( sep )
268 *sep = ' ';
269 }
270
271 /* Look for "mem=" */
272 if ( ( mem = image_argument ( image, "mem=" ) ) ) {
273 bzimg->mem_limit = strtoul ( mem, &end, 0 );
274 switch ( *end ) {
275 case 'G':
276 case 'g':
277 bzimg->mem_limit <<= 10;
278 /* Fall through */
279 case 'M':
280 case 'm':
281 bzimg->mem_limit <<= 10;
282 /* Fall through */
283 case 'K':
284 case 'k':
285 bzimg->mem_limit <<= 10;
286 break;
287 case '\0':
288 case ' ':
289 break;
290 default:
291 DBGC ( image, "bzImage %s strange \"mem=\" "
292 "terminator '%c'\n", image->name, *end );
293 break;
294 }
295 bzimg->mem_limit -= 1;
296 }
297
298 return 0;
299}
#define BZI_VID_MODE_ASK
bzImage special video mode "ask"
Definition bzimage.h:114
#define BZI_VID_MODE_EXT
bzImage special video mode "ext"
Definition bzimage.h:111
#define BZI_VID_MODE_NORMAL
bzImage special video mode "normal"
Definition bzimage.h:108
const char * image_argument(struct image *image, const char *key)
Find argument within image command line.
Definition image.c:653
uint32_t end
Ending offset.
Definition netvsc.h:7
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272

References BZI_VID_MODE_ASK, BZI_VID_MODE_EXT, BZI_VID_MODE_NORMAL, DBGC, end, image_argument(), bzimage_context::mem_limit, image::name, strchr(), strcmp(), strtoul(), and bzimage_context::vid_mode.

Referenced by bzimage_exec().

◆ bzimage_set_cmdline()

void bzimage_set_cmdline ( struct image * image,
struct bzimage_context * bzimg )
static

Set command line.

Parameters
imagebzImage image
bzimgbzImage context

Definition at line 307 of file bzimage.c.

308 {
309 const char *cmdline = ( image->cmdline ? image->cmdline : "" );
310 char *rm_cmdline;
311
312 /* Copy command line down to real-mode portion */
313 rm_cmdline = ( bzimg->rm_kernel + bzimg->rm_cmdline );
314 snprintf ( rm_cmdline, bzimg->cmdline_size, "%s", cmdline );
315 DBGC ( image, "bzImage %s command line \"%s\"\n",
316 image->name, rm_cmdline );
317}
char * cmdline
Command line to pass to image.
Definition image.h:43
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References cmdline, image::cmdline, bzimage_context::cmdline_size, DBGC, image::name, bzimage_context::rm_cmdline, bzimage_context::rm_kernel, and snprintf().

Referenced by bzimage_exec().

◆ bzimage_check_initrds()

int bzimage_check_initrds ( struct image * image,
struct bzimage_context * bzimg )
static

Check that initrds can be loaded.

Parameters
imagebzImage image
bzimgbzImage context
Return values
rcReturn status code

Definition at line 326 of file bzimage.c.

327 {
328 struct memmap_region region;
332 int rc;
333
334 /* Calculate total loaded length of initrds */
335 bzimg->initrd_size = initrd_len();
336
337 /* Succeed if there are no initrds */
338 if ( ! bzimg->initrd_size )
339 return 0;
340
341 /* Calculate available load region after reshuffling */
342 if ( ( rc = initrd_region ( bzimg->initrd_size, &region ) ) != 0 ) {
343 DBGC ( image, "bzImage %s no region for initrds: %s\n",
344 image->name, strerror ( rc ) );
345 return rc;
346 }
347
348 /* Limit region to avoiding kernel itself */
349 min = virt_to_phys ( bzimg->pm_kernel + bzimg->pm_sz );
350 if ( min < region.min )
351 min = region.min;
352
353 /* Limit region to kernel's memory limit */
354 max = region.max;
355 if ( max > bzimg->mem_limit )
356 max = bzimg->mem_limit;
357
358 /* Calculate installation address */
359 if ( max < ( bzimg->initrd_size - 1 ) ) {
360 DBGC ( image, "bzImage %s not enough space for initrds\n",
361 image->name );
362 return -ENOBUFS;
363 }
364 dest = ( ( max + 1 - bzimg->initrd_size ) & ~( INITRD_ALIGN - 1 ) );
365 if ( dest < min ) {
366 DBGC ( image, "bzImage %s not enough space for initrds\n",
367 image->name );
368 return -ENOBUFS;
369 }
370 bzimg->initrd = phys_to_virt ( dest );
371
372 DBGC ( image, "bzImage %s loading initrds from %#08lx downwards\n",
373 image->name, max );
374 return 0;
375}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned long physaddr_t
Definition stdint.h:20
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" retur dest)
Definition string.h:151
#define min(x, y)
Definition ath.h:36
#define max(x, y)
Definition ath.h:41
#define ENOBUFS
No buffer space available.
Definition errno.h:499
int initrd_region(size_t len, struct memmap_region *region)
Calculate post-reshuffle initrd load region.
Definition initrd.c:354
#define INITRD_ALIGN
Initial ramdisk chunk alignment.
Definition initrd.h:17
#define initrd_len
Definition runtime.c:63
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A memory region descriptor.
Definition memmap.h:49

References DBGC, dest, ENOBUFS, bzimage_context::initrd, INITRD_ALIGN, initrd_len, initrd_region(), bzimage_context::initrd_size, max, memmap_region::max, bzimage_context::mem_limit, memmap_region::min, min, image::name, bzimage_context::pm_kernel, bzimage_context::pm_sz, rc, and strerror().

Referenced by bzimage_exec().

◆ bzimage_load_initrds()

void bzimage_load_initrds ( struct image * image,
struct bzimage_context * bzimg )
static

Load initrds, if any.

Parameters
imagebzImage image
bzimgbzImage context

Definition at line 383 of file bzimage.c.

384 {
385 size_t len;
386
387 /* Do nothing if there are no initrds */
388 if ( ! bzimg->initrd )
389 return;
390
391 /* Reshuffle initrds into desired order */
393
394 /* Load initrds */
395 DBGC ( image, "bzImage %s initrds at [%#08lx,%#08lx)\n",
396 image->name, virt_to_phys ( bzimg->initrd ),
397 ( virt_to_phys ( bzimg->initrd ) + bzimg->initrd_size ) );
398 len = initrd_load_all ( bzimg->initrd );
399 assert ( len == bzimg->initrd_size );
400}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
void initrd_reshuffle(void)
Reshuffle initrds into desired order at top of memory.
Definition initrd.c:229
size_t initrd_load_all(void *address)
Load all initrds.
Definition initrd.c:317

References assert, DBGC, bzimage_context::initrd, initrd_load_all(), initrd_reshuffle(), bzimage_context::initrd_size, len, and image::name.

Referenced by bzimage_exec().

◆ bzimage_exec()

int bzimage_exec ( struct image * image)
static

Execute bzImage image.

Parameters
imagebzImage image
Return values
rcReturn status code

Definition at line 408 of file bzimage.c.

408 {
409 struct bzimage_context bzimg;
410 int rc;
411
412 /* Read and parse header from image */
413 if ( ( rc = bzimage_parse_header ( image, &bzimg ) ) != 0 )
414 return rc;
415
416 /* Prepare segments */
417 if ( ( rc = prep_segment ( bzimg.rm_kernel, bzimg.rm_filesz,
418 bzimg.rm_memsz ) ) != 0 ) {
419 DBGC ( image, "bzImage %s could not prepare RM segment: %s\n",
420 image->name, strerror ( rc ) );
421 return rc;
422 }
423 if ( ( rc = prep_segment ( bzimg.pm_kernel, bzimg.pm_sz,
424 bzimg.pm_sz ) ) != 0 ) {
425 DBGC ( image, "bzImage %s could not prepare PM segment: %s\n",
426 image->name, strerror ( rc ) );
427 return rc;
428 }
429
430 /* Parse command line for bootloader parameters */
431 if ( ( rc = bzimage_parse_cmdline ( image, &bzimg ) ) != 0)
432 return rc;
433
434 /* Check that initrds can be loaded */
435 if ( ( rc = bzimage_check_initrds ( image, &bzimg ) ) != 0 )
436 return rc;
437
438 /* Remove kernel from image list (without invalidating image pointer) */
440
441 /* Load segments */
442 memcpy ( bzimg.rm_kernel, image->data, bzimg.rm_filesz );
443 memcpy ( bzimg.pm_kernel, ( image->data + bzimg.rm_filesz ),
444 bzimg.pm_sz );
445
446 /* Store command line */
447 bzimage_set_cmdline ( image, &bzimg );
448
449 /* Prepare for exiting. Must do this before loading initrds,
450 * since loading the initrds will corrupt the external heap.
451 */
453
454 /* Load any initrds */
455 bzimage_load_initrds ( image, &bzimg );
456
457 /* Update kernel header */
458 bzimage_update_header ( image, &bzimg );
459
460 DBGC ( image, "bzImage %s jumping to RM kernel at %04x:0000 (stack "
461 "%04x:%04zx)\n", image->name, ( bzimg.rm_kernel_seg + 0x20 ),
462 bzimg.rm_kernel_seg, bzimg.rm_heap );
463
464 /* Jump to the kernel */
465 __asm__ __volatile__ ( REAL_CODE ( "movw %w0, %%ds\n\t"
466 "movw %w0, %%es\n\t"
467 "movw %w0, %%fs\n\t"
468 "movw %w0, %%gs\n\t"
469 "movw %w0, %%ss\n\t"
470 "movw %w1, %%sp\n\t"
471 "pushw %w2\n\t"
472 "pushw $0\n\t"
473 "lret\n\t" )
474 : : "R" ( bzimg.rm_kernel_seg ),
475 "R" ( bzimg.rm_heap ),
476 "R" ( bzimg.rm_kernel_seg + 0x20 ) );
477
478 /* There is no way for the image to return, since we provide
479 * no return address.
480 */
481 assert ( 0 );
482
483 return -ECANCELED; /* -EIMPOSSIBLE */
484}
__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))
static int bzimage_parse_cmdline(struct image *image, struct bzimage_context *bzimg)
Parse kernel command line for bootloader parameters.
Definition bzimage.c:241
static void bzimage_load_initrds(struct image *image, struct bzimage_context *bzimg)
Load initrds, if any.
Definition bzimage.c:383
static void bzimage_update_header(struct image *image, struct bzimage_context *bzimg)
Update bzImage header in loaded kernel.
Definition bzimage.c:195
static void bzimage_set_cmdline(struct image *image, struct bzimage_context *bzimg)
Set command line.
Definition bzimage.c:307
static int bzimage_check_initrds(struct image *image, struct bzimage_context *bzimg)
Check that initrds can be loaded.
Definition bzimage.c:326
static int bzimage_parse_header(struct image *image, struct bzimage_context *bzimg)
Parse bzImage header.
Definition bzimage.c:92
#define ECANCELED
Operation canceled.
Definition errno.h:344
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
static struct image * image_get(struct image *image)
Increment reference count on an image.
Definition image.h:240
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void shutdown_boot(void)
Shut down system for OS boot.
Definition init.h:78
#define REAL_CODE(asm_code_str)
Definition libkir.h:226
__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")
int prep_segment(void *segment, size_t filesz, size_t memsz)
Prepare segment for loading.
Definition segment.c:61
bzImage context
Definition bzimage.c:54

References __asm__(), __volatile__(), assert, bzimage_check_initrds(), bzimage_load_initrds(), bzimage_parse_cmdline(), bzimage_parse_header(), bzimage_set_cmdline(), bzimage_update_header(), image::data, DBGC, ECANCELED, image_get(), memcpy(), image::name, bzimage_context::pm_kernel, bzimage_context::pm_sz, prep_segment(), rc, REAL_CODE, bzimage_context::rm_filesz, bzimage_context::rm_heap, bzimage_context::rm_kernel, bzimage_context::rm_kernel_seg, bzimage_context::rm_memsz, shutdown_boot(), strerror(), and unregister_image().

Referenced by __image_type().

◆ bzimage_probe()

int bzimage_probe ( struct image * image)

Probe bzImage image.

Parameters
imagebzImage file
Return values
rcReturn status code

Definition at line 492 of file bzimage.c.

492 {
493 struct bzimage_context bzimg;
494 int rc;
495
496 /* Read and parse header from image */
497 if ( ( rc = bzimage_parse_header ( image, &bzimg ) ) != 0 )
498 return rc;
499
500 return 0;
501}

References bzimage_parse_header(), and rc.

Referenced by __image_type().

◆ __image_type()

struct image_type bzimage_image_type __image_type ( PROBE_NORMAL )

Linux bzImage image type.

References __image_type, bzimage_exec(), bzimage_probe(), and PROBE_NORMAL.