iPXE
initrd.h File Reference

Initial ramdisk (initrd) reshuffling. More...

#include <stdint.h>
#include <ipxe/memmap.h>

Go to the source code of this file.

Macros

#define INITRD_ALIGN   4096
 Initial ramdisk chunk alignment.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void initrd_reshuffle (void)
 Reshuffle initrds into desired order at top of memory.
int initrd_region (size_t len, struct memmap_region *region)
 Calculate post-reshuffle initrd load region.
size_t initrd_load_all (void *address)
 Load all initrds.
static size_t initrd_align (size_t len)
 Align initrd length.
static size_t initrd_len (void)
 Get required length for initrds.

Detailed Description

Initial ramdisk (initrd) reshuffling.

Definition in file initrd.h.

Macro Definition Documentation

◆ INITRD_ALIGN

#define INITRD_ALIGN   4096

Initial ramdisk chunk alignment.

Definition at line 17 of file initrd.h.

Referenced by bzimage_check_initrds(), efi_file_read_initrd(), initrd_align(), initrd_load(), and initrd_load_all().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ initrd_reshuffle()

void initrd_reshuffle ( void )
extern

Reshuffle initrds into desired order at top of memory.

After this function returns, the initrds have been rearranged in memory and the external heap structures will have been corrupted. Reshuffling must therefore take place immediately prior to jumping to the loaded OS kernel; no further execution within iPXE is permitted.

Definition at line 229 of file initrd.c.

229 {
232
233 /* Calculate limits of reshuffle region */
236
237 /* Debug */
238 initrd_dump();
239
240 /* Squash initrds as high as possible in memory */
242
243 /* Bubble-sort initrds into desired order */
244 while ( initrd_swap_any ( start, end ) ) {}
245
246 /* Debug */
247 initrd_dump();
248}
unsigned long physaddr_t
Definition stdint.h:20
uint32_t start
Starting offset.
Definition netvsc.h:1
static int initrd_swap_any(physaddr_t start, physaddr_t end)
Swap position of any two adjacent initrds not currently in the correct order.
Definition initrd.c:155
static physaddr_t initrd_end
End of reshuffle region.
Definition initrd.c:42
static void initrd_squash_high(physaddr_t start, physaddr_t end)
Squash initrds as high as possible in memory.
Definition initrd.c:50
static void initrd_dump(void)
Dump initrd locations (for debug)
Definition initrd.c:203
uint32_t end
Ending offset.
Definition netvsc.h:7
physaddr_t uheap_end
End of external heap.
Definition uheap.c:60
physaddr_t uheap_limit
Minimum possible start of external heap.
Definition uheap.c:54

References end, initrd_dump(), initrd_end, initrd_squash_high(), initrd_swap_any(), start, uheap_end, and uheap_limit.

Referenced by bzimage_load_initrds(), and lkrn_exec().

◆ initrd_region()

int initrd_region ( size_t len,
struct memmap_region * region )
extern

Calculate post-reshuffle initrd load region.

Parameters
lenLength of initrds (from initrd_len())
regionRegion descriptor to fill in
Return values
rcReturn status code

If successful, then any suitably aligned range within the region may be used as the load address after reshuffling. The caller does not need to call prep_segment() for a range in this region. (Calling prep_segment() would probably fail, since prior to reshuffling the region is still in use by the external heap.)

Definition at line 354 of file initrd.c.

354 {
356 size_t available;
357
358 /* Calculate limits of available space for initrds */
360 available = ( ( initrd_end ? initrd_end : uheap_end ) - min );
361 if ( available < len )
362 return -ENOSPC;
363 DBGC ( &images, "INITRD post-reshuffle region is [%#08lx,%#08lx)\n",
364 min, ( min + available ) );
365
366 /* Populate region descriptor */
367 region->min = min;
368 region->max = ( min + available - 1 );
369 region->flags = MEMMAP_FL_MEMORY;
370 region->name = "initrd";
371
372 return 0;
373}
#define min(x, y)
Definition ath.h:36
ring len
Length.
Definition dwmac.h:226
#define DBGC(...)
Definition compiler.h:505
#define ENOSPC
No space left on device.
Definition errno.h:550
struct list_head images
List of registered images.
Definition image.c:59
#define MEMMAP_FL_MEMORY
Contains memory.
Definition memmap.h:60
const char * name
Region name (for debug messages)
Definition memmap.h:57
uint64_t min
Minimum address in region.
Definition memmap.h:51
unsigned int flags
Region flags.
Definition memmap.h:55
uint64_t max
Maximum address in region.
Definition memmap.h:53

References DBGC, ENOSPC, memmap_region::flags, images, initrd_end, len, memmap_region::max, MEMMAP_FL_MEMORY, memmap_region::min, min, memmap_region::name, uheap_end, and uheap_limit.

Referenced by bzimage_check_initrds(), and lkrn_exec().

◆ initrd_load_all()

size_t initrd_load_all ( void * address)
extern

Load all initrds.

Parameters
addressLoad address, or NULL
Return values
lenLength

This function is called after the point of no return, when the external heap has been corrupted by reshuffling and there is no way to resume normal execution. The caller must have previously ensured that there is no way for installation to this address to fail.

Definition at line 317 of file initrd.c.

317 {
318 struct image *initrd;
319 size_t len = 0;
320 size_t pad_len;
321 void *dest;
322
323 /* Load all initrds */
324 for_each_image ( initrd ) {
325
326 /* Zero-pad to next INITRD_ALIGN boundary */
327 pad_len = ( ( -len ) & ( INITRD_ALIGN - 1 ) );
328 if ( address )
329 memset ( ( address + len ), 0, pad_len );
330 len += pad_len;
331 assert ( len == initrd_align ( len ) );
332
333 /* Load initrd */
334 dest = ( address ? ( address + len ) : NULL );
335 len += initrd_load ( initrd, dest );
336 }
337
338 return len;
339}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
long pad_len
Definition bigint.h:31
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 assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint64_t address
Base address.
Definition ena.h:13
#define for_each_image(image)
Iterate over all registered images.
Definition image.h:191
void * memset(void *dest, int character, size_t len) __nonnull
static size_t initrd_load(struct image *initrd, void *address)
Load initrd.
Definition initrd.c:257
#define INITRD_ALIGN
Initial ramdisk chunk alignment.
Definition initrd.h:17
static size_t initrd_align(size_t len)
Align initrd length.
Definition initrd.h:30
An executable image.
Definition image.h:24

References address, assert, dest, for_each_image, INITRD_ALIGN, initrd_align(), initrd_load(), len, memset(), NULL, and pad_len.

Referenced by bzimage_load_initrds(), initrd_len(), and lkrn_exec().

◆ initrd_align()

size_t initrd_align ( size_t len)
inlinestatic

Align initrd length.

Parameters
lenLength
Return values
lenAligned length

Definition at line 30 of file initrd.h.

30 {
31
32 return ( ( len + INITRD_ALIGN - 1 ) & ~( INITRD_ALIGN - 1 ) );
33}

References INITRD_ALIGN, and len.

Referenced by initrd_load_all(), initrd_squash_high(), initrd_swap(), initrd_swap_any(), and lkrn_exec().

◆ initrd_len()

size_t initrd_len ( void )
inlinestatic

Get required length for initrds.

Return values
lenRequired length

Definition at line 41 of file initrd.h.

41 {
42
43 return initrd_load_all ( NULL );
44}
size_t initrd_load_all(void *address)
Load all initrds.
Definition initrd.c:317

References initrd_load_all(), and NULL.