Add BLS devicetree support and a couple of RISC-V fixes

- A couple of RISC-V fixes
- Remove grub2-tools %%posttrans scriptlet that migrates to a BLS config
- Add blscfg device tree support
  Resolves: rhbz#1751307

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
This commit is contained in:
Javier Martinez Canillas 2019-09-18 10:01:25 +02:00
parent e1531466e1
commit be6e591e0f
No known key found for this signature in database
GPG Key ID: C751E590D63F3D69
6 changed files with 257 additions and 8 deletions

View File

@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Tue, 27 Aug 2019 10:34:24 +0200
Subject: [PATCH] Fix build error with the fdt module on risc-v
The risc-v architecture also uses Device Trees, but the symbols in the
fdt header aren't defined for this arch which lead to following error:
BUILDSTDERR: ../../grub-core/loader/efi/fdt.c: In function 'grub_fdt_load':
BUILDSTDERR: ../../grub-core/loader/efi/fdt.c:48:39: warning: implicit declaration of function 'grub_fdt_get_totalsize' [-Wimplicit-function-declaration]
BUILDSTDERR: 48 | size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt));
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
include/grub/fdt.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/grub/fdt.h b/include/grub/fdt.h
index 2041341fd68..3514aa4a5b6 100644
--- a/include/grub/fdt.h
+++ b/include/grub/fdt.h
@@ -19,7 +19,8 @@
#ifndef GRUB_FDT_HEADER
#define GRUB_FDT_HEADER 1
-#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__))
+#if !defined(GRUB_MACHINE_EMU) && \
+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv))
#include <grub/types.h>
#include <grub/symbol.h>
@@ -146,6 +147,7 @@ int EXPORT_FUNC(grub_fdt_set_prop) (void *fdt, unsigned int nodeoffset, const ch
grub_fdt_set_prop ((fdt), (nodeoffset), "reg", reg_64, 16); \
})
-#endif /* defined(__arm__) || defined(__aarch64__) */
+#endif /* !defined(GRUB_MACHINE_EMU) && \
+ (defined(__arm__) || defined(__aarch64__) || defined(__riscv)) */
#endif /* ! GRUB_FDT_HEADER */

View File

@ -0,0 +1,36 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andreas Schwab <schwab@suse.de>
Date: Wed, 26 Jun 2019 16:50:03 +0200
Subject: [PATCH] RISC-V: Fix computation of pc-relative relocation offset
The offset calculation was missing the relocation addend.
Signed-off-by: Andreas Schwab <schwab@suse.de>
Tested-by: Chester Lin <clin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
util/grub-mkimagexx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
index bc087c2b57f..d16ec63a16f 100644
--- a/util/grub-mkimagexx.c
+++ b/util/grub-mkimagexx.c
@@ -1232,8 +1232,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
grub_uint32_t *t32 = (grub_uint32_t *) target;
grub_uint16_t *t16 = (grub_uint16_t *) target;
grub_uint8_t *t8 = (grub_uint8_t *) target;
- grub_int64_t off = (long)sym_addr - target_section_addr - offset
- - image_target->vaddr_offset;
+ grub_int64_t off;
/*
* Instructions and instruction encoding are documented in the RISC-V
@@ -1243,6 +1242,7 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
*/
sym_addr += addend;
+ off = sym_addr - target_section_addr - offset - image_target->vaddr_offset;
switch (ELF_R_TYPE (info))
{

View File

@ -0,0 +1,132 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Sun, 15 Sep 2019 09:37:45 +0200
Subject: [PATCH] blscfg: Add support for the devicetree field
The BootLoaderSpec mentions that a devicetree field can be used to pass a
Device Tree (DT) to the kernel, for the platforms that use it to describe
information about the hardware.
Allow the blscfg module to parse this field and call the grub2 devicetree
command in that case. If there is a devicetree grub2 environment variable
defined, this will be used if the field is not defined in the BLS snippet.
Resolves: rhbz#1751307
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
grub-core/commands/blscfg.c | 60 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 3 deletions(-)
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
index 54458b14518..1ec89870483 100644
--- a/grub-core/commands/blscfg.c
+++ b/grub-core/commands/blscfg.c
@@ -698,6 +698,8 @@ static void create_entry (struct bls_entry *entry)
const char *early_initrd = NULL;
char **early_initrds = NULL;
char *initrd_prefix = NULL;
+ char *devicetree = NULL;
+ char *dt = NULL;
char *id = entry->filename;
char *dotconf = id;
char *hotkey = NULL;
@@ -709,6 +711,7 @@ static void create_entry (struct bls_entry *entry)
char *src = NULL;
int i, index;
+ bool add_dt_prefix = false;
grub_dprintf("blscfg", "%s got here\n", __func__);
clinux = bls_get_val (entry, "linux", NULL);
@@ -736,6 +739,14 @@ static void create_entry (struct bls_entry *entry)
initrds = bls_make_list (entry, "initrd", NULL);
+ devicetree = expand_val (bls_get_val (entry, "devicetree", NULL));
+
+ if (!devicetree)
+ {
+ devicetree = expand_val (grub_env_get("devicetree"));
+ add_dt_prefix = true;
+ }
+
hotkey = bls_get_val (entry, "grub_hotkey", NULL);
users = expand_val (bls_get_val (entry, "grub_users", NULL));
classes = bls_make_list (entry, "grub_class", NULL);
@@ -801,7 +812,6 @@ static void create_entry (struct bls_entry *entry)
goto finish;
}
-
tmp = grub_stpcpy(initrd, "initrd");
for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++)
{
@@ -821,21 +831,65 @@ static void create_entry (struct bls_entry *entry)
tmp = grub_stpcpy (tmp, "\n");
}
+ if (devicetree)
+ {
+ char *prefix = NULL;
+ int dt_size;
+
+ if (add_dt_prefix)
+ {
+ prefix = grub_strrchr (clinux, '/');
+ prefix = grub_strndup(clinux, prefix - clinux + 1);
+ if (!prefix)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ goto finish;
+ }
+ }
+
+ dt_size = sizeof("devicetree " GRUB_BOOT_DEVICE) + grub_strlen(devicetree) + 1;
+
+ if (add_dt_prefix)
+ {
+ dt_size += grub_strlen(prefix);
+ }
+
+ dt = grub_malloc (dt_size);
+ if (!dt)
+ {
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
+ goto finish;
+ }
+ char *tmp = dt;
+ tmp = grub_stpcpy (dt, "devicetree");
+ tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
+ if (add_dt_prefix)
+ tmp = grub_stpcpy (tmp, prefix);
+ tmp = grub_stpcpy (tmp, devicetree);
+ tmp = grub_stpcpy (tmp, "\n");
+
+ grub_free(prefix);
+ }
+
+ grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id);
+
src = grub_xasprintf ("load_video\n"
"set gfxpayload=keep\n"
"insmod gzio\n"
"linux %s%s%s%s\n"
- "%s",
+ "%s%s",
GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
- initrd ? initrd : "");
+ initrd ? initrd : "", dt ? dt : "");
grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index, entry);
grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id);
finish:
+ grub_free (dt);
grub_free (initrd);
grub_free (initrd_prefix);
grub_free (early_initrds);
+ grub_free (devicetree);
grub_free (initrds);
grub_free (options);
grub_free (classes);

View File

@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Sun, 15 Sep 2019 10:05:29 +0200
Subject: [PATCH] Set a devicetree var in a BLS config if GRUB_DEFAULT_DTB is
present
The BootLoaderSpec mentions that a devicetree field can be used to pass a
Device Tree (DT) to the kernel, for the platforms that use it to describe
information about the hardware.
The blscfg module supports parsing the field from the BLS snippets but it
allows to set a DT for all the entries if a devicetree env var is defined.
Make the grub2-mkconfig tool to set this variable if GRUB_DEFAULT_DTB was
defined in the /etc/default/grub file.
Resolves: rhbz#1751307
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
util/grub.d/10_linux.in | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 301594a0c9e..1520b7e47c1 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -138,6 +138,10 @@ EOF
if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then
${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}"
fi
+
+ if [ -n "${GRUB_DEFAULT_DTB}" ]; then
+ ${grub_editenv} - set devicetree="${GRUB_DEFAULT_DTB}"
+ fi
fi
exit 0

View File

@ -176,3 +176,7 @@ Patch0175: 0175-Do-better-in-bootstrap.conf.patch
Patch0176: 0176-Use-git-to-apply-gnulib-patches.patch
Patch0177: 0177-autogen.sh-use-find-wholename-for-long-path-matches.patch
Patch0178: 0178-bootstrap.conf-don-t-clobber-AM_CFLAGS-here.patch
Patch0179: 0179-Fix-build-error-with-the-fdt-module-on-risc-v.patch
Patch0180: 0180-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch
Patch0181: 0181-blscfg-Add-support-for-the-devicetree-field.patch
Patch0182: 0182-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch

View File

@ -9,7 +9,7 @@
Name: grub2
Epoch: 1
Version: 2.04
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Bootloader with support for Linux, Multiboot and more
License: GPLv3+
URL: http://www.gnu.org/software/grub/
@ -311,13 +311,6 @@ elif [ -f /etc/grub.d/01_users ] && \
fi
fi
%posttrans tools
if [ -f /etc/default/grub ]; then
! grep -q '^GRUB_ENABLE_BLSCFG=.*' /etc/default/grub && \
/sbin/grub2-switch-to-blscfg --backup-suffix=.rpmsave &>/dev/null || :
fi
%triggerun -- grub2 < 1:1.99-4
# grub2 < 1.99-4 removed a number of essential files in postun. To fix upgrades
# from the affected grub2 packages, we first back up the files in triggerun and
@ -522,6 +515,12 @@ rm -r /boot/grub2.tmp/ || :
%endif
%changelog
* Wed Sep 18 2019 Javier Martinez Canillas <javierm@redhat.com> - 2.04-2
- A couple of RISC-V fixes
- Remove grub2-tools %%posttrans scriptlet that migrates to a BLS config
- Add blscfg device tree support
Resolves: rhbz#1751307
* Thu Aug 15 2019 Javier Martinez Canillas <javierm@redhat.com> - 2.04-1
- Update to 2.04
Resolves: rhbz#1727279