File 0001-blsuki-Add-support-for-LoaderEntries.patch of Package grub2

From cefeef68dc16afc9428199959ec98a8af94dc93d Mon Sep 17 00:00:00 2001
From: Danilo Spinella <danilo.spinella@suse.com>
Date: Tue, 10 Mar 2026 16:38:34 +0100
Subject: [PATCH 1/7] blsuki: Add support for LoaderEntries

---
 grub-core/commands/blsuki.c | 63 +++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
index 4133d3111..e69d40473 100644
--- a/grub-core/commands/blsuki.c
+++ b/grub-core/commands/blsuki.c
@@ -33,9 +33,12 @@
 #include <filevercmp.h>
 
 #ifdef GRUB_MACHINE_EFI
+#include <grub/charset.h>
 #include <grub/efi/efi.h>
 #include <grub/efi/disk.h>
 #include <grub/efi/pe32.h>
+
+static const grub_guid_t bli_vendor_guid = GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID;
 #endif
 
 #ifdef GRUB_MACHINE_EMU
@@ -1383,6 +1386,13 @@ blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id,
   const char *def_entry = NULL;
   grub_blsuki_entry_t *entry = NULL;
   int idx = 0;
+#ifdef GRUB_MACHINE_EFI
+  grub_size_t size = 0, remaining_size;
+  grub_efi_char16_t *efi_entries = NULL;
+  grub_efi_char16_t *p = NULL;
+  grub_size_t len;
+  char* boot_counting_idx;
+#endif
 
   def_entry = grub_env_get ("default");
 
@@ -1402,6 +1412,19 @@ blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id,
 #ifdef GRUB_MACHINE_EFI
 	  else if (cmd_type == BLSUKI_UKI_CMD)
 	    uki_create_entry (entry);
+
+        /* Calculate the size of LoaderEntries string */
+	  len = grub_strlen (entry->filename);
+          /* Skip boot counting if found */
+	  boot_counting_idx = grub_strrchr(entry->filename, '+');
+	  if (boot_counting_idx != NULL)
+	    len = boot_counting_idx - entry->filename - 1;
+          /* Skip ".conf" extension if found */
+	  else if (len > BLS_EXT_LEN
+	      && grub_strcmp (entry->filename + len - BLS_EXT_LEN, ".conf") == 0)
+	    len -= BLS_EXT_LEN;
+
+	  size += len;
 #endif
 	  entry->visible = true;
 	}
@@ -1409,6 +1432,46 @@ blsuki_create_entries (bool show_default, bool show_non_default, char *entry_id,
       idx++;
     }
 
+#ifdef GRUB_MACHINE_EFI
+  efi_entries = grub_malloc (size * sizeof (grub_efi_char16_t));
+  if (efi_entries == NULL)
+    return grub_errno;
+
+  p = efi_entries;
+  remaining_size = size;
+  /* Create a null separated list of all entries (with the extension removed) */
+  FOR_BLSUKI_ENTRIES (entry)
+    {
+      if (entry->visible)
+	{
+	  len = grub_strlen (entry->filename);
+
+	  boot_counting_idx = grub_strrchr(entry->filename, '+');
+	  if (boot_counting_idx != NULL)
+	    len = boot_counting_idx - entry->filename - 1;
+          else if ((len > BLS_EXT_LEN)
+	      && grub_strcmp (entry->filename + len - BLS_EXT_LEN, ".conf") == 0)
+	    len -= BLS_EXT_LEN;
+
+	  if (remaining_size < len)
+	    {
+	      grub_dprintf ("blsuki", "LoaderEntries buffer too small\n");
+	      break;
+	    }
+
+	  grub_utf8_to_utf16 (p, remaining_size, (grub_uint8_t*) entry->filename, len, NULL);
+	  p += len - 1;
+	  *p++ = '\0';
+	  remaining_size -= len;
+	}
+    }
+  grub_efi_set_variable_with_attributes ("LoaderEntries", &bli_vendor_guid,
+					 efi_entries, size * sizeof (grub_efi_char16_t),
+					 GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS |
+					 GRUB_EFI_VARIABLE_RUNTIME_ACCESS);
+  grub_free (efi_entries);
+#endif
+
   return GRUB_ERR_NONE;
 }
 
-- 
2.53.0

openSUSE Build Service is sponsored by