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

Subscribers

People subscribed via source and target branches