Merge ~xypron/grub:fixups into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by Heinrich Schuchardt
Status: Merged
Merged at revision: fdb8c44103af4ed21e9b7d3b2f55360932b84834
Proposed branch: ~xypron/grub:fixups
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 193 lines (+173/-0)
3 files modified
debian/patches/efi-EFI-Device-Tree-Fixup-Protocol.patch (+140/-0)
debian/patches/fdt-add-debug-output-to-devicetree-command.patch (+31/-0)
debian/patches/series (+2/-0)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+417641@code.launchpad.net

Commit message

efi: EFI Device Tree Fixup Protocol

Device-trees are used to convey information about hardware to the operating
system. Some of the properties are only known at boot time. (One example of
such a property is the number of the boot hart on RISC-V systems.) Therefore
the firmware applies fix-ups to the original device-tree. Some nodes and
properties are added or altered.

When using GRUB's device-tree command the same fix-ups have to be applied.
The EFI Device Tree Fixup Protocol allows to pass the loaded device tree
to the firmware for this purpose.

The protocol can

* add nodes and update properties
* reserve memory according to the /reserved-memory node and the memory
  reservation block
* install the device-tree as configuration table

With the series GRUB checks if the protocol is installed and invokes it if
available. (LP: #1965796)

For debugging we need feedback that the devicetree command has be executed.
Add debug output.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/patches/efi-EFI-Device-Tree-Fixup-Protocol.patch b/debian/patches/efi-EFI-Device-Tree-Fixup-Protocol.patch
0new file mode 1006440new file mode 100644
index 0000000..70dd184
--- /dev/null
+++ b/debian/patches/efi-EFI-Device-Tree-Fixup-Protocol.patch
@@ -0,0 +1,140 @@
1From: Heinrich Schuchardt <xypron.glpk@gmx.de>
2Date: Fri, 29 Jan 2021 07:36:42 +0100
3Subject: [PATCH] efi: EFI Device Tree Fixup Protocol
4
5Device-trees are used to convey information about hardware to the operating
6system. Some of the properties are only known at boot time. (One example of
7such a property is the number of the boot hart on RISC-V systems.) Therefore
8the firmware applies fix-ups to the original device-tree. Some nodes and
9properties are added or altered.
10
11When using GRUB's device-tree command the same fix-ups have to be applied.
12The EFI Device Tree Fixup Protocol allows to pass the loaded device tree
13to the firmware for this purpose.
14
15The protocol can
16
17* add nodes and update properties
18* reserve memory according to the /reserved-memory node and the memory
19 reservation block
20* install the device-tree as configuration table
21
22With the patch GRUB checks if the protocol is installed and invokes it if
23available. (LP: #1965796)
24
25Link: https://lists.gnu.org/archive/html/grub-devel/2021-02/msg00013.html
26Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
27---
28 grub-core/loader/efi/fdt.c | 37 +++++++++++++++++++++++++++++++++++++
29 include/grub/efi/api.h | 22 ++++++++++++++++++++++
30 2 files changed, 59 insertions(+)
31
32diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
33index b846bf35d..91691d913 100644
34--- a/grub-core/loader/efi/fdt.c
35+++ b/grub-core/loader/efi/fdt.c
36@@ -30,6 +30,7 @@
37
38 static void *loaded_fdt;
39 static void *fdt;
40+static grub_efi_guid_t dt_fixup_guid = GRUB_EFI_DT_FIXUP_PROTOCOL_GUID;
41
42 #define FDT_ADDR_CELLS_STRING "#address-cells"
43 #define FDT_SIZE_CELLS_STRING "#size-cells"
44@@ -37,6 +38,39 @@ static void *fdt;
45 sizeof (FDT_ADDR_CELLS_STRING) + \
46 sizeof (FDT_SIZE_CELLS_STRING))
47
48+static void *
49+grub_fdt_fixup (void)
50+{
51+ grub_efi_dt_fixup_t *dt_fixup_prot;
52+ grub_efi_uintn_t size = 0;
53+ grub_efi_status_t status;
54+ void *fixup_fdt;
55+
56+ dt_fixup_prot = grub_efi_locate_protocol (&dt_fixup_guid, 0);
57+ if (!dt_fixup_prot)
58+ return loaded_fdt;
59+
60+ grub_dprintf ("linux", "EFI_DT_FIXUP_PROTOCOL available\n");
61+
62+ status = efi_call_4 (dt_fixup_prot->fixup, dt_fixup_prot, loaded_fdt, &size,
63+ GRUB_EFI_DT_APPLY_FIXUPS | GRUB_EFI_DT_RESERVE_MEMORY);
64+ if (status != GRUB_EFI_BUFFER_TOO_SMALL)
65+ return loaded_fdt;
66+
67+ fixup_fdt = grub_realloc (loaded_fdt, size);
68+ if (!fixup_fdt)
69+ return loaded_fdt;
70+ loaded_fdt = fixup_fdt;
71+
72+ status = efi_call_4 (dt_fixup_prot->fixup, dt_fixup_prot, loaded_fdt, &size,
73+ GRUB_EFI_DT_APPLY_FIXUPS | GRUB_EFI_DT_RESERVE_MEMORY);
74+
75+ if (status == GRUB_EFI_SUCCESS)
76+ grub_dprintf ("linux", "Device tree fixed up via EFI_DT_FIXUP_PROTOCOL\n");
77+
78+ return loaded_fdt;
79+}
80+
81 void *
82 grub_fdt_load (grub_size_t additional_size)
83 {
84@@ -93,6 +127,9 @@ grub_fdt_install (void)
85 if (!fdt && !loaded_fdt)
86 return GRUB_ERR_NONE;
87
88+ if (loaded_fdt)
89+ loaded_fdt = grub_fdt_fixup();
90+
91 b = grub_efi_system_table->boot_services;
92 status = b->install_configuration_table (&fdt_guid, fdt ?: loaded_fdt);
93 if (status != GRUB_EFI_SUCCESS)
94diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
95index c5dd4af1b..c222a2e3b 100644
96--- a/include/grub/efi/api.h
97+++ b/include/grub/efi/api.h
98@@ -344,6 +344,11 @@
99 { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } \
100 }
101
102+#define GRUB_EFI_DT_FIXUP_PROTOCOL_GUID \
103+ { 0xe617d64c, 0xfe08, 0x46da, \
104+ { 0xf4, 0xdc, 0xbb, 0xd5, 0x87, 0x0c, 0x73, 0x00 } \
105+ }
106+
107 #define GRUB_EFI_VENDOR_APPLE_GUID \
108 { 0x2B0585EB, 0xD8B8, 0x49A9, \
109 { 0x8B, 0x8C, 0xE2, 0x1B, 0x01, 0xAE, 0xF2, 0xB7 } \
110@@ -1789,6 +1794,13 @@ enum
111 GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST = 0x10,
112 };
113
114+enum
115+ {
116+ GRUB_EFI_DT_APPLY_FIXUPS = 0x01,
117+ GRUB_EFI_DT_RESERVE_MEMORY = 0x02,
118+ GRUB_EFI_EFI_DT_INSTALL_TABLE = 0x04,
119+ };
120+
121 struct grub_efi_simple_network
122 {
123 grub_uint64_t revision;
124@@ -1852,6 +1864,16 @@ struct grub_efi_block_io
125 };
126 typedef struct grub_efi_block_io grub_efi_block_io_t;
127
128+struct grub_efi_dt_fixup
129+{
130+ grub_efi_uint64_t revision;
131+ grub_efi_status_t (*fixup) (struct grub_efi_dt_fixup *this,
132+ void *fdt,
133+ grub_efi_uintn_t *buffer_size,
134+ grub_uint32_t flags);
135+};
136+typedef struct grub_efi_dt_fixup grub_efi_dt_fixup_t;
137+
138 struct grub_efi_shim_lock_protocol
139 {
140 grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size);
diff --git a/debian/patches/fdt-add-debug-output-to-devicetree-command.patch b/debian/patches/fdt-add-debug-output-to-devicetree-command.patch
0new file mode 100644141new file mode 100644
index 0000000..fed033f
--- /dev/null
+++ b/debian/patches/fdt-add-debug-output-to-devicetree-command.patch
@@ -0,0 +1,31 @@
1From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2Date: Thu, 24 Mar 2022 13:21:26 +0100
3Subject: [PATCH] fdt: add debug output to devicetree command
4
5For debugging we need feedback that the devicetree command has be executed.
6
7Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
8---
9 grub-core/loader/efi/fdt.c | 2 ++
10 1 file changed, 2 insertions(+)
11
12diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
13index 6e4968a1a..fcd389253 100644
14--- a/grub-core/loader/efi/fdt.c
15+++ b/grub-core/loader/efi/fdt.c
16@@ -161,6 +161,7 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
17 /* No arguments means "use firmware FDT". */
18 if (argc == 0)
19 {
20+ grub_dprintf ("fdt", "Using firmware FDT\n");
21 return GRUB_ERR_NONE;
22 }
23
24@@ -192,6 +193,7 @@ out:
25
26 if (blob)
27 {
28+ grub_dprintf ("fdt", "Device-tree %s loaded\n", argv[0]);
29 if (grub_errno == GRUB_ERR_NONE)
30 loaded_fdt = blob;
31 else
diff --git a/debian/patches/series b/debian/patches/series
index 7c2c2d4..24509f9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -123,3 +123,5 @@ efi-implement-grub_efi_run_image.patch
123fat-fix-listing-the-root-directory.patch123fat-fix-listing-the-root-directory.patch
124efivar-check-that-efivarfs-is-writeable.patch124efivar-check-that-efivarfs-is-writeable.patch
125linuxefi-do-not-validate-kernels-twice.patch125linuxefi-do-not-validate-kernels-twice.patch
126fdt-add-debug-output-to-devicetree-command.patch
127efi-EFI-Device-Tree-Fixup-Protocol.patch

Subscribers

People subscribed via source and target branches