iPXE
Macros | Functions
initrd.h File Reference

Initial ramdisk (initrd) reshuffling. More...

#include <ipxe/uaccess.h>

Go to the source code of this file.

Macros

#define INITRD_ALIGN   4096
 Minimum alignment for initrds. More...
 
#define INITRD_MIN_FREE_LEN   ( 512 * 1024 )
 Minimum free space required to reshuffle initrds. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void initrd_reshuffle (userptr_t bottom)
 Reshuffle initrds into desired order at top of memory. More...
 
int initrd_reshuffle_check (size_t len, userptr_t bottom)
 Check that there is enough space to reshuffle initrds. More...
 

Detailed Description

Initial ramdisk (initrd) reshuffling.

Definition in file initrd.h.

Macro Definition Documentation

◆ INITRD_ALIGN

#define INITRD_ALIGN   4096

Minimum alignment for initrds.

Some versions of Linux complain about initrds that are not page-aligned.

Definition at line 19 of file initrd.h.

◆ INITRD_MIN_FREE_LEN

#define INITRD_MIN_FREE_LEN   ( 512 * 1024 )

Minimum free space required to reshuffle initrds.

Chosen to avoid absurdly long reshuffling times

Definition at line 25 of file initrd.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ initrd_reshuffle()

void initrd_reshuffle ( userptr_t  bottom)

Reshuffle initrds into desired order at top of memory.

Parameters
bottomLowest address available for initrds

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  {
230  userptr_t top;
231  userptr_t used;
232  userptr_t free;
233  size_t free_len;
234 
235  /* Calculate limits of available space for initrds */
236  top = initrd_top;
237  if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
239 
240  /* Debug */
241  DBGC ( &images, "INITRD region [%#08lx,%#08lx)\n",
242  user_to_phys ( bottom, 0 ), user_to_phys ( top, 0 ) );
243  initrd_dump();
244 
245  /* Squash initrds as high as possible in memory */
246  used = initrd_squash_high ( top );
247 
248  /* Calculate available free space */
249  free = bottom;
250  free_len = userptr_sub ( used, free );
251 
252  /* Bubble-sort initrds into desired order */
253  while ( initrd_swap_any ( free, free_len ) ) {}
254 
255  /* Debug */
256  initrd_dump();
257 }
static int initrd_swap_any(userptr_t free, size_t free_len)
Swap position of any two adjacent initrds not currently in the correct order.
Definition: initrd.c:161
userptr_t initrd_bottom
Minimum address available for initrd.
Definition: initrd.c:43
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
static userptr_t bottom
Bottom of heap (current lowest allocated block)
off_t userptr_sub(userptr_t userptr, userptr_t subtrahend)
Subtract user pointers.
userptr_t initrd_top
Maximum address available for initrd.
Definition: initrd.c:40
static void initrd_dump(void)
Dump initrd locations (for debug)
Definition: initrd.c:201
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static userptr_t top
Top of heap.
struct list_head images
List of registered images.
Definition: image.c:56
static userptr_t initrd_squash_high(userptr_t top)
Squash initrds as high as possible in memory.
Definition: initrd.c:51
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References bottom, DBGC, free, images, initrd_bottom, initrd_dump(), initrd_squash_high(), initrd_swap_any(), initrd_top, top, user_to_phys(), and userptr_sub().

Referenced by bzimage_load_initrds().

◆ initrd_reshuffle_check()

int initrd_reshuffle_check ( size_t  len,
userptr_t  bottom 
)

Check that there is enough space to reshuffle initrds.

Parameters
lenTotal length of initrds (including padding)
bottomLowest address available for initrds
Return values
rcReturn status code

Definition at line 266 of file initrd.c.

266  {
267  userptr_t top;
268  size_t available;
269 
270  /* Calculate limits of available space for initrds */
271  top = initrd_top;
272  if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
274  available = userptr_sub ( top, bottom );
275 
276  /* Allow for a sensible minimum amount of free space */
278 
279  /* Check for available space */
280  return ( ( len < available ) ? 0 : -ENOBUFS );
281 }
userptr_t initrd_bottom
Minimum address available for initrd.
Definition: initrd.c:43
#define INITRD_MIN_FREE_LEN
Minimum free space required to reshuffle initrds.
Definition: initrd.h:25
static userptr_t bottom
Bottom of heap (current lowest allocated block)
off_t userptr_sub(userptr_t userptr, userptr_t subtrahend)
Subtract user pointers.
userptr_t initrd_top
Maximum address available for initrd.
Definition: initrd.c:40
static userptr_t top
Top of heap.
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References bottom, ENOBUFS, initrd_bottom, INITRD_MIN_FREE_LEN, initrd_top, len, top, and userptr_sub().

Referenced by bzimage_check_initrds().