VladikSS informed me that the patch was accidentally pasted twice: "wimboot syslinux kludge 2/4: provide common read_mem_file cpio handler"
Attached are all the changes again as diffs which can be applied in order with patch -p2 in the wimboot/src directory. Submitting the broken patch in question again for reference: -- For the next patch that will add cpio support for efi, we want to use a common read_mem_file() as cpio handler. This patch moves the private read_file() from main.c to vdisk.c as read_mem_file() so it can shared. Signed-off-by: Friedemann Gerold <f.ger...@b-c-s.de> --- wimbootorig/src/vdisk.h 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/vdisk.h 2018-11-02 12:28:48.071166732 +0100 @@ -610,11 +610,15 @@ extern struct vdisk_file vdisk_files[VDISK_MAX_FILES]; + extern void vdisk_read ( uint64_t lba, unsigned int count, void *data ); extern struct vdisk_file * vdisk_add_file ( const char *name, void *opaque, size_t len, void ( * read ) ( struct vdisk_file *file, void *data, size_t offset, size_t len ) ); + +extern void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ); + extern void vdisk_patch_file ( struct vdisk_file *file, void ( * patch ) ( struct vdisk_file *file, void *data, --- wimbootorig/src/vdisk.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/vdisk.c 2018-11-02 12:28:48.071166732 +0100 @@ -614,6 +614,19 @@ } /** + * Read from file + * + * @v file Virtual file + * @v data Data buffer + * @v offset Offset + * @v len Length + */ +void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ) { + memcpy ( data, ( file->opaque + offset ), len ); +} + + +/** * Add file to virtual disk * * @v name Name --- wimbootorig/src/main.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/main.c 2018-11-02 12:28:48.071166732 +0100 @@ -197,20 +197,6 @@ } /** - * Read from file - * - * @v file Virtual file - * @v data Data buffer - * @v offset Offset - * @v len Length - */ -static void read_file ( struct vdisk_file *file, void *data, size_t offset, - size_t len ) { - - memcpy ( data, ( file->opaque + offset ), len ); -} - -/** * Add embedded bootmgr.exe extracted from bootmgr * * @v data File data @@ -305,8 +291,7 @@ decompress ( compressed, compressed_len, initrd ); /* Add decompressed image */ - return vdisk_add_file ( "bootmgr.exe", initrd, - decompressed_len, read_file ); + return vdisk_add_file ( "bootmgr.exe", initrd, decompressed_len, read_mem_file ); } DBG ( "...no embedded bootmgr.exe found\n" ); @@ -325,7 +310,7 @@ struct vdisk_file *file; /* Store file */ - file = vdisk_add_file ( name, data, len, read_file ); + file = vdisk_add_file ( name, data, len, read_mem_file ); /* Check for special-case files */ if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) { @@ -378,7 +363,7 @@ /* Read bootmgr.exe into memory */ if ( ! bootmgr ) die ( "FATAL: no bootmgr.exe\n" ); - if ( bootmgr->read == read_file ) { + if ( bootmgr->read == read_mem_file ) { raw_pe = bootmgr->opaque; } else { padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) &
--- wimbootorig/src/prefix.S 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/prefix.S 2018-11-02 12:28:48.071166732 +0100 @@ -33,8 +33,12 @@ #define i386(symbol) symbol #endif -/** Standard number of setup sectors */ -#define SETUP_SECTS 4 +/* + * Standard number of setup sectors was 5, + * but we need to round it to 4k to page + * align _payload. + */ +#define SETUP_SECTS ((0x1000/SECTOR_SIZE)-1) /** Sector size */ #define SECTOR_SIZE 512 @@ -219,7 +223,7 @@ .org 0x206 version: - .word 0x203 /* Version 2.03 */ + .word 0x20b /* Version 2.11 */ .org 0x20e kernel_version: @@ -229,6 +233,10 @@ loadflags: .byte LOADED_HIGH + .org 0x214 +code32_start: + .long 0 + .org 0x218 ramdisk_image: .long 0 /* Filled in by boot loader */ @@ -245,6 +253,37 @@ ramdisk_max: .long 0x7fffffff + .org 0x236 +xloadflags: + .word (1<<3) + + .org 0x238 +cmdline_size: + .long 256 + + .org 0x23c +hardware_subarch: + .long 0 + + .org 0x258 +prefaddr: + .long _payload + .long 0 + + .org 0x260 +init_size: + .long 0x10000 + + .org 0x264 +handover_offset: + /* + * really would like to write efihandover-_payload here, + * but we cant as efihandover its part of the payload + * section. 0x4000 is the page rounded size of this + * prefix setion (4k) + text16/bss16 section (12k). + */ + .long ( efihandover-BASE_ADDRESS-0x4000 ) + version_string: .asciz VERSION --- wimbootorig/src/startup.S 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/startup.S 2018-11-02 12:28:48.071166732 +0100 @@ -57,6 +57,15 @@ jmp reboot .size startup, . - startup + .section ".text", "ax", @progbits + .globl efihandover + .globl efihandover64 +efihandover: + .org .+512, 0x90 +efihandover64: + jmp efi_linuxentry + .size startup, . - startup + /* Reboot system */ .section ".text", "ax", @progbits .globl reboot --- wimbootorig/src/efimain.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/efimain.c 2018-11-02 13:41:05.044672622 +0100 @@ -99,3 +99,19 @@ return 0; } + +void +efi_linuxentry(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab, uint32_t *bp) +{ + efi_image_handle = image_handle; + efi_systab = systab; + +#if __x86_64__ + extern char _bss[]; + extern char _ebss[]; + memset(_bss, 0, _ebss-_bss); +#endif + + efi_main(image_handle, systab); +} +
--- wimbootorig/src/vdisk.h 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/vdisk.h 2018-11-02 12:28:48.071166732 +0100 @@ -610,11 +610,15 @@ extern struct vdisk_file vdisk_files[VDISK_MAX_FILES]; + extern void vdisk_read ( uint64_t lba, unsigned int count, void *data ); extern struct vdisk_file * vdisk_add_file ( const char *name, void *opaque, size_t len, void ( * read ) ( struct vdisk_file *file, void *data, size_t offset, size_t len ) ); + +extern void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ); + extern void vdisk_patch_file ( struct vdisk_file *file, void ( * patch ) ( struct vdisk_file *file, void *data, --- wimbootorig/src/vdisk.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/vdisk.c 2018-11-02 12:28:48.071166732 +0100 @@ -614,6 +614,19 @@ } /** + * Read from file + * + * @v file Virtual file + * @v data Data buffer + * @v offset Offset + * @v len Length + */ +void read_mem_file ( struct vdisk_file *file, void *data, size_t offset, size_t len ) { + memcpy ( data, ( file->opaque + offset ), len ); +} + + +/** * Add file to virtual disk * * @v name Name --- wimbootorig/src/main.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/main.c 2018-11-02 12:28:48.071166732 +0100 @@ -197,20 +197,6 @@ } /** - * Read from file - * - * @v file Virtual file - * @v data Data buffer - * @v offset Offset - * @v len Length - */ -static void read_file ( struct vdisk_file *file, void *data, size_t offset, - size_t len ) { - - memcpy ( data, ( file->opaque + offset ), len ); -} - -/** * Add embedded bootmgr.exe extracted from bootmgr * * @v data File data @@ -305,8 +291,7 @@ decompress ( compressed, compressed_len, initrd ); /* Add decompressed image */ - return vdisk_add_file ( "bootmgr.exe", initrd, - decompressed_len, read_file ); + return vdisk_add_file ( "bootmgr.exe", initrd, decompressed_len, read_mem_file ); } DBG ( "...no embedded bootmgr.exe found\n" ); @@ -325,7 +310,7 @@ struct vdisk_file *file; /* Store file */ - file = vdisk_add_file ( name, data, len, read_file ); + file = vdisk_add_file ( name, data, len, read_mem_file ); /* Check for special-case files */ if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) { @@ -378,7 +363,7 @@ /* Read bootmgr.exe into memory */ if ( ! bootmgr ) die ( "FATAL: no bootmgr.exe\n" ); - if ( bootmgr->read == read_file ) { + if ( bootmgr->read == read_mem_file ) { raw_pe = bootmgr->opaque; } else { padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) &
--- wimboot/src/efimain.c.1 2018-11-02 13:43:01.737251269 +0100 +++ wimboot/src/efimain.c 2018-11-02 13:43:10.549294966 +0100 @@ -32,6 +32,15 @@ #include "efiblock.h" #include "efiboot.h" +#include "string.h" +#include "cpio.h" + +/** initrd */ +void *initrd; + +/** Length of initrd */ +size_t initrd_len; + /** * Process command line * @@ -88,8 +97,13 @@ /* Process command line */ efi_cmdline ( loaded.image ); - /* Extract files from file system */ - efi_extract ( loaded.image->DeviceHandle ); + if(initrd_len){ + /* Extract files from initrd (syslinux) */ + cpio_extract ( initrd, initrd_len, efi_add_file ); + } else { + /* Extract files from file system */ + efi_extract ( loaded.image->DeviceHandle ); + } /* Install virtual disk */ efi_install ( &vdisk, &vpartition ); @@ -112,6 +126,11 @@ memset(_bss, 0, _ebss-_bss); #endif + if(bp){ + initrd = (void*)(intptr_t)bp[0x218/4]; + initrd_len = (size_t)bp[0x21c/4]; + } + efi_main(image_handle, systab); } --- wimbootorig/src/efifile.c 2018-11-02 12:29:14.343297008 +0100 +++ wimboot/src/efifile.c 2018-11-02 12:28:48.071166732 +0100 @@ -28,6 +28,7 @@ #include <string.h> #include <strings.h> #include <wchar.h> +#include <ctype.h> #include "wimboot.h" #include "vdisk.h" #include "cmdline.h" @@ -117,6 +118,58 @@ } } +static int +isbootmgfw( const char *name) +{ + char bootarch[32]; + + if (strcasecmp(name, "bootmgfw.efi") == 0) + return 1; + snprintf ( bootarch, sizeof ( bootarch ), "%ls", efi_bootarch() ); + return strcasecmp(name, bootarch) == 0; +} + +static int +addfile( const char *name, void *data, size_t len, void ( * read ) ( struct vdisk_file *file, + void *data, + size_t offset, + size_t len ) ) { + struct vdisk_file *vfile; + + vfile = vdisk_add_file ( name, data, len, read ); + + /* Check for special-case files */ + if ( isbootmgfw( name ) ) { + bootmgfw = vfile; + } else if ( strcasecmp ( name, "BCD" ) == 0 ) { + vdisk_patch_file ( vfile, efi_patch_bcd ); + } else if ( strlen( name ) > 4 && strcasecmp ( ( name + ( strlen ( name ) - 4 ) ), ".wim" ) == 0 ) { + vdisk_patch_file ( vfile, patch_wim ); + if ( ( ! bootmgfw ) && + ( bootmgfw = wim_add_file ( vfile, cmdline_index, + bootmgfw_path, + efi_bootarch() ) ) ) { + DBG ( "...extracted %ls\n", bootmgfw_path ); + } + } + return 0; +} + +/** + * File handler + * + * @v name File name + * @v data File data + * @v len Length + * @ret rc Return status code + */ +int +efi_add_file ( const char *name, void *data, size_t len) +{ + return addfile(name, data, len, read_mem_file); +} + + /** * Extract files from EFI file system * @@ -133,7 +186,6 @@ CHAR16 name[ VDISK_NAME_LEN + 1 /* WNUL */ ]; } __attribute__ (( packed )) info; char name[ VDISK_NAME_LEN + 1 /* NUL */ ]; - struct vdisk_file *vfile; EFI_FILE_PROTOCOL *root; EFI_FILE_PROTOCOL *file; UINTN size; @@ -186,28 +238,7 @@ /* Add file */ snprintf ( name, sizeof ( name ), "%ls", wname ); - vfile = vdisk_add_file ( name, file, info.file.FileSize, - efi_read_file ); - - /* Check for special-case files */ - if ( ( wcscasecmp ( wname, efi_bootarch() ) == 0 ) || - ( wcscasecmp ( wname, L"bootmgfw.efi" ) == 0 ) ) { - DBG ( "...found bootmgfw.efi file %ls\n", wname ); - bootmgfw = vfile; - } else if ( wcscasecmp ( wname, L"BCD" ) == 0 ) { - DBG ( "...found BCD\n" ); - vdisk_patch_file ( vfile, efi_patch_bcd ); - } else if ( wcscasecmp ( ( wname + ( wcslen ( wname ) - 4 ) ), - L".wim" ) == 0 ) { - DBG ( "...found WIM file %ls\n", wname ); - vdisk_patch_file ( vfile, patch_wim ); - if ( ( ! bootmgfw ) && - ( bootmgfw = wim_add_file ( vfile, cmdline_index, - bootmgfw_path, - efi_bootarch() ) ) ) { - DBG ( "...extracted %ls\n", bootmgfw_path ); - } - } + addfile(name, file, info.file.FileSize, efi_read_file); } /* Check that we have a boot file */
--- wimbootorig/src/cmdline.c 2018-11-02 12:29:14.339296989 +0100 +++ wimboot/src/cmdline.c 2018-11-02 12:28:48.071166732 +0100 @@ -105,7 +105,7 @@ cmdline_index = strtoul ( value, &endp, 0 ); if ( *endp ) die ( "Invalid index \"%s\"\n", value ); - } else if ( strcmp ( key, "initrdfile" ) == 0 ) { + } else if ( strcmp ( key, "initrdfile" ) == 0 || strcmp ( key, "initrd" ) == 0) { /* Ignore this keyword to allow for use with syslinux */ } else if ( key == cmdline ) { /* Ignore unknown initial arguments, which may
_______________________________________________ ipxe-devel mailing list ipxe-devel@lists.ipxe.org https://lists.ipxe.org/mailman/listinfo.cgi/ipxe-devel