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_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_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 18 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 230 of file initrd.c.

230  {
231  userptr_t top;
232  userptr_t used;
233  userptr_t free;
234  size_t free_len;
235 
236  /* Calculate limits of available space for initrds */
237  top = initrd_top;
238  if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
240 
241  /* Debug */
242  DBGC ( &images, "INITRD region [%#08lx,%#08lx)\n",
243  user_to_phys ( bottom, 0 ), user_to_phys ( top, 0 ) );
244  initrd_dump();
245 
246  /* Squash initrds as high as possible in memory */
247  used = initrd_squash_high ( top );
248 
249  /* Calculate available free space */
250  free = bottom;
251  free_len = userptr_sub ( used, free );
252 
253  /* Bubble-sort initrds into desired order */
254  while ( initrd_swap_any ( free, free_len ) ) {}
255 
256  /* Debug */
257  initrd_dump();
258 }
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:162
userptr_t initrd_bottom
Minimum address available for initrd.
Definition: initrd.c:44
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:41
static void initrd_dump(void)
Dump initrd locations (for debug)
Definition: initrd.c:202
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:57
static userptr_t initrd_squash_high(userptr_t top)
Squash initrds as high as possible in memory.
Definition: initrd.c:52
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 267 of file initrd.c.

267  {
268  userptr_t top;
269  size_t available;
270 
271  /* Calculate limits of available space for initrds */
272  top = initrd_top;
273  if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
275  available = userptr_sub ( top, bottom );
276 
277  /* Allow for a sensible minimum amount of free space */
279 
280  /* Check for available space */
281  return ( ( len < available ) ? 0 : -ENOBUFS );
282 }
userptr_t initrd_bottom
Minimum address available for initrd.
Definition: initrd.c:44
#define INITRD_MIN_FREE_LEN
Minimum free space required to reshuffle initrds.
Definition: initrd.h:18
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:41
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().