Skip to content

Commit

Permalink
add wimboot
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ive committed Dec 8, 2024
1 parent 64f2f65 commit c247b4a
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ jobs:
- name: 初始化
run: |
sudo apt update
sudo apt -y install gcc gcc-multilib nasm p7zip-full autoconf automake make patch binutils-dev liblzma-dev gcc-mingw-w64-i686
sudo apt -y install gcc gcc-multilib nasm p7zip-full autoconf automake make patch binutils-dev liblzma-dev gcc-mingw-w64-i686 libiberty-dev pesign gcab
- name: 编译
run: |
make -C umbr
make -j -C g4dext
make -j -C g4eext
cd wimboot && ./build.sh
zip -j g4dext-*.zip wimboot/wimboot
zip -j g4eext-*.zip wimboot/wimboot
# make -C grubutils/fbinst OSTYPE=MINGW CC=i686-w64-mingw32-gcc
# make -C grubutils/loadbin
# make -C grubutils/makemod OSTYPE=MINGW CC=i686-w64-mingw32-gcc
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ g4dext/zip
grubutils/wee/stage2_size.h
grubutils/wee/wee127/stage2_size.h
g4eext/bin
wimboot/build
wimboot/wimboot
180 changes: 180 additions & 0 deletions wimboot/0001_Add-EFI-LoadFile2-and-InitrdMedia-headers.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
From 0e9a72074727a11ee756c8c357fbb2953fca89de Mon Sep 17 00:00:00 2001
From: a1ive <[email protected]>
Date: Sat, 4 Nov 2023 10:32:17 +0800
Subject: [PATCH] Add EFI LoadFile2 and InitrdMedia headers

Signed-off-by: a1ive <[email protected]>
---
src/efi.h | 1 +
src/efi/Guid/LinuxEfiInitrdMedia.h | 30 ++++++++++++
src/efi/Protocol/LoadFile2.h | 78 ++++++++++++++++++++++++++++++
src/efifile.c | 2 +
src/efiguid.c | 5 ++
5 files changed, 116 insertions(+)
create mode 100644 src/efi/Guid/LinuxEfiInitrdMedia.h
create mode 100644 src/efi/Protocol/LoadFile2.h

diff --git a/src/efi.h b/src/efi.h
index afc7c42..239d64d 100644
--- a/src/efi.h
+++ b/src/efi.h
@@ -48,5 +48,6 @@ extern EFI_GUID efi_device_path_protocol_guid;
extern EFI_GUID efi_graphics_output_protocol_guid;
extern EFI_GUID efi_loaded_image_protocol_guid;
extern EFI_GUID efi_simple_file_system_protocol_guid;
+extern EFI_GUID efi_load_file2_protocol_guid;

#endif /* _EFI_H */
diff --git a/src/efi/Guid/LinuxEfiInitrdMedia.h b/src/efi/Guid/LinuxEfiInitrdMedia.h
new file mode 100644
index 0000000..5f62027
--- /dev/null
+++ b/src/efi/Guid/LinuxEfiInitrdMedia.h
@@ -0,0 +1,30 @@
+/** @file
+ GUID definition for the Linux Initrd media device path
+
+ Linux distro boot generally relies on an initial ramdisk (initrd) which is
+ provided by the loader, and which contains additional kernel modules (for
+ storage and network, for instance), and the initial user space startup code,
+ i.e., the code which brings up the user space side of the entire OS.
+
+ In order to provide a standard method to locate this initrd, the GUID defined
+ in this file is used to describe the device path for a LoadFile2 Protocol
+ instance that is responsible for loading the initrd file.
+
+ The kernel EFI Stub will locate and use this instance to load the initrd,
+ therefore the firmware/loader should install an instance of this to load the
+ relevant initrd.
+
+ Copyright (c) 2020, Arm, Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef LINUX_EFI_INITRD_MEDIA_GUID_H_
+#define LINUX_EFI_INITRD_MEDIA_GUID_H_
+
+#define LINUX_EFI_INITRD_MEDIA_GUID \
+ {0x5568e427, 0x68fc, 0x4f3d, {0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68}}
+
+extern EFI_GUID gLinuxEfiInitrdMediaGuid;
+
+#endif
diff --git a/src/efi/Protocol/LoadFile2.h b/src/efi/Protocol/LoadFile2.h
new file mode 100644
index 0000000..2d3a5fd
--- /dev/null
+++ b/src/efi/Protocol/LoadFile2.h
@@ -0,0 +1,78 @@
+/** @file
+ Load File protocol as defined in the UEFI 2.0 specification.
+
+ Load file protocol exists to supports the addition of new boot devices,
+ and to support booting from devices that do not map well to file system.
+ Network boot is done via a LoadFile protocol.
+
+ UEFI 2.0 can boot from any device that produces a LoadFile protocol.
+
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __EFI_LOAD_FILE2_PROTOCOL_H__
+#define __EFI_LOAD_FILE2_PROTOCOL_H__
+
+#define EFI_LOAD_FILE2_PROTOCOL_GUID \
+ { \
+ 0x4006c0c1, 0xfcb3, 0x403e, {0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \
+ }
+
+///
+/// Protocol Guid defined by UEFI2.1.
+///
+#define LOAD_FILE2_PROTOCOL EFI_LOAD_FILE2_PROTOCOL_GUID
+
+typedef struct _EFI_LOAD_FILE2_PROTOCOL EFI_LOAD_FILE2_PROTOCOL;
+
+/**
+ Causes the driver to load a specified file.
+
+ @param This Protocol instance pointer.
+ @param FilePath The device specific path of the file to load.
+ @param BootPolicy Should always be FALSE.
+ @param BufferSize On input the size of Buffer in bytes. On output with a return
+ code of EFI_SUCCESS, the amount of data transferred to
+ Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
+ the size of Buffer required to retrieve the requested file.
+ @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
+ then no the size of the requested file is returned in
+ BufferSize.
+
+ @retval EFI_SUCCESS The file was loaded.
+ @retval EFI_UNSUPPORTED BootPolicy is TRUE.
+ @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
+ BufferSize is NULL.
+ @retval EFI_NO_MEDIA No medium was present to load the file.
+ @retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
+ @retval EFI_NO_RESPONSE The remote system did not respond.
+ @retval EFI_NOT_FOUND The file was not found
+ @retval EFI_ABORTED The file load process was manually canceled.
+ @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current
+ directory entry. BufferSize has been updated with
+ the size needed to complete the request.
+
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_LOAD_FILE2)(
+ IN EFI_LOAD_FILE2_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN BOOLEAN BootPolicy,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer OPTIONAL
+ );
+
+///
+/// The EFI_LOAD_FILE_PROTOCOL is a simple protocol used to obtain files from arbitrary devices.
+///
+struct _EFI_LOAD_FILE2_PROTOCOL {
+ EFI_LOAD_FILE2 LoadFile;
+};
+
+extern EFI_GUID gEfiLoadFile2ProtocolGuid;
+
+#endif
diff --git a/src/efifile.c b/src/efifile.c
index 4ce2cd3..f5369d5 100644
--- a/src/efifile.c
+++ b/src/efifile.c
@@ -35,6 +35,8 @@
#include "wimfile.h"
#include "efi.h"
#include "efifile.h"
+#include "efi/Protocol/LoadFile2.h"
+#include "efi/Guid/LinuxEfiInitrdMedia.h"

/** bootmgfw.efi path within WIM */
static const wchar_t bootmgfw_path[] = L"\\Windows\\Boot\\EFI\\bootmgfw.efi";
diff --git a/src/efiguid.c b/src/efiguid.c
index 00313fa..6dc3755 100644
--- a/src/efiguid.c
+++ b/src/efiguid.c
@@ -31,6 +31,7 @@
#include "efi/Protocol/GraphicsOutput.h"
#include "efi/Protocol/LoadedImage.h"
#include "efi/Protocol/SimpleFileSystem.h"
+#include "efi/Protocol/LoadFile2.h"

/** Block I/O protocol GUID */
EFI_GUID efi_block_io_protocol_guid
@@ -51,3 +52,7 @@ EFI_GUID efi_loaded_image_protocol_guid
/** Simple file system protocol GUID */
EFI_GUID efi_simple_file_system_protocol_guid
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+
+/** Load File 2 protocol GUID */
+EFI_GUID efi_load_file2_protocol_guid
+ = EFI_LOAD_FILE2_PROTOCOL_GUID;
22 changes: 22 additions & 0 deletions wimboot/0002_Fix-optinal-header-in-wimboot-2.8.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From 0890cc86c970659dcbefdf5c09c80d975f7184e2 Mon Sep 17 00:00:00 2001
From: MexIT <[email protected]>
Date: Tue, 29 Oct 2024 01:24:47 +0000
Subject: [PATCH] Fix optinal header in wimboot 2.8.0

Thanks @Melanie.Malachite (#1)
---
src/elf2efi.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/src/elf2efi.c b/src/elf2efi.c
index 3109486..39c8d66 100644
--- a/src/elf2efi.c
+++ b/src/elf2efi.c
@@ -249,6 +249,7 @@ static struct pe_header efi_pe_header = {
.MinorLinkerVersion = 42,
.SectionAlignment = EFI_IMAGE_ALIGN,
.FileAlignment = EFI_FILE_ALIGN,
+ .MajorImageVersion = 1,
.SizeOfImage = EFI_IMAGE_ALIGN,
.SizeOfHeaders =
( sizeof ( efi_pe_header ) -
103 changes: 103 additions & 0 deletions wimboot/0003_Provide-common-vdisk_read_mem_file-cpio-handler.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
From 395f15bb10d35e9f48381898ea3807032e5f8585 Mon Sep 17 00:00:00 2001
From: a1ive <[email protected]>
Date: Sat, 4 Nov 2023 10:51:24 +0800
Subject: [PATCH] Provide common vdisk_read_mem_file cpio handler

https://lists.ipxe.org/pipermail/ipxe-devel/2018-November/006339.html

Signed-off-by: a1ive <[email protected]>
---
src/main.c | 20 +++-----------------
src/vdisk.c | 13 +++++++++++++
src/vdisk.h | 2 ++
3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/main.c b/src/main.c
index 371c822..7274344 100644
--- a/src/main.c
+++ b/src/main.c
@@ -226,20 +226,6 @@ static int is_empty_pgh ( const void *pgh ) {
return ( ( dwords[0] | dwords[1] | dwords[2] | dwords[3] ) == 0 );
}

-/**
- * 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
*
@@ -337,7 +323,7 @@ static struct vdisk_file * add_bootmgr ( const void *data, size_t len ) {

/* Add decompressed image */
return vdisk_add_file ( "bootmgr.exe", initrd,
- decompressed_len, read_file );
+ decompressed_len, vdisk_read_mem_file );
}

DBG ( "...no embedded bootmgr.exe found\n" );
@@ -356,7 +342,7 @@ static int add_file ( const char *name, void *data, size_t len ) {
struct vdisk_file *file;

/* Store file */
- file = vdisk_add_file ( name, data, len, read_file );
+ file = vdisk_add_file ( name, data, len, vdisk_read_mem_file );

/* Check for special-case files */
if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) {
@@ -467,7 +453,7 @@ int main ( void ) {
/* Read bootmgr.exe into memory */
if ( ! bootmgr )
die ( "FATAL: no bootmgr.exe\n" );
- if ( bootmgr->read == read_file ) {
+ if ( bootmgr->read == vdisk_read_mem_file ) {
raw_pe = bootmgr->opaque;
} else {
padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) &
diff --git a/src/vdisk.c b/src/vdisk.c
index 7885a5b..6685b14 100644
--- a/src/vdisk.c
+++ b/src/vdisk.c
@@ -613,6 +613,19 @@ void vdisk_read ( uint64_t lba, unsigned int count, void *data ) {
DBG2 ( "\n" );
}

+/**
+ * Read virtual file from memory
+ *
+ * @v file Virtual file
+ * @v data Data buffer
+ * @v offset Offset
+ * @v len Length
+ */
+void vdisk_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
*
diff --git a/src/vdisk.h b/src/vdisk.h
index 7cae51c..b3b526b 100644
--- a/src/vdisk.h
+++ b/src/vdisk.h
@@ -611,6 +611,8 @@ struct vdisk_file {
extern struct vdisk_file vdisk_files[VDISK_MAX_FILES];

extern void vdisk_read ( uint64_t lba, unsigned int count, void *data );
+extern void vdisk_read_mem_file ( struct vdisk_file *file, void *data,
+ size_t offset, size_t len );
extern struct vdisk_file *
vdisk_add_file ( const char *name, void *opaque, size_t len,
void ( * read ) ( struct vdisk_file *file, void *data,
Loading

0 comments on commit c247b4a

Please sign in to comment.