iPXE
Defines | Functions
initrd.h File Reference

Initial ramdisk (initrd) reshuffling. More...

#include <ipxe/uaccess.h>

Go to the source code of this file.

Defines

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

Functions

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

Detailed Description

Initial ramdisk (initrd) reshuffling.

Definition in file initrd.h.


Define Documentation

#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.

Referenced by bzimage_align(), bzimage_load_initrd(), bzimage_load_initrds(), initrd_squash_high(), initrd_swap(), and initrd_swap_any().

#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.

Referenced by initrd_reshuffle_check().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

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().

                                           {
        userptr_t top;
        userptr_t used;
        userptr_t free;
        size_t free_len;

        /* Calculate limits of available space for initrds */
        top = initrd_top;
        if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
                bottom = initrd_bottom;

        /* Debug */
        DBGC ( &images, "INITRD region [%#08lx,%#08lx)\n",
               user_to_phys ( bottom, 0 ), user_to_phys ( top, 0 ) );
        initrd_dump();

        /* Squash initrds as high as possible in memory */
        used = initrd_squash_high ( top );

        /* Calculate available free space */
        free = bottom;
        free_len = userptr_sub ( used, free );

        /* Bubble-sort initrds into desired order */
        while ( initrd_swap_any ( free, free_len ) ) {}

        /* Debug */
        initrd_dump();
}
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.

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

Referenced by bzimage_check_initrds().

                                                            {
        userptr_t top;
        size_t available;

        /* Calculate limits of available space for initrds */
        top = initrd_top;
        if ( userptr_sub ( initrd_bottom, bottom ) > 0 )
                bottom = initrd_bottom;
        available = userptr_sub ( top, bottom );

        /* Allow for a sensible minimum amount of free space */
        len += INITRD_MIN_FREE_LEN;

        /* Check for available space */
        return ( ( len < available ) ? 0 : -ENOBUFS );
}