Skip to contentSkip to conversation

blsuki: Add uki command to load Unified Kernel Image entries

PATCH Avnish Chouhan 2 participants 2 messages May 30, 2025 – Jun 3, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 19 lines

Message: 1
Date: Wed, 21 May 2025 12:51:26 +0000
From: Alec Brown <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v4 4/4] blsuki: Add uki command to load Unified Kernel
Image entries
Message-ID: <[email protected]>

A Unified Kernel Image is a single UEFI PE file that combines a UEFI boot stub, a Linux kernel image, an initrd, and further resources. The uki command will locate where the UKI file is and create a GRUB menu entry to load it.

The Unified Kernel Image Specification:
https://uapi-group.org/specifications/specs/unified_kernel_image/

Quoted 7 lines
---
 docs/grub.texi              |  33 +++
 grub-core/commands/blsuki.c | 463 +++++++++++++++++++++++++++++++++---
 include/grub/menu.h         |   2 +
 3 files changed, 463 insertions(+), 35 deletions(-)

.
.
.

Review

Quoted 12 lines

+/*
+ * This function searches for the .cmdline, .osrel, and .linux sections of a
+ * UKI. We only need to store the data for the .cmdline and .osrel sections,
+ * but we also need to verify that the .linux section exists.
+ */

(quoted diff) +4 -0
+#ifdef GRUB_MACHINE_EFI
+static grub_err_t
+uki_parse_keyvals (grub_file_t f, grub_blsuki_entry_t *entry)
+{

.
.
.

Quoted 65 lines
(quoted diff) +14 -0
+
+  for (int i = 0; i < coff_header->num_sections; i++)
+    {
+      key = NULL;
+      val = NULL;
+      section = grub_zalloc (sizeof (*section));
+      if (section == NULL)
+	{
+	  err = grub_errno;
+	  goto finish;
+	}
+
+      if (grub_file_seek (f, section_offset) == (grub_off_t) -1 ||
+          grub_file_read (f, section, sizeof (*section)) != sizeof 

(*section))

(quoted diff) +2 -0
+	{
+	  err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read

section header");

(quoted diff) +16 -0
+	  goto finish;
+	}
+
+      key = grub_strndup (section->name, 8);
+      if (key == NULL)
+	{
+	  err = grub_errno;
+	  goto finish;
+	}
+
+      for (int j = 0; target[j] != NULL; j++)
+	{
+	  if (grub_strcmp (key, target[j]) == 0)
+	    {
+	      /*
+	       * We don't need to read the contents of the .linux PE section, 

but we

(quoted diff) +16 -0
+	       * should verify that the section exists.
+	       */
+	      if (grub_strcmp (key, ".linux") == 0)
+		{
+		  has_linux = true;
+		  break;
+		}
+
+	      val = grub_zalloc (section->raw_data_size);
+	      if (val == NULL)
+		{
+		  err = grub_errno;
+		  goto finish;
+		}
+
+	      if (grub_file_seek (f, section->raw_data_offset) == 

(grub_off_t) -1 ||

(quoted diff) +1 -0
+		  grub_file_read (f, val, section->raw_data_size) != (grub_ssize_t)

section->raw_data_size)

(quoted diff) +2 -0
+		{
+		  err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read 

section");

(quoted diff) +8 -0
+		  goto finish;
+		}
+
+	      err = blsuki_add_keyval (entry, key, val);
+	      if (err != GRUB_ERR_NONE)
+		goto finish;
+
+	      break;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	    }
+	}
+
+      section_offset += sizeof (*section);
+      grub_free (section);
+      grub_free (val);
+      grub_free (key);
+      section = NULL;
+      val = NULL;
+      key = NULL;

Hi Alec,

These couple of NULL statements above seems redundant as you are doing the same in the starting of the loop!

And it seems there are some indentation issues in "if" conditions and "loops" in multiple places which probably needs to be checked/fixed.

Suggestion : Adding a new line after the loop or a condition would be good! I see some statements has, some doesn't.

Thank you,

Regards,
Avnish Chouhan

.
.
.

Quoted 9 lines

};
typedef struct grub_blsuki_entry grub_blsuki_entry_t;
--
2.27.0

------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw

[External] : Re: [PATCH v4 4/4] blsuki: Add uki command to load Unified Kernel Image entries

Quoted 125 lines · Avnish Chouhan
Quoted 22 lines

Message: 1
Date: Wed, 21 May 2025 12:51:26 +0000
From: Alec Brown <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v4 4/4] blsuki: Add uki command to load Unified Kernel
Image entries
Message-ID: <[email protected]>

A Unified Kernel Image is a single UEFI PE file that combines a UEFI boot stub, a Linux kernel image, an initrd, and further resources. The uki command will locate where the UKI file is and create a GRUB menu entry to load it.

The Unified Kernel Image Specification:
https://urldefense.com/v3/__https://uapi-group.org/specifications/spec
s/unified_kernel_image/__;!!ACWV5N9M2RV99hQ!MLcCQykiFNenp16SX023gevWvP 4pETCVqAOq96F90j7i6HTTXoeUZAVSGOGc2rcLXQWEEwXZmF02M-W1xmoX$

Quoted 7 lines
---
 docs/grub.texi              |  33 +++
 grub-core/commands/blsuki.c | 463 +++++++++++++++++++++++++++++++++---
 include/grub/menu.h         |   2 +
 3 files changed, 463 insertions(+), 35 deletions(-)

.
.
.

Review

Quoted 11 lines

+/*
+ * This function searches for the .cmdline, .osrel, and .linux sections of a
+ * UKI. We only need to store the data for the .cmdline and .osrel sections,
+ * but we also need to verify that the .linux section exists.
+ */

(quoted diff) +3 -0
+#ifdef GRUB_MACHINE_EFI
+static grub_err_t
+uki_parse_keyvals (grub_file_t f, grub_blsuki_entry_t *entry) {

.
.
.

Quoted 66 lines
(quoted diff) +14 -0
+
+  for (int i = 0; i < coff_header->num_sections; i++)
+    {
+      key = NULL;
+      val = NULL;
+      section = grub_zalloc (sizeof (*section));
+      if (section == NULL)
+	{
+	  err = grub_errno;
+	  goto finish;
+	}
+
+      if (grub_file_seek (f, section_offset) == (grub_off_t) -1 ||
+          grub_file_read (f, section, sizeof (*section)) != sizeof

(*section))

(quoted diff) +2 -0
+	{
+	  err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read

section header");

(quoted diff) +17 -0
+	  goto finish;
+	}
+
+      key = grub_strndup (section->name, 8);
+      if (key == NULL)
+	{
+	  err = grub_errno;
+	  goto finish;
+	}
+
+      for (int j = 0; target[j] != NULL; j++)
+	{
+	  if (grub_strcmp (key, target[j]) == 0)
+	    {
+	      /*
+	       * We don't need to read the contents of the .linux PE
+section,

but we

(quoted diff) +16 -0
+	       * should verify that the section exists.
+	       */
+	      if (grub_strcmp (key, ".linux") == 0)
+		{
+		  has_linux = true;
+		  break;
+		}
+
+	      val = grub_zalloc (section->raw_data_size);
+	      if (val == NULL)
+		{
+		  err = grub_errno;
+		  goto finish;
+		}
+
+	      if (grub_file_seek (f, section->raw_data_offset) ==

(grub_off_t) -1 ||

(quoted diff) +1 -0
+		  grub_file_read (f, val, section->raw_data_size) != (grub_ssize_t)

section->raw_data_size)

(quoted diff) +2 -0
+		{
+		  err = grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read

section");

(quoted diff) +8 -0
+		  goto finish;
+		}
+
+	      err = blsuki_add_keyval (entry, key, val);
+	      if (err != GRUB_ERR_NONE)
+		goto finish;
+
+	      break;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	    }
+	}
+
+      section_offset += sizeof (*section);
+      grub_free (section);
+      grub_free (val);
+      grub_free (key);
+      section = NULL;
+      val = NULL;
+      key = NULL;

Hi Alec,

Quoted 3 lines

These couple of NULL statements above seems redundant as you are doing the same in the starting of the loop!

Hi Avnish,

I moved them to the end of the loop so that we won't have to worry about a double free once the loop finishes but it looks like I forgot to remove the NULL statements at the start. I'll fix that.

Quoted 2 lines

And it seems there are some indentation issues in "if" conditions and "loops" in multiple places which probably needs to be checked/fixed.

Same thing with the other patches, the indentation looks strange because tabs are being used in place of 8 spaces and the formatting of the patch looks strange because of it.

Quoted 3 lines

Suggestion : Adding a new line after the loop or a condition would be good! I see some statements has, some doesn't.

Sure thing!

Quoted 6 lines

Thank you,

Regards,
Avnish Chouhan

Thanks for looking over these patches!

Alec Brown

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel