Skip to content

Commit

Permalink
Add EDK2 build support [EXPERIMENTAL]
Browse files Browse the repository at this point in the history
* As per http://www.insanelymac.com/forum/topic/300222-updated-efi-filesystem-drivers-efifs-ported-to-edk2/:
  I've decided to port the efifs drivers to EDK2 fully (instead of good old GNU EFI) because I wanted a lot more filesystems supported under UEFI.
  I've now ported them all (all drivers from GRUB).
  This means there is a total of 36 FS drivers (newly) available.
  I've upgraded the routines so they support also BlockIo2 and DIskIo2 protocol from UEFI 2.3.1 if they are available.
  I also extended the SimpleFIleSystem interface to support the extended (OpenEx, ReadEx, WriteEx, FlushEx) functions.
  • Loading branch information
andyvand authored and pbatard committed Jul 28, 2017
1 parent 15a5ced commit ff7c0e0
Show file tree
Hide file tree
Showing 55 changed files with 3,300 additions and 121 deletions.
6 changes: 3 additions & 3 deletions 0000-GRUB-add-F2FS-support.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d9e9f44f0c043688cbf476634e8e39c768517e28 Mon Sep 17 00:00:00 2001
From 24863a4de9b40fc00a8f3c51cd08fde78ce1cb3a Mon Sep 17 00:00:00 2001
From: Pete Batard <[email protected]>
Date: Sun, 14 Aug 2016 19:22:13 +0200
Subject: [PATCH] Add F2FS support
Subject: [PATCH 1/4] Add F2FS support

* Taken from https://github.com/efidroid/uefi_edk2packages_GrubFSPkg
---
Expand Down Expand Up @@ -1305,5 +1305,5 @@ index 0000000..7fb256f
+ grub_fs_unregister (&grub_f2fs_fs);
+}
--
2.8.1.windows.1
2.9.3.windows.2

8 changes: 4 additions & 4 deletions 0001-GRUB-fixes-for-VS-Clang.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From bf6591faa32cf00aefb80180952dafa1c921c21f Mon Sep 17 00:00:00 2001
From d05789f5d54ed27069f1c54a1697a8ae28527134 Mon Sep 17 00:00:00 2001
From: Pete Batard <[email protected]>
Date: Wed, 13 Jul 2016 14:19:14 +0100
Subject: [PATCH 1/2] Clang/C2 compatibility fixes
Subject: [PATCH 2/4] Clang/C2 compatibility fixes

---
grub-core/fs/affs.c | 4 ++--
Expand Down Expand Up @@ -42,7 +42,7 @@ index 2f73449..053d1f7 100644
#else
#define expect(expr, value) (expr)
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index d1a54df..5bec00c 100644
index 3b633d5..9024c10 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -138,7 +138,7 @@ grub_puts_ (const char *s)
Expand Down Expand Up @@ -118,5 +118,5 @@ index 0bbdc6d..866b345 100644
#else
#define GRUB_TARGET_SIZEOF_LONG 8
--
2.8.1.windows.1
2.9.3.windows.2

59 changes: 36 additions & 23 deletions 0002-GRUB-fixes-for-VS-MSVC.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From 6848bbc5d6bb52448d2998cb3f3357de7273d255 Mon Sep 17 00:00:00 2001
From da61392469c17c75021380581cf84db47e18c584 Mon Sep 17 00:00:00 2001
From: Pete Batard <[email protected]>
Date: Sun, 14 Aug 2016 14:59:37 +0200
Subject: [PATCH] MSVC compatibility fixes, for packed structs, initialization,
etc
Date: Fri, 28 Jul 2017 12:54:37 +0100
Subject: [PATCH 3/4] MSVC compatibility fixes, for packed structs,
initialization, etc

---
grub-core/fs/affs.c | 2 ++
Expand All @@ -16,7 +16,7 @@ Subject: [PATCH] MSVC compatibility fixes, for packed structs, initialization,
grub-core/fs/jfs.c | 2 ++
grub-core/fs/nilfs2.c | 2 ++
grub-core/fs/ntfs.c | 2 ++
grub-core/fs/reiserfs.c | 7 +++++++
grub-core/fs/reiserfs.c | 16 +++++++++++++++-
grub-core/fs/sfs.c | 4 +++-
grub-core/fs/udf.c | 2 ++
grub-core/fs/ufs.c | 2 ++
Expand All @@ -26,16 +26,16 @@ Subject: [PATCH] MSVC compatibility fixes, for packed structs, initialization,
include/grub/btrfs.h | 3 +++
include/grub/hfs.h | 2 ++
include/grub/hfsplus.h | 6 ++++++
include/grub/misc.h | 8 ++++++++
include/grub/misc.h | 10 ++++++++++
include/grub/ntfs.h | 2 ++
include/grub/term.h | 4 ++--
include/grub/types.h | 36 +++++++++++++++++++++++++-----------
include/grub/zfs/zap_leaf.h | 17 ++++++++++++++---
include/grub/zfs/zio.h | 2 ++
27 files changed, 147 insertions(+), 38 deletions(-)
27 files changed, 157 insertions(+), 39 deletions(-)

diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c
index 25f8e68..38b7afd 100644
index 8580d81..26e4a33 100644
--- a/grub-core/fs/affs.c
+++ b/grub-core/fs/affs.c
@@ -30,6 +30,7 @@
Expand Down Expand Up @@ -75,7 +75,7 @@ index d2b490b..8d78fd6 100644
struct grub_bfs_data
{
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 9cffa91..c9617a0 100644
index 4849c1c..de1f023 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -48,6 +48,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
Expand Down Expand Up @@ -154,7 +154,7 @@ index 9cffa91..c9617a0 100644
stripen *= nsubstripes;
redundancy = nsubstripes;
diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
index 635c2c4..8f589f2 100644
index 8d8dc35..f3b5717 100644
--- a/grub-core/fs/fat.c
+++ b/grub-core/fs/fat.c
@@ -75,6 +75,7 @@ enum
Expand Down Expand Up @@ -189,7 +189,7 @@ index 635c2c4..8f589f2 100644

typedef struct grub_fat_dir_entry grub_fat_dir_node_t;

@@ -722,7 +726,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
@@ -726,7 +730,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
grub_dprintf ("exfat", "unknown primary type 0x%02x\n",
dir.entry_type);
}
Expand All @@ -198,7 +198,7 @@ index 635c2c4..8f589f2 100644
}

#else
@@ -849,7 +853,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
@@ -853,7 +857,7 @@ grub_fat_iterate_dir_next (grub_fshelp_node_t node,
return GRUB_ERR_NONE;
}

Expand Down Expand Up @@ -490,37 +490,47 @@ index 6f84688..4fa140e 100644
static char *
grub_ntfs_read_symlink (grub_fshelp_node_t node)
diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c
index 39736f6..b14de19 100644
index 39736f6..c3c65f2 100644
--- a/grub-core/fs/reiserfs.c
+++ b/grub-core/fs/reiserfs.c
@@ -42,6 +42,7 @@
@@ -42,15 +42,27 @@

GRUB_MOD_LICENSE ("GPLv3+");

+#ifndef _MSC_VER
+#ifndef MIN
#define MIN(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
@@ -51,6 +52,10 @@ GRUB_MOD_LICENSE ("GPLv3+");
_a < _b ? _a : _b; })
-
+#endif
+#ifndef MAX
#define MAX(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })
+#endif
+#else
+#ifndef MIN
+#define MIN(a, b) ((a)<(b)?(a):(b))
+#endif
+#ifndef MAX
+#define MAX(a, b) ((a)>(b)?(a):(b))
+#endif
+#endif

#define REISERFS_SUPER_BLOCK_OFFSET 0x10000
#define REISERFS_MAGIC_LEN 12
@@ -82,6 +87,7 @@ enum grub_reiserfs_item_type
@@ -82,6 +94,7 @@ enum grub_reiserfs_item_type
GRUB_REISERFS_UNKNOWN
};

+PRAGMA_BEGIN_PACKED
struct grub_reiserfs_superblock
{
grub_uint32_t block_count;
@@ -217,6 +223,7 @@ struct grub_reiserfs_directory_header
@@ -217,6 +230,7 @@ struct grub_reiserfs_directory_header
grub_uint16_t location;
grub_uint16_t state;
} GRUB_PACKED;
Expand Down Expand Up @@ -643,10 +653,10 @@ index 6e1fff9..b1589a0 100644
{

diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index f0af232..218d9a5 100644
index 9024c10..498ec83 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -968,7 +968,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
@@ -969,7 +969,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
{
grub_size_t len = 0;
grub_size_t fill;
Expand Down Expand Up @@ -754,10 +764,10 @@ index 117740a..5a8caf5 100644
/* Return the offset of the record with the index INDEX, in the node
NODE which is part of the B+ tree BTREE. */
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 2a9f87c..bc6fbec 100644
index 2a9f87c..e353dcd 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -27,11 +27,19 @@
@@ -27,12 +27,22 @@
#include <grub/i18n.h>
#include <grub/compiler.h>

Expand All @@ -774,9 +784,12 @@ index 2a9f87c..bc6fbec 100644
+#define ALIGN_DOWN(addr, align) \
+ ((addr) & ~(align - 1))
+#endif
+#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
+#endif
#define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; }

#define grub_dprintf(condition, ...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, __VA_ARGS__)
diff --git a/include/grub/ntfs.h b/include/grub/ntfs.h
index d1a6af6..203e014 100644
--- a/include/grub/ntfs.h
Expand Down Expand Up @@ -817,7 +830,7 @@ index 5ffb38f..cc6d92a 100644

static inline struct grub_term_coordinate
diff --git a/include/grub/types.h b/include/grub/types.h
index bb8a711..5b44fea 100644
index afcda13..3c9565a 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -26,10 +26,20 @@
Expand Down Expand Up @@ -951,5 +964,5 @@ index 19ce136..11ee51b 100644
/*
* Gang block headers are self-checksumming and contain an array
--
2.8.1.windows.1
2.9.3.windows.2

120 changes: 120 additions & 0 deletions 0003-GRUB-fixes-for-VS-EDK2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
From 846131b962c85048acffcd4f14f96a2d192f11f5 Mon Sep 17 00:00:00 2001
From: Pete Batard <[email protected]>
Date: Fri, 28 Jul 2017 16:56:39 +0100
Subject: [PATCH 4/4] EDK2 Compatibility fixes

---
grub-core/fs/zfs/zfs_lz4.c | 1 -
grub-core/io/gzio.c | 40 ++++++++++++++++++++--------------------
grub-core/lib/crypto.c | 4 ++--
3 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/grub-core/fs/zfs/zfs_lz4.c b/grub-core/fs/zfs/zfs_lz4.c
index 053d1f7..c20cf5f 100644
--- a/grub-core/fs/zfs/zfs_lz4.c
+++ b/grub-core/fs/zfs/zfs_lz4.c
@@ -73,7 +73,6 @@ static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest,
#define U32 grub_uint32_t
#define S32 grub_int32_t
#define U64 grub_uint64_t
-typedef grub_size_t size_t;

typedef struct _U16_S {
U16 v;
diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c
index 0f2ea6b..150e250 100644
--- a/grub-core/io/gzio.c
+++ b/grub-core/io/gzio.c
@@ -140,24 +140,24 @@ eat_field (grub_file_t file, int len)
#define OLD_GZIP_MAGIC grub_le_to_cpu16 (0x9E1F)

/* Compression methods (see algorithm.doc) */
-#define STORED 0
-#define COMPRESSED 1
-#define PACKED 2
-#define LZHED 3
+#define GZ_STORED 0
+#define GZ_COMPRESSED 1
+#define GZ_PACKED 2
+#define GZ_LZHED 3
/* methods 4 to 7 reserved */
-#define DEFLATED 8
-#define MAX_METHODS 9
+#define GZ_DEFLATED 8
+#define GZ_MAX_METHODS 9

/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
+#define GZ_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define GZ_CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
+#define GZ_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define GZ_ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define GZ_COMMENT 0x10 /* bit 4 set: file comment present */
+#define GZ_ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
+#define GZ_RESERVED 0xC0 /* bit 6,7: reserved */

-#define UNSUPPORTED_FLAGS (CONTINUATION | ENCRYPTED | RESERVED)
+#define GZ_UNSUPPORTED_FLAGS (GZ_CONTINUATION | GZ_ENCRYPTED | GZ_RESERVED)

/* inflate block codes */
#define INFLATE_STORED 0
@@ -201,14 +201,14 @@ test_gzip_header (grub_file_t file)
* problem occurs from here on, then we have corrupt or otherwise
* bad data, and the error should be reported to the user.
*/
- if (hdr.method != DEFLATED
- || (hdr.flags & UNSUPPORTED_FLAGS)
- || ((hdr.flags & EXTRA_FIELD)
+ if (hdr.method != GZ_DEFLATED
+ || (hdr.flags & GZ_UNSUPPORTED_FLAGS)
+ || ((hdr.flags & GZ_EXTRA_FIELD)
&& (grub_file_read (gzio->file, &extra_len, 2) != 2
|| eat_field (gzio->file,
grub_le_to_cpu16 (extra_len))))
- || ((hdr.flags & ORIG_NAME) && eat_field (gzio->file, -1))
- || ((hdr.flags & COMMENT) && eat_field (gzio->file, -1)))
+ || ((hdr.flags & GZ_ORIG_NAME) && eat_field (gzio->file, -1))
+ || ((hdr.flags & GZ_COMMENT) && eat_field (gzio->file, -1)))
return 0;

gzio->data_offset = grub_file_tell (gzio->file);
@@ -1183,7 +1183,7 @@ test_zlib_header (grub_gzio_t gzio)
flg = get_byte (gzio);

/* Check that compression method is DEFLATE. */
- if ((cmf & 0xf) != DEFLATED)
+ if ((cmf & 0xf) != GZ_DEFLATED)
{
/* TRANSLATORS: It's about given file having some strange format, not
complete lack of gzip support. */
diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c
index 683a8aa..620d439 100644
--- a/grub-core/lib/crypto.c
+++ b/grub-core/lib/crypto.c
@@ -462,7 +462,7 @@ grub_password_get (char buf[], unsigned buf_size)
if (key == '\n' || key == '\r')
break;

- if (key == '\e')
+ if (key == 0x1B)
{
cur_len = 0;
break;
@@ -487,7 +487,7 @@ grub_password_get (char buf[], unsigned buf_size)
grub_xputs ("\n");
grub_refresh ();

- return (key != '\e');
+ return (key != 0x1B);
}
#endif

--
2.9.3.windows.2

21 changes: 21 additions & 0 deletions EfiFsPkg.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## @file
# EfiFs Package
#
# Copyright (c) 2017, Pete Batard <[email protected]>
#
##

[Defines]
DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = EfiFsPkg
PACKAGE_UNI_FILE = EfiFsPkg.uni
PACKAGE_GUID = D65E40B8-BC4B-4625-9E5C-17C5726C39C3
PACKAGE_VERSION = 1.1

[UserExtensions.TianoCore."ExtraFiles"]
EfiFsPkgExtra.uni

[Includes]
grub/include
grub
grub/grub-core/lib/minilzo
Loading

0 comments on commit ff7c0e0

Please sign in to comment.