[REGRESSION] Re: [PATCH v4 5/5] efi: Use generic EFI loader for x86_64 and i386

2024-05-16 Thread Jan Čermák

Hi Ard, everyone,

On 23. 05. 23 17:31, Ard Biesheuvel wrote:
> Switch the x86 based EFI platform builds to the generic EFI loader,
> ...

We use GRUB as the loader for the Home Assistant Operating System (based 
on Buildroot, using mostly unpatched GRUB 2 build [1]) and after 
updating to the latest 2.12 release, this patch (commit 
cfbfae1aef0694b416aa199291cfef7596cdfc20) has been identified to break 
boot on Intel Atom NM10, at least with upstream kernel 6.6 with 
CONFIG_EFI_STUB enabled. I reproduced it on Intel D525MW board, and 
there are some more reports from HAOS users on Github [2].


Initially, we decided to revert the patch [3] for the time being, 
however, while it fixed issue for users running on those rather old 
boards, it broke boot [4] on the comparatively newer Fujitsu Esprimo 
Q920. From the user reports, there is no BIOS update available that will 
make any difference but reverting to a "vanilla" 2.12 fixes that.


Do you have a clue what could have gone wrong, either with the original 
patch, or why the revert breaks the other platform? I'll be happy to get 
any details and perform tests on the NM10 board I have here. 
Alternatively, I can also ask users with the Q920 for more details or do 
some tests.


Regards,
Jan

[1] 
https://github.com/home-assistant/buildroot/tree/2024.02.x-haos/boot/grub2

[2] https://github.com/home-assistant/operating-system/issues/3305
[3] https://github.com/home-assistant/operating-system/pull/3324
[4] https://github.com/home-assistant/operating-system/issues/3348

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [REGRESSION] Re: [PATCH v4 5/5] efi: Use generic EFI loader for x86_64 and i386

2024-05-16 Thread Ard Biesheuvel
On Thu, 16 May 2024 at 14:24, Jan Čermák  wrote:
>
> Hi Ard, everyone,
>
> On 23. 05. 23 17:31, Ard Biesheuvel wrote:
>  > Switch the x86 based EFI platform builds to the generic EFI loader,
>  > ...
>
> We use GRUB as the loader for the Home Assistant Operating System (based
> on Buildroot, using mostly unpatched GRUB 2 build [1]) and after
> updating to the latest 2.12 release, this patch (commit
> cfbfae1aef0694b416aa199291cfef7596cdfc20) has been identified to break
> boot on Intel Atom NM10, at least with upstream kernel 6.6 with
> CONFIG_EFI_STUB enabled. I reproduced it on Intel D525MW board, and
> there are some more reports from HAOS users on Github [2].
>
> Initially, we decided to revert the patch [3] for the time being,
> however, while it fixed issue for users running on those rather old
> boards, it broke boot [4] on the comparatively newer Fujitsu Esprimo
> Q920. From the user reports, there is no BIOS update available that will
> make any difference but reverting to a "vanilla" 2.12 fixes that.
>
> Do you have a clue what could have gone wrong, either with the original
> patch, or why the revert breaks the other platform? I'll be happy to get
> any details and perform tests on the NM10 board I have here.
> Alternatively, I can also ask users with the Q920 for more details or do
> some tests.
>

Upstream GRUB 2.06 does not boot Linux via the EFI stub, it uses the
legacy EFI boot method where the Linux kernel is only entered after
the EFI firmware has been shut down.

GRUB 2.12 changed this, and will know always use the pure EFI boot
sequence, relying on the EFI stub in the Linux kernel to shut down the
firmware services.

Does your Kconfig have EFI_DISABLE_PCI_DMA enabled by any chance? That
could definitely produce the issues you are observing.

In any case, given that you never relied on the EFI stub in the past
on x86_64 (as GRUB 2.06 does not rely on it), you could just disable
that in your Kconfig.

That of course does not solve the Fujitsu issue, which apparently
requires boot via the EFI stub, but I don't have a solution for that -
I suppose that simply never worked with the old 'working' version of
the OS?

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 3/3] keccak: Disable acceleration with SSE asm

2024-05-16 Thread Vladimir Serbinenko
---
 grub-core/lib/libgcrypt/cipher/keccak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/lib/libgcrypt/cipher/keccak.c 
b/grub-core/lib/libgcrypt/cipher/keccak.c
index 11e64b3e7..8b570263b 100644
--- a/grub-core/lib/libgcrypt/cipher/keccak.c
+++ b/grub-core/lib/libgcrypt/cipher/keccak.c
@@ -251,7 +251,7 @@ keccak_absorb_lane32bi(u32 *lane, u32 x0, u32 x1)
 /* Construct generic 64-bit implementation. */
 #ifdef USE_64BIT
 
-#if __GNUC__ >= 4 && defined(__x86_64__)
+#if __GNUC__ >= 4 && defined(__x86_64__) && 0
 
 static inline void absorb_lanes64_8(u64 *dst, const byte *in)
 {
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/3] Adjust import script, definitions and API users for libgcrypt 1.10

2024-05-16 Thread Vladimir Serbinenko
---
 autogen.sh |   1 +
 conf/Makefile.common   |   4 +-
 grub-core/Makefile.core.def|  36 +-
 grub-core/commands/hashsum.c   |   2 +-
 grub-core/commands/legacycfg.c |   6 +-
 grub-core/commands/pgp.c   | 114 +---
 grub-core/commands/xnu_uuid.c  |   2 +-
 grub-core/disk/cryptodisk.c|   2 +-
 grub-core/io/gzio.c|   2 +-
 grub-core/io/lzopio.c  |   2 +-
 grub-core/lib/adler32.c|  21 +-
 grub-core/lib/b64dec.c | 293 +
 grub-core/lib/crc64.c  |  24 +-
 grub-core/lib/crypto.c | 245 +++-
 grub-core/lib/libgcrypt/src/gcrypt-int.h   |  51 --
 grub-core/lib/libgcrypt_wrap/cipher_wrap.h |  12 +-
 grub-core/lib/libgcrypt_wrap/md.c  | 687 +
 grub-core/lib/libgcrypt_wrap/mem.c |  83 ++-
 grub-core/lib/xzembed/xz_dec_stream.c  |  18 +-
 grub-core/tests/dsa_sexp_test.c| 107 
 grub-core/tests/rsa_sexp_test.c|  81 +++
 include/grub/crypto.h  | 261 ++--
 include/grub/gcrypt/gpg-error.h|   9 +
 util/grub-fstest.c |   2 +-
 util/import_gcry.py| 122 ++--
 util/import_gcrypt_inth.sed|  17 +
 util/import_gcrypth.sed|   2 -
 27 files changed, 1942 insertions(+), 264 deletions(-)
 create mode 100644 grub-core/lib/b64dec.c
 create mode 100644 grub-core/lib/libgcrypt_wrap/md.c
 create mode 100644 grub-core/tests/dsa_sexp_test.c
 create mode 100644 grub-core/tests/rsa_sexp_test.c
 create mode 100644 util/import_gcrypt_inth.sed

diff --git a/autogen.sh b/autogen.sh
index 195daa541..04779c955 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -35,6 +35,7 @@ ${PYTHON} util/import_unicode.py unicode/UnicodeData.txt 
unicode/BidiMirroring.t
 echo "Importing libgcrypt..."
 ${PYTHON} util/import_gcry.py grub-core/lib/libgcrypt/ grub-core
 sed -n -f util/import_gcrypth.sed < grub-core/lib/libgcrypt/src/gcrypt.h.in > 
include/grub/gcrypt/gcrypt.h
+sed -n -f util/import_gcrypt_inth.sed < 
grub-core/lib/libgcrypt/src/gcrypt-int.h >> include/grub/gcrypt/gcrypt.h
 if [ -f include/grub/gcrypt/g10lib.h ]; then
 rm include/grub/gcrypt/g10lib.h
 fi
diff --git a/conf/Makefile.common b/conf/Makefile.common
index b8f216f6c..1fd3fc9da 100644
--- a/conf/Makefile.common
+++ b/conf/Makefile.common
@@ -81,8 +81,8 @@ CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib 
-I$(top_srcdir)/grub-co
 CFLAGS_POSIX = -fno-builtin
 CPPFLAGS_POSIX = -I$(top_srcdir)/grub-core/lib/posix_wrap
 
-CFLAGS_GCRY = -Wno-error -Wno-missing-field-initializers -Wno-redundant-decls 
-Wno-undef $(CFLAGS_POSIX)
-CPPFLAGS_GCRY = -I$(top_srcdir)/grub-core/lib/libgcrypt_wrap $(CPPFLAGS_POSIX) 
-D_GCRYPT_IN_LIBGCRYPT=1 -I$(top_srcdir)/include/grub/gcrypt
+CFLAGS_GCRY = -Wno-error=sign-compare -Wno-error=shift-count-overflow 
-Wno-missing-field-initializers -Wno-redundant-decls -Wno-undef $(CFLAGS_POSIX)
+CPPFLAGS_GCRY = -I$(top_srcdir)/grub-core/lib/libgcrypt_wrap $(CPPFLAGS_POSIX) 
-D_GCRYPT_IN_LIBGCRYPT=1 -D_GCRYPT_CONFIG_H_INCLUDED=1 -DHAVE_STRTOUL=1 
-I$(top_srcdir)/include/grub/gcrypt
 
 CPPFLAGS_EFIEMU = -I$(top_srcdir)/grub-core/efiemu/runtime
 
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 1571421d7..59270fc9a 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -971,8 +971,8 @@ module = {
 module = {
   name = pgp;
   common = commands/pgp.c;
-  cflags = '$(CFLAGS_POSIX)';
-  cppflags = '-I$(srcdir)/lib/posix_wrap';
+  cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare';
+  cppflags = '$(CPPFLAGS_GCRY)';
 };
 
 module = {
@@ -2165,6 +2165,22 @@ module = {
   common = tests/setjmp_test.c;
 };
 
+module = {
+  name = dsa_sexp_test;
+  common = tests/dsa_sexp_test.c;
+
+  cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare';
+  cppflags = '$(CPPFLAGS_GCRY)';
+};
+
+module = {
+  name = rsa_sexp_test;
+  common = tests/rsa_sexp_test.c;
+
+  cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare';
+  cppflags = '$(CPPFLAGS_GCRY)';
+};
+
 module = {
   name = signature_test;
   common = tests/signature_test.c;
@@ -2519,7 +2535,23 @@ module = {
   common = lib/libgcrypt-grub/mpi/mpicoder.c;
   common = lib/libgcrypt-grub/mpi/mpih-rshift.c;
   common = lib/libgcrypt-grub/mpi/mpi-inline.c;
+  common = lib/libgcrypt-grub/mpi/mpih-const-time.c;
+  common = lib/libgcrypt-grub/mpi/mpi-scan.c;
+  common = lib/libgcrypt-grub/src/const-time.c;
   common = lib/libgcrypt_wrap/mem.c;
+  common = lib/libgcrypt_wrap/md.c;
+
+  cflags = '$(CFLAGS_GCRY) -Wno-redundant-decls -Wno-sign-compare 
-Wno-unused-but-set-variable';
+  cppflags = '$(CPPFLAGS_GCRY)';
+};
+
+module = {
+  name = pubkey;
+  common = lib/libgcrypt-grub/cipher/pubkey-util.c;
+  common = lib/

[PATCH 0/3] Upgrade to libgcrypt 1.10.3

2024-05-16 Thread Vladimir 'phcoder' Serbinenko
This series of patches upgrades to libgcrypt 1.10.3
First one just imports libgcrypt tarball as-is
Second one updates import script
Third one add a small adjustments to make it work with GRUB x64

-- 
Regards
Vladimir 'phcoder' Serbinenko

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] bfs: Fix improper free() on non-existing files

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 grub-core/fs/bfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/fs/bfs.c b/grub-core/fs/bfs.c
index 07cb3e3ac..9bc478ce8 100644
--- a/grub-core/fs/bfs.c
+++ b/grub-core/fs/bfs.c
@@ -808,7 +808,7 @@ find_file (const char *path, grub_disk_t disk,
 .disk = disk,
 .sb = sb,
   };
-  struct grub_fshelp_node *found;
+  struct grub_fshelp_node *found = NULL;
 
   err = read_extent (disk, sb, &sb->root_dir, 0, 0, &root.ino,
 sizeof (root.ino));
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add --noefistub option for linux

2024-05-16 Thread Vladimir Serbinenko
In some cases like loading kernel from native disk (e.g. nvme) not
supported by EFI in question efi stub is not an option. Allow
user to disable efi stub and fallback to older protocol
---
 grub-core/loader/efi/linux.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
index bfbd95aee..0bf9d9cbb 100644
--- a/grub-core/loader/efi/linux.c
+++ b/grub-core/loader/efi/linux.c
@@ -459,10 +459,18 @@ grub_cmd_linux (grub_command_t cmd __attribute__ 
((unused)),
   grub_file_t file = 0;
   struct linux_arch_kernel_header lh;
   grub_err_t err;
+  int force_legacy = 0;
 
   grub_dl_ref (my_mod);
 
-  if (grub_is_shim_lock_enabled () == true)
+  if (argc > 0 && grub_strcmp(argv[0], "--noefistub") == 0)
+{
+  force_legacy = 1;
+  argv++;
+  argc--;
+}
+
+  if (grub_is_shim_lock_enabled () == true || force_legacy)
 {
 #if defined(__i386__) || defined(__x86_64__)
   grub_dprintf ("linux", "shim_lock enabled, falling back to legacy Linux 
kernel loader\n");
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Implement NVMe native disk support

2024-05-16 Thread Vladimir Serbinenko
This is useful 2-fold:
1) On coreboot port it allows to boot from NVMe devices
2) On older systems you can install NVMe via PCIe adapter and boot from
   it

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/Makefile.core.def |   6 +
 grub-core/commands/nativedisk.c |   3 +-
 grub-core/disk/nvme.c   | 642 
 include/grub/disk.h |   1 +
 4 files changed, 651 insertions(+), 1 deletion(-)
 create mode 100644 grub-core/disk/nvme.c

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..47ac8bf3f 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1305,6 +1305,12 @@ module = {
   enable = pci;
 };
 
+module = {
+  name = nvme;
+  common = disk/nvme.c;
+  enable = pci;
+};
+
 module = {
   name = pata;
   common = disk/pata.c;
diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c
index 580c8d3b0..a431a066a 100644
--- a/grub-core/commands/nativedisk.c
+++ b/grub-core/commands/nativedisk.c
@@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 static const char *modnames_def[] = {
   /* FIXME: autogenerate this.  */
 #if defined (__i386__) || defined (__x86_64__) || defined 
(GRUB_MACHINE_MIPS_LOONGSON)
-  "pata", "ahci", "usbms", "ohci", "uhci", "ehci"
+  "pata", "ahci", "usbms", "ohci", "uhci", "ehci", "nvme"
 #elif defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
   "pata"
 #else
@@ -77,6 +77,7 @@ get_uuid (const char *name, char **uuid, int getnative)
   /* Native disks.  */
 case GRUB_DISK_DEVICE_ATA_ID:
 case GRUB_DISK_DEVICE_SCSI_ID:
+case GRUB_DISK_DEVICE_NVME_ID:
 case GRUB_DISK_DEVICE_XEN:
   if (getnative)
break;
diff --git a/grub-core/disk/nvme.c b/grub-core/disk/nvme.c
new file mode 100644
index 0..b2949308d
--- /dev/null
+++ b/grub-core/disk/nvme.c
@@ -0,0 +1,642 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *
+ *  Copyright (C) 2019 secunet Security Networks AG
+ *  Copyright (C) 2024  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Additionally this file can be distributed under 3-clause BSD license.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define NVME_CC_EN (1 <<  0)
+#define NVME_CC_CSS(0 <<  4)
+#define NVME_CC_MPS(0 <<  7)
+#define NVME_CC_AMS(0 << 11)
+#define NVME_CC_SHN(0 << 14)
+#define NVME_CC_IOSQES (6 << 16)
+#define NVME_CC_IOCQES (4 << 20)
+
+#define NVME_QUEUE_SIZE 2
+#define NVME_SQ_ENTRY_SIZE 64
+#define NVME_CQ_ENTRY_SIZE 16
+
+struct grub_nvme_mmio_reg
+{
+  /*  0 */ grub_uint64_t cap;
+  /*  8 */ grub_uint32_t vs;
+  /*  c */ grub_uint32_t intms;
+  /* 10 */ grub_uint32_t intmc;
+  /* 14 */ grub_uint32_t controller_config;
+  /* 18 */ grub_uint32_t reserved1;
+  /* 1c */ grub_uint32_t controller_status;
+  /* 20 */ grub_uint32_t nssr;
+  /* 24 */ grub_uint32_t aqa;
+  /* 28 */ grub_uint64_t asq;
+  /* 30 */ grub_uint64_t acq;
+};
+
+struct nvme_ident_block
+{
+  /*  0 */ grub_uint64_t nsze;
+  /*  8 */ grub_uint64_t ncap;
+  /* 10 */ grub_uint64_t nuse;
+  /* 18 */ grub_uint8_t nsfeat;
+  /* 19 */ grub_uint8_t nlbaf;
+  /* 1a */ grub_uint8_t flbas;
+  /* 1b */ grub_uint8_t mc;
+  /* 1c */ grub_uint32_t fill[(0x80 - 0x1c) / 4];
+  /* 80 */ grub_uint32_t lbaf[64];
+};
+
+struct grub_nvme_device
+{
+  struct grub_nvme_device *next;
+  struct grub_nvme_device **prev;
+  volatile struct grub_nvme_mmio_reg *regs;
+  struct grub_pci_dma_chunk *prp_list;
+  struct grub_pci_dma_chunk *sq_buffer;
+  struct grub_pci_dma_chunk *cq_buffer;
+  struct grub_pci_dma_chunk *ioc_buffer;
+  struct grub_pci_dma_chunk *ios_buffer;
+  struct grub_pci_dma_chunk *ident_buffer;
+  int num;
+  grub_uint64_t total_sectors;
+  int log_sector_size;
+
+  struct {
+volatile void *base;
+volatile grub_uint32_t *bell;
+grub_uint16_t idx; // bool pos 0 or 1
+grub_uint16_t round; // bool round 0 or 1+0xd
+  } queue[4];
+};
+
+struct nvme_s_queue_entry {
+  grub_uint32_t dw[16];
+};
+
+struct nvme_c_queue_entry {
+  grub_uint32_t dw[4];
+};
+
+static struct grub_nvme_device *grub_nvme_devices;
+static int numdevs;
+
+enum nvme_queue {
+  NVME_ADMIN_QUEUE = 0,
+  ads = 0,
+  adc = 1,
+  NVME_IO_QUEUE = 2,
+  ios = 2,
+  ioc = 3,
+};
+
+static int
+nvme_cmd(struct grub_nvme_device *nvme, enum nvme_queue 

[PATCH 2/2] Support qcow in grub-fstest

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 util/grub-fstest.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/util/grub-fstest.c b/util/grub-fstest.c
index 7ff9037b8..3c4fa26c6 100644
--- a/util/grub-fstest.c
+++ b/util/grub-fstest.c
@@ -383,12 +383,14 @@ static int cmd = 0;
 static char *debug_str = NULL;
 static char **args = NULL;
 static int mount_crypt = 0;
+static int mount_qcow = 0;
 
 static void
 fstest (int n)
 {
   char *host_file;
   char *loop_name;
+  const char *loopback_cmd = mount_qcow ? "qcow" : "loopback";
   int i;
 
   for (i = 0; i < num_disks; i++)
@@ -405,8 +407,8 @@ fstest (int n)
   argv[0] = loop_name;
   argv[1] = host_file;
 
-  if (execute_command ("loopback", 2, argv))
-grub_util_error (_("`loopback' command fails: %s"), grub_errmsg);
+  if (execute_command (loopback_cmd, 2, argv))
+grub_util_error (_("`%s' command fails: %s"), loopback_cmd, 
grub_errmsg);
 
   grub_free (loop_name);
   grub_free (host_file);
@@ -530,6 +532,7 @@ static struct argp_option options[] = {
   {"diskcount", 'c', N_("NUM"),   0, N_("Specify the number of input 
files."),   2},
   {"debug", 'd', N_("STRING"),   0, N_("Set debug environment 
variable."),  2},
   {"crypto",   'C', NULL, 0, N_("Mount crypto devices."), 2},
+  {"qcow",  'q', NULL, 0, N_("Mount qcow images."), 2},
   {"zfs-key",  'K',
/* TRANSLATORS: "prompt" is a keyword.  */
N_("FILE|prompt"), 0, N_("Load zfs crypto key."), 2},
@@ -597,6 +600,10 @@ argp_parser (int key, char *arg, struct argp_state *state)
   mount_crypt = 1;
   return 0;
 
+case 'q':
+  mount_qcow = 1;
+  return 0;
+
 case 's':
   skip = grub_strtoul (arg, &p, 0);
   if (*p == 's')
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 1/2] Support qcow disks in GRUB

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 Makefile.util.def   |   1 +
 grub-core/Makefile.core.def |   6 +
 grub-core/commands/nativedisk.c |   1 +
 grub-core/disk/qcow.c   | 464 
 include/grub/disk.h |   1 +
 5 files changed, 473 insertions(+)
 create mode 100644 grub-core/disk/qcow.c

diff --git a/Makefile.util.def b/Makefile.util.def
index 9432365a9..d8b556afd 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -71,6 +71,7 @@ library = {
   common = grub-core/commands/ls.c;
   common = grub-core/disk/dmraid_nvidia.c;
   common = grub-core/disk/loopback.c;
+  common = grub-core/disk/qcow.c;
   common = grub-core/disk/lvm.c;
   common = grub-core/disk/mdraid_linux.c;
   common = grub-core/disk/mdraid_linux_be.c;
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..da65ba68c 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1204,6 +1204,12 @@ module = {
   common = disk/loopback.c;
 };
 
+module = {
+  name = qcow;
+  common = disk/qcow.c;
+  cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd';
+};
+
 module = {
   name = cryptodisk;
   common = disk/cryptodisk.c;
diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c
index 580c8d3b0..3e9bafac7 100644
--- a/grub-core/commands/nativedisk.c
+++ b/grub-core/commands/nativedisk.c
@@ -98,6 +98,7 @@ get_uuid (const char *name, char **uuid, int getnative)
 
   /* FIXME: those probably need special handling.  */
 case GRUB_DISK_DEVICE_LOOPBACK_ID:
+case GRUB_DISK_DEVICE_QCOW_ID:
 case GRUB_DISK_DEVICE_DISKFILTER_ID:
 case GRUB_DISK_DEVICE_CRYPTODISK_ID:
   break;
diff --git a/grub-core/disk/qcow.c b/grub-core/disk/qcow.c
new file mode 100644
index 0..ed99b4c78
--- /dev/null
+++ b/grub-core/disk/qcow.c
@@ -0,0 +1,464 @@
+/* qcow.c - command to add loopback qcow devices.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2024  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define QCOW_MAGIC 0x514649fb
+#define LX_OFFSET_MASK 0xfffe00LL
+struct qcow_header
+{
+  grub_uint32_t magic;
+  grub_uint32_t version;
+  grub_uint64_t backing_file_offset;
+  grub_uint32_t backing_file_size;
+  grub_uint32_t cluster_bits;
+  grub_uint64_t size;
+  grub_uint32_t crypt_method;
+  grub_uint32_t l1_size;
+  grub_uint64_t l1_table_offset;
+  grub_uint64_t refcount_table_offset;
+  grub_uint32_t refcount_table_clusters;
+  grub_uint32_t nb_snapshots;
+  grub_uint64_t snapshots_offset;
+
+  /* v3 only */
+  grub_uint64_t feat_incompat;
+  grub_uint64_t feat_compat;
+  grub_uint64_t feat_autoclear;
+  grub_uint32_t refcount_order;
+  grub_uint32_t header_length;
+
+  /* Only if v3 and header_length allows it.  */
+  grub_uint8_t compression_type;
+};
+
+struct qcow_header_extension
+{
+  grub_uint32_t type;
+  grub_uint32_t length;
+};
+
+struct grub_qcow
+{
+  struct grub_qcow *next;
+  char *devname;
+  grub_file_t file;
+  unsigned long id;
+  struct qcow_header head;
+  grub_uint64_t *l1;
+  grub_uint64_t *l2_0;
+  grub_uint64_t *l2_cache;
+  grub_uint64_t l2_cache_current;
+  grub_uint8_t compression_type;
+};
+
+static struct grub_qcow *qcow_list;
+static unsigned long last_id = 0;
+
+static const struct grub_arg_option options[] =
+  {
+/* TRANSLATORS: The disk is simply removed from the list of available ones,
+   not wiped, avoid to scare user.  */
+{"delete", 'd', 0, N_("Delete the specified qcow drive."), 0, 0},
+{0, 0, 0, 0, 0, 0}
+  };
+
+static grub_err_t
+open_qcow (struct grub_qcow *qcow)
+{
+  grub_file_read (qcow->file, &qcow->head, sizeof(qcow->head));
+  if (grub_errno)
+return grub_errno;
+  if (qcow->head.magic != grub_cpu_to_be32_compile_time(QCOW_MAGIC))
+return grub_error(GRUB_ERR_BAD_ARGUMENT, "invalid qcow magic");
+  if (qcow->head.version != grub_cpu_to_be32_compile_time(2)
+  && qcow->head.version != grub_cpu_to_be32_compile_time(3))
+return grub_error(GRUB_ERR_NOT_IMPLEMENTED_YET, "unsupported qcow 
version");
+  if (qcow->head.backing_file_offset || qcow->head.backing_file_size)
+return grub_error(GRUB_ERR_NOT_IMPLEMENTED_YET, "qcow backi

[PATCH] Add Fedora-specific font paths

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 84a202c6e..c76a29af4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1847,7 +1847,7 @@ if test "x$with_dejavufont" = x; then
   # search in well-known directories
   if test x"$starfield_excuse" = x; then
  for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
-   for dir in . /usr/src /usr/share/fonts/X11/misc 
/usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu 
/usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF 
/usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF; do
+   for dir in . /usr/src /usr/share/fonts/X11/misc 
/usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu 
/usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF 
/usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF 
/usr/share/fonts/dejavu-sans-fonts; do
   if test -f "$dir/DejaVuSans.$ext"; then
 DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
 break 2
@@ -1875,7 +1875,7 @@ AC_ARG_WITH([unifont],
 
 if test "x$with_unifont" = x; then
   # search in well-known directories
-  for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
+  for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz otf otf.gz; do
 for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont 
/usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc 
/usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont 
/usr/local/share/fonts/unifont; do
   if test -f "$dir/unifont.$ext"; then
 md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add convenience TARGET_CROSS

2024-05-16 Thread Vladimir Serbinenko
This allows to set up cross environment with just 3 parameters: target,
platform and TARGET_CROSS

Signed-off-by: Vladimir Serbinenko 
---
 configure.ac | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 84a202c6e..cacbdb6ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -539,12 +539,12 @@ if test "x$target_alias" != x && test "x$host_alias" != 
"x$target_alias"; then
   tmp_ac_tool_prefix="$ac_tool_prefix"
   ac_tool_prefix=$target_alias-
 
-  AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
+  AC_CHECK_TOOLS(TARGET_CC, [${TARGET_CROSS}gcc ${TARGET_CROSS}egcs 
${TARGET_CROSS}cc],
  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set 
TARGET_CC manually.])])
-  AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
-  AC_CHECK_TOOL(TARGET_STRIP, strip)
-  AC_CHECK_TOOL(TARGET_NM, nm)
-  AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
+  AC_CHECK_TOOL(TARGET_OBJCOPY, ${TARGET_CROSS}objcopy)
+  AC_CHECK_TOOL(TARGET_STRIP, ${TARGET_CROSS}strip)
+  AC_CHECK_TOOL(TARGET_NM, ${TARGET_CROSS}nm)
+  AC_CHECK_TOOL(TARGET_RANLIB, ${TARGET_CROSS}ranlib)
 
   ac_tool_prefix="$tmp_ac_tool_prefix"
 else
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add missing cast in compile-time byteswaps

2024-05-16 Thread Vladimir Serbinenko
Without them 0x80LL is 32-bit byte-swapped to 0x8000 instead
of correct 0x8000

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/types.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/grub/types.h b/include/grub/types.h
index 064066e2e..45079bf65 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -196,8 +196,8 @@ static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t 
_x)
return (grub_uint16_t) ((_x << 8) | (_x >> 8));
 }
 
-#define grub_swap_bytes16_compile_time(x) x) & 0xff) << 8) | (((x) & 
0xff00) >> 8))
-#define grub_swap_bytes32_compile_time(x) x) & 0xff) << 24) | (((x) & 
0xff00) << 8) | (((x) & 0xff) >> 8) | (((x) & 0xff00UL) >> 24))
+#define grub_swap_bytes16_compile_time(x) ((grub_uint16_t)x) & 0xff) << 8) 
| (((x) & 0xff00) >> 8)))
+#define grub_swap_bytes32_compile_time(x) ((grub_uint32_t)x) & 0xff) << 
24) | (((x) & 0xff00) << 8) | (((x) & 0xff) >> 8) | (((x) & 0xff00UL) 
>> 24)))
 #define grub_swap_bytes64_compile_time(x)  \
 ({ \
grub_uint64_t _x = (x); \
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Mark vdev_zaps_v2 and head_errlog as supported

2024-05-16 Thread Vladimir Serbinenko
We don't need any actual adjustments as we don't use the affected
structures

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/fs/zfs/zfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index b5453e006..dbe4ea503 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -291,6 +291,8 @@ static const char *spa_feature_names[] = {
   "com.delphix:embedded_data",
   "com.delphix:extensible_dataset",
   "org.open-zfs:large_blocks",
+  "com.klarasystems:vdev_zaps_v2",
+  "com.delphix:head_errlog",
   NULL
 };
 
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 1/3] Add grub_font_get_no_fallback

2024-05-16 Thread Vladimir Serbinenko
This allows the caller to handle the fallback

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/font/font.c | 21 -
 include/grub/font.h   |  2 ++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/grub-core/font/font.c b/grub-core/font/font.c
index 18de52562..ea01db01b 100644
--- a/grub-core/font/font.c
+++ b/grub-core/font/font.c
@@ -904,12 +904,8 @@ remove_font (grub_font_t font)
 }
 }
 
-/* Get a font from the list of loaded fonts.  This function will return
-   another font if the requested font is not available.  If no fonts are
-   loaded, then a special 'null font' is returned, which contains no glyphs,
-   but is not a null pointer so the caller may omit checks for NULL.  */
 grub_font_t
-grub_font_get (const char *font_name)
+grub_font_get_no_fallback (const char *font_name)
 {
   struct grub_font_node *node;
 
@@ -920,6 +916,21 @@ grub_font_get (const char *font_name)
return font;
 }
 
+  return NULL;
+}
+
+/* Get a font from the list of loaded fonts.  This function will return
+   another font if the requested font is not available.  If no fonts are
+   loaded, then a special 'null font' is returned, which contains no glyphs,
+   but is not a null pointer so the caller may omit checks for NULL.  */
+grub_font_t
+grub_font_get (const char *font_name)
+{
+  grub_font_t font = grub_font_get_no_fallback (font_name);
+
+  if (font)
+return font;
+
   /* If no font by that name is found, return the first font in the list
  as a fallback.  */
   if (grub_font_list && grub_font_list->value)
diff --git a/include/grub/font.h b/include/grub/font.h
index 708fa42ac..e6a43f8fc 100644
--- a/include/grub/font.h
+++ b/include/grub/font.h
@@ -107,6 +107,8 @@ grub_font_t EXPORT_FUNC(grub_font_load) (const char 
*filename);
is returned as a fallback.  */
 grub_font_t EXPORT_FUNC (grub_font_get) (const char *font_name);
 
+grub_font_t EXPORT_FUNC(grub_font_get_no_fallback) (const char *font_name);
+   
 const char *EXPORT_FUNC (grub_font_get_name) (grub_font_t font);
 
 int EXPORT_FUNC (grub_font_get_max_char_width) (grub_font_t font);
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/3] gfxmenu: Add missing error handling

2024-05-16 Thread Vladimir Serbinenko
We don't currently handle errors from gfxterm

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/gfxmenu/view.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c
index e02eba8b0..19d3f2f14 100644
--- a/grub-core/gfxmenu/view.c
+++ b/grub-core/gfxmenu/view.c
@@ -539,7 +539,7 @@ init_terminal (grub_gfxmenu_view_t view)
   /* Note: currently there is no API for changing the gfxterm font
  on the fly, so whatever font the initially loaded theme specifies
  will be permanent.  */
-  grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
+  grub_err_t err = grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
view->terminal_rect.x,
view->terminal_rect.y,
view->terminal_rect.width,
@@ -547,6 +547,9 @@ init_terminal (grub_gfxmenu_view_t view)
view->double_repaint,
terminal_font,
view->terminal_border);
+  if (err)
+return;
+
   grub_gfxterm_decorator_hook = grub_gfxmenu_draw_terminal_box;
 }
 
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 3/3] Improve font fallback scanning and validation for gfxterm

2024-05-16 Thread Vladimir Serbinenko
Choosing a font which is too large breaks gfxterm. Be more diligent in
font choice. This being said it's better to specify the correct font explicitly
in config when several fonts are loaded.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/gfxmenu/view.c |  7 +
 grub-core/term/gfxterm.c | 56 
 2 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/grub-core/gfxmenu/view.c b/grub-core/gfxmenu/view.c
index 19d3f2f14..d96b5cdc9 100644
--- a/grub-core/gfxmenu/view.c
+++ b/grub-core/gfxmenu/view.c
@@ -524,12 +524,7 @@ init_terminal (grub_gfxmenu_view_t view)
 {
   grub_font_t terminal_font;
 
-  terminal_font = grub_font_get (view->terminal_font_name);
-  if (!terminal_font)
-{
-  grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
-  return;
-}
+  terminal_font = grub_font_get_no_fallback (view->terminal_font_name);
 
   /* Check that terminal window size and position are sane. */
   terminal_sanity_check (view);
diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
index 3c468f459..addad5ee2 100644
--- a/grub-core/term/gfxterm.c
+++ b/grub-core/term/gfxterm.c
@@ -293,12 +293,56 @@ grub_gfxterm_schedule_repaint (void)
   repaint_scheduled = 1;
 }
 
+static int
+font_validate (grub_font_t font, int width, int height)
+{
+  int normal_char_width = calculate_normal_character_width (font);
+  int normal_char_height = grub_font_get_max_char_height (font);
+  if (normal_char_height == 0)
+normal_char_height = 16;
+  if (normal_char_width == 0)
+normal_char_width = 8;
+
+  /* Calculate size of text buffer.  */
+  int columns = width / normal_char_width;
+  int rows = height / normal_char_height;
+
+  return columns >= 40 && rows >= 12;
+}
+
 grub_err_t
 grub_gfxterm_set_window (struct grub_video_render_target *target,
 int x, int y, int width, int height,
 int double_repaint,
 grub_font_t font, int border_width)
 {
+  if (!font)
+{
+  const char *font_name;
+  /* Select the font to use.  */
+  font_name = grub_env_get ("gfxterm_font");
+  if (! font_name)
+   font_name = "";   /* Allow fallback to any font.  */
+
+  font = grub_font_get_no_fallback (font_name);
+}
+
+  if (!font || !font_validate(font, width, height))
+{
+  struct grub_font_node *node;
+
+  font = NULL;
+
+  for (node = grub_font_list; node; node = node->next)
+   if (font_validate(node->value, width, height))
+ font = node->value;
+
+  if (!font)
+   font = grub_font_get("");
+}
+  if (!font)
+return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
+
   /* Clean up any prior instance.  */
   destroy_window ();
 
@@ -331,12 +375,10 @@ grub_gfxterm_set_window (struct grub_video_render_target 
*target,
 static grub_err_t
 grub_gfxterm_fullscreen (void)
 {
-  const char *font_name;
   struct grub_video_mode_info mode_info;
   grub_video_color_t color;
   grub_err_t err;
   int double_redraw;
-  grub_font_t font;
 
   err = grub_video_get_info (&mode_info);
   /* Figure out what mode we ended up.  */
@@ -357,21 +399,13 @@ grub_gfxterm_fullscreen (void)
   grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height);
 }
 
-  /* Select the font to use.  */
-  font_name = grub_env_get ("gfxterm_font");
-  if (! font_name)
-font_name = "";   /* Allow fallback to any font.  */
-
-  font = grub_font_get (font_name);
-  if (!font)
-return grub_error (GRUB_ERR_BAD_FONT, "no font loaded");
 
   grub_gfxterm_decorator_hook = NULL;
 
   return grub_gfxterm_set_window (GRUB_VIDEO_RENDER_TARGET_DISPLAY,
  0, 0, mode_info.width, mode_info.height,
  double_redraw,
- font, DEFAULT_BORDER_WIDTH);
+ NULL, DEFAULT_BORDER_WIDTH);
 }
 
 static grub_err_t
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 1/3] Decrease minimal gfxterm size to 10x6

2024-05-16 Thread Vladimir Serbinenko
10x6 is still marginally usable. Erroring out may leave user without any console

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/term/gfxterm.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
index addad5ee2..e8734a388 100644
--- a/grub-core/term/gfxterm.c
+++ b/grub-core/term/gfxterm.c
@@ -234,12 +234,13 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y,
 
   /*
* There must be a minimum number of rows and columns for the screen to
-   * make sense. Arbitrarily pick half of 80x24. If either dimensions is 0
+   * make sense. Arbitrarily pick 10x6. If either dimensions is 0
* we would allocate 0 bytes for the text_buffer.
*/
-  if (virtual_screen.columns < 40 || virtual_screen.rows < 12)
+  if (virtual_screen.columns < 10 || virtual_screen.rows < 6)
 return grub_error (GRUB_ERR_BAD_FONT,
-  "font: glyphs too large to fit on screen");
+  "font: glyphs too large to fit on screen (%dx%d)",
+  virtual_screen.columns, virtual_screen.rows);
 
   /* Allocate memory for text buffer.  */
   virtual_screen.text_buffer =
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/3] Don't attempt to do terminal functions on non-functional gfxterm

2024-05-16 Thread Vladimir Serbinenko
Attempting to do anything easily leads to a crash

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/term/gfxterm.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
index e8734a388..6513a529b 100644
--- a/grub-core/term/gfxterm.c
+++ b/grub-core/term/gfxterm.c
@@ -1038,6 +1038,9 @@ static void
 grub_gfxterm_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
 struct grub_term_coordinate pos)
 {
+  if (!virtual_screen.functional)
+return;
+
   if (pos.x >= virtual_screen.columns)
 pos.x = virtual_screen.columns - 1;
 
@@ -1072,6 +1075,9 @@ grub_gfxterm_cls (struct grub_term_output *term)
 {
   grub_video_color_t color;
 
+  if (!virtual_screen.functional)
+return;
+
   /* Clear virtual screen.  */
   grub_virtual_screen_cls (term);
 
@@ -1118,6 +1124,9 @@ static void
 grub_gfxterm_setcursor (struct grub_term_output *term __attribute__ ((unused)),
int on)
 {
+  if (!virtual_screen.functional)
+return;
+
   if (virtual_screen.cursor_state != on)
 {
   if (virtual_screen.cursor_state)
@@ -1132,6 +1141,9 @@ grub_gfxterm_setcursor (struct grub_term_output *term 
__attribute__ ((unused)),
 static void
 grub_gfxterm_refresh (struct grub_term_output *term __attribute__ ((unused)))
 {
+  if (!virtual_screen.functional)
+return;
+
   real_scroll ();
 
   /* Redraw only changed regions.  */
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 3/3] grub_unicode_destroy_glyph: Don't destroy NULL glyph

2024-05-16 Thread Vladimir Serbinenko
This is more in-line with free() behaviour.

Signed-off-by: Vladimir Serbinenko 
---
 include/grub/unicode.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/grub/unicode.h b/include/grub/unicode.h
index 9360b0b97..9a3a1d02a 100644
--- a/include/grub/unicode.h
+++ b/include/grub/unicode.h
@@ -281,6 +281,8 @@ grub_unicode_get_comb (const struct grub_unicode_glyph *in)
 static inline void
 grub_unicode_destroy_glyph (struct grub_unicode_glyph *glyph)
 {
+  if (!glyph)
+return;
   if (glyph->ncomb > ARRAY_SIZE (glyph->combining_inline))
 grub_free (glyph->combining_ptr);
   glyph->ncomb = 0;
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 2/2 v2] LVM Cachevol and Integrity volumes break entire LVM VG

2024-05-16 Thread Patrick Plenefisch
Daniel,

I haven't heard any update about my patch from you since early February. Is
there anything I need to do or is this good to go? I'm not too familiar
with actually submitting patches to mailing-list based development, so let
me know if everything is all set or I need to do something else.

Thanks,
Patrick


On Fri, Apr 26, 2024 at 9:00 PM Patrick Plenefisch 
wrote:

> From 8cfb6dbb011d3773b90a3cbb8561616a2fb5955f Mon Sep 17 00:00:00 2001
> From: Patrick Plenefisch 
> Date: Sun, 18 Feb 2024 18:36:05 -0500
> Subject: [PATCH 2/2] lvm: Add support for cachevol and integrity lv
>
> lv matching must be done after processing, as integrity
> volumes may have several levels that the segments must be
> shifted through
>
> pv matching must be completely finished before validating a
> volume, otherwise referenced raid stripes may not have pv
> data applied yet
>
> Signed-off-by: Patrick Plenefisch 
> ---
>  grub-core/disk/diskfilter.c |  6 ++-
>  grub-core/disk/lvm.c| 83 +++--
>  2 files changed, 56 insertions(+), 33 deletions(-)
>
> diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
> index 21e239511..dc3bd943b 100644
> --- a/grub-core/disk/diskfilter.c
> +++ b/grub-core/disk/diskfilter.c
> @@ -966,8 +966,6 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg
> *vg)
>
>for (lv = vg->lvs; lv; lv = lv->next)
>  {
> -  grub_err_t err;
> -
>/* RAID 1 and single-disk RAID 0 don't use a chunksize but code
>   assumes one so set one. */
>for (i = 0; i < lv->segment_count; i++)
> @@ -979,6 +977,10 @@ grub_diskfilter_vg_register (struct
> grub_diskfilter_vg *vg)
>&& lv->segments[i].stripe_size == 0)
>  lv->segments[i].stripe_size = 64;
>   }
> +}
> +  for (lv = vg->lvs; lv; lv = lv->next)
> +{
> +  grub_err_t err;
>
>err = validate_lv(lv);
>if (err)
> diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c
> index 10bc965a4..7615a507a 100644
> --- a/grub-core/disk/lvm.c
> +++ b/grub-core/disk/lvm.c
> @@ -805,13 +805,27 @@ grub_lvm_detect (grub_disk_t disk,
>seg->nodes[seg->node_count - 1].name = tmp;
>   }
>  }
> +  /* Cache and integrity LVs have extra parts that
> + we can ignore for our read-only access */
>else if (grub_memcmp (p, "cache\"",
> -   sizeof ("cache\"") - 1) == 0)
> +   sizeof ("cache\"") - 1) == 0
> +   || grub_memcmp (p, "cache+CACHE_USES_CACHEVOL\"",
> +   sizeof ("cache+CACHE_USES_CACHEVOL\"") - 1) == 0
> +   || grub_memcmp (p, "integrity\"",
> +   sizeof ("integrity\"") - 1) == 0)
>  {
>struct ignored_feature_lv *ignored_feature = NULL;
>
>char *p2, *p3;
>grub_size_t sz;
> +#ifdef GRUB_UTIL
> +  p2 = grub_strchr (p, '"');
> +  if (p2)
> + *p2 = 0;
> +  grub_util_info ("Ignoring extra metadata type '%s' for %s", p,
> lv->name);
> +  if (p2)
> + *p2 ='"';
> +#endif
>
>ignored_feature = grub_zalloc (sizeof (*ignored_feature));
>if (!ignored_feature)
> @@ -936,36 +950,6 @@ grub_lvm_detect (grub_disk_t disk,
>  }
>   }
>
> -  /* Match lvs.  */
> -  {
> - struct grub_diskfilter_lv *lv1;
> - struct grub_diskfilter_lv *lv2;
> - for (lv1 = vg->lvs; lv1; lv1 = lv1->next)
> -  for (i = 0; i < lv1->segment_count; i++)
> -for (j = 0; j < lv1->segments[i].node_count; j++)
> -  {
> - if (vg->pvs)
> -  for (pv = vg->pvs; pv; pv = pv->next)
> -{
> -  if (! grub_strcmp (pv->name,
> - lv1->segments[i].nodes[j].name))
> - {
> -  lv1->segments[i].nodes[j].pv = pv;
> -  break;
> - }
> -}
> - if (lv1->segments[i].nodes[j].pv == NULL)
> -  for (lv2 = vg->lvs; lv2; lv2 = lv2->next)
> -{
> -  if (lv1 == lv2)
> -continue;
> -  if (grub_strcmp (lv2->name,
> -   lv1->segments[i].nodes[j].name) == 0)
> - lv1->segments[i].nodes[j].lv = lv2;
> -}
> -  }
> -
> -  }
>
>{
>   struct ignored_feature_lv *ignored_feature;
> @@ -1014,9 +998,46 @@ grub_lvm_detect (grub_disk_t disk,
>  ignored_feature->lv = NULL;
>}
>}
> +  else
> +  {
> +
> +#ifdef GRUB_UTIL
> +  grub_util_info ("Couldn't find LVM part of ignored feature on
> %s", ignored_feature->origin);
> +#endif
> +  }
>}
>}
>
> +  /* Match lvs. Must be done after cache and integrity are found  */
> +  {
> + struct grub_diskfilter_lv *lv1;
> + struct grub_diskfilter_lv *lv2;
> + for (lv1 = vg->lvs; lv1; lv1 = lv1->next)
> +  for (i = 0; i < lv1->segment_count; i++)
> +for (j = 0; j < lv1->segments[i].node_count; j++)
> +  {
> + if (vg->pvs)
> +  for (pv = vg->pvs; pv; pv = pv->next)
> +{
> +  if (! grub_strcmp (pv->name,
> + lv1->segments[i].nodes[j].name))
> + {
> +  lv1->segments[i].nodes[j].pv = pv;
> +  break;
> + }
> +}
> + if (lv1->segments[i].nodes[j].pv == NULL)
> +  for (lv2 = vg->lvs; lv2; lv2 = lv2->next)
> +{
> +  if (lv1 == lv2)
> +continue;
> +  if (grub_strcmp (lv2->name,
> +   lv1->segments[i].no

[PATCH 1/2] zfs: Support zstd compression

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 grub-core/Makefile.core.def |  1 +
 grub-core/fs/zfs/zfs.c  | 32 
 include/grub/zfs/zio.h  |  1 +
 3 files changed, 34 insertions(+)

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..2ba4962d5 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1596,6 +1596,7 @@ module = {
   common = fs/zfs/zfs_lz4.c;
   common = fs/zfs/zfs_sha256.c;
   common = fs/zfs/zfs_fletcher.c;
+  cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/zstd';
 };
 
 module = {
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index b5453e006..b8441faef 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -57,6 +57,8 @@
 #include 
 #include 
 
+#include 
+
 GRUB_MOD_LICENSE ("GPLv3+");
 
 #defineZPOOL_PROP_BOOTFS   "bootfs"
@@ -291,6 +293,7 @@ static const char *spa_feature_names[] = {
   "com.delphix:embedded_data",
   "com.delphix:extensible_dataset",
   "org.open-zfs:large_blocks",
+  "org.freebsd:zstd_compress",
   NULL
 };
 
@@ -312,6 +315,34 @@ zlib_decompress (void *s, void *d,
   return grub_errno;
 }
 
+static grub_err_t
+zstd_decompress (void *ibuf, void *obuf, grub_size_t isize,
+grub_size_t osize)
+{
+  grub_size_t zstd_ret;
+  grub_uint8_t *byte_buf = (grub_uint8_t *) ibuf;
+
+  if (isize < 8)
+  return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data too short");
+
+  grub_uint32_t c_len = grub_be_to_cpu32(grub_get_unaligned32(byte_buf));
+
+  if (c_len > isize - 8)
+  return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data announced 
size overflow");
+
+  /* Fix magic number.  */
+  byte_buf[4] = 0x28;
+  byte_buf[5] = 0xb5;
+  byte_buf[6] = 0x2f;
+  byte_buf[7] = 0xfd;
+  zstd_ret = ZSTD_decompress (obuf, osize, byte_buf + 4, c_len + 4);
+
+  if (ZSTD_isError (zstd_ret))
+return grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "zstd data corrupted 
(error %d)", (int) zstd_ret);
+
+  return GRUB_ERR_NONE;
+}
+
 static grub_err_t
 zle_decompress (void *s, void *d,
grub_size_t slen, grub_size_t dlen)
@@ -362,6 +393,7 @@ static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] 
= {
   {"gzip-9", zlib_decompress},  /* ZIO_COMPRESS_GZIP9 */
   {"zle", zle_decompress},  /* ZIO_COMPRESS_ZLE   */
   {"lz4", lz4_decompress},  /* ZIO_COMPRESS_LZ4   */
+  {"zstd", zstd_decompress},/* ZIO_COMPRESS_ZSTD   */
 };
 
 static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian,
diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h
index 19ce136bb..997b0c4d4 100644
--- a/include/grub/zfs/zio.h
+++ b/include/grub/zfs/zio.h
@@ -89,6 +89,7 @@ enum zio_compress {
ZIO_COMPRESS_GZIP9,
ZIO_COMPRESS_ZLE,
ZIO_COMPRESS_LZ4,
+   ZIO_COMPRESS_ZSTD,
ZIO_COMPRESS_FUNCTIONS
 };
 
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH 2/2] Add test for zfs zstd

2024-05-16 Thread Vladimir Serbinenko
Signed-off-by: Vladimir Serbinenko 
---
 tests/util/grub-fs-tester.in | 2 +-
 tests/zfs_test.in| 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index ea8b2d1f6..f0451ecd9 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -775,7 +775,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 
1); do
sleep 1
"zfs" create -o casesensitivity=insensitive 
"$FSLABEL"/"grub fs"
sleep 1;;
-   x"zfs_lzjb" | xzfs_gzip | xzfs_zle)
+   x"zfs_lzjb" | xzfs_gzip | xzfs_zle | xzfs_zstd)
"zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" 
"$FSLABEL" "${MOUNTDEVICE}"
sleep 1
"zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs"
diff --git a/tests/zfs_test.in b/tests/zfs_test.in
index 58cc25b22..0d0a57f7d 100644
--- a/tests/zfs_test.in
+++ b/tests/zfs_test.in
@@ -19,6 +19,7 @@ fi
 "@builddir@/grub-fs-tester" zfs_lzjb
 "@builddir@/grub-fs-tester" zfs_gzip
 "@builddir@/grub-fs-tester" zfs_zle
+"@builddir@/grub-fs-tester" zfs_zstd
 "@builddir@/grub-fs-tester" zfs_raidz3
 "@builddir@/grub-fs-tester" zfs_raidz2
 "@builddir@/grub-fs-tester" zfs_raidz
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Implement fmap support as used by coreboot

2024-05-16 Thread Vladimir Serbinenko
This patch limits itself to fmap coming from booted coreboot,
not as used in images.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/Makefile.core.def |   7 ++
 grub-core/partmap/fmap.c| 172 
 2 files changed, 179 insertions(+)
 create mode 100644 grub-core/partmap/fmap.c

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..28c5d9050 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -2016,6 +2016,13 @@ module = {
   common = partmap/apple.c;
 };
 
+module = {
+  name = part_fmap;
+  common = partmap/fmap.c;
+  enable = x86;
+  enable = coreboot;
+};
+
 module = {
   name = part_gpt;
   common = partmap/gpt.c;
diff --git a/grub-core/partmap/fmap.c b/grub-core/partmap/fmap.c
new file mode 100644
index 0..2625e4c75
--- /dev/null
+++ b/grub-core/partmap/fmap.c
@@ -0,0 +1,172 @@
+/* gpt.c - Read GUID Partition Tables (GPT).  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2023  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+/* Definitions copied from fmap_serialized.h using BSDL.  */
+#define FMAP_SIGNATURE "__FMAP__"
+#define FMAP_VER_MAJOR 1   /* this header's FMAP minor version */
+#define FMAP_VER_MINOR 1   /* this header's FMAP minor version */
+#define FMAP_STRLEN32  /* maximum length for strings, */
+   /* including null-terminator */
+
+/* Mapping of volatile and static regions in firmware binary */
+struct grub_fmap_entry {
+  grub_uint32_t offset;/* offset relative to base */
+  grub_uint32_t size;  /* size in bytes */
+  grub_uint8_t  name[FMAP_STRLEN]; /* descriptive name */
+  grub_uint16_t flags; /* flags for this area */
+} GRUB_PACKED;
+
+struct grub_fmap_header {
+  grub_uint8_t  signature[8];  /* "__FMAP__" (0x5F5F464D41505F5F) */
+  grub_uint8_t  ver_major; /* major version */
+  grub_uint8_t  ver_minor; /* minor version */
+  grub_uint64_t base;  /* address of the firmware binary */
+  grub_uint32_t size;  /* size of firmware binary in bytes */
+  grub_uint8_t  name[FMAP_STRLEN]; /* name of this firmware binary */
+  grub_uint16_t nareas;/* number of areas described by
+  fmap_areas[] below */
+} GRUB_PACKED;
+
+static struct grub_partition_map grub_fmap_partition_map;
+
+
+
+static int
+validate_fmap_header(struct grub_fmap_header *header)
+{
+  if (grub_memcmp (header->signature, FMAP_SIGNATURE, sizeof 
(header->signature)) != 0)
+return 0;
+  if (header->ver_major != FMAP_VER_MAJOR || header->ver_minor != 
FMAP_VER_MINOR)
+return 0;
+  return 1;
+}
+
+static grub_uint64_t cbfsdisk_fmap_offset = 0x;
+
+static int cbtable_iter (grub_linuxbios_table_item_t item,
+void *ctxt_in __attribute__((unused)))
+{
+  if (item->tag == GRUB_LINUXBIOS_MEMBER_BOOT_MEDIA)
+{
+  cbfsdisk_fmap_offset = ((struct grub_linuxbios_table_boot_media *) (item 
+ 1))->fmap_offset;
+  return 1;
+}
+
+  return 0;
+}
+
+static void
+discover_cbfsdisk_fmap_offset(void)
+{
+  static int discovery_done;
+  if (discovery_done)
+return;
+   grub_linuxbios_table_iterate (cbtable_iter, NULL);
+}
+
+
+static grub_err_t
+grub_fmap_partition_map_iterate (grub_disk_t disk,
+   grub_partition_iterate_hook_t hook,
+   void *hook_data)
+{
+  struct grub_partition part;
+  struct grub_fmap_header header;
+  struct grub_fmap_entry entry;
+  unsigned int i;
+  grub_uint64_t header_offset = 0;
+  grub_uint64_t current_offset = 0;
+
+  if (disk->dev->id == GRUB_DISK_DEVICE_CBFSDISK_ID)
+{
+  discover_cbfsdisk_fmap_offset();
+  header_offset = cbfsdisk_fmap_offset;
+  if (cbfsdisk_fmap_offset == 0x || cbfsdisk_fmap_offset == 
0xULL)
+   return grub_error(GRUB_ERR_BAD_PART_TABLE, "fmap not declared");
+}
+  else
+return grub_error(GRUB_ERR_BAD_PART_TABLE, "fmap in non-cbfs devices isn't 
implemented yet");
+
+  /* Read the FMAP header.  */
+  if (grub_

Re: [PATCH v11 1/2] fs/erofs: Add support for EROFS

2024-05-16 Thread Daniel Kiper via Grub-devel
On Fri, May 10, 2024 at 08:52:55AM +0800, Gao Xiang wrote:
> From: Yifan Zhao 
>
> EROFS [1] is a lightweight read-only filesystem designed for performance
> which has already been shipped in most Linux distributions as well as widely
> used in several scenarios, such as Android system partitions, container
> images, and rootfs for embedded devices.
>
> This patch brings EROFS uncompressed support. Now, it's possible to boot
> directly through GRUB with an EROFS rootfs.
>
> EROFS compressed files will be supported later since it has more work to
> polish.
>
> [1] https://erofs.docs.kernel.org
>
> Signed-off-by: Yifan Zhao 
> Tested-by: Daniel Axtens  # fuzz testing only
> Signed-off-by: Gao Xiang 

In general patch LGTM except some nits...

> ---
> Tested-by Link: 
> https://lists.gnu.org/archive/html/grub-devel/2024-05/msg1.html
>
>  INSTALL |8 +-
>  Makefile.util.def   |1 +
>  docs/grub.texi  |3 +-
>  grub-core/Makefile.core.def |5 +
>  grub-core/fs/erofs.c| 1008 +++
>  5 files changed, 1020 insertions(+), 5 deletions(-)
>  create mode 100644 grub-core/fs/erofs.c
>
> diff --git a/INSTALL b/INSTALL
> index 8d9207c84..84030c9f4 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -77,15 +77,15 @@ Prerequisites for make-check:
>
>  * If running a Linux kernel the following modules must be loaded:
>- fuse, loop
> -  - btrfs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
> +  - btrfs, erofs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, 
> nilfs2,
>  reiserfs, udf, xfs
>- On newer kernels, the exfat kernel modules may be used instead of the
>  exfat FUSE filesystem
>  * The following are Debian named packages required mostly for the full
>suite of filesystem testing (but some are needed by other tests as well):
> -  - btrfs-progs, dosfstools, e2fsprogs, exfat-utils, f2fs-tools, genromfs,
> -hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs, squashfs-tools,
> -reiserfsprogs, udftools, xfsprogs, zfs-fuse
> +  - btrfs-progs, dosfstools, e2fsprogs, erofs-utils, exfat-utils, f2fs-tools,
> +genromfs, hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs,
> +squashfs-tools, reiserfsprogs, udftools, xfsprogs, zfs-fuse
>- exfat-fuse, if not using the exfat kernel module
>- gzip, lzop, xz-utils
>- attr, cpio, g++, gawk, parted, recode, tar, util-linux
> diff --git a/Makefile.util.def b/Makefile.util.def
> index 9432365a9..8d3bc107f 100644
> --- a/Makefile.util.def
> +++ b/Makefile.util.def
> @@ -98,6 +98,7 @@ library = {
>common = grub-core/fs/cpio_be.c;
>common = grub-core/fs/odc.c;
>common = grub-core/fs/newc.c;
> +  common = grub-core/fs/erofs.c;
>common = grub-core/fs/ext2.c;
>common = grub-core/fs/fat.c;
>common = grub-core/fs/exfat.c;
> diff --git a/docs/grub.texi b/docs/grub.texi
> index d32266f69..b198d963d 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -353,6 +353,7 @@ blocklist notation. The currently supported filesystem 
> types are @dfn{Amiga
>  Fast FileSystem (AFFS)}, @dfn{AtheOS fs}, @dfn{BeFS},
>  @dfn{BtrFS} (including raid0, raid1, raid10, gzip and lzo),
>  @dfn{cpio} (little- and big-endian bin, odc and newc variants),
> +@dfn{EROFS} (only uncompressed support for now),
>  @dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32},
>  @dfn{exFAT}, @dfn{F2FS}, @dfn{HFS}, @dfn{HFS+},
>  @dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files),
> @@ -6276,7 +6277,7 @@ assumed to be encoded in UTF-8.
>  NTFS, JFS, UDF, HFS+, exFAT, long filenames in FAT, Joliet part of
>  ISO9660 are treated as UTF-16 as per specification. AFS and BFS are read
>  as UTF-8, again according to specification. BtrFS, cpio, tar, squash4, minix,
> -minix2, minix3, ROMFS, ReiserFS, XFS, ext2, ext3, ext4, FAT (short names),
> +minix2, minix3, ROMFS, ReiserFS, XFS, EROFS, ext2, ext3, ext4, FAT (short 
> names),
>  F2FS, RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed
>  to be UTF-8. This might be false on systems configured with legacy charset
>  but as long as the charset used is superset of ASCII you should be able to
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 8e1b1d9f3..7fa9446bd 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -1442,6 +1442,11 @@ module = {
>common = fs/odc.c;
>  };
>
> +module = {
> +  name = erofs;
> +  common = fs/erofs.c;
> +};
> +
>  module = {
>name = ext2;
>common = fs/ext2.c;
> diff --git a/grub-core/fs/erofs.c b/grub-core/fs/erofs.c
> new file mode 100644
> index 0..14c86f435
> --- /dev/null
> +++ b/grub-core/fs/erofs.c
> @@ -0,0 +1,1008 @@
> +/* erofs.c - Enhanced Read-Only File System */
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2024 Free Software Foundation, Inc.
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under 

Re: [PATCH v11 2/2] fs/erofs: Add tests for EROFS in grub-fs-tester

2024-05-16 Thread Daniel Kiper via Grub-devel
On Fri, May 10, 2024 at 08:52:56AM +0800, Gao Xiang wrote:
> From: Yifan Zhao 
>
> In this patch, three tests of EROFS are introduced and they cover
> compact, extended and chunk-based inodes, respectively.
>
> Signed-off-by: Yifan Zhao 
> Reviewed-by: Glenn Washburn 
> Signed-off-by: Gao Xiang 

Reviewed-by: Daniel Kiper 

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH 2/2 v2] LVM Cachevol and Integrity volumes break entire LVM VG

2024-05-16 Thread Daniel Kiper
Patrick,

On Thu, May 16, 2024 at 03:38:17PM -0400, Patrick Plenefisch wrote:
> Daniel,
>
> I haven't heard any update about my patch from you since early February. Is
> there anything I need to do or is this good to go? I'm not too familiar with
> actually submitting patches to mailing-list based development, so let me know
> if everything is all set or I need to do something else.

Sorry, I forgot about your patch. I will take a look at it next week.

Daniel

___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] Add commands for reading and writing raw bytes to CMOS

2024-05-16 Thread Vladimir Serbinenko
With some coreboot configs setting a byte to a magic value
changes behaviour on next boot. Setting bit-by-bit is
possible but not convenient. Add cmosread and cmoswrite for
convenience.

Signed-off-by: Vladimir Serbinenko 
---
 grub-core/commands/i386/cmostest.c | 72 +-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/grub-core/commands/i386/cmostest.c 
b/grub-core/commands/i386/cmostest.c
index 1f0c5341d..814df0f43 100644
--- a/grub-core/commands/i386/cmostest.c
+++ b/grub-core/commands/i386/cmostest.c
@@ -18,9 +18,12 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -99,7 +102,66 @@ grub_cmd_cmosset (struct grub_command *cmd __attribute__ 
((unused)),
   return grub_cmos_write (byte, value | (1 << bit));
 }
 
-static grub_command_t cmd, cmd_clean, cmd_set;
+static grub_err_t
+grub_cmd_cmoswrite (struct grub_command *cmd __attribute__ ((unused)),
+   int argc, char *argv[])
+{
+  unsigned long byte, value;
+  const char *end;
+
+  if (argc != 2)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
+
+  byte = grub_strtoul (argv[0], &end, 0);
+  if (byte >= 0x100 || argv[0][0] == '\0' || *end != '\0')
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid address"));
+
+  value = grub_strtoul (argv[1], &end, 0);
+  if (value >= 0x100 || argv[1][0] == '\0' || *end != '\0')
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid value"));
+
+  return grub_cmos_write (byte, value);
+}
+
+static grub_err_t
+grub_cmd_cmosread (grub_extcmd_context_t ctxt, int argc, char **argv)
+{
+  unsigned long byte;
+  grub_uint8_t value = 0;
+  grub_err_t err;
+  const char *end;
+
+  if (argc != 1)
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+
+  byte = grub_strtoul (argv[0], &end, 0);
+  if (byte >= 0x100 || argv[0][0] == '\0' || *end != '\0')
+return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid address"));
+
+  err = grub_cmos_read (byte, &value);
+  if (err)
+return err;
+
+  if (ctxt->state[0].set)
+{
+  char buf[sizeof ("XX")];
+  grub_snprintf (buf, sizeof (buf), "%x", value);
+  grub_env_set(ctxt->state[0].arg, buf);
+}
+  else
+grub_printf_("CMOS value at 0x%lx is 0x%x\n", byte, value);
+  return GRUB_ERR_NONE;
+}
+
+static const struct grub_arg_option read_options[] =
+  {
+{0, 's', 0, N_("Save read value into variable VARNAME."),
+ N_("VARNAME"), ARG_TYPE_STRING},
+{0, 0, 0, 0, 0, 0}
+  };
+
+static grub_command_t cmd, cmd_clean, cmd_set, cmd_write;
+static grub_extcmd_t cmd_read;
 
 
 GRUB_MOD_INIT(cmostest)
@@ -114,6 +176,12 @@ GRUB_MOD_INIT(cmostest)
   N_("BYTE:BIT"),
   /* TRANSLATORS: A bit may be either set (1) 
or clear (0).  */
   N_("Set bit at BYTE:BIT in CMOS."));
+  cmd_read = grub_register_extcmd_lockdown ("cmosread", grub_cmd_cmosread, 0,
+  N_("[-s VAR] ADDR"),
+  N_("Read CMOS byte at ADDR."), 
read_options);
+  cmd_write = grub_register_command_lockdown ("cmoswrite", grub_cmd_cmoswrite,
+ N_("ADDR VALUE"),
+ N_("Set CMOS byte at ADDR to 
VALUE."));
 }
 
 GRUB_MOD_FINI(cmostest)
@@ -121,4 +189,6 @@ GRUB_MOD_FINI(cmostest)
   grub_unregister_command (cmd);
   grub_unregister_command (cmd_clean);
   grub_unregister_command (cmd_set);
+  grub_unregister_extcmd (cmd_read);
+  grub_unregister_command (cmd_write);
 }
-- 
2.39.2


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v11 2/2] fs/erofs: Add tests for EROFS in grub-fs-tester

2024-05-16 Thread Gao Xiang



On 2024/5/17 05:37, Daniel Kiper wrote:

On Fri, May 10, 2024 at 08:52:56AM +0800, Gao Xiang wrote:

From: Yifan Zhao 

In this patch, three tests of EROFS are introduced and they cover
compact, extended and chunk-based inodes, respectively.

Signed-off-by: Yifan Zhao 
Reviewed-by: Glenn Washburn 
Signed-off-by: Gao Xiang 


Reviewed-by: Daniel Kiper 


Thanks for the review!

Thanks,
Gao Xiang



Daniel


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH v11 1/2] fs/erofs: Add support for EROFS

2024-05-16 Thread Gao Xiang

Hi Daniel,

On 2024/5/17 05:33, Daniel Kiper wrote:

On Fri, May 10, 2024 at 08:52:55AM +0800, Gao Xiang wrote:


...



In general patch LGTM except some nits...


Thanks for the comments.  Let me address them.




---
Tested-by Link: 
https://lists.gnu.org/archive/html/grub-devel/2024-05/msg1.html


...


+struct grub_erofs_super
+{
+  grub_uint32_t magic;
+  grub_uint32_t checksum;
+  grub_uint32_t feature_compat;
+  grub_uint8_t log2_blksz;
+  grub_uint8_t sb_extslots;


May I ask you to align struct/union members in the following way?

   grub_uint32_t magic;
   grub_uint32_t checksum;
   grub_uint32_t feature_compat;
   grub_uint8_t  log2_blksz;
   grub_uint8_t  sb_extslots;

   grub_uint16_t root_nid;
   grub_uint64_t inos;

   grub_uint64_t build_time;
   grub_uint32_t build_time_nsec;

   ...



Sorry, anyway, I'm not quite familiar with GRUB coding
styles.

It seems that using TABs in the middle of names and types.
Is my understanding correct?  I will try to update like this.


Please do this for all/most structs and unions definitions below.



...


+
+static grub_err_t
+erofs_read_inode (struct grub_erofs_data *data, grub_fshelp_node_t node)
+{
+  union grub_erofs_inode *di;
+  grub_err_t err;
+  grub_uint16_t i_format;
+  grub_uint64_t addr = erofs_iloc (node);
+
+  di = (union grub_erofs_inode *) &node->inode;
+
+  err = grub_disk_read (data->disk, addr >> GRUB_DISK_SECTOR_BITS,
+   addr & (GRUB_DISK_SECTOR_SIZE - 1),
+   sizeof (struct grub_erofs_inode_compact), &di->c);
+  if (err != GRUB_ERR_NONE)
+return err;
+
+  i_format = grub_le_to_cpu16 (di->c.i_format);
+  node->inode_type = (i_format >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASKS;
+  node->inode_datalayout = (i_format >> EROFS_I_DATALAYOUT_BIT) & 
EROFS_I_DATALAYOUT_MASKS;
+
+  switch (node->inode_type)
+{
+case EROFS_INODE_LAYOUT_EXTENDED:
+  addr += sizeof (struct grub_erofs_inode_compact);
+  err = grub_disk_read (
+ data->disk, addr >> GRUB_DISK_SECTOR_BITS,
+ addr & (GRUB_DISK_SECTOR_SIZE - 1),
+ sizeof (struct grub_erofs_inode_extended) - sizeof (struct 
grub_erofs_inode_compact),
+ (grub_uint8_t *) di + sizeof (struct grub_erofs_inode_compact));


This function call is unreadable. Please fix it. I am OK with lines
longer than 80 chars. So, first argument for the grub_disk_read() should
be immediately behind "(". Then other arguments may follow below
starting from the same column with the first argument.

   grub_disk_read (data->disk, addr >> GRUB_DISK_SECTOR_BITS,
   addr & (GRUB_DISK_SECTOR_SIZE - 1),
  ...


Okay, will fix.





...


+
+  /* file_size is checked by caller and cannot be zero, hence nblocks > 0 */
+  file_size = erofs_inode_file_size (node);
+  if (grub_add (file_size, blocksz - 1, &nblocks))
+return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");


You use "overflow is detected" message everywhere. It is not helpful.
I think (almost) every message should be different, e.g. "nblocks overflow"
or "invalid argument: %d..." or ...


Let me fix it as "nblocks overflow".




+  nblocks >>= node->data->sb.log2_blksz;
+  lastblk = nblocks - tailendpacking;
+
+  map->m_flags = EROFS_MAP_MAPPED;
+
+  /* no overflow as (lastblk <= nblocks) && (nblocks * blocksz <= UINT64_MAX - 
blocksz + 1) */
+  if (map->m_la < (lastblk * blocksz))
+{
+  if (grub_mul ((grub_uint64_t) grub_le_to_cpu32 
(node->inode.e.i_u.raw_blkaddr), blocksz,
+   &map->m_pa) ||


Please move this to the line with grub_mul()...


Okay, will fix as

  if (grub_mul ((grub_uint64_t) grub_le_to_cpu32 (node->inode.e.i_u.raw_blkaddr), 
blocksz, &map->m_pa) ||




+ grub_add (map->m_pa, map->m_la, &map->m_pa))
+   return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");


Again, this message does not help...


Will fix as "m_pa overflow".




+  if (grub_sub (lastblk * blocksz, map->m_la, &map->m_plen))
+   return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");


To be precise, this is an underflow...


Will fix as "m_plen underflow".




+}
+  else if (tailendpacking)
+{
+  if (grub_add (erofs_iloc (node), erofs_inode_size (node), &map->m_pa) ||
+ grub_add (map->m_pa, erofs_inode_xattr_ibody_size (node), &map->m_pa) 
||
+ grub_add (map->m_pa, map->m_la % blocksz, &map->m_pa))
+   return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");


Please fix all these messages...


Thanks, will fix as "m_pa overflow".




+  if (grub_sub (file_size, map->m_la, &map->m_plen))
+   return grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");


Will fix as "m_plen overflow".


+
+  /* no overflow as map->m_plen <= UINT64_MAX - blocksz + 1 */
+  if (((map->m_pa % block

[PATCH v12 2/2] fs/erofs: Add tests for EROFS in grub-fs-tester

2024-05-16 Thread Gao Xiang
From: Yifan Zhao 

In this patch, three tests of EROFS are introduced and they cover
compact, extended and chunk-based inodes, respectively.

Signed-off-by: Yifan Zhao 
Reviewed-by: Glenn Washburn 
Reviewed-by: Daniel Kiper 
Signed-off-by: Gao Xiang 
---
 .gitignore   |  1 +
 Makefile.util.def|  6 ++
 tests/erofs_test.in  | 20 
 tests/util/grub-fs-tester.in | 32 +---
 4 files changed, 52 insertions(+), 7 deletions(-)
 create mode 100644 tests/erofs_test.in

diff --git a/.gitignore b/.gitignore
index 11fcecf5c..4c1f91db8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,6 +104,7 @@ widthspec.bin
 /docs/version-dev.texi
 /docs/version.texi
 /ehci_test
+/erofs_test
 /example_grub_script_test
 /example_scripted_test
 /example_unit_test
diff --git a/Makefile.util.def b/Makefile.util.def
index 8d3bc107f..0f74a1680 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -764,6 +764,12 @@ script = {
   dependencies = 'garbage-gen$(BUILD_EXEEXT)';
 };
 
+script = {
+  testcase = native;
+  name = erofs_test;
+  common = tests/erofs_test.in;
+};
+
 script = {
   testcase = native;
   name = ext234_test;
diff --git a/tests/erofs_test.in b/tests/erofs_test.in
new file mode 100644
index 0..5627a
--- /dev/null
+++ b/tests/erofs_test.in
@@ -0,0 +1,20 @@
+#!@BUILD_SHEBANG@
+
+set -e
+
+if [ "x$EUID" = "x" ] ; then
+  EUID=`id -u`
+fi
+
+if [ "$EUID" != 0 ] ; then
+   exit 99
+fi
+
+if ! which mkfs.erofs >/dev/null 2>&1; then
+   echo "mkfs.erofs not installed; cannot test erofs."
+   exit 99
+fi
+
+"@builddir@/grub-fs-tester" erofs_compact
+"@builddir@/grub-fs-tester" erofs_extended
+"@builddir@/grub-fs-tester" erofs_chunk
diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index ea8b2d1f6..df5dc7542 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -227,6 +227,10 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" 
"$MAXLOGSECSIZE" 1); do
xsquash*)
MINBLKSIZE=4096
MAXBLKSIZE=1048576;;
+   x"erofs_"*)
+   MINBLKSIZE=4096
+   MAXBLKSIZE=4096
+   ;;
xxfs|xf2fs)
MINBLKSIZE=$SECSIZE
# OS Limitation: GNU/Linux doesn't accept > 4096
@@ -382,8 +386,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 
1); do
FSLABEL="g;/_é䏌䐓䏕䎛䎾䏴кит u"
#FSLABEL="g;/_é莭莽😁кит u"
;;
-   # FS LIMITATION: reiserfs, extN and jfs label is at most 16 
UTF-8 characters
-   x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"luks"* | 
x"mdraid"* | x"jfs" | x"jfs_caseins")
+   # FS LIMITATION: reiserfs, extN, jfs and erofs label is at most 
16 UTF-8 characters
+   x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"luks"* | 
x"mdraid"* | x"jfs" | x"jfs_caseins" | x"erofs_"*)
FSLABEL="g;/éт 莭😁";;
# FS LIMITATION: No underscore, space, semicolon, slash or 
international characters in UFS* in label. Limited to 32 UTF-8 characters
x"ufs1" | x"ufs1_sun" | x"ufs2")
@@ -661,7 +665,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 
1); do
x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\
| x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \
| x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 \
-   | xrockridge_joliet_1999)
+   | xrockridge_joliet_1999 | x"erofs_"*)
MNTPOINTRW="$MASTER"
MNTPOINTRO="$MASTER"
mkdir -p "$MASTER";;
@@ -805,7 +809,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 
1); do
sleep 1
"zfs" create "$FSLABEL"/"grub fs"
sleep 1;;
-   x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | 
xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | 
xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*)
+   x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | 
xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | 
xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | x"erofs_"*)
INSTDEVICE=/dev/null;;
x"reiserfs")
"mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q 
"${MOUNTDEVICE}" ;;
@@ -990,7 +994,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 
1); do
x"zfs"*)
OSDIR="grub fs/"
GRUBDIR="($GRUBDEVICE)/grub fs@";;
-   x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | 
xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | 
xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"* | xafs)
+   x"tarfs" | x"cpio_"* | 

[PATCH v12 1/2] fs/erofs: Add support for EROFS

2024-05-16 Thread Gao Xiang
From: Yifan Zhao 

EROFS [1] is a lightweight read-only filesystem designed for performance
which has already been shipped in most Linux distributions as well as widely
used in several scenarios, such as Android system partitions, container
images, and rootfs for embedded devices.

This patch brings EROFS uncompressed support. Now, it's possible to boot
directly through GRUB with an EROFS rootfs.

EROFS compressed files will be supported later since it has more work to
polish.

[1] https://erofs.docs.kernel.org

Signed-off-by: Yifan Zhao 
Tested-by: Daniel Axtens  # fuzz testing only
Signed-off-by: Gao Xiang 
---
 INSTALL |8 +-
 Makefile.util.def   |1 +
 docs/grub.texi  |3 +-
 grub-core/Makefile.core.def |5 +
 grub-core/fs/erofs.c| 1002 +++
 5 files changed, 1014 insertions(+), 5 deletions(-)
 create mode 100644 grub-core/fs/erofs.c

diff --git a/INSTALL b/INSTALL
index 8d9207c84..84030c9f4 100644
--- a/INSTALL
+++ b/INSTALL
@@ -77,15 +77,15 @@ Prerequisites for make-check:
 
 * If running a Linux kernel the following modules must be loaded:
   - fuse, loop
-  - btrfs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
+  - btrfs, erofs, ext4, f2fs, fat, hfs, hfsplus, jfs, mac-roman, minix, nilfs2,
 reiserfs, udf, xfs
   - On newer kernels, the exfat kernel modules may be used instead of the
 exfat FUSE filesystem
 * The following are Debian named packages required mostly for the full
   suite of filesystem testing (but some are needed by other tests as well):
-  - btrfs-progs, dosfstools, e2fsprogs, exfat-utils, f2fs-tools, genromfs,
-hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs, squashfs-tools,
-reiserfsprogs, udftools, xfsprogs, zfs-fuse
+  - btrfs-progs, dosfstools, e2fsprogs, erofs-utils, exfat-utils, f2fs-tools,
+genromfs, hfsprogs, jfsutils, nilfs-tools, ntfs-3g, reiserfsprogs,
+squashfs-tools, reiserfsprogs, udftools, xfsprogs, zfs-fuse
   - exfat-fuse, if not using the exfat kernel module
   - gzip, lzop, xz-utils
   - attr, cpio, g++, gawk, parted, recode, tar, util-linux
diff --git a/Makefile.util.def b/Makefile.util.def
index 9432365a9..8d3bc107f 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -98,6 +98,7 @@ library = {
   common = grub-core/fs/cpio_be.c;
   common = grub-core/fs/odc.c;
   common = grub-core/fs/newc.c;
+  common = grub-core/fs/erofs.c;
   common = grub-core/fs/ext2.c;
   common = grub-core/fs/fat.c;
   common = grub-core/fs/exfat.c;
diff --git a/docs/grub.texi b/docs/grub.texi
index d32266f69..b198d963d 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -353,6 +353,7 @@ blocklist notation. The currently supported filesystem 
types are @dfn{Amiga
 Fast FileSystem (AFFS)}, @dfn{AtheOS fs}, @dfn{BeFS},
 @dfn{BtrFS} (including raid0, raid1, raid10, gzip and lzo),
 @dfn{cpio} (little- and big-endian bin, odc and newc variants),
+@dfn{EROFS} (only uncompressed support for now),
 @dfn{Linux ext2/ext3/ext4}, @dfn{DOS FAT12/FAT16/FAT32},
 @dfn{exFAT}, @dfn{F2FS}, @dfn{HFS}, @dfn{HFS+},
 @dfn{ISO9660} (including Joliet, Rock-ridge and multi-chunk files),
@@ -6276,7 +6277,7 @@ assumed to be encoded in UTF-8.
 NTFS, JFS, UDF, HFS+, exFAT, long filenames in FAT, Joliet part of
 ISO9660 are treated as UTF-16 as per specification. AFS and BFS are read
 as UTF-8, again according to specification. BtrFS, cpio, tar, squash4, minix,
-minix2, minix3, ROMFS, ReiserFS, XFS, ext2, ext3, ext4, FAT (short names),
+minix2, minix3, ROMFS, ReiserFS, XFS, EROFS, ext2, ext3, ext4, FAT (short 
names),
 F2FS, RockRidge part of ISO9660, nilfs2, UFS1, UFS2 and ZFS are assumed
 to be UTF-8. This might be false on systems configured with legacy charset
 but as long as the charset used is superset of ASCII you should be able to
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 8e1b1d9f3..7fa9446bd 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1442,6 +1442,11 @@ module = {
   common = fs/odc.c;
 };
 
+module = {
+  name = erofs;
+  common = fs/erofs.c;
+};
+
 module = {
   name = ext2;
   common = fs/ext2.c;
diff --git a/grub-core/fs/erofs.c b/grub-core/fs/erofs.c
new file mode 100644
index 0..630f95e75
--- /dev/null
+++ b/grub-core/fs/erofs.c
@@ -0,0 +1,1002 @@
+/* erofs.c - Enhanced Read-Only File System */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2024 Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more deta

[PATCH v12 0/2] Introduce EROFS support

2024-05-16 Thread Gao Xiang
Hi folks,

EROFS [1] is a lightweight read-only filesystem designed for performance
which has already been shipped in most Linux distributions as well as widely
used in several scenarios, such as Android system partitions, container
images, and rootfs for embedded devices.

This patch brings EROFS uncompressed support together with related tests.
Now, it's possible to boot directly through GRUB with an EROFS rootfs.

EROFS compressed files will be supported later since it has more work to
polish.

[1] https://erofs.docs.kernel.org

changelog since v11:
- Address nits mentioned by Daniel for better reading:
https://lore.kernel.org/grub-devel/zkz7xw56awybf...@tomti.i.net-space.pl/
- Simplify erofs_read_symlink() since erofs_inode_file_size() is checked
  against EROFS_PATH_LEN(4096) first. 

Tested-by Link (Commit 1): 
https://lists.gnu.org/archive/html/grub-devel/2024-05/msg1.html
Reviewed-by Link (Commit 2): 
https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00101.html
Reviewed-by Link (Commit 2): 
https://lore.kernel.org/grub-devel/zkz8fdd+zckt+...@tomti.i.net-space.pl/

Yifan Zhao (2):
  fs/erofs: Add support for EROFS
  fs/erofs: Add tests for EROFS in grub-fs-tester

 .gitignore   |1 +
 INSTALL  |8 +-
 Makefile.util.def|7 +
 docs/grub.texi   |3 +-
 grub-core/Makefile.core.def  |5 +
 grub-core/fs/erofs.c | 1002 ++
 tests/erofs_test.in  |   20 +
 tests/util/grub-fs-tester.in |   32 +-
 8 files changed, 1066 insertions(+), 12 deletions(-)
 create mode 100644 grub-core/fs/erofs.c
 create mode 100644 tests/erofs_test.in

Interdiff against v11:

diff --git a/grub-core/fs/erofs.c b/grub-core/fs/erofs.c
index 14c86f435..630f95e75 100644
--- a/grub-core/fs/erofs.c
+++ b/grub-core/fs/erofs.c
@@ -39,37 +39,37 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct grub_erofs_super
 {
-  grub_uint32_t magic;
-  grub_uint32_t checksum;
-  grub_uint32_t feature_compat;
-  grub_uint8_t log2_blksz;
-  grub_uint8_t sb_extslots;
-
-  grub_uint16_t root_nid;
-  grub_uint64_t inos;
-
-  grub_uint64_t build_time;
-  grub_uint32_t build_time_nsec;
-  grub_uint32_t blocks;
-  grub_uint32_t meta_blkaddr;
-  grub_uint32_t xattr_blkaddr;
-  grub_packed_guid_t uuid;
-  grub_uint8_t volume_name[16];
-  grub_uint32_t feature_incompat;
+  grub_uint32_tmagic;
+  grub_uint32_tchecksum;
+  grub_uint32_tfeature_compat;
+  grub_uint8_t log2_blksz;
+  grub_uint8_t sb_extslots;
+
+  grub_uint16_troot_nid;
+  grub_uint64_tinos;
+
+  grub_uint64_tbuild_time;
+  grub_uint32_tbuild_time_nsec;
+  grub_uint32_tblocks;
+  grub_uint32_tmeta_blkaddr;
+  grub_uint32_txattr_blkaddr;
+  grub_packed_guid_t   uuid;
+  grub_uint8_t volume_name[16];
+  grub_uint32_tfeature_incompat;
 
   union
   {
-grub_uint16_t available_compr_algs;
-grub_uint16_t lz4_max_distance;
+grub_uint16_t  available_compr_algs;
+grub_uint16_t  lz4_max_distance;
   } GRUB_PACKED u1;
 
-  grub_uint16_t extra_devices;
-  grub_uint16_t devt_slotoff;
-  grub_uint8_t log2_dirblksz;
-  grub_uint8_t xattr_prefix_count;
-  grub_uint32_t xattr_prefix_start;
-  grub_uint64_t packed_nid;
-  grub_uint8_t reserved2[24];
+  grub_uint16_textra_devices;
+  grub_uint16_tdevt_slotoff;
+  grub_uint8_t log2_dirblksz;
+  grub_uint8_t xattr_prefix_count;
+  grub_uint32_txattr_prefix_start;
+  grub_uint64_tpacked_nid;
+  grub_uint8_t reserved2[24];
 } GRUB_PACKED;
 
 #define EROFS_INODE_LAYOUT_COMPACT 0
@@ -89,8 +89,8 @@ struct grub_erofs_super
 
 struct grub_erofs_inode_chunk_info
 {
-  grub_uint16_t format;
-  grub_uint16_t reserved;
+  grub_uint16_tformat;
+  grub_uint16_treserved;
 } GRUB_PACKED;
 
 #define EROFS_CHUNK_FORMAT_BLKBITS_MASK0x001F
@@ -107,64 +107,64 @@ struct grub_erofs_inode_chunk_info
 
 struct grub_erofs_inode_chunk_index
 {
-  grub_uint16_t advise;
-  grub_uint16_t device_id;
-  grub_uint32_t blkaddr;
+  grub_uint16_tadvise;
+  grub_uint16_tdevice_id;
+  grub_uint32_tblkaddr;
 };
 
 union grub_erofs_inode_i_u
 {
-  grub_uint32_t compressed_blocks;
-  grub_uint32_t raw_blkaddr;
+  grub_uint32_tcompressed_blocks;
+  grub_uint32_traw_blkaddr;
 
-  grub_uint32_t rdev;
+  grub_uint32_trdev;
 
-  struct grub_erofs_inode_chunk_info c;
+  struct grub_erofs_inode_chunk_info   c;
 };
 
 struct grub_erofs_inode_compact
 {
-  grub_uint16_t i_format;
+  grub_uint16_ti_format;
 
-  grub_uint16_t i_xattr_icount;
-  grub_uint16_t i_mode;
-  grub_uint16_t 

Re: [PATCH v11 1/2] fs/erofs: Add support for EROFS

2024-05-16 Thread Gao Xiang

Hi Daniel,

On 2024/5/17 08:34, Gao Xiang wrote:

Hi Daniel,

On 2024/5/17 05:33, Daniel Kiper wrote:

On Fri, May 10, 2024 at 08:52:55AM +0800, Gao Xiang wrote:


...



In general patch LGTM except some nits...


Thanks for the comments.  Let me address them.


I've addressed your comments as a try, please kindly take
some time at the latest diff and full version...

https://lore.kernel.org/grub-devel/20240517044054.2752375-1-hsiang...@linux.alibaba.com

Thanks,
Gao Xiang





Daniel


___
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel