aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2021-05-17 14:57:48 +0100
committerMichael Brown <mcb30@ipxe.org>2021-05-21 15:19:38 +0100
commitbfca3db41e9af78e56e7a9b7f30121df83b6af0a (patch)
tree4f75eef31776bcc8d2918b9b2e92e90560859794 /src/arch/x86
parentfc8bd4ba1a65db9d9091705f30fec19ded75530c (diff)
downloadipxe-bfca3db41e9af78e56e7a9b7f30121df83b6af0a.zip
ipxe-bfca3db41e9af78e56e7a9b7f30121df83b6af0a.tar.gz
ipxe-bfca3db41e9af78e56e7a9b7f30121df83b6af0a.tar.bz2
[cpio] Split out bzImage initrd CPIO header construction
iPXE will construct CPIO headers for images that have a non-empty command line, thereby allowing raw images (without CPIO headers) to be injected into a dynamically constructed initrd. This feature is currently implemented within the BIOS-only bzImage format support. Split out the CPIO header construction logic to allow for reuse in other contexts such as in a UEFI build. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/x86')
-rw-r--r--src/arch/x86/image/bzimage.c52
-rw-r--r--src/arch/x86/image/initrd.c1
-rw-r--r--src/arch/x86/include/initrd.h7
3 files changed, 4 insertions, 56 deletions
diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c
index 51498bf..a782127 100644
--- a/src/arch/x86/image/bzimage.c
+++ b/src/arch/x86/image/bzimage.c
@@ -327,32 +327,6 @@ static void bzimage_set_cmdline ( struct image *image,
}
/**
- * Parse standalone image command line for cpio parameters
- *
- * @v image bzImage file
- * @v cpio CPIO header
- * @v cmdline Command line
- */
-static void bzimage_parse_cpio_cmdline ( struct image *image,
- struct cpio_header *cpio,
- const char *cmdline ) {
- char *arg;
- char *end;
- unsigned int mode;
-
- /* Look for "mode=" */
- if ( ( arg = strstr ( cmdline, "mode=" ) ) ) {
- arg += 5;
- mode = strtoul ( arg, &end, 8 /* Octal for file mode */ );
- if ( *end && ( *end != ' ' ) ) {
- DBGC ( image, "bzImage %p strange \"mode=\""
- "terminator '%c'\n", image, *end );
- }
- cpio_set_field ( cpio->c_mode, ( 0100000 | mode ) );
- }
-}
-
-/**
* Align initrd length
*
* @v len Length
@@ -374,11 +348,9 @@ static inline size_t bzimage_align ( size_t len ) {
static size_t bzimage_load_initrd ( struct image *image,
struct image *initrd,
userptr_t address ) {
- char *filename = initrd->cmdline;
- char *cmdline;
+ const char *filename = cpio_name ( initrd );
struct cpio_header cpio;
size_t offset;
- size_t name_len;
size_t pad_len;
/* Do not include kernel image itself as an initrd */
@@ -386,25 +358,7 @@ static size_t bzimage_load_initrd ( struct image *image,
return 0;
/* Create cpio header for non-prebuilt images */
- if ( filename && filename[0] ) {
- cmdline = strchr ( filename, ' ' );
- name_len = ( ( cmdline ? ( ( size_t ) ( cmdline - filename ) )
- : strlen ( filename ) ) + 1 /* NUL */ );
- memset ( &cpio, '0', sizeof ( cpio ) );
- memcpy ( cpio.c_magic, CPIO_MAGIC, sizeof ( cpio.c_magic ) );
- cpio_set_field ( cpio.c_mode, 0100644 );
- cpio_set_field ( cpio.c_nlink, 1 );
- cpio_set_field ( cpio.c_filesize, initrd->len );
- cpio_set_field ( cpio.c_namesize, name_len );
- if ( cmdline ) {
- bzimage_parse_cpio_cmdline ( image, &cpio,
- ( cmdline + 1 /* ' ' */ ));
- }
- offset = ( ( sizeof ( cpio ) + name_len + 0x03 ) & ~0x03 );
- } else {
- offset = 0;
- name_len = 0;
- }
+ offset = cpio_header ( initrd, &cpio );
/* Copy in initrd image body (and cpio header if applicable) */
if ( address ) {
@@ -413,7 +367,7 @@ static size_t bzimage_load_initrd ( struct image *image,
memset_user ( address, 0, 0, offset );
copy_to_user ( address, 0, &cpio, sizeof ( cpio ) );
copy_to_user ( address, sizeof ( cpio ), filename,
- ( name_len - 1 /* NUL (or space) */ ) );
+ cpio_name_len ( initrd ) );
}
DBGC ( image, "bzImage %p initrd %p [%#08lx,%#08lx,%#08lx)"
"%s%s\n", image, initrd, user_to_phys ( address, 0 ),
diff --git a/src/arch/x86/image/initrd.c b/src/arch/x86/image/initrd.c
index 49b959a..d7b1f57 100644
--- a/src/arch/x86/image/initrd.c
+++ b/src/arch/x86/image/initrd.c
@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/uaccess.h>
#include <ipxe/init.h>
#include <ipxe/memblock.h>
+#include <ipxe/cpio.h>
/** @file
*
diff --git a/src/arch/x86/include/initrd.h b/src/arch/x86/include/initrd.h
index ddb3e5a..2fb9d3d 100644
--- a/src/arch/x86/include/initrd.h
+++ b/src/arch/x86/include/initrd.h
@@ -11,13 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/uaccess.h>
-/** Minimum alignment for initrds
- *
- * Some versions of Linux complain about initrds that are not
- * page-aligned.
- */
-#define INITRD_ALIGN 4096
-
/** Minimum free space required to reshuffle initrds
*
* Chosen to avoid absurdly long reshuffling times