ppc/mkimage: SBAT support on powerpc
Resolves: #RHEL-87421 Signed-off-by: Nicolas Frayer <nfrayer@redhat.com>
This commit is contained in:
parent
6b93e67189
commit
f00a43d2a6
167
0465-grub-mkimage-Create-new-ELF-note-for-SBAT.patch
Normal file
167
0465-grub-mkimage-Create-new-ELF-note-for-SBAT.patch
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
|
||||||
|
Date: Wed, 23 Oct 2024 17:54:32 +0530
|
||||||
|
Subject: [PATCH] grub-mkimage: Create new ELF note for SBAT
|
||||||
|
|
||||||
|
In order to store the SBAT data we create a new ELF note. The string
|
||||||
|
".sbat", zero-padded to 4 byte alignment, shall be entered in the name
|
||||||
|
field. The string "SBAT"'s ASCII values, 0x53424154, should be entered
|
||||||
|
in the type field.
|
||||||
|
|
||||||
|
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||||
|
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
|
||||||
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||||
|
---
|
||||||
|
include/grub/util/mkimage.h | 4 ++--
|
||||||
|
util/grub-mkimagexx.c | 48 +++++++++++++++++++++++++++++++++++++++++++--
|
||||||
|
util/mkimage.c | 5 +++--
|
||||||
|
3 files changed, 51 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h
|
||||||
|
index 6f1da89b9b65..881e3031f41f 100644
|
||||||
|
--- a/include/grub/util/mkimage.h
|
||||||
|
+++ b/include/grub/util/mkimage.h
|
||||||
|
@@ -51,12 +51,12 @@ grub_mkimage_load_image64 (const char *kernel_path,
|
||||||
|
const struct grub_install_image_target_desc *image_target);
|
||||||
|
void
|
||||||
|
grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
|
||||||
|
- int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||||
|
+ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size,
|
||||||
|
Elf32_Addr target_addr,
|
||||||
|
struct grub_mkimage_layout *layout);
|
||||||
|
void
|
||||||
|
grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
|
||||||
|
- int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||||
|
+ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size,
|
||||||
|
Elf64_Addr target_addr,
|
||||||
|
struct grub_mkimage_layout *layout);
|
||||||
|
|
||||||
|
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
|
||||||
|
index 393119486d3f..3609015673ec 100644
|
||||||
|
--- a/util/grub-mkimagexx.c
|
||||||
|
+++ b/util/grub-mkimagexx.c
|
||||||
|
@@ -115,6 +115,14 @@ struct section_metadata
|
||||||
|
const char *strtab;
|
||||||
|
};
|
||||||
|
|
||||||
|
+#define GRUB_SBAT_NOTE_NAME ".sbat"
|
||||||
|
+#define GRUB_SBAT_NOTE_TYPE 0x53424154 /* "SBAT" */
|
||||||
|
+
|
||||||
|
+struct grub_sbat_note {
|
||||||
|
+ Elf32_Nhdr header;
|
||||||
|
+ char name[ALIGN_UP(sizeof(GRUB_SBAT_NOTE_NAME), 4)];
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
static int
|
||||||
|
is_relocatable (const struct grub_install_image_target_desc *image_target)
|
||||||
|
{
|
||||||
|
@@ -216,7 +224,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr)
|
||||||
|
|
||||||
|
void
|
||||||
|
SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target,
|
||||||
|
- int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||||
|
+ int note, size_t appsig_size, char *sbat, char **core_img, size_t *core_size,
|
||||||
|
Elf_Addr target_addr,
|
||||||
|
struct grub_mkimage_layout *layout)
|
||||||
|
{
|
||||||
|
@@ -225,10 +233,17 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||||
|
Elf_Ehdr *ehdr;
|
||||||
|
Elf_Phdr *phdr;
|
||||||
|
Elf_Shdr *shdr;
|
||||||
|
- int header_size, footer_size = 0;
|
||||||
|
+ int header_size, footer_size = 0, footer_offset = 0;
|
||||||
|
int phnum = 1;
|
||||||
|
int shnum = 4;
|
||||||
|
int string_size = sizeof (".text") + sizeof ("mods") + 1;
|
||||||
|
+ char *footer;
|
||||||
|
+
|
||||||
|
+ if (sbat)
|
||||||
|
+ {
|
||||||
|
+ phnum++;
|
||||||
|
+ footer_size += ALIGN_UP (sizeof (struct grub_sbat_note) + layout->sbat_size, 4);
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if (appsig_size)
|
||||||
|
{
|
||||||
|
@@ -262,6 +277,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||||
|
ehdr = (void *) elf_img;
|
||||||
|
phdr = (void *) (elf_img + sizeof (*ehdr));
|
||||||
|
shdr = (void *) (elf_img + sizeof (*ehdr) + phnum * sizeof (*phdr));
|
||||||
|
+ footer = elf_img + program_size + header_size;
|
||||||
|
memcpy (ehdr->e_ident, ELFMAG, SELFMAG);
|
||||||
|
ehdr->e_ident[EI_CLASS] = ELFCLASSXX;
|
||||||
|
if (!image_target->bigendian)
|
||||||
|
@@ -434,6 +450,8 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||||
|
phdr->p_filesz = grub_host_to_target32 (XEN_NOTE_SIZE);
|
||||||
|
phdr->p_memsz = 0;
|
||||||
|
phdr->p_offset = grub_host_to_target32 (header_size + program_size);
|
||||||
|
+ footer = ptr;
|
||||||
|
+ footer_offset = XEN_NOTE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (image_target->id == IMAGE_XEN_PVH)
|
||||||
|
@@ -467,6 +485,8 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||||
|
phdr->p_filesz = grub_host_to_target32 (XEN_PVH_NOTE_SIZE);
|
||||||
|
phdr->p_memsz = 0;
|
||||||
|
phdr->p_offset = grub_host_to_target32 (header_size + program_size);
|
||||||
|
+ footer = ptr;
|
||||||
|
+ footer_offset = XEN_PVH_NOTE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (note)
|
||||||
|
@@ -497,6 +517,30 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||||
|
phdr->p_filesz = grub_host_to_target32 (note_size);
|
||||||
|
phdr->p_memsz = 0;
|
||||||
|
phdr->p_offset = grub_host_to_target32 (header_size + program_size);
|
||||||
|
+ footer = (elf_img + program_size + header_size + note_size);
|
||||||
|
+ footer_offset += note_size;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (sbat)
|
||||||
|
+ {
|
||||||
|
+ int note_size = ALIGN_UP (sizeof (struct grub_sbat_note) + layout->sbat_size, 4);
|
||||||
|
+ struct grub_sbat_note *note_ptr = (struct grub_sbat_note *) footer;
|
||||||
|
+
|
||||||
|
+ note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_SBAT_NOTE_NAME));
|
||||||
|
+ note_ptr->header.n_descsz = grub_host_to_target32 (ALIGN_UP(layout->sbat_size, 4));
|
||||||
|
+ note_ptr->header.n_type = grub_host_to_target32 (GRUB_SBAT_NOTE_TYPE);
|
||||||
|
+ memcpy (note_ptr->name, GRUB_SBAT_NOTE_NAME, sizeof (GRUB_SBAT_NOTE_NAME));
|
||||||
|
+ memcpy ((char *)(note_ptr + 1), sbat, layout->sbat_size);
|
||||||
|
+
|
||||||
|
+ phdr++;
|
||||||
|
+ phdr->p_type = grub_host_to_target32 (PT_NOTE);
|
||||||
|
+ phdr->p_flags = grub_host_to_target32 (PF_R);
|
||||||
|
+ phdr->p_align = grub_host_to_target32 (image_target->voidp_sizeof);
|
||||||
|
+ phdr->p_vaddr = 0;
|
||||||
|
+ phdr->p_paddr = 0;
|
||||||
|
+ phdr->p_filesz = grub_host_to_target32 (note_size);
|
||||||
|
+ phdr->p_memsz = 0;
|
||||||
|
+ phdr->p_offset = grub_host_to_target32 (header_size + program_size + footer_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appsig_size) {
|
||||||
|
diff --git a/util/mkimage.c b/util/mkimage.c
|
||||||
|
index 9ba1a8988f19..358db8378422 100644
|
||||||
|
--- a/util/mkimage.c
|
||||||
|
+++ b/util/mkimage.c
|
||||||
|
@@ -1811,6 +1811,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||||
|
case IMAGE_I386_IEEE1275:
|
||||||
|
{
|
||||||
|
grub_uint64_t target_addr;
|
||||||
|
+ char *sbat = NULL;
|
||||||
|
if (image_target->id == IMAGE_LOONGSON_ELF)
|
||||||
|
{
|
||||||
|
if (comp == GRUB_COMPRESSION_NONE)
|
||||||
|
@@ -1822,10 +1823,10 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||||
|
else
|
||||||
|
target_addr = image_target->link_addr;
|
||||||
|
if (image_target->voidp_sizeof == 4)
|
||||||
|
- grub_mkimage_generate_elf32 (image_target, note, appsig_size, &core_img,
|
||||||
|
+ grub_mkimage_generate_elf32 (image_target, note, appsig_size, sbat, &core_img,
|
||||||
|
&core_size, target_addr, &layout);
|
||||||
|
else
|
||||||
|
- grub_mkimage_generate_elf64 (image_target, note, appsig_size, &core_img,
|
||||||
|
+ grub_mkimage_generate_elf64 (image_target, note, appsig_size, sbat, &core_img,
|
||||||
|
&core_size, target_addr, &layout);
|
||||||
|
}
|
||||||
|
break;
|
@ -0,0 +1,45 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
|
||||||
|
Date: Wed, 23 Oct 2024 17:54:33 +0530
|
||||||
|
Subject: [PATCH] grub-mkimage: Add SBAT metadata into ELF note for PowerPC
|
||||||
|
targets
|
||||||
|
|
||||||
|
The SBAT metadata is read from CSV file and transformed into an ELF note
|
||||||
|
with the -s option.
|
||||||
|
|
||||||
|
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||||
|
Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
|
||||||
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||||
|
---
|
||||||
|
util/mkimage.c | 11 +++++++++--
|
||||||
|
1 file changed, 9 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/util/mkimage.c b/util/mkimage.c
|
||||||
|
index 358db8378422..eaa382b2a120 100644
|
||||||
|
--- a/util/mkimage.c
|
||||||
|
+++ b/util/mkimage.c
|
||||||
|
@@ -941,8 +941,8 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||||
|
total_module_size += dtb_size + sizeof (struct grub_module_header);
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (sbat_path != NULL && image_target->id != IMAGE_EFI)
|
||||||
|
- grub_util_error (_(".sbat section can be embedded into EFI images only"));
|
||||||
|
+ if (sbat_path != NULL && (image_target->id != IMAGE_EFI && image_target->id != IMAGE_PPC))
|
||||||
|
+ grub_util_error (_("SBAT data can be added only to EFI or powerpc-ieee1275 images"));
|
||||||
|
|
||||||
|
if (disable_shim_lock)
|
||||||
|
total_module_size += sizeof (struct grub_module_header);
|
||||||
|
@@ -1812,6 +1812,13 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||||
|
{
|
||||||
|
grub_uint64_t target_addr;
|
||||||
|
char *sbat = NULL;
|
||||||
|
+ if (sbat_path != NULL)
|
||||||
|
+ {
|
||||||
|
+ sbat_size = grub_util_get_image_size (sbat_path);
|
||||||
|
+ sbat = xmalloc (sbat_size);
|
||||||
|
+ grub_util_load_image (sbat_path, sbat);
|
||||||
|
+ layout.sbat_size = sbat_size;
|
||||||
|
+ }
|
||||||
|
if (image_target->id == IMAGE_LOONGSON_ELF)
|
||||||
|
{
|
||||||
|
if (comp == GRUB_COMPRESSION_NONE)
|
@ -461,3 +461,5 @@ Patch0461: 0461-fs-xfs-Fix-XFS-directory-extent-parsing.patch
|
|||||||
Patch0462: 0462-fs-xfs-Add-large-extent-counters-incompat-feature-su.patch
|
Patch0462: 0462-fs-xfs-Add-large-extent-counters-incompat-feature-su.patch
|
||||||
Patch0463: 0463-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch
|
Patch0463: 0463-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch
|
||||||
Patch0464: 0464-fs-xfs-fix-large-extent-counters-incompat-feature-su.patch
|
Patch0464: 0464-fs-xfs-fix-large-extent-counters-incompat-feature-su.patch
|
||||||
|
Patch0465: 0465-grub-mkimage-Create-new-ELF-note-for-SBAT.patch
|
||||||
|
Patch0466: 0466-grub-mkimage-Add-SBAT-metadata-into-ELF-note-for-Pow.patch
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
Name: grub2
|
Name: grub2
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
Version: 2.06
|
Version: 2.06
|
||||||
Release: 104%{?dist}
|
Release: 105%{?dist}
|
||||||
Summary: Bootloader with support for Linux, Multiboot and more
|
Summary: Bootloader with support for Linux, Multiboot and more
|
||||||
License: GPLv3+
|
License: GPLv3+
|
||||||
URL: http://www.gnu.org/software/grub/
|
URL: http://www.gnu.org/software/grub/
|
||||||
@ -547,6 +547,10 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Apr 15 2025 Nicolas Frayer <nfrayer@redhat.com> - 2.06-105
|
||||||
|
- ppc/mkimage: SBAT support on powerpc
|
||||||
|
- Resolves: #RHEL-87421
|
||||||
|
|
||||||
* Thu Apr 3 2025 Nicolas Frayer <nfrayer@redhat.com> 2.06-104
|
* Thu Apr 3 2025 Nicolas Frayer <nfrayer@redhat.com> 2.06-104
|
||||||
- fs/xfs: Sync with latest xfs upstream
|
- fs/xfs: Sync with latest xfs upstream
|
||||||
- Resolves: #RHEL-85960
|
- Resolves: #RHEL-85960
|
||||||
|
Loading…
Reference in New Issue
Block a user