diff --git a/.git.diff.order b/.git.diff.order new file mode 100644 index 0000000..fca2682 --- /dev/null +++ b/.git.diff.order @@ -0,0 +1,15 @@ +*.dec +*.dsc.inc +*.dsc +*.fdf +*.inf +*.vfr +*.ac +*.def +*.c +*.h +*.S +*.mk +Makefile.* +Make.* +Makefile diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..33ffaa4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +po/exclude.pot binary diff --git a/.gitignore b/.gitignore index e69de29..19364b8 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,13 @@ +grub-*.tar.?z +*.rpm +clog +/unifont-5.1.20080820.pcf.gz +/theme.tar.bz2 +kojilogs +/grub-*/ +.build*.log +.*.git/ +tmp/ +.*.sw? +results_grub2/ +/gnulib-*.tar.?z diff --git a/0001-Add-support-for-Linux-EFI-stub-loading.patch b/0001-Add-support-for-Linux-EFI-stub-loading.patch new file mode 100644 index 0000000..95c7cd5 --- /dev/null +++ b/0001-Add-support-for-Linux-EFI-stub-loading.patch @@ -0,0 +1,984 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Fri, 5 Jul 2019 18:36:44 +0200 +Subject: [PATCH] Add support for Linux EFI stub loading. + +Also: + +commit 71c843745f22f81e16d259e2e19c99bf3c1855c1 +Author: Colin Watson +Date: Tue Oct 23 10:40:49 2012 -0400 + +Don't allow insmod when secure boot is enabled. + +Hi, + +Fedora's patch to forbid insmod in UEFI Secure Boot environments is fine +as far as it goes. However, the insmod command is not the only way that +modules can be loaded. In particular, the 'normal' command, which +implements the usual GRUB menu and the fully-featured command prompt, +will implicitly load commands not currently loaded into memory. This +permits trivial Secure Boot violations by writing commands implementing +whatever you want to do and pointing $prefix at the malicious code. + +I'm currently test-building this patch (replacing your current +grub-2.00-no-insmod-on-sb.patch), but this should be more correct. It +moves the check into grub_dl_load_file. +--- + grub-core/Makefile.core.def | 16 +- + grub-core/kern/dl.c | 21 +++ + grub-core/kern/efi/efi.c | 28 ++++ + grub-core/kern/efi/mm.c | 32 ++++ + grub-core/loader/arm64/linux.c | 118 +++++++------- + grub-core/loader/arm64/xen_boot.c | 1 - + grub-core/loader/efi/linux.c | 70 ++++++++ + grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++ + grub-core/loader/i386/pc/linux.c | 10 +- + include/grub/arm/linux.h | 9 + + include/grub/arm64/linux.h | 10 ++ + include/grub/efi/efi.h | 7 +- + include/grub/efi/linux.h | 31 ++++ + 13 files changed, 619 insertions(+), 69 deletions(-) + create mode 100644 grub-core/loader/efi/linux.c + create mode 100644 grub-core/loader/i386/efi/linux.c + create mode 100644 include/grub/efi/linux.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 474a63e68c5..581d9dfc3b3 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1709,13 +1709,6 @@ module = { + enable = i386_pc; + }; + +- +-module = { +- name = linux16; +- common = loader/i386/pc/linux.c; +- enable = x86; +-}; +- + module = { + name = ntldr; + i386_pc = loader/i386/pc/ntldr.c; +@@ -1771,7 +1764,9 @@ module = { + + module = { + name = linux; +- x86 = loader/i386/linux.c; ++ i386_pc = loader/i386/pc/linux.c; ++ x86_64_efi = loader/i386/efi/linux.c; ++ i386_efi = loader/i386/efi/linux.c; + i386_xen_pvh = loader/i386/linux.c; + xen = loader/i386/xen.c; + i386_pc = lib/i386/pc/vesa_modes_table.c; +@@ -1786,9 +1781,14 @@ module = { + arm64 = loader/arm64/linux.c; + riscv32 = loader/riscv/linux.c; + riscv64 = loader/riscv/linux.c; ++ emu = loader/emu/linux.c; ++ fdt = lib/fdt.c; ++ + common = loader/linux.c; + common = lib/cmdline.c; + enable = noemu; ++ ++ efi = loader/efi/linux.c; + }; + + module = { +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 48eb5e7b627..896bebfd57e 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -38,6 +38,14 @@ + #define GRUB_MODULES_MACHINE_READONLY + #endif + ++#ifdef GRUB_MACHINE_EMU ++#include ++#endif ++ ++#ifdef GRUB_MACHINE_EFI ++#include ++#endif ++ + + + #pragma GCC diagnostic ignored "-Wcast-align" +@@ -686,6 +694,19 @@ grub_dl_load_file (const char *filename) + void *core = 0; + grub_dl_t mod = 0; + ++#ifdef GRUB_MACHINE_EFI ++ if (grub_efi_secure_boot ()) ++ { ++#if 0 ++ /* This is an error, but grub2-mkconfig still generates a pile of ++ * insmod commands, so emitting it would be mostly just obnoxious. */ ++ grub_error (GRUB_ERR_ACCESS_DENIED, ++ "Secure Boot forbids loading module from %s", filename); ++#endif ++ return 0; ++ } ++#endif ++ + grub_boot_time ("Loading module %s", filename); + + file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 6e1ceb90516..a0faa40ecf0 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -273,6 +273,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + return NULL; + } + ++grub_efi_boolean_t ++grub_efi_secure_boot (void) ++{ ++ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; ++ grub_size_t datasize; ++ char *secure_boot = NULL; ++ char *setup_mode = NULL; ++ grub_efi_boolean_t ret = 0; ++ ++ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); ++ ++ if (datasize != 1 || !secure_boot) ++ goto out; ++ ++ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); ++ ++ if (datasize != 1 || !setup_mode) ++ goto out; ++ ++ if (*secure_boot && !*setup_mode) ++ ret = 1; ++ ++ out: ++ grub_free (secure_boot); ++ grub_free (setup_mode); ++ return ret; ++} ++ + #pragma GCC diagnostic ignored "-Wcast-align" + + /* Search the mods section from the PE32/PE32+ image. This code uses +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index b02fab1b102..a9e37108c6d 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address, + } + } + ++/* Allocate pages below a specified address */ ++void * ++grub_efi_allocate_pages_max (grub_efi_physical_address_t max, ++ grub_efi_uintn_t pages) ++{ ++ grub_efi_status_t status; ++ grub_efi_boot_services_t *b; ++ grub_efi_physical_address_t address = max; ++ ++ if (max > 0xffffffff) ++ return 0; ++ ++ b = grub_efi_system_table->boot_services; ++ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ ++ if (address == 0) ++ { ++ /* Uggh, the address 0 was allocated... This is too annoying, ++ so reallocate another one. */ ++ address = max; ++ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); ++ grub_efi_free_pages (0, pages); ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ } ++ ++ return (void *) ((grub_addr_t) address); ++} ++ + /* Allocate pages. Return the pointer to the first of allocated pages. */ + void * + grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index ef3e9f9444c..a312c668685 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -41,6 +42,7 @@ static int loaded; + + static void *kernel_addr; + static grub_uint64_t kernel_size; ++static grub_uint32_t handover_offset; + + static char *linux_args; + static grub_uint32_t cmdline_size; +@@ -67,7 +69,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) + static grub_err_t + finalize_params_linux (void) + { +- int node, retval; ++ grub_efi_loaded_image_t *loaded_image = NULL; ++ int node, retval, len; + + void *fdt; + +@@ -102,79 +105,70 @@ finalize_params_linux (void) + if (grub_fdt_install() != GRUB_ERR_NONE) + goto failure; + +- return GRUB_ERR_NONE; +- +-failure: +- grub_fdt_unload(); +- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); +-} +- +-grub_err_t +-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) +-{ +- grub_efi_memory_mapped_device_path_t *mempath; +- grub_efi_handle_t image_handle; +- grub_efi_boot_services_t *b; +- grub_efi_status_t status; +- grub_efi_loaded_image_t *loaded_image; +- int len; +- +- mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); +- if (!mempath) +- return grub_errno; +- +- mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; +- mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; +- mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); +- mempath[0].memory_type = GRUB_EFI_LOADER_DATA; +- mempath[0].start_address = addr; +- mempath[0].end_address = addr + size; +- +- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; +- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; +- mempath[1].header.length = sizeof (grub_efi_device_path_t); +- +- b = grub_efi_system_table->boot_services; +- status = b->load_image (0, grub_efi_image_handle, +- (grub_efi_device_path_t *) mempath, +- (void *) addr, size, &image_handle); +- if (status != GRUB_EFI_SUCCESS) +- return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); +- +- grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", ++ fdt); + + /* Convert command line to UCS-2 */ +- loaded_image = grub_efi_get_loaded_image (image_handle); ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (!loaded_image) ++ goto failure; ++ + loaded_image->load_options_size = len = +- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); ++ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); + loaded_image->load_options = + grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + if (!loaded_image->load_options) +- return grub_errno; ++ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); + + loaded_image->load_options_size = + 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, +- (grub_uint8_t *) args, len, NULL); ++ (grub_uint8_t *) linux_args, len, NULL); + +- grub_dprintf ("linux", "starting image %p\n", image_handle); +- status = b->start_image (image_handle, 0, NULL); ++ return GRUB_ERR_NONE; + +- /* When successful, not reached */ +- b->unload_image (image_handle); +- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, +- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++failure: ++ grub_fdt_unload(); ++ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); ++} + +- return grub_errno; ++static void ++free_params (void) ++{ ++ grub_efi_loaded_image_t *loaded_image = NULL; ++ ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (loaded_image) ++ { ++ if (loaded_image->load_options) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options, ++ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++ loaded_image->load_options = NULL; ++ loaded_image->load_options_size = 0; ++ } ++} ++ ++grub_err_t ++grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) ++{ ++ grub_err_t retval; ++ ++ retval = finalize_params_linux (); ++ if (retval != GRUB_ERR_NONE) ++ return grub_errno; ++ ++ grub_dprintf ("linux", "linux command line: '%s'\n", args); ++ ++ retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); ++ ++ /* Never reached... */ ++ free_params(); ++ return retval; + } + + static grub_err_t + grub_linux_boot (void) + { +- if (finalize_params_linux () != GRUB_ERR_NONE) +- return grub_errno; +- +- return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, +- kernel_size, linux_args)); ++ return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args)); + } + + static grub_err_t +@@ -288,6 +282,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + { + grub_file_t file = 0; + struct linux_arch_kernel_header lh; ++ struct grub_armxx_linux_pe_header *pe; + grub_err_t err; + + grub_dl_ref (my_mod); +@@ -333,6 +328,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); + ++ if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size)) ++ { ++ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); ++ goto fail; ++ } ++ ++ pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); ++ handover_offset = pe->opt.entry_addr; ++ + cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); + linux_args = grub_malloc (cmdline_size); + if (!linux_args) +diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c +index 22cc25eccd9..d9b7a9ba400 100644 +--- a/grub-core/loader/arm64/xen_boot.c ++++ b/grub-core/loader/arm64/xen_boot.c +@@ -266,7 +266,6 @@ xen_boot (void) + return err; + + return grub_arch_efi_linux_boot_image (xen_hypervisor->start, +- xen_hypervisor->size, + xen_hypervisor->cmdline); + } + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +new file mode 100644 +index 00000000000..c24202a5dd1 +--- /dev/null ++++ b/grub-core/loader/efi/linux.c +@@ -0,0 +1,70 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2014 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define SHIM_LOCK_GUID \ ++ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} } ++ ++struct grub_efi_shim_lock ++{ ++ grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size); ++}; ++typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; ++ ++grub_efi_boolean_t ++grub_linuxefi_secure_validate (void *data, grub_uint32_t size) ++{ ++ grub_efi_guid_t guid = SHIM_LOCK_GUID; ++ grub_efi_shim_lock_t *shim_lock; ++ ++ shim_lock = grub_efi_locate_protocol(&guid, NULL); ++ ++ if (!shim_lock) ++ return 1; ++ ++ if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) ++ return 1; ++ ++ return 0; ++} ++ ++#pragma GCC diagnostic push ++#pragma GCC diagnostic ignored "-Wcast-align" ++ ++typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); ++ ++grub_err_t ++grub_efi_linux_boot (void *kernel_addr, grub_off_t offset, ++ void *kernel_params) ++{ ++ handover_func hf; ++ ++ hf = (handover_func)((char *)kernel_addr + offset); ++ hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); ++ ++ return GRUB_ERR_BUG; ++} ++ ++#pragma GCC diagnostic pop +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +new file mode 100644 +index 00000000000..bb2616a8092 +--- /dev/null ++++ b/grub-core/loader/i386/efi/linux.c +@@ -0,0 +1,335 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2012 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_dl_t my_mod; ++static int loaded; ++static void *kernel_mem; ++static grub_uint64_t kernel_size; ++static grub_uint8_t *initrd_mem; ++static grub_uint32_t handover_offset; ++struct linux_kernel_params *params; ++static char *linux_cmdline; ++ ++#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) ++ ++static grub_err_t ++grub_linuxefi_boot (void) ++{ ++ int offset = 0; ++ ++#ifdef __x86_64__ ++ offset = 512; ++#endif ++ asm volatile ("cli"); ++ ++ return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, ++ params); ++} ++ ++static grub_err_t ++grub_linuxefi_unload (void) ++{ ++ grub_dl_unref (my_mod); ++ loaded = 0; ++ if (initrd_mem) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, ++ BYTES_TO_PAGES(params->ramdisk_size)); ++ if (linux_cmdline) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) ++ linux_cmdline, ++ BYTES_TO_PAGES(params->cmdline_size + 1)); ++ if (kernel_mem) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, ++ BYTES_TO_PAGES(kernel_size)); ++ if (params) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, ++ BYTES_TO_PAGES(16384)); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char *argv[]) ++{ ++ grub_file_t *files = 0; ++ int i, nfiles = 0; ++ grub_size_t size = 0; ++ grub_uint8_t *ptr; ++ ++ if (argc == 0) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); ++ goto fail; ++ } ++ ++ if (!loaded) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first")); ++ goto fail; ++ } ++ ++ files = grub_zalloc (argc * sizeof (files[0])); ++ if (!files) ++ goto fail; ++ ++ for (i = 0; i < argc; i++) ++ { ++ files[i] = grub_file_open (argv[i], GRUB_FILE_TYPE_LINUX_INITRD | GRUB_FILE_TYPE_NO_DECOMPRESS); ++ if (! files[i]) ++ goto fail; ++ nfiles++; ++ size += ALIGN_UP (grub_file_size (files[i]), 4); ++ } ++ ++ initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size)); ++ if (!initrd_mem) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd")); ++ goto fail; ++ } ++ ++ params->ramdisk_size = size; ++ params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; ++ ++ ptr = initrd_mem; ++ ++ for (i = 0; i < nfiles; i++) ++ { ++ grub_ssize_t cursize = grub_file_size (files[i]); ++ if (grub_file_read (files[i], ptr, cursize) != cursize) ++ { ++ if (!grub_errno) ++ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), ++ argv[i]); ++ goto fail; ++ } ++ ptr += cursize; ++ grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); ++ ptr += ALIGN_UP_OVERHEAD (cursize, 4); ++ } ++ ++ params->ramdisk_size = size; ++ ++ fail: ++ for (i = 0; i < nfiles; i++) ++ grub_file_close (files[i]); ++ grub_free (files); ++ ++ if (initrd_mem && grub_errno) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, ++ BYTES_TO_PAGES(size)); ++ ++ return grub_errno; ++} ++ ++static grub_err_t ++grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char *argv[]) ++{ ++ grub_file_t file = 0; ++ struct linux_i386_kernel_header lh; ++ grub_ssize_t len, start, filelen; ++ void *kernel = NULL; ++ ++ grub_dl_ref (my_mod); ++ ++ if (argc == 0) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); ++ goto fail; ++ } ++ ++ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); ++ if (! file) ++ goto fail; ++ ++ filelen = grub_file_size (file); ++ ++ kernel = grub_malloc(filelen); ++ ++ if (!kernel) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer")); ++ goto fail; ++ } ++ ++ if (grub_file_read (file, kernel, filelen) != filelen) ++ { ++ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]); ++ goto fail; ++ } ++ ++ if (! grub_linuxefi_secure_validate (kernel, filelen)) ++ { ++ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), ++ argv[0]); ++ goto fail; ++ } ++ ++ params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384)); ++ ++ if (! params) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); ++ goto fail; ++ } ++ ++ grub_memset (params, 0, 16384); ++ ++ grub_memcpy (&lh, kernel, sizeof (lh)); ++ ++ if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("invalid magic number")); ++ goto fail; ++ } ++ ++ if (lh.setup_sects > GRUB_LINUX_MAX_SETUP_SECTS) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("too many setup sectors")); ++ goto fail; ++ } ++ ++ if (lh.version < grub_cpu_to_le16 (0x020b)) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("kernel too old")); ++ goto fail; ++ } ++ ++ if (!lh.handover_offset) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support EFI handover")); ++ goto fail; ++ } ++ ++ grub_dprintf ("linux", "setting up cmdline\n"); ++ linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff, ++ BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ ++ if (!linux_cmdline) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline")); ++ goto fail; ++ } ++ ++ grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); ++ grub_create_loader_cmdline (argc, argv, ++ linux_cmdline + sizeof (LINUX_IMAGE) - 1, ++ lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), ++ GRUB_VERIFY_KERNEL_CMDLINE); ++ ++ lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; ++ ++ handover_offset = lh.handover_offset; ++ ++ start = (lh.setup_sects + 1) * 512; ++ len = grub_file_size(file) - start; ++ ++ kernel_mem = grub_efi_allocate_pages_max(lh.pref_address, ++ BYTES_TO_PAGES(lh.init_size)); ++ ++ if (!kernel_mem) ++ kernel_mem = grub_efi_allocate_pages_max(0x3fffffff, ++ BYTES_TO_PAGES(lh.init_size)); ++ ++ if (!kernel_mem) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel")); ++ goto fail; ++ } ++ ++ grub_memcpy (kernel_mem, (char *)kernel + start, len); ++ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); ++ loaded=1; ++ ++ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; ++ grub_memcpy (params, &lh, 2 * 512); ++ ++ params->type_of_loader = 0x21; ++ ++ fail: ++ ++ if (file) ++ grub_file_close (file); ++ ++ if (kernel) ++ grub_free (kernel); ++ ++ if (grub_errno != GRUB_ERR_NONE) ++ { ++ grub_dl_unref (my_mod); ++ loaded = 0; ++ } ++ ++ if (linux_cmdline && !loaded) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) ++ linux_cmdline, ++ BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ ++ if (kernel_mem && !loaded) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, ++ BYTES_TO_PAGES(kernel_size)); ++ ++ if (params && !loaded) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, ++ BYTES_TO_PAGES(16384)); ++ ++ return grub_errno; ++} ++ ++static grub_command_t cmd_linux, cmd_initrd; ++static grub_command_t cmd_linuxefi, cmd_initrdefi; ++ ++GRUB_MOD_INIT(linux) ++{ ++ cmd_linux = ++ grub_register_command ("linux", grub_cmd_linux, ++ 0, N_("Load Linux.")); ++ cmd_linuxefi = ++ grub_register_command ("linuxefi", grub_cmd_linux, ++ 0, N_("Load Linux.")); ++ cmd_initrd = ++ grub_register_command ("initrd", grub_cmd_initrd, ++ 0, N_("Load initrd.")); ++ cmd_initrdefi = ++ grub_register_command ("initrdefi", grub_cmd_initrd, ++ 0, N_("Load initrd.")); ++ my_mod = mod; ++} ++ ++GRUB_MOD_FINI(linux) ++{ ++ grub_unregister_command (cmd_linux); ++ grub_unregister_command (cmd_linuxefi); ++ grub_unregister_command (cmd_initrd); ++ grub_unregister_command (cmd_initrdefi); ++} +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 47ea2945e4f..eea25ea39ca 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -470,14 +470,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + return grub_errno; + } + +-static grub_command_t cmd_linux, cmd_initrd; ++static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16; + + GRUB_MOD_INIT(linux16) + { + cmd_linux = ++ grub_register_command ("linux", grub_cmd_linux, ++ 0, N_("Load Linux.")); ++ cmd_linux16 = + grub_register_command ("linux16", grub_cmd_linux, + 0, N_("Load Linux.")); + cmd_initrd = ++ grub_register_command ("initrd", grub_cmd_initrd, ++ 0, N_("Load initrd.")); ++ cmd_initrd16 = + grub_register_command ("initrd16", grub_cmd_initrd, + 0, N_("Load initrd.")); + my_mod = mod; +@@ -486,5 +492,7 @@ GRUB_MOD_INIT(linux16) + GRUB_MOD_FINI(linux16) + { + grub_unregister_command (cmd_linux); ++ grub_unregister_command (cmd_linux16); + grub_unregister_command (cmd_initrd); ++ grub_unregister_command (cmd_initrd16); + } +diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h +index 2e98a668969..775297db869 100644 +--- a/include/grub/arm/linux.h ++++ b/include/grub/arm/linux.h +@@ -20,6 +20,7 @@ + #ifndef GRUB_ARM_LINUX_HEADER + #define GRUB_ARM_LINUX_HEADER 1 + ++#include + #include "system.h" + + #define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818 +@@ -34,9 +35,17 @@ struct linux_arm_kernel_header { + grub_uint32_t hdr_offset; + }; + ++struct grub_arm_linux_pe_header ++{ ++ grub_uint32_t magic; ++ struct grub_pe32_coff_header coff; ++ struct grub_pe32_optional_header opt; ++}; ++ + #if defined(__arm__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE + # define linux_arch_kernel_header linux_arm_kernel_header ++# define grub_armxx_linux_pe_header grub_arm_linux_pe_header + #endif + + #if defined GRUB_MACHINE_UBOOT +diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h +index 4269adc6dae..a3be9dd7003 100644 +--- a/include/grub/arm64/linux.h ++++ b/include/grub/arm64/linux.h +@@ -19,6 +19,8 @@ + #ifndef GRUB_ARM64_LINUX_HEADER + #define GRUB_ARM64_LINUX_HEADER 1 + ++#include ++ + #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ + + /* From linux/Documentation/arm64/booting.txt */ +@@ -36,9 +38,17 @@ struct linux_arm64_kernel_header + grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ + }; + ++struct grub_arm64_linux_pe_header ++{ ++ grub_uint32_t magic; ++ struct grub_pe32_coff_header coff; ++ struct grub_pe64_optional_header opt; ++}; ++ + #if defined(__aarch64__) + # define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE + # define linux_arch_kernel_header linux_arm64_kernel_header ++# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header + #endif + + #endif /* ! GRUB_ARM64_LINUX_HEADER */ +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index e90e00dc431..6840bfee9b7 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); + void * + EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages); ++void * ++EXPORT_FUNC(grub_efi_allocate_pages_max) (grub_efi_physical_address_t max, ++ grub_efi_uintn_t pages); + void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); + grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); +@@ -82,6 +85,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, + const grub_efi_guid_t *guid, + void *data, + grub_size_t datasize); ++grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void); + int + EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, + const grub_efi_device_path_t *dp2); +@@ -95,8 +99,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); + grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); + #include + grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); +-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, +- char *args); ++grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); + #endif + + grub_addr_t grub_efi_modules_addr (void); +diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h +new file mode 100644 +index 00000000000..d9ede36773b +--- /dev/null ++++ b/include/grub/efi/linux.h +@@ -0,0 +1,31 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2014 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++#ifndef GRUB_EFI_LINUX_HEADER ++#define GRUB_EFI_LINUX_HEADER 1 ++ ++#include ++#include ++#include ++ ++grub_efi_boolean_t ++EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size); ++grub_err_t ++EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, ++ void *kernel_param); ++ ++#endif /* ! GRUB_EFI_LINUX_HEADER */ diff --git a/0002-Rework-linux-command.patch b/0002-Rework-linux-command.patch new file mode 100644 index 0000000..bd136d6 --- /dev/null +++ b/0002-Rework-linux-command.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Fri, 5 Jul 2019 20:54:51 +0200 +Subject: [PATCH] Rework linux command + +We want a single buffer that contains the entire kernel image in order to +perform a TPM measurement. Allocate one and copy the entire kernel into it +before pulling out the individual blocks later on. +--- + grub-core/loader/i386/linux.c | 36 +++++++++++++++++++++++------------- + 1 file changed, 23 insertions(+), 13 deletions(-) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index d0501e22957..b255c950526 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -641,13 +641,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + { + grub_file_t file = 0; + struct linux_i386_kernel_header lh; ++ grub_uint8_t *linux_params_ptr; + grub_uint8_t setup_sects; +- grub_size_t real_size, prot_size, prot_file_size; ++ grub_size_t real_size, prot_size, prot_file_size, kernel_offset; + grub_ssize_t len; + int i; + grub_size_t align, min_align; + int relocatable; + grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR; ++ grub_uint8_t *kernel = NULL; + + grub_dl_ref (my_mod); + +@@ -661,7 +663,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (! file) + goto fail; + +- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) ++ len = grub_file_size (file); ++ kernel = grub_malloc (len); ++ if (!kernel) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer")); ++ goto fail; ++ } ++ ++ if (grub_file_read (file, kernel, len) != len) + { + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +@@ -669,6 +679,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_memcpy (&lh, kernel, sizeof (lh)); ++ kernel_offset = sizeof (lh); ++ + if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) + { + grub_error (GRUB_ERR_BAD_OS, "invalid magic number"); +@@ -760,6 +773,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + preferred_address)) + goto fail; + ++ + grub_memset (&linux_params, 0, sizeof (linux_params)); + grub_memcpy (&linux_params.setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1); + +@@ -782,13 +796,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + /* We've already read lh so there is no need to read it second time. */ + len -= sizeof(lh); + +- if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len) +- { +- if (!grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); +- goto fail; +- } ++ linux_params_ptr = (void *)&linux_params; ++ grub_memcpy (linux_params_ptr + sizeof (lh), kernel + kernel_offset, len); ++ kernel_offset += len; + + linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; + +@@ -847,7 +857,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + /* The other parameters are filled when booting. */ + +- grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE); ++ kernel_offset = real_size + GRUB_DISK_SECTOR_SIZE; + + grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n", + (unsigned) real_size, (unsigned) prot_size); +@@ -1001,9 +1011,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + len = prot_file_size; +- if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); ++ grub_memcpy (prot_mode_mem, kernel + kernel_offset, len); + + if (grub_errno == GRUB_ERR_NONE) + { +@@ -1014,6 +1022,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + fail: + ++ grub_free (kernel); ++ + if (file) + grub_file_close (file); + diff --git a/0003-Rework-linux16-command.patch b/0003-Rework-linux16-command.patch new file mode 100644 index 0000000..e73423b --- /dev/null +++ b/0003-Rework-linux16-command.patch @@ -0,0 +1,97 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Fri, 5 Jul 2019 21:12:00 +0200 +Subject: [PATCH] Rework linux16 command + +We want a single buffer that contains the entire kernel image in order to +perform a TPM measurement. Allocate one and copy the entire kernel int it +before pulling out the individual blocks later on. +--- + grub-core/loader/i386/pc/linux.c | 33 +++++++++++++++++++++------------ + 1 file changed, 21 insertions(+), 12 deletions(-) + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index eea25ea39ca..73fb91e0570 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -123,13 +123,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_file_t file = 0; + struct linux_i386_kernel_header lh; + grub_uint8_t setup_sects; +- grub_size_t real_size; ++ grub_size_t real_size, kernel_offset = 0; + grub_ssize_t len; + int i; + char *grub_linux_prot_chunk; + int grub_linux_is_bzimage; + grub_addr_t grub_linux_prot_target; + grub_err_t err; ++ grub_uint8_t *kernel = NULL; + + grub_dl_ref (my_mod); + +@@ -143,7 +144,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (! file) + goto fail; + +- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) ++ len = grub_file_size (file); ++ kernel = grub_malloc (len); ++ if (!kernel) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer")); ++ goto fail; ++ } ++ ++ if (grub_file_read (file, kernel, len) != len) + { + if (!grub_errno) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +@@ -151,6 +160,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_memcpy (&lh, kernel, sizeof (lh)); ++ kernel_offset = sizeof (lh); ++ + if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) + { + grub_error (GRUB_ERR_BAD_OS, "invalid magic number"); +@@ -314,13 +326,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_memmove (grub_linux_real_chunk, &lh, sizeof (lh)); + + len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh); +- if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len) +- { +- if (!grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); +- goto fail; +- } ++ grub_memcpy (grub_linux_real_chunk + sizeof (lh), kernel + kernel_offset, ++ len); ++ kernel_offset += len; + + if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE) + || grub_le_to_cpu16 (lh.version) < 0x0200) +@@ -358,9 +366,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + len = grub_linux16_prot_size; +- if (grub_file_read (file, grub_linux_prot_chunk, len) != len && !grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); ++ grub_memcpy (grub_linux_prot_chunk, kernel + kernel_offset, len); ++ kernel_offset += len; + + if (grub_errno == GRUB_ERR_NONE) + { +@@ -370,6 +377,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + fail: + ++ grub_free (kernel); ++ + if (file) + grub_file_close (file); + diff --git a/0004-Add-secureboot-support-on-efi-chainloader.patch b/0004-Add-secureboot-support-on-efi-chainloader.patch new file mode 100644 index 0000000..092032b --- /dev/null +++ b/0004-Add-secureboot-support-on-efi-chainloader.patch @@ -0,0 +1,1390 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Raymund Will +Date: Mon, 8 Jul 2019 11:55:18 +0200 +Subject: [PATCH] Add secureboot support on efi chainloader + +Expand the chainloader to be able to verify the image by means of shim +lock protocol. The PE/COFF image is loaded and relocated by the +chainloader instead of calling LoadImage and StartImage UEFI boot +Service as they require positive verification result from keys enrolled +in KEK or DB. The shim will use MOK in addition to firmware enrolled +keys to verify the image. + +The chainloader module could be used to load other UEFI bootloaders, +such as xen.efi, and could be signed by any of MOK, KEK or DB. + +Based on https://build.opensuse.org/package/view_file/openSUSE:Factory/grub2/grub2-secureboot-chainloader.patch + +Signed-off-by: Peter Jones + +Also: + +commit cd7a8984d4fda905877b5bfe466339100156b3bc +Author: Raymund Will +Date: Fri Apr 10 01:45:02 2015 -0400 + +Use device part of chainloader target, if present. + +Otherwise chainloading is restricted to '$root', which might not even +be readable by EFI! + +v1. use grub_file_get_device_name() to get device name + +Signed-off-by: Michael Chang +Signed-off-by: Peter Jones + +Also: + +commit 0872a2310a0eeac4ecfe9e1b49dd2d72ab373039 +Author: Peter Jones +Date: Fri Jun 10 14:06:15 2016 -0400 + +Rework even more of efi chainload so non-sb cases work right. + +This ensures that if shim protocol is not loaded, or is loaded but shim +is disabled, we will fall back to a correct load method for the efi +chain loader. + +Here's what I tested with this version: + +results expected actual +------------------------------------------------------------ +sb + enabled + shim + fedora success success +sb + enabled + shim + win success success +sb + enabled + grub + fedora fail fail +sb + enabled + grub + win fail fail + +sb + mokdisabled + shim + fedora success success +sb + mokdisabled + shim + win success success +sb + mokdisabled + grub + fedora fail fail +sb + mokdisabled + grub + win fail fail + +sb disabled + shim + fedora success success* +sb disabled + shim + win success success* +sb disabled + grub + fedora success success +sb disabled + grub + win success success + +nosb + shim + fedora success success* +nosb + shim + win success success* +nosb + grub + fedora success success +nosb + grub + win success success + +* for some reason shim protocol is being installed in these cases, and I + can't see why, but I think it may be this firmware build returning an + erroneous value. But this effectively falls back to the mokdisabled + behavior, which works correctly, and the presence of the "grub" (i.e. + no shim) tests effectively tests the desired behavior here. + +Resolves: rhbz#1344512 + +Signed-off-by: Peter Jones + +Also: + +commit ff7b1cb7f69487870211aeb69ff4f54470fbcb58 +Author: Laszlo Ersek +Date: Mon Nov 21 15:34:00 2016 +0100 + +efi/chainloader: fix wrong sanity check in relocate_coff() + +In relocate_coff(), the relocation entries are parsed from the original +image (not the section-wise copied image). The original image is +pointed-to by the "orig" pointer. The current check + + (void *)reloc_end < data + +compares the addresses of independent memory allocations. "data" is a typo +here, it should be "orig". + +Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1347291 +Signed-off-by: Laszlo Ersek +Tested-by: Bogdan Costescu +Tested-by: Juan Orti + +Also: + +commit ab4ba9997ad4832449e54d930fa2aac6a160d0e9 +Author: Laszlo Ersek +Date: Wed Nov 23 06:27:09 2016 +0100 + +efi/chainloader: truncate overlong relocation section + +The UEFI Windows 7 boot loader ("EFI/Microsoft/Boot/bootmgfw.efi", SHA1 +31b410e029bba87d2068c65a80b88882f9f8ea25) has inconsistent headers. + +Compare: + +> The Data Directory +> ... +> Entry 5 00000000000d9000 00000574 Base Relocation Directory [.reloc] + +Versus: + +> Sections: +> Idx Name Size VMA LMA File off ... +> ... +> 10 .reloc 00000e22 00000000100d9000 00000000100d9000 000a1800 ... + +That is, the size reported by the RelocDir entry (0x574) is smaller than +the virtual size of the .reloc section (0xe22). + +Quoting the grub2 debug log for the same: + +> chainloader.c:595: reloc_dir: 0xd9000 reloc_size: 0x00000574 +> chainloader.c:603: reloc_base: 0x7d208000 reloc_base_end: 0x7d208573 +> ... +> chainloader.c:620: Section 10 ".reloc" at 0x7d208000..0x7d208e21 +> chainloader.c:661: section is not reloc section? +> chainloader.c:663: rds: 0x00001000, vs: 00000e22 +> chainloader.c:664: base: 0x7d208000 end: 0x7d208e21 +> chainloader.c:666: reloc_base: 0x7d208000 reloc_base_end: 0x7d208573 +> chainloader.c:671: Section characteristics are 42000040 +> chainloader.c:673: Section virtual size: 00000e22 +> chainloader.c:675: Section raw_data size: 00001000 +> chainloader.c:678: Discarding section + +After hexdumping "bootmgfw.efi" and manually walking its relocation blocks +(yes, really), I determined that the (smaller) RelocDir value is correct. +The remaining area that extends up to the .reloc section size (== 0xe22 - +0x574 == 0x8ae bytes) exists as zero padding in the file. + +This zero padding shouldn't be passed to relocate_coff() for parsing. In +order to cope with it, split the handling of .reloc sections into the +following branches: + +- original case (equal size): original behavior (--> relocation + attempted), + +- overlong .reloc section (longer than reported by RelocDir): truncate the + section to the RelocDir size for the purposes of relocate_coff(), and + attempt relocation, + +- .reloc section is too short, or other checks fail: original behavior + (--> relocation not attempted). + +Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1347291 +Signed-off-by: Laszlo Ersek +--- + grub-core/kern/efi/efi.c | 14 +- + grub-core/loader/arm64/linux.c | 4 +- + grub-core/loader/efi/chainloader.c | 817 +++++++++++++++++++++++++++++++++---- + grub-core/loader/efi/linux.c | 25 +- + grub-core/loader/i386/efi/linux.c | 17 +- + include/grub/efi/linux.h | 2 +- + include/grub/efi/pe32.h | 52 ++- + 7 files changed, 840 insertions(+), 91 deletions(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index a0faa40ecf0..3487b0623a4 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -283,14 +283,20 @@ grub_efi_secure_boot (void) + grub_efi_boolean_t ret = 0; + + secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); +- + if (datasize != 1 || !secure_boot) +- goto out; ++ { ++ grub_dprintf ("secureboot", "No SecureBoot variable\n"); ++ goto out; ++ } ++ grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); + + setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); +- + if (datasize != 1 || !setup_mode) +- goto out; ++ { ++ grub_dprintf ("secureboot", "No SetupMode variable\n"); ++ goto out; ++ } ++ grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); + + if (*secure_boot && !*setup_mode) + ret = 1; +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index a312c668685..04994d5c67d 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -284,6 +284,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + struct linux_arch_kernel_header lh; + struct grub_armxx_linux_pe_header *pe; + grub_err_t err; ++ int rc; + + grub_dl_ref (my_mod); + +@@ -328,7 +329,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); + +- if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size)) ++ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); ++ if (rc < 0) + { + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); + goto fail; +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index cd92ea3f24b..ef87b06cf70 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -32,6 +32,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -46,9 +48,14 @@ static grub_dl_t my_mod; + + static grub_efi_physical_address_t address; + static grub_efi_uintn_t pages; ++static grub_ssize_t fsize; + static grub_efi_device_path_t *file_path; + static grub_efi_handle_t image_handle; + static grub_efi_char16_t *cmdline; ++static grub_ssize_t cmdline_len; ++static grub_efi_handle_t dev_handle; ++ ++static grub_efi_status_t (*entry_point) (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); + + static grub_err_t + grub_chainloader_unload (void) +@@ -63,6 +70,7 @@ grub_chainloader_unload (void) + grub_free (cmdline); + cmdline = 0; + file_path = 0; ++ dev_handle = 0; + + grub_dl_unref (my_mod); + return GRUB_ERR_NONE; +@@ -179,7 +187,6 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + /* Fill the file path for the directory. */ + d = (grub_efi_device_path_t *) ((char *) file_path + + ((char *) d - (char *) dp)); +- grub_efi_print_device_path (d); + copy_file_path ((grub_efi_file_path_device_path_t *) d, + dir_start, dir_end - dir_start); + +@@ -197,20 +204,690 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + return file_path; + } + ++#define SHIM_LOCK_GUID \ ++ { 0x605dab50, 0xe046, 0x4300, { 0xab,0xb6,0x3d,0xd8,0x10,0xdd,0x8b,0x23 } } ++ ++typedef union ++{ ++ struct grub_pe32_header_32 pe32; ++ struct grub_pe32_header_64 pe32plus; ++} grub_pe_header_t; ++ ++struct pe_coff_loader_image_context ++{ ++ grub_efi_uint64_t image_address; ++ grub_efi_uint64_t image_size; ++ grub_efi_uint64_t entry_point; ++ grub_efi_uintn_t size_of_headers; ++ grub_efi_uint16_t image_type; ++ grub_efi_uint16_t number_of_sections; ++ grub_efi_uint32_t section_alignment; ++ struct grub_pe32_section_table *first_section; ++ struct grub_pe32_data_directory *reloc_dir; ++ struct grub_pe32_data_directory *sec_dir; ++ grub_efi_uint64_t number_of_rva_and_sizes; ++ grub_pe_header_t *pe_hdr; ++}; ++ ++typedef struct pe_coff_loader_image_context pe_coff_loader_image_context_t; ++ ++struct grub_efi_shim_lock ++{ ++ grub_efi_status_t (*verify)(void *buffer, ++ grub_efi_uint32_t size); ++ grub_efi_status_t (*hash)(void *data, ++ grub_efi_int32_t datasize, ++ pe_coff_loader_image_context_t *context, ++ grub_efi_uint8_t *sha256hash, ++ grub_efi_uint8_t *sha1hash); ++ grub_efi_status_t (*context)(void *data, ++ grub_efi_uint32_t size, ++ pe_coff_loader_image_context_t *context); ++}; ++ ++typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; ++ ++static grub_efi_boolean_t ++read_header (void *data, grub_efi_uint32_t size, ++ pe_coff_loader_image_context_t *context) ++{ ++ grub_efi_guid_t guid = SHIM_LOCK_GUID; ++ grub_efi_shim_lock_t *shim_lock; ++ grub_efi_status_t status; ++ ++ shim_lock = grub_efi_locate_protocol (&guid, NULL); ++ if (!shim_lock) ++ { ++ grub_dprintf ("chain", "no shim lock protocol"); ++ return 0; ++ } ++ ++ status = shim_lock->context (data, size, context); ++ ++ if (status == GRUB_EFI_SUCCESS) ++ { ++ grub_dprintf ("chain", "context success\n"); ++ return 1; ++ } ++ ++ switch (status) ++ { ++ case GRUB_EFI_UNSUPPORTED: ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "context error unsupported"); ++ break; ++ case GRUB_EFI_INVALID_PARAMETER: ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "context error invalid parameter"); ++ break; ++ default: ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "context error code"); ++ break; ++ } ++ ++ return -1; ++} ++ ++static void* ++image_address (void *image, grub_efi_uint64_t sz, grub_efi_uint64_t adr) ++{ ++ if (adr > sz) ++ return NULL; ++ ++ return ((grub_uint8_t*)image + adr); ++} ++ ++static int ++image_is_64_bit (grub_pe_header_t *pe_hdr) ++{ ++ /* .Magic is the same offset in all cases */ ++ if (pe_hdr->pe32plus.optional_header.magic == GRUB_PE32_PE64_MAGIC) ++ return 1; ++ return 0; ++} ++ ++static const grub_uint16_t machine_type __attribute__((__unused__)) = ++#if defined(__x86_64__) ++ GRUB_PE32_MACHINE_X86_64; ++#elif defined(__aarch64__) ++ GRUB_PE32_MACHINE_ARM64; ++#elif defined(__arm__) ++ GRUB_PE32_MACHINE_ARMTHUMB_MIXED; ++#elif defined(__i386__) || defined(__i486__) || defined(__i686__) ++ GRUB_PE32_MACHINE_I386; ++#elif defined(__ia64__) ++ GRUB_PE32_MACHINE_IA64; ++#else ++#error this architecture is not supported by grub2 ++#endif ++ ++static grub_efi_status_t ++relocate_coff (pe_coff_loader_image_context_t *context, ++ struct grub_pe32_section_table *section, ++ void *orig, void *data) ++{ ++ struct grub_pe32_data_directory *reloc_base, *reloc_base_end; ++ grub_efi_uint64_t adjust; ++ struct grub_pe32_fixup_block *reloc, *reloc_end; ++ char *fixup, *fixup_base, *fixup_data = NULL; ++ grub_efi_uint16_t *fixup_16; ++ grub_efi_uint32_t *fixup_32; ++ grub_efi_uint64_t *fixup_64; ++ grub_efi_uint64_t size = context->image_size; ++ void *image_end = (char *)orig + size; ++ int n = 0; ++ ++ if (image_is_64_bit (context->pe_hdr)) ++ context->pe_hdr->pe32plus.optional_header.image_base = ++ (grub_uint64_t)(unsigned long)data; ++ else ++ context->pe_hdr->pe32.optional_header.image_base = ++ (grub_uint32_t)(unsigned long)data; ++ ++ /* Alright, so here's how this works: ++ * ++ * context->reloc_dir gives us two things: ++ * - the VA the table of base relocation blocks are (maybe) to be ++ * mapped at (reloc_dir->rva) ++ * - the virtual size (reloc_dir->size) ++ * ++ * The .reloc section (section here) gives us some other things: ++ * - the name! kind of. (section->name) ++ * - the virtual size (section->virtual_size), which should be the same ++ * as RelocDir->Size ++ * - the virtual address (section->virtual_address) ++ * - the file section size (section->raw_data_size), which is ++ * a multiple of optional_header->file_alignment. Only useful for image ++ * validation, not really useful for iteration bounds. ++ * - the file address (section->raw_data_offset) ++ * - a bunch of stuff we don't use that's 0 in our binaries usually ++ * - Flags (section->characteristics) ++ * ++ * and then the thing that's actually at the file address is an array ++ * of struct grub_pe32_fixup_block structs with some values packed behind ++ * them. The block_size field of this structure includes the ++ * structure itself, and adding it to that structure's address will ++ * yield the next entry in the array. ++ */ ++ ++ reloc_base = image_address (orig, size, section->raw_data_offset); ++ reloc_base_end = image_address (orig, size, section->raw_data_offset ++ + section->virtual_size); ++ ++ grub_dprintf ("chain", "relocate_coff(): reloc_base %p reloc_base_end %p\n", ++ reloc_base, reloc_base_end); ++ ++ if (!reloc_base && !reloc_base_end) ++ return GRUB_EFI_SUCCESS; ++ ++ if (!reloc_base || !reloc_base_end) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "Reloc table overflows binary"); ++ return GRUB_EFI_UNSUPPORTED; ++ } ++ ++ adjust = (grub_uint64_t)(grub_efi_uintn_t)data - context->image_address; ++ if (adjust == 0) ++ return GRUB_EFI_SUCCESS; ++ ++ while (reloc_base < reloc_base_end) ++ { ++ grub_uint16_t *entry; ++ reloc = (struct grub_pe32_fixup_block *)((char*)reloc_base); ++ ++ if ((reloc_base->size == 0) || ++ (reloc_base->size > context->reloc_dir->size)) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "Reloc %d block size %d is invalid\n", n, ++ reloc_base->size); ++ return GRUB_EFI_UNSUPPORTED; ++ } ++ ++ entry = &reloc->entries[0]; ++ reloc_end = (struct grub_pe32_fixup_block *) ++ ((char *)reloc_base + reloc_base->size); ++ ++ if ((void *)reloc_end < orig || (void *)reloc_end > image_end) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "Reloc entry %d overflows binary", ++ n); ++ return GRUB_EFI_UNSUPPORTED; ++ } ++ ++ fixup_base = image_address(data, size, reloc_base->rva); ++ ++ if (!fixup_base) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "Reloc %d Invalid fixupbase", n); ++ return GRUB_EFI_UNSUPPORTED; ++ } ++ ++ while ((void *)entry < (void *)reloc_end) ++ { ++ fixup = fixup_base + (*entry & 0xFFF); ++ switch ((*entry) >> 12) ++ { ++ case GRUB_PE32_REL_BASED_ABSOLUTE: ++ break; ++ case GRUB_PE32_REL_BASED_HIGH: ++ fixup_16 = (grub_uint16_t *)fixup; ++ *fixup_16 = (grub_uint16_t) ++ (*fixup_16 + ((grub_uint16_t)((grub_uint32_t)adjust >> 16))); ++ if (fixup_data != NULL) ++ { ++ *(grub_uint16_t *) fixup_data = *fixup_16; ++ fixup_data = fixup_data + sizeof (grub_uint16_t); ++ } ++ break; ++ case GRUB_PE32_REL_BASED_LOW: ++ fixup_16 = (grub_uint16_t *)fixup; ++ *fixup_16 = (grub_uint16_t) (*fixup_16 + (grub_uint16_t)adjust); ++ if (fixup_data != NULL) ++ { ++ *(grub_uint16_t *) fixup_data = *fixup_16; ++ fixup_data = fixup_data + sizeof (grub_uint16_t); ++ } ++ break; ++ case GRUB_PE32_REL_BASED_HIGHLOW: ++ fixup_32 = (grub_uint32_t *)fixup; ++ *fixup_32 = *fixup_32 + (grub_uint32_t)adjust; ++ if (fixup_data != NULL) ++ { ++ fixup_data = (char *)ALIGN_UP ((grub_addr_t)fixup_data, sizeof (grub_uint32_t)); ++ *(grub_uint32_t *) fixup_data = *fixup_32; ++ fixup_data += sizeof (grub_uint32_t); ++ } ++ break; ++ case GRUB_PE32_REL_BASED_DIR64: ++ fixup_64 = (grub_uint64_t *)fixup; ++ *fixup_64 = *fixup_64 + (grub_uint64_t)adjust; ++ if (fixup_data != NULL) ++ { ++ fixup_data = (char *)ALIGN_UP ((grub_addr_t)fixup_data, sizeof (grub_uint64_t)); ++ *(grub_uint64_t *) fixup_data = *fixup_64; ++ fixup_data += sizeof (grub_uint64_t); ++ } ++ break; ++ default: ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "Reloc %d unknown relocation type %d", ++ n, (*entry) >> 12); ++ return GRUB_EFI_UNSUPPORTED; ++ } ++ entry += 1; ++ } ++ reloc_base = (struct grub_pe32_data_directory *)reloc_end; ++ n++; ++ } ++ ++ return GRUB_EFI_SUCCESS; ++} ++ ++static grub_efi_device_path_t * ++grub_efi_get_media_file_path (grub_efi_device_path_t *dp) ++{ ++ while (1) ++ { ++ grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); ++ grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); ++ ++ if (type == GRUB_EFI_END_DEVICE_PATH_TYPE) ++ break; ++ else if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE ++ && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE) ++ return dp; ++ ++ dp = GRUB_EFI_NEXT_DEVICE_PATH (dp); ++ } ++ ++ return NULL; ++} ++ ++static grub_efi_boolean_t ++handle_image (void *data, grub_efi_uint32_t datasize) ++{ ++ grub_efi_boot_services_t *b; ++ grub_efi_loaded_image_t *li, li_bak; ++ grub_efi_status_t efi_status; ++ char *buffer = NULL; ++ char *buffer_aligned = NULL; ++ grub_efi_uint32_t i; ++ struct grub_pe32_section_table *section; ++ char *base, *end; ++ pe_coff_loader_image_context_t context; ++ grub_uint32_t section_alignment; ++ grub_uint32_t buffer_size; ++ int found_entry_point = 0; ++ int rc; ++ ++ b = grub_efi_system_table->boot_services; ++ ++ rc = read_header (data, datasize, &context); ++ if (rc < 0) ++ { ++ grub_dprintf ("chain", "Failed to read header\n"); ++ goto error_exit; ++ } ++ else if (rc == 0) ++ { ++ grub_dprintf ("chain", "Secure Boot is not enabled\n"); ++ return 0; ++ } ++ else ++ { ++ grub_dprintf ("chain", "Header read without error\n"); ++ } ++ ++ /* ++ * The spec says, uselessly, of SectionAlignment: ++ * ===== ++ * The alignment (in bytes) of sections when they are loaded into ++ * memory. It must be greater than or equal to FileAlignment. The ++ * default is the page size for the architecture. ++ * ===== ++ * Which doesn't tell you whose responsibility it is to enforce the ++ * "default", or when. It implies that the value in the field must ++ * be > FileAlignment (also poorly defined), but it appears visual ++ * studio will happily write 512 for FileAlignment (its default) and ++ * 0 for SectionAlignment, intending to imply PAGE_SIZE. ++ * ++ * We only support one page size, so if it's zero, nerf it to 4096. ++ */ ++ section_alignment = context.section_alignment; ++ if (section_alignment == 0) ++ section_alignment = 4096; ++ ++ buffer_size = context.image_size + section_alignment; ++ grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n", ++ context.image_size, datasize); ++ ++ efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, ++ buffer_size, &buffer); ++ ++ if (efi_status != GRUB_EFI_SUCCESS) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto error_exit; ++ } ++ ++ buffer_aligned = (char *)ALIGN_UP ((grub_addr_t)buffer, section_alignment); ++ if (!buffer_aligned) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto error_exit; ++ } ++ ++ grub_memcpy (buffer_aligned, data, context.size_of_headers); ++ ++ entry_point = image_address (buffer_aligned, context.image_size, ++ context.entry_point); ++ ++ grub_dprintf ("chain", "entry_point: %p\n", entry_point); ++ if (!entry_point) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid entry point"); ++ goto error_exit; ++ } ++ ++ char *reloc_base, *reloc_base_end; ++ grub_dprintf ("chain", "reloc_dir: %p reloc_size: 0x%08x\n", ++ (void *)(unsigned long)context.reloc_dir->rva, ++ context.reloc_dir->size); ++ reloc_base = image_address (buffer_aligned, context.image_size, ++ context.reloc_dir->rva); ++ /* RelocBaseEnd here is the address of the last byte of the table */ ++ reloc_base_end = image_address (buffer_aligned, context.image_size, ++ context.reloc_dir->rva ++ + context.reloc_dir->size - 1); ++ grub_dprintf ("chain", "reloc_base: %p reloc_base_end: %p\n", ++ reloc_base, reloc_base_end); ++ ++ struct grub_pe32_section_table *reloc_section = NULL, fake_reloc_section; ++ ++ section = context.first_section; ++ for (i = 0; i < context.number_of_sections; i++, section++) ++ { ++ char name[9]; ++ ++ base = image_address (buffer_aligned, context.image_size, ++ section->virtual_address); ++ end = image_address (buffer_aligned, context.image_size, ++ section->virtual_address + section->virtual_size -1); ++ ++ grub_strncpy(name, section->name, 9); ++ name[8] = '\0'; ++ grub_dprintf ("chain", "Section %d \"%s\" at %p..%p\n", i, ++ name, base, end); ++ ++ if (end < base) ++ { ++ grub_dprintf ("chain", " base is %p but end is %p... bad.\n", ++ base, end); ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "Image has invalid negative size"); ++ goto error_exit; ++ } ++ ++ if (section->virtual_address <= context.entry_point && ++ (section->virtual_address + section->raw_data_size - 1) ++ > context.entry_point) ++ { ++ found_entry_point++; ++ grub_dprintf ("chain", " section contains entry point\n"); ++ } ++ ++ /* We do want to process .reloc, but it's often marked ++ * discardable, so we don't want to memcpy it. */ ++ if (grub_memcmp (section->name, ".reloc\0\0", 8) == 0) ++ { ++ if (reloc_section) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "Image has multiple relocation sections"); ++ goto error_exit; ++ } ++ ++ /* If it has nonzero sizes, and our bounds check ++ * made sense, and the VA and size match RelocDir's ++ * versions, then we believe in this section table. */ ++ if (section->raw_data_size && section->virtual_size && ++ base && end && reloc_base == base) ++ { ++ if (reloc_base_end == end) ++ { ++ grub_dprintf ("chain", " section is relocation section\n"); ++ reloc_section = section; ++ } ++ else if (reloc_base_end && reloc_base_end < end) ++ { ++ /* Bogus virtual size in the reloc section -- RelocDir ++ * reported a smaller Base Relocation Directory. Decrease ++ * the section's virtual size so that it equal RelocDir's ++ * idea, but only for the purposes of relocate_coff(). */ ++ grub_dprintf ("chain", ++ " section is (overlong) relocation section\n"); ++ grub_memcpy (&fake_reloc_section, section, sizeof *section); ++ fake_reloc_section.virtual_size -= (end - reloc_base_end); ++ reloc_section = &fake_reloc_section; ++ } ++ } ++ ++ if (!reloc_section) ++ { ++ grub_dprintf ("chain", " section is not reloc section?\n"); ++ grub_dprintf ("chain", " rds: 0x%08x, vs: %08x\n", ++ section->raw_data_size, section->virtual_size); ++ grub_dprintf ("chain", " base: %p end: %p\n", base, end); ++ grub_dprintf ("chain", " reloc_base: %p reloc_base_end: %p\n", ++ reloc_base, reloc_base_end); ++ } ++ } ++ ++ grub_dprintf ("chain", " Section characteristics are %08x\n", ++ section->characteristics); ++ grub_dprintf ("chain", " Section virtual size: %08x\n", ++ section->virtual_size); ++ grub_dprintf ("chain", " Section raw_data size: %08x\n", ++ section->raw_data_size); ++ if (section->characteristics & GRUB_PE32_SCN_MEM_DISCARDABLE) ++ { ++ grub_dprintf ("chain", " Discarding section\n"); ++ continue; ++ } ++ ++ if (!base || !end) ++ { ++ grub_dprintf ("chain", " section is invalid\n"); ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid section size"); ++ goto error_exit; ++ } ++ ++ if (section->characteristics & GRUB_PE32_SCN_CNT_UNINITIALIZED_DATA) ++ { ++ if (section->raw_data_size != 0) ++ grub_dprintf ("chain", " UNINITIALIZED_DATA section has data?\n"); ++ } ++ else if (section->virtual_address < context.size_of_headers || ++ section->raw_data_offset < context.size_of_headers) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "Section %d is inside image headers", i); ++ goto error_exit; ++ } ++ ++ if (section->raw_data_size > 0) ++ { ++ grub_dprintf ("chain", " copying 0x%08x bytes to %p\n", ++ section->raw_data_size, base); ++ grub_memcpy (base, ++ (grub_efi_uint8_t*)data + section->raw_data_offset, ++ section->raw_data_size); ++ } ++ ++ if (section->raw_data_size < section->virtual_size) ++ { ++ grub_dprintf ("chain", " padding with 0x%08x bytes at %p\n", ++ section->virtual_size - section->raw_data_size, ++ base + section->raw_data_size); ++ grub_memset (base + section->raw_data_size, 0, ++ section->virtual_size - section->raw_data_size); ++ } ++ ++ grub_dprintf ("chain", " finished section %s\n", name); ++ } ++ ++ /* 5 == EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC */ ++ if (context.number_of_rva_and_sizes <= 5) ++ { ++ grub_dprintf ("chain", "image has no relocation entry\n"); ++ goto error_exit; ++ } ++ ++ if (context.reloc_dir->size && reloc_section) ++ { ++ /* run the relocation fixups */ ++ efi_status = relocate_coff (&context, reloc_section, data, ++ buffer_aligned); ++ ++ if (efi_status != GRUB_EFI_SUCCESS) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "relocation failed"); ++ goto error_exit; ++ } ++ } ++ ++ if (!found_entry_point) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "entry point is not within sections"); ++ goto error_exit; ++ } ++ if (found_entry_point > 1) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "%d sections contain entry point", ++ found_entry_point); ++ goto error_exit; ++ } ++ ++ li = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (!li) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "no loaded image available"); ++ goto error_exit; ++ } ++ ++ grub_memcpy (&li_bak, li, sizeof (grub_efi_loaded_image_t)); ++ li->image_base = buffer_aligned; ++ li->image_size = context.image_size; ++ li->load_options = cmdline; ++ li->load_options_size = cmdline_len; ++ li->file_path = grub_efi_get_media_file_path (file_path); ++ li->device_handle = dev_handle; ++ if (!li->file_path) ++ { ++ grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file path found"); ++ goto error_exit; ++ } ++ ++ grub_dprintf ("chain", "booting via entry point\n"); ++ efi_status = efi_call_2 (entry_point, grub_efi_image_handle, ++ grub_efi_system_table); ++ ++ grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); ++ grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); ++ efi_status = efi_call_1 (b->free_pool, buffer); ++ ++ return 1; ++ ++error_exit: ++ grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno); ++ if (buffer) ++ efi_call_1 (b->free_pool, buffer); ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_secureboot_chainloader_unload (void) ++{ ++ grub_efi_boot_services_t *b; ++ ++ b = grub_efi_system_table->boot_services; ++ efi_call_2 (b->free_pages, address, pages); ++ grub_free (file_path); ++ grub_free (cmdline); ++ cmdline = 0; ++ file_path = 0; ++ dev_handle = 0; ++ ++ grub_dl_unref (my_mod); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_load_and_start_image(void *boot_image) ++{ ++ grub_efi_boot_services_t *b; ++ grub_efi_status_t status; ++ grub_efi_loaded_image_t *loaded_image; ++ ++ b = grub_efi_system_table->boot_services; ++ ++ status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, ++ boot_image, fsize, &image_handle); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ if (status == GRUB_EFI_OUT_OF_RESOURCES) ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); ++ else ++ grub_error (GRUB_ERR_BAD_OS, "cannot load image"); ++ return -1; ++ } ++ ++ /* LoadImage does not set a device handler when the image is ++ loaded from memory, so it is necessary to set it explicitly here. ++ This is a mess. */ ++ loaded_image = grub_efi_get_loaded_image (image_handle); ++ if (! loaded_image) ++ { ++ grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); ++ return -1; ++ } ++ loaded_image->device_handle = dev_handle; ++ ++ if (cmdline) ++ { ++ loaded_image->load_options = cmdline; ++ loaded_image->load_options_size = cmdline_len; ++ } ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_secureboot_chainloader_boot (void) ++{ ++ int rc; ++ rc = handle_image ((void *)(unsigned long)address, fsize); ++ if (rc == 0) ++ { ++ grub_load_and_start_image((void *)(unsigned long)address); ++ } ++ ++ grub_loader_unset (); ++ return grub_errno; ++} ++ + static grub_err_t + grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) + { + grub_file_t file = 0; +- grub_ssize_t size; + grub_efi_status_t status; + grub_efi_boot_services_t *b; + grub_device_t dev = 0; + grub_efi_device_path_t *dp = 0; +- grub_efi_loaded_image_t *loaded_image; + char *filename; + void *boot_image = 0; +- grub_efi_handle_t dev_handle = 0; ++ int rc; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); +@@ -222,15 +899,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + address = 0; + image_handle = 0; + file_path = 0; ++ dev_handle = 0; + + b = grub_efi_system_table->boot_services; + ++ if (argc > 1) ++ { ++ int i; ++ grub_efi_char16_t *p16; ++ ++ for (i = 1, cmdline_len = 0; i < argc; i++) ++ cmdline_len += grub_strlen (argv[i]) + 1; ++ ++ cmdline_len *= sizeof (grub_efi_char16_t); ++ cmdline = p16 = grub_malloc (cmdline_len); ++ if (! cmdline) ++ goto fail; ++ ++ for (i = 1; i < argc; i++) ++ { ++ char *p8; ++ ++ p8 = argv[i]; ++ while (*p8) ++ *(p16++) = *(p8++); ++ ++ *(p16++) = ' '; ++ } ++ *(--p16) = 0; ++ } ++ + file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE); + if (! file) + goto fail; + +- /* Get the root device's device path. */ +- dev = grub_device_open (0); ++ /* Get the device path from filename. */ ++ char *devname = grub_file_get_device_name (filename); ++ dev = grub_device_open (devname); ++ if (devname) ++ grub_free (devname); + if (! dev) + goto fail; + +@@ -267,17 +974,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + if (! file_path) + goto fail; + +- grub_printf ("file path: "); +- grub_efi_print_device_path (file_path); +- +- size = grub_file_size (file); +- if (!size) ++ fsize = grub_file_size (file); ++ if (!fsize) + { + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + goto fail; + } +- pages = (((grub_efi_uintn_t) size + ((1 << 12) - 1)) >> 12); ++ pages = (((grub_efi_uintn_t) fsize + ((1 << 12) - 1)) >> 12); + + status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES, + GRUB_EFI_LOADER_CODE, +@@ -291,7 +995,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + + boot_image = (void *) ((grub_addr_t) address); +- if (grub_file_read (file, boot_image, size) != size) ++ if (grub_file_read (file, boot_image, fsize) != fsize) + { + if (grub_errno == GRUB_ERR_NONE) + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +@@ -301,7 +1005,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + + #if defined (__i386__) || defined (__x86_64__) +- if (size >= (grub_ssize_t) sizeof (struct grub_macho_fat_header)) ++ if (fsize >= (grub_ssize_t) sizeof (struct grub_macho_fat_header)) + { + struct grub_macho_fat_header *head = boot_image; + if (head->magic +@@ -310,6 +1014,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_uint32_t i; + struct grub_macho_fat_arch *archs + = (struct grub_macho_fat_arch *) (head + 1); ++ ++ if (grub_efi_secure_boot()) ++ { ++ grub_error (GRUB_ERR_BAD_OS, ++ "MACHO binaries are forbidden with Secure Boot"); ++ goto fail; ++ } ++ + for (i = 0; i < grub_cpu_to_le32 (head->nfat_arch); i++) + { + if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype)) +@@ -324,79 +1036,39 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + > ~grub_cpu_to_le32 (archs[i].size) + || grub_cpu_to_le32 (archs[i].offset) + + grub_cpu_to_le32 (archs[i].size) +- > (grub_size_t) size) ++ > (grub_size_t) fsize) + { + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), + filename); + goto fail; + } + boot_image = (char *) boot_image + grub_cpu_to_le32 (archs[i].offset); +- size = grub_cpu_to_le32 (archs[i].size); ++ fsize = grub_cpu_to_le32 (archs[i].size); + } + } + #endif + +- status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, +- boot_image, size, +- &image_handle); +- if (status != GRUB_EFI_SUCCESS) ++ rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); ++ grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); ++ if (rc > 0) + { +- if (status == GRUB_EFI_OUT_OF_RESOURCES) +- grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of resources"); +- else +- grub_error (GRUB_ERR_BAD_OS, "cannot load image"); +- +- goto fail; ++ grub_file_close (file); ++ grub_device_close (dev); ++ grub_loader_set (grub_secureboot_chainloader_boot, ++ grub_secureboot_chainloader_unload, 0); ++ return 0; + } +- +- /* LoadImage does not set a device handler when the image is +- loaded from memory, so it is necessary to set it explicitly here. +- This is a mess. */ +- loaded_image = grub_efi_get_loaded_image (image_handle); +- if (! loaded_image) ++ else if (rc == 0) + { +- grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); +- goto fail; +- } +- loaded_image->device_handle = dev_handle; +- +- if (argc > 1) +- { +- int i, len; +- grub_efi_char16_t *p16; +- +- for (i = 1, len = 0; i < argc; i++) +- len += grub_strlen (argv[i]) + 1; +- +- len *= sizeof (grub_efi_char16_t); +- cmdline = p16 = grub_malloc (len); +- if (! cmdline) +- goto fail; ++ grub_load_and_start_image(boot_image); ++ grub_file_close (file); ++ grub_device_close (dev); ++ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); + +- for (i = 1; i < argc; i++) +- { +- char *p8; +- +- p8 = argv[i]; +- while (*p8) +- *(p16++) = *(p8++); +- +- *(p16++) = ' '; +- } +- *(--p16) = 0; +- +- loaded_image->load_options = cmdline; +- loaded_image->load_options_size = len; ++ return 0; + } + +- grub_file_close (file); +- grub_device_close (dev); +- +- grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0); +- return 0; +- +- fail: +- ++fail: + if (dev) + grub_device_close (dev); + +@@ -408,6 +1080,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + if (address) + efi_call_2 (b->free_pages, address, pages); + ++ if (cmdline) ++ grub_free (cmdline); ++ + grub_dl_unref (my_mod); + + return grub_errno; +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index c24202a5dd1..c8ecce6dfd0 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -33,21 +33,34 @@ struct grub_efi_shim_lock + }; + typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; + +-grub_efi_boolean_t ++int + grub_linuxefi_secure_validate (void *data, grub_uint32_t size) + { + grub_efi_guid_t guid = SHIM_LOCK_GUID; + grub_efi_shim_lock_t *shim_lock; ++ grub_efi_status_t status; + + shim_lock = grub_efi_locate_protocol(&guid, NULL); +- ++ grub_dprintf ("secureboot", "shim_lock: %p\n", shim_lock); + if (!shim_lock) +- return 1; ++ { ++ grub_dprintf ("secureboot", "shim not available\n"); ++ return 0; ++ } + +- if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) +- return 1; ++ grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); ++ status = shim_lock->verify (data, size); ++ grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", (long int)status); ++ if (status == GRUB_EFI_SUCCESS) ++ { ++ grub_dprintf ("secureboot", "Kernel signature verification passed\n"); ++ return 1; ++ } + +- return 0; ++ grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", ++ (unsigned long) status); ++ ++ return -1; + } + + #pragma GCC diagnostic push +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index bb2616a8092..6b24cbb9483 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -117,6 +117,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_dprintf ("linux", "initrd_mem = %lx\n", (unsigned long) initrd_mem); ++ + params->ramdisk_size = size; + params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; + +@@ -159,6 +161,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + struct linux_i386_kernel_header lh; + grub_ssize_t len, start, filelen; + void *kernel = NULL; ++ int rc; + + grub_dl_ref (my_mod); + +@@ -184,11 +187,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + if (grub_file_read (file, kernel, filelen) != filelen) + { +- grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]); ++ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), ++ argv[0]); + goto fail; + } + +- if (! grub_linuxefi_secure_validate (kernel, filelen)) ++ rc = grub_linuxefi_secure_validate (kernel, filelen); ++ if (rc < 0) + { + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), + argv[0]); +@@ -203,6 +208,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_dprintf ("linux", "params = %lx\n", (unsigned long) params); ++ + grub_memset (params, 0, 16384); + + grub_memcpy (&lh, kernel, sizeof (lh)); +@@ -241,6 +248,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_dprintf ("linux", "linux_cmdline = %lx\n", ++ (unsigned long)linux_cmdline); ++ + grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, + linux_cmdline + sizeof (LINUX_IMAGE) - 1, +@@ -275,9 +285,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_memcpy (params, &lh, 2 * 512); + + params->type_of_loader = 0x21; ++ grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", ++ kernel_mem, handover_offset); + + fail: +- + if (file) + grub_file_close (file); + +diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h +index d9ede36773b..0033d9305a9 100644 +--- a/include/grub/efi/linux.h ++++ b/include/grub/efi/linux.h +@@ -22,7 +22,7 @@ + #include + #include + +-grub_efi_boolean_t ++int + EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size); + grub_err_t + EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, +diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index 0ed8781f037..a43adf27464 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -223,7 +223,11 @@ struct grub_pe64_optional_header + struct grub_pe32_section_table + { + char name[8]; +- grub_uint32_t virtual_size; ++ union ++ { ++ grub_uint32_t physical_address; ++ grub_uint32_t virtual_size; ++ }; + grub_uint32_t virtual_address; + grub_uint32_t raw_data_size; + grub_uint32_t raw_data_offset; +@@ -234,12 +238,18 @@ struct grub_pe32_section_table + grub_uint32_t characteristics; + }; + ++#define GRUB_PE32_SCN_TYPE_NO_PAD 0x00000008 + #define GRUB_PE32_SCN_CNT_CODE 0x00000020 + #define GRUB_PE32_SCN_CNT_INITIALIZED_DATA 0x00000040 +-#define GRUB_PE32_SCN_MEM_DISCARDABLE 0x02000000 +-#define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000 +-#define GRUB_PE32_SCN_MEM_READ 0x40000000 +-#define GRUB_PE32_SCN_MEM_WRITE 0x80000000 ++#define GRUB_PE32_SCN_CNT_UNINITIALIZED_DATA 0x00000080 ++#define GRUB_PE32_SCN_LNK_OTHER 0x00000100 ++#define GRUB_PE32_SCN_LNK_INFO 0x00000200 ++#define GRUB_PE32_SCN_LNK_REMOVE 0x00000800 ++#define GRUB_PE32_SCN_LNK_COMDAT 0x00001000 ++#define GRUB_PE32_SCN_GPREL 0x00008000 ++#define GRUB_PE32_SCN_MEM_16BIT 0x00020000 ++#define GRUB_PE32_SCN_MEM_LOCKED 0x00040000 ++#define GRUB_PE32_SCN_MEM_PRELOAD 0x00080000 + + #define GRUB_PE32_SCN_ALIGN_1BYTES 0x00100000 + #define GRUB_PE32_SCN_ALIGN_2BYTES 0x00200000 +@@ -248,10 +258,28 @@ struct grub_pe32_section_table + #define GRUB_PE32_SCN_ALIGN_16BYTES 0x00500000 + #define GRUB_PE32_SCN_ALIGN_32BYTES 0x00600000 + #define GRUB_PE32_SCN_ALIGN_64BYTES 0x00700000 ++#define GRUB_PE32_SCN_ALIGN_128BYTES 0x00800000 ++#define GRUB_PE32_SCN_ALIGN_256BYTES 0x00900000 ++#define GRUB_PE32_SCN_ALIGN_512BYTES 0x00A00000 ++#define GRUB_PE32_SCN_ALIGN_1024BYTES 0x00B00000 ++#define GRUB_PE32_SCN_ALIGN_2048BYTES 0x00C00000 ++#define GRUB_PE32_SCN_ALIGN_4096BYTES 0x00D00000 ++#define GRUB_PE32_SCN_ALIGN_8192BYTES 0x00E00000 + + #define GRUB_PE32_SCN_ALIGN_SHIFT 20 + #define GRUB_PE32_SCN_ALIGN_MASK 7 + ++#define GRUB_PE32_SCN_LNK_NRELOC_OVFL 0x01000000 ++#define GRUB_PE32_SCN_MEM_DISCARDABLE 0x02000000 ++#define GRUB_PE32_SCN_MEM_NOT_CACHED 0x04000000 ++#define GRUB_PE32_SCN_MEM_NOT_PAGED 0x08000000 ++#define GRUB_PE32_SCN_MEM_SHARED 0x10000000 ++#define GRUB_PE32_SCN_MEM_EXECUTE 0x20000000 ++#define GRUB_PE32_SCN_MEM_READ 0x40000000 ++#define GRUB_PE32_SCN_MEM_WRITE 0x80000000 ++ ++ ++ + #define GRUB_PE32_SIGNATURE_SIZE 4 + + struct grub_pe32_header +@@ -274,6 +302,20 @@ struct grub_pe32_header + #endif + }; + ++struct grub_pe32_header_32 ++{ ++ char signature[GRUB_PE32_SIGNATURE_SIZE]; ++ struct grub_pe32_coff_header coff_header; ++ struct grub_pe32_optional_header optional_header; ++}; ++ ++struct grub_pe32_header_64 ++{ ++ char signature[GRUB_PE32_SIGNATURE_SIZE]; ++ struct grub_pe32_coff_header coff_header; ++ struct grub_pe64_optional_header optional_header; ++}; ++ + struct grub_pe32_fixup_block + { + grub_uint32_t page_rva; diff --git a/0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch b/0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch new file mode 100644 index 0000000..382fd23 --- /dev/null +++ b/0005-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch @@ -0,0 +1,516 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 6 Oct 2015 16:09:25 -0400 +Subject: [PATCH] Make any of the loaders that link in efi mode honor secure + boot. + +And in this case "honor" means "even if somebody does link this in, they +won't register commands if SB is enabled." + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 1 + + grub-core/commands/iorw.c | 7 +++++ + grub-core/commands/memrw.c | 7 +++++ + grub-core/kern/dl.c | 1 + + grub-core/kern/efi/efi.c | 34 -------------------- + grub-core/kern/efi/sb.c | 64 ++++++++++++++++++++++++++++++++++++++ + grub-core/loader/efi/appleloader.c | 7 +++++ + grub-core/loader/efi/chainloader.c | 1 + + grub-core/loader/i386/bsd.c | 7 +++++ + grub-core/loader/i386/linux.c | 7 +++++ + grub-core/loader/i386/pc/linux.c | 7 +++++ + grub-core/loader/multiboot.c | 7 +++++ + grub-core/loader/xnu.c | 7 +++++ + include/grub/efi/efi.h | 1 - + include/grub/efi/sb.h | 29 +++++++++++++++++ + include/grub/ia64/linux.h | 0 + include/grub/mips/linux.h | 0 + include/grub/powerpc/linux.h | 0 + include/grub/sparc64/linux.h | 0 + grub-core/Makefile.am | 1 + + 20 files changed, 153 insertions(+), 35 deletions(-) + create mode 100644 grub-core/kern/efi/sb.c + create mode 100644 include/grub/efi/sb.h + create mode 100644 include/grub/ia64/linux.h + create mode 100644 include/grub/mips/linux.h + create mode 100644 include/grub/powerpc/linux.h + create mode 100644 include/grub/sparc64/linux.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 581d9dfc3b3..eb1088fd654 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -207,6 +207,7 @@ kernel = { + i386_multiboot = kern/i386/pc/acpi.c; + i386_coreboot = kern/acpi.c; + i386_multiboot = kern/acpi.c; ++ common = kern/efi/sb.c; + + x86 = kern/i386/tsc.c; + x86 = kern/i386/tsc_pit.c; +diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c +index a0c164e54f0..41a7f3f0466 100644 +--- a/grub-core/commands/iorw.c ++++ b/grub-core/commands/iorw.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -118,6 +119,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) + + GRUB_MOD_INIT(memrw) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_read_byte = + grub_register_extcmd ("inb", grub_cmd_read, 0, + N_("PORT"), N_("Read 8-bit value from PORT."), +@@ -146,6 +150,9 @@ GRUB_MOD_INIT(memrw) + + GRUB_MOD_FINI(memrw) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_extcmd (cmd_read_byte); + grub_unregister_extcmd (cmd_read_word); + grub_unregister_extcmd (cmd_read_dword); +diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c +index 98769eadb34..088cbe9e2bc 100644 +--- a/grub-core/commands/memrw.c ++++ b/grub-core/commands/memrw.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -120,6 +121,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv) + + GRUB_MOD_INIT(memrw) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_read_byte = + grub_register_extcmd ("read_byte", grub_cmd_read, 0, + N_("ADDR"), N_("Read 8-bit value from ADDR."), +@@ -148,6 +152,9 @@ GRUB_MOD_INIT(memrw) + + GRUB_MOD_FINI(memrw) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_extcmd (cmd_read_byte); + grub_unregister_extcmd (cmd_read_word); + grub_unregister_extcmd (cmd_read_dword); +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 896bebfd57e..d7718d26abc 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + /* Platforms where modules are in a readonly area of memory. */ + #if defined(GRUB_MACHINE_QEMU) +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 3487b0623a4..6e1ceb90516 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -273,40 +273,6 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + return NULL; + } + +-grub_efi_boolean_t +-grub_efi_secure_boot (void) +-{ +- grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; +- grub_size_t datasize; +- char *secure_boot = NULL; +- char *setup_mode = NULL; +- grub_efi_boolean_t ret = 0; +- +- secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); +- if (datasize != 1 || !secure_boot) +- { +- grub_dprintf ("secureboot", "No SecureBoot variable\n"); +- goto out; +- } +- grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); +- +- setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); +- if (datasize != 1 || !setup_mode) +- { +- grub_dprintf ("secureboot", "No SetupMode variable\n"); +- goto out; +- } +- grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); +- +- if (*secure_boot && !*setup_mode) +- ret = 1; +- +- out: +- grub_free (secure_boot); +- grub_free (setup_mode); +- return ret; +-} +- + #pragma GCC diagnostic ignored "-Wcast-align" + + /* Search the mods section from the PE32/PE32+ image. This code uses +diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c +new file mode 100644 +index 00000000000..d74778b0cac +--- /dev/null ++++ b/grub-core/kern/efi/sb.c +@@ -0,0 +1,64 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2014 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++int ++grub_efi_secure_boot (void) ++{ ++#ifdef GRUB_MACHINE_EFI ++ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; ++ grub_size_t datasize; ++ char *secure_boot = NULL; ++ char *setup_mode = NULL; ++ grub_efi_boolean_t ret = 0; ++ ++ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize); ++ if (datasize != 1 || !secure_boot) ++ { ++ grub_dprintf ("secureboot", "No SecureBoot variable\n"); ++ goto out; ++ } ++ grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot); ++ ++ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize); ++ if (datasize != 1 || !setup_mode) ++ { ++ grub_dprintf ("secureboot", "No SetupMode variable\n"); ++ goto out; ++ } ++ grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode); ++ ++ if (*secure_boot && !*setup_mode) ++ ret = 1; ++ ++ out: ++ grub_free (secure_boot); ++ grub_free (setup_mode); ++ return ret; ++#else ++ return 0; ++#endif ++} +diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c +index 74888c463ba..69c2a10d351 100644 +--- a/grub-core/loader/efi/appleloader.c ++++ b/grub-core/loader/efi/appleloader.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -227,6 +228,9 @@ static grub_command_t cmd; + + GRUB_MOD_INIT(appleloader) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd = grub_register_command ("appleloader", grub_cmd_appleloader, + N_("[OPTS]"), + /* TRANSLATORS: This command is used on EFI to +@@ -238,5 +242,8 @@ GRUB_MOD_INIT(appleloader) + + GRUB_MOD_FINI(appleloader) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_command (cmd); + } +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index ef87b06cf70..5aa3a5dc7dd 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + #include + #include + #include +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 3730ed38247..5b9b92d6ba5 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -39,6 +39,7 @@ + #ifdef GRUB_MACHINE_PCBIOS + #include + #endif ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -2130,6 +2131,9 @@ static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk; + + GRUB_MOD_INIT (bsd) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + /* Net and OpenBSD kernels are often compressed. */ + grub_dl_load ("gzio"); + +@@ -2169,6 +2173,9 @@ GRUB_MOD_INIT (bsd) + + GRUB_MOD_FINI (bsd) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_extcmd (cmd_freebsd); + grub_unregister_extcmd (cmd_openbsd); + grub_unregister_extcmd (cmd_netbsd); +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index b255c950526..376c726928a 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1131,6 +1132,9 @@ static grub_command_t cmd_linux, cmd_initrd; + + GRUB_MOD_INIT(linux) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_linux = grub_register_command ("linux", grub_cmd_linux, + 0, N_("Load Linux.")); + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, +@@ -1140,6 +1144,9 @@ GRUB_MOD_INIT(linux) + + GRUB_MOD_FINI(linux) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); + } +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 73fb91e0570..fe3e1d41d09 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -483,6 +484,9 @@ static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16; + + GRUB_MOD_INIT(linux16) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_linux = + grub_register_command ("linux", grub_cmd_linux, + 0, N_("Load Linux.")); +@@ -500,6 +504,9 @@ GRUB_MOD_INIT(linux16) + + GRUB_MOD_FINI(linux16) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_linux16); + grub_unregister_command (cmd_initrd); +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 4a98d708259..3e6ad166dc9 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -50,6 +50,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -444,6 +445,9 @@ static grub_command_t cmd_multiboot, cmd_module; + + GRUB_MOD_INIT(multiboot) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_multiboot = + #ifdef GRUB_USE_MULTIBOOT2 + grub_register_command ("multiboot2", grub_cmd_multiboot, +@@ -464,6 +468,9 @@ GRUB_MOD_INIT(multiboot) + + GRUB_MOD_FINI(multiboot) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_command (cmd_multiboot); + grub_unregister_command (cmd_module); + } +diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c +index 7f74d1d6fc9..e0f47e72b06 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1478,6 +1479,9 @@ static grub_extcmd_t cmd_splash; + + GRUB_MOD_INIT(xnu) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0, + N_("Load XNU image.")); + cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64, +@@ -1518,6 +1522,9 @@ GRUB_MOD_INIT(xnu) + + GRUB_MOD_FINI(xnu) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + #ifndef GRUB_MACHINE_EMU + grub_unregister_command (cmd_resume); + #endif +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 6840bfee9b7..090c8621066 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -85,7 +85,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var, + const grub_efi_guid_t *guid, + void *data, + grub_size_t datasize); +-grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void); + int + EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1, + const grub_efi_device_path_t *dp2); +diff --git a/include/grub/efi/sb.h b/include/grub/efi/sb.h +new file mode 100644 +index 00000000000..9629fbb0f9e +--- /dev/null ++++ b/include/grub/efi/sb.h +@@ -0,0 +1,29 @@ ++/* sb.h - declare functions for EFI Secure Boot support */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_EFI_SB_HEADER ++#define GRUB_EFI_SB_HEADER 1 ++ ++#include ++#include ++ ++/* Functions. */ ++int EXPORT_FUNC (grub_efi_secure_boot) (void); ++ ++#endif /* ! GRUB_EFI_SB_HEADER */ +diff --git a/include/grub/ia64/linux.h b/include/grub/ia64/linux.h +new file mode 100644 +index 00000000000..e69de29bb2d +diff --git a/include/grub/mips/linux.h b/include/grub/mips/linux.h +new file mode 100644 +index 00000000000..e69de29bb2d +diff --git a/include/grub/powerpc/linux.h b/include/grub/powerpc/linux.h +new file mode 100644 +index 00000000000..e69de29bb2d +diff --git a/include/grub/sparc64/linux.h b/include/grub/sparc64/linux.h +new file mode 100644 +index 00000000000..e69de29bb2d +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 3ea8e7ff45f..c6ba5b2d763 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -71,6 +71,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/disk.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/dl.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h diff --git a/0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch b/0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch new file mode 100644 index 0000000..274321e --- /dev/null +++ b/0006-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch @@ -0,0 +1,264 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jul 2019 12:32:37 +0200 +Subject: [PATCH] Handle multi-arch (64-on-32) boot in linuxefi loader. + +Allow booting 64-bit kernels on 32-bit EFI on x86. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/linux.c | 9 +++- + grub-core/loader/i386/efi/linux.c | 110 ++++++++++++++++++++++++++------------ + include/grub/i386/linux.h | 7 ++- + 3 files changed, 89 insertions(+), 37 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index c8ecce6dfd0..0622dfa48d4 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -69,12 +69,17 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) + typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); + + grub_err_t +-grub_efi_linux_boot (void *kernel_addr, grub_off_t offset, ++grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, + void *kernel_params) + { + handover_func hf; ++ int offset = 0; + +- hf = (handover_func)((char *)kernel_addr + offset); ++#ifdef __x86_64__ ++ offset = 512; ++#endif ++ ++ hf = (handover_func)((char *)kernel_addr + handover_offset + offset); + hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); + + return GRUB_ERR_BUG; +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 6b24cbb9483..3017d0f3e52 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -44,14 +44,10 @@ static char *linux_cmdline; + static grub_err_t + grub_linuxefi_boot (void) + { +- int offset = 0; +- +-#ifdef __x86_64__ +- offset = 512; +-#endif + asm volatile ("cli"); + +- return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, ++ return grub_efi_linux_boot ((char *)kernel_mem, ++ handover_offset, + params); + } + +@@ -153,14 +149,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + return grub_errno; + } + ++#define MIN(a, b) \ ++ ({ typeof (a) _a = (a); \ ++ typeof (b) _b = (b); \ ++ _a < _b ? _a : _b; }) ++ + static grub_err_t + grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) + { + grub_file_t file = 0; +- struct linux_i386_kernel_header lh; +- grub_ssize_t len, start, filelen; ++ struct linux_i386_kernel_header *lh = NULL; ++ grub_ssize_t start, filelen; + void *kernel = NULL; ++ int setup_header_end_offset; + int rc; + + grub_dl_ref (my_mod); +@@ -200,48 +202,79 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384)); +- ++ params = grub_efi_allocate_pages_max (0x3fffffff, ++ BYTES_TO_PAGES(sizeof(*params))); + if (! params) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); + goto fail; + } + +- grub_dprintf ("linux", "params = %lx\n", (unsigned long) params); ++ grub_dprintf ("linux", "params = %p\n", params); + +- grub_memset (params, 0, 16384); ++ grub_memset (params, 0, sizeof(*params)); + +- grub_memcpy (&lh, kernel, sizeof (lh)); +- +- if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) ++ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); ++ grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", ++ MIN((grub_size_t)0x202+setup_header_end_offset, ++ sizeof (*params)) - 0x1f1, ++ (grub_uint8_t *)kernel + 0x1f1, ++ (grub_uint8_t *)params + 0x1f1); ++ grub_memcpy ((grub_uint8_t *)params + 0x1f1, ++ (grub_uint8_t *)kernel + 0x1f1, ++ MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); ++ lh = (struct linux_i386_kernel_header *)params; ++ grub_dprintf ("linux", "lh is at %p\n", lh); ++ grub_dprintf ("linux", "checking lh->boot_flag\n"); ++ if (lh->boot_flag != grub_cpu_to_le16 (0xaa55)) + { + grub_error (GRUB_ERR_BAD_OS, N_("invalid magic number")); + goto fail; + } + +- if (lh.setup_sects > GRUB_LINUX_MAX_SETUP_SECTS) ++ grub_dprintf ("linux", "checking lh->setup_sects\n"); ++ if (lh->setup_sects > GRUB_LINUX_MAX_SETUP_SECTS) + { + grub_error (GRUB_ERR_BAD_OS, N_("too many setup sectors")); + goto fail; + } + +- if (lh.version < grub_cpu_to_le16 (0x020b)) ++ grub_dprintf ("linux", "checking lh->version\n"); ++ if (lh->version < grub_cpu_to_le16 (0x020b)) + { + grub_error (GRUB_ERR_BAD_OS, N_("kernel too old")); + goto fail; + } + +- if (!lh.handover_offset) ++ grub_dprintf ("linux", "checking lh->handover_offset\n"); ++ if (!lh->handover_offset) + { + grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support EFI handover")); + goto fail; + } + ++#if defined(__x86_64__) || defined(__aarch64__) ++ grub_dprintf ("linux", "checking lh->xloadflags\n"); ++ if (!(lh->xloadflags & LINUX_XLF_KERNEL_64)) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support 64-bit CPUs")); ++ goto fail; ++ } ++#endif ++ ++#if defined(__i386__) ++ if ((lh->xloadflags & LINUX_XLF_KERNEL_64) && ++ !(lh->xloadflags & LINUX_XLF_EFI_HANDOVER_32)) ++ { ++ grub_error (GRUB_ERR_BAD_OS, ++ N_("kernel doesn't support 32-bit handover")); ++ goto fail; ++ } ++#endif ++ + grub_dprintf ("linux", "setting up cmdline\n"); + linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff, +- BYTES_TO_PAGES(lh.cmdline_size + 1)); +- ++ BYTES_TO_PAGES(lh->cmdline_size + 1)); + if (!linux_cmdline) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline")); +@@ -254,22 +287,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, + linux_cmdline + sizeof (LINUX_IMAGE) - 1, +- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1), ++ lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1), + GRUB_VERIFY_KERNEL_CMDLINE); + +- lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; ++ grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); ++ grub_dprintf ("linux", "setting lh->cmd_line_ptr\n"); ++ lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; + +- handover_offset = lh.handover_offset; ++ grub_dprintf ("linux", "computing handover offset\n"); ++ handover_offset = lh->handover_offset; + +- start = (lh.setup_sects + 1) * 512; +- len = grub_file_size(file) - start; ++ start = (lh->setup_sects + 1) * 512; + +- kernel_mem = grub_efi_allocate_pages_max(lh.pref_address, +- BYTES_TO_PAGES(lh.init_size)); ++ kernel_mem = grub_efi_allocate_pages_max(lh->pref_address, ++ BYTES_TO_PAGES(lh->init_size)); + + if (!kernel_mem) + kernel_mem = grub_efi_allocate_pages_max(0x3fffffff, +- BYTES_TO_PAGES(lh.init_size)); ++ BYTES_TO_PAGES(lh->init_size)); + + if (!kernel_mem) + { +@@ -277,14 +312,21 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_memcpy (kernel_mem, (char *)kernel + start, len); ++ grub_dprintf ("linux", "kernel_mem = %lx\n", (unsigned long) kernel_mem); ++ + grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); + loaded=1; ++ grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem); ++ lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem; + +- lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; +- grub_memcpy (params, &lh, 2 * 512); ++ grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); + +- params->type_of_loader = 0x21; ++ grub_dprintf ("linux", "setting lh->type_of_loader\n"); ++ lh->type_of_loader = 0x6; ++ ++ grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n"); ++ params->ext_loader_type = 0; ++ params->ext_loader_ver = 2; + grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", + kernel_mem, handover_offset); + +@@ -301,10 +343,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + loaded = 0; + } + +- if (linux_cmdline && !loaded) ++ if (linux_cmdline && lh && !loaded) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) + linux_cmdline, +- BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ BYTES_TO_PAGES(lh->cmdline_size + 1)); + + if (kernel_mem && !loaded) + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, +diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h +index ce30e7fb01b..a093679cb80 100644 +--- a/include/grub/i386/linux.h ++++ b/include/grub/i386/linux.h +@@ -136,7 +136,12 @@ struct linux_i386_kernel_header + grub_uint32_t kernel_alignment; + grub_uint8_t relocatable; + grub_uint8_t min_alignment; +- grub_uint8_t pad[2]; ++#define LINUX_XLF_KERNEL_64 (1<<0) ++#define LINUX_XLF_CAN_BE_LOADED_ABOVE_4G (1<<1) ++#define LINUX_XLF_EFI_HANDOVER_32 (1<<2) ++#define LINUX_XLF_EFI_HANDOVER_64 (1<<3) ++#define LINUX_XLF_EFI_KEXEC (1<<4) ++ grub_uint16_t xloadflags; + grub_uint32_t cmdline_size; + grub_uint32_t hardware_subarch; + grub_uint64_t hardware_subarch_data; diff --git a/0007-re-write-.gitignore.patch b/0007-re-write-.gitignore.patch new file mode 100644 index 0000000..2573139 --- /dev/null +++ b/0007-re-write-.gitignore.patch @@ -0,0 +1,470 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jul 2019 12:55:29 +0200 +Subject: [PATCH] re-write .gitignore + +--- + .gitignore | 366 +++++++++++++++----------------------- + docs/.gitignore | 5 + + grub-core/.gitignore | 16 ++ + grub-core/lib/.gitignore | 1 + + include/grub/gcrypt/.gitignore | 2 + + po/.gitignore | 5 + + util/bash-completion.d/.gitignore | 2 + + 7 files changed, 171 insertions(+), 226 deletions(-) + create mode 100644 docs/.gitignore + create mode 100644 grub-core/.gitignore + create mode 100644 grub-core/lib/.gitignore + create mode 100644 include/grub/gcrypt/.gitignore + create mode 100644 po/.gitignore + create mode 100644 util/bash-completion.d/.gitignore + +diff --git a/.gitignore b/.gitignore +index 819cd185d44..b45a633f3d1 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -1,237 +1,151 @@ ++# things ./autogen.sh will create ++/Makefile.utilgcry.def ++/ABOUT-NLS ++/aclocal.m4 ++/autom4te.cache ++/build-aux ++/configure ++/gnulib ++/grub-core/lib/gnulib/ ++/Makefile ++ ++# things very common editors create that we never want + *~ +-00_header +-10_* +-20_linux_xen +-30_os-prober +-40_custom +-41_custom +-*.1 +-*.8 +-ABOUT-NLS +-aclocal.m4 +-ahci_test +-ascii.bitmaps +-ascii.h +-autom4te.cache +-build-aux +-build-grub-gen-asciih +-build-grub-gen-widthspec +-build-grub-mkfont +-cdboot_test +-cmp_test +-config.cache +-config.guess +-config.h +-config-util.h +-config-util.h.in +-config.log +-config.status +-config.sub +-configure +-core_compress_test +-DISTLIST +-docs/*.info +-docs/stamp-vti +-docs/version.texi +-ehci_test +-example_grub_script_test +-example_scripted_test +-example_unit_test ++.*.sw? ++*.patch ++ ++# stuff you're likely to make while building test trees ++grub.cfg ++/build*/ ++ ++# built objects across the whole tree ++Makefile.in ++*.a ++*.am ++*.efi + *.exec +-*.exec.exe +-fddboot_test +-genkernsyms.sh +-gensymlist.sh +-gentrigtables +-gentrigtables.exe +-gettext_strings_test +-/gnulib +-grub-bin2h +-/grub-bios-setup +-/grub-bios-setup.exe +-grub_cmd_date +-grub_cmd_echo +-grub_cmd_regexp +-grub_cmd_set_date +-grub_cmd_sleep +-/grub-editenv +-/grub-editenv.exe +-grub-emu +-grub-emu-lite +-grub-emu.exe +-grub-emu-lite.exe +-grub_emu_init.c +-grub_emu_init.h +-/grub-file +-/grub-file.exe +-grub-fstest +-grub-fstest.exe +-grub_fstest_init.c +-grub_fstest_init.h +-grub_func_test +-grub-install +-grub-install.exe +-grub-kbdcomp +-/grub-macbless +-/grub-macbless.exe +-grub-macho2img +-/grub-menulst2cfg +-/grub-menulst2cfg.exe +-/grub-mk* +-grub-mount +-/grub-ofpathname +-/grub-ofpathname.exe +-grub-core/build-grub-pe2elf.exe +-/grub-probe +-/grub-probe.exe +-grub_probe_init.c +-grub_probe_init.h +-/grub-reboot +-grub_script_blanklines +-grub_script_blockarg +-grub_script_break +-grub-script-check +-grub-script-check.exe +-grub_script_check_init.c +-grub_script_check_init.h +-grub_script_comments +-grub_script_continue +-grub_script_dollar +-grub_script_echo1 +-grub_script_echo_keywords +-grub_script_escape_comma +-grub_script_eval +-grub_script_expansion +-grub_script_final_semicolon +-grub_script_for1 +-grub_script_functions +-grub_script_gettext +-grub_script_if +-grub_script_leading_whitespace +-grub_script_no_commands +-grub_script_not +-grub_script_return +-grub_script_setparams +-grub_script_shift +-grub_script_strcmp +-grub_script_test +-grub_script_vars1 +-grub_script_while1 +-grub_script.tab.c +-grub_script.tab.h +-grub_script.yy.c +-grub_script.yy.h +-grub-set-default +-grub_setup_init.c +-grub_setup_init.h +-grub-shell +-grub-shell-tester +-grub-sparc64-setup +-grub-sparc64-setup.exe +-/grub-syslinux2cfg +-/grub-syslinux2cfg.exe +-gzcompress_test +-hddboot_test +-help_test +-*.img + *.image +-*.image.exe +-include/grub/cpu +-include/grub/machine +-INSTALL.grub +-install-sh +-lib/libgcrypt-grub +-libgrub_a_init.c +-*.log ++*.img ++*.info + *.lst +-lzocompress_test + *.marker +-Makefile + /m4 + *.mod +-mod-*.c +-missing +-netboot_test ++*.module + *.o +-*.a +-ohci_test +-partmap_test +-pata_test + *.pf2 +-*.pp +-po/*.mo +-po/grub.pot +-po/Makefile.in.in +-po/Makevars +-po/Makevars.template +-po/POTFILES +-po/Rules-quot +-po/stamp-po +-printf_test +-priority_queue_unit_test +-pseries_test +-stamp-h +-stamp-h1 +-stamp-h.in +-symlist.c +-symlist.h +-trigtables.c +-*.trs +-uhci_test +-update-grub_lib +-unidata.c +-xzcompress_test +-Makefile.in +-GPATH +-GRTAGS +-GSYMS +-GTAGS +-compile +-depcomp +-mdate-sh +-texinfo.tex +-grub-core/lib/libgcrypt-grub +-.deps +-.deps-util +-.deps-core ++*.yy.[ch] ++.deps/ ++.deps-core/ ++.deps-util/ + .dirstamp +-Makefile.util.am +-contrib +-grub-core/bootinfo.txt +-grub-core/Makefile.core.am +-grub-core/Makefile.gcry.def +-grub-core/contrib +-grub-core/gdb_grub +-grub-core/genmod.sh +-grub-core/gensyminfo.sh +-grub-core/gmodule.pl +-grub-core/grub.chrp +-grub-core/modinfo.sh +-grub-core/*.module +-grub-core/*.module.exe +-grub-core/*.pp +-grub-core/kernel.img.bin +-util/bash-completion.d/grub +-grub-core/lib/gnulib +-grub-core/rs_decoder.h +-widthspec.bin +-widthspec.h +-docs/stamp-1 +-docs/version-dev.texi +-Makefile.utilgcry.def +-po/*.po +-po/*.gmo +-po/LINGUAS +-po/remove-potcdate.sed +-include/grub/gcrypt/gcrypt.h +-include/grub/gcrypt/g10lib.h +-po/POTFILES.in +-po/POTFILES-shell.in +-/grub-glue-efi +-/grub-render-label +-/grub-glue-efi.exe +-/grub-render-label.exe ++ ++# next are things you get if you do ./configure in the topdir (for e.g. ++# "make dist" invocation. ++/config-util.h ++/config.h ++/include/grub/cpu ++/include/grub/machine ++/INSTALL ++/INSTALL.grub ++/po/Makefile.in.in ++/po/Makevars ++/po/Makevars.template ++/po/POTFILES ++/po/Rules-quot ++/stamp-h ++/stamp-h1 ++bootstrap.log ++config.log ++config.status ++ ++# stuff "make dist" creates ++ChangeLog ++grub-*.tar ++grub-*.tar.* ++ ++# stuff "make" creates ++/[[:digit:]][[:digit:]]_?* ++/ascii.h ++/build-grub-gen-asciih ++/build-grub-gen-widthspec ++/build-grub-mkfont ++/config-util.h.in + /garbage-gen +-/garbage-gen.exe +-/grub-fs-tester +-grub-core/build-grub-module-verifier ++/grub*-bios-setup ++/grub*-bios-setup.8 ++/grub*-editenv ++/grub*-editenv.1 ++/grub*-file ++/grub*-file.1 ++/grub*-fs-tester ++/grub*-fstest ++/grub*-fstest.1 ++/grub*-get-kernel-settings ++/grub*-get-kernel-settings.3 ++/grub*-glue-efi ++/grub*-glue-efi.1 ++/grub*-install ++/grub*-install.8 ++/grub*-kbdcomp ++/grub*-kbdcomp.1 ++/grub*-macbless ++/grub*-macbless.8 ++/grub*-menulst2cfg ++/grub*-menulst2cfg.1 ++/grub*-mount ++/grub*-mount.1 ++/grub*-mkconfig ++/grub*-mkconfig.8 ++/grub*-mkconfig_lib ++/grub*-mkfont ++/grub*-mkfont.1 ++/grub*-mkimage ++/grub*-mkimage.1 ++/grub*-mklayout ++/grub*-mklayout.1 ++/grub*-mknetdir ++/grub*-mknetdir.1 ++/grub*-mkpasswd-pbkdf2 ++/grub*-mkpasswd-pbkdf2.1 ++/grub*-mkrelpath ++/grub*-mkrelpath.1 ++/grub*-mkrescue ++/grub*-mkrescue.1 ++/grub*-mkstandalone ++/grub*-mkstandalone.1 ++/grub*-ofpathname ++/grub*-ofpathname.8 ++/grub*-probe ++/grub*-probe.8 ++/grub*-reboot ++/grub*-reboot.8 ++/grub*-render-label ++/grub*-render-label.1 ++/grub*-rpm-sort ++/grub*-rpm-sort.8 ++/grub*-script-check ++/grub*-script-check.1 ++/grub*-set-bootflag ++/grub*-set-bootflag.1 ++/grub*-set-default ++/grub*-set-default.8 ++/grub*-set-password ++/grub*-set-password.8 ++/grub*-shell ++/grub*-shell-tester ++/grub*-sparc64-setup ++/grub*-sparc64-setup.8 ++/grub*-syslinux2cfg ++/grub*-syslinux2cfg.1 ++/grub*-switch-to-blscfg ++/grub*-switch-to-blscfg.8 ++/grub_fstest.pp ++/grub_fstest_init.c ++/grub_fstest_init.lst ++/grub_script.tab.[ch] ++/libgrub.pp ++/libgrub_a_init.c ++/libgrub_a_init.lst ++/stamp-h.in ++/widthspec.h +diff --git a/docs/.gitignore b/docs/.gitignore +new file mode 100644 +index 00000000000..e1d849ef95b +--- /dev/null ++++ b/docs/.gitignore +@@ -0,0 +1,5 @@ ++/*.in ++/Makefile ++/stamp-1 ++/stamp-vti ++/version*.texi +diff --git a/grub-core/.gitignore b/grub-core/.gitignore +new file mode 100644 +index 00000000000..2acce281159 +--- /dev/null ++++ b/grub-core/.gitignore +@@ -0,0 +1,16 @@ ++/*.lst ++/Makefile ++/Makefile.gcry.def ++/unidata.c ++/build-grub-module-verifier ++/gdb_grub ++/genmod.sh ++/gensyminfo.sh ++/gentrigtables ++/gmodule.pl ++/grub_script.tab.[ch] ++/modinfo.sh ++/rs_decoder.h ++/symlist.c ++/symlist.h ++/trigtables.c +diff --git a/grub-core/lib/.gitignore b/grub-core/lib/.gitignore +new file mode 100644 +index 00000000000..68154591404 +--- /dev/null ++++ b/grub-core/lib/.gitignore +@@ -0,0 +1 @@ ++/libgcrypt-grub/ +diff --git a/include/grub/gcrypt/.gitignore b/include/grub/gcrypt/.gitignore +new file mode 100644 +index 00000000000..8fbf5646246 +--- /dev/null ++++ b/include/grub/gcrypt/.gitignore +@@ -0,0 +1,2 @@ ++g10lib.h ++gcrypt.h +diff --git a/po/.gitignore b/po/.gitignore +new file mode 100644 +index 00000000000..f507e7741e3 +--- /dev/null ++++ b/po/.gitignore +@@ -0,0 +1,5 @@ ++/Makefile ++/POTFILES*.in ++/grub.pot ++/remove-potcdate.sed ++/stamp-po +diff --git a/util/bash-completion.d/.gitignore b/util/bash-completion.d/.gitignore +new file mode 100644 +index 00000000000..6813a527ad3 +--- /dev/null ++++ b/util/bash-completion.d/.gitignore +@@ -0,0 +1,2 @@ ++Makefile ++grub diff --git a/0008-IBM-client-architecture-CAS-reboot-support.patch b/0008-IBM-client-architecture-CAS-reboot-support.patch new file mode 100644 index 0000000..4c12e5a --- /dev/null +++ b/0008-IBM-client-architecture-CAS-reboot-support.patch @@ -0,0 +1,172 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Thu, 20 Sep 2012 18:07:39 -0300 +Subject: [PATCH] IBM client architecture (CAS) reboot support + +This is an implementation of IBM client architecture (CAS) reboot for GRUB. + +There are cases where the POWER firmware must reboot in order to support +specific features requested by a kernel. The kernel calls +ibm,client-architecture-support and it may either return or reboot with the new +feature set. eg: + +Calling ibm,client-architecture-support.../ +Elapsed time since release of system processors: 70959 mins 50 secs +Welcome to GRUB! + +Instead of return to the GRUB menu, it will check if the flag for CAS reboot is +set. If so, grub will automatically boot the last booted kernel using the same +parameters +--- + grub-core/kern/ieee1275/openfw.c | 63 ++++++++++++++++++++++++++++++++++++++++ + grub-core/normal/main.c | 19 ++++++++++++ + grub-core/script/execute.c | 7 +++++ + include/grub/ieee1275/ieee1275.h | 2 ++ + 4 files changed, 91 insertions(+) + +diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c +index 4d493ab7661..3a6689abb11 100644 +--- a/grub-core/kern/ieee1275/openfw.c ++++ b/grub-core/kern/ieee1275/openfw.c +@@ -591,3 +591,66 @@ grub_ieee1275_get_boot_dev (void) + + return bootpath; + } ++ ++/* Check if it's a CAS reboot. If so, set the script to be executed. */ ++int ++grub_ieee1275_cas_reboot (char *script) ++{ ++ grub_uint32_t ibm_ca_support_reboot; ++ grub_uint32_t ibm_fw_nbr_reboots; ++ char property_value[10]; ++ grub_ssize_t actual; ++ grub_ieee1275_ihandle_t options; ++ ++ if (grub_ieee1275_finddevice ("/options", &options) < 0) ++ return -1; ++ ++ /* Check two properties, one is enough to get cas reboot value */ ++ ibm_ca_support_reboot = 0; ++ if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, ++ "ibm,client-architecture-support-reboot", ++ &ibm_ca_support_reboot, ++ sizeof (ibm_ca_support_reboot), ++ &actual) >= 0) ++ grub_dprintf("ieee1275", "ibm,client-architecture-support-reboot: %u\n", ++ ibm_ca_support_reboot); ++ ++ ibm_fw_nbr_reboots = 0; ++ if (grub_ieee1275_get_property (options, "ibm,fw-nbr-reboots", ++ property_value, sizeof (property_value), ++ &actual) >= 0) ++ { ++ property_value[sizeof (property_value) - 1] = 0; ++ ibm_fw_nbr_reboots = (grub_uint8_t) grub_strtoul (property_value, 0, 10); ++ grub_dprintf("ieee1275", "ibm,fw-nbr-reboots: %u\n", ibm_fw_nbr_reboots); ++ } ++ ++ if (ibm_ca_support_reboot || ibm_fw_nbr_reboots) ++ { ++ if (! grub_ieee1275_get_property_length (options, "boot-last-label", &actual)) ++ { ++ if (actual > 1024) ++ script = grub_realloc (script, actual + 1); ++ grub_ieee1275_get_property (options, "boot-last-label", script, actual, ++ &actual); ++ return 0; ++ } ++ } ++ ++ grub_ieee1275_set_boot_last_label (""); ++ ++ return -1; ++} ++ ++int grub_ieee1275_set_boot_last_label (const char *text) ++{ ++ grub_ieee1275_ihandle_t options; ++ grub_ssize_t actual; ++ ++ grub_dprintf("ieee1275", "set boot_last_label (size: %u)\n", grub_strlen(text)); ++ if (! grub_ieee1275_finddevice ("/options", &options) && ++ options != (grub_ieee1275_ihandle_t) -1) ++ grub_ieee1275_set_property (options, "boot-last-label", text, ++ grub_strlen (text), &actual); ++ return 0; ++} +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 1b03dfd57b9..222e239c1be 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -33,6 +33,9 @@ + #include + #include + #include ++#ifdef GRUB_MACHINE_IEEE1275 ++#include ++#endif + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -275,6 +278,22 @@ grub_normal_execute (const char *config, int nested, int batch) + { + menu = read_config_file (config); + ++#ifdef GRUB_MACHINE_IEEE1275 ++ int boot; ++ boot = 0; ++ char *script; ++ script = grub_malloc (1024); ++ if (! grub_ieee1275_cas_reboot (script)) ++ { ++ char *dummy[1] = { NULL }; ++ if (! grub_script_execute_sourcecode (script)) ++ boot = 1; ++ } ++ grub_free (script); ++ if (boot) ++ grub_command_execute ("boot", 0, 0); ++#endif ++ + /* Ignore any error. */ + grub_errno = GRUB_ERR_NONE; + } +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index ee299fd0ea6..0d05d6b0709 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -28,6 +28,9 @@ + #include + #include + #include ++#ifdef GRUB_MACHINE_IEEE1275 ++#include ++#endif + + /* Max digits for a char is 3 (0xFF is 255), similarly for an int it + is sizeof (int) * 3, and one extra for a possible -ve sign. */ +@@ -878,6 +881,10 @@ grub_script_execute_sourcecode (const char *source) + grub_err_t ret = 0; + struct grub_script *parsed_script; + ++#ifdef GRUB_MACHINE_IEEE1275 ++ grub_ieee1275_set_boot_last_label (source); ++#endif ++ + while (source) + { + char *line; +diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h +index 73e2f464475..0a599607f31 100644 +--- a/include/grub/ieee1275/ieee1275.h ++++ b/include/grub/ieee1275/ieee1275.h +@@ -254,6 +254,8 @@ int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *ali + void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias); + void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath, + struct grub_ieee1275_devalias *alias); ++int EXPORT_FUNC(grub_ieee1275_cas_reboot) (char *script); ++int EXPORT_FUNC(grub_ieee1275_set_boot_last_label) (const char *text); + + char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void); + diff --git a/0009-for-ppc-reset-console-display-attr-when-clear-screen.patch b/0009-for-ppc-reset-console-display-attr-when-clear-screen.patch new file mode 100644 index 0000000..ac67453 --- /dev/null +++ b/0009-for-ppc-reset-console-display-attr-when-clear-screen.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Wed, 24 Apr 2013 10:51:48 -0300 +Subject: [PATCH] for ppc, reset console display attr when clear screen + +v2: Also use \x0c instead of a literal ^L to make future patches less +awkward. + +This should fix this bugzilla: +https://bugzilla.redhat.com/show_bug.cgi?id=908519 + +Signed-off-by: Peter Jones +--- + grub-core/term/terminfo.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c +index d317efa368d..29df35e6d20 100644 +--- a/grub-core/term/terminfo.c ++++ b/grub-core/term/terminfo.c +@@ -151,7 +151,7 @@ grub_terminfo_set_current (struct grub_term_output *term, + /* Clear the screen. Using serial console, screen(1) only recognizes the + * ANSI escape sequence. Using video console, Apple Open Firmware + * (version 3.1.1) only recognizes the literal ^L. So use both. */ +- data->cls = grub_strdup (" \e[2J"); ++ data->cls = grub_strdup ("\x0c\e[2J\e[m"); + data->reverse_video_on = grub_strdup ("\e[7m"); + data->reverse_video_off = grub_strdup ("\e[m"); + if (grub_strcmp ("ieee1275", str) == 0) diff --git a/0010-Disable-GRUB-video-support-for-IBM-power-machines.patch b/0010-Disable-GRUB-video-support-for-IBM-power-machines.patch new file mode 100644 index 0000000..430f600 --- /dev/null +++ b/0010-Disable-GRUB-video-support-for-IBM-power-machines.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Tue, 11 Jun 2013 15:14:05 -0300 +Subject: [PATCH] Disable GRUB video support for IBM power machines + +Should fix the problem in bugzilla: +https://bugzilla.redhat.com/show_bug.cgi?id=973205 +--- + grub-core/kern/ieee1275/cmain.c | 5 ++++- + grub-core/video/ieee1275.c | 9 ++++++--- + include/grub/ieee1275/ieee1275.h | 2 ++ + 3 files changed, 12 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/ieee1275/cmain.c b/grub-core/kern/ieee1275/cmain.c +index 20cbbd761ec..04df9d2c667 100644 +--- a/grub-core/kern/ieee1275/cmain.c ++++ b/grub-core/kern/ieee1275/cmain.c +@@ -90,7 +90,10 @@ grub_ieee1275_find_options (void) + } + + if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0) +- grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS); ++ { ++ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS); ++ grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT); ++ } + + /* Old Macs have no key repeat, newer ones have fully working one. + The ones inbetween when repeated key generates an escaoe sequence +diff --git a/grub-core/video/ieee1275.c b/grub-core/video/ieee1275.c +index 17a3dbbb575..b8e4b3feb32 100644 +--- a/grub-core/video/ieee1275.c ++++ b/grub-core/video/ieee1275.c +@@ -352,9 +352,12 @@ static struct grub_video_adapter grub_video_ieee1275_adapter = + + GRUB_MOD_INIT(ieee1275_fb) + { +- find_display (); +- if (display) +- grub_video_register (&grub_video_ieee1275_adapter); ++ if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT)) ++ { ++ find_display (); ++ if (display) ++ grub_video_register (&grub_video_ieee1275_adapter); ++ } + } + + GRUB_MOD_FINI(ieee1275_fb) +diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h +index 0a599607f31..b5a1d49bbc3 100644 +--- a/include/grub/ieee1275/ieee1275.h ++++ b/include/grub/ieee1275/ieee1275.h +@@ -148,6 +148,8 @@ enum grub_ieee1275_flag + GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN, + + GRUB_IEEE1275_FLAG_RAW_DEVNAMES, ++ ++ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT + }; + + extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); diff --git a/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch b/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch new file mode 100644 index 0000000..2b953a6 --- /dev/null +++ b/0011-Honor-a-symlink-when-generating-configuration-by-gru.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Marcel Kolaja +Date: Tue, 21 Jan 2014 10:57:08 -0500 +Subject: [PATCH] Honor a symlink when generating configuration by + grub2-mkconfig + +Honor a symlink when generating configuration by grub2-mkconfig, so that +the -o option follows it rather than overwriting it with a regular file. +--- + util/grub-mkconfig.in | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 9f477ff0546..523d4e029bb 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -287,7 +287,8 @@ and /etc/grub.d/* files or please file a bug report with + exit 1 + else + # none of the children aborted with error, install the new grub.cfg +- mv -f ${grub_cfg}.new ${grub_cfg} ++ cat ${grub_cfg}.new > ${grub_cfg} ++ rm -f ${grub_cfg}.new + fi + fi + diff --git a/0012-Move-bash-completion-script-922997.patch b/0012-Move-bash-completion-script-922997.patch new file mode 100644 index 0000000..e3af586 --- /dev/null +++ b/0012-Move-bash-completion-script-922997.patch @@ -0,0 +1,52 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 3 Apr 2013 14:35:34 -0400 +Subject: [PATCH] Move bash completion script (#922997) + +Apparently these go in a new place now. +--- + configure.ac | 11 +++++++++++ + util/bash-completion.d/Makefile.am | 1 - + 2 files changed, 11 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 7656f2434e5..d283af64c8c 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -305,6 +305,14 @@ AC_SUBST(grubdirname) + AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname", + [Default grub directory name]) + ++PKG_PROG_PKG_CONFIG ++AS_IF([$($PKG_CONFIG --exists bash-completion)], [ ++ bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion) ++] , [ ++ bashcompletiondir=${datadir}/bash-completion/completions ++]) ++AC_SUBST(bashcompletiondir) ++ + # + # Checks for build programs. + # +@@ -516,6 +524,9 @@ HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags" + # Check for target programs. + # + ++# This makes sure pkg.m4 is available. ++m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config]) ++ + # Find tools for the target. + if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then + tmp_ac_tool_prefix="$ac_tool_prefix" +diff --git a/util/bash-completion.d/Makefile.am b/util/bash-completion.d/Makefile.am +index 136287cf1bf..61108f05429 100644 +--- a/util/bash-completion.d/Makefile.am ++++ b/util/bash-completion.d/Makefile.am +@@ -6,7 +6,6 @@ EXTRA_DIST = $(bash_completion_source) + + CLEANFILES = $(bash_completion_script) config.log + +-bashcompletiondir = $(sysconfdir)/bash_completion.d + bashcompletion_DATA = $(bash_completion_script) + + $(bash_completion_script): $(bash_completion_source) $(top_builddir)/config.status diff --git a/0013-Update-to-minilzo-2.08.patch b/0013-Update-to-minilzo-2.08.patch new file mode 100644 index 0000000..a71c501 --- /dev/null +++ b/0013-Update-to-minilzo-2.08.patch @@ -0,0 +1,8509 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Dec 2014 15:36:09 -0500 +Subject: [PATCH] Update to minilzo-2.08 + +This fixes CVE-2014-4607 - lzo: lzo1x_decompress_safe() integer overflow + +Signed-off-by: Peter Jones +--- + grub-core/lib/minilzo/minilzo.c | 3801 +++++++++++++++++++++++++++------------ + grub-core/lib/minilzo/lzoconf.h | 216 ++- + grub-core/lib/minilzo/lzodefs.h | 2320 ++++++++++++++++++------ + grub-core/lib/minilzo/minilzo.h | 21 +- + 4 files changed, 4489 insertions(+), 1869 deletions(-) + +diff --git a/grub-core/lib/minilzo/minilzo.c b/grub-core/lib/minilzo/minilzo.c +index 25a1f68b3b5..ab2be5f4fd0 100644 +--- a/grub-core/lib/minilzo/minilzo.c ++++ b/grub-core/lib/minilzo/minilzo.c +@@ -2,22 +2,7 @@ + + This file is part of the LZO real-time data compression library. + +- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer ++ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or +@@ -67,12 +52,6 @@ + #if defined(__CYGWIN32__) && !defined(__CYGWIN__) + # define __CYGWIN__ __CYGWIN32__ + #endif +-#if defined(__IBMCPP__) && !defined(__IBMC__) +-# define __IBMC__ __IBMCPP__ +-#endif +-#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +-# define __INTEL_COMPILER __ICL +-#endif + #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) + # define _ALL_SOURCE 1 + #endif +@@ -81,19 +60,30 @@ + # define __LONG_MAX__ 9223372036854775807L + # endif + #endif +-#if defined(__INTEL_COMPILER) && defined(__linux__) ++#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) ++#if defined(__ARMCC_VERSION) ++# pragma diag_suppress 193 ++#elif defined(__clang__) && defined(__clang_minor__) ++# pragma clang diagnostic ignored "-Wundef" ++#elif defined(__INTEL_COMPILER) + # pragma warning(disable: 193) +-#endif +-#if defined(__KEIL__) && defined(__C166__) ++#elif defined(__KEIL__) && defined(__C166__) + # pragma warning disable = 322 +-#elif 0 && defined(__C251__) +-# pragma warning disable = 322 +-#endif +-#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +-# if (_MSC_VER >= 1300) ++#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) ++# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) ++# pragma GCC diagnostic ignored "-Wundef" ++# endif ++#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) ++# if ((_MSC_VER-0) >= 1300) + # pragma warning(disable: 4668) + # endif + #endif ++#endif ++#if 0 && defined(__POCC__) && defined(_WIN32) ++# if (__POCC__ >= 400) ++# pragma warn(disable: 2216) ++# endif ++#endif + #if 0 && defined(__WATCOMC__) + # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) + # pragma warning 203 9 +@@ -102,13 +92,29 @@ + #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) + # pragma option -h + #endif ++#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) ++#ifndef _CRT_NONSTDC_NO_DEPRECATE ++#define _CRT_NONSTDC_NO_DEPRECATE 1 ++#endif ++#ifndef _CRT_NONSTDC_NO_WARNINGS ++#define _CRT_NONSTDC_NO_WARNINGS 1 ++#endif ++#ifndef _CRT_SECURE_NO_DEPRECATE ++#define _CRT_SECURE_NO_DEPRECATE 1 ++#endif ++#ifndef _CRT_SECURE_NO_WARNINGS ++#define _CRT_SECURE_NO_WARNINGS 1 ++#endif ++#endif + #if 0 +-#define LZO_0xffffL 0xfffful +-#define LZO_0xffffffffL 0xfffffffful ++#define LZO_0xffffUL 0xfffful ++#define LZO_0xffffffffUL 0xfffffffful + #else +-#define LZO_0xffffL 65535ul +-#define LZO_0xffffffffL 4294967295ul ++#define LZO_0xffffUL 65535ul ++#define LZO_0xffffffffUL 4294967295ul + #endif ++#define LZO_0xffffL LZO_0xffffUL ++#define LZO_0xffffffffL LZO_0xffffffffUL + #if (LZO_0xffffL == LZO_0xffffffffL) + # error "your preprocessor is broken 1" + #endif +@@ -123,6 +129,13 @@ + # error "your preprocessor is broken 4" + #endif + #endif ++#if defined(__COUNTER__) ++# ifndef LZO_CFG_USE_COUNTER ++# define LZO_CFG_USE_COUNTER 1 ++# endif ++#else ++# undef LZO_CFG_USE_COUNTER ++#endif + #if (UINT_MAX == LZO_0xffffL) + #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) + # if !defined(MSDOS) +@@ -253,14 +266,31 @@ + #endif + #define LZO_PP_STRINGIZE(x) #x + #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) ++#define LZO_PP_CONCAT0() /*empty*/ ++#define LZO_PP_CONCAT1(a) a + #define LZO_PP_CONCAT2(a,b) a ## b + #define LZO_PP_CONCAT3(a,b,c) a ## b ## c + #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d + #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f ++#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g ++#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() ++#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) + #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) + #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) + #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) + #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) ++#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) ++#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) ++#define LZO_PP_EMPTY /*empty*/ ++#define LZO_PP_EMPTY0() /*empty*/ ++#define LZO_PP_EMPTY1(a) /*empty*/ ++#define LZO_PP_EMPTY2(a,b) /*empty*/ ++#define LZO_PP_EMPTY3(a,b,c) /*empty*/ ++#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ ++#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ ++#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ ++#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ + #if 1 + #define LZO_CPP_STRINGIZE(x) #x + #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +@@ -268,12 +298,16 @@ + #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c + #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d + #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f ++#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g + #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) + #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) + #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) + #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) ++#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) ++#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) + #endif +-#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) ++#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) + #if 1 && defined(__cplusplus) + # if !defined(__STDC_CONSTANT_MACROS) + # define __STDC_CONSTANT_MACROS 1 +@@ -283,9 +317,13 @@ + # endif + #endif + #if defined(__cplusplus) +-# define LZO_EXTERN_C extern "C" ++# define LZO_EXTERN_C extern "C" ++# define LZO_EXTERN_C_BEGIN extern "C" { ++# define LZO_EXTERN_C_END } + #else +-# define LZO_EXTERN_C extern ++# define LZO_EXTERN_C extern ++# define LZO_EXTERN_C_BEGIN /*empty*/ ++# define LZO_EXTERN_C_END /*empty*/ + #endif + #if !defined(__LZO_OS_OVERRIDE) + #if (LZO_OS_FREESTANDING) +@@ -386,12 +424,12 @@ + #elif defined(__VMS) + # define LZO_OS_VMS 1 + # define LZO_INFO_OS "vms" +-#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) + # define LZO_OS_CONSOLE 1 + # define LZO_OS_CONSOLE_PS2 1 + # define LZO_INFO_OS "console" + # define LZO_INFO_OS_CONSOLE "ps2" +-#elif (defined(__mips__) && defined(__psp__)) ++#elif defined(__mips__) && defined(__psp__) + # define LZO_OS_CONSOLE 1 + # define LZO_OS_CONSOLE_PSP 1 + # define LZO_INFO_OS "console" +@@ -419,9 +457,18 @@ + # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) + # define LZO_OS_POSIX_LINUX 1 + # define LZO_INFO_OS_POSIX "linux" +-# elif defined(__APPLE__) || defined(__MACOS__) +-# define LZO_OS_POSIX_MACOSX 1 +-# define LZO_INFO_OS_POSIX "macosx" ++# elif defined(__APPLE__) && defined(__MACH__) ++# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) ++# define LZO_OS_POSIX_DARWIN 1040 ++# define LZO_INFO_OS_POSIX "darwin_iphone" ++# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) ++# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ ++# define LZO_INFO_OS_POSIX "darwin" ++# else ++# define LZO_OS_POSIX_DARWIN 1 ++# define LZO_INFO_OS_POSIX "darwin" ++# endif ++# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN + # elif defined(__minix__) || defined(__minix) + # define LZO_OS_POSIX_MINIX 1 + # define LZO_INFO_OS_POSIX "minix" +@@ -456,18 +503,18 @@ + #endif + #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + # if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) + # if (UINT_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +@@ -483,59 +530,65 @@ + # define LZO_INFO_CC "sdcc" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) + #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +-# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) ++# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) + # define LZO_INFO_CC "Pathscale C" + # define LZO_INFO_CCVER __PATHSCALE__ +-#elif defined(__INTEL_COMPILER) +-# define LZO_CC_INTELC 1 ++# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# endif ++#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) ++# define LZO_CC_INTELC __INTEL_COMPILER + # define LZO_INFO_CC "Intel C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +-# if defined(_WIN32) || defined(_WIN64) +-# define LZO_CC_SYNTAX_MSC 1 +-# else +-# define LZO_CC_SYNTAX_GNUC 1 ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_INTELC_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # endif + #elif defined(__POCC__) && defined(_WIN32) + # define LZO_CC_PELLESC 1 + # define LZO_INFO_CC "Pelles C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +-#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) + # if defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # else +-# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) + # endif ++# define LZO_CC_ARMCC __ARMCC_VERSION ++# define LZO_INFO_CC "ARM C Compiler" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) + # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) +-# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) ++# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) + # else +-# define LZO_CC_CLANG_CLANG 0x010000L ++# define LZO_CC_CLANG 0x010000L ++# endif ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_CLANG_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # endif +-# define LZO_CC_CLANG LZO_CC_CLANG_GNUC + # define LZO_INFO_CC "clang" + # define LZO_INFO_CCVER __VERSION__ + #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) + # if defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # else +-# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) + # endif + # define LZO_CC_LLVM LZO_CC_LLVM_GNUC + # define LZO_INFO_CC "llvm-gcc" + # define LZO_INFO_CCVER __VERSION__ +-#elif defined(__GNUC__) && defined(__VERSION__) +-# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +-# elif defined(__GNUC_MINOR__) +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +-# else +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +-# endif +-# define LZO_INFO_CC "gcc" +-# define LZO_INFO_CCVER __VERSION__ + #elif defined(__ACK__) && defined(_ACK) + # define LZO_CC_ACK 1 + # define LZO_INFO_CC "Amsterdam Compiler Kit C" + # define LZO_INFO_CCVER "unknown" ++#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) ++# define LZO_CC_ARMCC __ARMCC_VERSION ++# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION ++# define LZO_INFO_CC "ARM C Compiler" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) + #elif defined(__AZTEC_C__) + # define LZO_CC_AZTECC 1 + # define LZO_INFO_CC "Aztec C" +@@ -560,10 +613,23 @@ + # define LZO_CC_DECC 1 + # define LZO_INFO_CC "DEC C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) ++#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) ++# define LZO_CC_GHS 1 ++# define LZO_INFO_CC "Green Hills C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_GHS_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# endif + #elif defined(__HIGHC__) + # define LZO_CC_HIGHC 1 + # define LZO_INFO_CC "MetaWare High C" + # define LZO_INFO_CCVER "unknown" ++#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) ++# define LZO_CC_HPACC __HP_aCC ++# define LZO_INFO_CC "HP aCC" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) + #elif defined(__IAR_SYSTEMS_ICC__) + # define LZO_CC_IARC 1 + # define LZO_INFO_CC "IAR C" +@@ -572,10 +638,14 @@ + # else + # define LZO_INFO_CCVER "unknown" + # endif +-#elif defined(__IBMC__) +-# define LZO_CC_IBMC 1 ++#elif defined(__IBMC__) && ((__IBMC__-0) > 0) ++# define LZO_CC_IBMC __IBMC__ + # define LZO_INFO_CC "IBM C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) ++#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) ++# define LZO_CC_IBMC __IBMCPP__ ++# define LZO_INFO_CC "IBM C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) + #elif defined(__KEIL__) && defined(__C166__) + # define LZO_CC_KEILC 1 + # define LZO_INFO_CC "Keil C" +@@ -592,16 +662,8 @@ + # else + # define LZO_INFO_CCVER "unknown" + # endif +-#elif defined(_MSC_VER) +-# define LZO_CC_MSC 1 +-# define LZO_INFO_CC "Microsoft C" +-# if defined(_MSC_FULL_VER) +-# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +-# else +-# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +-# endif +-#elif defined(__MWERKS__) +-# define LZO_CC_MWERKS 1 ++#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) ++# define LZO_CC_MWERKS __MWERKS__ + # define LZO_INFO_CC "Metrowerks C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) + #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +@@ -612,6 +674,15 @@ + # define LZO_CC_PACIFICC 1 + # define LZO_INFO_CC "Pacific C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) ++#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) ++# if defined(__PGIC_PATCHLEVEL__) ++# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) ++# else ++# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" ++# endif ++# define LZO_INFO_CC "Portland Group PGI C" + #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) + # define LZO_CC_PGI 1 + # define LZO_INFO_CC "Portland Group PGI C" +@@ -626,7 +697,7 @@ + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) + #elif defined(__SUNPRO_C) + # define LZO_INFO_CC "SunPro C" +-# if ((__SUNPRO_C)+0 > 0) ++# if ((__SUNPRO_C-0) > 0) + # define LZO_CC_SUNPROC __SUNPRO_C + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) + # else +@@ -635,7 +706,7 @@ + # endif + #elif defined(__SUNPRO_CC) + # define LZO_INFO_CC "SunPro C" +-# if ((__SUNPRO_CC)+0 > 0) ++# if ((__SUNPRO_CC-0) > 0) + # define LZO_CC_SUNPROC __SUNPRO_CC + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) + # else +@@ -661,16 +732,46 @@ + #elif defined(__ZTC__) + # define LZO_CC_ZORTECHC 1 + # define LZO_INFO_CC "Zortech C" +-# if (__ZTC__ == 0x310) ++# if ((__ZTC__-0) == 0x310) + # define LZO_INFO_CCVER "0x310" + # else + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) + # endif ++#elif defined(__GNUC__) && defined(__VERSION__) ++# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# elif defined(__GNUC_MINOR__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) ++# else ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L) ++# endif ++# define LZO_INFO_CC "gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_MSC _MSC_VER ++# define LZO_INFO_CC "Microsoft C" ++# if defined(_MSC_FULL_VER) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) ++# endif + #else + # define LZO_CC_UNKNOWN 1 + # define LZO_INFO_CC "unknown" + # define LZO_INFO_CCVER "unknown" + #endif ++#if (LZO_CC_GNUC) && defined(__OPEN64__) ++# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) ++# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) ++# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC ++# endif ++#endif ++#if (LZO_CC_GNUC) && defined(__PCC__) ++# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) ++# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) ++# define LZO_CC_PCC_GNUC LZO_CC_GNUC ++# endif ++#endif + #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) + # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" + #endif +@@ -688,8 +789,10 @@ + # define LZO_INFO_ARCH "generic" + #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + # define LZO_ARCH_I086 1 +-# define LZO_ARCH_IA16 1 + # define LZO_INFO_ARCH "i086" ++#elif defined(__aarch64__) ++# define LZO_ARCH_ARM64 1 ++# define LZO_INFO_ARCH "arm64" + #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) + # define LZO_ARCH_ALPHA 1 + # define LZO_INFO_ARCH "alpha" +@@ -705,10 +808,10 @@ + # define LZO_INFO_ARCH "arm_thumb" + #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) + # define LZO_ARCH_ARM 1 +-# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) ++# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) + # define LZO_ARCH_ARM_THUMB 1 + # define LZO_INFO_ARCH "arm_thumb" +-# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) ++# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) + # define LZO_INFO_ARCH "arm" + # else + # define LZO_INFO_ARCH "arm" +@@ -826,53 +929,147 @@ + # error "FIXME - missing define for CPU architecture" + #endif + #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +-# error "FIXME - missing WIN32 define for CPU architecture" ++# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" + #endif + #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +-# error "FIXME - missing WIN64 define for CPU architecture" ++# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" + #endif + #if (LZO_OS_OS216 || LZO_OS_WIN16) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #endif +-#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +-# error "this should not happen" ++#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) ++# define LZO_ARCH_X64 1 ++#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_AMD64 1 + #endif +-#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +-# error "this should not happen" ++#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) ++# define LZO_ARCH_AARCH64 1 ++#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_ARM64 1 ++#endif ++#if (LZO_ARCH_I386 && !LZO_ARCH_X86) ++# define LZO_ARCH_X86 1 ++#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_I386 1 ++#endif ++#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) ++# error "unexpected configuration - check your compiler defines" + #endif + #if (LZO_ARCH_I086) + # if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if (LZO_ARCH_I386) + # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif +-#if !defined(__LZO_MM_OVERRIDE) ++#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++# if !defined(LZO_TARGET_FEATURE_SSE2) ++# if defined(__SSE2__) ++# define LZO_TARGET_FEATURE_SSE2 1 ++# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) ++# define LZO_TARGET_FEATURE_SSE2 1 ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_SSSE3) ++# if (LZO_TARGET_FEATURE_SSE2) ++# if defined(__SSSE3__) ++# define LZO_TARGET_FEATURE_SSSE3 1 ++# elif defined(_MSC_VER) && defined(__AVX__) ++# define LZO_TARGET_FEATURE_SSSE3 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_SSE4_2) ++# if (LZO_TARGET_FEATURE_SSSE3) ++# if defined(__SSE4_2__) ++# define LZO_TARGET_FEATURE_SSE4_2 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_AVX) ++# if (LZO_TARGET_FEATURE_SSSE3) ++# if defined(__AVX__) ++# define LZO_TARGET_FEATURE_AVX 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_AVX2) ++# if (LZO_TARGET_FEATURE_AVX) ++# if defined(__AVX2__) ++# define LZO_TARGET_FEATURE_AVX2 1 ++# endif ++# endif ++# endif ++#endif ++#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM) ++# if !defined(LZO_TARGET_FEATURE_NEON) ++# if defined(__ARM_NEON__) ++# define LZO_TARGET_FEATURE_NEON 1 ++# endif ++# endif ++#elif (LZO_ARCH_ARM64) ++# if !defined(LZO_TARGET_FEATURE_NEON) ++# if 1 ++# define LZO_TARGET_FEATURE_NEON 1 ++# endif ++# endif ++#endif ++#if 0 ++#elif !defined(__LZO_MM_OVERRIDE) + #if (LZO_ARCH_I086) + #if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + #endif + #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) + # define LZO_MM_TINY 1 +@@ -899,7 +1096,7 @@ + #elif (LZO_CC_ZORTECHC && defined(__VCM__)) + # define LZO_MM_LARGE 1 + #else +-# error "unknown memory model" ++# error "unknown LZO_ARCH_I086 memory model" + #endif + #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + #define LZO_HAVE_MM_HUGE_PTR 1 +@@ -922,10 +1119,10 @@ + #endif + #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) + # if (LZO_OS_DOS16) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # elif (LZO_CC_ZORTECHC) + # else +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #ifdef __cplusplus +@@ -957,7 +1154,7 @@ extern "C" { + #endif + #elif (LZO_ARCH_C166) + #if !defined(__MODEL__) +-# error "FIXME - C166 __MODEL__" ++# error "FIXME - LZO_ARCH_C166 __MODEL__" + #elif ((__MODEL__) == 0) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 1) +@@ -971,11 +1168,11 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - C166 __MODEL__" ++# error "FIXME - LZO_ARCH_C166 __MODEL__" + #endif + #elif (LZO_ARCH_MCS251) + #if !defined(__MODEL__) +-# error "FIXME - MCS251 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS251 __MODEL__" + #elif ((__MODEL__) == 0) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 2) +@@ -987,11 +1184,11 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - MCS251 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS251 __MODEL__" + #endif + #elif (LZO_ARCH_MCS51) + #if !defined(__MODEL__) +-# error "FIXME - MCS51 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS51 __MODEL__" + #elif ((__MODEL__) == 1) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 2) +@@ -1003,7 +1200,7 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - MCS51 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS51 __MODEL__" + #endif + #elif (LZO_ARCH_CRAY_PVP) + # define LZO_MM_PVP 1 +@@ -1030,35 +1227,818 @@ extern "C" { + # error "unknown memory model" + #endif + #endif ++#if !defined(__lzo_gnuc_extension__) ++#if (LZO_CC_GNUC >= 0x020800ul) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_gnuc_extension__ __extension__ ++#else ++#endif ++#endif ++#if !defined(__lzo_gnuc_extension__) ++# define __lzo_gnuc_extension__ /*empty*/ ++#endif ++#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 ++# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++# else ++# define LZO_CFG_USE_NEW_STYLE_CASTS 1 ++# endif ++#endif ++#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++#endif ++#if !defined(__cplusplus) ++# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) ++# undef LZO_CFG_USE_NEW_STYLE_CASTS ++# endif ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++#endif ++#if !defined(LZO_REINTERPRET_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) ++# endif ++#endif ++#if !defined(LZO_REINTERPRET_CAST) ++# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) ++#endif ++#if !defined(LZO_STATIC_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_STATIC_CAST(t,e) (static_cast (e)) ++# endif ++#endif ++#if !defined(LZO_STATIC_CAST) ++# define LZO_STATIC_CAST(t,e) ((t) (e)) ++#endif ++#if !defined(LZO_STATIC_CAST2) ++# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNCONST_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNCONST_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) ++#endif ++#if !defined(LZO_UNCONST_VOLATILE_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNCONST_VOLATILE_CAST) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) ++#endif ++#if !defined(LZO_UNVOLATILE_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNVOLATILE_CAST) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) ++#endif ++#if !defined(LZO_UNVOLATILE_CONST_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNVOLATILE_CONST_CAST) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) ++#endif ++#if !defined(LZO_PCAST) ++# if (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_PCAST(t,e) ((t) (e)) ++# endif ++#endif ++#if !defined(LZO_PCAST) ++# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) ++#endif ++#if !defined(LZO_CCAST) ++# if (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_CCAST(t,e) ((t) (e)) ++# endif ++#endif ++#if !defined(LZO_CCAST) ++# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) ++#endif ++#if !defined(LZO_ICONV) ++# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(LZO_ICAST) ++# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(LZO_ITRUNC) ++# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(__lzo_cte) ++# if (LZO_CC_MSC || LZO_CC_WATCOMC) ++# define __lzo_cte(e) ((void)0,(e)) ++# elif 1 ++# define __lzo_cte(e) ((void)0,(e)) ++# endif ++#endif ++#if !defined(__lzo_cte) ++# define __lzo_cte(e) (e) ++#endif ++#if !defined(LZO_BLOCK_BEGIN) ++# define LZO_BLOCK_BEGIN do { ++# define LZO_BLOCK_END } while __lzo_cte(0) ++#endif ++#if !defined(LZO_UNUSED) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNUSED(var) ((void) var) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_KEILC) ++# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} ++# elif (LZO_CC_PACIFICC) ++# define LZO_UNUSED(var) ((void) sizeof(var)) ++# elif (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED(var) ((void) var) ++# else ++# define LZO_UNUSED(var) ((void) &var) ++# endif ++#endif ++#if !defined(LZO_UNUSED_FUNC) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_MSC) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_KEILC || LZO_CC_PELLESC) ++# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} ++# else ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# endif ++#endif ++#if !defined(LZO_UNUSED_LABEL) ++# if (LZO_CC_CLANG >= 0x020800ul) ++# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) ++# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) ++# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l ++# else ++# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l ++# endif ++#endif ++#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) ++# if 0 ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var ++# elif 0 && (LZO_CC_GNUC) ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var ++# else ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init ++# endif ++#endif ++#if !defined(__lzo_inline) ++#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) ++#elif defined(__cplusplus) ++# define __lzo_inline inline ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) ++# define __lzo_inline inline ++#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) ++# define __lzo_inline __inline ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_DMC) ++# define __lzo_inline __inline ++#elif (LZO_CC_GHS) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_INTELC) ++# define __lzo_inline __inline ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) ++# define __lzo_inline __inline ++#elif (LZO_CC_MSC && (_MSC_VER >= 900)) ++# define __lzo_inline __inline ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_inline __inline__ ++#endif ++#endif ++#if defined(__lzo_inline) ++# ifndef __lzo_HAVE_inline ++# define __lzo_HAVE_inline 1 ++# endif ++#else ++# define __lzo_inline /*empty*/ ++#endif ++#if !defined(__lzo_forceinline) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#endif ++#endif ++#if defined(__lzo_forceinline) ++# ifndef __lzo_HAVE_forceinline ++# define __lzo_HAVE_forceinline 1 ++# endif ++#else ++# define __lzo_forceinline __lzo_inline ++#endif ++#if !defined(__lzo_noinline) ++#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) ++# define __lzo_noinline __attribute__((__noinline__,__used__)) ++#elif (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) ++# if defined(__cplusplus) ++# else ++# define __lzo_noinline __declspec(noinline) ++# endif ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_noinline __attribute__((__noinline__)) ++#endif ++#endif ++#if defined(__lzo_noinline) ++# ifndef __lzo_HAVE_noinline ++# define __lzo_HAVE_noinline 1 ++# endif ++#else ++# define __lzo_noinline /*empty*/ ++#endif ++#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if !defined(__lzo_static_inline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline ++#endif ++#endif ++#if !defined(__lzo_static_inline) ++# define __lzo_static_inline static __lzo_inline ++#endif ++#if !defined(__lzo_static_forceinline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline ++#endif ++#endif ++#if !defined(__lzo_static_forceinline) ++# define __lzo_static_forceinline static __lzo_forceinline ++#endif ++#if !defined(__lzo_static_noinline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline ++#endif ++#endif ++#if !defined(__lzo_static_noinline) ++# define __lzo_static_noinline static __lzo_noinline ++#endif ++#if !defined(__lzo_c99_extern_inline) ++#if defined(__GNUC_GNU_INLINE__) ++# define __lzo_c99_extern_inline __lzo_inline ++#elif defined(__GNUC_STDC_INLINE__) ++# define __lzo_c99_extern_inline extern __lzo_inline ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) ++# define __lzo_c99_extern_inline extern __lzo_inline ++#endif ++#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) ++# define __lzo_c99_extern_inline __lzo_inline ++#endif ++#endif ++#if defined(__lzo_c99_extern_inline) ++# ifndef __lzo_HAVE_c99_extern_inline ++# define __lzo_HAVE_c99_extern_inline 1 ++# endif ++#else ++# define __lzo_c99_extern_inline /*empty*/ ++#endif ++#if !defined(__lzo_may_alias) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_CLANG >= 0x020900ul) ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#endif ++#endif ++#if defined(__lzo_may_alias) ++# ifndef __lzo_HAVE_may_alias ++# define __lzo_HAVE_may_alias 1 ++# endif ++#else ++# define __lzo_may_alias /*empty*/ ++#endif ++#if !defined(__lzo_noreturn) ++#if (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#endif ++#endif ++#if defined(__lzo_noreturn) ++# ifndef __lzo_HAVE_noreturn ++# define __lzo_HAVE_noreturn 1 ++# endif ++#else ++# define __lzo_noreturn /*empty*/ ++#endif ++#if !defined(__lzo_nothrow) ++#if (LZO_CC_GNUC >= 0x030300ul) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#endif ++#endif ++#if defined(__lzo_nothrow) ++# ifndef __lzo_HAVE_nothrow ++# define __lzo_HAVE_nothrow 1 ++# endif ++#else ++# define __lzo_nothrow /*empty*/ ++#endif ++#if !defined(__lzo_restrict) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_IBMC >= 1210) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define __lzo_restrict __restrict ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_restrict __restrict__ ++#endif ++#endif ++#if defined(__lzo_restrict) ++# ifndef __lzo_HAVE_restrict ++# define __lzo_HAVE_restrict 1 ++# endif ++#else ++# define __lzo_restrict /*empty*/ ++#endif ++#if !defined(__lzo_alignof) ++#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_GHS) && !defined(__cplusplus) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_alignof(e) __alignof(e) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_alignof(e) __alignof__(e) ++#endif ++#endif ++#if defined(__lzo_alignof) ++# ifndef __lzo_HAVE_alignof ++# define __lzo_HAVE_alignof 1 ++# endif ++#endif ++#if !defined(__lzo_struct_packed) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) ++#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++# define __lzo_struct_packed(s) struct s { ++# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_struct_packed(s) struct s { ++# define __lzo_struct_packed_end() } __attribute__((__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { ++# define __lzo_struct_packed_end() } __attribute__((__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { ++# define __lzo_struct_packed_end() } __pragma(pack(pop)); ++#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) ++# define __lzo_struct_packed(s) _Packed struct s { ++# define __lzo_struct_packed_end() }; ++#endif ++#endif ++#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) ++# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) ++#endif ++#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) ++# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() ++#endif ++#if !defined(__lzo_byte_struct) ++#if defined(__lzo_struct_packed) ++# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() ++# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() ++#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); ++# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); ++#endif ++#endif ++#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) ++# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) ++#endif ++#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) ++#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) ++#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_CILLY || LZO_CC_PCC) ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_struct_align16(s) struct __declspec(align(16)) s { ++# define __lzo_struct_align16_end() }; ++# define __lzo_struct_align32(s) struct __declspec(align(32)) s { ++# define __lzo_struct_align32_end() }; ++# define __lzo_struct_align64(s) struct __declspec(align(64)) s { ++# define __lzo_struct_align64_end() }; ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_struct_align16(s) struct s { ++# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); ++# define __lzo_struct_align32(s) struct s { ++# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); ++# define __lzo_struct_align64(s) struct s { ++# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); ++#endif ++#endif ++#if !defined(__lzo_union_um) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) ++#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_union_am(s) union s { ++# define __lzo_union_am_end() } __lzo_may_alias; ++# define __lzo_union_um(s) union s { ++# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { ++# define __lzo_union_am_end() } __lzo_may_alias; ++# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { ++# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_union_um(s) __pragma(pack(push,1)) union s { ++# define __lzo_union_um_end() } __pragma(pack(pop)); ++#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) ++# define __lzo_union_um(s) _Packed union s { ++# define __lzo_union_um_end() }; ++#endif ++#endif ++#if !defined(__lzo_union_am) ++# define __lzo_union_am(s) union s { ++# define __lzo_union_am_end() }; ++#endif ++#if !defined(__lzo_constructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_constructor __attribute__((__constructor__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_constructor __attribute__((__constructor__)) ++#endif ++#endif ++#if defined(__lzo_constructor) ++# ifndef __lzo_HAVE_constructor ++# define __lzo_HAVE_constructor 1 ++# endif ++#endif ++#if !defined(__lzo_destructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_destructor __attribute__((__destructor__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_destructor __attribute__((__destructor__)) ++#endif ++#endif ++#if defined(__lzo_destructor) ++# ifndef __lzo_HAVE_destructor ++# define __lzo_HAVE_destructor 1 ++# endif ++#endif ++#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if !defined(__lzo_likely) && !defined(__lzo_unlikely) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_IBMC >= 1010) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#endif ++#endif ++#if defined(__lzo_likely) ++# ifndef __lzo_HAVE_likely ++# define __lzo_HAVE_likely 1 ++# endif ++#else ++# define __lzo_likely(e) (e) ++#endif ++#if defined(__lzo_unlikely) ++# ifndef __lzo_HAVE_unlikely ++# define __lzo_HAVE_unlikely 1 ++# endif ++#else ++# define __lzo_unlikely(e) (e) ++#endif ++#if !defined(__lzo_static_unused_void_func) ++# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) ++# else ++# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) ++# endif ++#endif ++#if !defined(__lzo_loop_forever) ++# if (LZO_CC_IBMC) ++# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END ++# else ++# define __lzo_loop_forever() do { ; } while __lzo_cte(1) ++# endif ++#endif ++#if !defined(__lzo_unreachable) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) ++# define __lzo_unreachable() __builtin_unreachable(); ++#elif (LZO_CC_GNUC >= 0x040500ul) ++# define __lzo_unreachable() __builtin_unreachable(); ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 ++# define __lzo_unreachable() __builtin_unreachable(); ++#endif ++#endif ++#if defined(__lzo_unreachable) ++# ifndef __lzo_HAVE_unreachable ++# define __lzo_HAVE_unreachable 1 ++# endif ++#else ++# if 0 ++# define __lzo_unreachable() ((void)0); ++# else ++# define __lzo_unreachable() __lzo_loop_forever(); ++# endif ++#endif ++#ifndef __LZO_CTA_NAME ++#if (LZO_CFG_USE_COUNTER) ++# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) ++#else ++# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) ++#endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) ++# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END ++# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END ++# else ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT) ++# if (LZO_CC_AZTECC) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} ++# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) ++# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} ++# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) ++# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} ++# elif (LZO_CC_GNUC >= 0x040700ul) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# else ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} ++# endif ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) ++#if defined(__cplusplus) ++extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) ++#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit /*empty*/ ++# define __lzo_cdecl_main __cdecl ++# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_qsort __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_qsort _stdcall ++# else ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# elif (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++# else ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit __cdecl ++# define __lzo_cdecl_main __cdecl ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) ++# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_sighandler __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_sighandler _stdcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) ++# define __lzo_cdecl_sighandler __clrcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) ++# if defined(_DLL) ++# define __lzo_cdecl_sighandler _far _cdecl _loadds ++# elif defined(_MT) ++# define __lzo_cdecl_sighandler _far _cdecl ++# else ++# define __lzo_cdecl_sighandler _cdecl ++# endif ++# else ++# define __lzo_cdecl_sighandler __cdecl ++# endif ++#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) ++# define __lzo_cdecl cdecl ++#endif ++#if !defined(__lzo_cdecl) ++# define __lzo_cdecl /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_atexit) ++# define __lzo_cdecl_atexit /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_main) ++# define __lzo_cdecl_main /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_qsort) ++# define __lzo_cdecl_qsort /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_sighandler) ++# define __lzo_cdecl_sighandler /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_va) ++# define __lzo_cdecl_va __lzo_cdecl ++#endif ++#if !(LZO_CFG_NO_WINDOWS_H) ++#if !defined(LZO_HAVE_WINDOWS_H) ++#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) ++# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) ++# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) ++# else ++# define LZO_HAVE_WINDOWS_H 1 ++# endif ++#endif ++#endif ++#endif ++#ifndef LZO_SIZEOF_SHORT + #if defined(SIZEOF_SHORT) + # define LZO_SIZEOF_SHORT (SIZEOF_SHORT) ++#elif defined(__SIZEOF_SHORT__) ++# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) + #endif ++#endif ++#ifndef LZO_SIZEOF_INT + #if defined(SIZEOF_INT) + # define LZO_SIZEOF_INT (SIZEOF_INT) ++#elif defined(__SIZEOF_INT__) ++# define LZO_SIZEOF_INT (__SIZEOF_INT__) + #endif ++#endif ++#ifndef LZO_SIZEOF_LONG + #if defined(SIZEOF_LONG) + # define LZO_SIZEOF_LONG (SIZEOF_LONG) ++#elif defined(__SIZEOF_LONG__) ++# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) + #endif ++#endif ++#ifndef LZO_SIZEOF_LONG_LONG + #if defined(SIZEOF_LONG_LONG) + # define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) ++#elif defined(__SIZEOF_LONG_LONG__) ++# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT16 + #if defined(SIZEOF___INT16) + # define LZO_SIZEOF___INT16 (SIZEOF___INT16) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT32 + #if defined(SIZEOF___INT32) + # define LZO_SIZEOF___INT32 (SIZEOF___INT32) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT64 + #if defined(SIZEOF___INT64) + # define LZO_SIZEOF___INT64 (SIZEOF___INT64) + #endif ++#endif ++#ifndef LZO_SIZEOF_VOID_P + #if defined(SIZEOF_VOID_P) + # define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) ++#elif defined(__SIZEOF_POINTER__) ++# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) + #endif ++#endif ++#ifndef LZO_SIZEOF_SIZE_T + #if defined(SIZEOF_SIZE_T) + # define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) ++#elif defined(__SIZEOF_SIZE_T__) ++# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) + #endif ++#endif ++#ifndef LZO_SIZEOF_PTRDIFF_T + #if defined(SIZEOF_PTRDIFF_T) + # define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) ++#elif defined(__SIZEOF_PTRDIFF_T__) ++# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) ++#endif + #endif + #define __LZO_LSR(x,b) (((x)+0ul) >> (b)) + #if !defined(LZO_SIZEOF_SHORT) +@@ -1080,6 +2060,7 @@ extern "C" { + # error "LZO_SIZEOF_SHORT" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) + #if !defined(LZO_SIZEOF_INT) + # if (LZO_ARCH_CRAY_PVP) + # define LZO_SIZEOF_INT 8 +@@ -1101,6 +2082,7 @@ extern "C" { + # error "LZO_SIZEOF_INT" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) + #if !defined(LZO_SIZEOF_LONG) + # if (ULONG_MAX == LZO_0xffffffffL) + # define LZO_SIZEOF_LONG 4 +@@ -1110,6 +2092,8 @@ extern "C" { + # define LZO_SIZEOF_LONG 2 + # elif (__LZO_LSR(ULONG_MAX,31) == 1) + # define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,39) == 1) ++# define LZO_SIZEOF_LONG 5 + # elif (__LZO_LSR(ULONG_MAX,63) == 1) + # define LZO_SIZEOF_LONG 8 + # elif (__LZO_LSR(ULONG_MAX,127) == 1) +@@ -1118,11 +2102,12 @@ extern "C" { + # error "LZO_SIZEOF_LONG" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) + #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) + #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) + # if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) + # if (LZO_CC_GNUC >= 0x030300ul) +-# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) ++# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) + # define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG + # elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) + # define LZO_SIZEOF_LONG_LONG 4 +@@ -1136,7 +2121,7 @@ extern "C" { + #if (LZO_ARCH_I086 && LZO_CC_DMC) + #elif (LZO_CC_CILLY) && defined(__GNUC__) + # define LZO_SIZEOF_LONG_LONG 8 +-#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) + # define LZO_SIZEOF_LONG_LONG 8 + #elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) + # define LZO_SIZEOF_LONG_LONG 8 +@@ -1158,11 +2143,13 @@ extern "C" { + # define LZO_SIZEOF___INT64 8 + #elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) + # define LZO_SIZEOF___INT64 8 +-#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) ++#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) + # define LZO_SIZEOF___INT64 8 + #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) + # define LZO_SIZEOF_LONG_LONG 8 +-#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) + # define LZO_SIZEOF_LONG_LONG 8 + #elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) + #elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +@@ -1175,87 +2162,127 @@ extern "C" { + # undef LZO_SIZEOF_LONG_LONG + # endif + #endif +-#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) ++#if (LZO_CFG_NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#elif defined(__NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#elif defined(_NO_LONGLONG) + # undef LZO_SIZEOF_LONG_LONG + #endif +-#if !defined(LZO_SIZEOF_VOID_P) +-#if (LZO_ARCH_I086) +-# define __LZO_WORDSIZE 2 +-# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +-# define LZO_SIZEOF_VOID_P 2 +-# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +-# define LZO_SIZEOF_VOID_P 4 ++#if !defined(LZO_WORDSIZE) ++#if (LZO_ARCH_ALPHA) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_AMD64) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_AVR) ++# define LZO_WORDSIZE 1 ++#elif (LZO_ARCH_H8300) ++# if defined(__NORMAL_MODE__) ++# define LZO_WORDSIZE 4 ++# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define LZO_WORDSIZE 4 + # else +-# error "LZO_MM" ++# define LZO_WORDSIZE 2 + # endif +-#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +-# define __LZO_WORDSIZE 1 ++#elif (LZO_ARCH_I086) ++# define LZO_WORDSIZE 2 ++#elif (LZO_ARCH_IA64) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_M16C) ++# define LZO_WORDSIZE 2 ++#elif (LZO_ARCH_SPU) ++# define LZO_WORDSIZE 4 ++#elif (LZO_ARCH_Z80) ++# define LZO_WORDSIZE 1 ++#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define LZO_WORDSIZE 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) ++# define LZO_WORDSIZE 8 ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_WORDSIZE 8 ++#endif ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) ++# define LZO_SIZEOF_VOID_P 4 ++#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) ++# define LZO_SIZEOF_VOID_P 8 ++#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) ++# define LZO_SIZEOF_VOID_P 8 ++#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) ++# define LZO_SIZEOF_VOID_P 8 ++#elif (LZO_ARCH_AVR) + # define LZO_SIZEOF_VOID_P 2 + #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) + # define LZO_SIZEOF_VOID_P 2 + #elif (LZO_ARCH_H8300) + # if defined(__NORMAL_MODE__) +-# define __LZO_WORDSIZE 4 + # define LZO_SIZEOF_VOID_P 2 + # elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +-# define __LZO_WORDSIZE 4 + # define LZO_SIZEOF_VOID_P 4 + # else +-# define __LZO_WORDSIZE 2 + # define LZO_SIZEOF_VOID_P 2 + # endif + # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) + # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT + # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT + # endif ++#elif (LZO_ARCH_I086) ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) ++# define LZO_SIZEOF_VOID_P 2 ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# error "invalid LZO_ARCH_I086 memory model" ++# endif + #elif (LZO_ARCH_M16C) +-# define __LZO_WORDSIZE 2 + # if defined(__m32c_cpu__) || defined(__m32cm_cpu__) + # define LZO_SIZEOF_VOID_P 4 + # else + # define LZO_SIZEOF_VOID_P 2 + # endif ++#elif (LZO_ARCH_SPU) ++# define LZO_SIZEOF_VOID_P 4 ++#elif (LZO_ARCH_Z80) ++# define LZO_SIZEOF_VOID_P 2 + #elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +-# define __LZO_WORDSIZE 8 + # define LZO_SIZEOF_VOID_P 4 +-#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +-# define __LZO_WORDSIZE 8 +-# define LZO_SIZEOF_VOID_P 8 +-#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +-# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + #elif (LZO_OS_OS400 || defined(__OS400__)) +-# define __LZO_WORDSIZE LZO_SIZEOF_LONG +-# define LZO_SIZEOF_VOID_P 16 +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +-#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +-# define LZO_SIZEOF_VOID_P 8 +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +-#elif (LZO_ARCH_SPU) +-# if 0 +-# define __LZO_WORDSIZE 16 +-# endif +-# define LZO_SIZEOF_VOID_P 4 +-#else +-# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +-#endif +-#endif +-#if !defined(LZO_WORDSIZE) +-# if defined(__LZO_WORDSIZE) +-# define LZO_WORDSIZE __LZO_WORDSIZE ++# if defined(__LLP64_IFC__) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + # else +-# define LZO_WORDSIZE LZO_SIZEOF_VOID_P ++# define LZO_SIZEOF_VOID_P 16 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + # endif ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + #endif ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) + #if !defined(LZO_SIZEOF_SIZE_T) + #if (LZO_ARCH_I086 || LZO_ARCH_M16C) + # define LZO_SIZEOF_SIZE_T 2 +-#else ++#endif ++#endif ++#if !defined(LZO_SIZEOF_SIZE_T) + # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P + #endif ++#if defined(offsetof) ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) + #endif + #if !defined(LZO_SIZEOF_PTRDIFF_T) + #if (LZO_ARCH_I086) +@@ -1268,11 +2295,18 @@ extern "C" { + # define LZO_SIZEOF_PTRDIFF_T 2 + # endif + # else +-# error "LZO_MM" ++# error "invalid LZO_ARCH_I086 memory model" + # endif +-#else ++#endif ++#endif ++#if !defined(LZO_SIZEOF_PTRDIFF_T) + # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T + #endif ++#if defined(offsetof) ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) ++#endif ++#if !defined(LZO_WORDSIZE) ++# define LZO_WORDSIZE LZO_SIZEOF_VOID_P + #endif + #if (LZO_ABI_NEUTRAL_ENDIAN) + # undef LZO_ABI_BIG_ENDIAN +@@ -1284,7 +2318,7 @@ extern "C" { + # define LZO_ABI_LITTLE_ENDIAN 1 + #elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) + # define LZO_ABI_LITTLE_ENDIAN 1 +-#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) ++#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) + # if (__LITTLE_ENDIAN__ == 1) +@@ -1300,6 +2334,19 @@ extern "C" { + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) + # define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) ++# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) ++# error "unexpected configuration - check your compiler defines" ++# elif defined(__BIG_ENDIAN) ++# define LZO_ABI_BIG_ENDIAN 1 ++# else ++# define LZO_ABI_LITTLE_ENDIAN 1 ++# endif ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 + #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +@@ -1307,7 +2354,7 @@ extern "C" { + #endif + #endif + #if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + #endif + #if (LZO_ABI_BIG_ENDIAN) + # define LZO_INFO_ABI_ENDIAN "be" +@@ -1322,6 +2369,9 @@ extern "C" { + #elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) + # define LZO_ABI_ILP16 1 + # define LZO_INFO_ABI_PM "ilp16" ++#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_LP32 1 ++# define LZO_INFO_ABI_PM "lp32" + #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) + # define LZO_ABI_ILP32 1 + # define LZO_INFO_ABI_PM "ilp32" +@@ -1338,7 +2388,8 @@ extern "C" { + # define LZO_ABI_IP32L64 1 + # define LZO_INFO_ABI_PM "ip32l64" + #endif +-#if !defined(__LZO_LIBC_OVERRIDE) ++#if 0 ++#elif !defined(__LZO_LIBC_OVERRIDE) + #if (LZO_LIBC_NAKED) + # define LZO_INFO_LIBC "naked" + #elif (LZO_LIBC_FREESTANDING) +@@ -1349,6 +2400,9 @@ extern "C" { + # define LZO_INFO_LIBC "isoc90" + #elif (LZO_LIBC_ISOC99) + # define LZO_INFO_LIBC "isoc99" ++#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) ++# define LZO_LIBC_ISOC90 1 ++# define LZO_INFO_LIBC "isoc90" + #elif defined(__dietlibc__) + # define LZO_LIBC_DIETLIBC 1 + # define LZO_INFO_LIBC "dietlibc" +@@ -1357,13 +2411,13 @@ extern "C" { + # define LZO_INFO_LIBC "newlib" + #elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) + # if defined(__UCLIBC_SUBLEVEL__) +-# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) ++# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) + # else + # define LZO_LIBC_UCLIBC 0x00090bL + # endif +-# define LZO_INFO_LIBC "uclibc" ++# define LZO_INFO_LIBC "uc" "libc" + #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +-# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) ++# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) + # define LZO_INFO_LIBC "glibc" + #elif (LZO_CC_MWERKS) && defined(__MSL__) + # define LZO_LIBC_MSL __MSL__ +@@ -1376,423 +2430,159 @@ extern "C" { + # define LZO_INFO_LIBC "default" + #endif + #endif +-#if !defined(__lzo_gnuc_extension__) +-#if (LZO_CC_GNUC >= 0x020800ul) +-# define __lzo_gnuc_extension__ __extension__ +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_gnuc_extension__ __extension__ +-#else +-# define __lzo_gnuc_extension__ /*empty*/ +-#endif +-#endif +-#if !defined(__lzo_ua_volatile) +-# define __lzo_ua_volatile volatile +-#endif +-#if !defined(__lzo_alignof) +-#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +-# define __lzo_alignof(e) __alignof__(e) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +-# define __lzo_alignof(e) __alignof__(e) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +-# define __lzo_alignof(e) __alignof(e) +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_alignof(e) __alignof__(e) +-#endif +-#endif +-#if defined(__lzo_alignof) +-# define __lzo_HAVE_alignof 1 +-#endif +-#if !defined(__lzo_constructor) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_constructor __attribute__((__constructor__,__used__)) +-#elif (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_constructor __attribute__((__constructor__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_constructor __attribute__((__constructor__)) +-#endif +-#endif +-#if defined(__lzo_constructor) +-# define __lzo_HAVE_constructor 1 +-#endif +-#if !defined(__lzo_destructor) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_destructor __attribute__((__destructor__,__used__)) +-#elif (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_destructor __attribute__((__destructor__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_destructor __attribute__((__destructor__)) +-#endif +-#endif +-#if defined(__lzo_destructor) +-# define __lzo_HAVE_destructor 1 +-#endif +-#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +-# error "this should not happen" +-#endif +-#if !defined(__lzo_inline) +-#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +-#elif defined(__cplusplus) +-# define __lzo_inline inline +-#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +-# define __lzo_inline __inline +-#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +-# define __lzo_inline __inline__ +-#elif (LZO_CC_DMC) +-# define __lzo_inline __inline +-#elif (LZO_CC_INTELC) +-# define __lzo_inline __inline +-#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +-# define __lzo_inline __inline +-#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +-# define __lzo_inline __inline +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_inline __inline__ +-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +-# define __lzo_inline inline +-#endif +-#endif +-#if defined(__lzo_inline) +-# define __lzo_HAVE_inline 1 +-#else +-# define __lzo_inline /*empty*/ +-#endif +-#if !defined(__lzo_forceinline) +-#if (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +-# define __lzo_forceinline __forceinline +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +-# define __lzo_forceinline __forceinline +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#endif +-#endif +-#if defined(__lzo_forceinline) +-# define __lzo_HAVE_forceinline 1 +-#else +-# define __lzo_forceinline /*empty*/ +-#endif +-#if !defined(__lzo_noinline) +-#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +-# define __lzo_noinline __attribute__((__noinline__,__used__)) +-#elif (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +-# define __lzo_noinline __declspec(noinline) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +-# define __lzo_noinline __declspec(noinline) +-#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +-# if defined(__cplusplus) +-# else +-# define __lzo_noinline __declspec(noinline) +-# endif +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_noinline __attribute__((__noinline__)) +-#endif +-#endif +-#if defined(__lzo_noinline) +-# define __lzo_HAVE_noinline 1 +-#else +-# define __lzo_noinline /*empty*/ +-#endif +-#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +-# error "this should not happen" +-#endif +-#if !defined(__lzo_noreturn) +-#if (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +-# define __lzo_noreturn __declspec(noreturn) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +-# define __lzo_noreturn __declspec(noreturn) +-#endif +-#endif +-#if defined(__lzo_noreturn) +-# define __lzo_HAVE_noreturn 1 +-#else +-# define __lzo_noreturn /*empty*/ +-#endif +-#if !defined(__lzo_nothrow) +-#if (LZO_CC_GNUC >= 0x030300ul) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +-# define __lzo_nothrow __declspec(nothrow) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +-# define __lzo_nothrow __declspec(nothrow) +-#endif +-#endif +-#if defined(__lzo_nothrow) +-# define __lzo_HAVE_nothrow 1 +-#else +-# define __lzo_nothrow /*empty*/ +-#endif +-#if !defined(__lzo_restrict) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_CLANG || LZO_CC_LLVM) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +-# define __lzo_restrict __restrict +-#endif +-#endif +-#if defined(__lzo_restrict) +-# define __lzo_HAVE_restrict 1 +-#else +-# define __lzo_restrict /*empty*/ +-#endif +-#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +-#if (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#endif +-#endif +-#if defined(__lzo_likely) +-# define __lzo_HAVE_likely 1 +-#else +-# define __lzo_likely(e) (e) +-#endif +-#if defined(__lzo_unlikely) +-# define __lzo_HAVE_unlikely 1 +-#else +-# define __lzo_unlikely(e) (e) +-#endif +-#if !defined(LZO_UNUSED) +-# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +-# define LZO_UNUSED(var) ((void) &var) +-# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +-# define LZO_UNUSED(var) if (&var) ; else +-# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define LZO_UNUSED(var) ((void) var) +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_UNUSED(var) if (&var) ; else +-# elif (LZO_CC_KEILC) +-# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +-# elif (LZO_CC_PACIFICC) +-# define LZO_UNUSED(var) ((void) sizeof(var)) +-# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +-# define LZO_UNUSED(var) ((void) var) +-# else +-# define LZO_UNUSED(var) ((void) &var) +-# endif +-#endif +-#if !defined(LZO_UNUSED_FUNC) +-# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +-# define LZO_UNUSED_FUNC(func) ((void) func) +-# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +-# define LZO_UNUSED_FUNC(func) if (func) ; else +-# elif (LZO_CC_CLANG || LZO_CC_LLVM) +-# define LZO_UNUSED_FUNC(func) ((void) &func) +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_UNUSED_FUNC(func) if (func) ; else +-# elif (LZO_CC_MSC) +-# define LZO_UNUSED_FUNC(func) ((void) &func) +-# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +-# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +-# else +-# define LZO_UNUSED_FUNC(func) ((void) func) +-# endif +-#endif +-#if !defined(LZO_UNUSED_LABEL) +-# if (LZO_CC_WATCOMC) && defined(__cplusplus) +-# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +-# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +-# define LZO_UNUSED_LABEL(l) if (0) goto l +-# else +-# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +-# endif +-#endif +-#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +-# if 0 +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +-# elif 0 && (LZO_CC_GNUC) +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +-# else +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +-# endif +-#endif +-#if !defined(LZO_UNCONST_CAST) +-# if 0 && defined(__cplusplus) +-# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +-# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +-# else +-# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +-# endif +-#endif +-#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +-# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +-# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +-# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +-# else +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +-# endif +-#endif +-#if !defined(LZO_COMPILE_TIME_ASSERT) +-# if (LZO_CC_AZTECC) +-# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +-# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# else +-# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +-# endif +-#endif +-#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +-# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +-# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +-# define __lzo_cdecl __cdecl +-# define __lzo_cdecl_atexit /*empty*/ +-# define __lzo_cdecl_main __cdecl +-# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +-# define __lzo_cdecl_qsort __pascal +-# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +-# define __lzo_cdecl_qsort _stdcall +-# else +-# define __lzo_cdecl_qsort __cdecl +-# endif +-# elif (LZO_CC_WATCOMC) +-# define __lzo_cdecl __cdecl +-# else +-# define __lzo_cdecl __cdecl +-# define __lzo_cdecl_atexit __cdecl +-# define __lzo_cdecl_main __cdecl +-# define __lzo_cdecl_qsort __cdecl +-# endif +-# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +-# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +-# define __lzo_cdecl_sighandler __pascal +-# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +-# define __lzo_cdecl_sighandler _stdcall +-# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +-# define __lzo_cdecl_sighandler __clrcall +-# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +-# if defined(_DLL) +-# define __lzo_cdecl_sighandler _far _cdecl _loadds +-# elif defined(_MT) +-# define __lzo_cdecl_sighandler _far _cdecl +-# else +-# define __lzo_cdecl_sighandler _cdecl +-# endif +-# else +-# define __lzo_cdecl_sighandler __cdecl +-# endif +-#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +-# define __lzo_cdecl __cdecl +-#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +-# define __lzo_cdecl cdecl +-#endif +-#if !defined(__lzo_cdecl) +-# define __lzo_cdecl /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_atexit) +-# define __lzo_cdecl_atexit /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_main) +-# define __lzo_cdecl_main /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_qsort) +-# define __lzo_cdecl_qsort /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_sighandler) +-# define __lzo_cdecl_sighandler /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_va) +-# define __lzo_cdecl_va __lzo_cdecl +-#endif +-#if !(LZO_CFG_NO_WINDOWS_H) +-#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +-# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +-# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +-# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +-# else +-# define LZO_HAVE_WINDOWS_H 1 +-# endif ++#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++# define LZO_ASM_SYNTAX_MSC 1 ++#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) ++#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_CC_GNUC) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#endif ++#if (LZO_ASM_SYNTAX_GNUC) ++#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) ++# define __LZO_ASM_CLOBBER "ax" ++# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) ++# define __LZO_ASM_CLOBBER "memory" ++# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ ++#else ++# define __LZO_ASM_CLOBBER "cc", "memory" ++# define __LZO_ASM_CLOBBER_LIST_CC : "cc" ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ + #endif + #endif + #if (LZO_ARCH_ALPHA) +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_AVOID_SHORT 1 +-# define LZO_OPT_AVOID_USHORT 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 + #elif (LZO_ARCH_AMD64) +-# define LZO_OPT_AVOID_INT_INDEX 1 +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 +-# define LZO_OPT_UNALIGNED64 1 +-#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + #elif (LZO_ARCH_ARM) +-# define LZO_OPT_AVOID_SHORT 1 +-# define LZO_OPT_AVOID_USHORT 1 ++# if defined(__ARM_FEATURE_UNALIGNED) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# endif ++#elif (LZO_ARCH_ARM64) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + #elif (LZO_ARCH_CRIS) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + #elif (LZO_ARCH_I386) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + #elif (LZO_ARCH_IA64) +-# define LZO_OPT_AVOID_INT_INDEX 1 +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_PREFER_POSTINC 1 + #elif (LZO_ARCH_M68K) +-# define LZO_OPT_PREFER_POSTINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + # if defined(__mc68020__) && !defined(__mcoldfire__) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + # endif + #elif (LZO_ARCH_MIPS) +-# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 + #elif (LZO_ARCH_POWERPC) +-# define LZO_OPT_PREFER_PREINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_PREINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + # if (LZO_ABI_BIG_ENDIAN) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# if (LZO_WORDSIZE == 8) ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif ++# endif + # endif + #elif (LZO_ARCH_S390) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 +-# if (LZO_SIZEOF_SIZE_T == 8) +-# define LZO_OPT_UNALIGNED64 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# if (LZO_WORDSIZE == 8) ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + # endif + #elif (LZO_ARCH_SH) +-# define LZO_OPT_PREFER_POSTINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + #endif + #ifndef LZO_CFG_NO_INLINE_ASM +-#if (LZO_CC_LLVM) ++#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) + # define LZO_CFG_NO_INLINE_ASM 1 ++#elif (LZO_CC_LLVM) ++# define LZO_CFG_NO_INLINE_ASM 1 ++#endif + #endif ++#if (LZO_CFG_NO_INLINE_ASM) ++# undef LZO_ASM_SYNTAX_MSC ++# undef LZO_ASM_SYNTAX_GNUC ++# undef __LZO_ASM_CLOBBER ++# undef __LZO_ASM_CLOBBER_LIST_CC ++# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY ++# undef __LZO_ASM_CLOBBER_LIST_EMPTY + #endif + #ifndef LZO_CFG_NO_UNALIGNED + #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) +@@ -1804,25 +2594,6 @@ extern "C" { + # undef LZO_OPT_UNALIGNED32 + # undef LZO_OPT_UNALIGNED64 + #endif +-#if (LZO_CFG_NO_INLINE_ASM) +-#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +-# define LZO_ASM_SYNTAX_MSC 1 +-#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +-#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +-#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +-# define LZO_ASM_SYNTAX_GNUC 1 +-#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +-# define LZO_ASM_SYNTAX_GNUC 1 +-#endif +-#if (LZO_ASM_SYNTAX_GNUC) +-#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +-# define __LZO_ASM_CLOBBER "ax" +-#elif (LZO_CC_INTELC) +-# define __LZO_ASM_CLOBBER "memory" +-#else +-# define __LZO_ASM_CLOBBER "cc", "memory" +-#endif +-#endif + #if defined(__LZO_INFOSTR_MM) + #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) + # define __LZO_INFOSTR_MM "" +@@ -1866,6 +2637,381 @@ extern "C" { + #define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER ++#if !(LZO_CFG_SKIP_LZO_TYPES) ++#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) ++# error "missing defines for sizes" ++#endif ++#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) ++# error "missing defines for sizes" ++#endif ++#if !defined(lzo_llong_t) ++#if (LZO_SIZEOF_LONG_LONG+0 > 0) ++__lzo_gnuc_extension__ typedef long long lzo_llong_t__; ++__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; ++# define lzo_llong_t lzo_llong_t__ ++# define lzo_ullong_t lzo_ullong_t__ ++#endif ++#endif ++#if !defined(lzo_int16e_t) ++#if (LZO_SIZEOF_LONG == 2) ++# define lzo_int16e_t long ++# define lzo_uint16e_t unsigned long ++#elif (LZO_SIZEOF_INT == 2) ++# define lzo_int16e_t int ++# define lzo_uint16e_t unsigned int ++#elif (LZO_SIZEOF_SHORT == 2) ++# define lzo_int16e_t short int ++# define lzo_uint16e_t unsigned short int ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) ++ typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); ++ typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); ++# define lzo_int16e_t lzo_int16e_hi_t__ ++# define lzo_uint16e_t lzo_uint16e_hi_t__ ++#elif (LZO_SIZEOF___INT16 == 2) ++# define lzo_int16e_t __int16 ++# define lzo_uint16e_t unsigned __int16 ++#else ++#endif ++#endif ++#if defined(lzo_int16e_t) ++# define LZO_SIZEOF_LZO_INT16E_T 2 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) ++#endif ++#if !defined(lzo_int32e_t) ++#if (LZO_SIZEOF_LONG == 4) ++# define lzo_int32e_t long int ++# define lzo_uint32e_t unsigned long int ++#elif (LZO_SIZEOF_INT == 4) ++# define lzo_int32e_t int ++# define lzo_uint32e_t unsigned int ++#elif (LZO_SIZEOF_SHORT == 4) ++# define lzo_int32e_t short int ++# define lzo_uint32e_t unsigned short int ++#elif (LZO_SIZEOF_LONG_LONG == 4) ++# define lzo_int32e_t lzo_llong_t ++# define lzo_uint32e_t lzo_ullong_t ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) ++ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); ++ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); ++# define lzo_int32e_t lzo_int32e_si_t__ ++# define lzo_uint32e_t lzo_uint32e_si_t__ ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) ++ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); ++ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); ++# define lzo_int32e_t lzo_int32e_si_t__ ++# define lzo_uint32e_t lzo_uint32e_si_t__ ++# define LZO_INT32_C(c) (c##LL) ++# define LZO_UINT32_C(c) (c##ULL) ++#elif (LZO_SIZEOF___INT32 == 4) ++# define lzo_int32e_t __int32 ++# define lzo_uint32e_t unsigned __int32 ++#else ++#endif ++#endif ++#if defined(lzo_int32e_t) ++# define LZO_SIZEOF_LZO_INT32E_T 4 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) ++#endif ++#if !defined(lzo_int64e_t) ++#if (LZO_SIZEOF___INT64 == 8) ++# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) ++# define LZO_CFG_TYPE_PREFER___INT64 1 ++# endif ++#endif ++#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_int64e_t int ++# define lzo_uint64e_t unsigned int ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG == 8) ++# define lzo_int64e_t long int ++# define lzo_uint64e_t unsigned long int ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG ++#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) ++# define lzo_int64e_t lzo_llong_t ++# define lzo_uint64e_t lzo_ullong_t ++# if (LZO_CC_BORLANDC) ++# define LZO_INT64_C(c) ((c) + 0ll) ++# define LZO_UINT64_C(c) ((c) + 0ull) ++# elif 0 ++# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) ++# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) ++# else ++# define LZO_INT64_C(c) (c##LL) ++# define LZO_UINT64_C(c) (c##ULL) ++# endif ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG ++#elif (LZO_SIZEOF___INT64 == 8) ++# define lzo_int64e_t __int64 ++# define lzo_uint64e_t unsigned __int64 ++# if (LZO_CC_BORLANDC) ++# define LZO_INT64_C(c) ((c) + 0i64) ++# define LZO_UINT64_C(c) ((c) + 0ui64) ++# else ++# define LZO_INT64_C(c) (c##i64) ++# define LZO_UINT64_C(c) (c##ui64) ++# endif ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 ++#else ++#endif ++#endif ++#if defined(lzo_int64e_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) ++#endif ++#if !defined(lzo_int32l_t) ++#if defined(lzo_int32e_t) ++# define lzo_int32l_t lzo_int32e_t ++# define lzo_uint32l_t lzo_uint32e_t ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T ++#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_int32l_t int ++# define lzo_uint32l_t unsigned int ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG >= 4) ++# define lzo_int32l_t long int ++# define lzo_uint32l_t unsigned long int ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG ++#else ++# error "lzo_int32l_t" ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) ++#endif ++#if !defined(lzo_int64l_t) ++#if defined(lzo_int64e_t) ++# define lzo_int64l_t lzo_int64e_t ++# define lzo_uint64l_t lzo_uint64e_t ++# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T ++#else ++#endif ++#endif ++#if defined(lzo_int64l_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) ++#endif ++#if !defined(lzo_int32f_t) ++#if (LZO_SIZEOF_SIZE_T >= 8) ++# define lzo_int32f_t lzo_int64l_t ++# define lzo_uint32f_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T ++#else ++# define lzo_int32f_t lzo_int32l_t ++# define lzo_uint32f_t lzo_uint32l_t ++# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) ++#endif ++#if !defined(lzo_int64f_t) ++#if defined(lzo_int64l_t) ++# define lzo_int64f_t lzo_int64l_t ++# define lzo_uint64f_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T ++#else ++#endif ++#endif ++#if defined(lzo_int64f_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) ++#endif ++#if !defined(lzo_intptr_t) ++#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) ++# define __LZO_INTPTR_T_IS_POINTER 1 ++ typedef char* lzo_intptr_t; ++ typedef char* lzo_uintptr_t; ++# define lzo_intptr_t lzo_intptr_t ++# define lzo_uintptr_t lzo_uintptr_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) ++ typedef __w64 int lzo_intptr_t; ++ typedef __w64 unsigned int lzo_uintptr_t; ++# define lzo_intptr_t lzo_intptr_t ++# define lzo_uintptr_t lzo_uintptr_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t short ++# define lzo_uintptr_t unsigned short ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT ++#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_intptr_t int ++# define lzo_uintptr_t unsigned int ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t long ++# define lzo_uintptr_t unsigned long ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG ++#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t lzo_int64l_t ++# define lzo_uintptr_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T ++#else ++# error "lzo_intptr_t" ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) ++#endif ++#if !defined(lzo_word_t) ++#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) ++#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) ++# define lzo_word_t lzo_uintptr_t ++# define lzo_sword_t lzo_intptr_t ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T ++#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) ++# define lzo_word_t unsigned long ++# define lzo_sword_t long ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG ++#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) ++# define lzo_word_t unsigned int ++# define lzo_sword_t int ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT ++#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) ++# define lzo_word_t unsigned short ++# define lzo_sword_t short ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT ++#elif (LZO_WORDSIZE == 1) ++# define lzo_word_t unsigned char ++# define lzo_sword_t signed char ++# define LZO_SIZEOF_LZO_WORD_T 1 ++#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) ++# define lzo_word_t lzo_uint64l_t ++# define lzo_sword_t lzo_int64l_t ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T ++#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) ++#if 0 ++ typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); ++ typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); ++# define lzo_word_t lzo_word_t ++# define lzo_sword_t lzo_sword_t ++# define LZO_SIZEOF_LZO_WORD_T 16 ++#endif ++#else ++# error "lzo_word_t" ++#endif ++#endif ++#endif ++#if 1 && defined(lzo_word_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) ++#endif ++#if 1 ++#define lzo_int8_t signed char ++#define lzo_uint8_t unsigned char ++#define LZO_SIZEOF_LZO_INT8_T 1 ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) ++#endif ++#if defined(lzo_int16e_t) ++#define lzo_int16_t lzo_int16e_t ++#define lzo_uint16_t lzo_uint16e_t ++#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) ++#endif ++#if defined(lzo_int32e_t) ++#define lzo_int32_t lzo_int32e_t ++#define lzo_uint32_t lzo_uint32e_t ++#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) ++#endif ++#if defined(lzo_int64e_t) ++#define lzo_int64_t lzo_int64e_t ++#define lzo_uint64_t lzo_uint64e_t ++#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) ++#endif ++#if 1 ++#define lzo_int_least32_t lzo_int32l_t ++#define lzo_uint_least32_t lzo_uint32l_t ++#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) ++#endif ++#if defined(lzo_int64l_t) ++#define lzo_int_least64_t lzo_int64l_t ++#define lzo_uint_least64_t lzo_uint64l_t ++#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) ++#endif ++#if 1 ++#define lzo_int_fast32_t lzo_int32f_t ++#define lzo_uint_fast32_t lzo_uint32f_t ++#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) ++#endif ++#if defined(lzo_int64f_t) ++#define lzo_int_fast64_t lzo_int64f_t ++#define lzo_uint_fast64_t lzo_uint64f_t ++#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) ++#endif ++#if !defined(LZO_INT16_C) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) ++# define LZO_INT16_C(c) ((c) + 0) ++# define LZO_UINT16_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) ++# define LZO_INT16_C(c) ((c) + 0L) ++# define LZO_UINT16_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 2) ++# define LZO_INT16_C(c) (c) ++# define LZO_UINT16_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 2) ++# define LZO_INT16_C(c) (c##L) ++# define LZO_UINT16_C(c) (c##UL) ++# else ++# error "LZO_INT16_C" ++# endif ++#endif ++#if !defined(LZO_INT32_C) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) ++# define LZO_INT32_C(c) ((c) + 0) ++# define LZO_UINT32_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) ++# define LZO_INT32_C(c) ((c) + 0L) ++# define LZO_UINT32_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 4) ++# define LZO_INT32_C(c) (c) ++# define LZO_UINT32_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 4) ++# define LZO_INT32_C(c) (c##L) ++# define LZO_UINT32_C(c) (c##UL) ++# elif (LZO_SIZEOF_LONG_LONG >= 4) ++# define LZO_INT32_C(c) (c##LL) ++# define LZO_UINT32_C(c) (c##ULL) ++# else ++# error "LZO_INT32_C" ++# endif ++#endif ++#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) ++# define LZO_INT64_C(c) ((c) + 0) ++# define LZO_UINT64_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) ++# define LZO_INT64_C(c) ((c) + 0L) ++# define LZO_UINT64_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 8) ++# define LZO_INT64_C(c) (c) ++# define LZO_UINT64_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 8) ++# define LZO_INT64_C(c) (c##L) ++# define LZO_UINT64_C(c) (c##UL) ++# else ++# error "LZO_INT64_C" ++# endif ++#endif ++#endif + + #endif + +@@ -1874,7 +3020,7 @@ extern "C" { + #undef LZO_HAVE_CONFIG_H + #include "minilzo.h" + +-#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050) ++#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2080) + # error "version mismatch in miniLZO source files" + #endif + +@@ -1886,23 +3032,9 @@ extern "C" { + #define __LZO_CONF_H 1 + + #if !defined(__LZO_IN_MINILZO) +-#if (LZO_CFG_FREESTANDING) ++#if defined(LZO_CFG_FREESTANDING) && (LZO_CFG_FREESTANDING) + # define LZO_LIBC_FREESTANDING 1 + # define LZO_OS_FREESTANDING 1 +-# define ACC_LIBC_FREESTANDING 1 +-# define ACC_OS_FREESTANDING 1 +-#endif +-#if (LZO_CFG_NO_UNALIGNED) +-# define ACC_CFG_NO_UNALIGNED 1 +-#endif +-#if (LZO_ARCH_GENERIC) +-# define ACC_ARCH_GENERIC 1 +-#endif +-#if (LZO_ABI_NEUTRAL_ENDIAN) +-# define ACC_ABI_NEUTRAL_ENDIAN 1 +-#endif +-#if (LZO_HAVE_CONFIG_H) +-# define ACC_CONFIG_NO_HEADER 1 + #endif + #if defined(LZO_CFG_EXTRA_CONFIG_HEADER) + # include LZO_CFG_EXTRA_CONFIG_HEADER +@@ -1911,22 +3043,27 @@ extern "C" { + # error "include this file first" + #endif + #include "lzo/lzoconf.h" ++#if defined(LZO_CFG_EXTRA_CONFIG_HEADER2) ++# include LZO_CFG_EXTRA_CONFIG_HEADER2 ++#endif + #endif + +-#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) ++#if (LZO_VERSION < 0x2080) || !defined(__LZOCONF_H_INCLUDED) + # error "version mismatch" + #endif + +-#if (LZO_CC_BORLANDC && LZO_ARCH_I086) +-# pragma option -h ++#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1100)) ++# pragma warning(disable: 4702) + #endif +- + #if (LZO_CC_MSC && (_MSC_VER >= 1000)) + # pragma warning(disable: 4127 4701) ++# pragma warning(disable: 4514 4710 4711) + #endif + #if (LZO_CC_MSC && (_MSC_VER >= 1300)) + # pragma warning(disable: 4820) +-# pragma warning(disable: 4514 4710 4711) ++#endif ++#if (LZO_CC_MSC && (_MSC_VER >= 1800)) ++# pragma warning(disable: 4746) + #endif + + #if (LZO_CC_SUNPROC) +@@ -1937,49 +3074,16 @@ extern "C" { + #endif + #endif + +-#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) +-# error "this should not happen - check defines for __huge" +-#endif +- +-#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) +-#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) +-# define ACC_WANT_ACC_INCD_H 1 +-# define ACC_WANT_ACC_INCE_H 1 +-# define ACC_WANT_ACC_INCI_H 1 ++#if defined(__LZO_IN_MINILZO) || (LZO_CFG_FREESTANDING) + #elif 1 + # include + #else +-# define ACC_WANT_ACC_INCD_H 1 ++# define LZO_WANT_ACC_INCD_H 1 + #endif +- +-#if (LZO_ARCH_I086) +-# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT +-# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) +-# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) +-# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) ++#if defined(LZO_HAVE_CONFIG_H) ++# define LZO_CFG_NO_CONFIG_HEADER 1 + #endif + +-#if !defined(lzo_uintptr_t) +-# if defined(__LZO_MMODEL_HUGE) +-# define lzo_uintptr_t unsigned long +-# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) +-# define __LZO_UINTPTR_T_IS_POINTER 1 +- typedef char* lzo_uintptr_t; +-# define lzo_uintptr_t lzo_uintptr_t +-# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) +-# define lzo_uintptr_t size_t +-# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) +-# define lzo_uintptr_t unsigned long +-# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) +-# define lzo_uintptr_t unsigned int +-# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) +-# define lzo_uintptr_t unsigned long long +-# else +-# define lzo_uintptr_t size_t +-# endif +-#endif +-LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) +- + #if 1 && !defined(LZO_CFG_FREESTANDING) + #if 1 && !defined(HAVE_STRING_H) + #define HAVE_STRING_H 1 +@@ -2002,6 +3106,23 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + #include + #endif + ++#if 1 || defined(lzo_int8_t) || defined(lzo_uint8_t) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint8_t) == 1) ++#endif ++#if 1 || defined(lzo_int16_t) || defined(lzo_uint16_t) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint16_t) == 2) ++#endif ++#if 1 || defined(lzo_int32_t) || defined(lzo_uint32_t) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32_t) == 4) ++#endif ++#if defined(lzo_int64_t) || defined(lzo_uint64_t) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) ++#endif ++ + #if (LZO_CFG_FREESTANDING) + # undef HAVE_MEMCMP + # undef HAVE_MEMCPY +@@ -2012,28 +3133,28 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + #if !(HAVE_MEMCMP) + # undef memcmp + # define memcmp(a,b,c) lzo_memcmp(a,b,c) +-#elif !(__LZO_MMODEL_HUGE) ++#else + # undef lzo_memcmp + # define lzo_memcmp(a,b,c) memcmp(a,b,c) + #endif + #if !(HAVE_MEMCPY) + # undef memcpy + # define memcpy(a,b,c) lzo_memcpy(a,b,c) +-#elif !(__LZO_MMODEL_HUGE) ++#else + # undef lzo_memcpy + # define lzo_memcpy(a,b,c) memcpy(a,b,c) + #endif + #if !(HAVE_MEMMOVE) + # undef memmove + # define memmove(a,b,c) lzo_memmove(a,b,c) +-#elif !(__LZO_MMODEL_HUGE) ++#else + # undef lzo_memmove + # define lzo_memmove(a,b,c) memmove(a,b,c) + #endif + #if !(HAVE_MEMSET) + # undef memset + # define memset(a,b,c) lzo_memset(a,b,c) +-#elif !(__LZO_MMODEL_HUGE) ++#else + # undef lzo_memset + # define lzo_memset(a,b,c) memset(a,b,c) + #endif +@@ -2058,27 +3179,29 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) + #endif + +-#if !defined(__lzo_inline) +-# define __lzo_inline /*empty*/ +-#endif +-#if !defined(__lzo_forceinline) +-# define __lzo_forceinline /*empty*/ +-#endif +-#if !defined(__lzo_noinline) +-# define __lzo_noinline /*empty*/ +-#endif +- + #if (LZO_CFG_PGO) +-# undef __acc_likely +-# undef __acc_unlikely + # undef __lzo_likely + # undef __lzo_unlikely +-# define __acc_likely(e) (e) +-# define __acc_unlikely(e) (e) + # define __lzo_likely(e) (e) + # define __lzo_unlikely(e) (e) + #endif + ++#undef _ ++#undef __ ++#undef ___ ++#undef ____ ++#undef _p0 ++#undef _p1 ++#undef _p2 ++#undef _p3 ++#undef _p4 ++#undef _s0 ++#undef _s1 ++#undef _s2 ++#undef _s3 ++#undef _s4 ++#undef _ww ++ + #if 1 + # define LZO_BYTE(x) ((unsigned char) (x)) + #else +@@ -2097,84 +3220,548 @@ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + #define LZO_SIZE(bits) (1u << (bits)) + #define LZO_MASK(bits) (LZO_SIZE(bits) - 1) + +-#define LZO_LSIZE(bits) (1ul << (bits)) +-#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) +- + #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) + #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) + + #if !defined(DMUL) + #if 0 + +-# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) ++# define DMUL(a,b) ((lzo_xint) ((lzo_uint32_t)(a) * (lzo_uint32_t)(b))) + #else + # define DMUL(a,b) ((lzo_xint) ((a) * (b))) + #endif + #endif + +-#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) +-# if (LZO_SIZEOF_SHORT == 2) +-# define LZO_UNALIGNED_OK_2 1 +-# endif +-# if (LZO_SIZEOF_INT == 4) +-# define LZO_UNALIGNED_OK_4 1 +-# endif +-#endif +-#if 1 && (LZO_ARCH_AMD64) +-# if defined(LZO_UINT64_MAX) +-# define LZO_UNALIGNED_OK_8 1 +-# endif +-#endif +-#if (LZO_CFG_NO_UNALIGNED) +-# undef LZO_UNALIGNED_OK_2 +-# undef LZO_UNALIGNED_OK_4 +-# undef LZO_UNALIGNED_OK_8 +-#endif +- +-#undef UA_GET16 +-#undef UA_SET16 +-#undef UA_COPY16 +-#undef UA_GET32 +-#undef UA_SET32 +-#undef UA_COPY32 +-#undef UA_GET64 +-#undef UA_SET64 +-#undef UA_COPY64 +-#if defined(LZO_UNALIGNED_OK_2) +- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2) +-# if 1 && defined(ACC_UA_COPY16) +-# define UA_GET16 ACC_UA_GET16 +-# define UA_SET16 ACC_UA_SET16 +-# define UA_COPY16 ACC_UA_COPY16 +-# else +-# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) +-# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) +-# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) +-# endif +-#endif +-#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) +-# if 1 && defined(ACC_UA_COPY32) +-# define UA_GET32 ACC_UA_GET32 +-# define UA_SET32 ACC_UA_SET32 +-# define UA_COPY32 ACC_UA_COPY32 +-# else +-# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) +-# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) +-# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) +-# endif +-#endif +-#if defined(LZO_UNALIGNED_OK_8) +- LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8) +-# if 1 && defined(ACC_UA_COPY64) +-# define UA_GET64 ACC_UA_GET64 +-# define UA_SET64 ACC_UA_SET64 +-# define UA_COPY64 ACC_UA_COPY64 +-# else +-# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) +-# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) +-# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) +-# endif ++#ifndef __LZO_FUNC_H ++#define __LZO_FUNC_H 1 ++ ++#if !defined(LZO_BITOPS_USE_ASM_BITSCAN) && !defined(LZO_BITOPS_USE_GNUC_BITSCAN) && !defined(LZO_BITOPS_USE_MSC_BITSCAN) ++#if 1 && (LZO_ARCH_AMD64) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_ASM_SYNTAX_GNUC) ++#define LZO_BITOPS_USE_ASM_BITSCAN 1 ++#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) ++#define LZO_BITOPS_USE_GNUC_BITSCAN 1 ++#elif (LZO_OS_WIN32 || LZO_OS_WIN64) && ((LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1010)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) ++#define LZO_BITOPS_USE_MSC_BITSCAN 1 ++#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++#include ++#endif ++#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++#pragma intrinsic(_BitScanReverse) ++#pragma intrinsic(_BitScanForward) ++#endif ++#if (LZO_CC_MSC) && (LZO_ARCH_AMD64) ++#pragma intrinsic(_BitScanReverse64) ++#pragma intrinsic(_BitScanForward64) ++#endif ++#endif ++#endif ++ ++__lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v) ++{ ++#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++ unsigned long r; (void) _BitScanReverse(&r, v); return (unsigned) r ^ 31; ++#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) ++#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_uint32_t r; ++ __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); ++ return (unsigned) r ^ 31; ++#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4) ++ unsigned r; r = (unsigned) __builtin_clz(v); return r; ++#define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v)) ++#else ++ LZO_UNUSED(v); return 0; ++#endif ++} ++ ++#if defined(lzo_uint64_t) ++__lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v) ++{ ++#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) ++ unsigned long r; (void) _BitScanReverse64(&r, v); return (unsigned) r ^ 63; ++#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) ++#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_uint64_t r; ++ __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); ++ return (unsigned) r ^ 63; ++#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) ++ unsigned r; r = (unsigned) __builtin_clzl(v); return r; ++#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v)) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8) ++ unsigned r; r = (unsigned) __builtin_clzll(v); return r; ++#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v)) ++#else ++ LZO_UNUSED(v); return 0; ++#endif ++} ++#endif ++ ++__lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v) ++{ ++#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++ unsigned long r; (void) _BitScanForward(&r, v); return (unsigned) r; ++#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) ++#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_uint32_t r; ++ __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); ++ return (unsigned) r; ++#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4) ++ unsigned r; r = (unsigned) __builtin_ctz(v); return r; ++#define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v)) ++#else ++ LZO_UNUSED(v); return 0; ++#endif ++} ++ ++#if defined(lzo_uint64_t) ++__lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v) ++{ ++#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) ++ unsigned long r; (void) _BitScanForward64(&r, v); return (unsigned) r; ++#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) ++#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_uint64_t r; ++ __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); ++ return (unsigned) r; ++#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8) ++ unsigned r; r = (unsigned) __builtin_ctzl(v); return r; ++#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v)) ++#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8) ++ unsigned r; r = (unsigned) __builtin_ctzll(v); return r; ++#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v)) ++#else ++ LZO_UNUSED(v); return 0; ++#endif ++} ++#endif ++ ++#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++static void __attribute__((__unused__)) ++#else ++__lzo_static_forceinline void ++#endif ++lzo_bitops_unused_funcs(void) ++{ ++ LZO_UNUSED_FUNC(lzo_bitops_ctlz32_func); ++ LZO_UNUSED_FUNC(lzo_bitops_cttz32_func); ++#if defined(lzo_uint64_t) ++ LZO_UNUSED_FUNC(lzo_bitops_ctlz64_func); ++ LZO_UNUSED_FUNC(lzo_bitops_cttz64_func); ++#endif ++ LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); ++} ++ ++#if defined(__lzo_alignof) && !(LZO_CFG_NO_UNALIGNED) ++#ifndef __lzo_memops_tcheck ++#define __lzo_memops_tcheck(t,a,b) ((void)0, sizeof(t) == (a) && __lzo_alignof(t) == (b)) ++#endif ++#endif ++#ifndef lzo_memops_TU0p ++#define lzo_memops_TU0p void __LZO_MMODEL * ++#endif ++#ifndef lzo_memops_TU1p ++#define lzo_memops_TU1p unsigned char __LZO_MMODEL * ++#endif ++#ifndef lzo_memops_TU2p ++#if (LZO_OPT_UNALIGNED16) ++typedef lzo_uint16_t __lzo_may_alias lzo_memops_TU2; ++#define lzo_memops_TU2p volatile lzo_memops_TU2 * ++#elif defined(__lzo_byte_struct) ++__lzo_byte_struct(lzo_memops_TU2_struct,2) ++typedef struct lzo_memops_TU2_struct lzo_memops_TU2; ++#else ++struct lzo_memops_TU2_struct { unsigned char a[2]; } __lzo_may_alias; ++typedef struct lzo_memops_TU2_struct lzo_memops_TU2; ++#endif ++#ifndef lzo_memops_TU2p ++#define lzo_memops_TU2p lzo_memops_TU2 * ++#endif ++#endif ++#ifndef lzo_memops_TU4p ++#if (LZO_OPT_UNALIGNED32) ++typedef lzo_uint32_t __lzo_may_alias lzo_memops_TU4; ++#define lzo_memops_TU4p volatile lzo_memops_TU4 __LZO_MMODEL * ++#elif defined(__lzo_byte_struct) ++__lzo_byte_struct(lzo_memops_TU4_struct,4) ++typedef struct lzo_memops_TU4_struct lzo_memops_TU4; ++#else ++struct lzo_memops_TU4_struct { unsigned char a[4]; } __lzo_may_alias; ++typedef struct lzo_memops_TU4_struct lzo_memops_TU4; ++#endif ++#ifndef lzo_memops_TU4p ++#define lzo_memops_TU4p lzo_memops_TU4 __LZO_MMODEL * ++#endif ++#endif ++#ifndef lzo_memops_TU8p ++#if (LZO_OPT_UNALIGNED64) ++typedef lzo_uint64_t __lzo_may_alias lzo_memops_TU8; ++#define lzo_memops_TU8p volatile lzo_memops_TU8 __LZO_MMODEL * ++#elif defined(__lzo_byte_struct) ++__lzo_byte_struct(lzo_memops_TU8_struct,8) ++typedef struct lzo_memops_TU8_struct lzo_memops_TU8; ++#else ++struct lzo_memops_TU8_struct { unsigned char a[8]; } __lzo_may_alias; ++typedef struct lzo_memops_TU8_struct lzo_memops_TU8; ++#endif ++#ifndef lzo_memops_TU8p ++#define lzo_memops_TU8p lzo_memops_TU8 __LZO_MMODEL * ++#endif ++#endif ++#ifndef lzo_memops_set_TU1p ++#define lzo_memops_set_TU1p volatile lzo_memops_TU1p ++#endif ++#ifndef lzo_memops_move_TU1p ++#define lzo_memops_move_TU1p lzo_memops_TU1p ++#endif ++#define LZO_MEMOPS_SET1(dd,cc) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_set_TU1p d__1 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ ++ d__1[0] = LZO_BYTE(cc); \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_SET2(dd,cc) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_set_TU1p d__2 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ ++ d__2[0] = LZO_BYTE(cc); d__2[1] = LZO_BYTE(cc); \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_SET3(dd,cc) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_set_TU1p d__3 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ ++ d__3[0] = LZO_BYTE(cc); d__3[1] = LZO_BYTE(cc); d__3[2] = LZO_BYTE(cc); \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_SET4(dd,cc) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_set_TU1p d__4 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ ++ d__4[0] = LZO_BYTE(cc); d__4[1] = LZO_BYTE(cc); d__4[2] = LZO_BYTE(cc); d__4[3] = LZO_BYTE(cc); \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_MOVE1(dd,ss) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_move_TU1p d__1 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_move_TU1p s__1 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ ++ d__1[0] = s__1[0]; \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_MOVE2(dd,ss) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_move_TU1p d__2 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_move_TU1p s__2 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ ++ d__2[0] = s__2[0]; d__2[1] = s__2[1]; \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_MOVE3(dd,ss) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_move_TU1p d__3 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_move_TU1p s__3 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ ++ d__3[0] = s__3[0]; d__3[1] = s__3[1]; d__3[2] = s__3[2]; \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_MOVE4(dd,ss) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_move_TU1p d__4 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_move_TU1p s__4 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ ++ d__4[0] = s__4[0]; d__4[1] = s__4[1]; d__4[2] = s__4[2]; d__4[3] = s__4[3]; \ ++ LZO_BLOCK_END ++#define LZO_MEMOPS_MOVE8(dd,ss) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_move_TU1p d__8 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_move_TU1p s__8 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ ++ d__8[0] = s__8[0]; d__8[1] = s__8[1]; d__8[2] = s__8[2]; d__8[3] = s__8[3]; \ ++ d__8[4] = s__8[4]; d__8[5] = s__8[5]; d__8[6] = s__8[6]; d__8[7] = s__8[7]; \ ++ LZO_BLOCK_END ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU1p)0)==1) ++#define LZO_MEMOPS_COPY1(dd,ss) LZO_MEMOPS_MOVE1(dd,ss) ++#if (LZO_OPT_UNALIGNED16) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU2p)0)==2) ++#define LZO_MEMOPS_COPY2(dd,ss) \ ++ * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) ++#elif defined(__lzo_memops_tcheck) ++#define LZO_MEMOPS_COPY2(dd,ss) \ ++ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU2,2,1)) { \ ++ * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss); \ ++ } else { LZO_MEMOPS_MOVE2(dd,ss); } LZO_BLOCK_END ++#else ++#define LZO_MEMOPS_COPY2(dd,ss) LZO_MEMOPS_MOVE2(dd,ss) ++#endif ++#if (LZO_OPT_UNALIGNED32) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU4p)0)==4) ++#define LZO_MEMOPS_COPY4(dd,ss) \ ++ * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) ++#elif defined(__lzo_memops_tcheck) ++#define LZO_MEMOPS_COPY4(dd,ss) \ ++ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU4,4,1)) { \ ++ * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss); \ ++ } else { LZO_MEMOPS_MOVE4(dd,ss); } LZO_BLOCK_END ++#else ++#define LZO_MEMOPS_COPY4(dd,ss) LZO_MEMOPS_MOVE4(dd,ss) ++#endif ++#if (LZO_WORDSIZE != 8) ++#define LZO_MEMOPS_COPY8(dd,ss) \ ++ LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END ++#else ++#if (LZO_OPT_UNALIGNED64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU8p)0)==8) ++#define LZO_MEMOPS_COPY8(dd,ss) \ ++ * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) ++#elif (LZO_OPT_UNALIGNED32) ++#define LZO_MEMOPS_COPY8(dd,ss) \ ++ LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END ++#elif defined(__lzo_memops_tcheck) ++#define LZO_MEMOPS_COPY8(dd,ss) \ ++ LZO_BLOCK_BEGIN if (__lzo_memops_tcheck(lzo_memops_TU8,8,1)) { \ ++ * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss); \ ++ } else { LZO_MEMOPS_MOVE8(dd,ss); } LZO_BLOCK_END ++#else ++#define LZO_MEMOPS_COPY8(dd,ss) LZO_MEMOPS_MOVE8(dd,ss) ++#endif ++#endif ++#define LZO_MEMOPS_COPYN(dd,ss,nn) \ ++ LZO_BLOCK_BEGIN \ ++ lzo_memops_TU1p d__n = (lzo_memops_TU1p) (lzo_memops_TU0p) (dd); \ ++ const lzo_memops_TU1p s__n = (const lzo_memops_TU1p) (const lzo_memops_TU0p) (ss); \ ++ lzo_uint n__n = (nn); \ ++ while ((void)0, n__n >= 8) { LZO_MEMOPS_COPY8(d__n, s__n); d__n += 8; s__n += 8; n__n -= 8; } \ ++ if ((void)0, n__n >= 4) { LZO_MEMOPS_COPY4(d__n, s__n); d__n += 4; s__n += 4; n__n -= 4; } \ ++ if ((void)0, n__n > 0) do { *d__n++ = *s__n++; } while (--n__n > 0); \ ++ LZO_BLOCK_END ++ ++__lzo_static_forceinline lzo_uint16_t lzo_memops_get_le16(const lzo_voidp ss) ++{ ++ lzo_uint16_t v; ++#if (LZO_ABI_LITTLE_ENDIAN) ++ LZO_MEMOPS_COPY2(&v, ss); ++#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) ++ const lzo_memops_TU2p s = (const lzo_memops_TU2p) ss; ++ unsigned long vv; ++ __asm__("lhbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); ++ v = (lzo_uint16_t) vv; ++#else ++ const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; ++ v = (lzo_uint16_t) (((lzo_uint16_t)s[0]) | ((lzo_uint16_t)s[1] << 8)); ++#endif ++ return v; ++} ++#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) ++#define LZO_MEMOPS_GET_LE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) ++#else ++#define LZO_MEMOPS_GET_LE16(ss) lzo_memops_get_le16(ss) ++#endif ++ ++__lzo_static_forceinline lzo_uint32_t lzo_memops_get_le32(const lzo_voidp ss) ++{ ++ lzo_uint32_t v; ++#if (LZO_ABI_LITTLE_ENDIAN) ++ LZO_MEMOPS_COPY4(&v, ss); ++#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) ++ const lzo_memops_TU4p s = (const lzo_memops_TU4p) ss; ++ unsigned long vv; ++ __asm__("lwbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); ++ v = (lzo_uint32_t) vv; ++#else ++ const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; ++ v = (lzo_uint32_t) (((lzo_uint32_t)s[0]) | ((lzo_uint32_t)s[1] << 8) | ((lzo_uint32_t)s[2] << 16) | ((lzo_uint32_t)s[3] << 24)); ++#endif ++ return v; ++} ++#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) ++#define LZO_MEMOPS_GET_LE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) ++#else ++#define LZO_MEMOPS_GET_LE32(ss) lzo_memops_get_le32(ss) ++#endif ++ ++#if (LZO_OPT_UNALIGNED64) && (LZO_ABI_LITTLE_ENDIAN) ++#define LZO_MEMOPS_GET_LE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) ++#endif ++ ++__lzo_static_forceinline lzo_uint16_t lzo_memops_get_ne16(const lzo_voidp ss) ++{ ++ lzo_uint16_t v; ++ LZO_MEMOPS_COPY2(&v, ss); ++ return v; ++} ++#if (LZO_OPT_UNALIGNED16) ++#define LZO_MEMOPS_GET_NE16(ss) * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) ++#else ++#define LZO_MEMOPS_GET_NE16(ss) lzo_memops_get_ne16(ss) ++#endif ++ ++__lzo_static_forceinline lzo_uint32_t lzo_memops_get_ne32(const lzo_voidp ss) ++{ ++ lzo_uint32_t v; ++ LZO_MEMOPS_COPY4(&v, ss); ++ return v; ++} ++#if (LZO_OPT_UNALIGNED32) ++#define LZO_MEMOPS_GET_NE32(ss) * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) ++#else ++#define LZO_MEMOPS_GET_NE32(ss) lzo_memops_get_ne32(ss) ++#endif ++ ++#if (LZO_OPT_UNALIGNED64) ++#define LZO_MEMOPS_GET_NE64(ss) * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) ++#endif ++ ++__lzo_static_forceinline void lzo_memops_put_le16(lzo_voidp dd, lzo_uint16_t vv) ++{ ++#if (LZO_ABI_LITTLE_ENDIAN) ++ LZO_MEMOPS_COPY2(dd, &vv); ++#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_memops_TU2p d = (lzo_memops_TU2p) dd; ++ unsigned long v = vv; ++ __asm__("sthbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); ++#else ++ lzo_memops_TU1p d = (lzo_memops_TU1p) dd; ++ d[0] = LZO_BYTE((vv ) & 0xff); ++ d[1] = LZO_BYTE((vv >> 8) & 0xff); ++#endif ++} ++#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) ++#define LZO_MEMOPS_PUT_LE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) ++#else ++#define LZO_MEMOPS_PUT_LE16(dd,vv) lzo_memops_put_le16(dd,vv) ++#endif ++ ++__lzo_static_forceinline void lzo_memops_put_le32(lzo_voidp dd, lzo_uint32_t vv) ++{ ++#if (LZO_ABI_LITTLE_ENDIAN) ++ LZO_MEMOPS_COPY4(dd, &vv); ++#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) ++ lzo_memops_TU4p d = (lzo_memops_TU4p) dd; ++ unsigned long v = vv; ++ __asm__("stwbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); ++#else ++ lzo_memops_TU1p d = (lzo_memops_TU1p) dd; ++ d[0] = LZO_BYTE((vv ) & 0xff); ++ d[1] = LZO_BYTE((vv >> 8) & 0xff); ++ d[2] = LZO_BYTE((vv >> 16) & 0xff); ++ d[3] = LZO_BYTE((vv >> 24) & 0xff); ++#endif ++} ++#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) ++#define LZO_MEMOPS_PUT_LE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) ++#else ++#define LZO_MEMOPS_PUT_LE32(dd,vv) lzo_memops_put_le32(dd,vv) ++#endif ++ ++__lzo_static_forceinline void lzo_memops_put_ne16(lzo_voidp dd, lzo_uint16_t vv) ++{ ++ LZO_MEMOPS_COPY2(dd, &vv); ++} ++#if (LZO_OPT_UNALIGNED16) ++#define LZO_MEMOPS_PUT_NE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) ++#else ++#define LZO_MEMOPS_PUT_NE16(dd,vv) lzo_memops_put_ne16(dd,vv) ++#endif ++ ++__lzo_static_forceinline void lzo_memops_put_ne32(lzo_voidp dd, lzo_uint32_t vv) ++{ ++ LZO_MEMOPS_COPY4(dd, &vv); ++} ++#if (LZO_OPT_UNALIGNED32) ++#define LZO_MEMOPS_PUT_NE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) ++#else ++#define LZO_MEMOPS_PUT_NE32(dd,vv) lzo_memops_put_ne32(dd,vv) ++#endif ++ ++#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++static void __attribute__((__unused__)) ++#else ++__lzo_static_forceinline void ++#endif ++lzo_memops_unused_funcs(void) ++{ ++ LZO_UNUSED_FUNC(lzo_memops_get_le16); ++ LZO_UNUSED_FUNC(lzo_memops_get_le32); ++ LZO_UNUSED_FUNC(lzo_memops_get_ne16); ++ LZO_UNUSED_FUNC(lzo_memops_get_ne32); ++ LZO_UNUSED_FUNC(lzo_memops_put_le16); ++ LZO_UNUSED_FUNC(lzo_memops_put_le32); ++ LZO_UNUSED_FUNC(lzo_memops_put_ne16); ++ LZO_UNUSED_FUNC(lzo_memops_put_ne32); ++ LZO_UNUSED_FUNC(lzo_memops_unused_funcs); ++} ++ ++#endif ++ ++#ifndef UA_SET1 ++#define UA_SET1 LZO_MEMOPS_SET1 ++#endif ++#ifndef UA_SET2 ++#define UA_SET2 LZO_MEMOPS_SET2 ++#endif ++#ifndef UA_SET3 ++#define UA_SET3 LZO_MEMOPS_SET3 ++#endif ++#ifndef UA_SET4 ++#define UA_SET4 LZO_MEMOPS_SET4 ++#endif ++#ifndef UA_MOVE1 ++#define UA_MOVE1 LZO_MEMOPS_MOVE1 ++#endif ++#ifndef UA_MOVE2 ++#define UA_MOVE2 LZO_MEMOPS_MOVE2 ++#endif ++#ifndef UA_MOVE3 ++#define UA_MOVE3 LZO_MEMOPS_MOVE3 ++#endif ++#ifndef UA_MOVE4 ++#define UA_MOVE4 LZO_MEMOPS_MOVE4 ++#endif ++#ifndef UA_MOVE8 ++#define UA_MOVE8 LZO_MEMOPS_MOVE8 ++#endif ++#ifndef UA_COPY1 ++#define UA_COPY1 LZO_MEMOPS_COPY1 ++#endif ++#ifndef UA_COPY2 ++#define UA_COPY2 LZO_MEMOPS_COPY2 ++#endif ++#ifndef UA_COPY3 ++#define UA_COPY3 LZO_MEMOPS_COPY3 ++#endif ++#ifndef UA_COPY4 ++#define UA_COPY4 LZO_MEMOPS_COPY4 ++#endif ++#ifndef UA_COPY8 ++#define UA_COPY8 LZO_MEMOPS_COPY8 ++#endif ++#ifndef UA_COPYN ++#define UA_COPYN LZO_MEMOPS_COPYN ++#endif ++#ifndef UA_COPYN_X ++#define UA_COPYN_X LZO_MEMOPS_COPYN ++#endif ++#ifndef UA_GET_LE16 ++#define UA_GET_LE16 LZO_MEMOPS_GET_LE16 ++#endif ++#ifndef UA_GET_LE32 ++#define UA_GET_LE32 LZO_MEMOPS_GET_LE32 ++#endif ++#ifdef LZO_MEMOPS_GET_LE64 ++#ifndef UA_GET_LE64 ++#define UA_GET_LE64 LZO_MEMOPS_GET_LE64 ++#endif ++#endif ++#ifndef UA_GET_NE16 ++#define UA_GET_NE16 LZO_MEMOPS_GET_NE16 ++#endif ++#ifndef UA_GET_NE32 ++#define UA_GET_NE32 LZO_MEMOPS_GET_NE32 ++#endif ++#ifdef LZO_MEMOPS_GET_NE64 ++#ifndef UA_GET_NE64 ++#define UA_GET_NE64 LZO_MEMOPS_GET_NE64 ++#endif ++#endif ++#ifndef UA_PUT_LE16 ++#define UA_PUT_LE16 LZO_MEMOPS_PUT_LE16 ++#endif ++#ifndef UA_PUT_LE32 ++#define UA_PUT_LE32 LZO_MEMOPS_PUT_LE32 ++#endif ++#ifndef UA_PUT_NE16 ++#define UA_PUT_NE16 LZO_MEMOPS_PUT_NE16 ++#endif ++#ifndef UA_PUT_NE32 ++#define UA_PUT_NE32 LZO_MEMOPS_PUT_NE32 + #endif + + #define MEMCPY8_DS(dest,src,len) \ +@@ -2195,25 +3782,10 @@ LZO_EXTERN(const lzo_bytep) lzo_copyright(void); + extern "C" { + #endif + +-#if !defined(lzo_uintptr_t) +-# if (__LZO_MMODEL_HUGE) +-# define lzo_uintptr_t unsigned long +-# else +-# define lzo_uintptr_t acc_uintptr_t +-# ifdef __ACC_INTPTR_T_IS_POINTER +-# define __LZO_UINTPTR_T_IS_POINTER 1 +-# endif +-# endif +-#endif +- + #if (LZO_ARCH_I086) +-#define PTR(a) ((lzo_bytep) (a)) +-#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) +-#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) ++#error "LZO_ARCH_I086 is unsupported" + #elif (LZO_MM_PVP) +-#define PTR(a) ((lzo_bytep) (a)) +-#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) +-#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) ++#error "LZO_MM_PVP is unsupported" + #else + #define PTR(a) ((lzo_uintptr_t) (a)) + #define PTR_LINEAR(a) PTR(a) +@@ -2243,24 +3815,28 @@ typedef union + unsigned long a_ulong; + lzo_int a_lzo_int; + lzo_uint a_lzo_uint; +- lzo_int32 a_lzo_int32; +- lzo_uint32 a_lzo_uint32; +-#if defined(LZO_UINT64_MAX) +- lzo_int64 a_lzo_int64; +- lzo_uint64 a_lzo_uint64; ++ lzo_xint a_lzo_xint; ++ lzo_int16_t a_lzo_int16_t; ++ lzo_uint16_t a_lzo_uint16_t; ++ lzo_int32_t a_lzo_int32_t; ++ lzo_uint32_t a_lzo_uint32_t; ++#if defined(lzo_uint64_t) ++ lzo_int64_t a_lzo_int64_t; ++ lzo_uint64_t a_lzo_uint64_t; + #endif ++ size_t a_size_t; + ptrdiff_t a_ptrdiff_t; + lzo_uintptr_t a_lzo_uintptr_t; +- lzo_voidp a_lzo_voidp; + void * a_void_p; +- lzo_bytep a_lzo_bytep; +- lzo_bytepp a_lzo_bytepp; +- lzo_uintp a_lzo_uintp; +- lzo_uint * a_lzo_uint_p; +- lzo_uint32p a_lzo_uint32p; +- lzo_uint32 * a_lzo_uint32_p; +- unsigned char * a_uchar_p; + char * a_char_p; ++ unsigned char * a_uchar_p; ++ const void * a_c_void_p; ++ const char * a_c_char_p; ++ const unsigned char * a_c_uchar_p; ++ lzo_voidp a_lzo_voidp; ++ lzo_bytep a_lzo_bytep; ++ const lzo_voidp a_c_lzo_voidp; ++ const lzo_bytep a_c_lzo_bytep; + } + lzo_full_align_t; + +@@ -2276,18 +3852,14 @@ lzo_full_align_t; + + #ifndef LZO_DICT_USE_PTR + #define LZO_DICT_USE_PTR 1 +-#if 0 && (LZO_ARCH_I086) +-# undef LZO_DICT_USE_PTR +-# define LZO_DICT_USE_PTR 0 +-#endif + #endif + + #if (LZO_DICT_USE_PTR) + # define lzo_dict_t const lzo_bytep +-# define lzo_dict_p lzo_dict_t __LZO_MMODEL * ++# define lzo_dict_p lzo_dict_t * + #else + # define lzo_dict_t lzo_uint +-# define lzo_dict_p lzo_dict_t __LZO_MMODEL * ++# define lzo_dict_p lzo_dict_t * + #endif + + #endif +@@ -2300,10 +3872,9 @@ __lzo_ptr_linear(const lzo_voidp ptr) + lzo_uintptr_t p; + + #if (LZO_ARCH_I086) +- p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); ++#error "LZO_ARCH_I086 is unsupported" + #elif (LZO_MM_PVP) +- p = (lzo_uintptr_t) (ptr); +- p = (p << 3) | (p >> 61); ++#error "LZO_MM_PVP is unsupported" + #else + p = (lzo_uintptr_t) PTR_LINEAR(ptr); + #endif +@@ -2314,9 +3885,8 @@ __lzo_ptr_linear(const lzo_voidp ptr) + LZO_PUBLIC(unsigned) + __lzo_align_gap(const lzo_voidp ptr, lzo_uint size) + { +-#if defined(__LZO_UINTPTR_T_IS_POINTER) +- size_t n = (size_t) ptr; +- n = (((n + size - 1) / size) * size) - n; ++#if (__LZO_UINTPTR_T_IS_POINTER) ++#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" + #else + lzo_uintptr_t p, n; + p = __lzo_ptr_linear(ptr); +@@ -2342,7 +3912,7 @@ static const char __lzo_copyright[] = + #else + "\r\n\n" + "LZO data compression library.\n" +- "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" ++ "$Copyright: LZO Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer\n" + "\n" + "http://www.oberhumer.com $\n\n" + "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" +@@ -2352,11 +3922,7 @@ static const char __lzo_copyright[] = + LZO_PUBLIC(const lzo_bytep) + lzo_copyright(void) + { +-#if (LZO_OS_DOS16 && LZO_CC_TURBOC) +- return (lzo_voidp) __lzo_copyright; +-#else + return (const lzo_bytep) __lzo_copyright; +-#endif + } + + LZO_PUBLIC(unsigned) +@@ -2393,16 +3959,16 @@ _lzo_version_date(void) + #define LZO_NMAX 5552 + + #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 +-#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); +-#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); +-#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); +-#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); ++#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1) ++#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2) ++#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4) ++#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8) + +-LZO_PUBLIC(lzo_uint32) +-lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) ++LZO_PUBLIC(lzo_uint32_t) ++lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) + { +- lzo_uint32 s1 = adler & 0xffff; +- lzo_uint32 s2 = (adler >> 16) & 0xffff; ++ lzo_uint32_t s1 = adler & 0xffff; ++ lzo_uint32_t s2 = (adler >> 16) & 0xffff; + unsigned k; + + if (buf == NULL) +@@ -2459,8 +4025,8 @@ lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) + LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) + { + #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) +- const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; +- const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; ++ const lzo_hbyte_p p1 = LZO_STATIC_CAST(const lzo_hbyte_p, s1); ++ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, s2); + if __lzo_likely(len > 0) do + { + int d = *p1 - *p2; +@@ -2476,8 +4042,8 @@ LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo + LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) + { + #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) +- lzo_hbyte_p p1 = (lzo_hbyte_p) dest; +- const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; ++ lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); ++ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); + if (!(len > 0) || p1 == p2) + return dest; + do +@@ -2491,8 +4057,8 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src + LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) + { + #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) +- lzo_hbyte_p p1 = (lzo_hbyte_p) dest; +- const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; ++ lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); ++ const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); + if (!(len > 0) || p1 == p2) + return dest; + if (p1 < p2) +@@ -2514,16 +4080,17 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p sr + return memmove(dest, src, len); + #endif + } +-LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) ++LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int cc, lzo_hsize_t len) + { + #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) +- lzo_hbyte_p p = (lzo_hbyte_p) s; ++ lzo_hbyte_p p = LZO_STATIC_CAST(lzo_hbyte_p, s); ++ unsigned char c = LZO_ITRUNC(unsigned char, cc); + if __lzo_likely(len > 0) do +- *p++ = (unsigned char) c; ++ *p++ = c; + while __lzo_likely(--len > 0); + return s; + #else +- return memset(s, c, len); ++ return memset(s, cc, len); + #endif + } + #undef LZOLIB_PUBLIC +@@ -2532,105 +4099,28 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) + + #if !defined(__LZO_IN_MINILZO) + +-#define ACC_WANT_ACC_CHK_CH 1 +-#undef ACCCHK_ASSERT ++#define LZO_WANT_ACC_CHK_CH 1 ++#undef LZOCHK_ASSERT + +- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) +- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) +- +- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) +- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) +- ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) +- ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) +-#if defined(LZO_UINT64_MAX) +- ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) +- ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) +- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) ++ LZOCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) ++ LZOCHK_ASSERT_IS_SIGNED_T(lzo_int) ++ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) ++#if !(__LZO_UINTPTR_T_IS_POINTER) ++ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) + #endif ++ LZOCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) ++ LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) + +-#if !defined(__LZO_UINTPTR_T_IS_POINTER) +- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) + #endif +- ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) +- +- ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) +- ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) +- ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) +- ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) ++#undef LZOCHK_ASSERT + ++union lzo_config_check_union { ++ lzo_uint a[2]; ++ unsigned char b[2*LZO_MAX(8,sizeof(lzo_uint))]; ++#if defined(lzo_uint64_t) ++ lzo_uint64_t c[2]; + #endif +-#undef ACCCHK_ASSERT +- +-#if 0 +-#define WANT_lzo_bitops_clz32 1 +-#define WANT_lzo_bitops_clz64 1 +-#endif +-#define WANT_lzo_bitops_ctz32 1 +-#define WANT_lzo_bitops_ctz64 1 +- +-#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +-#include +-#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +-#pragma intrinsic(_BitScanReverse) +-static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +-{ +- unsigned long r; +- (void) _BitScanReverse(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_clz32 lzo_bitops_clz32 +-#endif +-#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +-#pragma intrinsic(_BitScanReverse64) +-static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +-{ +- unsigned long r; +- (void) _BitScanReverse64(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_clz64 lzo_bitops_clz64 +-#endif +-#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +-#pragma intrinsic(_BitScanForward) +-static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +-{ +- unsigned long r; +- (void) _BitScanForward(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_ctz32 lzo_bitops_ctz32 +-#endif +-#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +-#pragma intrinsic(_BitScanForward64) +-static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +-{ +- unsigned long r; +- (void) _BitScanForward64(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_ctz64 lzo_bitops_ctz64 +-#endif +- +-#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +-#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +-#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +-#endif +-#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +-#endif +-#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +-#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +-#endif +-#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +-#endif +-#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +-#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +-#endif +-#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +-#endif +-#endif ++}; + + #if 0 + #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) +@@ -2644,73 +4134,101 @@ static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off) + LZO_PUBLIC(int) + _lzo_config_check(void) + { +- lzo_bool r = 1; +- union { +- lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))]; +-#if defined(LZO_UNALIGNED_OK_8) +- lzo_uint64 c[2]; ++#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030100ul && LZO_CC_CLANG < 0x030300ul)) ++# if 0 ++ volatile ++# endif + #endif +- unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; +- } u; ++ union lzo_config_check_union u; + lzo_voidp p; ++ unsigned r = 1; + + u.a[0] = u.a[1] = 0; + p = u2p(&u, 0); + r &= ((* (lzo_bytep) p) == 0); +-#if !defined(LZO_CFG_NO_CONFIG_CHECK) +-#if defined(LZO_ABI_BIG_ENDIAN) ++#if !(LZO_CFG_NO_CONFIG_CHECK) ++#if (LZO_ABI_BIG_ENDIAN) + u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; + p = u2p(&u, 0); + r &= ((* (lzo_uintp) p) == 128); + #endif +-#if defined(LZO_ABI_LITTLE_ENDIAN) ++#if (LZO_ABI_LITTLE_ENDIAN) + u.a[0] = u.a[1] = 0; u.b[0] = 128; + p = u2p(&u, 0); + r &= ((* (lzo_uintp) p) == 128); + #endif +-#if defined(LZO_UNALIGNED_OK_2) + u.a[0] = u.a[1] = 0; +- u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; ++ u.b[0] = 1; u.b[3] = 2; + p = u2p(&u, 1); +- r &= ((* (lzo_ushortp) p) == 0); ++ r &= UA_GET_NE16(p) == 0; ++ r &= UA_GET_LE16(p) == 0; ++ u.b[1] = 128; ++ r &= UA_GET_LE16(p) == 128; ++ u.b[2] = 129; ++ r &= UA_GET_LE16(p) == LZO_UINT16_C(0x8180); ++#if (LZO_ABI_BIG_ENDIAN) ++ r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8081); ++#endif ++#if (LZO_ABI_LITTLE_ENDIAN) ++ r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180); + #endif +-#if defined(LZO_UNALIGNED_OK_4) + u.a[0] = u.a[1] = 0; +- u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; ++ u.b[0] = 3; u.b[5] = 4; + p = u2p(&u, 1); +- r &= ((* (lzo_uint32p) p) == 0); ++ r &= UA_GET_NE32(p) == 0; ++ r &= UA_GET_LE32(p) == 0; ++ u.b[1] = 128; ++ r &= UA_GET_LE32(p) == 128; ++ u.b[2] = 129; u.b[3] = 130; u.b[4] = 131; ++ r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180); ++#if (LZO_ABI_BIG_ENDIAN) ++ r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283); ++#endif ++#if (LZO_ABI_LITTLE_ENDIAN) ++ r &= UA_GET_NE32(p) == LZO_UINT32_C(0x83828180); + #endif +-#if defined(LZO_UNALIGNED_OK_8) ++#if defined(UA_GET_NE64) + u.c[0] = u.c[1] = 0; +- u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; ++ u.b[0] = 5; u.b[9] = 6; + p = u2p(&u, 1); +- r &= ((* (lzo_uint64p) p) == 0); ++ u.c[0] = u.c[1] = 0; ++ r &= UA_GET_NE64(p) == 0; ++#if defined(UA_GET_LE64) ++ r &= UA_GET_LE64(p) == 0; ++ u.b[1] = 128; ++ r &= UA_GET_LE64(p) == 128; ++#endif + #endif +-#if defined(lzo_bitops_clz32) +- { unsigned i; lzo_uint32 v = 1; +- for (i = 0; i < 31; i++, v <<= 1) +- r &= lzo_bitops_clz32(v) == 31 - i; +- } ++#if defined(lzo_bitops_ctlz32) ++ { unsigned i = 0; lzo_uint32_t v; ++ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { ++ r &= lzo_bitops_ctlz32(v) == 31 - i; ++ r &= lzo_bitops_ctlz32_func(v) == 31 - i; ++ }} + #endif +-#if defined(lzo_bitops_clz64) +- { unsigned i; lzo_uint64 v = 1; +- for (i = 0; i < 63; i++, v <<= 1) +- r &= lzo_bitops_clz64(v) == 63 - i; +- } ++#if defined(lzo_bitops_ctlz64) ++ { unsigned i = 0; lzo_uint64_t v; ++ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { ++ r &= lzo_bitops_ctlz64(v) == 63 - i; ++ r &= lzo_bitops_ctlz64_func(v) == 63 - i; ++ }} + #endif +-#if defined(lzo_bitops_ctz32) +- { unsigned i; lzo_uint32 v = 1; +- for (i = 0; i < 31; i++, v <<= 1) +- r &= lzo_bitops_ctz32(v) == i; +- } ++#if defined(lzo_bitops_cttz32) ++ { unsigned i = 0; lzo_uint32_t v; ++ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { ++ r &= lzo_bitops_cttz32(v) == i; ++ r &= lzo_bitops_cttz32_func(v) == i; ++ }} + #endif +-#if defined(lzo_bitops_ctz64) +- { unsigned i; lzo_uint64 v = 1; +- for (i = 0; i < 63; i++, v <<= 1) +- r &= lzo_bitops_ctz64(v) == i; +- } ++#if defined(lzo_bitops_cttz64) ++ { unsigned i = 0; lzo_uint64_t v; ++ for (v = 1; v != 0 && r == 1; v <<= 1, i++) { ++ r &= lzo_bitops_cttz64(v) == i; ++ r &= lzo_bitops_cttz64_func(v) == i; ++ }} + #endif + #endif ++ LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); + + return r == 1 ? LZO_E_OK : LZO_E_ERROR; + } +@@ -2724,11 +4242,11 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, + #if defined(__LZO_IN_MINILZO) + #elif (LZO_CC_MSC && ((_MSC_VER) < 700)) + #else +-#define ACC_WANT_ACC_CHK_CH 1 +-#undef ACCCHK_ASSERT +-#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) ++#define LZO_WANT_ACC_CHK_CH 1 ++#undef LZOCHK_ASSERT ++#define LZOCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) + #endif +-#undef ACCCHK_ASSERT ++#undef LZOCHK_ASSERT + + if (v == 0) + return LZO_E_ERROR; +@@ -2736,7 +4254,7 @@ __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, + r = (s1 == -1 || s1 == (int) sizeof(short)) && + (s2 == -1 || s2 == (int) sizeof(int)) && + (s3 == -1 || s3 == (int) sizeof(long)) && +- (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && ++ (s4 == -1 || s4 == (int) sizeof(lzo_uint32_t)) && + (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && + (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && + (s7 == -1 || s7 == (int) sizeof(char *)) && +@@ -2779,11 +4297,11 @@ int __far __pascal LibMain ( int a, short b, short c, long d ) + + #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) + +-#if 1 && defined(UA_GET32) ++#if 1 && defined(UA_GET_LE32) + #undef LZO_DICT_USE_PTR + #define LZO_DICT_USE_PTR 0 + #undef lzo_dict_t +-#define lzo_dict_t unsigned short ++#define lzo_dict_t lzo_uint16_t + #endif + + #define LZO_NEED_DICT_H 1 +@@ -3088,77 +4606,7 @@ DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) + #endif + + #if 1 && defined(DO_COMPRESS) && !defined(do_compress) +-# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) +-#endif +- +-#if defined(UA_GET64) +-# define WANT_lzo_bitops_ctz64 1 +-#elif defined(UA_GET32) +-# define WANT_lzo_bitops_ctz32 1 +-#endif +- +-#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +-#include +-#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 +-#pragma intrinsic(_BitScanReverse) +-static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) +-{ +- unsigned long r; +- (void) _BitScanReverse(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_clz32 lzo_bitops_clz32 +-#endif +-#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 +-#pragma intrinsic(_BitScanReverse64) +-static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) +-{ +- unsigned long r; +- (void) _BitScanReverse64(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_clz64 lzo_bitops_clz64 +-#endif +-#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +-#pragma intrinsic(_BitScanForward) +-static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) +-{ +- unsigned long r; +- (void) _BitScanForward(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_ctz32 lzo_bitops_ctz32 +-#endif +-#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +-#pragma intrinsic(_BitScanForward64) +-static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) +-{ +- unsigned long r; +- (void) _BitScanForward64(&r, v); +- return (unsigned) r; +-} +-#define lzo_bitops_ctz64 lzo_bitops_ctz64 +-#endif +- +-#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) +-#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) +-#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) +-#endif +-#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) +-#endif +-#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) +-#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) +-#endif +-#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) +-#endif +-#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) +-#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) +-#endif +-#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) +-#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) +-#endif ++# define do_compress LZO_PP_ECONCAT2(DO_COMPRESS,_core) + #endif + + static __lzo_noinline lzo_uint +@@ -3166,7 +4614,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, + lzo_bytep out, lzo_uintp out_len, + lzo_uint ti, lzo_voidp wrkmem) + { +- register const lzo_bytep ip; ++ const lzo_bytep ip; + lzo_bytep op; + const lzo_bytep const in_end = in + in_len; + const lzo_bytep const ip_end = in + in_len - 20; +@@ -3175,7 +4623,7 @@ do_compress ( const lzo_bytep in , lzo_uint in_len, + + op = out; + ip = in; +- ii = ip - ti; ++ ii = ip; + + ip += ti < 4 ? 4 - ti : 0; + for (;;) +@@ -3205,8 +4653,8 @@ next: + goto literal; + + try_match: +-#if defined(UA_GET32) +- if (UA_GET32(m_pos) != UA_GET32(ip)) ++#if (LZO_OPT_UNALIGNED32) ++ if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip)) + #else + if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) + #endif +@@ -3221,49 +4669,43 @@ literal: + lzo_uint m_off; + lzo_uint m_len; + { +- lzo_uint32 dv; ++ lzo_uint32_t dv; + lzo_uint dindex; + literal: + ip += 1 + ((ip - ii) >> 5); + next: + if __lzo_unlikely(ip >= ip_end) + break; +- dv = UA_GET32(ip); ++ dv = UA_GET_LE32(ip); + dindex = DINDEX(dv,ip); + GINDEX(m_off,m_pos,in+dict,dindex,in); + UPDATE_I(dict,0,dindex,ip,in); +- if __lzo_unlikely(dv != UA_GET32(m_pos)) ++ if __lzo_unlikely(dv != UA_GET_LE32(m_pos)) + goto literal; + } + #endif + ++ ii -= ti; ti = 0; + { +- register lzo_uint t = pd(ip,ii); ++ lzo_uint t = pd(ip,ii); + if (t != 0) + { + if (t <= 3) + { +- op[-2] |= LZO_BYTE(t); +-#if defined(UA_COPY32) +- UA_COPY32(op, ii); ++ op[-2] = LZO_BYTE(op[-2] | t); ++#if (LZO_OPT_UNALIGNED32) ++ UA_COPY4(op, ii); + op += t; + #else + { do *op++ = *ii++; while (--t > 0); } + #endif + } +-#if defined(UA_COPY32) || defined(UA_COPY64) ++#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) + else if (t <= 16) + { + *op++ = LZO_BYTE(t - 3); +-#if defined(UA_COPY64) +- UA_COPY64(op, ii); +- UA_COPY64(op+8, ii+8); +-#else +- UA_COPY32(op, ii); +- UA_COPY32(op+4, ii+4); +- UA_COPY32(op+8, ii+8); +- UA_COPY32(op+12, ii+12); +-#endif ++ UA_COPY8(op, ii); ++ UA_COPY8(op+8, ii+8); + op += t; + } + #endif +@@ -3273,31 +4715,21 @@ next: + *op++ = LZO_BYTE(t - 3); + else + { +- register lzo_uint tt = t - 18; ++ lzo_uint tt = t - 18; + *op++ = 0; + while __lzo_unlikely(tt > 255) + { + tt -= 255; +-#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) +- * (volatile unsigned char *) op++ = 0; +-#else +- *op++ = 0; +-#endif ++ UA_SET1(op, 0); ++ op++; + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } +-#if defined(UA_COPY32) || defined(UA_COPY64) ++#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) + do { +-#if defined(UA_COPY64) +- UA_COPY64(op, ii); +- UA_COPY64(op+8, ii+8); +-#else +- UA_COPY32(op, ii); +- UA_COPY32(op+4, ii+4); +- UA_COPY32(op+8, ii+8); +- UA_COPY32(op+12, ii+12); +-#endif ++ UA_COPY8(op, ii); ++ UA_COPY8(op+8, ii+8); + op += 16; ii += 16; t -= 16; + } while (t >= 16); if (t > 0) + #endif +@@ -3307,19 +4739,26 @@ next: + } + m_len = 4; + { +-#if defined(UA_GET64) +- lzo_uint64 v; +- v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); ++#if (LZO_OPT_UNALIGNED64) ++ lzo_uint64_t v; ++ v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 8; +- v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); ++ v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +-#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) +- m_len += lzo_bitops_ctz64(v) / CHAR_BIT; ++#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64) ++ m_len += lzo_bitops_ctlz64(v) / CHAR_BIT; ++#elif (LZO_ABI_BIG_ENDIAN) ++ if ((v >> (64 - CHAR_BIT)) == 0) do { ++ v <<= CHAR_BIT; ++ m_len += 1; ++ } while ((v >> (64 - CHAR_BIT)) == 0); ++#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64) ++ m_len += lzo_bitops_cttz64(v) / CHAR_BIT; + #elif (LZO_ABI_LITTLE_ENDIAN) + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; +@@ -3330,19 +4769,30 @@ next: + m_len += 1; + } while (ip[m_len] == m_pos[m_len]); + #endif +-#elif defined(UA_GET32) +- lzo_uint32 v; +- v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); ++#elif (LZO_OPT_UNALIGNED32) ++ lzo_uint32_t v; ++ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 4; +- v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); ++ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); ++ if (v != 0) ++ break; ++ m_len += 4; ++ v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +-#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) +- m_len += lzo_bitops_ctz32(v) / CHAR_BIT; ++#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32) ++ m_len += lzo_bitops_ctlz32(v) / CHAR_BIT; ++#elif (LZO_ABI_BIG_ENDIAN) ++ if ((v >> (32 - CHAR_BIT)) == 0) do { ++ v <<= CHAR_BIT; ++ m_len += 1; ++ } while ((v >> (32 - CHAR_BIT)) == 0); ++#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32) ++ m_len += lzo_bitops_cttz32(v) / CHAR_BIT; + #elif (LZO_ABI_LITTLE_ENDIAN) + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; +@@ -3357,6 +4807,27 @@ next: + if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { + do { + m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; ++ if (ip[m_len] != m_pos[m_len]) ++ break; ++ m_len += 1; + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (ip[m_len] == m_pos[m_len]); +@@ -3390,11 +4861,8 @@ m_len_done: + while __lzo_unlikely(m_len > 255) + { + m_len -= 255; +-#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) +- * (volatile unsigned char *) op++ = 0; +-#else +- *op++ = 0; +-#endif ++ UA_SET1(op, 0); ++ op++; + } + *op++ = LZO_BYTE(m_len); + } +@@ -3413,11 +4881,8 @@ m_len_done: + while __lzo_unlikely(m_len > 255) + { + m_len -= 255; +-#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) +- * (volatile unsigned char *) op++ = 0; +-#else +- *op++ = 0; +-#endif ++ UA_SET1(op, 0); ++ op++; + } + *op++ = LZO_BYTE(m_len); + } +@@ -3428,7 +4893,7 @@ m_len_done: + } + + *out_len = pd(op, out); +- return pd(in_end,ii); ++ return pd(in_end,ii-ti); + } + + LZO_PUBLIC(int) +@@ -3468,7 +4933,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + if (op == out && t <= 238) + *op++ = LZO_BYTE(17 + t); + else if (t <= 3) +- op[-2] |= LZO_BYTE(t); ++ op[-2] = LZO_BYTE(op[-2] | t); + else if (t <= 18) + *op++ = LZO_BYTE(t - 3); + else +@@ -3479,17 +4944,14 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + while (tt > 255) + { + tt -= 255; +-#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) +- +- * (volatile unsigned char *) op++ = 0; +-#else +- *op++ = 0; +-#endif ++ UA_SET1(op, 0); ++ op++; + } + assert(tt > 0); + *op++ = LZO_BYTE(tt); + } +- do *op++ = *ii++; while (--t > 0); ++ UA_COPYN(op, ii, t); ++ op += t; + } + + *op++ = M4_MARKER | 1; +@@ -3526,10 +4988,13 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + + #undef TEST_IP + #undef TEST_OP ++#undef TEST_IP_AND_TEST_OP + #undef TEST_LB + #undef TEST_LBO + #undef NEED_IP + #undef NEED_OP ++#undef TEST_IV ++#undef TEST_OV + #undef HAVE_TEST_IP + #undef HAVE_TEST_OP + #undef HAVE_NEED_IP +@@ -3544,6 +5009,7 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + # if (LZO_TEST_OVERRUN_INPUT >= 2) + # define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun ++# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun + # endif + #endif + +@@ -3555,12 +5021,13 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + # undef TEST_OP + # define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun ++# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun + # endif + #endif + + #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +-# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +-# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun ++# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun ++# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun + #else + # define TEST_LB(m_pos) ((void) 0) + # define TEST_LBO(m_pos,o) ((void) 0) +@@ -3581,15 +5048,27 @@ DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, + # define TEST_OP 1 + #endif + ++#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) ++# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) ++#elif defined(HAVE_TEST_IP) ++# define TEST_IP_AND_TEST_OP TEST_IP ++#elif defined(HAVE_TEST_OP) ++# define TEST_IP_AND_TEST_OP TEST_OP ++#else ++# define TEST_IP_AND_TEST_OP 1 ++#endif ++ + #if defined(NEED_IP) + # define HAVE_NEED_IP 1 + #else + # define NEED_IP(x) ((void) 0) ++# define TEST_IV(x) ((void) 0) + #endif + #if defined(NEED_OP) + # define HAVE_NEED_OP 1 + #else + # define NEED_OP(x) ((void) 0) ++# define TEST_OV(x) ((void) 0) + #endif + + #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +@@ -3606,14 +5085,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_voidp wrkmem ) + #endif + { +- register lzo_bytep op; +- register const lzo_bytep ip; +- register lzo_uint t; ++ lzo_bytep op; ++ const lzo_bytep ip; ++ lzo_uint t; + #if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; + #else +- register const lzo_bytep m_pos; ++ const lzo_bytep m_pos; + #endif + + const lzo_bytep const ip_end = in + in_len; +@@ -3648,43 +5127,45 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + op = out; + ip = in; + ++ NEED_IP(1); + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; +- assert(t > 0); NEED_OP(t); NEED_IP(t+1); ++ assert(t > 0); NEED_OP(t); NEED_IP(t+3); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + +- while (TEST_IP && TEST_OP) ++ for (;;) + { ++ NEED_IP(3); + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_IV(t); + NEED_IP(1); + } + t += 15 + *ip++; + } +- assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +-#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); ++#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + t += 3; + if (t >= 8) do + { +- UA_COPY64(op,ip); ++ UA_COPY8(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } + if (t > 0) +@@ -3692,19 +5173,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + } +-#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +-#if !defined(LZO_UNALIGNED_OK_4) ++#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + if (PTR_ALIGNED2_4(op,ip)) + { + #endif +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); +@@ -3712,12 +5193,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + else + do *op++ = *ip++; while (--t > 0); + } +-#if !defined(LZO_UNALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + } + else + #endif + #endif +-#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) ++#if !(LZO_OPT_UNALIGNED32) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); +@@ -3753,7 +5234,7 @@ first_literal_run: + #endif + goto match_done; + +- do { ++ for (;;) { + match: + if (t >= 64) + { +@@ -3813,14 +5294,15 @@ match: + t &= 31; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_OV(t); + NEED_IP(1); + } + t += 31 + *ip++; ++ NEED_IP(2); + } + #if defined(COPY_DICT) + #if defined(LZO1Z) +@@ -3836,9 +5318,9 @@ match: + m_pos = op - off; + last_m_off = off; + } +-#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; +- m_pos -= UA_GET16(ip) >> 2; ++ m_pos -= UA_GET_LE16(ip) >> 2; + #else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +@@ -3857,14 +5339,15 @@ match: + t &= 7; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_OV(t); + NEED_IP(1); + } + t += 7 + *ip++; ++ NEED_IP(2); + } + #if defined(COPY_DICT) + #if defined(LZO1Z) +@@ -3882,8 +5365,8 @@ match: + #else + #if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +-#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) +- m_pos -= UA_GET16(ip) >> 2; ++#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) ++ m_pos -= UA_GET_LE16(ip) >> 2; + #else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); + #endif +@@ -3931,18 +5414,18 @@ match: + #else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +-#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + if (op - m_pos >= 8) + { + t += (3 - 1); + if (t >= 8) do + { +- UA_COPY64(op,m_pos); ++ UA_COPY8(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } + if (t > 0) +@@ -3952,8 +5435,8 @@ match: + } + } + else +-#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +-#if !defined(LZO_UNALIGNED_OK_4) ++#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +@@ -3961,10 +5444,10 @@ match: + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { + #endif +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); +@@ -3989,7 +5472,7 @@ match_done: + break; + + match_next: +- assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); ++ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); + #if 0 + do *op++ = *ip++; while (--t > 0); + #else +@@ -3997,16 +5480,10 @@ match_next: + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + #endif + t = *ip++; +- } while (TEST_IP && TEST_OP); ++ } + } + +-#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) +- *out_len = pd(op, out); +- return LZO_E_EOF_NOT_FOUND; +-#endif +- + eof_found: +- assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); +@@ -4052,10 +5529,13 @@ lookbehind_overrun: + + #undef TEST_IP + #undef TEST_OP ++#undef TEST_IP_AND_TEST_OP + #undef TEST_LB + #undef TEST_LBO + #undef NEED_IP + #undef NEED_OP ++#undef TEST_IV ++#undef TEST_OV + #undef HAVE_TEST_IP + #undef HAVE_TEST_OP + #undef HAVE_NEED_IP +@@ -4070,6 +5550,7 @@ lookbehind_overrun: + # if (LZO_TEST_OVERRUN_INPUT >= 2) + # define NEED_IP(x) \ + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun ++# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun + # endif + #endif + +@@ -4081,12 +5562,13 @@ lookbehind_overrun: + # undef TEST_OP + # define NEED_OP(x) \ + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun ++# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun + # endif + #endif + + #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +-# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun +-# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun ++# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun ++# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun + #else + # define TEST_LB(m_pos) ((void) 0) + # define TEST_LBO(m_pos,o) ((void) 0) +@@ -4107,15 +5589,27 @@ lookbehind_overrun: + # define TEST_OP 1 + #endif + ++#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) ++# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) ++#elif defined(HAVE_TEST_IP) ++# define TEST_IP_AND_TEST_OP TEST_IP ++#elif defined(HAVE_TEST_OP) ++# define TEST_IP_AND_TEST_OP TEST_OP ++#else ++# define TEST_IP_AND_TEST_OP 1 ++#endif ++ + #if defined(NEED_IP) + # define HAVE_NEED_IP 1 + #else + # define NEED_IP(x) ((void) 0) ++# define TEST_IV(x) ((void) 0) + #endif + #if defined(NEED_OP) + # define HAVE_NEED_OP 1 + #else + # define NEED_OP(x) ((void) 0) ++# define TEST_OV(x) ((void) 0) + #endif + + #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) +@@ -4132,14 +5626,14 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + lzo_voidp wrkmem ) + #endif + { +- register lzo_bytep op; +- register const lzo_bytep ip; +- register lzo_uint t; ++ lzo_bytep op; ++ const lzo_bytep ip; ++ lzo_uint t; + #if defined(COPY_DICT) + lzo_uint m_off; + const lzo_bytep dict_end; + #else +- register const lzo_bytep m_pos; ++ const lzo_bytep m_pos; + #endif + + const lzo_bytep const ip_end = in + in_len; +@@ -4174,43 +5668,45 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + op = out; + ip = in; + ++ NEED_IP(1); + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; +- assert(t > 0); NEED_OP(t); NEED_IP(t+1); ++ assert(t > 0); NEED_OP(t); NEED_IP(t+3); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + +- while (TEST_IP && TEST_OP) ++ for (;;) + { ++ NEED_IP(3); + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_IV(t); + NEED_IP(1); + } + t += 15 + *ip++; + } +- assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +-#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); ++#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + t += 3; + if (t >= 8) do + { +- UA_COPY64(op,ip); ++ UA_COPY8(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } + if (t > 0) +@@ -4218,19 +5714,19 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + } +-#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +-#if !defined(LZO_UNALIGNED_OK_4) ++#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + if (PTR_ALIGNED2_4(op,ip)) + { + #endif +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { +- UA_COPY32(op,ip); ++ UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); +@@ -4238,12 +5734,12 @@ DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, + else + do *op++ = *ip++; while (--t > 0); + } +-#if !defined(LZO_UNALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + } + else + #endif + #endif +-#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) ++#if !(LZO_OPT_UNALIGNED32) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); +@@ -4279,7 +5775,7 @@ first_literal_run: + #endif + goto match_done; + +- do { ++ for (;;) { + match: + if (t >= 64) + { +@@ -4339,14 +5835,15 @@ match: + t &= 31; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_OV(t); + NEED_IP(1); + } + t += 31 + *ip++; ++ NEED_IP(2); + } + #if defined(COPY_DICT) + #if defined(LZO1Z) +@@ -4362,9 +5859,9 @@ match: + m_pos = op - off; + last_m_off = off; + } +-#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; +- m_pos -= UA_GET16(ip) >> 2; ++ m_pos -= UA_GET_LE16(ip) >> 2; + #else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +@@ -4383,14 +5880,15 @@ match: + t &= 7; + if (t == 0) + { +- NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; ++ TEST_OV(t); + NEED_IP(1); + } + t += 7 + *ip++; ++ NEED_IP(2); + } + #if defined(COPY_DICT) + #if defined(LZO1Z) +@@ -4408,8 +5906,8 @@ match: + #else + #if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +-#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) +- m_pos -= UA_GET16(ip) >> 2; ++#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) ++ m_pos -= UA_GET_LE16(ip) >> 2; + #else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); + #endif +@@ -4457,18 +5955,18 @@ match: + #else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +-#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) + if (op - m_pos >= 8) + { + t += (3 - 1); + if (t >= 8) do + { +- UA_COPY64(op,m_pos); ++ UA_COPY8(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } + if (t > 0) +@@ -4478,8 +5976,8 @@ match: + } + } + else +-#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +-#if !defined(LZO_UNALIGNED_OK_4) ++#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) ++#if !(LZO_OPT_UNALIGNED32) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +@@ -4487,10 +5985,10 @@ match: + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { + #endif +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { +- UA_COPY32(op,m_pos); ++ UA_COPY4(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); +@@ -4515,7 +6013,7 @@ match_done: + break; + + match_next: +- assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); ++ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); + #if 0 + do *op++ = *ip++; while (--t > 0); + #else +@@ -4523,16 +6021,10 @@ match_next: + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + #endif + t = *ip++; +- } while (TEST_IP && TEST_OP); ++ } + } + +-#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) +- *out_len = pd(op, out); +- return LZO_E_EOF_NOT_FOUND; +-#endif +- + eof_found: +- assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); +@@ -4559,4 +6051,3 @@ lookbehind_overrun: + #endif + + /***** End of minilzo.c *****/ +- +diff --git a/grub-core/lib/minilzo/lzoconf.h b/grub-core/lib/minilzo/lzoconf.h +index 1d0fe14fcda..61be29c5dc2 100644 +--- a/grub-core/lib/minilzo/lzoconf.h ++++ b/grub-core/lib/minilzo/lzoconf.h +@@ -2,22 +2,7 @@ + + This file is part of the LZO real-time data compression library. + +- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer ++ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or +@@ -44,9 +29,9 @@ + #ifndef __LZOCONF_H_INCLUDED + #define __LZOCONF_H_INCLUDED 1 + +-#define LZO_VERSION 0x2050 +-#define LZO_VERSION_STRING "2.05" +-#define LZO_VERSION_DATE "Apr 23 2011" ++#define LZO_VERSION 0x2080 ++#define LZO_VERSION_STRING "2.08" ++#define LZO_VERSION_DATE "Jun 29 2014" + + /* internal Autoconf configuration file - only used when building LZO */ + #if defined(LZO_HAVE_CONFIG_H) +@@ -63,7 +48,7 @@ + #if !defined(CHAR_BIT) || (CHAR_BIT != 8) + # error "invalid CHAR_BIT" + #endif +-#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) ++#if !defined(UCHAR_MAX) || !defined(USHRT_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) + # error "check your compiler installation" + #endif + #if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) +@@ -85,14 +70,6 @@ extern "C" { + // some core defines + ************************************************************************/ + +-#if !defined(LZO_UINT32_C) +-# if (UINT_MAX < LZO_0xffffffffL) +-# define LZO_UINT32_C(c) c ## UL +-# else +-# define LZO_UINT32_C(c) ((c) + 0U) +-# endif +-#endif +- + /* memory checkers */ + #if !defined(__LZO_CHECKER) + # if defined(__BOUNDS_CHECKING_ON) +@@ -111,28 +88,31 @@ extern "C" { + // integral and pointer types + ************************************************************************/ + +-/* lzo_uint should match size_t */ ++/* lzo_uint must match size_t */ + #if !defined(LZO_UINT_MAX) +-# if defined(LZO_ABI_LLP64) /* WIN64 */ +-# if defined(LZO_OS_WIN64) ++# if (LZO_ABI_LLP64) ++# if (LZO_OS_WIN64) + typedef unsigned __int64 lzo_uint; + typedef __int64 lzo_int; + # else +- typedef unsigned long long lzo_uint; +- typedef long long lzo_int; ++ typedef lzo_ullong_t lzo_uint; ++ typedef lzo_llong_t lzo_int; + # endif ++# define LZO_SIZEOF_LZO_UINT 8 + # define LZO_UINT_MAX 0xffffffffffffffffull + # define LZO_INT_MAX 9223372036854775807LL + # define LZO_INT_MIN (-1LL - LZO_INT_MAX) +-# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ ++# elif (LZO_ABI_IP32L64) /* MIPS R5900 */ + typedef unsigned int lzo_uint; + typedef int lzo_int; ++# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_INT + # define LZO_UINT_MAX UINT_MAX + # define LZO_INT_MAX INT_MAX + # define LZO_INT_MIN INT_MIN + # elif (ULONG_MAX >= LZO_0xffffffffL) + typedef unsigned long lzo_uint; + typedef long lzo_int; ++# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_LONG + # define LZO_UINT_MAX ULONG_MAX + # define LZO_INT_MAX LONG_MAX + # define LZO_INT_MIN LONG_MIN +@@ -141,63 +121,22 @@ extern "C" { + # endif + #endif + +-/* Integral types with 32 bits or more. */ +-#if !defined(LZO_UINT32_MAX) +-# if (UINT_MAX >= LZO_0xffffffffL) +- typedef unsigned int lzo_uint32; +- typedef int lzo_int32; +-# define LZO_UINT32_MAX UINT_MAX +-# define LZO_INT32_MAX INT_MAX +-# define LZO_INT32_MIN INT_MIN +-# elif (ULONG_MAX >= LZO_0xffffffffL) +- typedef unsigned long lzo_uint32; +- typedef long lzo_int32; +-# define LZO_UINT32_MAX ULONG_MAX +-# define LZO_INT32_MAX LONG_MAX +-# define LZO_INT32_MIN LONG_MIN +-# else +-# error "lzo_uint32" +-# endif +-#endif +- +-/* Integral types with exactly 64 bits. */ +-#if !defined(LZO_UINT64_MAX) +-# if (LZO_UINT_MAX >= LZO_0xffffffffL) +-# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3) +-# define lzo_uint64 lzo_uint +-# define lzo_int64 lzo_int +-# define LZO_UINT64_MAX LZO_UINT_MAX +-# define LZO_INT64_MAX LZO_INT_MAX +-# define LZO_INT64_MIN LZO_INT_MIN +-# endif +-# elif (ULONG_MAX >= LZO_0xffffffffL) +-# if ((((ULONG_MAX) >> 31) >> 31) == 3) +- typedef unsigned long lzo_uint64; +- typedef long lzo_int64; +-# define LZO_UINT64_MAX ULONG_MAX +-# define LZO_INT64_MAX LONG_MAX +-# define LZO_INT64_MIN LONG_MIN +-# endif +-# endif +-#endif +- +-/* The larger type of lzo_uint and lzo_uint32. */ +-#if (LZO_UINT_MAX >= LZO_UINT32_MAX) ++/* The larger type of lzo_uint and lzo_uint32_t. */ ++#if (LZO_SIZEOF_LZO_UINT >= 4) + # define lzo_xint lzo_uint + #else +-# define lzo_xint lzo_uint32 ++# define lzo_xint lzo_uint32_t + #endif + +-/* Memory model that allows to access memory at offsets of lzo_uint. */ +-#if !defined(__LZO_MMODEL) +-# if (LZO_UINT_MAX <= UINT_MAX) +-# define __LZO_MMODEL /*empty*/ +-# elif defined(LZO_HAVE_MM_HUGE_PTR) +-# define __LZO_MMODEL_HUGE 1 +-# define __LZO_MMODEL __huge +-# else +-# define __LZO_MMODEL /*empty*/ +-# endif ++typedef int lzo_bool; ++ ++/* sanity checks */ ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == LZO_SIZEOF_LZO_UINT) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t)) ++ ++#ifndef __LZO_MMODEL ++#define __LZO_MMODEL /*empty*/ + #endif + + /* no typedef here because of const-pointer issues */ +@@ -206,21 +145,52 @@ extern "C" { + #define lzo_voidp void __LZO_MMODEL * + #define lzo_shortp short __LZO_MMODEL * + #define lzo_ushortp unsigned short __LZO_MMODEL * +-#define lzo_uint32p lzo_uint32 __LZO_MMODEL * +-#define lzo_int32p lzo_int32 __LZO_MMODEL * +-#if defined(LZO_UINT64_MAX) +-#define lzo_uint64p lzo_uint64 __LZO_MMODEL * +-#define lzo_int64p lzo_int64 __LZO_MMODEL * +-#endif +-#define lzo_uintp lzo_uint __LZO_MMODEL * + #define lzo_intp lzo_int __LZO_MMODEL * ++#define lzo_uintp lzo_uint __LZO_MMODEL * + #define lzo_xintp lzo_xint __LZO_MMODEL * + #define lzo_voidpp lzo_voidp __LZO_MMODEL * + #define lzo_bytepp lzo_bytep __LZO_MMODEL * +-/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ +-#define lzo_byte unsigned char __LZO_MMODEL + +-typedef int lzo_bool; ++#define lzo_int8_tp lzo_int8_t __LZO_MMODEL * ++#define lzo_uint8_tp lzo_uint8_t __LZO_MMODEL * ++#define lzo_int16_tp lzo_int16_t __LZO_MMODEL * ++#define lzo_uint16_tp lzo_uint16_t __LZO_MMODEL * ++#define lzo_int32_tp lzo_int32_t __LZO_MMODEL * ++#define lzo_uint32_tp lzo_uint32_t __LZO_MMODEL * ++#if defined(lzo_int64_t) ++#define lzo_int64_tp lzo_int64_t __LZO_MMODEL * ++#define lzo_uint64_tp lzo_uint64_t __LZO_MMODEL * ++#endif ++ ++/* Older LZO versions used to support ancient systems and memory models ++ * like 16-bit MSDOS with __huge pointers and Cray PVP, but these ++ * obsolete configurations are not supported any longer. ++ */ ++#if defined(__LZO_MMODEL_HUGE) ++#error "__LZO_MMODEL_HUGE is unsupported" ++#endif ++#if (LZO_MM_PVP) ++#error "LZO_MM_PVP is unsupported" ++#endif ++#if (LZO_SIZEOF_INT < 4) ++#error "LZO_SIZEOF_INT < 4 is unsupported" ++#endif ++#if (__LZO_UINTPTR_T_IS_POINTER) ++#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) >= 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) >= 4) ++/* Strange configurations where sizeof(lzo_uint) != sizeof(size_t) should ++ * work but have not received much testing lately, so be strict here. ++ */ ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(size_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(ptrdiff_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(lzo_uintptr_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_uintptr_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_uintptr_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long *) == sizeof(lzo_uintptr_t)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_voidp)) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_bytep)) + + + /*********************************************************************** +@@ -315,7 +285,7 @@ struct lzo_callback_t + /* a progress indicator callback function (set to 0 to disable) */ + lzo_progress_func_t nprogress; + +- /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress ++ /* INFO: the first parameter "self" of the nalloc/nfree/nprogress + * callbacks points back to this struct, so you are free to store + * some extra info in the following variables. */ + lzo_voidp user1; +@@ -343,6 +313,9 @@ struct lzo_callback_t + #define LZO_E_INPUT_NOT_CONSUMED (-8) + #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ + #define LZO_E_INVALID_ARGUMENT (-10) ++#define LZO_E_INVALID_ALIGNMENT (-11) /* pointer argument is not properly aligned */ ++#define LZO_E_OUTPUT_NOT_CONSUMED (-12) ++#define LZO_E_INTERNAL_ERROR (-99) + + + #ifndef lzo_sizeof_dict_t +@@ -356,7 +329,7 @@ struct lzo_callback_t + * compiler's view of various types are consistent. + */ + #define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ +- (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ ++ (int)sizeof(long),(int)sizeof(lzo_uint32_t),(int)sizeof(lzo_uint),\ + (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ + (int)sizeof(lzo_callback_t)) + LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); +@@ -379,18 +352,22 @@ LZO_EXTERN(lzo_voidp) + lzo_memset(lzo_voidp buf, int c, lzo_uint len); + + /* checksum functions */ +-LZO_EXTERN(lzo_uint32) +- lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +-LZO_EXTERN(lzo_uint32) +- lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); +-LZO_EXTERN(const lzo_uint32p) ++LZO_EXTERN(lzo_uint32_t) ++ lzo_adler32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); ++LZO_EXTERN(lzo_uint32_t) ++ lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); ++LZO_EXTERN(const lzo_uint32_tp) + lzo_get_crc32_table(void); + + /* misc. */ + LZO_EXTERN(int) _lzo_config_check(void); +-typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u; +-typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u; +-typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t; ++typedef union { ++ lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04; ++ void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09; ++#if defined(lzo_int64_t) ++ lzo_uint64_t a10; ++#endif ++} lzo_align_t; + + /* align a char pointer on a boundary that is a multiple of 'size' */ + LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); +@@ -399,9 +376,30 @@ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); + + + /*********************************************************************** +-// deprecated macros - only for backward compatibility with LZO v1.xx ++// deprecated macros - only for backward compatibility + ************************************************************************/ + ++/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ ++#define lzo_byte unsigned char ++/* deprecated type names */ ++#define lzo_int32 lzo_int32_t ++#define lzo_uint32 lzo_uint32_t ++#define lzo_int32p lzo_int32_t __LZO_MMODEL * ++#define lzo_uint32p lzo_uint32_t __LZO_MMODEL * ++#define LZO_INT32_MAX LZO_INT32_C(2147483647) ++#define LZO_UINT32_MAX LZO_UINT32_C(4294967295) ++#if defined(lzo_int64_t) ++#define lzo_int64 lzo_int64_t ++#define lzo_uint64 lzo_uint64_t ++#define lzo_int64p lzo_int64_t __LZO_MMODEL * ++#define lzo_uint64p lzo_uint64_t __LZO_MMODEL * ++#define LZO_INT64_MAX LZO_INT64_C(9223372036854775807) ++#define LZO_UINT64_MAX LZO_UINT64_C(18446744073709551615) ++#endif ++/* deprecated types */ ++typedef union { lzo_bytep a; lzo_uint b; } __lzo_pu_u; ++typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u; ++ + #if defined(LZO_CFG_COMPAT) + + #define __LZOCONF_H 1 +@@ -443,4 +441,4 @@ LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); + #endif /* already included */ + + +-/* vim:set ts=4 et: */ ++/* vim:set ts=4 sw=4 et: */ +diff --git a/grub-core/lib/minilzo/lzodefs.h b/grub-core/lib/minilzo/lzodefs.h +index 0e40e332a8d..f4ae9487ebe 100644 +--- a/grub-core/lib/minilzo/lzodefs.h ++++ b/grub-core/lib/minilzo/lzodefs.h +@@ -2,22 +2,7 @@ + + This file is part of the LZO real-time data compression library. + +- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer ++ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or +@@ -47,12 +32,6 @@ + #if defined(__CYGWIN32__) && !defined(__CYGWIN__) + # define __CYGWIN__ __CYGWIN32__ + #endif +-#if defined(__IBMCPP__) && !defined(__IBMC__) +-# define __IBMC__ __IBMCPP__ +-#endif +-#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) +-# define __INTEL_COMPILER __ICL +-#endif + #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) + # define _ALL_SOURCE 1 + #endif +@@ -61,19 +40,30 @@ + # define __LONG_MAX__ 9223372036854775807L + # endif + #endif +-#if defined(__INTEL_COMPILER) && defined(__linux__) ++#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) ++#if defined(__ARMCC_VERSION) ++# pragma diag_suppress 193 ++#elif defined(__clang__) && defined(__clang_minor__) ++# pragma clang diagnostic ignored "-Wundef" ++#elif defined(__INTEL_COMPILER) + # pragma warning(disable: 193) +-#endif +-#if defined(__KEIL__) && defined(__C166__) ++#elif defined(__KEIL__) && defined(__C166__) + # pragma warning disable = 322 +-#elif 0 && defined(__C251__) +-# pragma warning disable = 322 +-#endif +-#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +-# if (_MSC_VER >= 1300) ++#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) ++# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) ++# pragma GCC diagnostic ignored "-Wundef" ++# endif ++#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) ++# if ((_MSC_VER-0) >= 1300) + # pragma warning(disable: 4668) + # endif + #endif ++#endif ++#if 0 && defined(__POCC__) && defined(_WIN32) ++# if (__POCC__ >= 400) ++# pragma warn(disable: 2216) ++# endif ++#endif + #if 0 && defined(__WATCOMC__) + # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) + # pragma warning 203 9 +@@ -82,13 +72,29 @@ + #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) + # pragma option -h + #endif ++#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) ++#ifndef _CRT_NONSTDC_NO_DEPRECATE ++#define _CRT_NONSTDC_NO_DEPRECATE 1 ++#endif ++#ifndef _CRT_NONSTDC_NO_WARNINGS ++#define _CRT_NONSTDC_NO_WARNINGS 1 ++#endif ++#ifndef _CRT_SECURE_NO_DEPRECATE ++#define _CRT_SECURE_NO_DEPRECATE 1 ++#endif ++#ifndef _CRT_SECURE_NO_WARNINGS ++#define _CRT_SECURE_NO_WARNINGS 1 ++#endif ++#endif + #if 0 +-#define LZO_0xffffL 0xfffful +-#define LZO_0xffffffffL 0xfffffffful ++#define LZO_0xffffUL 0xfffful ++#define LZO_0xffffffffUL 0xfffffffful + #else +-#define LZO_0xffffL 65535ul +-#define LZO_0xffffffffL 4294967295ul ++#define LZO_0xffffUL 65535ul ++#define LZO_0xffffffffUL 4294967295ul + #endif ++#define LZO_0xffffL LZO_0xffffUL ++#define LZO_0xffffffffL LZO_0xffffffffUL + #if (LZO_0xffffL == LZO_0xffffffffL) + # error "your preprocessor is broken 1" + #endif +@@ -103,6 +109,13 @@ + # error "your preprocessor is broken 4" + #endif + #endif ++#if defined(__COUNTER__) ++# ifndef LZO_CFG_USE_COUNTER ++# define LZO_CFG_USE_COUNTER 1 ++# endif ++#else ++# undef LZO_CFG_USE_COUNTER ++#endif + #if (UINT_MAX == LZO_0xffffL) + #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) + # if !defined(MSDOS) +@@ -233,14 +246,31 @@ + #endif + #define LZO_PP_STRINGIZE(x) #x + #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) ++#define LZO_PP_CONCAT0() /*empty*/ ++#define LZO_PP_CONCAT1(a) a + #define LZO_PP_CONCAT2(a,b) a ## b + #define LZO_PP_CONCAT3(a,b,c) a ## b ## c + #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d + #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f ++#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g ++#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() ++#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) + #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) + #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) + #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) + #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) ++#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) ++#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) ++#define LZO_PP_EMPTY /*empty*/ ++#define LZO_PP_EMPTY0() /*empty*/ ++#define LZO_PP_EMPTY1(a) /*empty*/ ++#define LZO_PP_EMPTY2(a,b) /*empty*/ ++#define LZO_PP_EMPTY3(a,b,c) /*empty*/ ++#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ ++#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ ++#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ ++#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ + #if 1 + #define LZO_CPP_STRINGIZE(x) #x + #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) +@@ -248,12 +278,16 @@ + #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c + #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d + #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f ++#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g + #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) + #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) + #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) + #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) ++#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) ++#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) + #endif +-#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) ++#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) + #if 1 && defined(__cplusplus) + # if !defined(__STDC_CONSTANT_MACROS) + # define __STDC_CONSTANT_MACROS 1 +@@ -263,9 +297,13 @@ + # endif + #endif + #if defined(__cplusplus) +-# define LZO_EXTERN_C extern "C" ++# define LZO_EXTERN_C extern "C" ++# define LZO_EXTERN_C_BEGIN extern "C" { ++# define LZO_EXTERN_C_END } + #else +-# define LZO_EXTERN_C extern ++# define LZO_EXTERN_C extern ++# define LZO_EXTERN_C_BEGIN /*empty*/ ++# define LZO_EXTERN_C_END /*empty*/ + #endif + #if !defined(__LZO_OS_OVERRIDE) + #if (LZO_OS_FREESTANDING) +@@ -366,12 +404,12 @@ + #elif defined(__VMS) + # define LZO_OS_VMS 1 + # define LZO_INFO_OS "vms" +-#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) + # define LZO_OS_CONSOLE 1 + # define LZO_OS_CONSOLE_PS2 1 + # define LZO_INFO_OS "console" + # define LZO_INFO_OS_CONSOLE "ps2" +-#elif (defined(__mips__) && defined(__psp__)) ++#elif defined(__mips__) && defined(__psp__) + # define LZO_OS_CONSOLE 1 + # define LZO_OS_CONSOLE_PSP 1 + # define LZO_INFO_OS "console" +@@ -399,9 +437,18 @@ + # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) + # define LZO_OS_POSIX_LINUX 1 + # define LZO_INFO_OS_POSIX "linux" +-# elif defined(__APPLE__) || defined(__MACOS__) +-# define LZO_OS_POSIX_MACOSX 1 +-# define LZO_INFO_OS_POSIX "macosx" ++# elif defined(__APPLE__) && defined(__MACH__) ++# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) ++# define LZO_OS_POSIX_DARWIN 1040 ++# define LZO_INFO_OS_POSIX "darwin_iphone" ++# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) ++# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ ++# define LZO_INFO_OS_POSIX "darwin" ++# else ++# define LZO_OS_POSIX_DARWIN 1 ++# define LZO_INFO_OS_POSIX "darwin" ++# endif ++# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN + # elif defined(__minix__) || defined(__minix) + # define LZO_OS_POSIX_MINIX 1 + # define LZO_INFO_OS_POSIX "minix" +@@ -436,18 +483,18 @@ + #endif + #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + # if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) + # if (UINT_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) +@@ -463,59 +510,65 @@ + # define LZO_INFO_CC "sdcc" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) + #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) +-# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) ++# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) + # define LZO_INFO_CC "Pathscale C" + # define LZO_INFO_CCVER __PATHSCALE__ +-#elif defined(__INTEL_COMPILER) +-# define LZO_CC_INTELC 1 ++# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# endif ++#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) ++# define LZO_CC_INTELC __INTEL_COMPILER + # define LZO_INFO_CC "Intel C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) +-# if defined(_WIN32) || defined(_WIN64) +-# define LZO_CC_SYNTAX_MSC 1 +-# else +-# define LZO_CC_SYNTAX_GNUC 1 ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_INTELC_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # endif + #elif defined(__POCC__) && defined(_WIN32) + # define LZO_CC_PELLESC 1 + # define LZO_INFO_CC "Pelles C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) +-#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) + # if defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # else +-# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) + # endif ++# define LZO_CC_ARMCC __ARMCC_VERSION ++# define LZO_INFO_CC "ARM C Compiler" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) + # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) +-# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) ++# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) + # else +-# define LZO_CC_CLANG_CLANG 0x010000L ++# define LZO_CC_CLANG 0x010000L ++# endif ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_CLANG_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # endif +-# define LZO_CC_CLANG LZO_CC_CLANG_GNUC + # define LZO_INFO_CC "clang" + # define LZO_INFO_CCVER __VERSION__ + #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) + # if defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) + # else +-# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) + # endif + # define LZO_CC_LLVM LZO_CC_LLVM_GNUC + # define LZO_INFO_CC "llvm-gcc" + # define LZO_INFO_CCVER __VERSION__ +-#elif defined(__GNUC__) && defined(__VERSION__) +-# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +-# elif defined(__GNUC_MINOR__) +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +-# else +-# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +-# endif +-# define LZO_INFO_CC "gcc" +-# define LZO_INFO_CCVER __VERSION__ + #elif defined(__ACK__) && defined(_ACK) + # define LZO_CC_ACK 1 + # define LZO_INFO_CC "Amsterdam Compiler Kit C" + # define LZO_INFO_CCVER "unknown" ++#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) ++# define LZO_CC_ARMCC __ARMCC_VERSION ++# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION ++# define LZO_INFO_CC "ARM C Compiler" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) + #elif defined(__AZTEC_C__) + # define LZO_CC_AZTECC 1 + # define LZO_INFO_CC "Aztec C" +@@ -540,10 +593,23 @@ + # define LZO_CC_DECC 1 + # define LZO_INFO_CC "DEC C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) ++#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) ++# define LZO_CC_GHS 1 ++# define LZO_INFO_CC "Green Hills C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) ++# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_GHS_MSC _MSC_VER ++# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# endif + #elif defined(__HIGHC__) + # define LZO_CC_HIGHC 1 + # define LZO_INFO_CC "MetaWare High C" + # define LZO_INFO_CCVER "unknown" ++#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) ++# define LZO_CC_HPACC __HP_aCC ++# define LZO_INFO_CC "HP aCC" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) + #elif defined(__IAR_SYSTEMS_ICC__) + # define LZO_CC_IARC 1 + # define LZO_INFO_CC "IAR C" +@@ -552,10 +618,14 @@ + # else + # define LZO_INFO_CCVER "unknown" + # endif +-#elif defined(__IBMC__) +-# define LZO_CC_IBMC 1 ++#elif defined(__IBMC__) && ((__IBMC__-0) > 0) ++# define LZO_CC_IBMC __IBMC__ + # define LZO_INFO_CC "IBM C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) ++#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) ++# define LZO_CC_IBMC __IBMCPP__ ++# define LZO_INFO_CC "IBM C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) + #elif defined(__KEIL__) && defined(__C166__) + # define LZO_CC_KEILC 1 + # define LZO_INFO_CC "Keil C" +@@ -572,16 +642,8 @@ + # else + # define LZO_INFO_CCVER "unknown" + # endif +-#elif defined(_MSC_VER) +-# define LZO_CC_MSC 1 +-# define LZO_INFO_CC "Microsoft C" +-# if defined(_MSC_FULL_VER) +-# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +-# else +-# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +-# endif +-#elif defined(__MWERKS__) +-# define LZO_CC_MWERKS 1 ++#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) ++# define LZO_CC_MWERKS __MWERKS__ + # define LZO_INFO_CC "Metrowerks C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) + #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) +@@ -592,6 +654,15 @@ + # define LZO_CC_PACIFICC 1 + # define LZO_INFO_CC "Pacific C" + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) ++#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) ++# if defined(__PGIC_PATCHLEVEL__) ++# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) ++# else ++# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" ++# endif ++# define LZO_INFO_CC "Portland Group PGI C" + #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) + # define LZO_CC_PGI 1 + # define LZO_INFO_CC "Portland Group PGI C" +@@ -606,7 +677,7 @@ + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) + #elif defined(__SUNPRO_C) + # define LZO_INFO_CC "SunPro C" +-# if ((__SUNPRO_C)+0 > 0) ++# if ((__SUNPRO_C-0) > 0) + # define LZO_CC_SUNPROC __SUNPRO_C + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) + # else +@@ -615,7 +686,7 @@ + # endif + #elif defined(__SUNPRO_CC) + # define LZO_INFO_CC "SunPro C" +-# if ((__SUNPRO_CC)+0 > 0) ++# if ((__SUNPRO_CC-0) > 0) + # define LZO_CC_SUNPROC __SUNPRO_CC + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) + # else +@@ -641,16 +712,46 @@ + #elif defined(__ZTC__) + # define LZO_CC_ZORTECHC 1 + # define LZO_INFO_CC "Zortech C" +-# if (__ZTC__ == 0x310) ++# if ((__ZTC__-0) == 0x310) + # define LZO_INFO_CCVER "0x310" + # else + # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) + # endif ++#elif defined(__GNUC__) && defined(__VERSION__) ++# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) ++# elif defined(__GNUC_MINOR__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) ++# else ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L) ++# endif ++# define LZO_INFO_CC "gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) ++# define LZO_CC_MSC _MSC_VER ++# define LZO_INFO_CC "Microsoft C" ++# if defined(_MSC_FULL_VER) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) ++# endif + #else + # define LZO_CC_UNKNOWN 1 + # define LZO_INFO_CC "unknown" + # define LZO_INFO_CCVER "unknown" + #endif ++#if (LZO_CC_GNUC) && defined(__OPEN64__) ++# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) ++# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) ++# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC ++# endif ++#endif ++#if (LZO_CC_GNUC) && defined(__PCC__) ++# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) ++# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) ++# define LZO_CC_PCC_GNUC LZO_CC_GNUC ++# endif ++#endif + #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) + # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" + #endif +@@ -668,8 +769,10 @@ + # define LZO_INFO_ARCH "generic" + #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + # define LZO_ARCH_I086 1 +-# define LZO_ARCH_IA16 1 + # define LZO_INFO_ARCH "i086" ++#elif defined(__aarch64__) ++# define LZO_ARCH_ARM64 1 ++# define LZO_INFO_ARCH "arm64" + #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) + # define LZO_ARCH_ALPHA 1 + # define LZO_INFO_ARCH "alpha" +@@ -685,10 +788,10 @@ + # define LZO_INFO_ARCH "arm_thumb" + #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) + # define LZO_ARCH_ARM 1 +-# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) ++# if defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 1) + # define LZO_ARCH_ARM_THUMB 1 + # define LZO_INFO_ARCH "arm_thumb" +-# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) ++# elif defined(__CPU_MODE__) && ((__CPU_MODE__-0) == 2) + # define LZO_INFO_ARCH "arm" + # else + # define LZO_INFO_ARCH "arm" +@@ -806,53 +909,147 @@ + # error "FIXME - missing define for CPU architecture" + #endif + #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) +-# error "FIXME - missing WIN32 define for CPU architecture" ++# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" + #endif + #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) +-# error "FIXME - missing WIN64 define for CPU architecture" ++# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" + #endif + #if (LZO_OS_OS216 || LZO_OS_WIN16) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) + # define LZO_ARCH_I086PM 1 +-# define LZO_ARCH_IA16PM 1 + #endif +-#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) +-# error "this should not happen" ++#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) ++# define LZO_ARCH_X64 1 ++#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_AMD64 1 + #endif +-#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) +-# error "this should not happen" ++#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) ++# define LZO_ARCH_AARCH64 1 ++#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_ARM64 1 ++#endif ++#if (LZO_ARCH_I386 && !LZO_ARCH_X86) ++# define LZO_ARCH_X86 1 ++#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) ++# define LZO_ARCH_I386 1 ++#endif ++#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB && !LZO_ARCH_ARM) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM_THUMB) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM_THUMB) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) ++# error "unexpected configuration - check your compiler defines" + #endif + #if (LZO_ARCH_I086) + # if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #if (LZO_ARCH_I386) + # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + # if (ULONG_MAX != LZO_0xffffffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif +-#if !defined(__LZO_MM_OVERRIDE) ++#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++# if !defined(LZO_TARGET_FEATURE_SSE2) ++# if defined(__SSE2__) ++# define LZO_TARGET_FEATURE_SSE2 1 ++# elif defined(_MSC_VER) && ((defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) || defined(_M_AMD64)) ++# define LZO_TARGET_FEATURE_SSE2 1 ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_SSSE3) ++# if (LZO_TARGET_FEATURE_SSE2) ++# if defined(__SSSE3__) ++# define LZO_TARGET_FEATURE_SSSE3 1 ++# elif defined(_MSC_VER) && defined(__AVX__) ++# define LZO_TARGET_FEATURE_SSSE3 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_SSE4_2) ++# if (LZO_TARGET_FEATURE_SSSE3) ++# if defined(__SSE4_2__) ++# define LZO_TARGET_FEATURE_SSE4_2 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_AVX) ++# if (LZO_TARGET_FEATURE_SSSE3) ++# if defined(__AVX__) ++# define LZO_TARGET_FEATURE_AVX 1 ++# endif ++# endif ++# endif ++# if !defined(LZO_TARGET_FEATURE_AVX2) ++# if (LZO_TARGET_FEATURE_AVX) ++# if defined(__AVX2__) ++# define LZO_TARGET_FEATURE_AVX2 1 ++# endif ++# endif ++# endif ++#endif ++#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if (LZO_ARCH_ARM) ++# if !defined(LZO_TARGET_FEATURE_NEON) ++# if defined(__ARM_NEON__) ++# define LZO_TARGET_FEATURE_NEON 1 ++# endif ++# endif ++#elif (LZO_ARCH_ARM64) ++# if !defined(LZO_TARGET_FEATURE_NEON) ++# if 1 ++# define LZO_TARGET_FEATURE_NEON 1 ++# endif ++# endif ++#endif ++#if 0 ++#elif !defined(__LZO_MM_OVERRIDE) + #if (LZO_ARCH_I086) + #if (UINT_MAX != LZO_0xffffL) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + #endif + #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) + # define LZO_MM_TINY 1 +@@ -879,7 +1076,7 @@ + #elif (LZO_CC_ZORTECHC && defined(__VCM__)) + # define LZO_MM_LARGE 1 + #else +-# error "unknown memory model" ++# error "unknown LZO_ARCH_I086 memory model" + #endif + #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) + #define LZO_HAVE_MM_HUGE_PTR 1 +@@ -902,10 +1099,10 @@ + #endif + #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) + # if (LZO_OS_DOS16) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # elif (LZO_CC_ZORTECHC) + # else +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + # endif + #endif + #ifdef __cplusplus +@@ -937,7 +1134,7 @@ extern "C" { + #endif + #elif (LZO_ARCH_C166) + #if !defined(__MODEL__) +-# error "FIXME - C166 __MODEL__" ++# error "FIXME - LZO_ARCH_C166 __MODEL__" + #elif ((__MODEL__) == 0) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 1) +@@ -951,11 +1148,11 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - C166 __MODEL__" ++# error "FIXME - LZO_ARCH_C166 __MODEL__" + #endif + #elif (LZO_ARCH_MCS251) + #if !defined(__MODEL__) +-# error "FIXME - MCS251 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS251 __MODEL__" + #elif ((__MODEL__) == 0) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 2) +@@ -967,11 +1164,11 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - MCS251 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS251 __MODEL__" + #endif + #elif (LZO_ARCH_MCS51) + #if !defined(__MODEL__) +-# error "FIXME - MCS51 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS51 __MODEL__" + #elif ((__MODEL__) == 1) + # define LZO_MM_SMALL 1 + #elif ((__MODEL__) == 2) +@@ -983,7 +1180,7 @@ extern "C" { + #elif ((__MODEL__) == 5) + # define LZO_MM_XSMALL 1 + #else +-# error "FIXME - MCS51 __MODEL__" ++# error "FIXME - LZO_ARCH_MCS51 __MODEL__" + #endif + #elif (LZO_ARCH_CRAY_PVP) + # define LZO_MM_PVP 1 +@@ -1010,35 +1207,818 @@ extern "C" { + # error "unknown memory model" + #endif + #endif ++#if !defined(__lzo_gnuc_extension__) ++#if (LZO_CC_GNUC >= 0x020800ul) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_gnuc_extension__ __extension__ ++#else ++#endif ++#endif ++#if !defined(__lzo_gnuc_extension__) ++# define __lzo_gnuc_extension__ /*empty*/ ++#endif ++#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 ++# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++# else ++# define LZO_CFG_USE_NEW_STYLE_CASTS 1 ++# endif ++#endif ++#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++#endif ++#if !defined(__cplusplus) ++# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) ++# undef LZO_CFG_USE_NEW_STYLE_CASTS ++# endif ++# define LZO_CFG_USE_NEW_STYLE_CASTS 0 ++#endif ++#if !defined(LZO_REINTERPRET_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) ++# endif ++#endif ++#if !defined(LZO_REINTERPRET_CAST) ++# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) ++#endif ++#if !defined(LZO_STATIC_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_STATIC_CAST(t,e) (static_cast (e)) ++# endif ++#endif ++#if !defined(LZO_STATIC_CAST) ++# define LZO_STATIC_CAST(t,e) ((t) (e)) ++#endif ++#if !defined(LZO_STATIC_CAST2) ++# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNCONST_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNCONST_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) ++#endif ++#if !defined(LZO_UNCONST_VOLATILE_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNCONST_VOLATILE_CAST) ++# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) ++#endif ++#if !defined(LZO_UNVOLATILE_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNVOLATILE_CAST) ++# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) ++#endif ++#if !defined(LZO_UNVOLATILE_CONST_CAST) ++# if (LZO_CFG_USE_NEW_STYLE_CASTS) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) ++# elif (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) ++# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_UNVOLATILE_CONST_CAST) ++# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) ++#endif ++#if !defined(LZO_PCAST) ++# if (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_PCAST(t,e) ((t) (e)) ++# endif ++#endif ++#if !defined(LZO_PCAST) ++# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) ++#endif ++#if !defined(LZO_CCAST) ++# if (LZO_HAVE_MM_HUGE_PTR) ++# define LZO_CCAST(t,e) ((t) (e)) ++# endif ++#endif ++#if !defined(LZO_CCAST) ++# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) ++#endif ++#if !defined(LZO_ICONV) ++# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(LZO_ICAST) ++# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(LZO_ITRUNC) ++# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) ++#endif ++#if !defined(__lzo_cte) ++# if (LZO_CC_MSC || LZO_CC_WATCOMC) ++# define __lzo_cte(e) ((void)0,(e)) ++# elif 1 ++# define __lzo_cte(e) ((void)0,(e)) ++# endif ++#endif ++#if !defined(__lzo_cte) ++# define __lzo_cte(e) (e) ++#endif ++#if !defined(LZO_BLOCK_BEGIN) ++# define LZO_BLOCK_BEGIN do { ++# define LZO_BLOCK_END } while __lzo_cte(0) ++#endif ++#if !defined(LZO_UNUSED) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNUSED(var) ((void) var) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_KEILC) ++# define LZO_UNUSED(var) {LZO_EXTERN_C int lzo_unused__[1-2*!(sizeof(var)>0)];} ++# elif (LZO_CC_PACIFICC) ++# define LZO_UNUSED(var) ((void) sizeof(var)) ++# elif (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED(var) ((void) var) ++# else ++# define LZO_UNUSED(var) ((void) &var) ++# endif ++#endif ++#if !defined(LZO_UNUSED_FUNC) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_MSC) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_KEILC || LZO_CC_PELLESC) ++# define LZO_UNUSED_FUNC(func) {LZO_EXTERN_C int lzo_unused_func__[1-2*!(sizeof((int)func)>0)];} ++# else ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# endif ++#endif ++#if !defined(LZO_UNUSED_LABEL) ++# if (LZO_CC_CLANG >= 0x020800ul) ++# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) ++# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) ++# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l ++# else ++# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l ++# endif ++#endif ++#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) ++# if 0 ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var ++# elif 0 && (LZO_CC_GNUC) ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var ++# else ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init ++# endif ++#endif ++#if !defined(__lzo_inline) ++#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) ++#elif defined(__cplusplus) ++# define __lzo_inline inline ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) ++# define __lzo_inline inline ++#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) ++# define __lzo_inline __inline ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_DMC) ++# define __lzo_inline __inline ++#elif (LZO_CC_GHS) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_INTELC) ++# define __lzo_inline __inline ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) ++# define __lzo_inline __inline ++#elif (LZO_CC_MSC && (_MSC_VER >= 900)) ++# define __lzo_inline __inline ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_inline __inline__ ++#endif ++#endif ++#if defined(__lzo_inline) ++# ifndef __lzo_HAVE_inline ++# define __lzo_HAVE_inline 1 ++# endif ++#else ++# define __lzo_inline /*empty*/ ++#endif ++#if !defined(__lzo_forceinline) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#endif ++#endif ++#if defined(__lzo_forceinline) ++# ifndef __lzo_HAVE_forceinline ++# define __lzo_HAVE_forceinline 1 ++# endif ++#else ++# define __lzo_forceinline __lzo_inline ++#endif ++#if !defined(__lzo_noinline) ++#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) ++# define __lzo_noinline __attribute__((__noinline__,__used__)) ++#elif (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) ++# if defined(__cplusplus) ++# else ++# define __lzo_noinline __declspec(noinline) ++# endif ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_noinline __attribute__((__noinline__)) ++#endif ++#endif ++#if defined(__lzo_noinline) ++# ifndef __lzo_HAVE_noinline ++# define __lzo_HAVE_noinline 1 ++# endif ++#else ++# define __lzo_noinline /*empty*/ ++#endif ++#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if !defined(__lzo_static_inline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline ++#endif ++#endif ++#if !defined(__lzo_static_inline) ++# define __lzo_static_inline static __lzo_inline ++#endif ++#if !defined(__lzo_static_forceinline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline ++#endif ++#endif ++#if !defined(__lzo_static_forceinline) ++# define __lzo_static_forceinline static __lzo_forceinline ++#endif ++#if !defined(__lzo_static_noinline) ++#if (LZO_CC_IBMC) ++# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline ++#endif ++#endif ++#if !defined(__lzo_static_noinline) ++# define __lzo_static_noinline static __lzo_noinline ++#endif ++#if !defined(__lzo_c99_extern_inline) ++#if defined(__GNUC_GNU_INLINE__) ++# define __lzo_c99_extern_inline __lzo_inline ++#elif defined(__GNUC_STDC_INLINE__) ++# define __lzo_c99_extern_inline extern __lzo_inline ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) ++# define __lzo_c99_extern_inline extern __lzo_inline ++#endif ++#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) ++# define __lzo_c99_extern_inline __lzo_inline ++#endif ++#endif ++#if defined(__lzo_c99_extern_inline) ++# ifndef __lzo_HAVE_c99_extern_inline ++# define __lzo_HAVE_c99_extern_inline 1 ++# endif ++#else ++# define __lzo_c99_extern_inline /*empty*/ ++#endif ++#if !defined(__lzo_may_alias) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_CLANG >= 0x020900ul) ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 ++# define __lzo_may_alias __attribute__((__may_alias__)) ++#endif ++#endif ++#if defined(__lzo_may_alias) ++# ifndef __lzo_HAVE_may_alias ++# define __lzo_HAVE_may_alias 1 ++# endif ++#else ++# define __lzo_may_alias /*empty*/ ++#endif ++#if !defined(__lzo_noreturn) ++#if (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#endif ++#endif ++#if defined(__lzo_noreturn) ++# ifndef __lzo_HAVE_noreturn ++# define __lzo_HAVE_noreturn 1 ++# endif ++#else ++# define __lzo_noreturn /*empty*/ ++#endif ++#if !defined(__lzo_nothrow) ++#if (LZO_CC_GNUC >= 0x030300ul) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#endif ++#endif ++#if defined(__lzo_nothrow) ++# ifndef __lzo_HAVE_nothrow ++# define __lzo_HAVE_nothrow 1 ++# endif ++#else ++# define __lzo_nothrow /*empty*/ ++#endif ++#if !defined(__lzo_restrict) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_IBMC >= 1210) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define __lzo_restrict __restrict ++#elif (LZO_CC_PGI >= 0x0d0a00ul) ++# define __lzo_restrict __restrict__ ++#endif ++#endif ++#if defined(__lzo_restrict) ++# ifndef __lzo_HAVE_restrict ++# define __lzo_HAVE_restrict 1 ++# endif ++#else ++# define __lzo_restrict /*empty*/ ++#endif ++#if !defined(__lzo_alignof) ++#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_GHS) && !defined(__cplusplus) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_IBMC >= 600) ++# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_alignof(e) __alignof(e) ++#elif (LZO_CC_SUNPROC >= 0x5100) ++# define __lzo_alignof(e) __alignof__(e) ++#endif ++#endif ++#if defined(__lzo_alignof) ++# ifndef __lzo_HAVE_alignof ++# define __lzo_HAVE_alignof 1 ++# endif ++#endif ++#if !defined(__lzo_struct_packed) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) ++#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) ++# define __lzo_struct_packed(s) struct s { ++# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_struct_packed(s) struct s { ++# define __lzo_struct_packed_end() } __attribute__((__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { ++# define __lzo_struct_packed_end() } __attribute__((__packed__)); ++# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { ++# define __lzo_struct_packed_end() } __pragma(pack(pop)); ++#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) ++# define __lzo_struct_packed(s) _Packed struct s { ++# define __lzo_struct_packed_end() }; ++#endif ++#endif ++#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) ++# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) ++#endif ++#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) ++# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() ++#endif ++#if !defined(__lzo_byte_struct) ++#if defined(__lzo_struct_packed) ++# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() ++# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() ++#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); ++# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); ++#endif ++#endif ++#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) ++# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) ++#endif ++#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) ++#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) ++#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_CILLY || LZO_CC_PCC) ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_struct_align16(s) struct __declspec(align(16)) s { ++# define __lzo_struct_align16_end() }; ++# define __lzo_struct_align32(s) struct __declspec(align(32)) s { ++# define __lzo_struct_align32_end() }; ++# define __lzo_struct_align64(s) struct __declspec(align(64)) s { ++# define __lzo_struct_align64_end() }; ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_struct_align16(s) struct s { ++# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); ++# define __lzo_struct_align32(s) struct s { ++# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); ++# define __lzo_struct_align64(s) struct s { ++# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); ++#endif ++#endif ++#if !defined(__lzo_union_um) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) ++#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) ++#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) ++#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_union_am(s) union s { ++# define __lzo_union_am_end() } __lzo_may_alias; ++# define __lzo_union_um(s) union s { ++# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_IBMC >= 700) ++# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { ++# define __lzo_union_am_end() } __lzo_may_alias; ++# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { ++# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); ++#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_union_um(s) __pragma(pack(push,1)) union s { ++# define __lzo_union_um_end() } __pragma(pack(pop)); ++#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) ++# define __lzo_union_um(s) _Packed union s { ++# define __lzo_union_um_end() }; ++#endif ++#endif ++#if !defined(__lzo_union_am) ++# define __lzo_union_am(s) union s { ++# define __lzo_union_am_end() }; ++#endif ++#if !defined(__lzo_constructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_constructor __attribute__((__constructor__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_constructor __attribute__((__constructor__)) ++#endif ++#endif ++#if defined(__lzo_constructor) ++# ifndef __lzo_HAVE_constructor ++# define __lzo_HAVE_constructor 1 ++# endif ++#endif ++#if !defined(__lzo_destructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_destructor __attribute__((__destructor__)) ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_destructor __attribute__((__destructor__)) ++#endif ++#endif ++#if defined(__lzo_destructor) ++# ifndef __lzo_HAVE_destructor ++# define __lzo_HAVE_destructor 1 ++# endif ++#endif ++#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) ++# error "unexpected configuration - check your compiler defines" ++#endif ++#if !defined(__lzo_likely) && !defined(__lzo_unlikely) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_IBMC >= 1010) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#endif ++#endif ++#if defined(__lzo_likely) ++# ifndef __lzo_HAVE_likely ++# define __lzo_HAVE_likely 1 ++# endif ++#else ++# define __lzo_likely(e) (e) ++#endif ++#if defined(__lzo_unlikely) ++# ifndef __lzo_HAVE_unlikely ++# define __lzo_HAVE_unlikely 1 ++# endif ++#else ++# define __lzo_unlikely(e) (e) ++#endif ++#if !defined(__lzo_static_unused_void_func) ++# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_static_unused_void_func(f) static void __attribute__((__unused__)) f(void) ++# else ++# define __lzo_static_unused_void_func(f) static __lzo_inline void f(void) ++# endif ++#endif ++#if !defined(__lzo_loop_forever) ++# if (LZO_CC_IBMC) ++# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END ++# else ++# define __lzo_loop_forever() do { ; } while __lzo_cte(1) ++# endif ++#endif ++#if !defined(__lzo_unreachable) ++#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) ++# define __lzo_unreachable() __builtin_unreachable(); ++#elif (LZO_CC_GNUC >= 0x040500ul) ++# define __lzo_unreachable() __builtin_unreachable(); ++#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 ++# define __lzo_unreachable() __builtin_unreachable(); ++#endif ++#endif ++#if defined(__lzo_unreachable) ++# ifndef __lzo_HAVE_unreachable ++# define __lzo_HAVE_unreachable 1 ++# endif ++#else ++# if 0 ++# define __lzo_unreachable() ((void)0); ++# else ++# define __lzo_unreachable() __lzo_loop_forever(); ++# endif ++#endif ++#ifndef __LZO_CTA_NAME ++#if (LZO_CFG_USE_COUNTER) ++# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) ++#else ++# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) ++#endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) ++# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END ++# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END ++# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END ++# else ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT) ++# if (LZO_CC_AZTECC) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} ++# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) ++# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} ++# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) ++# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} ++# elif (LZO_CC_GNUC >= 0x040700ul) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# else ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} ++# endif ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) ++#if defined(__cplusplus) ++extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) ++#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit /*empty*/ ++# define __lzo_cdecl_main __cdecl ++# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_qsort __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_qsort _stdcall ++# else ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# elif (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++# else ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit __cdecl ++# define __lzo_cdecl_main __cdecl ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) ++# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_sighandler __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_sighandler _stdcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) ++# define __lzo_cdecl_sighandler __clrcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) ++# if defined(_DLL) ++# define __lzo_cdecl_sighandler _far _cdecl _loadds ++# elif defined(_MT) ++# define __lzo_cdecl_sighandler _far _cdecl ++# else ++# define __lzo_cdecl_sighandler _cdecl ++# endif ++# else ++# define __lzo_cdecl_sighandler __cdecl ++# endif ++#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) ++# define __lzo_cdecl cdecl ++#endif ++#if !defined(__lzo_cdecl) ++# define __lzo_cdecl /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_atexit) ++# define __lzo_cdecl_atexit /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_main) ++# define __lzo_cdecl_main /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_qsort) ++# define __lzo_cdecl_qsort /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_sighandler) ++# define __lzo_cdecl_sighandler /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_va) ++# define __lzo_cdecl_va __lzo_cdecl ++#endif ++#if !(LZO_CFG_NO_WINDOWS_H) ++#if !defined(LZO_HAVE_WINDOWS_H) ++#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) ++# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) ++# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) ++# else ++# define LZO_HAVE_WINDOWS_H 1 ++# endif ++#endif ++#endif ++#endif ++#ifndef LZO_SIZEOF_SHORT + #if defined(SIZEOF_SHORT) + # define LZO_SIZEOF_SHORT (SIZEOF_SHORT) ++#elif defined(__SIZEOF_SHORT__) ++# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) + #endif ++#endif ++#ifndef LZO_SIZEOF_INT + #if defined(SIZEOF_INT) + # define LZO_SIZEOF_INT (SIZEOF_INT) ++#elif defined(__SIZEOF_INT__) ++# define LZO_SIZEOF_INT (__SIZEOF_INT__) + #endif ++#endif ++#ifndef LZO_SIZEOF_LONG + #if defined(SIZEOF_LONG) + # define LZO_SIZEOF_LONG (SIZEOF_LONG) ++#elif defined(__SIZEOF_LONG__) ++# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) + #endif ++#endif ++#ifndef LZO_SIZEOF_LONG_LONG + #if defined(SIZEOF_LONG_LONG) + # define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) ++#elif defined(__SIZEOF_LONG_LONG__) ++# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT16 + #if defined(SIZEOF___INT16) + # define LZO_SIZEOF___INT16 (SIZEOF___INT16) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT32 + #if defined(SIZEOF___INT32) + # define LZO_SIZEOF___INT32 (SIZEOF___INT32) + #endif ++#endif ++#ifndef LZO_SIZEOF___INT64 + #if defined(SIZEOF___INT64) + # define LZO_SIZEOF___INT64 (SIZEOF___INT64) + #endif ++#endif ++#ifndef LZO_SIZEOF_VOID_P + #if defined(SIZEOF_VOID_P) + # define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) ++#elif defined(__SIZEOF_POINTER__) ++# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) + #endif ++#endif ++#ifndef LZO_SIZEOF_SIZE_T + #if defined(SIZEOF_SIZE_T) + # define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) ++#elif defined(__SIZEOF_SIZE_T__) ++# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) + #endif ++#endif ++#ifndef LZO_SIZEOF_PTRDIFF_T + #if defined(SIZEOF_PTRDIFF_T) + # define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) ++#elif defined(__SIZEOF_PTRDIFF_T__) ++# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) ++#endif + #endif + #define __LZO_LSR(x,b) (((x)+0ul) >> (b)) + #if !defined(LZO_SIZEOF_SHORT) +@@ -1060,6 +2040,7 @@ extern "C" { + # error "LZO_SIZEOF_SHORT" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) + #if !defined(LZO_SIZEOF_INT) + # if (LZO_ARCH_CRAY_PVP) + # define LZO_SIZEOF_INT 8 +@@ -1081,6 +2062,7 @@ extern "C" { + # error "LZO_SIZEOF_INT" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) + #if !defined(LZO_SIZEOF_LONG) + # if (ULONG_MAX == LZO_0xffffffffL) + # define LZO_SIZEOF_LONG 4 +@@ -1090,6 +2072,8 @@ extern "C" { + # define LZO_SIZEOF_LONG 2 + # elif (__LZO_LSR(ULONG_MAX,31) == 1) + # define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,39) == 1) ++# define LZO_SIZEOF_LONG 5 + # elif (__LZO_LSR(ULONG_MAX,63) == 1) + # define LZO_SIZEOF_LONG 8 + # elif (__LZO_LSR(ULONG_MAX,127) == 1) +@@ -1098,11 +2082,12 @@ extern "C" { + # error "LZO_SIZEOF_LONG" + # endif + #endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) + #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) + #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) + # if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) + # if (LZO_CC_GNUC >= 0x030300ul) +-# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) ++# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) + # define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG + # elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) + # define LZO_SIZEOF_LONG_LONG 4 +@@ -1116,7 +2101,7 @@ extern "C" { + #if (LZO_ARCH_I086 && LZO_CC_DMC) + #elif (LZO_CC_CILLY) && defined(__GNUC__) + # define LZO_SIZEOF_LONG_LONG 8 +-#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) + # define LZO_SIZEOF_LONG_LONG 8 + #elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) + # define LZO_SIZEOF_LONG_LONG 8 +@@ -1138,11 +2123,13 @@ extern "C" { + # define LZO_SIZEOF___INT64 8 + #elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) + # define LZO_SIZEOF___INT64 8 +-#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) ++#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) + # define LZO_SIZEOF___INT64 8 + #elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) + # define LZO_SIZEOF_LONG_LONG 8 +-#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) + # define LZO_SIZEOF_LONG_LONG 8 + #elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) + #elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +@@ -1155,87 +2142,127 @@ extern "C" { + # undef LZO_SIZEOF_LONG_LONG + # endif + #endif +-#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) ++#if (LZO_CFG_NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#elif defined(__NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#elif defined(_NO_LONGLONG) + # undef LZO_SIZEOF_LONG_LONG + #endif +-#if !defined(LZO_SIZEOF_VOID_P) +-#if (LZO_ARCH_I086) +-# define __LZO_WORDSIZE 2 +-# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +-# define LZO_SIZEOF_VOID_P 2 +-# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +-# define LZO_SIZEOF_VOID_P 4 ++#if !defined(LZO_WORDSIZE) ++#if (LZO_ARCH_ALPHA) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_AMD64) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_AVR) ++# define LZO_WORDSIZE 1 ++#elif (LZO_ARCH_H8300) ++# if defined(__NORMAL_MODE__) ++# define LZO_WORDSIZE 4 ++# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define LZO_WORDSIZE 4 + # else +-# error "LZO_MM" ++# define LZO_WORDSIZE 2 + # endif +-#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) +-# define __LZO_WORDSIZE 1 ++#elif (LZO_ARCH_I086) ++# define LZO_WORDSIZE 2 ++#elif (LZO_ARCH_IA64) ++# define LZO_WORDSIZE 8 ++#elif (LZO_ARCH_M16C) ++# define LZO_WORDSIZE 2 ++#elif (LZO_ARCH_SPU) ++# define LZO_WORDSIZE 4 ++#elif (LZO_ARCH_Z80) ++# define LZO_WORDSIZE 1 ++#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define LZO_WORDSIZE 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) ++# define LZO_WORDSIZE 8 ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_WORDSIZE 8 ++#endif ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) ++# define LZO_SIZEOF_VOID_P 4 ++#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) ++# define LZO_SIZEOF_VOID_P 8 ++#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) ++# define LZO_SIZEOF_VOID_P 8 ++#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) ++# define LZO_SIZEOF_VOID_P 8 ++#elif (LZO_ARCH_AVR) + # define LZO_SIZEOF_VOID_P 2 + #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) + # define LZO_SIZEOF_VOID_P 2 + #elif (LZO_ARCH_H8300) + # if defined(__NORMAL_MODE__) +-# define __LZO_WORDSIZE 4 + # define LZO_SIZEOF_VOID_P 2 + # elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +-# define __LZO_WORDSIZE 4 + # define LZO_SIZEOF_VOID_P 4 + # else +-# define __LZO_WORDSIZE 2 + # define LZO_SIZEOF_VOID_P 2 + # endif + # if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) + # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT + # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT + # endif ++#elif (LZO_ARCH_I086) ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) ++# define LZO_SIZEOF_VOID_P 2 ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# error "invalid LZO_ARCH_I086 memory model" ++# endif + #elif (LZO_ARCH_M16C) +-# define __LZO_WORDSIZE 2 + # if defined(__m32c_cpu__) || defined(__m32cm_cpu__) + # define LZO_SIZEOF_VOID_P 4 + # else + # define LZO_SIZEOF_VOID_P 2 + # endif ++#elif (LZO_ARCH_SPU) ++# define LZO_SIZEOF_VOID_P 4 ++#elif (LZO_ARCH_Z80) ++# define LZO_SIZEOF_VOID_P 2 + #elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +-# define __LZO_WORDSIZE 8 + # define LZO_SIZEOF_VOID_P 4 +-#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +-# define __LZO_WORDSIZE 8 +-# define LZO_SIZEOF_VOID_P 8 +-#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +-# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + #elif (LZO_OS_OS400 || defined(__OS400__)) +-# define __LZO_WORDSIZE LZO_SIZEOF_LONG +-# define LZO_SIZEOF_VOID_P 16 +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +-#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +-# define LZO_SIZEOF_VOID_P 8 +-# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +-# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +-#elif (LZO_ARCH_SPU) +-# if 0 +-# define __LZO_WORDSIZE 16 +-# endif +-# define LZO_SIZEOF_VOID_P 4 +-#else +-# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +-#endif +-#endif +-#if !defined(LZO_WORDSIZE) +-# if defined(__LZO_WORDSIZE) +-# define LZO_WORDSIZE __LZO_WORDSIZE ++# if defined(__LLP64_IFC__) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + # else +-# define LZO_WORDSIZE LZO_SIZEOF_VOID_P ++# define LZO_SIZEOF_VOID_P 16 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + # endif ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG + #endif ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) + #if !defined(LZO_SIZEOF_SIZE_T) + #if (LZO_ARCH_I086 || LZO_ARCH_M16C) + # define LZO_SIZEOF_SIZE_T 2 +-#else ++#endif ++#endif ++#if !defined(LZO_SIZEOF_SIZE_T) + # define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P + #endif ++#if defined(offsetof) ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) + #endif + #if !defined(LZO_SIZEOF_PTRDIFF_T) + #if (LZO_ARCH_I086) +@@ -1248,11 +2275,18 @@ extern "C" { + # define LZO_SIZEOF_PTRDIFF_T 2 + # endif + # else +-# error "LZO_MM" ++# error "invalid LZO_ARCH_I086 memory model" + # endif +-#else ++#endif ++#endif ++#if !defined(LZO_SIZEOF_PTRDIFF_T) + # define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T + #endif ++#if defined(offsetof) ++LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) ++#endif ++#if !defined(LZO_WORDSIZE) ++# define LZO_WORDSIZE LZO_SIZEOF_VOID_P + #endif + #if (LZO_ABI_NEUTRAL_ENDIAN) + # undef LZO_ABI_BIG_ENDIAN +@@ -1264,7 +2298,7 @@ extern "C" { + # define LZO_ABI_LITTLE_ENDIAN 1 + #elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) + # define LZO_ABI_LITTLE_ENDIAN 1 +-#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) ++#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) + # if (__LITTLE_ENDIAN__ == 1) +@@ -1280,6 +2314,19 @@ extern "C" { + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) + # define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) ++# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) ++# error "unexpected configuration - check your compiler defines" ++# elif defined(__BIG_ENDIAN) ++# define LZO_ABI_BIG_ENDIAN 1 ++# else ++# define LZO_ABI_LITTLE_ENDIAN 1 ++# endif ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 + #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) + # define LZO_ABI_BIG_ENDIAN 1 + #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +@@ -1287,7 +2334,7 @@ extern "C" { + #endif + #endif + #if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +-# error "this should not happen" ++# error "unexpected configuration - check your compiler defines" + #endif + #if (LZO_ABI_BIG_ENDIAN) + # define LZO_INFO_ABI_ENDIAN "be" +@@ -1302,6 +2349,9 @@ extern "C" { + #elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) + # define LZO_ABI_ILP16 1 + # define LZO_INFO_ABI_PM "ilp16" ++#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_LP32 1 ++# define LZO_INFO_ABI_PM "lp32" + #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) + # define LZO_ABI_ILP32 1 + # define LZO_INFO_ABI_PM "ilp32" +@@ -1318,7 +2368,8 @@ extern "C" { + # define LZO_ABI_IP32L64 1 + # define LZO_INFO_ABI_PM "ip32l64" + #endif +-#if !defined(__LZO_LIBC_OVERRIDE) ++#if 0 ++#elif !defined(__LZO_LIBC_OVERRIDE) + #if (LZO_LIBC_NAKED) + # define LZO_INFO_LIBC "naked" + #elif (LZO_LIBC_FREESTANDING) +@@ -1329,6 +2380,9 @@ extern "C" { + # define LZO_INFO_LIBC "isoc90" + #elif (LZO_LIBC_ISOC99) + # define LZO_INFO_LIBC "isoc99" ++#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) ++# define LZO_LIBC_ISOC90 1 ++# define LZO_INFO_LIBC "isoc90" + #elif defined(__dietlibc__) + # define LZO_LIBC_DIETLIBC 1 + # define LZO_INFO_LIBC "dietlibc" +@@ -1337,13 +2391,13 @@ extern "C" { + # define LZO_INFO_LIBC "newlib" + #elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) + # if defined(__UCLIBC_SUBLEVEL__) +-# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) ++# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) + # else + # define LZO_LIBC_UCLIBC 0x00090bL + # endif +-# define LZO_INFO_LIBC "uclibc" ++# define LZO_INFO_LIBC "uc" "libc" + #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +-# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) ++# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) + # define LZO_INFO_LIBC "glibc" + #elif (LZO_CC_MWERKS) && defined(__MSL__) + # define LZO_LIBC_MSL __MSL__ +@@ -1356,423 +2410,159 @@ extern "C" { + # define LZO_INFO_LIBC "default" + #endif + #endif +-#if !defined(__lzo_gnuc_extension__) +-#if (LZO_CC_GNUC >= 0x020800ul) +-# define __lzo_gnuc_extension__ __extension__ +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_gnuc_extension__ __extension__ +-#else +-# define __lzo_gnuc_extension__ /*empty*/ +-#endif +-#endif +-#if !defined(__lzo_ua_volatile) +-# define __lzo_ua_volatile volatile +-#endif +-#if !defined(__lzo_alignof) +-#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +-# define __lzo_alignof(e) __alignof__(e) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +-# define __lzo_alignof(e) __alignof__(e) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +-# define __lzo_alignof(e) __alignof(e) +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_alignof(e) __alignof__(e) +-#endif +-#endif +-#if defined(__lzo_alignof) +-# define __lzo_HAVE_alignof 1 +-#endif +-#if !defined(__lzo_constructor) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_constructor __attribute__((__constructor__,__used__)) +-#elif (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_constructor __attribute__((__constructor__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_constructor __attribute__((__constructor__)) +-#endif +-#endif +-#if defined(__lzo_constructor) +-# define __lzo_HAVE_constructor 1 +-#endif +-#if !defined(__lzo_destructor) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_destructor __attribute__((__destructor__,__used__)) +-#elif (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_destructor __attribute__((__destructor__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_destructor __attribute__((__destructor__)) +-#endif +-#endif +-#if defined(__lzo_destructor) +-# define __lzo_HAVE_destructor 1 +-#endif +-#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +-# error "this should not happen" +-#endif +-#if !defined(__lzo_inline) +-#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) +-#elif defined(__cplusplus) +-# define __lzo_inline inline +-#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) +-# define __lzo_inline __inline +-#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +-# define __lzo_inline __inline__ +-#elif (LZO_CC_DMC) +-# define __lzo_inline __inline +-#elif (LZO_CC_INTELC) +-# define __lzo_inline __inline +-#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) +-# define __lzo_inline __inline +-#elif (LZO_CC_MSC && (_MSC_VER >= 900)) +-# define __lzo_inline __inline +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_inline __inline__ +-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +-# define __lzo_inline inline +-#endif +-#endif +-#if defined(__lzo_inline) +-# define __lzo_HAVE_inline 1 +-#else +-# define __lzo_inline /*empty*/ +-#endif +-#if !defined(__lzo_forceinline) +-#if (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +-# define __lzo_forceinline __forceinline +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +-# define __lzo_forceinline __forceinline +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +-#endif +-#endif +-#if defined(__lzo_forceinline) +-# define __lzo_HAVE_forceinline 1 +-#else +-# define __lzo_forceinline /*empty*/ +-#endif +-#if !defined(__lzo_noinline) +-#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) +-# define __lzo_noinline __attribute__((__noinline__,__used__)) +-#elif (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +-# define __lzo_noinline __declspec(noinline) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_noinline __attribute__((__noinline__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +-# define __lzo_noinline __declspec(noinline) +-#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) +-# if defined(__cplusplus) +-# else +-# define __lzo_noinline __declspec(noinline) +-# endif +-#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +-# define __lzo_noinline __attribute__((__noinline__)) +-#endif +-#endif +-#if defined(__lzo_noinline) +-# define __lzo_HAVE_noinline 1 +-#else +-# define __lzo_noinline /*empty*/ +-#endif +-#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) +-# error "this should not happen" +-#endif +-#if !defined(__lzo_noreturn) +-#if (LZO_CC_GNUC >= 0x020700ul) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +-# define __lzo_noreturn __declspec(noreturn) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_noreturn __attribute__((__noreturn__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +-# define __lzo_noreturn __declspec(noreturn) +-#endif +-#endif +-#if defined(__lzo_noreturn) +-# define __lzo_HAVE_noreturn 1 +-#else +-# define __lzo_noreturn /*empty*/ +-#endif +-#if !defined(__lzo_nothrow) +-#if (LZO_CC_GNUC >= 0x030300ul) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +-# define __lzo_nothrow __declspec(nothrow) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_nothrow __attribute__((__nothrow__)) +-#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) +-# define __lzo_nothrow __declspec(nothrow) +-#endif +-#endif +-#if defined(__lzo_nothrow) +-# define __lzo_HAVE_nothrow 1 +-#else +-# define __lzo_nothrow /*empty*/ +-#endif +-#if !defined(__lzo_restrict) +-#if (LZO_CC_GNUC >= 0x030400ul) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_CLANG || LZO_CC_LLVM) +-# define __lzo_restrict __restrict__ +-#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) +-# define __lzo_restrict __restrict +-#endif +-#endif +-#if defined(__lzo_restrict) +-# define __lzo_HAVE_restrict 1 +-#else +-# define __lzo_restrict /*empty*/ +-#endif +-#if !defined(__lzo_likely) && !defined(__lzo_unlikely) +-#if (LZO_CC_GNUC >= 0x030200ul) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +-# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +-#endif +-#endif +-#if defined(__lzo_likely) +-# define __lzo_HAVE_likely 1 +-#else +-# define __lzo_likely(e) (e) +-#endif +-#if defined(__lzo_unlikely) +-# define __lzo_HAVE_unlikely 1 +-#else +-# define __lzo_unlikely(e) (e) +-#endif +-#if !defined(LZO_UNUSED) +-# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +-# define LZO_UNUSED(var) ((void) &var) +-# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +-# define LZO_UNUSED(var) if (&var) ; else +-# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define LZO_UNUSED(var) ((void) var) +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_UNUSED(var) if (&var) ; else +-# elif (LZO_CC_KEILC) +-# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} +-# elif (LZO_CC_PACIFICC) +-# define LZO_UNUSED(var) ((void) sizeof(var)) +-# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +-# define LZO_UNUSED(var) ((void) var) +-# else +-# define LZO_UNUSED(var) ((void) &var) +-# endif +-#endif +-#if !defined(LZO_UNUSED_FUNC) +-# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +-# define LZO_UNUSED_FUNC(func) ((void) func) +-# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +-# define LZO_UNUSED_FUNC(func) if (func) ; else +-# elif (LZO_CC_CLANG || LZO_CC_LLVM) +-# define LZO_UNUSED_FUNC(func) ((void) &func) +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_UNUSED_FUNC(func) if (func) ; else +-# elif (LZO_CC_MSC) +-# define LZO_UNUSED_FUNC(func) ((void) &func) +-# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +-# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +-# else +-# define LZO_UNUSED_FUNC(func) ((void) func) +-# endif +-#endif +-#if !defined(LZO_UNUSED_LABEL) +-# if (LZO_CC_WATCOMC) && defined(__cplusplus) +-# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +-# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +-# define LZO_UNUSED_LABEL(l) if (0) goto l +-# else +-# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l +-# endif +-#endif +-#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +-# if 0 +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +-# elif 0 && (LZO_CC_GNUC) +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +-# else +-# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +-# endif +-#endif +-#if !defined(LZO_UNCONST_CAST) +-# if 0 && defined(__cplusplus) +-# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +-# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +-# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +-# else +-# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +-# endif +-#endif +-#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) +-# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +-# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +-# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +-# else +-# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +-# endif +-#endif +-#if !defined(LZO_COMPILE_TIME_ASSERT) +-# if (LZO_CC_AZTECC) +-# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +-# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# elif (LZO_CC_MSC && (_MSC_VER < 900)) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) +-# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +-# else +-# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +-# endif +-#endif +-#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +-# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +-# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +-# define __lzo_cdecl __cdecl +-# define __lzo_cdecl_atexit /*empty*/ +-# define __lzo_cdecl_main __cdecl +-# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +-# define __lzo_cdecl_qsort __pascal +-# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +-# define __lzo_cdecl_qsort _stdcall +-# else +-# define __lzo_cdecl_qsort __cdecl +-# endif +-# elif (LZO_CC_WATCOMC) +-# define __lzo_cdecl __cdecl +-# else +-# define __lzo_cdecl __cdecl +-# define __lzo_cdecl_atexit __cdecl +-# define __lzo_cdecl_main __cdecl +-# define __lzo_cdecl_qsort __cdecl +-# endif +-# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +-# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +-# define __lzo_cdecl_sighandler __pascal +-# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +-# define __lzo_cdecl_sighandler _stdcall +-# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +-# define __lzo_cdecl_sighandler __clrcall +-# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +-# if defined(_DLL) +-# define __lzo_cdecl_sighandler _far _cdecl _loadds +-# elif defined(_MT) +-# define __lzo_cdecl_sighandler _far _cdecl +-# else +-# define __lzo_cdecl_sighandler _cdecl +-# endif +-# else +-# define __lzo_cdecl_sighandler __cdecl +-# endif +-#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +-# define __lzo_cdecl __cdecl +-#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +-# define __lzo_cdecl cdecl +-#endif +-#if !defined(__lzo_cdecl) +-# define __lzo_cdecl /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_atexit) +-# define __lzo_cdecl_atexit /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_main) +-# define __lzo_cdecl_main /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_qsort) +-# define __lzo_cdecl_qsort /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_sighandler) +-# define __lzo_cdecl_sighandler /*empty*/ +-#endif +-#if !defined(__lzo_cdecl_va) +-# define __lzo_cdecl_va __lzo_cdecl +-#endif +-#if !(LZO_CFG_NO_WINDOWS_H) +-#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +-# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +-# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +-# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +-# else +-# define LZO_HAVE_WINDOWS_H 1 +-# endif ++#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++# define LZO_ASM_SYNTAX_MSC 1 ++#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) ++#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_CC_GNUC) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#endif ++#if (LZO_ASM_SYNTAX_GNUC) ++#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) ++# define __LZO_ASM_CLOBBER "ax" ++# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) ++# define __LZO_ASM_CLOBBER "memory" ++# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ ++#else ++# define __LZO_ASM_CLOBBER "cc", "memory" ++# define __LZO_ASM_CLOBBER_LIST_CC : "cc" ++# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" ++# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ + #endif + #endif + #if (LZO_ARCH_ALPHA) +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_AVOID_SHORT 1 +-# define LZO_OPT_AVOID_USHORT 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 + #elif (LZO_ARCH_AMD64) +-# define LZO_OPT_AVOID_INT_INDEX 1 +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 +-# define LZO_OPT_UNALIGNED64 1 +-#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + #elif (LZO_ARCH_ARM) +-# define LZO_OPT_AVOID_SHORT 1 +-# define LZO_OPT_AVOID_USHORT 1 ++# if defined(__ARM_FEATURE_UNALIGNED) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 7) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# elif defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM+0) >= 6) && !defined(__TARGET_PROFILE_M) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# endif ++#elif (LZO_ARCH_ARM64) ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + #elif (LZO_ARCH_CRIS) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + #elif (LZO_ARCH_I386) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + #elif (LZO_ARCH_IA64) +-# define LZO_OPT_AVOID_INT_INDEX 1 +-# define LZO_OPT_AVOID_UINT_INDEX 1 +-# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_PREFER_POSTINC 1 + #elif (LZO_ARCH_M68K) +-# define LZO_OPT_PREFER_POSTINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + # if defined(__mc68020__) && !defined(__mcoldfire__) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif + # endif + #elif (LZO_ARCH_MIPS) +-# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 + #elif (LZO_ARCH_POWERPC) +-# define LZO_OPT_PREFER_PREINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_PREINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + # if (LZO_ABI_BIG_ENDIAN) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# if (LZO_WORDSIZE == 8) ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif ++# endif + # endif + #elif (LZO_ARCH_S390) +-# define LZO_OPT_UNALIGNED16 1 +-# define LZO_OPT_UNALIGNED32 1 +-# if (LZO_SIZEOF_SIZE_T == 8) +-# define LZO_OPT_UNALIGNED64 1 ++# ifndef LZO_OPT_UNALIGNED16 ++# define LZO_OPT_UNALIGNED16 1 ++# endif ++# ifndef LZO_OPT_UNALIGNED32 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++# if (LZO_WORDSIZE == 8) ++# ifndef LZO_OPT_UNALIGNED64 ++# define LZO_OPT_UNALIGNED64 1 ++# endif + # endif + #elif (LZO_ARCH_SH) +-# define LZO_OPT_PREFER_POSTINC 1 +-# define LZO_OPT_PREFER_PREDEC 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 + #endif + #ifndef LZO_CFG_NO_INLINE_ASM +-#if (LZO_CC_LLVM) ++#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) + # define LZO_CFG_NO_INLINE_ASM 1 ++#elif (LZO_CC_LLVM) ++# define LZO_CFG_NO_INLINE_ASM 1 ++#endif + #endif ++#if (LZO_CFG_NO_INLINE_ASM) ++# undef LZO_ASM_SYNTAX_MSC ++# undef LZO_ASM_SYNTAX_GNUC ++# undef __LZO_ASM_CLOBBER ++# undef __LZO_ASM_CLOBBER_LIST_CC ++# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY ++# undef __LZO_ASM_CLOBBER_LIST_EMPTY + #endif + #ifndef LZO_CFG_NO_UNALIGNED + #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) +@@ -1784,25 +2574,6 @@ extern "C" { + # undef LZO_OPT_UNALIGNED32 + # undef LZO_OPT_UNALIGNED64 + #endif +-#if (LZO_CFG_NO_INLINE_ASM) +-#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +-# define LZO_ASM_SYNTAX_MSC 1 +-#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +-#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +-#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +-# define LZO_ASM_SYNTAX_GNUC 1 +-#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +-# define LZO_ASM_SYNTAX_GNUC 1 +-#endif +-#if (LZO_ASM_SYNTAX_GNUC) +-#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +-# define __LZO_ASM_CLOBBER "ax" +-#elif (LZO_CC_INTELC) +-# define __LZO_ASM_CLOBBER "memory" +-#else +-# define __LZO_ASM_CLOBBER "cc", "memory" +-#endif +-#endif + #if defined(__LZO_INFOSTR_MM) + #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) + # define __LZO_INFOSTR_MM "" +@@ -1846,7 +2617,382 @@ extern "C" { + #define LZO_INFO_STRING \ + LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ + " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER ++#if !(LZO_CFG_SKIP_LZO_TYPES) ++#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) ++# error "missing defines for sizes" ++#endif ++#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) ++# error "missing defines for sizes" ++#endif ++#if !defined(lzo_llong_t) ++#if (LZO_SIZEOF_LONG_LONG+0 > 0) ++__lzo_gnuc_extension__ typedef long long lzo_llong_t__; ++__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; ++# define lzo_llong_t lzo_llong_t__ ++# define lzo_ullong_t lzo_ullong_t__ ++#endif ++#endif ++#if !defined(lzo_int16e_t) ++#if (LZO_SIZEOF_LONG == 2) ++# define lzo_int16e_t long ++# define lzo_uint16e_t unsigned long ++#elif (LZO_SIZEOF_INT == 2) ++# define lzo_int16e_t int ++# define lzo_uint16e_t unsigned int ++#elif (LZO_SIZEOF_SHORT == 2) ++# define lzo_int16e_t short int ++# define lzo_uint16e_t unsigned short int ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) ++ typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); ++ typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); ++# define lzo_int16e_t lzo_int16e_hi_t__ ++# define lzo_uint16e_t lzo_uint16e_hi_t__ ++#elif (LZO_SIZEOF___INT16 == 2) ++# define lzo_int16e_t __int16 ++# define lzo_uint16e_t unsigned __int16 ++#else ++#endif ++#endif ++#if defined(lzo_int16e_t) ++# define LZO_SIZEOF_LZO_INT16E_T 2 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) ++#endif ++#if !defined(lzo_int32e_t) ++#if (LZO_SIZEOF_LONG == 4) ++# define lzo_int32e_t long int ++# define lzo_uint32e_t unsigned long int ++#elif (LZO_SIZEOF_INT == 4) ++# define lzo_int32e_t int ++# define lzo_uint32e_t unsigned int ++#elif (LZO_SIZEOF_SHORT == 4) ++# define lzo_int32e_t short int ++# define lzo_uint32e_t unsigned short int ++#elif (LZO_SIZEOF_LONG_LONG == 4) ++# define lzo_int32e_t lzo_llong_t ++# define lzo_uint32e_t lzo_ullong_t ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) ++ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); ++ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); ++# define lzo_int32e_t lzo_int32e_si_t__ ++# define lzo_uint32e_t lzo_uint32e_si_t__ ++#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) ++ typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); ++ typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); ++# define lzo_int32e_t lzo_int32e_si_t__ ++# define lzo_uint32e_t lzo_uint32e_si_t__ ++# define LZO_INT32_C(c) (c##LL) ++# define LZO_UINT32_C(c) (c##ULL) ++#elif (LZO_SIZEOF___INT32 == 4) ++# define lzo_int32e_t __int32 ++# define lzo_uint32e_t unsigned __int32 ++#else ++#endif ++#endif ++#if defined(lzo_int32e_t) ++# define LZO_SIZEOF_LZO_INT32E_T 4 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) ++#endif ++#if !defined(lzo_int64e_t) ++#if (LZO_SIZEOF___INT64 == 8) ++# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) ++# define LZO_CFG_TYPE_PREFER___INT64 1 ++# endif ++#endif ++#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_int64e_t int ++# define lzo_uint64e_t unsigned int ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG == 8) ++# define lzo_int64e_t long int ++# define lzo_uint64e_t unsigned long int ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG ++#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) ++# define lzo_int64e_t lzo_llong_t ++# define lzo_uint64e_t lzo_ullong_t ++# if (LZO_CC_BORLANDC) ++# define LZO_INT64_C(c) ((c) + 0ll) ++# define LZO_UINT64_C(c) ((c) + 0ull) ++# elif 0 ++# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) ++# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) ++# else ++# define LZO_INT64_C(c) (c##LL) ++# define LZO_UINT64_C(c) (c##ULL) ++# endif ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF_LONG_LONG ++#elif (LZO_SIZEOF___INT64 == 8) ++# define lzo_int64e_t __int64 ++# define lzo_uint64e_t unsigned __int64 ++# if (LZO_CC_BORLANDC) ++# define LZO_INT64_C(c) ((c) + 0i64) ++# define LZO_UINT64_C(c) ((c) + 0ui64) ++# else ++# define LZO_INT64_C(c) (c##i64) ++# define LZO_UINT64_C(c) (c##ui64) ++# endif ++# define LZO_SIZEOF_LZO_INT64E_T LZO_SIZEOF___INT64 ++#else ++#endif ++#endif ++#if defined(lzo_int64e_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) ++#endif ++#if !defined(lzo_int32l_t) ++#if defined(lzo_int32e_t) ++# define lzo_int32l_t lzo_int32e_t ++# define lzo_uint32l_t lzo_uint32e_t ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T ++#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_int32l_t int ++# define lzo_uint32l_t unsigned int ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG >= 4) ++# define lzo_int32l_t long int ++# define lzo_uint32l_t unsigned long int ++# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG ++#else ++# error "lzo_int32l_t" ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) ++#endif ++#if !defined(lzo_int64l_t) ++#if defined(lzo_int64e_t) ++# define lzo_int64l_t lzo_int64e_t ++# define lzo_uint64l_t lzo_uint64e_t ++# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T ++#else ++#endif ++#endif ++#if defined(lzo_int64l_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) ++#endif ++#if !defined(lzo_int32f_t) ++#if (LZO_SIZEOF_SIZE_T >= 8) ++# define lzo_int32f_t lzo_int64l_t ++# define lzo_uint32f_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T ++#else ++# define lzo_int32f_t lzo_int32l_t ++# define lzo_uint32f_t lzo_uint32l_t ++# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) ++#endif ++#if !defined(lzo_int64f_t) ++#if defined(lzo_int64l_t) ++# define lzo_int64f_t lzo_int64l_t ++# define lzo_uint64f_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T ++#else ++#endif ++#endif ++#if defined(lzo_int64f_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) ++#endif ++#if !defined(lzo_intptr_t) ++#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) ++# define __LZO_INTPTR_T_IS_POINTER 1 ++ typedef char* lzo_intptr_t; ++ typedef char* lzo_uintptr_t; ++# define lzo_intptr_t lzo_intptr_t ++# define lzo_uintptr_t lzo_uintptr_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) ++ typedef __w64 int lzo_intptr_t; ++ typedef __w64 unsigned int lzo_uintptr_t; ++# define lzo_intptr_t lzo_intptr_t ++# define lzo_uintptr_t lzo_uintptr_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t short ++# define lzo_uintptr_t unsigned short ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT ++#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) ++# define lzo_intptr_t int ++# define lzo_uintptr_t unsigned int ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT ++#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t long ++# define lzo_uintptr_t unsigned long ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG ++#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) ++# define lzo_intptr_t lzo_int64l_t ++# define lzo_uintptr_t lzo_uint64l_t ++# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T ++#else ++# error "lzo_intptr_t" ++#endif ++#endif ++#if 1 ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) ++#endif ++#if !defined(lzo_word_t) ++#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) ++#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) ++# define lzo_word_t lzo_uintptr_t ++# define lzo_sword_t lzo_intptr_t ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T ++#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) ++# define lzo_word_t unsigned long ++# define lzo_sword_t long ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG ++#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) ++# define lzo_word_t unsigned int ++# define lzo_sword_t int ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT ++#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) ++# define lzo_word_t unsigned short ++# define lzo_sword_t short ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT ++#elif (LZO_WORDSIZE == 1) ++# define lzo_word_t unsigned char ++# define lzo_sword_t signed char ++# define LZO_SIZEOF_LZO_WORD_T 1 ++#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) ++# define lzo_word_t lzo_uint64l_t ++# define lzo_sword_t lzo_int64l_t ++# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T ++#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) ++#if 0 ++ typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); ++ typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); ++# define lzo_word_t lzo_word_t ++# define lzo_sword_t lzo_sword_t ++# define LZO_SIZEOF_LZO_WORD_T 16 ++#endif ++#else ++# error "lzo_word_t" ++#endif ++#endif ++#endif ++#if 1 && defined(lzo_word_t) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) ++#endif ++#if 1 ++#define lzo_int8_t signed char ++#define lzo_uint8_t unsigned char ++#define LZO_SIZEOF_LZO_INT8_T 1 ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) ++#endif ++#if defined(lzo_int16e_t) ++#define lzo_int16_t lzo_int16e_t ++#define lzo_uint16_t lzo_uint16e_t ++#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) ++#endif ++#if defined(lzo_int32e_t) ++#define lzo_int32_t lzo_int32e_t ++#define lzo_uint32_t lzo_uint32e_t ++#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) ++#endif ++#if defined(lzo_int64e_t) ++#define lzo_int64_t lzo_int64e_t ++#define lzo_uint64_t lzo_uint64e_t ++#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) ++#endif ++#if 1 ++#define lzo_int_least32_t lzo_int32l_t ++#define lzo_uint_least32_t lzo_uint32l_t ++#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) ++#endif ++#if defined(lzo_int64l_t) ++#define lzo_int_least64_t lzo_int64l_t ++#define lzo_uint_least64_t lzo_uint64l_t ++#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) ++#endif ++#if 1 ++#define lzo_int_fast32_t lzo_int32f_t ++#define lzo_uint_fast32_t lzo_uint32f_t ++#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) ++#endif ++#if defined(lzo_int64f_t) ++#define lzo_int_fast64_t lzo_int64f_t ++#define lzo_uint_fast64_t lzo_uint64f_t ++#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) ++#endif ++#if !defined(LZO_INT16_C) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) ++# define LZO_INT16_C(c) ((c) + 0) ++# define LZO_UINT16_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) ++# define LZO_INT16_C(c) ((c) + 0L) ++# define LZO_UINT16_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 2) ++# define LZO_INT16_C(c) (c) ++# define LZO_UINT16_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 2) ++# define LZO_INT16_C(c) (c##L) ++# define LZO_UINT16_C(c) (c##UL) ++# else ++# error "LZO_INT16_C" ++# endif ++#endif ++#if !defined(LZO_INT32_C) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) ++# define LZO_INT32_C(c) ((c) + 0) ++# define LZO_UINT32_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) ++# define LZO_INT32_C(c) ((c) + 0L) ++# define LZO_UINT32_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 4) ++# define LZO_INT32_C(c) (c) ++# define LZO_UINT32_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 4) ++# define LZO_INT32_C(c) (c##L) ++# define LZO_UINT32_C(c) (c##UL) ++# elif (LZO_SIZEOF_LONG_LONG >= 4) ++# define LZO_INT32_C(c) (c##LL) ++# define LZO_UINT32_C(c) (c##ULL) ++# else ++# error "LZO_INT32_C" ++# endif ++#endif ++#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) ++# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) ++# define LZO_INT64_C(c) ((c) + 0) ++# define LZO_UINT64_C(c) ((c) + 0U) ++# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) ++# define LZO_INT64_C(c) ((c) + 0L) ++# define LZO_UINT64_C(c) ((c) + 0UL) ++# elif (LZO_SIZEOF_INT >= 8) ++# define LZO_INT64_C(c) (c) ++# define LZO_UINT64_C(c) (c##U) ++# elif (LZO_SIZEOF_LONG >= 8) ++# define LZO_INT64_C(c) (c##L) ++# define LZO_UINT64_C(c) (c##UL) ++# else ++# error "LZO_INT64_C" ++# endif ++#endif ++#endif + + #endif /* already included */ + +-/* vim:set ts=4 et: */ ++/* vim:set ts=4 sw=4 et: */ +diff --git a/grub-core/lib/minilzo/minilzo.h b/grub-core/lib/minilzo/minilzo.h +index 74fefa9fe20..79374546748 100644 +--- a/grub-core/lib/minilzo/minilzo.h ++++ b/grub-core/lib/minilzo/minilzo.h +@@ -2,22 +2,7 @@ + + This file is part of the LZO real-time data compression library. + +- Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer +- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer ++ Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or +@@ -50,7 +35,7 @@ + #ifndef __MINILZO_H + #define __MINILZO_H 1 + +-#define MINILZO_VERSION 0x2050 ++#define MINILZO_VERSION 0x2080 + + #ifdef __LZOCONF_H + # error "you cannot use both LZO and miniLZO" +@@ -78,7 +63,7 @@ extern "C" { + */ + + #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS +-#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) ++#define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t)) + #define LZO1X_MEM_DECOMPRESS (0) + + diff --git a/0014-Allow-fallback-to-include-entries-by-title-not-just-.patch b/0014-Allow-fallback-to-include-entries-by-title-not-just-.patch new file mode 100644 index 0000000..ee5d1da --- /dev/null +++ b/0014-Allow-fallback-to-include-entries-by-title-not-just-.patch @@ -0,0 +1,141 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 5 Sep 2014 10:07:04 -0400 +Subject: [PATCH] Allow "fallback" to include entries by title, not just + number. + +Resolves: rhbz#1026084 + +Signed-off-by: Peter Jones +--- + grub-core/normal/menu.c | 85 +++++++++++++++++++++++++++++++++---------------- + 1 file changed, 58 insertions(+), 27 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index d5e0c79a70e..9175ad297d8 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -163,16 +163,41 @@ grub_menu_set_timeout (int timeout) + } + } + ++static int ++menuentry_eq (const char *id, const char *spec) ++{ ++ const char *ptr1, *ptr2; ++ ptr1 = id; ++ ptr2 = spec; ++ while (1) ++ { ++ if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) ++ return ptr2 - spec; ++ if (*ptr2 == '>' && ptr2[1] != '>') ++ return 0; ++ if (*ptr2 == '>') ++ ptr2++; ++ if (*ptr1 != *ptr2) ++ return 0; ++ if (*ptr1 == 0) ++ return ptr1 - id; ++ ptr1++; ++ ptr2++; ++ } ++ return 0; ++} ++ + /* Get the first entry number from the value of the environment variable NAME, + which is a space-separated list of non-negative integers. The entry number + which is returned is stripped from the value of NAME. If no entry number + can be found, -1 is returned. */ + static int +-get_and_remove_first_entry_number (const char *name) ++get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + { + const char *val; + char *tail; + int entry; ++ int sz = 0; + + val = grub_env_get (name); + if (! val) +@@ -182,9 +207,39 @@ get_and_remove_first_entry_number (const char *name) + + entry = (int) grub_strtoul (val, &tail, 0); + ++ if (grub_errno == GRUB_ERR_BAD_NUMBER) ++ { ++ /* See if the variable matches the title of a menu entry. */ ++ grub_menu_entry_t e = menu->entry_list; ++ int i; ++ ++ for (i = 0; e; i++) ++ { ++ sz = menuentry_eq (e->title, val); ++ if (sz < 1) ++ sz = menuentry_eq (e->id, val); ++ ++ if (sz >= 1) ++ { ++ entry = i; ++ break; ++ } ++ e = e->next; ++ } ++ ++ if (sz > 0) ++ grub_errno = GRUB_ERR_NONE; ++ ++ if (! e) ++ entry = -1; ++ } ++ + if (grub_errno == GRUB_ERR_NONE) + { +- /* Skip whitespace to find the next digit. */ ++ if (sz > 0) ++ tail += sz; ++ ++ /* Skip whitespace to find the next entry. */ + while (*tail && grub_isspace (*tail)) + tail++; + grub_env_set (name, tail); +@@ -347,7 +402,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, + grub_menu_execute_entry (entry, 1); + + /* Deal with fallback entries. */ +- while ((fallback_entry = get_and_remove_first_entry_number ("fallback")) ++ while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback")) + >= 0) + { + grub_print_error (); +@@ -465,30 +520,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) + viewers = viewer; + } + +-static int +-menuentry_eq (const char *id, const char *spec) +-{ +- const char *ptr1, *ptr2; +- ptr1 = id; +- ptr2 = spec; +- while (1) +- { +- if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) +- return 1; +- if (*ptr2 == '>' && ptr2[1] != '>') +- return 0; +- if (*ptr2 == '>') +- ptr2++; +- if (*ptr1 != *ptr2) +- return 0; +- if (*ptr1 == 0) +- return 1; +- ptr1++; +- ptr2++; +- } +-} +- +- + /* Get the entry number from the variable NAME. */ + static int + get_entry_number (grub_menu_t menu, const char *name) diff --git a/0015-Add-GRUB_DISABLE_UUID.patch b/0015-Add-GRUB_DISABLE_UUID.patch new file mode 100644 index 0000000..7051dd7 --- /dev/null +++ b/0015-Add-GRUB_DISABLE_UUID.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Sep 2014 16:49:25 -0400 +Subject: [PATCH] Add GRUB_DISABLE_UUID. + +This will cause "search --fs-uuid --set=root ..." not to be generated by +grub2-mkconfig, and instead simply attempt to use the grub device name +as it understands it. + +Signed-off-by: Peter Jones +--- + docs/grub.texi | 7 +++++++ + util/grub-mkconfig.in | 22 +++++++++++++++++++--- + util/grub-mkconfig_lib.in | 4 ++-- + 3 files changed, 28 insertions(+), 5 deletions(-) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 87795075a87..6f524305085 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -1441,6 +1441,13 @@ enable the use of partition UUIDs, set this option to @samp{false}. + If this option is set to @samp{true}, disable the generation of recovery + mode menu entries. + ++@item GRUB_DISABLE_UUID ++Normally, @command{grub-mkconfig} will generate menu entries that use ++universally-unique identifiers (UUIDs) to identify various filesystems to ++search for files. This is usually more reliable, but in some cases it may ++not be appropriate. To disable this use of UUIDs, set this option to ++@samp{true}. ++ + @item GRUB_VIDEO_BACKEND + If graphical video support is required, either because the @samp{gfxterm} + graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 523d4e029bb..9ecbcfb5b43 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -133,12 +133,12 @@ fi + + # Device containing our userland. Typically used for root= parameter. + GRUB_DEVICE="`${grub_probe} --target=device /`" +-GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true +-GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2> /dev/null`" || true ++GRUB_DEVICE_UUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true ++GRUB_DEVICE_PARTUUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2> /dev/null`" || true + + # Device containing our /boot partition. Usually the same as GRUB_DEVICE. + GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`" +-GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true ++GRUB_DEVICE_BOOT_UUID_GENERATED="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true + + # Filesystem for the device containing our userland. Used for stuff like + # choosing Hurd filesystem module. +@@ -158,6 +158,21 @@ if test -f ${sysconfdir}/default/grub ; then + . ${sysconfdir}/default/grub + fi + ++if [ "x$GRUB_DISABLE_UUID" != "xtrue" ]; then ++ if [ -z "$GRUB_DEVICE_UUID" ]; then ++ GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" ++ fi ++ if [ -z "$GRUB_DEVICE_BOOT_UUID" ]; then ++ GRUB_DEVICE_BOOT_UUID="$GRUB_DEVICE_BOOT_UUID_GENERATED" ++ fi ++ if [ -z "$GRUB_DEVICE_UUID" ]; then ++ GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" ++ fi ++ if [ -z "$GRUB_DEVICE_PART_UUID" ]; then ++ GRUB_DEVICE_PART_UUID="$GRUB_DEVICE_PART_UUID_GENERATED" ++ fi ++fi ++ + # XXX: should this be deprecated at some point? + if [ "x${GRUB_TERMINAL}" != "x" ] ; then + GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}" +@@ -227,6 +242,7 @@ export GRUB_DEFAULT \ + GRUB_DISABLE_LINUX_UUID \ + GRUB_DISABLE_LINUX_PARTUUID \ + GRUB_DISABLE_RECOVERY \ ++ GRUB_DISABLE_UUID \ + GRUB_VIDEO_BACKEND \ + GRUB_GFXMODE \ + GRUB_BACKGROUND \ +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 0f801cab3e4..1001a12232b 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -156,7 +156,7 @@ prepare_grub_to_access_device () + if [ "x$fs_hint" != x ]; then + echo "set root='$fs_hint'" + fi +- if fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then ++ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then + hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints= + echo "if [ x\$feature_platform_search_hint = xy ]; then" + echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" +@@ -173,7 +173,7 @@ grub_get_device_id () + IFS=' + ' + device="$1" +- if fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then ++ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then + echo "$fs_uuid"; + else + echo $device |sed 's, ,_,g' diff --git a/0016-Make-exit-take-a-return-code.patch b/0016-Make-exit-take-a-return-code.patch new file mode 100644 index 0000000..0cd25b2 --- /dev/null +++ b/0016-Make-exit-take-a-return-code.patch @@ -0,0 +1,267 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 26 Feb 2014 21:49:12 -0500 +Subject: [PATCH] Make "exit" take a return code. + +This adds "exit" with a return code. With this patch, any "exit" +command /may/ include a return code, and on platforms that support +returning with an exit status, we will do so. By default we return the +same exit status we did before this patch. + +Signed-off-by: Peter Jones +--- + grub-core/commands/minicmd.c | 20 ++++++++++++++++---- + grub-core/kern/efi/efi.c | 9 +++++++-- + grub-core/kern/emu/main.c | 2 +- + grub-core/kern/emu/misc.c | 5 +++-- + grub-core/kern/i386/coreboot/init.c | 2 +- + grub-core/kern/i386/qemu/init.c | 2 +- + grub-core/kern/ieee1275/init.c | 2 +- + grub-core/kern/mips/arc/init.c | 2 +- + grub-core/kern/mips/loongson/init.c | 2 +- + grub-core/kern/mips/qemu_mips/init.c | 2 +- + grub-core/kern/misc.c | 11 ++++++++++- + grub-core/kern/uboot/init.c | 6 +++--- + grub-core/kern/xen/init.c | 2 +- + include/grub/misc.h | 2 +- + 14 files changed, 48 insertions(+), 21 deletions(-) + +diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c +index 6bbce3128cf..6d66b7c453a 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -179,12 +179,24 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)), + } + + /* exit */ +-static grub_err_t __attribute__ ((noreturn)) ++static grub_err_t + grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), +- int argc __attribute__ ((unused)), +- char *argv[] __attribute__ ((unused))) ++ int argc, char *argv[]) + { +- grub_exit (); ++ int retval = -1; ++ unsigned long n; ++ ++ if (argc < 0 || argc > 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); ++ ++ if (argc == 1) ++ { ++ n = grub_strtoul (argv[0], 0, 10); ++ if (n != ~0UL) ++ retval = n; ++ } ++ ++ grub_exit (retval); + /* Not reached. */ + } + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 6e1ceb90516..370ce03c5d7 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -164,11 +164,16 @@ grub_reboot (void) + } + + void +-grub_exit (void) ++grub_exit (int retval) + { ++ int rc = GRUB_EFI_LOAD_ERROR; ++ ++ if (retval == 0) ++ rc = GRUB_EFI_SUCCESS; ++ + grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); + efi_call_4 (grub_efi_system_table->boot_services->exit, +- grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0); ++ grub_efi_image_handle, rc, 0, 0); + for (;;) ; + } + +diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c +index 425bb960347..55ea5a11ccd 100644 +--- a/grub-core/kern/emu/main.c ++++ b/grub-core/kern/emu/main.c +@@ -67,7 +67,7 @@ grub_reboot (void) + } + + void +-grub_exit (void) ++grub_exit (int retval __attribute__((unused))) + { + grub_reboot (); + } +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 65db79baa10..19cd007d448 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -139,9 +139,10 @@ xasprintf (const char *fmt, ...) + + #if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) + void +-grub_exit (void) ++__attribute__ ((noreturn)) ++grub_exit (int rc) + { +- exit (1); ++ exit (rc < 0 ? 1 : rc); + } + #endif + +diff --git a/grub-core/kern/i386/coreboot/init.c b/grub-core/kern/i386/coreboot/init.c +index 3314f027fec..36f9134b7b7 100644 +--- a/grub-core/kern/i386/coreboot/init.c ++++ b/grub-core/kern/i386/coreboot/init.c +@@ -41,7 +41,7 @@ extern grub_uint8_t _end[]; + extern grub_uint8_t _edata[]; + + void __attribute__ ((noreturn)) +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + /* We can't use grub_fatal() in this function. This would create an infinite + loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ +diff --git a/grub-core/kern/i386/qemu/init.c b/grub-core/kern/i386/qemu/init.c +index 271b6fbfabd..9fafe98f015 100644 +--- a/grub-core/kern/i386/qemu/init.c ++++ b/grub-core/kern/i386/qemu/init.c +@@ -42,7 +42,7 @@ extern grub_uint8_t _end[]; + extern grub_uint8_t _edata[]; + + void __attribute__ ((noreturn)) +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + /* We can't use grub_fatal() in this function. This would create an infinite + loop, since grub_fatal() calls grub_abort() which in turn calls grub_exit(). */ +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index d483e35eed2..e71d1584164 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -71,7 +71,7 @@ grub_addr_t grub_ieee1275_original_stack; + #endif + + void +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + grub_ieee1275_exit (); + } +diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c +index 3834a149093..86b3a25ec40 100644 +--- a/grub-core/kern/mips/arc/init.c ++++ b/grub-core/kern/mips/arc/init.c +@@ -276,7 +276,7 @@ grub_halt (void) + } + + void +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + GRUB_ARC_FIRMWARE_VECTOR->exit (); + +diff --git a/grub-core/kern/mips/loongson/init.c b/grub-core/kern/mips/loongson/init.c +index 7b96531b983..dff598ca7b0 100644 +--- a/grub-core/kern/mips/loongson/init.c ++++ b/grub-core/kern/mips/loongson/init.c +@@ -304,7 +304,7 @@ grub_halt (void) + } + + void +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + grub_halt (); + } +diff --git a/grub-core/kern/mips/qemu_mips/init.c b/grub-core/kern/mips/qemu_mips/init.c +index be88b77d22d..8b6c55ffc01 100644 +--- a/grub-core/kern/mips/qemu_mips/init.c ++++ b/grub-core/kern/mips/qemu_mips/init.c +@@ -75,7 +75,7 @@ grub_machine_fini (int flags __attribute__ ((unused))) + } + + void +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + grub_halt (); + } +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 3b633d51f4c..cd63a8cea73 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1095,9 +1095,18 @@ grub_abort (void) + grub_getkey (); + } + +- grub_exit (); ++ grub_exit (1); + } + ++#if defined (__clang__) && !defined (GRUB_UTIL) ++/* clang emits references to abort(). */ ++void __attribute__ ((noreturn)) ++abort (void) ++{ ++ grub_abort (); ++} ++#endif ++ + void + grub_fatal (const char *fmt, ...) + { +diff --git a/grub-core/kern/uboot/init.c b/grub-core/kern/uboot/init.c +index 3e338645c57..be2a5be1d07 100644 +--- a/grub-core/kern/uboot/init.c ++++ b/grub-core/kern/uboot/init.c +@@ -39,9 +39,9 @@ extern grub_size_t grub_total_module_size; + static unsigned long timer_start; + + void +-grub_exit (void) ++grub_exit (int rc) + { +- grub_uboot_return (0); ++ grub_uboot_return (rc < 0 ? 1 : rc); + } + + static grub_uint64_t +@@ -78,7 +78,7 @@ grub_machine_init (void) + if (!ver) + { + /* Don't even have a console to log errors to... */ +- grub_exit (); ++ grub_exit (-1); + } + else if (ver > API_SIG_VERSION) + { +diff --git a/grub-core/kern/xen/init.c b/grub-core/kern/xen/init.c +index 782ca72952a..708b060f324 100644 +--- a/grub-core/kern/xen/init.c ++++ b/grub-core/kern/xen/init.c +@@ -584,7 +584,7 @@ grub_machine_init (void) + } + + void +-grub_exit (void) ++grub_exit (int rc __attribute__((unused))) + { + struct sched_shutdown arg; + +diff --git a/include/grub/misc.h b/include/grub/misc.h +index ee48eb7a726..f9135b62e35 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -334,7 +334,7 @@ int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, + char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) + __attribute__ ((format (GNU_PRINTF, 1, 2))) WARN_UNUSED_RESULT; + char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args) WARN_UNUSED_RESULT; +-void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); ++void EXPORT_FUNC(grub_exit) (int rc) __attribute__ ((noreturn)); + grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n, + grub_uint64_t d, + grub_uint64_t *r); diff --git a/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch b/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch new file mode 100644 index 0000000..942116a --- /dev/null +++ b/0017-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch @@ -0,0 +1,19 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 22 Jul 2015 11:21:01 -0400 +Subject: [PATCH] Mark po/exclude.pot as binary so git won't try to diff + nonprintables. + +Signed-off-by: Peter Jones +--- + .gitattributes | 1 + + 1 file changed, 1 insertion(+) + create mode 100644 .gitattributes + +diff --git a/.gitattributes b/.gitattributes +new file mode 100644 +index 00000000000..33ffaa40460 +--- /dev/null ++++ b/.gitattributes +@@ -0,0 +1 @@ ++po/exclude.pot binary diff --git a/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch b/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch new file mode 100644 index 0000000..9665d7b --- /dev/null +++ b/0018-Make-efi-machines-load-an-env-block-from-a-variable.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 7 Dec 2015 14:20:49 -0500 +Subject: [PATCH] Make efi machines load an env block from a variable + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 1 + + grub-core/kern/efi/init.c | 34 +++++++++++++++++++++++++++++++++- + 2 files changed, 34 insertions(+), 1 deletion(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index eb1088fd654..41b5e16a3ce 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -203,6 +203,7 @@ kernel = { + efi = term/efi/console.c; + efi = kern/acpi.c; + efi = kern/efi/acpi.c; ++ efi = lib/envblk.c; + i386_coreboot = kern/i386/pc/acpi.c; + i386_multiboot = kern/i386/pc/acpi.c; + i386_coreboot = kern/acpi.c; +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index 3dfdf2d22b0..71d2279a0c1 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -25,9 +25,40 @@ + #include + #include + #include ++#include + + grub_addr_t grub_modbase; + ++#define GRUB_EFI_GRUB_VARIABLE_GUID \ ++ { 0x91376aff, 0xcba6, 0x42be, \ ++ { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \ ++ } ++ ++/* Helper for grub_efi_env_init */ ++static int ++set_var (const char *name, const char *value, ++ void *whitelist __attribute__((__unused__))) ++{ ++ grub_env_set (name, value); ++ return 0; ++} ++ ++static void ++grub_efi_env_init (void) ++{ ++ grub_efi_guid_t efi_grub_guid = GRUB_EFI_GRUB_VARIABLE_GUID; ++ struct grub_envblk envblk_s = { NULL, 0 }; ++ grub_envblk_t envblk = &envblk_s; ++ ++ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &efi_grub_guid, ++ &envblk_s.size); ++ if (!envblk_s.buf || envblk_s.size < 1) ++ return; ++ ++ grub_envblk_iterate (envblk, NULL, set_var); ++ grub_free (envblk_s.buf); ++} ++ + void + grub_efi_init (void) + { +@@ -42,10 +73,11 @@ grub_efi_init (void) + efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer, + 0, 0, 0, NULL); + ++ grub_efi_env_init (); + grub_efidisk_init (); + } + +-void (*grub_efi_net_config) (grub_efi_handle_t hnd, ++void (*grub_efi_net_config) (grub_efi_handle_t hnd, + char **device, + char **path); + diff --git a/0019-DHCP-client-ID-and-UUID-options-added.patch b/0019-DHCP-client-ID-and-UUID-options-added.patch new file mode 100644 index 0000000..6167b62 --- /dev/null +++ b/0019-DHCP-client-ID-and-UUID-options-added.patch @@ -0,0 +1,140 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Mon, 8 Jul 2019 14:10:58 +0200 +Subject: [PATCH] DHCP client ID and UUID options added. + +--- + grub-core/net/bootp.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++----- + include/grub/net.h | 2 ++ + 2 files changed, 79 insertions(+), 8 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 04cfbb04504..0e6e41a1699 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -95,6 +95,49 @@ enum + /* Max timeout when waiting for BOOTP/DHCP reply */ + #define GRUB_DHCP_MAX_PACKET_TIMEOUT 32 + ++static char * ++grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ return NULL; ++} ++ ++static void ++set_env_limn_ro (const char *intername, const char *suffix, ++ const char *value, grub_size_t len) ++{ ++ char *varname, *varvalue; ++ char *ptr; ++ varname = grub_xasprintf ("net_%s_%s", intername, suffix); ++ if (!varname) ++ return; ++ for (ptr = varname; *ptr; ptr++) ++ if (*ptr == ':') ++ *ptr = '_'; ++ varvalue = grub_malloc (len + 1); ++ if (!varvalue) ++ { ++ grub_free (varname); ++ return; ++ } ++ ++ grub_memcpy (varvalue, value, len); ++ varvalue[len] = 0; ++ grub_env_set (varname, varvalue); ++ grub_register_variable_hook (varname, 0, grub_env_write_readonly); ++ grub_env_export (varname); ++ grub_free (varname); ++ grub_free (varvalue); ++} ++ ++static char ++hexdigit (grub_uint8_t val) ++{ ++ if (val < 10) ++ return val + '0'; ++ return val + 'a' - 10; ++} ++ + static const void * + find_dhcp_option (const struct grub_net_bootp_packet *bp, grub_size_t size, + grub_uint8_t opt_code, grub_uint8_t *opt_len) +@@ -152,6 +195,9 @@ again: + if (i + taglength >= size) + return NULL; + ++ grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n", ++ tagtype, tagtype, taglength); ++ + /* FIXME RFC 3396 options concatentation */ + if (tagtype == opt_code) + { +@@ -354,6 +400,37 @@ grub_net_configure_by_dhcp_ack (const char *name, + } + grub_net_add_ipv4_local (inter, mask); + ++ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_ID, &opt_len); ++ if (opt) ++ { ++ set_env_limn_ro (name, "clientid", (char *) opt, opt_len); ++ } ++ ++ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_CLIENT_UUID, &opt_len); ++ if (opt && opt_len == 17) ++ { ++ /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */ ++ ++ opt += 1; ++ opt_len -= 1; ++ ++ char *val = grub_malloc (2 * opt_len + 4 + 1); ++ int i = 0; ++ int j = 0; ++ for (i = 0; i < opt_len; i++) ++ { ++ val[2 * i + j] = hexdigit (opt[i] >> 4); ++ val[2 * i + 1 + j] = hexdigit (opt[i] & 0xf); ++ ++ if ((i == 3) || (i == 5) || (i == 7) || (i == 9)) ++ { ++ j++; ++ val[2 * i + 1+ j] = '-'; ++ } ++ } ++ set_env_limn_ro (name, "clientuuid", (char *) val, 2 * opt_len + 4); ++ } ++ + /* We do not implement dead gateway detection and the first entry SHOULD + be preferred one */ + opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_ROUTER, &opt_len); +@@ -631,14 +708,6 @@ grub_net_process_dhcp (struct grub_net_buff *nb, + } + } + +-static char +-hexdigit (grub_uint8_t val) +-{ +- if (val < 10) +- return val + '0'; +- return val + 'a' - 10; +-} +- + static grub_err_t + grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +diff --git a/include/grub/net.h b/include/grub/net.h +index 4a9069a1474..556c54e579f 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -462,6 +462,8 @@ enum + GRUB_NET_BOOTP_DOMAIN = 0x0f, + GRUB_NET_BOOTP_ROOT_PATH = 0x11, + GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, ++ GRUB_NET_BOOTP_CLIENT_ID = 0x3d, ++ GRUB_NET_BOOTP_CLIENT_UUID = 0x61, + GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50, + GRUB_NET_DHCP_OVERLOAD = 52, + GRUB_NET_DHCP_MESSAGE_TYPE = 53, diff --git a/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch b/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch new file mode 100644 index 0000000..265e777 --- /dev/null +++ b/0020-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Prarit Bhargava +Date: Wed, 12 Mar 2014 10:58:16 -0400 +Subject: [PATCH] Fix bad test on GRUB_DISABLE_SUBMENU. + +The file /etc/grub.d/10_linux does + +if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then + +when it should do + +if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + +which results in submenus in /boot/grub2/grub.cfg when +GRUB_DISABLE_SUBMENU="yes". + +Resolves: rhbz#1063414 +--- + util/grub.d/10_linux.in | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 4532266be68..58defdbd83f 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -261,7 +261,11 @@ while [ "x$list" != "x" ] ; do + fi + fi + +- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then ++ if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then ++ GRUB_DISABLE_SUBMENU="true" ++ fi ++ ++ if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then + linux_entry "${OS}" "${version}" simple \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + diff --git a/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch b/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch new file mode 100644 index 0000000..6ddda34 --- /dev/null +++ b/0021-Add-support-for-UEFI-operating-systems-returned-by-o.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Wed, 12 Jun 2013 11:51:49 -0400 +Subject: [PATCH] Add support for UEFI operating systems returned by os-prober + +os-prober returns UEFI operating systems in the form: + +path:long-name:name + +where path is the path under the EFI directory on the ESP. This is in +contrast to legacy OSes, where path is the device string. Handle this case. +--- + util/grub.d/30_os-prober.in | 21 ++++++++++++++++++--- + 1 file changed, 18 insertions(+), 3 deletions(-) + +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 515a68c7aa0..9b8f5968e2d 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -328,8 +328,23 @@ EOF + EOF + ;; + *) +- # TRANSLATORS: %s is replaced by OS name. +- gettext_printf "%s is not yet supported by grub-mkconfig.\n" " ${LONGNAME}" >&2 +- ;; ++ case ${DEVICE} in ++ *.efi) ++ cat << EOF ++menuentry '$(echo "${LONGNAME}" | grub_quote)' { ++EOF ++ save_default_entry | grub_add_tab ++ cat << EOF ++ chainloader /EFI/${DEVICE} ++ boot ++} ++EOF ++ ;; ++ *) ++ echo -n " " ++ # TRANSLATORS: %s is replaced by OS name. ++ gettext_printf "%s is not yet supported by grub-mkconfig.\n" "${LONGNAME}" >&2 ++ ;; ++ esac + esac + done diff --git a/0022-Migrate-PPC-from-Yaboot-to-Grub2.patch b/0022-Migrate-PPC-from-Yaboot-to-Grub2.patch new file mode 100644 index 0000000..3fbb18a --- /dev/null +++ b/0022-Migrate-PPC-from-Yaboot-to-Grub2.patch @@ -0,0 +1,151 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Mark Hamzy +Date: Wed, 28 Mar 2012 14:46:41 -0500 +Subject: [PATCH] Migrate PPC from Yaboot to Grub2 + +Add configuration support for serial terminal consoles. This will set the +maximum screen size so that text is not overwritten. +--- + Makefile.util.def | 7 +++ + util/grub.d/20_ppc_terminfo.in | 114 +++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 121 insertions(+) + create mode 100644 util/grub.d/20_ppc_terminfo.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 969d32f0097..8717774d510 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -496,6 +496,13 @@ script = { + condition = COND_HOST_LINUX; + }; + ++script = { ++ name = '20_ppc_terminfo'; ++ common = util/grub.d/20_ppc_terminfo.in; ++ installdir = grubconf; ++ condition = COND_HOST_LINUX; ++}; ++ + script = { + name = '30_os-prober'; + common = util/grub.d/30_os-prober.in; +diff --git a/util/grub.d/20_ppc_terminfo.in b/util/grub.d/20_ppc_terminfo.in +new file mode 100644 +index 00000000000..10d66586820 +--- /dev/null ++++ b/util/grub.d/20_ppc_terminfo.in +@@ -0,0 +1,114 @@ ++#! /bin/sh ++set -e ++ ++# grub-mkconfig helper script. ++# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. ++# ++# GRUB is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# GRUB is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GRUB. If not, see . ++ ++prefix=@prefix@ ++exec_prefix=@exec_prefix@ ++bindir=@bindir@ ++libdir=@libdir@ ++. "@datadir@/@PACKAGE@/grub-mkconfig_lib" ++ ++export TEXTDOMAIN=@PACKAGE@ ++export TEXTDOMAINDIR=@localedir@ ++ ++X=80 ++Y=24 ++TERMINAL=ofconsole ++ ++argument () { ++ opt=$1 ++ shift ++ ++ if test $# -eq 0; then ++ echo "$0: option requires an argument -- '$opt'" 1>&2 ++ exit 1 ++ fi ++ echo $1 ++} ++ ++check_terminfo () { ++ ++ while test $# -gt 0 ++ do ++ option=$1 ++ shift ++ ++ case "$option" in ++ terminfo | TERMINFO) ++ ;; ++ ++ -g) ++ NEWXY=`argument $option "$@"` ++ NEWX=`echo $NEWXY | cut -d x -f 1` ++ NEWY=`echo $NEWXY | cut -d x -f 2` ++ ++ if [ ${NEWX} -ge 80 ] ; then ++ X=${NEWX} ++ else ++ echo "Warning: ${NEWX} is less than the minimum size of 80" ++ fi ++ ++ if [ ${NEWY} -ge 24 ] ; then ++ Y=${NEWY} ++ else ++ echo "Warning: ${NEWY} is less than the minimum size of 24" ++ fi ++ ++ shift ++ ;; ++ ++ *) ++# # accept console or ofconsole ++# if [ "$option" != "console" -a "$option" != "ofconsole" ] ; then ++# echo "Error: GRUB_TERMINFO unknown console: $option" ++# exit 1 ++# fi ++# # perfer console ++# TERMINAL=console ++ # accept ofconsole ++ if [ "$option" != "ofconsole" ] ; then ++ echo "Error: GRUB_TERMINFO unknown console: $option" ++ exit 1 ++ fi ++ # perfer console ++ TERMINAL=ofconsole ++ ;; ++ esac ++ ++ done ++ ++} ++ ++if ! uname -m | grep -q ppc ; then ++ exit 0 ++fi ++ ++if [ "x${GRUB_TERMINFO}" != "x" ] ; then ++ F1=`echo ${GRUB_TERMINFO} | cut -d " " -f 1` ++ ++ if [ "${F1}" != "terminfo" ] ; then ++ echo "Error: GRUB_TERMINFO is set to \"${GRUB_TERMINFO}\" The first word should be terminfo." ++ exit 1 ++ fi ++ ++ check_terminfo ${GRUB_TERMINFO} ++fi ++ ++cat << EOF ++ terminfo -g ${X}x${Y} ${TERMINAL} ++EOF diff --git a/0023-Add-fw_path-variable-revised.patch b/0023-Add-fw_path-variable-revised.patch new file mode 100644 index 0000000..36c3b1f --- /dev/null +++ b/0023-Add-fw_path-variable-revised.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Wed, 19 Sep 2012 21:22:55 -0300 +Subject: [PATCH] Add fw_path variable (revised) + +This patch makes grub look for its config file on efi where the app was +found. It was originally written by Matthew Garrett, and adapted to fix the +"No modules are loaded on grub2 network boot" issue: + +https://bugzilla.redhat.com/show_bug.cgi?id=857936 +--- + grub-core/kern/main.c | 13 ++++++------- + grub-core/normal/main.c | 25 ++++++++++++++++++++++++- + 2 files changed, 30 insertions(+), 8 deletions(-) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index 9cad0c4485c..8ab7794c47b 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -127,16 +127,15 @@ grub_set_prefix_and_root (void) + + grub_machine_get_bootlocation (&fwdevice, &fwpath); + +- if (fwdevice) ++ if (fwdevice && fwpath) + { +- char *cmdpath; ++ char *fw_path; + +- cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : ""); +- if (cmdpath) ++ fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath); ++ if (fw_path) + { +- grub_env_set ("cmdpath", cmdpath); +- grub_env_export ("cmdpath"); +- grub_free (cmdpath); ++ grub_env_set ("fw_path", fw_path); ++ grub_free (fw_path); + } + } + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 222e239c1be..394bfbea868 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -338,7 +338,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + /* Guess the config filename. It is necessary to make CONFIG static, + so that it won't get broken by longjmp. */ + char *config; +- const char *prefix; ++ const char *prefix, *fw_path; ++ ++ fw_path = grub_env_get ("fw_path"); ++ if (fw_path) ++ { ++ config = grub_xasprintf ("%s/grub.cfg", fw_path); ++ if (config) ++ { ++ grub_file_t file; ++ ++ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); ++ if (file) ++ { ++ grub_file_close (file); ++ grub_enter_normal_mode (config); ++ } ++ else ++ { ++ /* Ignore all errors. */ ++ grub_errno = 0; ++ } ++ grub_free (config); ++ } ++ } + + prefix = grub_env_get ("prefix"); + if (prefix) diff --git a/0024-Pass-x-hex-hex-straight-through-unmolested.patch b/0024-Pass-x-hex-hex-straight-through-unmolested.patch new file mode 100644 index 0000000..4fd7811 --- /dev/null +++ b/0024-Pass-x-hex-hex-straight-through-unmolested.patch @@ -0,0 +1,179 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 Oct 2012 13:24:37 -0400 +Subject: [PATCH] Pass "\x[[:hex:]][[:hex:]]" straight through unmolested. + +--- + grub-core/commands/wildcard.c | 16 +++++++++++++++- + grub-core/lib/cmdline.c | 34 ++++++++++++++++++++++++++++++++-- + grub-core/script/execute.c | 43 +++++++++++++++++++++++++++++++++++++------ + 3 files changed, 84 insertions(+), 9 deletions(-) + +diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c +index 4a106ca040b..560d437cdc6 100644 +--- a/grub-core/commands/wildcard.c ++++ b/grub-core/commands/wildcard.c +@@ -462,6 +462,12 @@ check_file (const char *dir, const char *basename) + return ctx.found; + } + ++static int ++is_hex(char c) ++{ ++ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); ++} ++ + static void + unescape (char *out, const char *in, const char *end) + { +@@ -470,7 +476,15 @@ unescape (char *out, const char *in, const char *end) + + for (optr = out, iptr = in; iptr < end;) + { +- if (*iptr == '\\' && iptr + 1 < end) ++ if (*iptr == '\\' && iptr + 3 < end && iptr[1] == 'x' && is_hex(iptr[2]) && is_hex(iptr[3])) ++ { ++ *optr++ = *iptr++; ++ *optr++ = *iptr++; ++ *optr++ = *iptr++; ++ *optr++ = *iptr++; ++ continue; ++ } ++ else if (*iptr == '\\' && iptr + 1 < end) + { + *optr++ = iptr[1]; + iptr += 2; +diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c +index ed0b149dca5..e0fb0a9e48a 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -20,6 +20,12 @@ + #include + #include + ++static int ++is_hex(char c) ++{ ++ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); ++} ++ + static unsigned int check_arg (char *c, int *has_space) + { + int space = 0; +@@ -27,7 +33,13 @@ static unsigned int check_arg (char *c, int *has_space) + + while (*c) + { +- if (*c == '\\' || *c == '\'' || *c == '"') ++ if (*c == '\\' && *(c+1) == 'x' && is_hex(*(c+2)) && is_hex(*(c+3))) ++ { ++ size += 4; ++ c += 4; ++ continue; ++ } ++ else if (*c == '\\' || *c == '\'' || *c == '"') + size++; + else if (*c == ' ') + space = 1; +@@ -86,7 +98,25 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, + + while (*c) + { +- if (*c == '\\' || *c == '\'' || *c == '"') ++ if (*c == ' ') ++ { ++ *buf++ = '\\'; ++ *buf++ = 'x'; ++ *buf++ = '2'; ++ *buf++ = '0'; ++ c++; ++ continue; ++ } ++ else if (*c == '\\' && *(c+1) == 'x' && ++ is_hex(*(c+2)) && is_hex(*(c+3))) ++ { ++ *buf++ = *c++; ++ *buf++ = *c++; ++ *buf++ = *c++; ++ *buf++ = *c++; ++ continue; ++ } ++ else if (*c == '\\' || *c == '\'' || *c == '"') + *buf++ = '\\'; + + *buf++ = *c; +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index 0d05d6b0709..ba38b5e8aef 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -56,6 +56,12 @@ static struct grub_script_scope *scope = 0; + /* Wildcard translator for GRUB script. */ + struct grub_script_wildcard_translator *grub_wildcard_translator; + ++static int ++is_hex(char c) ++{ ++ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); ++} ++ + static char* + wildcard_escape (const char *s) + { +@@ -72,7 +78,15 @@ wildcard_escape (const char *s) + i = 0; + while ((ch = *s++)) + { +- if (ch == '*' || ch == '\\' || ch == '?') ++ if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2])) ++ { ++ p[i++] = ch; ++ p[i++] = *s++; ++ p[i++] = *s++; ++ p[i++] = *s++; ++ continue; ++ } ++ else if (ch == '*' || ch == '\\' || ch == '?') + p[i++] = '\\'; + p[i++] = ch; + } +@@ -96,7 +110,14 @@ wildcard_unescape (const char *s) + i = 0; + while ((ch = *s++)) + { +- if (ch == '\\') ++ if (ch == '\\' && s[0] == 'x' && is_hex(s[1]) && is_hex(s[2])) ++ { ++ p[i++] = '\\'; ++ p[i++] = *s++; ++ p[i++] = *s++; ++ p[i++] = *s++; ++ } ++ else if (ch == '\\') + p[i++] = *s++; + else + p[i++] = ch; +@@ -398,10 +419,20 @@ parse_string (const char *str, + switch (*ptr) + { + case '\\': +- escaped = !escaped; +- if (!escaped && put) +- *(put++) = '\\'; +- ptr++; ++ if (!escaped && put && *(ptr+1) == 'x' && is_hex(*(ptr+2)) && is_hex(*(ptr+3))) ++ { ++ *(put++) = *ptr++; ++ *(put++) = *ptr++; ++ *(put++) = *ptr++; ++ *(put++) = *ptr++; ++ } ++ else ++ { ++ escaped = !escaped; ++ if (!escaped && put) ++ *(put++) = '\\'; ++ ptr++; ++ } + break; + case '$': + if (escaped) diff --git a/0025-Add-X-option-to-printf-functions.patch b/0025-Add-X-option-to-printf-functions.patch new file mode 100644 index 0000000..5f2a075 --- /dev/null +++ b/0025-Add-X-option-to-printf-functions.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Tue, 27 Nov 2012 16:58:39 -0200 +Subject: [PATCH] Add %X option to printf functions. + +--- + grub-core/kern/misc.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index cd63a8cea73..2656a670e09 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -588,7 +588,7 @@ grub_divmod64 (grub_uint64_t n, grub_uint64_t d, grub_uint64_t *r) + static inline char * + grub_lltoa (char *str, int c, unsigned long long n) + { +- unsigned base = (c == 'x') ? 16 : 10; ++ unsigned base = ((c == 'x') || (c == 'X')) ? 16 : 10; + char *p; + + if ((long long) n < 0 && c == 'd') +@@ -603,7 +603,7 @@ grub_lltoa (char *str, int c, unsigned long long n) + do + { + unsigned d = (unsigned) (n & 0xf); +- *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; ++ *p++ = (d > 9) ? d + ((c == 'x') ? 'a' : 'A') - 10 : d + '0'; + } + while (n >>= 4); + else +@@ -676,6 +676,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, + { + case 'p': + case 'x': ++ case 'X': + case 'u': + case 'd': + case 'c': +@@ -762,6 +763,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, + switch (c) + { + case 'x': ++ case 'X': + case 'u': + args->ptr[curn].type = UNSIGNED_INT + longfmt; + break; +@@ -900,6 +902,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, + c = 'x'; + /* Fall through. */ + case 'x': ++ case 'X': + case 'u': + case 'd': + { diff --git a/0026-Search-for-specific-config-file-for-netboot.patch b/0026-Search-for-specific-config-file-for-netboot.patch new file mode 100644 index 0000000..f94911c --- /dev/null +++ b/0026-Search-for-specific-config-file-for-netboot.patch @@ -0,0 +1,200 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Tue, 27 Nov 2012 17:22:07 -0200 +Subject: [PATCH] Search for specific config file for netboot + +This patch implements a search for a specific configuration when the config +file is on a remoteserver. It uses the following order: + 1) DHCP client UUID option. + 2) MAC address (in lower case hexadecimal with dash separators); + 3) IP (in upper case hexadecimal) or IPv6; + 4) The original grub.cfg file. + +This procedure is similar to what is used by pxelinux and yaboot: +http://www.syslinux.org/wiki/index.php/PXELINUX#config + +This should close the bugzilla: +https://bugzilla.redhat.com/show_bug.cgi?id=873406 +--- + grub-core/net/net.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ + grub-core/normal/main.c | 18 ++++++-- + include/grub/net.h | 3 ++ + 3 files changed, 135 insertions(+), 4 deletions(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index d5d726a315e..06454564b8f 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1735,6 +1735,124 @@ grub_net_restore_hw (void) + return GRUB_ERR_NONE; + } + ++grub_err_t ++grub_net_search_configfile (char *config) ++{ ++ grub_size_t config_len; ++ char *suffix; ++ ++ auto int search_through (grub_size_t num_tries, grub_size_t slice_size); ++ int search_through (grub_size_t num_tries, grub_size_t slice_size) ++ { ++ while (num_tries-- > 0) ++ { ++ grub_dprintf ("net", "probe %s\n", config); ++ ++ grub_file_t file; ++ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); ++ ++ if (file) ++ { ++ grub_file_close (file); ++ grub_dprintf ("net", "found!\n"); ++ return 0; ++ } ++ else ++ { ++ if (grub_errno == GRUB_ERR_IO) ++ grub_errno = GRUB_ERR_NONE; ++ } ++ ++ if (grub_strlen (suffix) < slice_size) ++ break; ++ ++ config[grub_strlen (config) - slice_size] = '\0'; ++ } ++ ++ return 1; ++ } ++ ++ config_len = grub_strlen (config); ++ config[config_len] = '-'; ++ suffix = config + config_len + 1; ++ ++ struct grub_net_network_level_interface *inf; ++ FOR_NET_NETWORK_LEVEL_INTERFACES (inf) ++ { ++ /* By the Client UUID. */ ++ ++ char client_uuid_var[sizeof ("net_") + grub_strlen (inf->name) + ++ sizeof ("_clientuuid") + 1]; ++ grub_snprintf (client_uuid_var, sizeof (client_uuid_var), ++ "net_%s_clientuuid", inf->name); ++ ++ const char *client_uuid; ++ client_uuid = grub_env_get (client_uuid_var); ++ ++ if (client_uuid) ++ { ++ grub_strcpy (suffix, client_uuid); ++ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; ++ } ++ ++ /* By the MAC address. */ ++ ++ /* Add ethernet type */ ++ grub_strcpy (suffix, "01-"); ++ ++ grub_net_hwaddr_to_str (&inf->hwaddress, suffix + 3); ++ ++ char *ptr; ++ for (ptr = suffix; *ptr; ptr++) ++ if (*ptr == ':') ++ *ptr = '-'; ++ ++ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; ++ ++ /* By IP address */ ++ ++ switch ((&inf->address)->type) ++ { ++ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: ++ { ++ grub_uint32_t n = grub_be_to_cpu32 ((&inf->address)->ipv4); ++ grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%02X%02X%02X%02X", \ ++ ((n >> 24) & 0xff), ((n >> 16) & 0xff), \ ++ ((n >> 8) & 0xff), ((n >> 0) & 0xff)); ++ ++ if (search_through (8, 1) == 0) return GRUB_ERR_NONE; ++ break; ++ } ++ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6: ++ { ++ char buf[GRUB_NET_MAX_STR_ADDR_LEN]; ++ struct grub_net_network_level_address base; ++ base.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ grub_memcpy (&base.ipv6, ((&inf->address)->ipv6), 16); ++ grub_net_addr_to_str (&base, buf); ++ ++ for (ptr = buf; *ptr; ptr++) ++ if (*ptr == ':') ++ *ptr = '-'; ++ ++ grub_snprintf (suffix, GRUB_NET_MAX_STR_ADDR_LEN, "%s", buf); ++ if (search_through (1, 0) == 0) return GRUB_ERR_NONE; ++ break; ++ } ++ case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV: ++ return grub_error (GRUB_ERR_BUG, "shouldn't reach here"); ++ default: ++ return grub_error (GRUB_ERR_BUG, ++ "unsupported address type %d", (&inf->address)->type); ++ } ++ } ++ ++ /* Remove the remaining minus sign at the end. */ ++ config[config_len] = '\0'; ++ ++ return GRUB_ERR_NONE; ++} ++ + static struct grub_preboot *fini_hnd; + + static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 394bfbea868..9ef98481f70 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + #ifdef GRUB_MACHINE_IEEE1275 + #include + #endif +@@ -365,10 +366,19 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + + prefix = grub_env_get ("prefix"); + if (prefix) +- { +- config = grub_xasprintf ("%s/grub.cfg", prefix); +- if (! config) +- goto quit; ++ { ++ grub_size_t config_len; ++ config_len = grub_strlen (prefix) + ++ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); ++ config = grub_malloc (config_len); ++ ++ if (! config) ++ goto quit; ++ ++ grub_snprintf (config, config_len, "%s/grub.cfg", prefix); ++ ++ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) ++ grub_net_search_configfile (config); + + grub_enter_normal_mode (config); + grub_free (config); +diff --git a/include/grub/net.h b/include/grub/net.h +index 556c54e579f..ff6d347f7da 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -578,4 +578,7 @@ extern char *grub_net_default_server; + + #define VLANTAG_IDENTIFIER 0x8100 + ++grub_err_t ++grub_net_search_configfile (char *config); ++ + #endif /* ! GRUB_NET_HEADER */ diff --git a/0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch b/0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch new file mode 100644 index 0000000..ada4564 --- /dev/null +++ b/0027-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch @@ -0,0 +1,1528 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 22 Jan 2013 06:31:38 +0100 +Subject: [PATCH] blscfg: add blscfg module to parse Boot Loader Specification + snippets + +The BootLoaderSpec (BLS) defines a scheme where different bootloaders can +share a format for boot items and a configuration directory that accepts +these common configurations as drop-in files. + +Signed-off-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +[wjt: some cleanups and fixes] +Signed-off-by: Will Thompson +--- + grub-core/Makefile.core.def | 11 + + grub-core/commands/blscfg.c | 1096 ++++++++++++++++++++++++++++++++++++++++ + grub-core/commands/legacycfg.c | 5 +- + grub-core/commands/loadenv.c | 77 +-- + grub-core/commands/menuentry.c | 20 +- + grub-core/normal/main.c | 6 + + grub-core/commands/loadenv.h | 93 ++++ + include/grub/compiler.h | 2 + + include/grub/menu.h | 13 + + include/grub/normal.h | 2 +- + 10 files changed, 1243 insertions(+), 82 deletions(-) + create mode 100644 grub-core/commands/blscfg.c + create mode 100644 grub-core/commands/loadenv.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 41b5e16a3ce..57e253ab1a1 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -811,6 +811,16 @@ module = { + common = commands/blocklist.c; + }; + ++module = { ++ name = blscfg; ++ common = commands/blscfg.c; ++ common = commands/loadenv.h; ++ enable = powerpc_ieee1275; ++ enable = efi; ++ enable = i386_pc; ++ enable = emu; ++}; ++ + module = { + name = boot; + common = commands/boot.c; +@@ -988,6 +998,7 @@ module = { + module = { + name = loadenv; + common = commands/loadenv.c; ++ common = commands/loadenv.h; + common = lib/envblk.c; + }; + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +new file mode 100644 +index 00000000000..54458b14518 +--- /dev/null ++++ b/grub-core/commands/blscfg.c +@@ -0,0 +1,1096 @@ ++/*-*- Mode: C; c-basic-offset: 2; indent-tabs-mode: t -*-*/ ++ ++/* bls.c - implementation of the boot loader spec */ ++ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++#include "loadenv.h" ++ ++#define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++#ifdef GRUB_MACHINE_EMU ++#define GRUB_BOOT_DEVICE "/boot" ++#else ++#define GRUB_BOOT_DEVICE "($root)" ++#endif ++ ++struct keyval ++{ ++ const char *key; ++ char *val; ++}; ++ ++static struct bls_entry *entries = NULL; ++ ++#define FOR_BLS_ENTRIES(var) FOR_LIST_ELEMENTS (var, entries) ++ ++static int bls_add_keyval(struct bls_entry *entry, char *key, char *val) ++{ ++ char *k, *v; ++ struct keyval **kvs, *kv; ++ int new_n = entry->nkeyvals + 1; ++ ++ kvs = grub_realloc (entry->keyvals, new_n * sizeof (struct keyval *)); ++ if (!kvs) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry"); ++ entry->keyvals = kvs; ++ ++ kv = grub_malloc (sizeof (struct keyval)); ++ if (!kv) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry"); ++ ++ k = grub_strdup (key); ++ if (!k) ++ { ++ grub_free (kv); ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry"); ++ } ++ ++ v = grub_strdup (val); ++ if (!v) ++ { ++ grub_free (k); ++ grub_free (kv); ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry"); ++ } ++ ++ kv->key = k; ++ kv->val = v; ++ ++ entry->keyvals[entry->nkeyvals] = kv; ++ grub_dprintf("blscfg", "new keyval at %p:%s:%s\n", entry->keyvals[entry->nkeyvals], k, v); ++ entry->nkeyvals = new_n; ++ ++ return 0; ++} ++ ++/* Find they value of the key named by keyname. If there are allowed to be ++ * more than one, pass a pointer to an int set to -1 the first time, and pass ++ * the same pointer through each time after, and it'll return them in sorted ++ * order as defined in the BLS fragment file */ ++static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last) ++{ ++ int idx, start = 0; ++ struct keyval *kv = NULL; ++ ++ if (last) ++ start = *last + 1; ++ ++ for (idx = start; idx < entry->nkeyvals; idx++) { ++ kv = entry->keyvals[idx]; ++ ++ if (!grub_strcmp (keyname, kv->key)) ++ break; ++ } ++ ++ if (idx == entry->nkeyvals) { ++ if (last) ++ *last = -1; ++ return NULL; ++ } ++ ++ if (last) ++ *last = idx; ++ ++ return kv->val; ++} ++ ++#define goto_return(x) ({ ret = (x); goto finish; }) ++ ++/* compare alpha and numeric segments of two versions */ ++/* return 1: a is newer than b */ ++/* 0: a and b are the same version */ ++/* -1: b is newer than a */ ++static int vercmp(const char * a, const char * b) ++{ ++ char oldch1, oldch2; ++ char *abuf, *bbuf; ++ char *str1, *str2; ++ char * one, * two; ++ int rc; ++ int isnum; ++ int ret = 0; ++ ++ grub_dprintf("blscfg", "%s comparing %s and %s\n", __func__, a, b); ++ if (!grub_strcmp(a, b)) ++ return 0; ++ ++ abuf = grub_malloc(grub_strlen(a) + 1); ++ bbuf = grub_malloc(grub_strlen(b) + 1); ++ str1 = abuf; ++ str2 = bbuf; ++ grub_strcpy(str1, a); ++ grub_strcpy(str2, b); ++ ++ one = str1; ++ two = str2; ++ ++ /* loop through each version segment of str1 and str2 and compare them */ ++ while (*one || *two) { ++ while (*one && !grub_isalnum(*one) && *one != '~') one++; ++ while (*two && !grub_isalnum(*two) && *two != '~') two++; ++ ++ /* handle the tilde separator, it sorts before everything else */ ++ if (*one == '~' || *two == '~') { ++ if (*one != '~') goto_return (1); ++ if (*two != '~') goto_return (-1); ++ one++; ++ two++; ++ continue; ++ } ++ ++ /* If we ran to the end of either, we are finished with the loop */ ++ if (!(*one && *two)) break; ++ ++ str1 = one; ++ str2 = two; ++ ++ /* grab first completely alpha or completely numeric segment */ ++ /* leave one and two pointing to the start of the alpha or numeric */ ++ /* segment and walk str1 and str2 to end of segment */ ++ if (grub_isdigit(*str1)) { ++ while (*str1 && grub_isdigit(*str1)) str1++; ++ while (*str2 && grub_isdigit(*str2)) str2++; ++ isnum = 1; ++ } else { ++ while (*str1 && grub_isalpha(*str1)) str1++; ++ while (*str2 && grub_isalpha(*str2)) str2++; ++ isnum = 0; ++ } ++ ++ /* save character at the end of the alpha or numeric segment */ ++ /* so that they can be restored after the comparison */ ++ oldch1 = *str1; ++ *str1 = '\0'; ++ oldch2 = *str2; ++ *str2 = '\0'; ++ ++ /* this cannot happen, as we previously tested to make sure that */ ++ /* the first string has a non-null segment */ ++ if (one == str1) goto_return(-1); /* arbitrary */ ++ ++ /* take care of the case where the two version segments are */ ++ /* different types: one numeric, the other alpha (i.e. empty) */ ++ /* numeric segments are always newer than alpha segments */ ++ /* XXX See patch #60884 (and details) from bugzilla #50977. */ ++ if (two == str2) goto_return (isnum ? 1 : -1); ++ ++ if (isnum) { ++ grub_size_t onelen, twolen; ++ /* this used to be done by converting the digit segments */ ++ /* to ints using atoi() - it's changed because long */ ++ /* digit segments can overflow an int - this should fix that. */ ++ ++ /* throw away any leading zeros - it's a number, right? */ ++ while (*one == '0') one++; ++ while (*two == '0') two++; ++ ++ /* whichever number has more digits wins */ ++ onelen = grub_strlen(one); ++ twolen = grub_strlen(two); ++ if (onelen > twolen) goto_return (1); ++ if (twolen > onelen) goto_return (-1); ++ } ++ ++ /* grub_strcmp will return which one is greater - even if the two */ ++ /* segments are alpha or if they are numeric. don't return */ ++ /* if they are equal because there might be more segments to */ ++ /* compare */ ++ rc = grub_strcmp(one, two); ++ if (rc) goto_return (rc < 1 ? -1 : 1); ++ ++ /* restore character that was replaced by null above */ ++ *str1 = oldch1; ++ one = str1; ++ *str2 = oldch2; ++ two = str2; ++ } ++ ++ /* this catches the case where all numeric and alpha segments have */ ++ /* compared identically but the segment sepparating characters were */ ++ /* different */ ++ if ((!*one) && (!*two)) goto_return (0); ++ ++ /* whichever version still has characters left over wins */ ++ if (!*one) goto_return (-1); else goto_return (1); ++ ++finish: ++ grub_free (abuf); ++ grub_free (bbuf); ++ return ret; ++} ++ ++/* returns name/version/release */ ++/* NULL string pointer returned if nothing found */ ++static void ++split_package_string (char *package_string, char **name, ++ char **version, char **release) ++{ ++ char *package_version, *package_release; ++ ++ /* Release */ ++ package_release = grub_strrchr (package_string, '-'); ++ ++ if (package_release != NULL) ++ *package_release++ = '\0'; ++ ++ *release = package_release; ++ ++ if (name == NULL) ++ { ++ *version = package_string; ++ } ++ else ++ { ++ /* Version */ ++ package_version = grub_strrchr(package_string, '-'); ++ ++ if (package_version != NULL) ++ *package_version++ = '\0'; ++ ++ *version = package_version; ++ /* Name */ ++ *name = package_string; ++ } ++ ++ /* Bubble up non-null values from release to name */ ++ if (name != NULL && *name == NULL) ++ { ++ *name = (*version == NULL ? *release : *version); ++ *version = *release; ++ *release = NULL; ++ } ++ if (*version == NULL) ++ { ++ *version = *release; ++ *release = NULL; ++ } ++} ++ ++static int ++split_cmp(char *nvr0, char *nvr1, int has_name) ++{ ++ int ret = 0; ++ char *name0, *version0, *release0; ++ char *name1, *version1, *release1; ++ ++ split_package_string(nvr0, has_name ? &name0 : NULL, &version0, &release0); ++ split_package_string(nvr1, has_name ? &name1 : NULL, &version1, &release1); ++ ++ if (has_name) ++ { ++ ret = vercmp(name0 == NULL ? "" : name0, ++ name1 == NULL ? "" : name1); ++ if (ret != 0) ++ return ret; ++ } ++ ++ ret = vercmp(version0 == NULL ? "" : version0, ++ version1 == NULL ? "" : version1); ++ if (ret != 0) ++ return ret; ++ ++ ret = vercmp(release0 == NULL ? "" : release0, ++ release1 == NULL ? "" : release1); ++ return ret; ++} ++ ++/* return 1: e0 is newer than e1 */ ++/* 0: e0 and e1 are the same version */ ++/* -1: e1 is newer than e0 */ ++static int bls_cmp(const struct bls_entry *e0, const struct bls_entry *e1) ++{ ++ char *id0, *id1; ++ int r; ++ ++ id0 = grub_strdup(e0->filename); ++ id1 = grub_strdup(e1->filename); ++ ++ r = split_cmp(id0, id1, 1); ++ ++ grub_free(id0); ++ grub_free(id1); ++ ++ return r; ++} ++ ++static void list_add_tail(struct bls_entry *head, struct bls_entry *item) ++{ ++ item->next = head; ++ if (head->prev) ++ head->prev->next = item; ++ item->prev = head->prev; ++ head->prev = item; ++} ++ ++static int bls_add_entry(struct bls_entry *entry) ++{ ++ struct bls_entry *e, *last = NULL; ++ int rc; ++ ++ if (!entries) { ++ grub_dprintf ("blscfg", "Add entry with id \"%s\"\n", entry->filename); ++ entries = entry; ++ return 0; ++ } ++ ++ FOR_BLS_ENTRIES(e) { ++ rc = bls_cmp(entry, e); ++ ++ if (!rc) ++ return GRUB_ERR_BAD_ARGUMENT; ++ ++ if (rc == 1) { ++ grub_dprintf ("blscfg", "Add entry with id \"%s\"\n", entry->filename); ++ list_add_tail (e, entry); ++ if (e == entries) { ++ entries = entry; ++ entry->prev = NULL; ++ } ++ return 0; ++ } ++ last = e; ++ } ++ ++ if (last) { ++ grub_dprintf ("blscfg", "Add entry with id \"%s\"\n", entry->filename); ++ last->next = entry; ++ entry->prev = last; ++ } ++ ++ return 0; ++} ++ ++struct read_entry_info { ++ const char *devid; ++ const char *dirname; ++ grub_file_t file; ++}; ++ ++static int read_entry ( ++ const char *filename, ++ const struct grub_dirhook_info *dirhook_info UNUSED, ++ void *data) ++{ ++ grub_size_t m = 0, n, clip = 0; ++ int rc = 0; ++ char *p = NULL; ++ grub_file_t f = NULL; ++ struct bls_entry *entry; ++ struct read_entry_info *info = (struct read_entry_info *)data; ++ ++ grub_dprintf ("blscfg", "filename: \"%s\"\n", filename); ++ ++ n = grub_strlen (filename); ++ ++ if (info->file) ++ { ++ f = info->file; ++ } ++ else ++ { ++ if (filename[0] == '.') ++ return 0; ++ ++ if (n <= 5) ++ return 0; ++ ++ if (grub_strcmp (filename + n - 5, ".conf") != 0) ++ return 0; ++ ++ p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename); ++ ++ f = grub_file_open (p, GRUB_FILE_TYPE_CONFIG); ++ if (!f) ++ goto finish; ++ } ++ ++ entry = grub_zalloc (sizeof (*entry)); ++ if (!entry) ++ goto finish; ++ ++ if (info->file) ++ { ++ char *slash; ++ ++ if (n > 5 && !grub_strcmp (filename + n - 5, ".conf") == 0) ++ clip = 5; ++ ++ slash = grub_strrchr (filename, '/'); ++ if (!slash) ++ slash = grub_strrchr (filename, '\\'); ++ ++ while (*slash == '/' || *slash == '\\') ++ slash++; ++ ++ m = slash ? slash - filename : 0; ++ } ++ else ++ { ++ m = 0; ++ clip = 5; ++ } ++ n -= m; ++ ++ entry->filename = grub_strndup(filename + m, n - clip); ++ if (!entry->filename) ++ goto finish; ++ ++ entry->filename[n - 5] = '\0'; ++ ++ for (;;) ++ { ++ char *buf; ++ char *separator; ++ ++ buf = grub_file_getline (f); ++ if (!buf) ++ break; ++ ++ while (buf && buf[0] && (buf[0] == ' ' || buf[0] == '\t')) ++ buf++; ++ if (buf[0] == '#') ++ continue; ++ ++ separator = grub_strchr (buf, ' '); ++ ++ if (!separator) ++ separator = grub_strchr (buf, '\t'); ++ ++ if (!separator || separator[1] == '\0') ++ { ++ grub_free (buf); ++ break; ++ } ++ ++ separator[0] = '\0'; ++ ++ do { ++ separator++; ++ } while (*separator == ' ' || *separator == '\t'); ++ ++ rc = bls_add_keyval (entry, buf, separator); ++ grub_free (buf); ++ if (rc < 0) ++ break; ++ } ++ ++ if (!rc) ++ bls_add_entry(entry); ++ ++finish: ++ if (p) ++ grub_free (p); ++ ++ if (f) ++ grub_file_close (f); ++ ++ return 0; ++} ++ ++static grub_envblk_t saved_env = NULL; ++ ++static int UNUSED ++save_var (const char *name, const char *value, void *whitelist UNUSED) ++{ ++ const char *val = grub_env_get (name); ++ grub_dprintf("blscfg", "saving \"%s\"\n", name); ++ ++ if (val) ++ grub_envblk_set (saved_env, name, value); ++ ++ return 0; ++} ++ ++static int UNUSED ++unset_var (const char *name, const char *value UNUSED, void *whitelist) ++{ ++ grub_dprintf("blscfg", "restoring \"%s\"\n", name); ++ if (! whitelist) ++ { ++ grub_env_unset (name); ++ return 0; ++ } ++ ++ if (test_whitelist_membership (name, ++ (const grub_env_whitelist_t *) whitelist)) ++ grub_env_unset (name); ++ ++ return 0; ++} ++ ++static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) ++{ ++ int last = -1; ++ char *val; ++ ++ int nlist = 0; ++ char **list = NULL; ++ ++ list = grub_malloc (sizeof (char *)); ++ if (!list) ++ return NULL; ++ list[0] = NULL; ++ ++ while (1) ++ { ++ char **new; ++ ++ val = bls_get_val (entry, key, &last); ++ if (!val) ++ break; ++ ++ new = grub_realloc (list, (nlist + 2) * sizeof (char *)); ++ if (!new) ++ break; ++ ++ list = new; ++ list[nlist++] = val; ++ list[nlist] = NULL; ++ } ++ ++ if (num) ++ *num = nlist; ++ ++ return list; ++} ++ ++static char *field_append(bool is_var, char *buffer, char *start, char *end) ++{ ++ char *temp = grub_strndup(start, end - start + 1); ++ const char *field = temp; ++ ++ if (is_var) { ++ field = grub_env_get (temp); ++ if (!field) ++ return buffer; ++ } ++ ++ if (!buffer) { ++ buffer = grub_strdup(field); ++ if (!buffer) ++ return NULL; ++ } else { ++ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field)); ++ if (!buffer) ++ return NULL; ++ ++ grub_stpcpy (buffer + grub_strlen(buffer), field); ++ } ++ ++ return buffer; ++} ++ ++static char *expand_val(char *value) ++{ ++ char *buffer = NULL; ++ char *start = value; ++ char *end = value; ++ bool is_var = false; ++ ++ if (!value) ++ return NULL; ++ ++ while (*value) { ++ if (*value == '$') { ++ if (start != end) { ++ buffer = field_append(is_var, buffer, start, end); ++ if (!buffer) ++ return NULL; ++ } ++ ++ is_var = true; ++ start = value + 1; ++ } else if (is_var) { ++ if (!grub_isalnum(*value) && *value != '_') { ++ buffer = field_append(is_var, buffer, start, end); ++ is_var = false; ++ start = value; ++ } ++ } ++ ++ end = value; ++ value++; ++ } ++ ++ if (start != end) { ++ buffer = field_append(is_var, buffer, start, end); ++ if (!buffer) ++ return NULL; ++ } ++ ++ return buffer; ++} ++ ++static char **early_initrd_list (const char *initrd) ++{ ++ int nlist = 0; ++ char **list = NULL; ++ char *separator; ++ ++ while ((separator = grub_strchr (initrd, ' '))) ++ { ++ list = grub_realloc (list, (nlist + 2) * sizeof (char *)); ++ if (!list) ++ return NULL; ++ ++ list[nlist++] = grub_strndup(initrd, separator - initrd); ++ list[nlist] = NULL; ++ initrd = separator + 1; ++ } ++ ++ list = grub_realloc (list, (nlist + 2) * sizeof (char *)); ++ if (!list) ++ return NULL; ++ ++ list[nlist++] = grub_strndup(initrd, grub_strlen(initrd)); ++ list[nlist] = NULL; ++ ++ return list; ++} ++ ++static void create_entry (struct bls_entry *entry) ++{ ++ int argc = 0; ++ const char **argv = NULL; ++ ++ char *title = NULL; ++ char *clinux = NULL; ++ char *options = NULL; ++ char **initrds = NULL; ++ char *initrd = NULL; ++ const char *early_initrd = NULL; ++ char **early_initrds = NULL; ++ char *initrd_prefix = NULL; ++ char *id = entry->filename; ++ char *dotconf = id; ++ char *hotkey = NULL; ++ ++ char *users = NULL; ++ char **classes = NULL; ++ ++ char **args = NULL; ++ ++ char *src = NULL; ++ int i, index; ++ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ clinux = bls_get_val (entry, "linux", NULL); ++ if (!clinux) ++ { ++ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", entry->filename); ++ goto finish; ++ } ++ ++ /* ++ * strip the ".conf" off the end before we make it our "id" field. ++ */ ++ do ++ { ++ dotconf = grub_strstr(dotconf, ".conf"); ++ } while (dotconf != NULL && dotconf[5] != '\0'); ++ if (dotconf) ++ dotconf[0] = '\0'; ++ ++ title = bls_get_val (entry, "title", NULL); ++ options = expand_val (bls_get_val (entry, "options", NULL)); ++ ++ if (!options) ++ options = expand_val (grub_env_get("default_kernelopts")); ++ ++ initrds = bls_make_list (entry, "initrd", NULL); ++ ++ 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); ++ args = bls_make_list (entry, "grub_arg", &argc); ++ ++ argc += 1; ++ argv = grub_malloc ((argc + 1) * sizeof (char *)); ++ argv[0] = title ? title : clinux; ++ for (i = 1; i < argc; i++) ++ argv[i] = args[i-1]; ++ argv[argc] = NULL; ++ ++ early_initrd = grub_env_get("early_initrd"); ++ ++ grub_dprintf ("blscfg", "adding menu entry for \"%s\" with id \"%s\"\n", ++ title, id); ++ if (early_initrd) ++ { ++ early_initrds = early_initrd_list(early_initrd); ++ if (!early_initrds) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto finish; ++ } ++ ++ if (initrds != NULL && initrds[0] != NULL) ++ { ++ initrd_prefix = grub_strrchr (initrds[0], '/'); ++ initrd_prefix = grub_strndup(initrds[0], initrd_prefix - initrds[0] + 1); ++ } ++ else ++ { ++ initrd_prefix = grub_strrchr (clinux, '/'); ++ initrd_prefix = grub_strndup(clinux, initrd_prefix - clinux + 1); ++ } ++ ++ if (!initrd_prefix) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto finish; ++ } ++ } ++ ++ if (early_initrds || initrds) ++ { ++ int initrd_size = sizeof ("initrd"); ++ char *tmp; ++ ++ for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++) ++ initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \ ++ + grub_strlen(initrd_prefix) \ ++ + grub_strlen (early_initrds[i]) + 1; ++ ++ for (i = 0; initrds != NULL && initrds[i] != NULL; i++) ++ initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \ ++ + grub_strlen (initrds[i]) + 1; ++ initrd_size += 1; ++ ++ initrd = grub_malloc (initrd_size); ++ if (!initrd) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ goto finish; ++ } ++ ++ ++ tmp = grub_stpcpy(initrd, "initrd"); ++ for (i = 0; early_initrds != NULL && early_initrds[i] != NULL; i++) ++ { ++ grub_dprintf ("blscfg", "adding early initrd %s\n", early_initrds[i]); ++ tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ tmp = grub_stpcpy (tmp, initrd_prefix); ++ tmp = grub_stpcpy (tmp, early_initrds[i]); ++ grub_free(early_initrds[i]); ++ } ++ ++ for (i = 0; initrds != NULL && initrds[i] != NULL; i++) ++ { ++ grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]); ++ tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE); ++ tmp = grub_stpcpy (tmp, initrds[i]); ++ } ++ tmp = grub_stpcpy (tmp, "\n"); ++ } ++ ++ src = grub_xasprintf ("load_video\n" ++ "set gfxpayload=keep\n" ++ "insmod gzio\n" ++ "linux %s%s%s%s\n" ++ "%s", ++ GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", ++ initrd ? initrd : ""); ++ ++ 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 (initrd); ++ grub_free (initrd_prefix); ++ grub_free (early_initrds); ++ grub_free (initrds); ++ grub_free (options); ++ grub_free (classes); ++ grub_free (args); ++ grub_free (argv); ++ grub_free (src); ++} ++ ++struct find_entry_info { ++ const char *dirname; ++ const char *devid; ++ grub_device_t dev; ++ grub_fs_t fs; ++}; ++ ++/* ++ * info: the filesystem object the file is on. ++ */ ++static int find_entry (struct find_entry_info *info) ++{ ++ struct read_entry_info read_entry_info; ++ grub_fs_t blsdir_fs = NULL; ++ grub_device_t blsdir_dev = NULL; ++ const char *blsdir = info->dirname; ++ int fallback = 0; ++ int r = 0; ++ ++ if (!blsdir) { ++ blsdir = grub_env_get ("blsdir"); ++ if (!blsdir) ++ blsdir = GRUB_BLS_CONFIG_PATH; ++ } ++ ++ read_entry_info.file = NULL; ++ read_entry_info.dirname = blsdir; ++ ++ grub_dprintf ("blscfg", "scanning blsdir: %s\n", blsdir); ++ ++ blsdir_dev = info->dev; ++ blsdir_fs = info->fs; ++ read_entry_info.devid = info->devid; ++ ++read_fallback: ++ r = blsdir_fs->fs_dir (blsdir_dev, read_entry_info.dirname, read_entry, ++ &read_entry_info); ++ if (r != 0) { ++ grub_dprintf ("blscfg", "read_entry returned error\n"); ++ grub_err_t e; ++ do ++ { ++ e = grub_error_pop(); ++ } while (e); ++ } ++ ++ if (r && !info->dirname && !fallback) { ++ read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH; ++ grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to %s\n", ++ blsdir, read_entry_info.dirname); ++ fallback = 1; ++ goto read_fallback; ++ } ++ ++ return 0; ++} ++ ++static grub_err_t ++bls_load_entries (const char *path) ++{ ++ grub_size_t len; ++ grub_fs_t fs; ++ grub_device_t dev; ++ static grub_err_t r; ++ const char *devid = NULL; ++ char *blsdir = NULL; ++ struct find_entry_info info = { ++ .dev = NULL, ++ .fs = NULL, ++ .dirname = NULL, ++ }; ++ struct read_entry_info rei = { ++ .devid = NULL, ++ .dirname = NULL, ++ }; ++ ++ if (path) { ++ len = grub_strlen (path); ++ if (grub_strcmp (path + len - 5, ".conf") == 0) { ++ rei.file = grub_file_open (path, GRUB_FILE_TYPE_CONFIG); ++ if (!rei.file) ++ return grub_errno; ++ /* ++ * read_entry() closes the file ++ */ ++ return read_entry(path, NULL, &rei); ++ } else if (path[0] == '(') { ++ devid = path + 1; ++ ++ blsdir = grub_strchr (path, ')'); ++ if (!blsdir) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Filepath isn't correct")); ++ ++ *blsdir = '\0'; ++ blsdir = blsdir + 1; ++ } ++ } ++ ++ if (!devid) { ++#ifdef GRUB_MACHINE_EMU ++ devid = "host"; ++#elif defined(GRUB_MACHINE_EFI) ++ devid = grub_env_get ("root"); ++#else ++ devid = grub_env_get ("boot"); ++#endif ++ if (!devid) ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, ++ N_("variable `%s' isn't set"), "boot"); ++ } ++ ++ grub_dprintf ("blscfg", "opening %s\n", devid); ++ dev = grub_device_open (devid); ++ if (!dev) ++ return grub_errno; ++ ++ grub_dprintf ("blscfg", "probing fs\n"); ++ fs = grub_fs_probe (dev); ++ if (!fs) ++ { ++ r = grub_errno; ++ goto finish; ++ } ++ ++ info.dirname = blsdir; ++ info.devid = devid; ++ info.dev = dev; ++ info.fs = fs; ++ find_entry(&info); ++ ++finish: ++ if (dev) ++ grub_device_close (dev); ++ ++ return r; ++} ++ ++static bool ++is_default_entry(const char *def_entry, struct bls_entry *entry, int idx) ++{ ++ const char *title; ++ int def_idx; ++ ++ if (!def_entry) ++ return false; ++ ++ if (grub_strcmp(def_entry, entry->filename) == 0) ++ return true; ++ ++ title = bls_get_val(entry, "title", NULL); ++ ++ if (title && grub_strcmp(def_entry, title) == 0) ++ return true; ++ ++ def_idx = (int)grub_strtol(def_entry, NULL, 0); ++ if (grub_errno == GRUB_ERR_BAD_NUMBER) { ++ grub_errno = GRUB_ERR_NONE; ++ return false; ++ } ++ ++ if (def_idx == idx) ++ return true; ++ ++ return false; ++} ++ ++static grub_err_t ++bls_create_entries (bool show_default, bool show_non_default, char *entry_id) ++{ ++ const char *def_entry = NULL; ++ struct bls_entry *entry = NULL; ++ int idx = 0; ++ ++ def_entry = grub_env_get("default"); ++ ++ grub_dprintf ("blscfg", "%s Creating entries from bls\n", __func__); ++ FOR_BLS_ENTRIES(entry) { ++ if (entry->visible) { ++ idx++; ++ continue; ++ } ++ ++ if ((show_default && is_default_entry(def_entry, entry, idx)) || ++ (show_non_default && !is_default_entry(def_entry, entry, idx)) || ++ (entry_id && grub_strcmp(entry_id, entry->filename) == 0)) { ++ create_entry(entry); ++ entry->visible = 1; ++ } ++ idx++; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, ++ int argc, char **args) ++{ ++ grub_err_t r; ++ char *path = NULL; ++ char *entry_id = NULL; ++ bool show_default = true; ++ bool show_non_default = true; ++ ++ if (argc == 1) { ++ if (grub_strcmp (args[0], "default") == 0) { ++ show_non_default = false; ++ } else if (grub_strcmp (args[0], "non-default") == 0) { ++ show_default = false; ++ } else if (args[0][0] == '(') { ++ path = args[0]; ++ } else { ++ entry_id = args[0]; ++ show_default = false; ++ show_non_default = false; ++ } ++ } ++ ++ r = bls_load_entries(path); ++ if (r) ++ return r; ++ ++ return bls_create_entries(show_default, show_non_default, entry_id); ++} ++ ++static grub_extcmd_t cmd; ++static grub_extcmd_t oldcmd; ++ ++GRUB_MOD_INIT(blscfg) ++{ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ cmd = grub_register_extcmd ("blscfg", ++ grub_cmd_blscfg, ++ 0, ++ NULL, ++ N_("Import Boot Loader Specification snippets."), ++ NULL); ++ oldcmd = grub_register_extcmd ("bls_import", ++ grub_cmd_blscfg, ++ 0, ++ NULL, ++ N_("Import Boot Loader Specification snippets."), ++ NULL); ++} ++ ++GRUB_MOD_FINI(blscfg) ++{ ++ grub_unregister_extcmd (cmd); ++ grub_unregister_extcmd (oldcmd); ++} +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index db7a8f00273..891eac5a33f 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -133,7 +133,7 @@ legacy_file (const char *filename) + args[0] = oldname; + grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy", + NULL, NULL, +- entrysrc, 0); ++ entrysrc, 0, NULL, NULL); + grub_free (args); + entrysrc[0] = 0; + grub_free (oldname); +@@ -186,7 +186,8 @@ legacy_file (const char *filename) + } + args[0] = entryname; + grub_normal_add_menu_entry (1, args, NULL, NULL, NULL, +- NULL, NULL, entrysrc, 0); ++ NULL, NULL, entrysrc, 0, NULL, ++ NULL); + grub_free (args); + } + +diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c +index 3fd664aac33..163b9a09042 100644 +--- a/grub-core/commands/loadenv.c ++++ b/grub-core/commands/loadenv.c +@@ -28,6 +28,8 @@ + #include + #include + ++#include "loadenv.h" ++ + GRUB_MOD_LICENSE ("GPLv3+"); + + static const struct grub_arg_option options[] = +@@ -79,81 +81,6 @@ open_envblk_file (char *filename, + return file; + } + +-static grub_envblk_t +-read_envblk_file (grub_file_t file) +-{ +- grub_off_t offset = 0; +- char *buf; +- grub_size_t size = grub_file_size (file); +- grub_envblk_t envblk; +- +- buf = grub_malloc (size); +- if (! buf) +- return 0; +- +- while (size > 0) +- { +- grub_ssize_t ret; +- +- ret = grub_file_read (file, buf + offset, size); +- if (ret <= 0) +- { +- grub_free (buf); +- return 0; +- } +- +- size -= ret; +- offset += ret; +- } +- +- envblk = grub_envblk_open (buf, offset); +- if (! envblk) +- { +- grub_free (buf); +- grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block"); +- return 0; +- } +- +- return envblk; +-} +- +-struct grub_env_whitelist +-{ +- grub_size_t len; +- char **list; +-}; +-typedef struct grub_env_whitelist grub_env_whitelist_t; +- +-static int +-test_whitelist_membership (const char* name, +- const grub_env_whitelist_t* whitelist) +-{ +- grub_size_t i; +- +- for (i = 0; i < whitelist->len; i++) +- if (grub_strcmp (name, whitelist->list[i]) == 0) +- return 1; /* found it */ +- +- return 0; /* not found */ +-} +- +-/* Helper for grub_cmd_load_env. */ +-static int +-set_var (const char *name, const char *value, void *whitelist) +-{ +- if (! whitelist) +- { +- grub_env_set (name, value); +- return 0; +- } +- +- if (test_whitelist_membership (name, +- (const grub_env_whitelist_t *) whitelist)) +- grub_env_set (name, value); +- +- return 0; +-} +- + static grub_err_t + grub_cmd_load_env (grub_extcmd_context_t ctxt, int argc, char **args) + { +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index 2c5363da7f5..9faf2be0f64 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + char **classes, const char *id, + const char *users, const char *hotkey, + const char *prefix, const char *sourcecode, +- int submenu) ++ int submenu, int *index, struct bls_entry *bls) + { + int menu_hotkey = 0; + char **menu_args = NULL; +@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char **args, + if (! menu_title) + goto fail; + ++ grub_dprintf ("menu", "id:\"%s\"\n", id); ++ grub_dprintf ("menu", "title:\"%s\"\n", menu_title); + menu_id = grub_strdup (id ? : menu_title); + if (! menu_id) + goto fail; ++ grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id); + + /* Save argc, args to pass as parameters to block arg later. */ + menu_args = grub_malloc (sizeof (char*) * (argc + 1)); +@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char **args, + } + + /* Add the menu entry at the end of the list. */ ++ int ind=0; + while (*last) +- last = &(*last)->next; ++ { ++ ind++; ++ last = &(*last)->next; ++ } + + *last = grub_zalloc (sizeof (**last)); + if (! *last) +@@ -188,8 +195,11 @@ grub_normal_add_menu_entry (int argc, const char **args, + (*last)->args = menu_args; + (*last)->sourcecode = menu_sourcecode; + (*last)->submenu = submenu; ++ (*last)->bls = bls; + + menu->size++; ++ if (index) ++ *index = ind; + return GRUB_ERR_NONE; + + fail: +@@ -286,7 +296,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + users, + ctxt->state[2].arg, 0, + ctxt->state[3].arg, +- ctxt->extcmd->cmd->name[0] == 's'); ++ ctxt->extcmd->cmd->name[0] == 's', ++ NULL, NULL); + + src = args[argc - 1]; + args[argc - 1] = NULL; +@@ -303,7 +314,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + ctxt->state[0].args, ctxt->state[4].arg, + users, + ctxt->state[2].arg, prefix, src + 1, +- ctxt->extcmd->cmd->name[0] == 's'); ++ ctxt->extcmd->cmd->name[0] == 's', NULL, ++ NULL); + + src[len - 1] = ch; + args[argc - 1] = src; +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 9ef98481f70..a326b192c89 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -70,6 +71,11 @@ grub_normal_free_menu (grub_menu_t menu) + grub_free (entry->args); + } + ++ if (entry->bls) ++ { ++ entry->bls->visible = 0; ++ } ++ + grub_free ((void *) entry->id); + grub_free ((void *) entry->users); + grub_free ((void *) entry->title); +diff --git a/grub-core/commands/loadenv.h b/grub-core/commands/loadenv.h +new file mode 100644 +index 00000000000..952f46121bd +--- /dev/null ++++ b/grub-core/commands/loadenv.h +@@ -0,0 +1,93 @@ ++/* loadenv.c - command to load/save environment variable. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++static grub_envblk_t UNUSED ++read_envblk_file (grub_file_t file) ++{ ++ grub_off_t offset = 0; ++ char *buf; ++ grub_size_t size = grub_file_size (file); ++ grub_envblk_t envblk; ++ ++ buf = grub_malloc (size); ++ if (! buf) ++ return 0; ++ ++ while (size > 0) ++ { ++ grub_ssize_t ret; ++ ++ ret = grub_file_read (file, buf + offset, size); ++ if (ret <= 0) ++ { ++ grub_free (buf); ++ return 0; ++ } ++ ++ size -= ret; ++ offset += ret; ++ } ++ ++ envblk = grub_envblk_open (buf, offset); ++ if (! envblk) ++ { ++ grub_free (buf); ++ grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block"); ++ return 0; ++ } ++ ++ return envblk; ++} ++ ++struct grub_env_whitelist ++{ ++ grub_size_t len; ++ char **list; ++}; ++typedef struct grub_env_whitelist grub_env_whitelist_t; ++ ++static int UNUSED ++test_whitelist_membership (const char* name, ++ const grub_env_whitelist_t* whitelist) ++{ ++ grub_size_t i; ++ ++ for (i = 0; i < whitelist->len; i++) ++ if (grub_strcmp (name, whitelist->list[i]) == 0) ++ return 1; /* found it */ ++ ++ return 0; /* not found */ ++} ++ ++/* Helper for grub_cmd_load_env. */ ++static int UNUSED ++set_var (const char *name, const char *value, void *whitelist) ++{ ++ if (! whitelist) ++ { ++ grub_env_set (name, value); ++ return 0; ++ } ++ ++ if (test_whitelist_membership (name, ++ (const grub_env_whitelist_t *) whitelist)) ++ grub_env_set (name, value); ++ ++ return 0; ++} +diff --git a/include/grub/compiler.h b/include/grub/compiler.h +index c9e1d7a73dc..9859ff4cc79 100644 +--- a/include/grub/compiler.h ++++ b/include/grub/compiler.h +@@ -48,4 +48,6 @@ + # define WARN_UNUSED_RESULT + #endif + ++#define UNUSED __attribute__((__unused__)) ++ + #endif /* ! GRUB_COMPILER_HEADER */ +diff --git a/include/grub/menu.h b/include/grub/menu.h +index ee2b5e91045..0acdc2aa6bf 100644 +--- a/include/grub/menu.h ++++ b/include/grub/menu.h +@@ -20,6 +20,16 @@ + #ifndef GRUB_MENU_HEADER + #define GRUB_MENU_HEADER 1 + ++struct bls_entry ++{ ++ struct bls_entry *next; ++ struct bls_entry *prev; ++ struct keyval **keyvals; ++ int nkeyvals; ++ char *filename; ++ int visible; ++}; ++ + struct grub_menu_entry_class + { + char *name; +@@ -60,6 +70,9 @@ struct grub_menu_entry + + /* The next element. */ + struct grub_menu_entry *next; ++ ++ /* BLS used to populate the entry */ ++ struct bls_entry *bls; + }; + typedef struct grub_menu_entry *grub_menu_entry_t; + +diff --git a/include/grub/normal.h b/include/grub/normal.h +index 218cbabccaf..8839ad85a19 100644 +--- a/include/grub/normal.h ++++ b/include/grub/normal.h +@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes, + const char *id, + const char *users, const char *hotkey, + const char *prefix, const char *sourcecode, +- int submenu); ++ int submenu, int *index, struct bls_entry *bls); + + grub_err_t + grub_normal_set_password (const char *user, const char *password); diff --git a/0028-Add-devicetree-loading.patch b/0028-Add-devicetree-loading.patch new file mode 100644 index 0000000..2558faa --- /dev/null +++ b/0028-Add-devicetree-loading.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Jan 2014 13:12:23 -0500 +Subject: [PATCH] Add devicetree loading + +Signed-off-by: Peter Jones + +Switch to use APM Mustang device tree, for hardware testing. + +Signed-off-by: David A. Marlin + +Use the default device tree from the grub default file + +instead of hardcoding a value. + +Signed-off-by: David A. Marlin +--- + util/grub-mkconfig.in | 3 ++- + util/grub.d/10_linux.in | 15 +++++++++++++++ + 2 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 9ecbcfb5b43..c645351dd2a 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -254,7 +254,8 @@ export GRUB_DEFAULT \ + GRUB_ENABLE_CRYPTODISK \ + GRUB_BADRAM \ + GRUB_OS_PROBER_SKIP_LIST \ +- GRUB_DISABLE_SUBMENU ++ GRUB_DISABLE_SUBMENU \ ++ GRUB_DEFAULT_DTB + + if test "x${grub_cfg}" != "x"; then + rm -f "${grub_cfg}.new" +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 58defdbd83f..dd3128440c4 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -153,6 +153,13 @@ EOF + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' + initrd $(echo $initrd_path) ++EOF ++ fi ++ if test -n "${fdt}" ; then ++ message="$(gettext_printf "Loading fdt ...")" ++ sed "s/^/$submenu_indentation/" << EOF ++ echo '$(echo "$message" | grub_quote)' ++ devicetree ${rel_dirname}/${fdt} + EOF + fi + sed "s/^/$submenu_indentation/" << EOF +@@ -236,6 +243,14 @@ while [ "x$list" != "x" ] ; do + gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 + fi + ++ fdt= ++ for i in "dtb-${version}" "dtb-${alt_version}"; do ++ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then ++ fdt="${i}/${GRUB_DEFAULT_DTB}" ++ break ++ fi ++ done ++ + config= + for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do + if test -e "${i}" ; then diff --git a/0029-Don-t-write-messages-to-the-screen.patch b/0029-Don-t-write-messages-to-the-screen.patch new file mode 100644 index 0000000..5677434 --- /dev/null +++ b/0029-Don-t-write-messages-to-the-screen.patch @@ -0,0 +1,176 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Wed, 15 May 2013 13:30:20 -0400 +Subject: [PATCH] Don't write messages to the screen + +Writing messages to the screen before the menus or boot splash +happens so quickly it looks like something is wrong and isn't +very appealing. +--- + grub-core/gettext/gettext.c | 25 +++++-------------------- + grub-core/kern/main.c | 5 ----- + grub-core/boot/i386/pc/boot.S | 3 --- + grub-core/boot/i386/pc/diskboot.S | 5 ----- + util/grub.d/10_linux.in | 7 ------- + 5 files changed, 5 insertions(+), 40 deletions(-) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 4d02e62c109..84d520cd494 100644 +--- a/grub-core/gettext/gettext.c ++++ b/grub-core/gettext/gettext.c +@@ -434,16 +434,12 @@ static char * + grub_gettext_env_write_lang (struct grub_env_var *var + __attribute__ ((unused)), const char *val) + { +- grub_err_t err; ++ grub_err_t __attribute__((__unused__)) err; + err = grub_gettext_init_ext (&main_context, val, grub_env_get ("locale_dir"), + grub_env_get ("prefix")); +- if (err) +- grub_print_error (); + + err = grub_gettext_init_ext (&secondary_context, val, + grub_env_get ("secondary_locale_dir"), 0); +- if (err) +- grub_print_error (); + + return grub_strdup (val); + } +@@ -451,23 +447,19 @@ grub_gettext_env_write_lang (struct grub_env_var *var + void + grub_gettext_reread_prefix (const char *val) + { +- grub_err_t err; ++ grub_err_t __attribute__((__unused__)) err; + err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), + grub_env_get ("locale_dir"), + val); +- if (err) +- grub_print_error (); + } + + static char * + read_main (struct grub_env_var *var + __attribute__ ((unused)), const char *val) + { +- grub_err_t err; ++ grub_err_t __attribute__((__unused__)) err; + err = grub_gettext_init_ext (&main_context, grub_env_get ("lang"), val, + grub_env_get ("prefix")); +- if (err) +- grub_print_error (); + return grub_strdup (val); + } + +@@ -475,12 +467,9 @@ static char * + read_secondary (struct grub_env_var *var + __attribute__ ((unused)), const char *val) + { +- grub_err_t err; ++ grub_err_t __attribute__((__unused__)) err; + err = grub_gettext_init_ext (&secondary_context, grub_env_get ("lang"), val, + 0); +- if (err) +- grub_print_error (); +- + return grub_strdup (val); + } + +@@ -500,18 +489,14 @@ grub_cmd_translate (grub_command_t cmd __attribute__ ((unused)), + GRUB_MOD_INIT (gettext) + { + const char *lang; +- grub_err_t err; ++ grub_err_t __attribute__((__unused__)) err; + + lang = grub_env_get ("lang"); + + err = grub_gettext_init_ext (&main_context, lang, grub_env_get ("locale_dir"), + grub_env_get ("prefix")); +- if (err) +- grub_print_error (); + err = grub_gettext_init_ext (&secondary_context, lang, + grub_env_get ("secondary_locale_dir"), 0); +- if (err) +- grub_print_error (); + + grub_register_variable_hook ("locale_dir", NULL, read_main); + grub_register_variable_hook ("secondary_locale_dir", NULL, read_secondary); +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index 8ab7794c47b..da47b18b50e 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -268,11 +268,6 @@ grub_main (void) + + grub_boot_time ("After machine init."); + +- /* Hello. */ +- grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT); +- grub_printf ("Welcome to GRUB!\n\n"); +- grub_setcolorstate (GRUB_TERM_COLOR_STANDARD); +- + grub_load_config (); + + grub_boot_time ("Before loading embedded modules."); +diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S +index 2bd0b2d2866..ea167fe1206 100644 +--- a/grub-core/boot/i386/pc/boot.S ++++ b/grub-core/boot/i386/pc/boot.S +@@ -249,9 +249,6 @@ real_start: + /* save drive reference first thing! */ + pushw %dx + +- /* print a notification message on the screen */ +- MSG(notification_string) +- + /* set %si to the disk address packet */ + movw $disk_address_packet, %si + +diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S +index c1addc0df29..68d31de0c4c 100644 +--- a/grub-core/boot/i386/pc/diskboot.S ++++ b/grub-core/boot/i386/pc/diskboot.S +@@ -50,11 +50,6 @@ _start: + /* save drive reference first thing! */ + pushw %dx + +- /* print a notification message on the screen */ +- pushw %si +- MSG(notification_string) +- popw %si +- + /* this sets up for the first run through "bootloop" */ + movw $LOCAL(firstlist), %di + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index dd3128440c4..ceb413fc2e3 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -138,27 +138,20 @@ linux_entry () + fi + printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" + fi +- message="$(gettext_printf "Loading Linux %s ..." ${version})" + sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' + linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} + EOF + if test -n "${initrd}" ; then +- # TRANSLATORS: ramdisk isn't identifier. Should be translated. +- message="$(gettext_printf "Loading initial ramdisk ...")" + initrd_path= + for i in ${initrd}; do + initrd_path="${initrd_path} ${rel_dirname}/${i}" + done + sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' + initrd $(echo $initrd_path) + EOF + fi + if test -n "${fdt}" ; then +- message="$(gettext_printf "Loading fdt ...")" + sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' + devicetree ${rel_dirname}/${fdt} + EOF + fi diff --git a/0030-Don-t-print-GNU-GRUB-header.patch b/0030-Don-t-print-GNU-GRUB-header.patch new file mode 100644 index 0000000..ce45d4b --- /dev/null +++ b/0030-Don-t-print-GNU-GRUB-header.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Wed, 15 May 2013 13:53:48 -0400 +Subject: [PATCH] Don't print GNU GRUB header + +No one cares. +--- + grub-core/normal/main.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index a326b192c89..09d0dfe76f1 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -208,15 +208,16 @@ read_config_file (const char *config) + /* Initialize the screen. */ + void + grub_normal_init_page (struct grub_term_output *term, +- int y) ++ int y __attribute__((__unused__))) + { ++ grub_term_cls (term); ++ ++#if 0 + grub_ssize_t msg_len; + int posx; + char *msg_formatted; + grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; +- +- grub_term_cls (term); + + msg_formatted = grub_xasprintf (_("GNU GRUB version %s"), PACKAGE_VERSION); + if (!msg_formatted) +@@ -241,6 +242,7 @@ grub_normal_init_page (struct grub_term_output *term, + grub_putcode ('\n', term); + grub_putcode ('\n', term); + grub_free (unicode_msg); ++#endif + } + + static void diff --git a/0031-Don-t-add-to-highlighted-row.patch b/0031-Don-t-add-to-highlighted-row.patch new file mode 100644 index 0000000..b2d5575 --- /dev/null +++ b/0031-Don-t-add-to-highlighted-row.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Wed, 15 May 2013 17:49:45 -0400 +Subject: [PATCH] Don't add '*' to highlighted row + +It is already highlighted. +--- + grub-core/normal/menu_text.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index e22bb91f6e8..a3d1f23f68f 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -242,7 +242,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, + unicode_title[i] = ' '; + + if (data->geo.num_entries > 1) +- grub_putcode (highlight ? '*' : ' ', data->term); ++ grub_putcode (' ', data->term); + + grub_print_ucs4_menu (unicode_title, + unicode_title + len, diff --git a/0032-Message-string-cleanups.patch b/0032-Message-string-cleanups.patch new file mode 100644 index 0000000..9b6208e --- /dev/null +++ b/0032-Message-string-cleanups.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 11:09:04 -0400 +Subject: [PATCH] Message string cleanups + +Make use of terminology consistent. Remove jargon. +--- + grub-core/normal/menu_text.c | 21 +++++++++------------ + 1 file changed, 9 insertions(+), 12 deletions(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index a3d1f23f68f..64a83862f66 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -157,9 +157,8 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) + + if (edit) + { +- ret += grub_print_message_indented_real (_("Minimum Emacs-like screen editing is \ +-supported. TAB lists completions. Press Ctrl-x or F10 to boot, Ctrl-c or F2 for a \ +-command-line or ESC to discard edits and return to the GRUB menu."), ++ ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ ++command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), + STANDARD_MARGIN, STANDARD_MARGIN, + term, dry_run); + } +@@ -167,8 +166,8 @@ command-line or ESC to discard edits and return to the GRUB menu."), + { + char *msg_translated; + +- msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " +- "entry is highlighted."), ++ msg_translated = grub_xasprintf (_("Use the %C and %C keys to change the " ++ "selection."), + GRUB_UNICODE_UPARROW, + GRUB_UNICODE_DOWNARROW); + if (!msg_translated) +@@ -181,17 +180,15 @@ command-line or ESC to discard edits and return to the GRUB menu."), + if (nested) + { + ret += grub_print_message_indented_real +- (_("Press enter to boot the selected OS, " +- "`e' to edit the commands before booting " +- "or `c' for a command-line. ESC to return previous menu."), ++ (_("Press 'e' to edit the selected item, " ++ "or 'c' for a command prompt. Press Escape to return to the previous menu."), + STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); + } + else + { + ret += grub_print_message_indented_real +- (_("Press enter to boot the selected OS, " +- "`e' to edit the commands before booting " +- "or `c' for a command-line."), ++ (_("Press 'e' to edit the selected item, " ++ "or 'c' for a command prompt."), + STANDARD_MARGIN, STANDARD_MARGIN, term, dry_run); + } + } +@@ -443,7 +440,7 @@ menu_text_print_timeout (int timeout, void *dataptr) + || data->timeout_msg == TIMEOUT_TERSE_NO_MARGIN) + msg_translated = grub_xasprintf (_("%ds"), timeout); + else +- msg_translated = grub_xasprintf (_("The highlighted entry will be executed automatically in %ds."), timeout); ++ msg_translated = grub_xasprintf (_("The selected entry will be started automatically in %ds."), timeout); + if (!msg_translated) + { + grub_print_error (); diff --git a/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch b/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch new file mode 100644 index 0000000..504f273 --- /dev/null +++ b/0033-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 14:08:23 -0400 +Subject: [PATCH] Fix border spacing now that we aren't displaying it + +--- + grub-core/normal/menu_text.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 64a83862f66..1062d64ee29 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -331,12 +331,12 @@ grub_menu_init_page (int nested, int edit, + int empty_lines = 1; + int version_msg = 1; + +- geo->border = 1; +- geo->first_entry_x = 1 /* margin */ + 1 /* border */; ++ geo->border = 0; ++ geo->first_entry_x = 0 /* margin */ + 0 /* border */; + geo->entry_width = grub_term_width (term) - 5; + + geo->first_entry_y = 2 /* two empty lines*/ +- + 1 /* GNU GRUB version text */ + 1 /* top border */; ++ + 0 /* GNU GRUB version text */ + 1 /* top border */; + + geo->timeout_lines = 2; + diff --git a/0034-Use-the-correct-indentation-for-the-term-help-text.patch b/0034-Use-the-correct-indentation-for-the-term-help-text.patch new file mode 100644 index 0000000..5a1f0b5 --- /dev/null +++ b/0034-Use-the-correct-indentation-for-the-term-help-text.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 14:08:49 -0400 +Subject: [PATCH] Use the correct indentation for the term help text + +That is consistent with the menu help text +--- + grub-core/normal/main.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 09d0dfe76f1..7f61c5b618b 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -432,8 +432,8 @@ grub_normal_reader_init (int nested) + grub_normal_init_page (term, 1); + grub_term_setcursor (term, 1); + +- if (grub_term_width (term) > 3 + STANDARD_MARGIN + 20) +- grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); ++ if (grub_term_width (term) > 2 * STANDARD_MARGIN + 20) ++ grub_print_message_indented (msg_formatted, STANDARD_MARGIN, STANDARD_MARGIN, term); + else + grub_print_message_indented (msg_formatted, 0, 0, term); + grub_putcode ('\n', term); diff --git a/0035-Indent-menu-entries.patch b/0035-Indent-menu-entries.patch new file mode 100644 index 0000000..7a843ec --- /dev/null +++ b/0035-Indent-menu-entries.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 14:30:55 -0400 +Subject: [PATCH] Indent menu entries + +--- + grub-core/normal/menu_text.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 1062d64ee29..ecc60f99fc3 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -239,7 +239,8 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, + unicode_title[i] = ' '; + + if (data->geo.num_entries > 1) +- grub_putcode (' ', data->term); ++ for (i = 0; i < STANDARD_MARGIN; i++) ++ grub_putcode (' ', data->term); + + grub_print_ucs4_menu (unicode_title, + unicode_title + len, diff --git a/0036-Fix-margins.patch b/0036-Fix-margins.patch new file mode 100644 index 0000000..9be1731 --- /dev/null +++ b/0036-Fix-margins.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 14:59:36 -0400 +Subject: [PATCH] Fix margins + +--- + grub-core/normal/menu_text.c | 8 +++----- + 1 file changed, 3 insertions(+), 5 deletions(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index ecc60f99fc3..0e43f2c10cc 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -333,17 +333,15 @@ grub_menu_init_page (int nested, int edit, + int version_msg = 1; + + geo->border = 0; +- geo->first_entry_x = 0 /* margin */ + 0 /* border */; +- geo->entry_width = grub_term_width (term) - 5; ++ geo->first_entry_x = 0; /* no margin */ ++ geo->entry_width = grub_term_width (term) - 1; + +- geo->first_entry_y = 2 /* two empty lines*/ +- + 0 /* GNU GRUB version text */ + 1 /* top border */; ++ geo->first_entry_y = 3; /* three empty lines*/ + + geo->timeout_lines = 2; + + /* 3 lines for timeout message and bottom margin. 2 lines for the border. */ + geo->num_entries = grub_term_height (term) - geo->first_entry_y +- - 1 /* bottom border */ + - 1 /* empty line before info message*/ + - geo->timeout_lines /* timeout */ + - 1 /* empty final line */; diff --git a/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch b/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch new file mode 100644 index 0000000..3a37839 --- /dev/null +++ b/0037-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 21 Jun 2013 14:44:08 -0400 +Subject: [PATCH] Use -2 instead of -1 for our right-hand margin, so + linewrapping works (#976643). + +Signed-off-by: Peter Jones +--- + grub-core/normal/menu_text.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 0e43f2c10cc..537d4bf86ff 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -334,7 +334,7 @@ grub_menu_init_page (int nested, int edit, + + geo->border = 0; + geo->first_entry_x = 0; /* no margin */ +- geo->entry_width = grub_term_width (term) - 1; ++ geo->entry_width = grub_term_width (term) - 2; + + geo->first_entry_y = 3; /* three empty lines*/ + diff --git a/0038-Enable-pager-by-default.-985860.patch b/0038-Enable-pager-by-default.-985860.patch new file mode 100644 index 0000000..d92fbcc --- /dev/null +++ b/0038-Enable-pager-by-default.-985860.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 28 Oct 2013 10:09:27 -0400 +Subject: [PATCH] Enable pager by default. (#985860) + +Signed-off-by: Peter Jones +--- + util/grub.d/00_header.in | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in +index 93a90233ead..858b526c925 100644 +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -43,6 +43,8 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_ + if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi + + cat << EOF ++set pager=1 ++ + if [ -s \$prefix/grubenv ]; then + load_env + fi diff --git a/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch b/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch new file mode 100644 index 0000000..93233bc --- /dev/null +++ b/0039-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 28 Oct 2013 10:13:27 -0400 +Subject: [PATCH] F10 doesn't work on serial, so don't tell the user to hit it + (#987443) + +Signed-off-by: Peter Jones +--- + grub-core/normal/menu_text.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 537d4bf86ff..452d55bf9ff 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -157,7 +157,7 @@ print_message (int nested, int edit, struct grub_term_output *term, int dry_run) + + if (edit) + { +- ret += grub_print_message_indented_real (_("Press Ctrl-x or F10 to start, Ctrl-c or F2 for a \ ++ ret += grub_print_message_indented_real (_("Press Ctrl-x to start, Ctrl-c for a \ + command prompt or Escape to discard edits and return to the menu. Pressing Tab lists possible completions."), + STANDARD_MARGIN, STANDARD_MARGIN, + term, dry_run); diff --git a/0040-Don-t-say-GNU-Linux-in-generated-menus.patch b/0040-Don-t-say-GNU-Linux-in-generated-menus.patch new file mode 100644 index 0000000..ced2560 --- /dev/null +++ b/0040-Don-t-say-GNU-Linux-in-generated-menus.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 14 Mar 2011 14:27:42 -0400 +Subject: [PATCH] Don't say "GNU/Linux" in generated menus. + +--- + util/grub.d/10_linux.in | 4 ++-- + util/grub.d/20_linux_xen.in | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index ceb413fc2e3..2b402d85a52 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" + CLASS="--class gnu-linux --class gnu --class os" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS=GNU/Linux ++ OS="$(sed 's, release .*$,,g' /etc/system-release)" + else +- OS="${GRUB_DISTRIBUTOR} GNU/Linux" ++ OS="${GRUB_DISTRIBUTOR}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" + fi + +diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in +index 96179ea613c..47e0d3f5cd6 100644 +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -29,9 +29,9 @@ export TEXTDOMAINDIR="@localedir@" + CLASS="--class gnu-linux --class gnu --class os --class xen" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS=GNU/Linux ++ OS="$(sed 's, release .*$,,g' /etc/system-release)" + else +- OS="${GRUB_DISTRIBUTOR} GNU/Linux" ++ OS="${GRUB_DISTRIBUTOR}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" + fi + diff --git a/0041-Don-t-draw-a-border-around-the-menu.patch b/0041-Don-t-draw-a-border-around-the-menu.patch new file mode 100644 index 0000000..e5d11ac --- /dev/null +++ b/0041-Don-t-draw-a-border-around-the-menu.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Wed, 15 May 2013 16:47:33 -0400 +Subject: [PATCH] Don't draw a border around the menu + +It looks cleaner without it. +--- + grub-core/normal/menu_text.c | 43 ------------------------------------------- + 1 file changed, 43 deletions(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 452d55bf9ff..1ed2bd92cf8 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -108,47 +108,6 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right, + grub_print_message_indented_real (msg, margin_left, margin_right, term, 0); + } + +-static void +-draw_border (struct grub_term_output *term, const struct grub_term_screen_geometry *geo) +-{ +- int i; +- +- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); +- +- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, +- geo->first_entry_y - 1 }); +- grub_putcode (GRUB_UNICODE_CORNER_UL, term); +- for (i = 0; i < geo->entry_width + 1; i++) +- grub_putcode (GRUB_UNICODE_HLINE, term); +- grub_putcode (GRUB_UNICODE_CORNER_UR, term); +- +- for (i = 0; i < geo->num_entries; i++) +- { +- grub_term_gotoxy (term, (struct grub_term_coordinate) { geo->first_entry_x - 1, +- geo->first_entry_y + i }); +- grub_putcode (GRUB_UNICODE_VLINE, term); +- grub_term_gotoxy (term, +- (struct grub_term_coordinate) { geo->first_entry_x + geo->entry_width + 1, +- geo->first_entry_y + i }); +- grub_putcode (GRUB_UNICODE_VLINE, term); +- } +- +- grub_term_gotoxy (term, +- (struct grub_term_coordinate) { geo->first_entry_x - 1, +- geo->first_entry_y - 1 + geo->num_entries + 1 }); +- grub_putcode (GRUB_UNICODE_CORNER_LL, term); +- for (i = 0; i < geo->entry_width + 1; i++) +- grub_putcode (GRUB_UNICODE_HLINE, term); +- grub_putcode (GRUB_UNICODE_CORNER_LR, term); +- +- grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL); +- +- grub_term_gotoxy (term, +- (struct grub_term_coordinate) { geo->first_entry_x - 1, +- (geo->first_entry_y - 1 + geo->num_entries +- + GRUB_TERM_MARGIN + 1) }); +-} +- + static int + print_message (int nested, int edit, struct grub_term_output *term, int dry_run) + { +@@ -406,8 +365,6 @@ grub_menu_init_page (int nested, int edit, + + grub_term_normal_color = grub_color_menu_normal; + grub_term_highlight_color = grub_color_menu_highlight; +- if (geo->border) +- draw_border (term, geo); + grub_term_normal_color = old_color_normal; + grub_term_highlight_color = old_color_highlight; + geo->timeout_y = geo->first_entry_y + geo->num_entries diff --git a/0042-Use-the-standard-margin-for-the-timeout-string.patch b/0042-Use-the-standard-margin-for-the-timeout-string.patch new file mode 100644 index 0000000..c6c770c --- /dev/null +++ b/0042-Use-the-standard-margin-for-the-timeout-string.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: William Jon McCann +Date: Fri, 7 Jun 2013 10:52:32 -0400 +Subject: [PATCH] Use the standard margin for the timeout string + +So that it aligns with the other messages +--- + grub-core/normal/menu_text.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 1ed2bd92cf8..7681f7d2893 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -372,7 +372,7 @@ grub_menu_init_page (int nested, int edit, + if (bottom_message) + { + grub_term_gotoxy (term, +- (struct grub_term_coordinate) { GRUB_TERM_MARGIN, ++ (struct grub_term_coordinate) { STANDARD_MARGIN, + geo->timeout_y }); + + print_message (nested, edit, term, 0); +@@ -407,14 +407,14 @@ menu_text_print_timeout (int timeout, void *dataptr) + if (data->timeout_msg == TIMEOUT_UNKNOWN) + { + data->timeout_msg = grub_print_message_indented_real (msg_translated, +- 3, 1, data->term, 1) ++ STANDARD_MARGIN, 1, data->term, 1) + <= data->geo.timeout_lines ? TIMEOUT_NORMAL : TIMEOUT_TERSE; + if (data->timeout_msg == TIMEOUT_TERSE) + { + grub_free (msg_translated); + msg_translated = grub_xasprintf (_("%ds"), timeout); + if (grub_term_width (data->term) < 10) +- data->timeout_msg = TIMEOUT_TERSE_NO_MARGIN; ++ data->timeout_msg = STANDARD_MARGIN; + } + } + diff --git a/0043-Add-.eh_frame-to-list-of-relocations-stripped.patch b/0043-Add-.eh_frame-to-list-of-relocations-stripped.patch new file mode 100644 index 0000000..4ab92e5 --- /dev/null +++ b/0043-Add-.eh_frame-to-list-of-relocations-stripped.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Mon, 13 Jan 2014 21:50:59 -0500 +Subject: [PATCH] Add .eh_frame to list of relocations stripped + +--- + conf/Makefile.common | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 6cd71cbb2ab..4ba729e14d8 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding + LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) + CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 + CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) +-STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx ++STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx + + CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding + LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d diff --git a/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch b/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch new file mode 100644 index 0000000..b8dbff5 --- /dev/null +++ b/0044-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Mon, 30 Jun 2014 14:16:46 -0400 +Subject: [PATCH] Don't munge raw spaces when we're doing our cmdline escaping + (#923374) + +Signed-off-by: Peter Jones +--- + grub-core/lib/cmdline.c | 11 +---------- + 1 file changed, 1 insertion(+), 10 deletions(-) + +diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c +index e0fb0a9e48a..8e2294d8ff6 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -98,16 +98,7 @@ grub_create_loader_cmdline (int argc, char *argv[], char *buf, + + while (*c) + { +- if (*c == ' ') +- { +- *buf++ = '\\'; +- *buf++ = 'x'; +- *buf++ = '2'; +- *buf++ = '0'; +- c++; +- continue; +- } +- else if (*c == '\\' && *(c+1) == 'x' && ++ if (*c == '\\' && *(c+1) == 'x' && + is_hex(*(c+2)) && is_hex(*(c+3))) + { + *buf++ = *c++; diff --git a/0045-Don-t-require-a-password-to-boot-entries-generated-b.patch b/0045-Don-t-require-a-password-to-boot-entries-generated-b.patch new file mode 100644 index 0000000..c737029 --- /dev/null +++ b/0045-Don-t-require-a-password-to-boot-entries-generated-b.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 11 Feb 2014 11:14:50 -0500 +Subject: [PATCH] Don't require a password to boot entries generated by + grub-mkconfig. + +When we set a password, we just want that to mean you can't /edit/ an entry. + +Resolves: rhbz#1030176 + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 2b402d85a52..d35b0f406bc 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -26,7 +26,7 @@ datarootdir="@datarootdir@" + export TEXTDOMAIN=@PACKAGE@ + export TEXTDOMAINDIR="@localedir@" + +-CLASS="--class gnu-linux --class gnu --class os" ++CLASS="--class gnu-linux --class gnu --class os --unrestricted" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS="$(sed 's, release .*$,,g' /etc/system-release)" diff --git a/0046-Don-t-emit-Booting-.-message.patch b/0046-Don-t-emit-Booting-.-message.patch new file mode 100644 index 0000000..63d1812 --- /dev/null +++ b/0046-Don-t-emit-Booting-.-message.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Feb 2014 09:37:49 -0500 +Subject: [PATCH] Don't emit "Booting ..." message. + +UI team still hates this stuff, so we're disabling it for RHEL 7. + +Resolves: rhbz#1023142 + +Signed-off-by: Peter Jones +--- + grub-core/normal/menu.c | 4 +++- + grub-core/normal/menu_entry.c | 3 --- + 2 files changed, 3 insertions(+), 4 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 9175ad297d8..783bde55b9e 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -839,12 +839,14 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) + + /* Callback invoked immediately before a menu entry is executed. */ + static void +-notify_booting (grub_menu_entry_t entry, ++notify_booting (grub_menu_entry_t __attribute__((unused)) entry, + void *userdata __attribute__((unused))) + { ++#if 0 + grub_printf (" "); + grub_printf_ (N_("Booting `%s'"), entry->title); + grub_printf ("\n\n"); ++#endif + } + + /* Callback invoked when a default menu entry executed because of a timeout +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index cdf3590a364..5785f67ee1c 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -1167,9 +1167,6 @@ run (struct screen *screen) + char *dummy[1] = { NULL }; + + grub_cls (); +- grub_printf (" "); +- grub_printf_ (N_("Booting a command list")); +- grub_printf ("\n\n"); + + errs_before = grub_err_printed_errors; + diff --git a/0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch b/0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch new file mode 100644 index 0000000..11d8a62 --- /dev/null +++ b/0047-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch @@ -0,0 +1,1960 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 4 Mar 2014 11:00:23 -0500 +Subject: [PATCH] Replace a lot of man pages with slightly nicer ones. + +Replace a bunch of machine generated ones with ones that look nicer. +--- + configure.ac | 23 ++++++ + conf/Makefile.extra-dist | 1 - + docs/Makefile.am | 2 - + docs/man/grub-bios-setup.h2m | 6 -- + docs/man/grub-editenv.h2m | 5 -- + docs/man/grub-emu.h2m | 6 -- + docs/man/grub-file.h2m | 2 - + docs/man/grub-fstest.h2m | 4 - + docs/man/grub-glue-efi.h2m | 4 - + docs/man/grub-install.h2m | 6 -- + docs/man/grub-kbdcomp.h2m | 10 --- + docs/man/grub-macbless.h2m | 4 - + docs/man/grub-macho2img.h2m | 4 - + docs/man/grub-menulst2cfg.h2m | 4 - + docs/man/grub-mkconfig.h2m | 4 - + docs/man/grub-mkfont.h2m | 4 - + docs/man/grub-mkimage.h2m | 6 -- + docs/man/grub-mklayout.h2m | 10 --- + docs/man/grub-mknetdir.h2m | 4 - + docs/man/grub-mkpasswd-pbkdf2.h2m | 4 - + docs/man/grub-mkrelpath.h2m | 4 - + docs/man/grub-mkrescue.h2m | 4 - + docs/man/grub-mkstandalone.h2m | 4 - + docs/man/grub-mount.h2m | 2 - + docs/man/grub-ofpathname.h2m | 4 - + docs/man/grub-pe2elf.h2m | 4 - + docs/man/grub-probe.h2m | 4 - + docs/man/grub-reboot.h2m | 5 -- + docs/man/grub-render-label.h2m | 3 - + docs/man/grub-script-check.h2m | 4 - + docs/man/grub-set-default.h2m | 5 -- + docs/man/grub-sparc64-setup.h2m | 6 -- + docs/man/grub-syslinux2cfg.h2m | 4 - + gentpl.py | 5 +- + util/grub-bios-setup.8 | 54 +++++++++++++ + util/grub-editenv.1 | 46 +++++++++++ + util/grub-file.1 | 165 ++++++++++++++++++++++++++++++++++++++ + util/grub-fstest.1 | 99 +++++++++++++++++++++++ + util/grub-glue-efi.1 | 31 +++++++ + util/grub-install.8 | 129 +++++++++++++++++++++++++++++ + util/grub-kbdcomp.1 | 19 +++++ + util/grub-macbless.1 | 22 +++++ + util/grub-menulst2cfg.1 | 12 +++ + util/grub-mkconfig.8 | 17 ++++ + util/grub-mkfont.1 | 87 ++++++++++++++++++++ + util/grub-mkimage.1 | 95 ++++++++++++++++++++++ + util/grub-mklayout.1 | 27 +++++++ + util/grub-mknetdir.1 | 12 +++ + util/grub-mkpasswd-pbkdf2.1 | 27 +++++++ + util/grub-mkrelpath.1 | 12 +++ + util/grub-mkrescue.1 | 123 ++++++++++++++++++++++++++++ + util/grub-mkstandalone.1 | 100 +++++++++++++++++++++++ + util/grub-ofpathname.8 | 12 +++ + util/grub-probe.8 | 80 ++++++++++++++++++ + util/grub-reboot.8 | 21 +++++ + util/grub-render-label.1 | 51 ++++++++++++ + util/grub-script-check.1 | 21 +++++ + util/grub-set-default.8 | 21 +++++ + util/grub-sparc64-setup.8 | 12 +++ + 59 files changed, 1319 insertions(+), 147 deletions(-) + delete mode 100644 docs/man/grub-bios-setup.h2m + delete mode 100644 docs/man/grub-editenv.h2m + delete mode 100644 docs/man/grub-emu.h2m + delete mode 100644 docs/man/grub-file.h2m + delete mode 100644 docs/man/grub-fstest.h2m + delete mode 100644 docs/man/grub-glue-efi.h2m + delete mode 100644 docs/man/grub-install.h2m + delete mode 100644 docs/man/grub-kbdcomp.h2m + delete mode 100644 docs/man/grub-macbless.h2m + delete mode 100644 docs/man/grub-macho2img.h2m + delete mode 100644 docs/man/grub-menulst2cfg.h2m + delete mode 100644 docs/man/grub-mkconfig.h2m + delete mode 100644 docs/man/grub-mkfont.h2m + delete mode 100644 docs/man/grub-mkimage.h2m + delete mode 100644 docs/man/grub-mklayout.h2m + delete mode 100644 docs/man/grub-mknetdir.h2m + delete mode 100644 docs/man/grub-mkpasswd-pbkdf2.h2m + delete mode 100644 docs/man/grub-mkrelpath.h2m + delete mode 100644 docs/man/grub-mkrescue.h2m + delete mode 100644 docs/man/grub-mkstandalone.h2m + delete mode 100644 docs/man/grub-mount.h2m + delete mode 100644 docs/man/grub-ofpathname.h2m + delete mode 100644 docs/man/grub-pe2elf.h2m + delete mode 100644 docs/man/grub-probe.h2m + delete mode 100644 docs/man/grub-reboot.h2m + delete mode 100644 docs/man/grub-render-label.h2m + delete mode 100644 docs/man/grub-script-check.h2m + delete mode 100644 docs/man/grub-set-default.h2m + delete mode 100644 docs/man/grub-sparc64-setup.h2m + delete mode 100644 docs/man/grub-syslinux2cfg.h2m + create mode 100644 util/grub-bios-setup.8 + create mode 100644 util/grub-editenv.1 + create mode 100644 util/grub-file.1 + create mode 100644 util/grub-fstest.1 + create mode 100644 util/grub-glue-efi.1 + create mode 100644 util/grub-install.8 + create mode 100644 util/grub-kbdcomp.1 + create mode 100644 util/grub-macbless.1 + create mode 100644 util/grub-menulst2cfg.1 + create mode 100644 util/grub-mkconfig.8 + create mode 100644 util/grub-mkfont.1 + create mode 100644 util/grub-mkimage.1 + create mode 100644 util/grub-mklayout.1 + create mode 100644 util/grub-mknetdir.1 + create mode 100644 util/grub-mkpasswd-pbkdf2.1 + create mode 100644 util/grub-mkrelpath.1 + create mode 100644 util/grub-mkrescue.1 + create mode 100644 util/grub-mkstandalone.1 + create mode 100644 util/grub-ofpathname.8 + create mode 100644 util/grub-probe.8 + create mode 100644 util/grub-reboot.8 + create mode 100644 util/grub-render-label.1 + create mode 100644 util/grub-script-check.1 + create mode 100644 util/grub-set-default.8 + create mode 100644 util/grub-sparc64-setup.8 + +diff --git a/configure.ac b/configure.ac +index d283af64c8c..8df400e0a8b 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -74,6 +74,29 @@ grub_TRANSFORM([grub-set-default]) + grub_TRANSFORM([grub-sparc64-setup]) + grub_TRANSFORM([grub-render-label]) + grub_TRANSFORM([grub-file]) ++grub_TRANSFORM([grub-bios-setup.3]) ++grub_TRANSFORM([grub-editenv.1]) ++grub_TRANSFORM([grub-fstest.3]) ++grub_TRANSFORM([grub-glue-efi.3]) ++grub_TRANSFORM([grub-install.1]) ++grub_TRANSFORM([grub-kbdcomp.3]) ++grub_TRANSFORM([grub-menulst2cfg.1]) ++grub_TRANSFORM([grub-mkconfig.1]) ++grub_TRANSFORM([grub-mkfont.3]) ++grub_TRANSFORM([grub-mkimage.1]) ++grub_TRANSFORM([grub-mklayout.3]) ++grub_TRANSFORM([grub-mknetdir.3]) ++grub_TRANSFORM([grub-mkpasswd-pbkdf2.3]) ++grub_TRANSFORM([grub-mkrelpath.3]) ++grub_TRANSFORM([grub-mkrescue.1]) ++grub_TRANSFORM([grub-mkstandalone.3]) ++grub_TRANSFORM([grub-ofpathname.3]) ++grub_TRANSFORM([grub-probe.3]) ++grub_TRANSFORM([grub-reboot.3]) ++grub_TRANSFORM([grub-render-label.3]) ++grub_TRANSFORM([grub-script-check.3]) ++grub_TRANSFORM([grub-set-default.1]) ++grub_TRANSFORM([grub-sparc64-setup.3]) + + # Optimization flag. Allow user to override. + if test "x$TARGET_CFLAGS" = x; then +diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist +index 46c4e95e2fa..58d7d9540be 100644 +--- a/conf/Makefile.extra-dist ++++ b/conf/Makefile.extra-dist +@@ -11,7 +11,6 @@ EXTRA_DIST += unicode + EXTRA_DIST += util/import_gcry.py + EXTRA_DIST += util/import_unicode.py + +-EXTRA_DIST += docs/man + EXTRA_DIST += docs/autoiso.cfg + EXTRA_DIST += docs/grub.cfg + EXTRA_DIST += docs/osdetect.cfg +diff --git a/docs/Makefile.am b/docs/Makefile.am +index 93eb3962765..ab28f199694 100644 +--- a/docs/Makefile.am ++++ b/docs/Makefile.am +@@ -5,5 +5,3 @@ info_TEXINFOS = grub.texi grub-dev.texi + grub_TEXINFOS = fdl.texi + + EXTRA_DIST = font_char_metrics.png font_char_metrics.txt +- +- +diff --git a/docs/man/grub-bios-setup.h2m b/docs/man/grub-bios-setup.h2m +deleted file mode 100644 +index ac6ede36296..00000000000 +--- a/docs/man/grub-bios-setup.h2m ++++ /dev/null +@@ -1,6 +0,0 @@ +-[NAME] +-grub-bios-setup \- set up a device to boot using GRUB +-[SEE ALSO] +-.BR grub-install (8), +-.BR grub-mkimage (1), +-.BR grub-mkrescue (1) +diff --git a/docs/man/grub-editenv.h2m b/docs/man/grub-editenv.h2m +deleted file mode 100644 +index 3859d3d4c4f..00000000000 +--- a/docs/man/grub-editenv.h2m ++++ /dev/null +@@ -1,5 +0,0 @@ +-[NAME] +-grub-editenv \- edit GRUB environment block +-[SEE ALSO] +-.BR grub-reboot (8), +-.BR grub-set-default (8) +diff --git a/docs/man/grub-emu.h2m b/docs/man/grub-emu.h2m +deleted file mode 100644 +index ef1c000656a..00000000000 +--- a/docs/man/grub-emu.h2m ++++ /dev/null +@@ -1,6 +0,0 @@ +-[NAME] +-grub-emu \- GRUB emulator +-[SEE ALSO] +-If you are trying to install GRUB, then you should use +-.BR grub-install (8) +-rather than this program. +diff --git a/docs/man/grub-file.h2m b/docs/man/grub-file.h2m +deleted file mode 100644 +index e09bb4d3101..00000000000 +--- a/docs/man/grub-file.h2m ++++ /dev/null +@@ -1,2 +0,0 @@ +-[NAME] +-grub-file \- check file type +diff --git a/docs/man/grub-fstest.h2m b/docs/man/grub-fstest.h2m +deleted file mode 100644 +index 9676b159afd..00000000000 +--- a/docs/man/grub-fstest.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-fstest \- debug tool for GRUB filesystem drivers +-[SEE ALSO] +-.BR grub-probe (8) +diff --git a/docs/man/grub-glue-efi.h2m b/docs/man/grub-glue-efi.h2m +deleted file mode 100644 +index c1c6ded49ff..00000000000 +--- a/docs/man/grub-glue-efi.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-glue-efi \- generate a fat binary for EFI +-[DESCRIPTION] +-grub-glue-efi processes ia32 and amd64 EFI images and glues them according to Apple format. +diff --git a/docs/man/grub-install.h2m b/docs/man/grub-install.h2m +deleted file mode 100644 +index 8cbbc87a0f2..00000000000 +--- a/docs/man/grub-install.h2m ++++ /dev/null +@@ -1,6 +0,0 @@ +-[NAME] +-grub-install \- install GRUB to a device +-[SEE ALSO] +-.BR grub-mkconfig (8), +-.BR grub-mkimage (1), +-.BR grub-mkrescue (1) +diff --git a/docs/man/grub-kbdcomp.h2m b/docs/man/grub-kbdcomp.h2m +deleted file mode 100644 +index d81f9157e01..00000000000 +--- a/docs/man/grub-kbdcomp.h2m ++++ /dev/null +@@ -1,10 +0,0 @@ +-[NAME] +-grub-kbdcomp \- generate a GRUB keyboard layout file +-[DESCRIPTION] +-grub-kbdcomp processes a X keyboard layout description in +-.BR keymaps (5) +-format into a format that can be used by GRUB's +-.B keymap +-command. +-[SEE ALSO] +-.BR grub-mklayout (8) +diff --git a/docs/man/grub-macbless.h2m b/docs/man/grub-macbless.h2m +deleted file mode 100644 +index 0197c0087d7..00000000000 +--- a/docs/man/grub-macbless.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-macbless \- bless a mac file/directory +-[SEE ALSO] +-.BR grub-install (1) +diff --git a/docs/man/grub-macho2img.h2m b/docs/man/grub-macho2img.h2m +deleted file mode 100644 +index d79aaeed8f9..00000000000 +--- a/docs/man/grub-macho2img.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-macho2img \- convert Mach-O to raw image +-[SEE ALSO] +-.BR grub-mkimage (1) +diff --git a/docs/man/grub-menulst2cfg.h2m b/docs/man/grub-menulst2cfg.h2m +deleted file mode 100644 +index c2e0055ed7e..00000000000 +--- a/docs/man/grub-menulst2cfg.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-menulst2cfg \- transform legacy menu.lst into grub.cfg +-[SEE ALSO] +-.BR grub-mkconfig (8) +diff --git a/docs/man/grub-mkconfig.h2m b/docs/man/grub-mkconfig.h2m +deleted file mode 100644 +index 9b42f813010..00000000000 +--- a/docs/man/grub-mkconfig.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkconfig \- generate a GRUB configuration file +-[SEE ALSO] +-.BR grub-install (8) +diff --git a/docs/man/grub-mkfont.h2m b/docs/man/grub-mkfont.h2m +deleted file mode 100644 +index d46fe600eca..00000000000 +--- a/docs/man/grub-mkfont.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkfont \- make GRUB font files +-[SEE ALSO] +-.BR grub-mkconfig (8) +diff --git a/docs/man/grub-mkimage.h2m b/docs/man/grub-mkimage.h2m +deleted file mode 100644 +index f0fbc2bb197..00000000000 +--- a/docs/man/grub-mkimage.h2m ++++ /dev/null +@@ -1,6 +0,0 @@ +-[NAME] +-grub-mkimage \- make a bootable image of GRUB +-[SEE ALSO] +-.BR grub-install (8), +-.BR grub-mkrescue (1), +-.BR grub-mknetdir (8) +diff --git a/docs/man/grub-mklayout.h2m b/docs/man/grub-mklayout.h2m +deleted file mode 100644 +index 1e43409c0ab..00000000000 +--- a/docs/man/grub-mklayout.h2m ++++ /dev/null +@@ -1,10 +0,0 @@ +-[NAME] +-grub-mklayout \- generate a GRUB keyboard layout file +-[DESCRIPTION] +-grub-mklayout processes a keyboard layout description in +-.BR keymaps (5) +-format into a format that can be used by GRUB's +-.B keymap +-command. +-[SEE ALSO] +-.BR grub-mkconfig (8) +diff --git a/docs/man/grub-mknetdir.h2m b/docs/man/grub-mknetdir.h2m +deleted file mode 100644 +index a2ef13ec111..00000000000 +--- a/docs/man/grub-mknetdir.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mknetdir \- prepare a GRUB netboot directory. +-[SEE ALSO] +-.BR grub-mkimage (1) +diff --git a/docs/man/grub-mkpasswd-pbkdf2.h2m b/docs/man/grub-mkpasswd-pbkdf2.h2m +deleted file mode 100644 +index 4d202f3da7e..00000000000 +--- a/docs/man/grub-mkpasswd-pbkdf2.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkpasswd-pbkdf2 \- generate hashed password for GRUB +-[SEE ALSO] +-.BR grub-mkconfig (8) +diff --git a/docs/man/grub-mkrelpath.h2m b/docs/man/grub-mkrelpath.h2m +deleted file mode 100644 +index d01f3961e3f..00000000000 +--- a/docs/man/grub-mkrelpath.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkrelpath \- make a system path relative to its root +-[SEE ALSO] +-.BR grub-probe (8) +diff --git a/docs/man/grub-mkrescue.h2m b/docs/man/grub-mkrescue.h2m +deleted file mode 100644 +index a427f02e3c6..00000000000 +--- a/docs/man/grub-mkrescue.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkrescue \- make a GRUB rescue image +-[SEE ALSO] +-.BR grub-mkimage (1) +diff --git a/docs/man/grub-mkstandalone.h2m b/docs/man/grub-mkstandalone.h2m +deleted file mode 100644 +index c77313978ad..00000000000 +--- a/docs/man/grub-mkstandalone.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-mkstandalone \- make a memdisk-based GRUB image +-[SEE ALSO] +-.BR grub-mkimage (1) +diff --git a/docs/man/grub-mount.h2m b/docs/man/grub-mount.h2m +deleted file mode 100644 +index 8d168982d72..00000000000 +--- a/docs/man/grub-mount.h2m ++++ /dev/null +@@ -1,2 +0,0 @@ +-[NAME] +-grub-mount \- export GRUB filesystem with FUSE +diff --git a/docs/man/grub-ofpathname.h2m b/docs/man/grub-ofpathname.h2m +deleted file mode 100644 +index 74b43eea039..00000000000 +--- a/docs/man/grub-ofpathname.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-ofpathname \- find OpenBOOT path for a device +-[SEE ALSO] +-.BR grub-probe (8) +diff --git a/docs/man/grub-pe2elf.h2m b/docs/man/grub-pe2elf.h2m +deleted file mode 100644 +index 7ca29bd703c..00000000000 +--- a/docs/man/grub-pe2elf.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-pe2elf \- convert PE image to ELF +-[SEE ALSO] +-.BR grub-mkimage (1) +diff --git a/docs/man/grub-probe.h2m b/docs/man/grub-probe.h2m +deleted file mode 100644 +index 6e1ffdcf937..00000000000 +--- a/docs/man/grub-probe.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-probe \- probe device information for GRUB +-[SEE ALSO] +-.BR grub-fstest (1) +diff --git a/docs/man/grub-reboot.h2m b/docs/man/grub-reboot.h2m +deleted file mode 100644 +index e4acace65ce..00000000000 +--- a/docs/man/grub-reboot.h2m ++++ /dev/null +@@ -1,5 +0,0 @@ +-[NAME] +-grub-reboot \- set the default boot entry for GRUB, for the next boot only +-[SEE ALSO] +-.BR grub-set-default (8), +-.BR grub-editenv (1) +diff --git a/docs/man/grub-render-label.h2m b/docs/man/grub-render-label.h2m +deleted file mode 100644 +index 50ae5247c05..00000000000 +--- a/docs/man/grub-render-label.h2m ++++ /dev/null +@@ -1,3 +0,0 @@ +-[NAME] +-grub-render-label \- generate a .disk_label for Apple Macs. +- +diff --git a/docs/man/grub-script-check.h2m b/docs/man/grub-script-check.h2m +deleted file mode 100644 +index 3653682671a..00000000000 +--- a/docs/man/grub-script-check.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-script-check \- check grub.cfg for syntax errors +-[SEE ALSO] +-.BR grub-mkconfig (8) +diff --git a/docs/man/grub-set-default.h2m b/docs/man/grub-set-default.h2m +deleted file mode 100644 +index 7945001c154..00000000000 +--- a/docs/man/grub-set-default.h2m ++++ /dev/null +@@ -1,5 +0,0 @@ +-[NAME] +-grub-set-default \- set the saved default boot entry for GRUB +-[SEE ALSO] +-.BR grub-reboot (8), +-.BR grub-editenv (1) +diff --git a/docs/man/grub-sparc64-setup.h2m b/docs/man/grub-sparc64-setup.h2m +deleted file mode 100644 +index 18f803a50db..00000000000 +--- a/docs/man/grub-sparc64-setup.h2m ++++ /dev/null +@@ -1,6 +0,0 @@ +-[NAME] +-grub-sparc64-setup \- set up a device to boot using GRUB +-[SEE ALSO] +-.BR grub-install (8), +-.BR grub-mkimage (1), +-.BR grub-mkrescue (1) +diff --git a/docs/man/grub-syslinux2cfg.h2m b/docs/man/grub-syslinux2cfg.h2m +deleted file mode 100644 +index ad25c8ab753..00000000000 +--- a/docs/man/grub-syslinux2cfg.h2m ++++ /dev/null +@@ -1,4 +0,0 @@ +-[NAME] +-grub-syslinux2cfg \- transform syslinux config into grub.cfg +-[SEE ALSO] +-.BR grub-menulst2cfg (8) +diff --git a/gentpl.py b/gentpl.py +index 387588c0589..f05812eace3 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -805,10 +805,7 @@ def manpage(defn, adddeps): + + output("if COND_MAN_PAGES\n") + gvar_add("man_MANS", name + "." + mansection) +- rule(name + "." + mansection, name + " " + adddeps, """ +-chmod a+x """ + name + """ +-PATH=$(builddir):$$PATH pkgdatadir=$(builddir) $(HELP2MAN) --section=""" + mansection + """ -i $(top_srcdir)/docs/man/""" + name + """.h2m -o $@ """ + name + """ +-""") ++ rule(name + "." + mansection, name + " " + adddeps, "cat $(top_srcdir)/util/" + name + "." + mansection + " | $(top_builddir)/config.status --file=$@:-") + gvar_add("CLEANFILES", name + "." + mansection) + output("endif\n") + +diff --git a/util/grub-bios-setup.8 b/util/grub-bios-setup.8 +new file mode 100644 +index 00000000000..56f582b3d75 +--- /dev/null ++++ b/util/grub-bios-setup.8 +@@ -0,0 +1,54 @@ ++.TH GRUB-BIOS-SETUP 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-bios-setup\fR \(em Set up images to boot from a device. ++ ++.SH SYNOPSIS ++\fBgrub-bios-setup\fR [-a | --allow-floppy] [-b | --boot-image=\fIFILE\fR] ++.RS 17 ++[-c | --core-image=\fIFILE\fR] [-d | --directory=\fIDIR\fR] ++.RE ++.RS 17 ++[-f | --force] [-m | --device-map=\fIFILE\fR] ++.RE ++.RS 17 ++[-s | --skip-fs-probe] [-v | --verbose] \fIDEVICE\fR ++ ++.SH DESCRIPTION ++You should not normally run this program directly. Use grub-install instead. ++ ++.SH OPTIONS ++.TP ++\fB--allow-floppy\fR ++Make the device also bootable as a floppy. This option is the default for ++/dev/fdX devices. Some BIOSes will not boot images created with this option. ++ ++.TP ++\fB--boot-image\fR=\fIFILE\fR ++Use FILE as the boot image. The default value is \fBboot.img\fR. ++ ++.TP ++\fB--core-image\fR=\fIFILE\fR ++Use FILE as ther core image. The default value is \fBcore.img\fR. ++ ++.TP ++\fB--directory\fR=\fIDIR\fR ++Use GRUB files in the directory DIR. The default value is \fB/boot/grub\fR. ++ ++.TP ++\fB--force\fR ++Install even if problems are detected. ++ ++.TP ++\fB--device-map\fR=\fIFILE\fR ++Use FILE as the device map. The default value is /boot/grub/device.map . ++ ++.TP ++\fB--skip-fs-probe\fR ++Do not probe DEVICE for filesystems. ++ ++.TP ++\fB--verbose\fR ++Print verbose messages. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-editenv.1 b/util/grub-editenv.1 +new file mode 100644 +index 00000000000..d28ba03ba42 +--- /dev/null ++++ b/util/grub-editenv.1 +@@ -0,0 +1,46 @@ ++.TH GRUB-EDITENV 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-editenv\fR \(em Manage the GRUB environment block. ++ ++.SH SYNOPSIS ++\fBgrub-editenv\fR [-v | --verbose] [\fIFILE\fR] ++.RS 14 ++ ++ ++.SH DESCRIPTION ++\fBgrub-editenv\fR is a command line tool to manage GRUB's stored environment. ++ ++.SH OPTIONS ++.TP ++\fB--verbose\fR ++Print verbose messages. ++ ++.TP ++\fBFILE\fR ++.RS 7 ++File name to use for grub environment. Default is /boot/grub/grubenv . ++.RE ++ ++.SH COMMANDS ++.TP ++\fBcreate\fR ++.RS 7 ++Create a blank environment block file. ++.RE ++ ++.TP ++\fBlist\fR ++.RS 7 ++List the current variables. ++.RE ++ ++.TP ++\fBset\fR [\fINAME\fR=\fIVALUE\fR ...] ++Set variables. ++ ++.TP ++\fBunset [\fINAME\fR ...] ++Delete variables. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-file.1 b/util/grub-file.1 +new file mode 100644 +index 00000000000..b29cb327889 +--- /dev/null ++++ b/util/grub-file.1 +@@ -0,0 +1,165 @@ ++.TH GRUB-FILE 1 "Web Feb 26 2014" ++.SH NAME ++\fBgrub-file\fR \(em Check if FILE is of specified type. ++ ++.SH SYNOPSIS ++\fBgrub-file\fR (--is-i386-xen-pae-domu | --is-x86_64-xen-domu | ++.RS 11 ++--is-x86-xen-dom0 | --is-x86-multiboot | ++.RE ++.RS 11 ++--is-x86-multiboot2 | --is-arm-linux | --is-arm64-linux | ++.RE ++.RS 11 ++--is-ia64-linux | --is-mips-linux | --is-mipsel-linux | ++.RE ++.RS 11 ++--is-sparc64-linux | --is-powerpc-linux | --is-x86-linux | ++.RE ++.RS 11 ++--is-x86-linux32 | --is-x86-kfreebsd | --is-i386-kfreebsd | ++.RE ++.RS 11 ++--is-x86_64-kfreebsd | --is-x86-knetbsd | ++.RE ++.RS 11 ++--is-i386-knetbsd | --is-x86_64-knetbsd | --is-i386-efi | ++.RE ++.RS 11 ++--is-x86_64-efi | --is-ia64-efi | --is-arm64-efi | ++.RE ++.RS 11 ++--is-arm-efi | --is-hibernated-hiberfil | --is-x86_64-xnu | ++.RE ++.RS 11 ++--is-i386-xnu | --is-xnu-hibr | --is-x86-bios-bootsector) ++.RE ++.RS 11 ++\fIFILE\fR ++ ++.SH DESCRIPTION ++\fBgrub-file\fR is used to check if \fIFILE\fR is of a specified type. ++ ++.SH OPTIONS ++.TP ++--is-i386-xen-pae-domu ++Check if FILE can be booted as i386 PAE Xen unprivileged guest kernel ++ ++.TP ++--is-x86_64-xen-domu ++Check if FILE can be booted as x86_64 Xen unprivileged guest kernel ++ ++.TP ++--is-x86-xen-dom0 ++Check if FILE can be used as Xen x86 privileged guest kernel ++ ++.TP ++--is-x86-multiboot ++Check if FILE can be used as x86 multiboot kernel ++ ++.TP ++--is-x86-multiboot2 ++Check if FILE can be used as x86 multiboot2 kernel ++ ++.TP ++--is-arm-linux ++Check if FILE is ARM Linux ++ ++.TP ++--is-arm64-linux ++Check if FILE is ARM64 Linux ++ ++.TP ++--is-ia64-linux ++Check if FILE is IA64 Linux ++ ++.TP ++--is-mips-linux ++Check if FILE is MIPS Linux ++ ++.TP ++--is-mipsel-linux ++Check if FILE is MIPSEL Linux ++ ++.TP ++--is-sparc64-linux ++Check if FILE is SPARC64 Linux ++ ++.TP ++--is-powerpc-linux ++Check if FILE is POWERPC Linux ++ ++.TP ++--is-x86-linux ++Check if FILE is x86 Linux ++ ++.TP ++--is-x86-linux32 ++Check if FILE is x86 Linux supporting 32-bit protocol ++ ++.TP ++--is-x86-kfreebsd ++Check if FILE is x86 kFreeBSD ++ ++.TP ++--is-i386-kfreebsd ++Check if FILE is i386 kFreeBSD ++ ++.TP ++--is-x86_64-kfreebsd ++Check if FILE is x86_64 kFreeBSD ++ ++.TP ++--is-x86-knetbsd ++Check if FILE is x86 kNetBSD ++ ++.TP ++--is-i386-knetbsd ++Check if FILE is i386 kNetBSD ++ ++.TP ++--is-x86_64-knetbsd ++Check if FILE is x86_64 kNetBSD ++ ++.TP ++--is-i386-efi ++Check if FILE is i386 EFI file ++ ++.TP ++--is-x86_64-efi ++Check if FILE is x86_64 EFI file ++ ++.TP ++--is-ia64-efi ++Check if FILE is IA64 EFI file ++ ++.TP ++--is-arm64-efi ++Check if FILE is ARM64 EFI file ++ ++.TP ++--is-arm-efi ++Check if FILE is ARM EFI file ++ ++.TP ++--is-hibernated-hiberfil ++Check if FILE is hiberfil.sys in hibernated state ++ ++.TP ++--is-x86_64-xnu ++Check if FILE is x86_64 XNU (Mac OS X kernel) ++ ++.TP ++--is-i386-xnu ++Check if FILE is i386 XNU (Mac OS X kernel) ++ ++.TP ++--is-xnu-hibr ++Check if FILE is XNU (Mac OS X kernel) hibernated image ++ ++.TP ++--is-x86-bios-bootsector ++Check if FILE is BIOS bootsector ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-fstest.1 b/util/grub-fstest.1 +new file mode 100644 +index 00000000000..792fa78634c +--- /dev/null ++++ b/util/grub-fstest.1 +@@ -0,0 +1,99 @@ ++.TH GRUB-FSTEST 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-fstest\fR — Debug tool for GRUB's filesystem driver. ++ ++.SH SYNOPSIS ++\fBgrub-fstest\fR [-c | --diskcount=\fINUM\fR] [-C | --crypto] ++.RS 13 ++[-d | --debug=\fISTRING\fR] [-K | --zfs-key=\fIFILE\fR|\fIprompt\fR] ++.RE ++.RS 13 ++[-n | --length=\fINUM\fR] [-r | --root=\fIDEVICE_NAME\fR] ++.RE ++.RS 13 ++[-s | --skip=\fINUM\fR] [-u | --uncompress] [-v | --verbose] ++.RE ++.RS 13 ++\fIIMAGE_PATH\fR ++ ++.SH DESCRIPTION ++\fBgrub-fstest\fR is a tool for testing GRUB's filesystem drivers. You should not normally need to run this program. ++ ++.SH OPTIONS ++.TP ++\fB--diskcount\fR=\fINUM\fR ++Specify the number of input files. ++ ++.TP ++\fB--crypto\fR ++Mount cryptographic devices. ++ ++.TP ++\fB--debug\fR=\fISTRING\fR ++Set debug environment variable. ++ ++.TP ++\fB--zfs-key\fR=\fIFILE\fR|\fIprompt\fR ++Load ZFS cryptographic key. ++ ++.TP ++\fB--length\fR=\fINUM\fR ++Handle NUM bytes in output file. ++ ++.TP ++\fB--root\fR=\fIDEVICE_NAME\fR ++Set root device. ++ ++.TP ++\fB--skip\fR=\fINUM\fR ++Skip NUM bytes from output file. ++ ++.TP ++\fB--uncompress\fR ++Uncompress data. ++ ++.TP ++\fB--verbose\fR ++Print verbose messages. ++ ++.SH COMMANDS ++.TP ++\fBblocklist\fR \fIFILE\fR ++Display block list of \fIFILE\fR. ++ ++.TP ++\fBcat\fR \fIFILE\fR ++Display \fIFILE\fR on standard output. ++ ++.TP ++\fBcmp\fR \fIFILE\fR \fILOCAL\fR ++Compare \fIFILE\fR with local file \fILOCAL\fR. ++ ++.TP ++\fBcp\fR \fIFILE\fR \fILOCAL\fR ++Copy \fIFILE\fR to local file \fILOCAL\fR. ++ ++.TP ++\fBcrc\fR \fIFILE\fR ++Display the CRC-32 checksum of \fIFILE\fR. ++ ++.TP ++\fBhex\fR \fIFILE\fR ++Display contents of \fIFILE\fR in hexidecimal. ++ ++.TP ++\fBls\fR \fIPATH\fR ++List files at \fIPATH\fR. ++ ++.TP ++\fBxnu_uuid\fR \fIDEVICE\fR ++Display the XNU UUID of \fIDEVICE\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-glue-efi.1 b/util/grub-glue-efi.1 +new file mode 100644 +index 00000000000..72bd555d577 +--- /dev/null ++++ b/util/grub-glue-efi.1 +@@ -0,0 +1,31 @@ ++.TH GRUB-GLUE-EFI 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-glue-efi\fR \(em Create an Apple fat EFI binary. ++ ++.SH SYNOPSIS ++\fBgrub-glue-efi\fR <-3 | --input32=\fIFILE\fR> <-6 | --input64=\fIFILE\fR> ++.RS 15 ++<-o | --output=\fIFILE\fR> [-v | --verbose] ++ ++.SH DESCRIPTION ++\fBgrub-glue-efi\fR creates an Apple fat EFI binary from two EFI binaries. ++ ++.SH OPTIONS ++.TP ++\fB--input32\fR=\fIFILE\fR ++Read 32-bit binary from \fIFILE\fR. ++ ++.TP ++\fB--input64\fR=\fIFILE\fR ++Read 64-bit binary from \fIFILE\fR. ++ ++.TP ++\fB--output\fR=\fIFILE\fR ++Write resulting fat binary to \fIFILE\fR. ++ ++.TP ++\fB--verbose\fR ++Print verbose messages. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-install.8 b/util/grub-install.8 +new file mode 100644 +index 00000000000..76272a39d2e +--- /dev/null ++++ b/util/grub-install.8 +@@ -0,0 +1,129 @@ ++.TH GRUB-INSTALL 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-install\fR \(em Install GRUB on a device. ++ ++.SH SYNOPSIS ++\fBgrub-install\fR [--modules=\fIMODULES\fR] [--install-modules=\fIMODULES\fR] ++.RS 14 ++[--themes=\fITHEMES\fR] [--fonts=\fIFONTS\fR] [--locales=\fILOCALES\fR] ++.RE ++.RS 14 ++[--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] [-d | --directory=\fIDIR\fR] ++.RE ++.RS 14 ++[--grub-mkimage=\fIFILE\fR] [--boot-directory=\fIDIR\fR] ++.RE ++.RS 14 ++[--target=\fITARGET\fR] [--grub-setup=\fIFILE\fR] ++.RE ++.RS 14 ++[--grub-mkrelpath=\fIFILE\fR] [--grub-probe=\fIFILE\fR] ++.RE ++.RS 14 ++[--allow-floppy] [--recheck] [--force] [--force-file-id] ++.RE ++.RS 14 ++[--disk-module=\fIMODULE\fR] [--no-nvram] [--removable] ++.RE ++.RS 14 ++[--bootloader-id=\fIID\fR] [--efi-directory=\fIDIR\fR] \fIINSTALL_DEVICE\fR ++ ++.SH DESCRIPTION ++\fBgrub-install\fR installs GRUB onto a device. This includes copying GRUB images into the target directory (generally \fI/boot/grub\fR), and on some platforms may also include installing GRUB onto a boot sector. ++ ++.SH OPTIONS ++.TP ++\fB--modules\fR=\fIMODULES\fR\! ++Pre-load modules specified by \fIMODULES\fR. ++ ++.TP ++\fB--install-modules\fR=\fIMODULES\fR ++Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. ++ ++.TP ++\fB--themes\fR=\fITHEMES\fR ++Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. ++ ++.TP ++\fB--fonts\fR=\fIFONTS\fR ++Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. ++ ++.TP ++\fB--locales\fR=\fILOCALES\fR ++Install only locales listed in \fILOCALES\fR. The default is to install all available locales. ++ ++.TP ++\fB--compress\fR=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR ++Compress GRUB files using the specified compression algorithm. ++ ++.TP ++\fB--directory\fR=\fIDIR\fR ++Use images and modules in \fIDIR\fR. ++ ++.TP ++\fB--grub-mkimage\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-mkimage\fR. The default is \fI/usr/bin/grub-mkimage\fR. ++ ++.TP ++\fB--boot-directory\fR=\fIDIR\fR ++Use \fIDIR\fR as the boot directory. The default is \fI/boot\fR. GRUB will put its files in a subdirectory of this directory named \fIgrub\fR. ++ ++.TP ++\fB--target\fR=\fITARGET\fR ++Install GRUB for \fITARGET\fR platform. The default is the platform \fBgrub-install\fR is running on. ++ ++.TP ++\fB--grub-setup\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-setup\fR. The default is \fI/usr/bin/grub-setup\fR. ++ ++.TP ++\fB--grub-mkrelpath\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-mkrelpath\fR. The default is \fI/usr/bin/grub-mkrelpath\fR. ++ ++.TP ++\fB--grub-probe\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-probe\fR. The default is \fI/usr/bin/grub-mkrelpath\fR. ++ ++.TP ++\fB--allow-floppy ++Make the device also bootable as a floppy. This option is the default for /dev/fdX devices. Some BIOSes will not boot images created with this option. ++ ++.TP ++\fB--recheck ++Delete any existing device map and create a new one if necessary. ++ ++.TP ++\fB--force ++Install even if problems are detected. ++ ++.TP ++\fB--force-file-id ++Use identifier file even if UUID is available. ++ ++.TP ++\fB--disk-module\fR=\fIMODULE\fR ++Use \fIMODULE\fR for disk access. This allows you to manually specify either \fIbiosdisk\fR or \fInative\fR disk access. This option is only available on the BIOS target platform. ++ ++.TP ++\fB--no-nvram ++Do not update the \fIboot-device\fR NVRAM variable. This option is only available on IEEE1275 target platforms. ++ ++.TP ++\fB--removable ++Treat the target device as if it is removeable. This option is only available on the EFI target platform. ++ ++.TP ++\fB--bootloader-id\fR=\fIID\fR ++Use \fIID\fR as the bootloader ID. This opption is only available on the EFI target platform. ++ ++.TP ++\fB--efi-directory\fR=\fIDIR\fR ++Use \fIDIR\fR as the EFI System Partition root. This opption is only available on the EFI ta ++rget platform. ++ ++.TP ++\fIINSTALL_DEVICE\fR ++Install GRUB to the block device \fIINSTALL_DEVICE\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-kbdcomp.1 b/util/grub-kbdcomp.1 +new file mode 100644 +index 00000000000..0bb969a5b43 +--- /dev/null ++++ b/util/grub-kbdcomp.1 +@@ -0,0 +1,19 @@ ++.TH GRUB-KBDCOMP 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-kbdcomp\fR \(em Generate a GRUB keyboard layout file. ++ ++.SH SYNOPSIS ++\fBgrub-kbdcomp\fR <-o | --output=\fIFILE\fR> \fICKBMAP_ARGUMENTS\fR ++ ++.SH DESCRIPTION ++\fBgrub-kbdcomp\fR processes an X keyboard layout description in ++\fBkeymaps\fR(5) format into a format that can be used by GRUB's \fBkeymap\fR ++command. ++ ++.SH OPTIONS ++.TP ++\fB--output\fR=\fIFILE\fR ++Write output to \fIFILE\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-macbless.1 b/util/grub-macbless.1 +new file mode 100644 +index 00000000000..41a96186f70 +--- /dev/null ++++ b/util/grub-macbless.1 +@@ -0,0 +1,22 @@ ++.TH GRUB-MACBLESS 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-macbless\fR \(em Mac-style bless on HFS or HFS+ ++ ++.SH SYNOPSIS ++\fBgrub-macbless\fR [-v | --verbose] [-p | --ppc] \fIFILE\fR | [-x | --x86] \fIFILE\fR ++ ++.SH OPTIONS ++.TP ++--x86 ++Bless for x86 based Macs. ++ ++.TP ++--ppc ++Bless for PPC based Macs. ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-menulst2cfg.1 b/util/grub-menulst2cfg.1 +new file mode 100644 +index 00000000000..91e2ef87113 +--- /dev/null ++++ b/util/grub-menulst2cfg.1 +@@ -0,0 +1,12 @@ ++.TH GRUB-MENULST2CFG 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-menulst2cfg\fR \(em Convert a configuration file from GRUB 0.xx to GRUB 2.xx format. ++ ++.SH SYNOPSIS ++\fBgrub-menulst2cfg\fR [\fIINFILE\fR [\fIOUTFILE\fR]] ++ ++.SH DESCRIPTION ++\fBgrub-menulst2cfg\fR converts a configuration file from GRUB 0.xx to the current format. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 +new file mode 100644 +index 00000000000..a2d1f577b9b +--- /dev/null ++++ b/util/grub-mkconfig.8 +@@ -0,0 +1,17 @@ ++.TH GRUB-MKCONFIG 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkconfig\fR \(em Generate a GRUB configuration file. ++ ++.SH SYNOPSIS ++\fBgrub-mkconfig\fR [-o | --output=\fIFILE\fR] ++ ++.SH DESCRIPTION ++\fBgrub-mkconfig\fR generates a configuration file for GRUB. ++ ++.SH OPTIONS ++.TP ++\fB--output\fR=\fIFILE\fR ++Write generated output to \fIFILE\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkfont.1 b/util/grub-mkfont.1 +new file mode 100644 +index 00000000000..3494857987d +--- /dev/null ++++ b/util/grub-mkfont.1 +@@ -0,0 +1,87 @@ ++.TH GRUB-MKFONT 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkfont\fR \(em Convert common font file formats into the PF2 format. ++ ++.SH SYNOPSIS ++\fBgrub-mkfont\fR [--ascii-bitmaps] [-a | --force-autohint] ++.RS 13 ++[-b | --bold] [-c | --asce=\fINUM\fR] [-d | --desc=\fINUM\fR] ++.RE ++.RS 13 ++[-i | --index=\fINUM\fR] [-n | --name=\fINAME\fR] [--no-bitmap] ++.RE ++.RS 13 ++[--no-hinting] <-o | --output=\fIFILE\fR> ++.RE ++.RS 13 ++[-r | --range=\fIFROM-TO\fR[\fI,FROM-TO\fR]] [-s | --size=\fISIZE\fR] ++.RE ++.RS 13 ++[-v | --verbose] [--width-spec] \fIFONT_FILES\fR ++ ++.SH DESCRIPTION ++\fBgrub-mkfont\fR converts font files from common formats into the PF2 format used by GRUB. ++ ++.SH OPTIONS ++.TP ++--ascii-bitmaps ++Save only bitmaps for ASCII characters. ++ ++.TP ++--force-autohint ++Force generation of automatic hinting. ++ ++.TP ++--bold ++Convert font to bold. ++ ++.TP ++--asce=\fINUM\fR ++Set font ascent to \fINUM\fR. ++ ++.TP ++--desc=\fINUM\fR ++Set font descent to \fINUM\fR. ++ ++.TP ++--index=\fINUM\fR ++Select face index \fINUM\fR. ++ ++.TP ++--name=\fINAME\fR ++Set font family to \fINAME\fR. ++ ++.TP ++--no-bitmap ++Ignore bitmap strikes when loading. ++ ++.TP ++--no-hinting ++Disable hinting. ++ ++.TP ++--output=\fIFILE\fR ++Save ouptut to \fIFILE\fR. This argument is required. ++ ++.TP ++--range=\fIFROM-TO\fR\fI,FROM-TO\fR ++Set the font ranges to each pair of \fIFROM\fR,\fITO\fR. ++ ++.TP ++--size=\fISIZE\fR ++Set font size to \fISIZE\fR. ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.TP ++--width-spec ++Create a width summary file. ++ ++.TP ++\fIFONT_FILES\fR ++The input files to be converted. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 +new file mode 100644 +index 00000000000..4dea4f54597 +--- /dev/null ++++ b/util/grub-mkimage.1 +@@ -0,0 +1,95 @@ ++.TH GRUB-MKIMAGE 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkimage\fR \(em Make a bootable GRUB image. ++ ++.SH SYNOPSIS ++\fBgrub-mkimage\fR [-c | --config=\fRFILE\fI] [-C | --compression=(\fIxz\fR,\fInone\fR,\fIauto\fR)] ++.RS 14 ++[-d | --directory=\fRDIR\fR] [-k | --pubkey=\fIFILE\fR] ++.RE ++.RS 14 ++[-m | --memdisk=\fIFILE\fR] [-n | --note] [-o | --output=\fIFILE\fR] ++.RE ++.RS 14 ++[-O | --format=\fIFORMAT\fR] [-p | --prefix=\fIDIR\fR] ++.RE ++.RS 14 ++[-v | --verbose] \fIMODULES\fR ++ ++.SH DESCRIPTION ++\fBgrub-mkimage\fI builds a bootable image of GRUB. ++ ++.SH OPTIONS ++.TP ++--config=\fIFILE\fR ++Embed \fIFILE\fR as the image's initial configuration file. ++ ++.TP ++--compression=(\fIxz\fR,\fInone\fR,\fIauto\fR) ++Use one of \fIxz\fR, \fInone\fR, or \fIauto\fR as the compression method for the core image. ++ ++.TP ++--directory=\fIDIR\fR ++Use images and modules from \fIDIR\fR. The default value is \fB/usr/lib/grub/\fR. ++ ++.TP ++--pubkey=\fIFILE\fR ++Embed the public key \fIFILE\fR for signature checking. ++ ++.TP ++--memdisk=\fIFILE\fR ++Embed the memdisk image \fIFILE\fR. If no \fB-p\fR option is also specified, this implies \fI-p (memdisk)/boot/grub\fR. ++ ++.TP ++--note ++Add a CHRP \fINOTE\fR section. This option is only valid on IEEE1275 platforms. ++ ++.TP ++--output=\fIFILE\fR ++Write the generated file to \fIFILE\fR. The default is to write to standard output. ++ ++.TP ++--format=\fIFORMAT\fR ++Generate an image in the specified \fIFORMAT\fR. Valid values are: ++.RS ++.RS 4 ++.P ++i386-coreboot, ++i386-multiboot, ++i386-pc, ++i386-pc-pxe, ++i386-efi, ++i386-ieee1275, ++i386-qemu, ++x86_64-efi, ++mipsel-yeeloong-flash, ++mipsel-fuloong2f-flash, ++mipself-loongson-elf, ++powerpc-ieee1275, ++sparc64-ieee1275-raw, ++sparc64-ieee1275-cdcore, ++sparc64-ieee1275-aout, ++ia64-efi, ++mips-arc, ++mipsel-arc, ++mipsel-qemu_mips-elf, ++mips-qemu_mips-flash, ++mipsel-qemu_mips-flash, ++mips-qemu_mips-elf ++.RE ++.RE ++ ++.TP ++--prefix=\fIDIR\fR ++Set prefix directory. The default value is \fI/boot/grub\fR. ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.TP ++\fIMODULES\fR ++Include \fIMODULES\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mklayout.1 b/util/grub-mklayout.1 +new file mode 100644 +index 00000000000..d1bbc2ec515 +--- /dev/null ++++ b/util/grub-mklayout.1 +@@ -0,0 +1,27 @@ ++.TH GRUB-MKLAYOUT 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mklayout\fR \(em Generate a GRUB keyboard layout file. ++ ++.SH SYNOPSIS ++\fBgrub-mklayout\fR [-i | --input=\fIFILE\fR] [-o | --output=\fIFILE\fR] ++.RS 15 ++[-v | --verbose] ++ ++.SH DESCRIPTION ++\fBgrub-mklayout\fR generates a GRUB keyboard layout description which corresponds with the Linux console layout description given as input. ++ ++.SH OPTIONS ++.TP ++--input=\fIFILE\fR ++Use \fIFILE\fR as the input. The default value is the standard input device. ++ ++.TP ++--output=\fIFILE\fR ++Use \fIFILE\fR as the output. The default value is the standard output device. ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mknetdir.1 b/util/grub-mknetdir.1 +new file mode 100644 +index 00000000000..fa7e8d4ef0d +--- /dev/null ++++ b/util/grub-mknetdir.1 +@@ -0,0 +1,12 @@ ++.TH GRUB-MKNETDIR 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mknetdir\fR \(em Prepare a GRUB netboot directory. ++ ++.SH SYNOPSIS ++\fBgrub-mknetdir\fR ++ ++.SH DESCRIPTION ++\fBgrub-mknetdir\fR prepares a directory for GRUB to be netbooted from. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkpasswd-pbkdf2.1 b/util/grub-mkpasswd-pbkdf2.1 +new file mode 100644 +index 00000000000..73c437c15d8 +--- /dev/null ++++ b/util/grub-mkpasswd-pbkdf2.1 +@@ -0,0 +1,27 @@ ++.TH GRUB-MKPASSWD-PBKDF2 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkpasswd-pbkdf2\fR \(em Generate a PBKDF2 password hash. ++ ++.SH SYNOPSIS ++\fBgrub-mkpasswd-pbkdf2\fR [-c | --iteration-count=\fINUM\fR] [-l | --buflen=\fINUM\fR] ++.RS 22 ++[-s | --salt=\fINUM\fR] ++ ++.SH DESCRIPTION ++\fBgrub-mkpasswd-pbkdf2\fR generates a PBKDF2 password string suitable for use in a GRUB configuration file. ++ ++.SH OPTIONS ++.TP ++--iteration-count=\fINUM\fR ++Number of PBKDF2 iterations. ++ ++.TP ++--buflen=\fINUM\fR ++Length of generated hash. ++ ++.TP ++--salt=\fINUM\fR ++Length of salt to use. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkrelpath.1 b/util/grub-mkrelpath.1 +new file mode 100644 +index 00000000000..85f1113621d +--- /dev/null ++++ b/util/grub-mkrelpath.1 +@@ -0,0 +1,12 @@ ++.TH GRUB-MKRELPATH 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkrelpath\fR \(em Generate a relative GRUB path given an OS path. ++ ++.SH SYNOPSIS ++\fBgrub-mkrelpath\fR \fIFILE\fR ++ ++.SH DESCRIPTION ++\fBgrub-mkrelpath\fR takes an OS filesystem path for \fIFILE\fR and returns a relative path suitable for use in a GRUB configuration file. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkrescue.1 b/util/grub-mkrescue.1 +new file mode 100644 +index 00000000000..4ed9fc723fd +--- /dev/null ++++ b/util/grub-mkrescue.1 +@@ -0,0 +1,123 @@ ++.TH GRUB-MKRESCUE 3 "Wed Feb 26 2014" ++.SH NAME ++grub-mkrescue \(em Generate a GRUB rescue image using GNU Xorriso. ++ ++.SH SYNOPSIS ++\fBgrub-mkrescue\fR [-o | --output=\fIFILE\fR] [--modules=\fIMODULES\fR] ++.RS 15 ++[--install-modules=\fIMODULES\fR] [--themes=\fITHEMES\fR] ++.RE ++.RS 15 ++[--fonts=\fIFONTS\fR] [--locales=\fILOCALES\fR] ++.RE ++.RS 15 ++[--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] [-d | --directory=\fIDIR\fR] ++.RE ++.RS 15 ++[--grub-mkimage=\fIFILE\fR] [--rom-directory=\fIDIR\fR] ++.RE ++.RS 15 ++[--xorriso=\fIFILE\fR] [--grub-glue-efi=\fIFILE\fR] ++.RE ++.RS 15 ++[--grub-render-label=\fIFILE\fR] [--label-font=\fIFILE\fR] ++.RE ++.RS 15 ++[--label-color=\fICOLOR\fR] [--label-bgcolor=\fIFILE\fR] ++.RE ++.RS 15 ++[--product-name=\fISTRING\fR] [--product-version=\fISTRING\fR] ++.RE ++.RS 15 ++[--sparc-boot] [--arcs-boot] ++ ++.SH DESCRIPTION ++\fBgrub-mkrescue\fR can be used to generate a rescue image with the GRUB bootloader. ++ ++.SH OPTIONS ++.TP ++\fB--output\fR=\fIFILE\fR ++Write the generated file to \fIFILE\fR. The default is to write to standard output. ++ ++.TP ++\fB--modules\fR=\fIMODULES\fR ++Pre-load modules specified by \fIMODULES\fR. ++ ++.TP ++\fB--install-modules\fR=\fIMODULES\fR ++Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. ++ ++.TP ++\fB--themes\fR=\fITHEMES\fR ++Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. ++ ++.TP ++\fB--fonts\fR=\fIFONTS\fR ++Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. ++ ++.TP ++\fB--locales\fR=\fILOCALES\fR ++Install only locales listed in \fILOCALES\fR. The default is to install all available locales. ++ ++.TP ++\fB--compress\fR[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR] ++Compress GRUB files using the specified compression algorithm. ++ ++.TP ++\fB--directory\fR=\fIDIR\fR ++Use images and modules in \fIDIR\fR. ++ ++.TP ++\fB--grub-mkimage\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-mkimage\fR(1). The default is \fI/usr/bin/grub-mkimage\fR. ++ ++.TP ++\fB--rom-directory\fR=\fIDIR\fR ++Save ROM images in \fIDIR\fR. ++ ++.TP ++\fB--xorriso\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBxorriso\fI. ++ ++.TP ++\fB--grub-glue-efi\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-glue-efi\fR(3). ++ ++.TP ++\fB--grub-render-label\fR=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-render-label\fR(3). ++ ++.TP ++\fB--label-font\fR=\fIFILE\fR ++Use \fIFILE\fR as the font file for generated labels. ++ ++.TP ++\fB--label-color\fR=\fICOLOR\fR ++Use \fICOLOR\fI as the color for generated labels. ++ ++.TP ++\fB--label-bgcolor\fR=\fICOLOR\fR ++Use \fICOLOR\fR as the background color for generated labels. ++ ++.TP ++\fB--product-name\fR=\fISTRING\fR ++Use \fISTRING\fR as the product name in generated labels. ++ ++.TP ++\fB--product-version\fR=\fISTRING\fR ++Use \fISTRING\fR as the product version in generated labels. ++ ++.TP ++\fB--sparc-boot\fR ++Enable booting the SPARC platform. This disables HFS+, APM, ARCS, and "boot as disk image" on the \fIi386-pc\fR target platform. ++ ++.TP ++\fB--arcs-boot\fR ++Enable ARCS booting. This is typically for big-endian MIPS machines, and disables HFS+, APM, sparc64, and "boot as disk image" on the \fIi386-pc\fR target platform. ++ ++.TP ++\fB--\fR ++All options after a \fB--\fR will be passed directly to xorriso's command line when generating the image. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkstandalone.1 b/util/grub-mkstandalone.1 +new file mode 100644 +index 00000000000..ba2d2bdf279 +--- /dev/null ++++ b/util/grub-mkstandalone.1 +@@ -0,0 +1,100 @@ ++.TH GRUB-MKSTANDALONE 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-mkstandalone\fR \(em Generate a standalone image in the selected format. ++ ++.SH SYNOPSIS ++\fBgrub-mkstandalone\fR [-o | --output=\fIFILE\fR] [-O | --format=\fIFORMAT\fR] ++.RS 19 ++[-C | --compression=(\fIxz\fR|\fInone\fR|\fIauto\fR)] ++.RE ++.RS 19 ++[--modules=\fIMODULES\fR] [--install-modules=\fIMODULES\fR] ++.RE ++.RS 19 ++[--themes=\fITHEMES\fR] [--fonts=\fIFONTS\fR] ++.RE ++.RS 19 ++[--locales=\fILOCALES\fR] [--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR]] ++.RE ++.RS 19 ++[-d | --directory=\fIDIR\fR] [--grub-mkimage=\fIFILE\fR] ++.RE ++.RS 19 ++\fISOURCE...\fR ++ ++.SH DESCRIPTION ++ ++.SH OPTIONS ++.TP ++--output=\fIFILE\fR ++Write the generated file to \fIFILE\fR. The default is to write to standard output. ++ ++.TP ++--format=\fIFORMAT\fR ++Generate an image in the specified \fIFORMAT\fR. Valid values are: ++.RS ++.RS 4 ++.P ++i386-coreboot, ++i386-multiboot, ++i386-pc, ++i386-pc-pxe, ++i386-efi, ++i386-ieee1275, ++i386-qemu, ++x86_64-efi, ++mipsel-yeeloong-flash, ++mipsel-fuloong2f-flash, ++mipself-loongson-elf, ++powerpc-ieee1275, ++sparc64-ieee1275-raw, ++sparc64-ieee1275-cdcore, ++sparc64-ieee1275-aout, ++ia64-efi, ++mips-arc, ++mipsel-arc, ++mipsel-qemu_mips-elf, ++mips-qemu_mips-flash, ++mipsel-qemu_mips-flash, ++mips-qemu_mips-elf ++.RE ++.RE ++ ++.TP ++--compression=(\fIxz\fR|\fInone\fR|\fIauto\fR) ++Use one of \fIxz\fR, \fInone\fR, or \fIauto\fR as the compression method for the core image. ++ ++.TP ++--modules=\fIMODULES\fR ++Pre-load modules specified by \fIMODULES\fR. ++ ++.TP ++--install-modules=\fIMODULES\fR ++Install only \fIMODULES\fR and their dependencies. The default is to install all available modules. ++ ++.TP ++--themes=\fITHEMES\fR ++Install \fITHEMES\fR. The default is to install the \fIstarfield\fR theme, if available. ++ ++.TP ++--fonts=\fIFONTS\fR ++Install \fIFONTS\fR. The default is to install the \fIunicode\fR font. ++ ++.TP ++--locales=\fILOCALES\fR ++Install only locales listed in \fILOCALES\fR. The default is to install all available locales. ++ ++.TP ++--compress[=\fIno\fR,\fIxz\fR,\fIgz\fR,\fIlzo\fR] ++Compress GRUB files using the specified compression algorithm. ++ ++.TP ++--directory=\fIDIR\fR ++Use images and modules in \fIDIR\fR. ++ ++.TP ++--grub-mkimage=\fIFILE\fR ++Use \fIFILE\fR as \fBgrub-mkimage\fR. The default is \fI/usr/bin/grub-mkimage\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-ofpathname.8 b/util/grub-ofpathname.8 +new file mode 100644 +index 00000000000..bf3743aeba1 +--- /dev/null ++++ b/util/grub-ofpathname.8 +@@ -0,0 +1,12 @@ ++.TH GRUB-OFPATHNAME 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-ofpathname\fR \(em Generate an IEEE-1275 device path for a specified device. ++ ++.SH SYNOPSIS ++\fBgrub-ofpathname\fR \fIDEVICE\fR ++ ++.SH DESCRIPTION ++\fBgrub-ofpathname\fR generates an IEEE-1275 device path for the specified \fIDEVICE\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-probe.8 b/util/grub-probe.8 +new file mode 100644 +index 00000000000..04e26c832bb +--- /dev/null ++++ b/util/grub-probe.8 +@@ -0,0 +1,80 @@ ++.TH GRUB-PROBE 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-probe\fR \(em Probe device information for a given path. ++ ++.SH SYNOPSIS ++\fBgrub-probe\fR \[-d | --device] [-m | --device-map=\fIFILE\fR] ++.RS 12 ++[-t | --target=(fs|fs_uuid|fs_label|drive|device|partmap| ++.RE ++.RS 28 ++abstraction|cryptodisk_uuid| ++.RE ++.RS 28 ++msdos_parttype)] ++.RE ++.RS 12 ++[-v | --verbose] (PATH|DEVICE) ++ ++.SH DESCRIPTION ++\fBgrub-probe\fR probes a path or device for filesystem and related information. ++ ++.SH OPTIONS ++.TP ++--device ++Final option represents a \fIDEVICE\fR, rather than a filesystem \fIPATH\fR. ++.TP ++--device-map=\fIFILE\fR ++Use \fIFILE\fR as the device map. The default value is \fI/boot/grub/device.map\fR. ++ ++.TP ++--target=(fs|fs_uuid|fs_label|drive|device|partmap|msdos_parttype) ++Select among various output definitions. The default is \fIfs\fR. ++.RS ++.TP ++\fIfs\fR ++filesystem module ++ ++.TP ++\fIfs_uuid\fR ++filesystem UUID ++ ++.TP ++\fIfs_label\fR ++filesystem label ++ ++.TP ++\fIdrive\fR ++GRUB drive name ++ ++.TP ++\fIdevice\fR ++System device ++ ++.TP ++\fIpartmap\fR ++partition map module ++ ++.TP ++\fIabstraction\fR ++abstraction module ++ ++.TP ++\fIcryptodisk_uuid\fR ++cryptographic container ++ ++.TP ++\fImsdos_partmap\fR ++MS-DOS partition map ++.RE ++ ++.TP ++--verbose ++Print verbose output. ++ ++.TP ++(\fIPATH\fR|\fIDEVICE\fR) ++If --device is passed, a block \fIDEVICE\fR. Otherwise, the \fIPATH\fR of a file on the filesystem. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-reboot.8 b/util/grub-reboot.8 +new file mode 100644 +index 00000000000..faa5e4eece2 +--- /dev/null ++++ b/util/grub-reboot.8 +@@ -0,0 +1,21 @@ ++.TH GRUB-REBOOT 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-reboot\fR \(em Set the default boot menu entry for the next boot only. ++ ++.SH SYNOPSIS ++\fBgrub-reboot\fR [--boot-directory=\fIDIR\fR] \fIMENU_ENTRY\fR ++ ++.SH DESCRIPTION ++\fBgrub-reboot\fR sets the default boot menu entry for the next boot, but not further boots after that. This command only works for GRUB configuration files created with \fIGRUB_DEFAULT=saved\fR in \fI/etc/default/grub\fR. ++ ++.SH OPTIONS ++.TP ++--boot-directory=\fIDIR\fR ++Find GRUB images under \fIDIR/grub\fR. The default value is \fI/boot\fR, resulting in grub images being search for at \fI/boot/grub\fR. ++ ++.TP ++\fIMENU_ENTRY\fR ++A number, a menu item title or a menu item identifier. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-render-label.1 b/util/grub-render-label.1 +new file mode 100644 +index 00000000000..4d51c8abf01 +--- /dev/null ++++ b/util/grub-render-label.1 +@@ -0,0 +1,51 @@ ++.TH GRUB-RENDER-LABEL 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-render-label\fR \(em Render an Apple disk label. ++ ++.SH SYNOPSIS ++\fBgrub-render-label\fR [-b | --bgcolor=\fICOLOR\fR] [-c | --color=\fICOLOR\fR] ++.RS 19 ++[-f | --font=\fIFILE\fR] [-i | --input=\fIFILE\fR] ++.RE ++.RS 19 ++[-o | --output=\fIFILE\fR] [-t | --text=\fISTRING\fR] ++.RE ++.RS 19 ++[-v | --verbose] ++ ++.SH DESCRIPTION ++\fBgrub-render-label\fR renders an Apple disk label (.disk_label) file. ++ ++ ++.SH OPTIONS ++.TP ++\fB--color\fR=\fICOLOR\fR ++Use \fICOLOR\fI as the color for generated labels. ++ ++.TP ++\fB--bgcolor\fR=\fICOLOR\fR ++Use \fICOLOR\fR as the background color for generated labels. ++ ++.TP ++\fB--font\fR=\fIFILE\fR ++Use \fIFILE\fR as the font file for generated labels. ++ ++.TP ++--input=\fIFILE\fR ++Read input text from \fIFILE\fR. ++ ++.TP ++--output=\fIFILE\fR ++Render output to \fIFILE\fR. ++ ++.TP ++--text=\fISTRING\fR ++Use \fISTRING\fR as input text. ++ ++.TP ++--verbose ++Print verbose output. ++ ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-script-check.1 b/util/grub-script-check.1 +new file mode 100644 +index 00000000000..0f1f625b05d +--- /dev/null ++++ b/util/grub-script-check.1 +@@ -0,0 +1,21 @@ ++.TH GRUB-SCRIPT-CHECK 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-script-check\fR \(em Check GRUB configuration file for syntax errors. ++ ++.SH SYNOPSIS ++\fBgrub-script-check\fR [-v | --verbose] \fIPATH\fR ++ ++.SH DESCRIPTION ++\fBgrub-script-check\fR verifies that a specified GRUB configuration file does not contain syntax errors. ++ ++.SH OPTIONS ++.TP ++--verbose ++Print verbose output. ++ ++.TP ++\fIPATH\fR ++Path of the file to use as input. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-set-default.8 b/util/grub-set-default.8 +new file mode 100644 +index 00000000000..a96265a1509 +--- /dev/null ++++ b/util/grub-set-default.8 +@@ -0,0 +1,21 @@ ++.TH GRUB-SET-DEFAULT 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-set-default\fR \(em Set the default boot menu entry for GRUB. ++ ++.SH SYNOPSIS ++\fBgrub-set-default\fR [--boot-directory=\fIDIR\fR] \fIMENU_ENTRY\fR ++ ++.SH DESCRIPTION ++\fBgrub-set-default\fR sets the default boot menu entry for all subsequent boots. This command only works for GRUB configuration files created with \fIGRUB_DEFAULT=saved\fR in \fI/etc/default/grub\fR. ++ ++.SH OPTIONS ++.TP ++--boot-directory=\fIDIR\fR ++Find GRUB images under \fIDIR/grub\fR. The default value is \fI/boot\fR, resulting in grub images being search for at \fI/boot/grub\fR. ++ ++.TP ++\fIMENU_ENTRY\fR ++A number, a menu item title or a menu item identifier. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-sparc64-setup.8 b/util/grub-sparc64-setup.8 +new file mode 100644 +index 00000000000..37ea2dd5eaa +--- /dev/null ++++ b/util/grub-sparc64-setup.8 +@@ -0,0 +1,12 @@ ++.TH GRUB-SPARC64-SETUP 3 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-sparc64-setup\fR \(em Set up a device to boot a sparc64 GRUB image. ++ ++.SH SYNOPSIS ++\fBgrub-sparc64-setup\fR [OPTIONS]. ++ ++.SH DESCRIPTION ++You should not normally run this program directly. Use grub-install instead. ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch b/0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch new file mode 100644 index 0000000..65b8855 --- /dev/null +++ b/0048-use-fw_path-prefix-when-fallback-searching-for-grub-.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Wed, 19 Feb 2014 15:58:43 -0500 +Subject: [PATCH] use fw_path prefix when fallback searching for grub config + +When PXE booting via UEFI firmware, grub was searching for grub.cfg +in the fw_path directory where the grub application was found. If +that didn't exist, a fallback search would look for config file names +based on MAC and IP address. However, the search would look in the +prefix directory which may not be the same fw_path. This patch +changes that behavior to use the fw_path directory for the fallback +search. Only if fw_path is NULL will the prefix directory be searched. + +Signed-off-by: Mark Salter +--- + grub-core/normal/main.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 7f61c5b618b..8add30e605f 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -349,7 +349,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + char *config; + const char *prefix, *fw_path; + +- fw_path = grub_env_get ("fw_path"); ++ prefix = fw_path = grub_env_get ("fw_path"); + if (fw_path) + { + config = grub_xasprintf ("%s/grub.cfg", fw_path); +@@ -372,7 +372,8 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + } + } + +- prefix = grub_env_get ("prefix"); ++ if (! prefix) ++ prefix = grub_env_get ("prefix"); + if (prefix) + { + grub_size_t config_len; diff --git a/0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch b/0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch new file mode 100644 index 0000000..45a0982 --- /dev/null +++ b/0049-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch @@ -0,0 +1,113 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jul 2019 17:33:22 +0200 +Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files. + +Signed-off-by: Peter Jones +--- + grub-core/normal/main.c | 84 ++++++++++++++++++++++++++----------------------- + 1 file changed, 45 insertions(+), 39 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 8add30e605f..d93bee613ac 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -347,53 +347,59 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + /* Guess the config filename. It is necessary to make CONFIG static, + so that it won't get broken by longjmp. */ + char *config; +- const char *prefix, *fw_path; +- +- prefix = fw_path = grub_env_get ("fw_path"); +- if (fw_path) +- { +- config = grub_xasprintf ("%s/grub.cfg", fw_path); +- if (config) +- { +- grub_file_t file; +- +- file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); +- if (file) +- { +- grub_file_close (file); +- grub_enter_normal_mode (config); +- } +- else +- { +- /* Ignore all errors. */ +- grub_errno = 0; +- } +- grub_free (config); +- } +- } ++ const char *prefix; + ++ prefix = grub_env_get ("fw_path"); + if (! prefix) + prefix = grub_env_get ("prefix"); ++ + if (prefix) + { +- grub_size_t config_len; +- config_len = grub_strlen (prefix) + +- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); +- config = grub_malloc (config_len); +- +- if (! config) +- goto quit; +- +- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); +- + if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) +- grub_net_search_configfile (config); ++ { ++ grub_size_t config_len; ++ config_len = grub_strlen (prefix) + ++ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); ++ config = grub_malloc (config_len); + +- grub_enter_normal_mode (config); +- grub_free (config); +- } ++ if (! config) ++ goto quit; ++ ++ grub_snprintf (config, config_len, "%s/grub.cfg", prefix); ++ ++ grub_net_search_configfile (config); ++ ++ grub_enter_normal_mode (config); ++ grub_free (config); ++ config = NULL; ++ } ++ ++ if (!config) ++ { ++ config = grub_xasprintf ("%s/grub.cfg", prefix); ++ if (config) ++ { ++ grub_file_t file; ++ ++ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); ++ if (file) ++ { ++ grub_file_close (file); ++ grub_enter_normal_mode (config); ++ } ++ else ++ { ++ /* Ignore all errors. */ ++ grub_errno = 0; ++ } ++ grub_free (config); ++ } ++ } ++ } + else +- grub_enter_normal_mode (0); ++ { ++ grub_enter_normal_mode (0); ++ } + } + else + grub_enter_normal_mode (argv[0]); diff --git a/0050-Fix-convert-function-to-support-NVMe-devices.patch b/0050-Fix-convert-function-to-support-NVMe-devices.patch new file mode 100644 index 0000000..0fb6616 --- /dev/null +++ b/0050-Fix-convert-function-to-support-NVMe-devices.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 18 Feb 2014 11:34:00 -0500 +Subject: [PATCH] Fix convert function to support NVMe devices + +This is adapted from the patch at +https://bugzilla.redhat.com/show_bug.cgi?id=1019660 , which is against +the now very old version of convert_system_partition_to_system_disk(). + +As such, it certainly not the right thing for upstream, but should +function for now. + +Resolves: rhbz#1019660 + +Signed-off-by: Peter Jones +--- + util/getroot.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/util/getroot.c b/util/getroot.c +index 847406fbab0..fa3460d6cd8 100644 +--- a/util/getroot.c ++++ b/util/getroot.c +@@ -153,6 +153,7 @@ convert_system_partition_to_system_disk (const char *os_dev, int *is_part) + { + #if GRUB_UTIL_FD_STAT_IS_FUNCTIONAL + struct stat st; ++ char *path = xmalloc(PATH_MAX); + + if (stat (os_dev, &st) < 0) + { +@@ -165,6 +166,24 @@ convert_system_partition_to_system_disk (const char *os_dev, int *is_part) + + *is_part = 0; + ++ if (realpath(os_dev, path)) ++ { ++ if ((strncmp ("/dev/nvme", path, 9) == 0)) ++ { ++ char *p = path + 5; ++ p = strchr(p, 'p'); ++ if (p) ++ { ++ *is_part = 1; ++ *p = '\0'; ++ } ++ return path; ++ } ++ } ++ ++ grub_free (path); ++ *is_part = 0; ++ + if (grub_util_device_is_mapped_stat (&st)) + return grub_util_devmapper_part_to_disk (&st, is_part, os_dev); + diff --git a/0051-Add-grub_util_readlink.patch b/0051-Add-grub_util_readlink.patch new file mode 100644 index 0000000..060a837 --- /dev/null +++ b/0051-Add-grub_util_readlink.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 8 Jul 2019 21:46:52 +0200 +Subject: [PATCH] Add grub_util_readlink() + +Add grub_util_readlink(). This requires pulling in stat and readlink from +gnulib, which pulls in stat and related headers, but after that the +implementation is straightforward. + +Signed-off-by: Peter Jones +Reviewed-by: Adam Jackson +--- + grub-core/osdep/windows/hostdisk.c | 6 ++++++ + include/grub/osdep/hostfile_aros.h | 6 ++++++ + include/grub/osdep/hostfile_unix.h | 6 ++++++ + include/grub/osdep/hostfile_windows.h | 2 ++ + 4 files changed, 20 insertions(+) + +diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c +index 355100789a7..87a106c9b82 100644 +--- a/grub-core/osdep/windows/hostdisk.c ++++ b/grub-core/osdep/windows/hostdisk.c +@@ -365,6 +365,12 @@ grub_util_mkdir (const char *dir) + free (windows_name); + } + ++ssize_t ++grub_util_readlink (const char *name, char *buf, size_t bufsize) ++{ ++ return readlink(name, buf, bufsize); ++} ++ + int + grub_util_rename (const char *from, const char *to) + { +diff --git a/include/grub/osdep/hostfile_aros.h b/include/grub/osdep/hostfile_aros.h +index a059c0fa40a..161fbb7bdfd 100644 +--- a/include/grub/osdep/hostfile_aros.h ++++ b/include/grub/osdep/hostfile_aros.h +@@ -68,6 +68,12 @@ grub_util_rename (const char *from, const char *to) + return rename (from, to); + } + ++static inline ssize_t ++grub_util_readlink (const char *name, char *buf, size_t bufsize) ++{ ++ return readlink(name, buf, bufsize); ++} ++ + #define grub_util_mkdir(a) mkdir ((a), 0755) + + struct grub_util_fd +diff --git a/include/grub/osdep/hostfile_unix.h b/include/grub/osdep/hostfile_unix.h +index 9ffe46fa3ca..17cd3aa8b30 100644 +--- a/include/grub/osdep/hostfile_unix.h ++++ b/include/grub/osdep/hostfile_unix.h +@@ -71,6 +71,12 @@ grub_util_rename (const char *from, const char *to) + return rename (from, to); + } + ++static inline ssize_t ++grub_util_readlink (const char *name, char *buf, size_t bufsize) ++{ ++ return readlink(name, buf, bufsize); ++} ++ + #define grub_util_mkdir(a) mkdir ((a), 0755) + + #if defined (__NetBSD__) +diff --git a/include/grub/osdep/hostfile_windows.h b/include/grub/osdep/hostfile_windows.h +index bf6451b6db4..8c92d0591bb 100644 +--- a/include/grub/osdep/hostfile_windows.h ++++ b/include/grub/osdep/hostfile_windows.h +@@ -41,6 +41,8 @@ typedef struct grub_util_fd_dir *grub_util_fd_dir_t; + + int + grub_util_rename (const char *from, const char *to); ++ssize_t ++grub_util_readlink (const char *name, char *buf, size_t bufsize); + int + grub_util_unlink (const char *name); + void diff --git a/0052-Make-editenv-chase-symlinks-including-those-across-d.patch b/0052-Make-editenv-chase-symlinks-including-those-across-d.patch new file mode 100644 index 0000000..288feba --- /dev/null +++ b/0052-Make-editenv-chase-symlinks-including-those-across-d.patch @@ -0,0 +1,104 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 3 Sep 2014 10:38:00 -0400 +Subject: [PATCH] Make editenv chase symlinks including those across devices. + +This lets us make /boot/grub2/grubenv a symlink to +/boot/efi/EFI/fedora/grubenv even though they're different mount points, +which allows /usr/bin/grub2-editenv to be the same across platforms +(i.e. UEFI vs BIOS). + +Signed-off-by: Peter Jones +Reviewed-by: Adam Jackson +--- + Makefile.util.def | 11 +++++++++++ + util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- + 2 files changed, 55 insertions(+), 2 deletions(-) + +diff --git a/Makefile.util.def b/Makefile.util.def +index 8717774d510..1f298d05f3d 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -240,8 +240,19 @@ program = { + + common = util/grub-editenv.c; + common = util/editenv.c; ++ common = util/grub-install-common.c; + common = grub-core/osdep/init.c; ++ common = grub-core/osdep/compress.c; ++ extra_dist = grub-core/osdep/unix/compress.c; ++ extra_dist = grub-core/osdep/basic/compress.c; ++ common = util/mkimage.c; ++ common = util/grub-mkimage32.c; ++ common = util/grub-mkimage64.c; ++ common = grub-core/osdep/config.c; ++ common = util/config.c; ++ common = util/resolve.c; + ++ ldadd = '$(LIBLZMA)'; + ldadd = libgrubmods.a; + ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; +diff --git a/util/editenv.c b/util/editenv.c +index eb2d0c03a98..e61dc1283a4 100644 +--- a/util/editenv.c ++++ b/util/editenv.c +@@ -37,6 +37,7 @@ grub_util_create_envblk_file (const char *name) + FILE *fp; + char *buf; + char *namenew; ++ char *rename_target = xstrdup(name); + + buf = xmalloc (DEFAULT_ENVBLK_SIZE); + +@@ -60,7 +61,48 @@ grub_util_create_envblk_file (const char *name) + free (buf); + fclose (fp); + +- if (grub_util_rename (namenew, name) < 0) +- grub_util_error (_("cannot rename the file %s to %s"), namenew, name); ++ ssize_t size = 1; ++ while (1) ++ { ++ char *linkbuf; ++ ssize_t retsize; ++ ++ linkbuf = xmalloc(size+1); ++ retsize = grub_util_readlink (rename_target, linkbuf, size); ++ if (retsize < 0 && (errno == ENOENT || errno == EINVAL)) ++ { ++ free (linkbuf); ++ break; ++ } ++ else if (retsize < 0) ++ { ++ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); ++ free (linkbuf); ++ free (namenew); ++ return; ++ } ++ else if (retsize == size) ++ { ++ free(linkbuf); ++ size += 128; ++ continue; ++ } ++ ++ free (rename_target); ++ linkbuf[retsize] = '\0'; ++ rename_target = linkbuf; ++ } ++ ++ int rc = grub_util_rename (namenew, rename_target); ++ if (rc < 0 && errno == EXDEV) ++ { ++ rc = grub_install_copy_file (namenew, rename_target, 1); ++ grub_util_unlink (namenew); ++ } ++ ++ if (rc < 0) ++ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); ++ + free (namenew); ++ free (rename_target); + } diff --git a/0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch b/0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch new file mode 100644 index 0000000..6acd50e --- /dev/null +++ b/0053-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Sep 2014 14:23:23 -0400 +Subject: [PATCH] Generate OS and CLASS in 10_linux from /etc/os-release + +This makes us use pretty names in the titles we generate in +grub2-mkconfig when GRUB_DISTRIBUTOR isn't set. + +Resolves: rhbz#996794 + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index d35b0f406bc..d12d2d784dc 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -29,7 +29,8 @@ export TEXTDOMAINDIR="@localedir@" + CLASS="--class gnu-linux --class gnu --class os --unrestricted" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS="$(sed 's, release .*$,,g' /etc/system-release)" ++ OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})" ++ CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}" + else + OS="${GRUB_DISTRIBUTOR}" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" diff --git a/0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch b/0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch new file mode 100644 index 0000000..fc29633 --- /dev/null +++ b/0054-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Sep 2014 15:52:08 -0400 +Subject: [PATCH] Minimize the sort ordering for .debug and -rescue- kernels. + +Resolves: rhbz#1065360 +Signed-off-by: Peter Jones +--- + util/grub-mkconfig_lib.in | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 1001a12232b..1a4a57898f9 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -249,6 +249,14 @@ version_test_gt () + *.old:*.old) ;; + *.old:*) version_test_gt_a="`echo "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;; + *:*.old) version_test_gt_b="`echo "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;; ++ *-rescue*:*-rescue*) ;; ++ *?debug:*?debug) ;; ++ *-rescue*:*?debug) return 1 ;; ++ *?debug:*-rescue*) return 0 ;; ++ *-rescue*:*) return 1 ;; ++ *:*-rescue*) return 0 ;; ++ *?debug:*) return 1 ;; ++ *:*?debug) return 0 ;; + esac + version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b" + return "$?" diff --git a/0055-Try-prefix-if-fw_path-doesn-t-work.patch b/0055-Try-prefix-if-fw_path-doesn-t-work.patch new file mode 100644 index 0000000..6c167e9 --- /dev/null +++ b/0055-Try-prefix-if-fw_path-doesn-t-work.patch @@ -0,0 +1,208 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jul 2019 10:35:16 +0200 +Subject: [PATCH] Try $prefix if $fw_path doesn't work. + +Related: rhbz#1148652 + +Signed-off-by: Peter Jones +--- + grub-core/kern/ieee1275/init.c | 28 +++++----- + grub-core/net/net.c | 2 +- + grub-core/normal/main.c | 120 ++++++++++++++++++++--------------------- + 3 files changed, 75 insertions(+), 75 deletions(-) + +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index e71d1584164..0cd2a627231 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -127,23 +127,25 @@ grub_machine_get_bootlocation (char **device, char **path) + grub_free (canon); + } + else +- *device = grub_ieee1275_encode_devname (bootpath); +- grub_free (type); +- +- filename = grub_ieee1275_get_filename (bootpath); +- if (filename) + { +- char *lastslash = grub_strrchr (filename, '\\'); +- +- /* Truncate at last directory. */ +- if (lastslash) ++ filename = grub_ieee1275_get_filename (bootpath); ++ if (filename) + { +- *lastslash = '\0'; +- grub_translate_ieee1275_path (filename); ++ char *lastslash = grub_strrchr (filename, '\\'); + +- *path = filename; +- } ++ /* Truncate at last directory. */ ++ if (lastslash) ++ { ++ *lastslash = '\0'; ++ grub_translate_ieee1275_path (filename); ++ ++ *path = filename; ++ } ++ } ++ *device = grub_ieee1275_encode_devname (bootpath); + } ++ ++ grub_free (type); + grub_free (bootpath); + } + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 06454564b8f..4b7972b8e7e 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1850,7 +1850,7 @@ grub_net_search_configfile (char *config) + /* Remove the remaining minus sign at the end. */ + config[config_len] = '\0'; + +- return GRUB_ERR_NONE; ++ return GRUB_ERR_FILE_NOT_FOUND; + } + + static struct grub_preboot *fini_hnd; +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index d93bee613ac..2fe6743399d 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -337,74 +337,72 @@ grub_enter_normal_mode (const char *config) + grub_boot_time ("Exiting normal mode"); + } + ++static grub_err_t ++grub_try_normal (const char *variable) ++{ ++ char *config; ++ const char *prefix; ++ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND; ++ ++ prefix = grub_env_get (variable); ++ if (!prefix) ++ return GRUB_ERR_FILE_NOT_FOUND; ++ ++ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) ++ { ++ grub_size_t config_len; ++ config_len = grub_strlen (prefix) + ++ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); ++ config = grub_malloc (config_len); ++ ++ if (! config) ++ return GRUB_ERR_FILE_NOT_FOUND; ++ ++ grub_snprintf (config, config_len, "%s/grub.cfg", prefix); ++ err = grub_net_search_configfile (config); ++ } ++ ++ if (err != GRUB_ERR_NONE) ++ { ++ config = grub_xasprintf ("%s/grub.cfg", prefix); ++ if (config) ++ { ++ grub_file_t file; ++ file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); ++ if (file) ++ { ++ grub_file_close (file); ++ err = GRUB_ERR_NONE; ++ } ++ } ++ } ++ ++ if (err == GRUB_ERR_NONE) ++ grub_enter_normal_mode (config); ++ ++ grub_errno = 0; ++ grub_free (config); ++ return err; ++} ++ + /* Enter normal mode from rescue mode. */ + static grub_err_t + grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), + int argc, char *argv[]) + { +- if (argc == 0) +- { +- /* Guess the config filename. It is necessary to make CONFIG static, +- so that it won't get broken by longjmp. */ +- char *config; +- const char *prefix; +- +- prefix = grub_env_get ("fw_path"); +- if (! prefix) +- prefix = grub_env_get ("prefix"); +- +- if (prefix) +- { +- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0) +- { +- grub_size_t config_len; +- config_len = grub_strlen (prefix) + +- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); +- config = grub_malloc (config_len); +- +- if (! config) +- goto quit; +- +- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); +- +- grub_net_search_configfile (config); +- +- grub_enter_normal_mode (config); +- grub_free (config); +- config = NULL; +- } +- +- if (!config) +- { +- config = grub_xasprintf ("%s/grub.cfg", prefix); +- if (config) +- { +- grub_file_t file; +- +- file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG); +- if (file) +- { +- grub_file_close (file); +- grub_enter_normal_mode (config); +- } +- else +- { +- /* Ignore all errors. */ +- grub_errno = 0; +- } +- grub_free (config); +- } +- } +- } +- else +- { +- grub_enter_normal_mode (0); +- } +- } +- else ++ if (argc) + grub_enter_normal_mode (argv[0]); ++ else ++ { ++ /* Guess the config filename. */ ++ grub_err_t err; ++ err = grub_try_normal ("fw_path"); ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ err = grub_try_normal ("prefix"); ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ grub_enter_normal_mode (0); ++ } + +-quit: + return 0; + } + diff --git a/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch b/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch new file mode 100644 index 0000000..afa3203 --- /dev/null +++ b/0056-Update-info-with-grub.cfg-netboot-selection-order-11.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Mon, 16 Mar 2015 16:34:51 -0400 +Subject: [PATCH] Update info with grub.cfg netboot selection order (#1148650) + +Added documentation to the grub info page that specifies the order +netboot clients will use to select a grub configuration file. + +Resolves rhbz#1148650 +--- + docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 6f524305085..221064b5679 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -2493,6 +2493,48 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 + Then follow instructions printed out by grub-mknetdir on configuring your DHCP + server. + ++The grub.cfg file is placed in the same directory as the path output by ++grub-mknetdir hereafter referred to as FWPATH. GRUB will search for its ++configuration files in order using the following rules where the appended ++value corresponds to a value on the client machine. ++ ++@example ++@group ++@samp{(FWPATH)}/grub.cfg-@samp{(UUID OF NIC)} ++@samp{(FWPATH)}/grub.cfg-@samp{(MAC ADDRESS OF NIC)} ++@samp{(FWPATH)}/grub.cfg-@samp{(IPv4 OR IPv6 ADDRESS)} ++@samp{(FWPATH)}/grub.cfg ++@end group ++@end example ++ ++The client will only attempt to look up an IPv6 address config once, however, ++it will try the IPv4 multiple times. The concrete example below shows what ++would happen under the IPv4 case. ++ ++@example ++@group ++UUID: 7726a678-7fc0-4853-a4f6-c85ac36a120a ++MAC: 52:54:00:ec:33:81 ++IPV4: 10.0.0.130 (0A000082) ++@end group ++@end example ++ ++@example ++@group ++@samp{(FWPATH)}/grub.cfg-7726a678-7fc0-4853-a4f6-c85ac36a120a ++@samp{(FWPATH)}/grub.cfg-52-54-00-ec-33-81 ++@samp{(FWPATH)}/grub.cfg-0A000082 ++@samp{(FWPATH)}/grub.cfg-0A00008 ++@samp{(FWPATH)}/grub.cfg-0A0000 ++@samp{(FWPATH)}/grub.cfg-0A000 ++@samp{(FWPATH)}/grub.cfg-0A00 ++@samp{(FWPATH)}/grub.cfg-0A0 ++@samp{(FWPATH)}/grub.cfg-0A ++@samp{(FWPATH)}/grub.cfg-0 ++@samp{(FWPATH)}/grub.cfg ++@end group ++@end example ++ + After GRUB has started, files on the TFTP server will be accessible via the + @samp{(tftp)} device. + diff --git a/0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch b/0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch new file mode 100644 index 0000000..bfebe38 --- /dev/null +++ b/0057-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch @@ -0,0 +1,447 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Mon, 16 Mar 2015 14:14:19 -0400 +Subject: [PATCH] Use Distribution Package Sort for grub2-mkconfig (#1124074) + +Users reported that newly installed kernels on their systems installed +with grub-mkconfig would not appear on the grub boot list in order +starting with the most recent. Added an option for rpm-based systems to +use the rpm-sort library to sort kernels instead. + +Resolves rhbz#1124074 + +Signed-off-by: Robert Marshall +[pjones: fix --enable-rpm-sort configure option] +Signed-off-by: Peter Jones +--- + configure.ac | 29 +++++ + Makefile.util.def | 16 +++ + util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ + util/grub-mkconfig_lib.in | 11 +- + util/grub-rpm-sort.8 | 12 ++ + 5 files changed, 348 insertions(+), 1 deletion(-) + create mode 100644 util/grub-rpm-sort.c + create mode 100644 util/grub-rpm-sort.8 + +diff --git a/configure.ac b/configure.ac +index 8df400e0a8b..6927615819b 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -69,6 +69,7 @@ grub_TRANSFORM([grub-mkrelpath]) + grub_TRANSFORM([grub-mkrescue]) + grub_TRANSFORM([grub-probe]) + grub_TRANSFORM([grub-reboot]) ++grub_TRANSFORM([grub-rpm-sort]) + grub_TRANSFORM([grub-script-check]) + grub_TRANSFORM([grub-set-default]) + grub_TRANSFORM([grub-sparc64-setup]) +@@ -92,6 +93,7 @@ grub_TRANSFORM([grub-mkrescue.1]) + grub_TRANSFORM([grub-mkstandalone.3]) + grub_TRANSFORM([grub-ofpathname.3]) + grub_TRANSFORM([grub-probe.3]) ++grub_TRANSFORM([grub-rpm-sort.8]) + grub_TRANSFORM([grub-reboot.3]) + grub_TRANSFORM([grub-render-label.3]) + grub_TRANSFORM([grub-script-check.3]) +@@ -1802,6 +1804,33 @@ fi + + AC_SUBST([LIBDEVMAPPER]) + ++AC_ARG_ENABLE([rpm-sort], ++ [AS_HELP_STRING([--enable-rpm-sort], ++ [enable native rpm sorting of kernels in grub (default=guessed)])]) ++if test x"$enable_rpm_sort" = xno ; then ++ rpm_sort_excuse="explicitly disabled" ++fi ++ ++if test x"$rpm_sort_excuse" = x ; then ++ # Check for rpmlib header. ++ AC_CHECK_HEADER([rpm/rpmlib.h], [], ++ [rpm_sort_excuse="need rpm/rpmlib header"]) ++fi ++ ++if test x"$rpm_sort_excuse" = x ; then ++ # Check for rpm library. ++ AC_CHECK_LIB([rpm], [rpmvercmp], [], ++ [rpm_sort_excuse="rpmlib missing rpmvercmp"]) ++fi ++ ++if test x"$rpm_sort_excuse" = x ; then ++ LIBRPM="-lrpm"; ++ AC_DEFINE([HAVE_RPM], [1], ++ [Define to 1 if you have the rpm library.]) ++fi ++ ++AC_SUBST([LIBRPM]) ++ + LIBGEOM= + if test x$host_kernel = xkfreebsd; then + AC_CHECK_LIB([geom], [geom_gettree], [], +diff --git a/Makefile.util.def b/Makefile.util.def +index 1f298d05f3d..843ce092b94 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -696,6 +696,22 @@ program = { + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + }; + ++program = { ++ name = grub-rpm-sort; ++ mansection = 8; ++ installdir = sbin; ++ ++ common = grub-core/kern/emu/misc.c; ++ common = grub-core/kern/emu/argp_common.c; ++ common = grub-core/osdep/init.c; ++ common = util/misc.c; ++ common = util/grub-rpm-sort.c; ++ ++ ldadd = libgrubkern.a; ++ ldadd = grub-core/lib/gnulib/libgnu.a; ++ ldadd = '$(LIBDEVMAPPER) $(LIBRPM)'; ++}; ++ + script = { + name = grub-mkconfig; + common = util/grub-mkconfig.in; +diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c +new file mode 100644 +index 00000000000..f33bd1ed568 +--- /dev/null ++++ b/util/grub-rpm-sort.c +@@ -0,0 +1,281 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++static size_t ++read_file (const char *input, char **ret) ++{ ++ FILE *in; ++ size_t s; ++ size_t sz = 2048; ++ size_t offset = 0; ++ char *text; ++ ++ if (!strcmp(input, "-")) ++ in = stdin; ++ else ++ in = grub_util_fopen(input, "r"); ++ ++ text = xmalloc (sz); ++ ++ if (!in) ++ grub_util_error (_("cannot open `%s': %s"), input, strerror (errno)); ++ ++ while ((s = fread (text + offset, 1, sz - offset, in)) != 0) ++ { ++ offset += s; ++ if (sz - offset == 0) ++ { ++ sz += 2048; ++ text = xrealloc (text, sz); ++ } ++ } ++ ++ text[offset] = '\0'; ++ *ret = text; ++ ++ if (in != stdin) ++ fclose(in); ++ ++ return offset + 1; ++} ++ ++/* returns name/version/release */ ++/* NULL string pointer returned if nothing found */ ++static void ++split_package_string (char *package_string, char **name, ++ char **version, char **release) ++{ ++ char *package_version, *package_release; ++ ++ /* Release */ ++ package_release = strrchr (package_string, '-'); ++ ++ if (package_release != NULL) ++ *package_release++ = '\0'; ++ ++ *release = package_release; ++ ++ /* Version */ ++ package_version = strrchr(package_string, '-'); ++ ++ if (package_version != NULL) ++ *package_version++ = '\0'; ++ ++ *version = package_version; ++ /* Name */ ++ *name = package_string; ++ ++ /* Bubble up non-null values from release to name */ ++ if (*name == NULL) ++ { ++ *name = (*version == NULL ? *release : *version); ++ *version = *release; ++ *release = NULL; ++ } ++ if (*version == NULL) ++ { ++ *version = *release; ++ *release = NULL; ++ } ++} ++ ++/* ++ * package name-version-release comparator for qsort ++ * expects p, q which are pointers to character strings (char *) ++ * which will not be altered in this function ++ */ ++static int ++package_version_compare (const void *p, const void *q) ++{ ++ char *local_p, *local_q; ++ char *lhs_name, *lhs_version, *lhs_release; ++ char *rhs_name, *rhs_version, *rhs_release; ++ int vercmpflag = 0; ++ ++ local_p = alloca (strlen (*(char * const *)p) + 1); ++ local_q = alloca (strlen (*(char * const *)q) + 1); ++ ++ /* make sure these allocated */ ++ assert (local_p); ++ assert (local_q); ++ ++ strcpy (local_p, *(char * const *)p); ++ strcpy (local_q, *(char * const *)q); ++ ++ split_package_string (local_p, &lhs_name, &lhs_version, &lhs_release); ++ split_package_string (local_q, &rhs_name, &rhs_version, &rhs_release); ++ ++ /* Check Name and return if unequal */ ++ vercmpflag = rpmvercmp ((lhs_name == NULL ? "" : lhs_name), ++ (rhs_name == NULL ? "" : rhs_name)); ++ if (vercmpflag != 0) ++ return vercmpflag; ++ ++ /* Check version and return if unequal */ ++ vercmpflag = rpmvercmp ((lhs_version == NULL ? "" : lhs_version), ++ (rhs_version == NULL ? "" : rhs_version)); ++ if (vercmpflag != 0) ++ return vercmpflag; ++ ++ /* Check release and return the version compare value */ ++ vercmpflag = rpmvercmp ((lhs_release == NULL ? "" : lhs_release), ++ (rhs_release == NULL ? "" : rhs_release)); ++ ++ return vercmpflag; ++} ++ ++static void ++add_input (const char *filename, char ***package_names, size_t *n_package_names) ++{ ++ char *orig_input_buffer = NULL; ++ char *input_buffer; ++ char *position_of_newline; ++ char **names = *package_names; ++ char **new_names = NULL; ++ size_t n_names = *n_package_names; ++ ++ if (!*package_names) ++ new_names = names = xmalloc (sizeof (char *) * 2); ++ ++ if (read_file (filename, &orig_input_buffer) < 2) ++ { ++ if (new_names) ++ free (new_names); ++ if (orig_input_buffer) ++ free (orig_input_buffer); ++ return; ++ } ++ ++ input_buffer = orig_input_buffer; ++ while (input_buffer && *input_buffer && ++ (position_of_newline = strchrnul (input_buffer, '\n'))) ++ { ++ size_t sz = position_of_newline - input_buffer; ++ char *new; ++ ++ if (sz == 0) ++ { ++ input_buffer = position_of_newline + 1; ++ continue; ++ } ++ ++ new = xmalloc (sz+1); ++ strncpy (new, input_buffer, sz); ++ new[sz] = '\0'; ++ ++ names = xrealloc (names, sizeof (char *) * (n_names + 1)); ++ names[n_names] = new; ++ n_names++; ++ ++ /* move buffer ahead to next line */ ++ input_buffer = position_of_newline + 1; ++ if (*position_of_newline == '\0') ++ input_buffer = NULL; ++ } ++ ++ free (orig_input_buffer); ++ ++ *package_names = names; ++ *n_package_names = n_names; ++} ++ ++static char * ++help_filter (int key, const char *text, void *input __attribute__ ((unused))) ++{ ++ return (char *)text; ++} ++ ++static struct argp_option options[] = { ++ { 0, } ++}; ++ ++struct arguments ++{ ++ size_t ninputs; ++ size_t input_max; ++ char **inputs; ++}; ++ ++static error_t ++argp_parser (int key, char *arg, struct argp_state *state) ++{ ++ struct arguments *arguments = state->input; ++ switch (key) ++ { ++ case ARGP_KEY_ARG: ++ assert (arguments->ninputs < arguments->input_max); ++ arguments->inputs[arguments->ninputs++] = xstrdup (arg); ++ break; ++ default: ++ return ARGP_ERR_UNKNOWN; ++ } ++ return 0; ++} ++ ++static struct argp argp = { ++ options, argp_parser, N_("[INPUT_FILES]"), ++ N_("Sort a list of strings in RPM version sort order."), ++ NULL, help_filter, NULL ++}; ++ ++int ++main (int argc, char *argv[]) ++{ ++ struct arguments arguments; ++ char **package_names = NULL; ++ size_t n_package_names = 0; ++ int i; ++ ++ grub_util_host_init (&argc, &argv); ++ ++ memset (&arguments, 0, sizeof (struct arguments)); ++ arguments.input_max = argc+1; ++ arguments.inputs = xmalloc ((arguments.input_max + 1) ++ * sizeof (arguments.inputs[0])); ++ memset (arguments.inputs, 0, (arguments.input_max + 1) ++ * sizeof (arguments.inputs[0])); ++ ++ /* Parse our arguments */ ++ if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0) ++ grub_util_error ("%s", _("Error in parsing command line arguments\n")); ++ ++ /* If there's no inputs in argv, add one for stdin */ ++ if (!arguments.ninputs) ++ { ++ arguments.ninputs = 1; ++ arguments.inputs[0] = xmalloc (2); ++ strcpy(arguments.inputs[0], "-"); ++ } ++ ++ for (i = 0; i < arguments.ninputs; i++) ++ add_input(arguments.inputs[i], &package_names, &n_package_names); ++ ++ if (package_names == NULL || n_package_names < 1) ++ grub_util_error ("%s", _("Invalid input\n")); ++ ++ qsort (package_names, n_package_names, sizeof (char *), ++ package_version_compare); ++ ++ /* send sorted list to stdout */ ++ for (i = 0; i < n_package_names; i++) ++ { ++ fprintf (stdout, "%s\n", package_names[i]); ++ free (package_names[i]); ++ } ++ ++ free (package_names); ++ for (i = 0; i < arguments.ninputs; i++) ++ free (arguments.inputs[i]); ++ ++ free (arguments.inputs); ++ ++ return 0; ++} +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 1a4a57898f9..113a41f9409 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -33,6 +33,9 @@ fi + if test "x$grub_mkrelpath" = x; then + grub_mkrelpath="${bindir}/@grub_mkrelpath@" + fi ++if test "x$grub_rpm_sort" = x; then ++ grub_rpm_sort="${sbindir}/@grub_rpm_sort@" ++fi + + if which gettext >/dev/null 2>/dev/null; then + : +@@ -214,6 +217,12 @@ version_sort () + esac + } + ++if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then ++ kernel_sort="$grub_rpm_sort" ++else ++ kernel_sort=version_sort ++fi ++ + version_test_numeric () + { + version_test_numeric_a="$1" +@@ -230,7 +239,7 @@ version_test_numeric () + version_test_numeric_a="$version_test_numeric_b" + version_test_numeric_b="$version_test_numeric_c" + fi +- if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | version_sort | head -n 1 | grep -qx "$version_test_numeric_b" ; then ++ if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | "$kernel_sort" | head -n 1 | grep -qx "$version_test_numeric_b" ; then + return 0 + else + return 1 +diff --git a/util/grub-rpm-sort.8 b/util/grub-rpm-sort.8 +new file mode 100644 +index 00000000000..8ce21488448 +--- /dev/null ++++ b/util/grub-rpm-sort.8 +@@ -0,0 +1,12 @@ ++.TH GRUB-RPM-SORT 8 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-rpm-sort\fR \(em Sort input according to RPM version compare. ++ ++.SH SYNOPSIS ++\fBgrub-rpm-sort\fR [OPTIONS]. ++ ++.SH DESCRIPTION ++You should not normally run this program directly. Use grub-mkconfig instead. ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0058-Handle-rssd-storage-devices.patch b/0058-Handle-rssd-storage-devices.patch new file mode 100644 index 0000000..8f25692 --- /dev/null +++ b/0058-Handle-rssd-storage-devices.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 30 Jun 2015 15:50:41 -0400 +Subject: [PATCH] Handle rssd storage devices. + +Resolves: rhbz#1087962 + +Signed-off-by: Peter Jones +--- + grub-core/osdep/linux/getroot.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 90d92d3ad5c..6d9f4e5faa2 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -921,6 +921,19 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, + return path; + } + ++ /* If this is an rssd device. */ ++ if ((strncmp ("rssd", p, 4) == 0) && p[4] >= 'a' && p[4] <= 'z') ++ { ++ char *pp = p + 4; ++ while (*pp >= 'a' && *pp <= 'z') ++ pp++; ++ if (*pp) ++ *is_part = 1; ++ /* /dev/rssd[a-z]+[0-9]* */ ++ *pp = '\0'; ++ return path; ++ } ++ + /* If this is a loop device */ + if ((strncmp ("loop", p, 4) == 0) && p[4] >= '0' && p[4] <= '9') + { diff --git a/0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch new file mode 100644 index 0000000..635a234 --- /dev/null +++ b/0059-Make-grub2-mkconfig-construct-titles-that-look-like-.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 28 Apr 2015 11:15:03 -0400 +Subject: [PATCH] Make grub2-mkconfig construct titles that look like the ones + we want elsewhere. + +Resolves: rhbz#1215839 + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 34 +++++++++++++++++++++++++++------- + 1 file changed, 27 insertions(+), 7 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index d12d2d784dc..12a20c9ad73 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -78,6 +78,32 @@ case x"$GRUB_FS" in + ;; + esac + ++mktitle () ++{ ++ local title_type ++ local version ++ local OS_NAME ++ local OS_VERS ++ ++ title_type=$1 && shift ++ version=$1 && shift ++ ++ OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" ++ OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" ++ ++ case $title_type in ++ recovery) ++ title=$(printf '%s (%s) %s (recovery mode)' \ ++ "${OS_NAME}" "${version}" "${OS_VERS}") ++ ;; ++ *) ++ title=$(printf '%s (%s) %s' \ ++ "${OS_NAME}" "${version}" "${OS_VERS}") ++ ;; ++ esac ++ echo -n ${title} ++} ++ + title_correction_code= + + linux_entry () +@@ -91,17 +117,11 @@ linux_entry () + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi + if [ x$type != xsimple ] ; then +- case $type in +- recovery) +- title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;; +- *) +- title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; +- esac ++ title=$(mktitle "$type" "$version") + if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then + replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" + quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" + title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" +- grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")" + fi + echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" + else diff --git a/0060-Add-friendly-grub2-password-config-tool-985962.patch b/0060-Add-friendly-grub2-password-config-tool-985962.patch new file mode 100644 index 0000000..5374425 --- /dev/null +++ b/0060-Add-friendly-grub2-password-config-tool-985962.patch @@ -0,0 +1,269 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 25 Jun 2015 11:13:11 -0400 +Subject: [PATCH] Add friendly grub2 password config tool (#985962) + +Provided a tool for users to reset the grub2 root user password +without having to alter the grub.cfg. The hashed password now +lives in a root-only-readable configuration file. + +Resolves: rhbz#985962 + +Signed-off-by: Robert Marshall +[pjones: fix the efidir in grub-setpassword and rename tool] +Signed-off-by: Peter Jones +[luto: fix grub-setpassword -o's output path] +Andy Lutomirski +--- + configure.ac | 1 + + Makefile.util.def | 13 +++++ + util/grub-mkconfig.in | 2 + + util/grub-set-password.8 | 28 ++++++++++ + util/grub-set-password.in | 128 ++++++++++++++++++++++++++++++++++++++++++++++ + util/grub.d/01_users.in | 11 ++++ + 6 files changed, 183 insertions(+) + create mode 100644 util/grub-set-password.8 + create mode 100644 util/grub-set-password.in + create mode 100644 util/grub.d/01_users.in + +diff --git a/configure.ac b/configure.ac +index 6927615819b..68501662e8d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -69,6 +69,7 @@ grub_TRANSFORM([grub-mkrelpath]) + grub_TRANSFORM([grub-mkrescue]) + grub_TRANSFORM([grub-probe]) + grub_TRANSFORM([grub-reboot]) ++grub_TRANSFORM([grub-set-password]) + grub_TRANSFORM([grub-rpm-sort]) + grub_TRANSFORM([grub-script-check]) + grub_TRANSFORM([grub-set-default]) +diff --git a/Makefile.util.def b/Makefile.util.def +index 843ce092b94..e50436a4987 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -451,6 +451,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '01_users'; ++ common = util/grub.d/01_users.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '10_windows'; + common = util/grub.d/10_windows.in; +@@ -733,6 +739,13 @@ script = { + installdir = sbin; + }; + ++script = { ++ name = grub-set-password; ++ common = util/grub-set-password.in; ++ mansection = 8; ++ installdir = sbin; ++}; ++ + script = { + name = grub-mkconfig_lib; + common = util/grub-mkconfig_lib.in; +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index c645351dd2a..4e7a875309e 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -282,6 +282,8 @@ for i in "${grub_mkconfig_dir}"/* ; do + *~) ;; + # emacsen autosave files. FIXME: support other editors + */\#*\#) ;; ++ # rpm config files of yore. ++ *.rpmsave|*.rpmnew|*.rpmorig) ;; + *) + if grub_file_is_not_garbage "$i" && test -x "$i" ; then + echo +diff --git a/util/grub-set-password.8 b/util/grub-set-password.8 +new file mode 100644 +index 00000000000..9646546e43d +--- /dev/null ++++ b/util/grub-set-password.8 +@@ -0,0 +1,28 @@ ++.TH GRUB-SET-PASSWORD 3 "Thu Jun 25 2015" ++.SH NAME ++\fBgrub-set-password\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. ++ ++.SH SYNOPSIS ++\fBgrub-set-password\fR [OPTION] ++ ++.SH DESCRIPTION ++\fBgrub-set-password\fR outputs the user.cfg file which contains the hashed GRUB bootloader password. This utility only supports configurations where there is a single root user. ++ ++The file has the format: ++GRUB2_PASSWORD=<\fIhashed password\fR>. ++ ++.SH OPTIONS ++.TP ++-h, --help ++Display program usage and exit. ++.TP ++-v, --version ++Display the current version. ++.TP ++-o, --output=<\fIDIRECTORY\fR> ++Choose the file path to which user.cfg will be written. ++ ++.SH SEE ALSO ++.BR "info grub" ++ ++.BR "info grub2-mkpasswd-pbkdf2" +diff --git a/util/grub-set-password.in b/util/grub-set-password.in +new file mode 100644 +index 00000000000..5ebf50576d6 +--- /dev/null ++++ b/util/grub-set-password.in +@@ -0,0 +1,128 @@ ++#!/bin/sh -e ++ ++EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') ++if [ -d /sys/firmware/efi/efivars/ ]; then ++ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` ++else ++ grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` ++fi ++ ++PACKAGE_VERSION="@PACKAGE_VERSION@" ++PACKAGE_NAME="@PACKAGE_NAME@" ++self=`basename $0` ++bindir="@bindir@" ++grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@" ++ ++# Usage: usage ++# Print the usage. ++usage () { ++ cat < put user.cfg in a user-selected directory ++ ++Report bugs at https://bugzilla.redhat.com. ++EOF ++} ++ ++argument () { ++ opt=$1 ++ shift ++ ++ if test $# -eq 0; then ++ gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2 ++ exit 1 ++ fi ++ echo $1 ++} ++ ++# Ensure that it's the root user running this script ++if [ "${EUID}" -ne 0 ]; then ++ echo "The grub bootloader password may only be set by root." ++ usage ++ exit 2 ++fi ++ ++# Check the arguments. ++while test $# -gt 0 ++do ++ option=$1 ++ shift ++ ++ case "$option" in ++ -h | --help) ++ usage ++ exit 0 ;; ++ -v | --version) ++ echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" ++ exit 0 ;; ++ -o | --output) ++ OUTPUT_PATH=`argument $option "$@"`; shift ;; ++ --output=*) ++ OUTPUT_PATH=`echo "$option" | sed 's/--output=//'` ;; ++ -o=*) ++ OUTPUT_PATH=`echo "$option" | sed 's/-o=//'` ;; ++ esac ++done ++ ++# set user input or default path for user.cfg file ++if [ -z "${OUTPUT_PATH}" ]; then ++ OUTPUT_PATH="${grubdir}" ++fi ++ ++if [ ! -d "${OUTPUT_PATH}" ]; then ++ echo "${OUTPUT_PATH} does not exist." ++ usage ++ exit 2; ++fi ++ ++ttyopt=$(stty -g) ++fixtty() { ++ stty ${ttyopt} ++} ++ ++trap fixtty EXIT ++stty -echo ++ ++# prompt & confirm new grub2 root user password ++echo -n "Enter password: " ++read PASSWORD ++echo ++echo -n "Confirm password: " ++read PASSWORD_CONFIRM ++echo ++stty ${ttyopt} ++ ++getpass() { ++ local P0 ++ local P1 ++ P0="$1" && shift ++ P1="$1" && shift ++ ++ ( echo ${P0} ; echo ${P1} ) | \ ++ LC_ALL=C ${grub_mkpasswd} | \ ++ grep -v '[eE]nter password:' | \ ++ sed -e "s/PBKDF2 hash of your password is //" ++} ++ ++MYPASS="$(getpass "${PASSWORD}" "${PASSWORD_CONFIRM}")" ++if [ -z "${MYPASS}" ]; then ++ echo "${self}: error: empty password" 1>&2 ++ exit 1 ++fi ++ ++# on the ESP, these will fail to set the permissions, but it's okay because ++# the directory is protected. ++install -m 0600 /dev/null "${OUTPUT_PATH}/user.cfg" 2>/dev/null || : ++chmod 0600 "${OUTPUT_PATH}/user.cfg" 2>/dev/null || : ++echo "GRUB2_PASSWORD=${MYPASS}" > "${OUTPUT_PATH}/user.cfg" ++ ++if ! grep -q "^### BEGIN /etc/grub.d/01_users ###$" "${OUTPUT_PATH}/grub.cfg"; then ++ echo "WARNING: The current configuration lacks password support!" ++ echo "Update your configuration with @grub_mkconfig@ to support this feature." ++fi +diff --git a/util/grub.d/01_users.in b/util/grub.d/01_users.in +new file mode 100644 +index 00000000000..db2f44bfb78 +--- /dev/null ++++ b/util/grub.d/01_users.in +@@ -0,0 +1,11 @@ ++#!/bin/sh -e ++cat << EOF ++if [ -f \${prefix}/user.cfg ]; then ++ source \${prefix}/user.cfg ++ if [ -n "\${GRUB2_PASSWORD}" ]; then ++ set superusers="root" ++ export superusers ++ password_pbkdf2 root \${GRUB2_PASSWORD} ++ fi ++fi ++EOF diff --git a/0061-tcp-add-window-scaling-support.patch b/0061-tcp-add-window-scaling-support.patch new file mode 100644 index 0000000..7d1996c --- /dev/null +++ b/0061-tcp-add-window-scaling-support.patch @@ -0,0 +1,87 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Wed, 12 Aug 2015 08:57:55 -0700 +Subject: [PATCH] tcp: add window scaling support + +Sometimes we have to provision boxes across regions, such as California to +Sweden. The http server has a 10 minute timeout, so if we can't get our 250mb +image transferred fast enough our provisioning fails, which is not ideal. So +add tcp window scaling on open connections and set the window size to 1mb. With +this change we're able to get higher sustained transfers between regions and can +transfer our image in well below 10 minutes. Without this patch we'd time out +every time halfway through the transfer. Thanks, + +Signed-off-by: Josef Bacik +--- + grub-core/net/tcp.c | 42 +++++++++++++++++++++++++++++------------- + 1 file changed, 29 insertions(+), 13 deletions(-) + +diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c +index e8ad34b84d4..7d4b822626d 100644 +--- a/grub-core/net/tcp.c ++++ b/grub-core/net/tcp.c +@@ -106,6 +106,18 @@ struct tcphdr + grub_uint16_t urgent; + } GRUB_PACKED; + ++struct tcp_scale_opt { ++ grub_uint8_t kind; ++ grub_uint8_t length; ++ grub_uint8_t scale; ++} GRUB_PACKED; ++ ++struct tcp_synhdr { ++ struct tcphdr tcphdr; ++ struct tcp_scale_opt scale_opt; ++ grub_uint8_t padding; ++}; ++ + struct tcp_pseudohdr + { + grub_uint32_t src; +@@ -566,7 +578,7 @@ grub_net_tcp_open (char *server, + grub_net_tcp_socket_t socket; + static grub_uint16_t in_port = 21550; + struct grub_net_buff *nb; +- struct tcphdr *tcph; ++ struct tcp_synhdr *tcph; + int i; + grub_uint8_t *nbd; + grub_net_link_level_address_t ll_target_addr; +@@ -635,20 +647,24 @@ grub_net_tcp_open (char *server, + } + + tcph = (void *) nb->data; ++ grub_memset(tcph, 0, sizeof (*tcph)); + socket->my_start_seq = grub_get_time_ms (); + socket->my_cur_seq = socket->my_start_seq + 1; +- socket->my_window = 8192; +- tcph->seqnr = grub_cpu_to_be32 (socket->my_start_seq); +- tcph->ack = grub_cpu_to_be32_compile_time (0); +- tcph->flags = grub_cpu_to_be16_compile_time ((5 << 12) | TCP_SYN); +- tcph->window = grub_cpu_to_be16 (socket->my_window); +- tcph->urgent = 0; +- tcph->src = grub_cpu_to_be16 (socket->in_port); +- tcph->dst = grub_cpu_to_be16 (socket->out_port); +- tcph->checksum = 0; +- tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP, +- &socket->inf->address, +- &socket->out_nla); ++ socket->my_window = 32768; ++ tcph->tcphdr.seqnr = grub_cpu_to_be32 (socket->my_start_seq); ++ tcph->tcphdr.ack = grub_cpu_to_be32_compile_time (0); ++ tcph->tcphdr.flags = grub_cpu_to_be16_compile_time ((6 << 12) | TCP_SYN); ++ tcph->tcphdr.window = grub_cpu_to_be16 (socket->my_window); ++ tcph->tcphdr.urgent = 0; ++ tcph->tcphdr.src = grub_cpu_to_be16 (socket->in_port); ++ tcph->tcphdr.dst = grub_cpu_to_be16 (socket->out_port); ++ tcph->tcphdr.checksum = 0; ++ tcph->scale_opt.kind = 3; ++ tcph->scale_opt.length = 3; ++ tcph->scale_opt.scale = 5; ++ tcph->tcphdr.checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP, ++ &socket->inf->address, ++ &socket->out_nla); + + tcp_socket_register (socket); + diff --git a/0062-Fix-security-issue-when-reading-username-and-passwor.patch b/0062-Fix-security-issue-when-reading-username-and-passwor.patch new file mode 100644 index 0000000..11bc434 --- /dev/null +++ b/0062-Fix-security-issue-when-reading-username-and-passwor.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hector Marco-Gisbert +Date: Fri, 13 Nov 2015 16:21:09 +0100 +Subject: [PATCH] Fix security issue when reading username and password + + This patch fixes two integer underflows at: + * grub-core/lib/crypto.c + * grub-core/normal/auth.c + +Resolves: CVE-2015-8370 + +Signed-off-by: Hector Marco-Gisbert +Signed-off-by: Ismael Ripoll-Ripoll +--- + grub-core/lib/crypto.c | 2 +- + grub-core/normal/auth.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c +index ca334d5a40e..e6c78d16d39 100644 +--- a/grub-core/lib/crypto.c ++++ b/grub-core/lib/crypto.c +@@ -468,7 +468,7 @@ grub_password_get (char buf[], unsigned buf_size) + break; + } + +- if (key == '\b') ++ if (key == '\b' && cur_len) + { + if (cur_len) + cur_len--; +diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c +index 6be678c0de1..c35ce972473 100644 +--- a/grub-core/normal/auth.c ++++ b/grub-core/normal/auth.c +@@ -172,7 +172,7 @@ grub_username_get (char buf[], unsigned buf_size) + break; + } + +- if (key == GRUB_TERM_BACKSPACE) ++ if (key == GRUB_TERM_BACKSPACE && cur_len) + { + if (cur_len) + { diff --git a/0063-Add-a-url-parser.patch b/0063-Add-a-url-parser.patch new file mode 100644 index 0000000..d6047fb --- /dev/null +++ b/0063-Add-a-url-parser.patch @@ -0,0 +1,1021 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Jun 2016 16:18:44 -0400 +Subject: [PATCH] Add a url parser. + +This patch adds a url parser that can parse http, https, tftp, and tftps +urls, and is easily extensible to handle more types. + +It's a little ugly in terms of the arguments it takes. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 1 + + grub-core/kern/misc.c | 13 + + grub-core/net/url.c | 861 ++++++++++++++++++++++++++++++++++++++++++++ + include/grub/misc.h | 45 +++ + include/grub/net/url.h | 28 ++ + 5 files changed, 948 insertions(+) + create mode 100644 grub-core/net/url.c + create mode 100644 include/grub/net/url.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 57e253ab1a1..99466b1e47e 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2284,6 +2284,7 @@ module = { + common = net/ethernet.c; + common = net/arp.c; + common = net/netbuff.c; ++ common = net/url.c; + }; + + module = { +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 2656a670e09..1c560ea570a 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -296,6 +296,19 @@ grub_strrchr (const char *s, int c) + return p; + } + ++char * ++grub_strchrnul (const char *s, int c) ++{ ++ do ++ { ++ if (*s == c) ++ break; ++ } ++ while (*s++); ++ ++ return (char *) s; ++} ++ + int + grub_strword (const char *haystack, const char *needle) + { +diff --git a/grub-core/net/url.c b/grub-core/net/url.c +new file mode 100644 +index 00000000000..146858284cd +--- /dev/null ++++ b/grub-core/net/url.c +@@ -0,0 +1,861 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2016 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifdef URL_TEST ++ ++#define _GNU_SOURCE 1 ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define N_(x) x ++ ++#define grub_malloc(x) malloc(x) ++#define grub_free(x) ({if (x) free(x);}) ++#define grub_error(a, fmt, args...) printf(fmt "\n", ## args) ++#define grub_dprintf(a, fmt, args...) printf(a ": " fmt, ## args) ++#define grub_strlen(x) strlen(x) ++#define grub_strdup(x) strdup(x) ++#define grub_strstr(x,y) strstr(x,y) ++#define grub_memcpy(x,y,z) memcpy(x,y,z) ++#define grub_strcmp(x,y) strcmp(x,y) ++#define grub_strncmp(x,y,z) strncmp(x,y,z) ++#define grub_strcasecmp(x,y) strcasecmp(x,y) ++#define grub_strchrnul(x,y) strchrnul(x,y) ++#define grub_strchr(x,y) strchr(x,y) ++#define grub_strndup(x,y) strndup(x,y) ++#define grub_strtoul(x,y,z) strtoul(x,y,z) ++#define grub_memmove(x,y,z) memmove(x,y,z) ++#define grub_size_t size_t ++#define grub_errno errno ++ ++#else ++#include ++#include ++#include ++#include ++#endif ++ ++static char * ++translate_slashes(char *str) ++{ ++ int i, j; ++ if (str == NULL) ++ return str; ++ ++ for (i = 0, j = 0; str[i] != '\0'; i++, j++) ++ { ++ if (str[i] == '\\') ++ { ++ str[j] = '/'; ++ if (str[i+1] == '\\') ++ i++; ++ } ++ } ++ ++ return str; ++} ++ ++static inline int ++hex2int (char c) ++{ ++ if (c >= '0' && c <= '9') ++ return c - '0'; ++ c |= 0x20; ++ if (c >= 'a' && c <= 'f') ++ return c - 'a' + 10; ++ return -1; ++} ++ ++static int ++url_unescape (char *buf, grub_size_t len) ++{ ++ int c, rc; ++ unsigned int i; ++ ++ ++ if (len < 3) ++ { ++ for (i = 0; i < len; i++) ++ if (buf[i] == '%') ++ return -1; ++ return 0; ++ } ++ ++ for (i = 0; len > 2 && i < len - 2; i++) ++ { ++ if (buf[i] == '%') ++ { ++ unsigned int j; ++ for (j = i+1; j < i+3; j++) ++ { ++ if (!(buf[j] >= '0' && buf[j] <= '9') && ++ !(buf[j] >= 'a' && buf[j] <= 'f') && ++ !(buf[j] >= 'A' && buf[j] <= 'F')) ++ return -1; ++ } ++ i += 2; ++ } ++ } ++ if (i == len - 2) ++ { ++ if (buf[i+1] == '%' || buf[i+2] == '%') ++ return -1; ++ } ++ for (i = 0; i < len - 2; i++) ++ { ++ if (buf[i] == '%') ++ { ++ rc = hex2int (buf[i+1]); ++ if (rc < 0) ++ return -1; ++ c = (rc & 0xf) << 4; ++ rc = hex2int (buf[i+2]); ++ if (rc < 0) ++ return -1; ++ c |= (rc & 0xf); ++ ++ buf[i] = c; ++ grub_memmove (buf+i+1, buf+i+3, len-(i+2)); ++ len -= 2; ++ } ++ } ++ return 0; ++} ++ ++static int ++extract_http_url_info (char *url, int ssl, ++ char **userinfo, char **host, int *port, ++ char **file) ++{ ++ char *colon, *slash, *query, *at = NULL, *separator, *auth_end; ++ ++ char *userinfo_off = NULL; ++ char *userinfo_end; ++ char *host_off = NULL; ++ char *host_end; ++ char *port_off = NULL; ++ char *port_end; ++ char *file_off = NULL; ++ ++ grub_size_t l; ++ int c; ++ ++ if (!url || !userinfo || !host || !port || !file) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); ++ ++ *userinfo = *host = *file = NULL; ++ *port = -1; ++ ++ userinfo_off = url; ++ ++ slash = grub_strchrnul (userinfo_off, '/'); ++ query = grub_strchrnul (userinfo_off, '?'); ++ auth_end = slash < query ? slash : query; ++ /* auth_end here is one /past/ the last character in the auth section, i.e. ++ * it's the : or / or NUL */ ++ ++ separator = grub_strchrnul (userinfo_off, '@'); ++ if (separator > auth_end) ++ { ++ host_off = userinfo_off; ++ userinfo_off = NULL; ++ userinfo_end = NULL; ++ } ++ else ++ { ++ at = separator; ++ *separator = '\0'; ++ userinfo_end = separator; ++ host_off = separator + 1; ++ } ++ ++ if (*host_off == '[') ++ { ++ separator = grub_strchrnul (host_off, ']'); ++ if (separator >= auth_end) ++ goto fail; ++ ++ separator += 1; ++ host_end = separator; ++ } ++ else ++ { ++ host_end = separator = colon = grub_strchrnul (host_off, ':'); ++ ++ if (colon > auth_end) ++ { ++ separator = NULL; ++ host_end = auth_end; ++ } ++ } ++ ++ if (separator && separator < auth_end) ++ { ++ if (*separator == ':') ++ { ++ port_off = separator + 1; ++ port_end = auth_end; ++ ++ if (auth_end - port_end > 0) ++ goto fail; ++ if (port_end - port_off < 1) ++ goto fail; ++ } ++ else ++ goto fail; ++ } ++ ++ file_off = auth_end; ++ if (port_off) ++ { ++ unsigned long portul; ++ ++ separator = NULL; ++ c = *port_end; ++ *port_end = '\0'; ++ ++ portul = grub_strtoul (port_off, &separator, 10); ++ *port_end = c; ++#ifdef URL_TEST ++ if (portul == ULONG_MAX && errno == ERANGE) ++ goto fail; ++#else ++ if (grub_errno == GRUB_ERR_OUT_OF_RANGE) ++ goto fail; ++#endif ++ if (portul & ~0xfffful) ++ goto fail; ++ if (separator != port_end) ++ goto fail; ++ ++ *port = portul & 0xfffful; ++ } ++ else if (ssl) ++ *port = 443; ++ else ++ *port = 80; ++ ++ if (userinfo_off && *userinfo_off) ++ { ++ l = userinfo_end - userinfo_off + 1; ++ ++ *userinfo = grub_strndup (userinfo_off, l); ++ if (!*userinfo) ++ goto fail; ++ (*userinfo)[l-1]= '\0'; ++ } ++ ++ l = host_end - host_off; ++ ++ if (host_end == NULL) ++ goto fail; ++ else ++ c = *host_end; ++ ++ *host_end = '\0'; ++ *host = grub_strndup (host_off, l); ++ *host_end = c; ++ if (!*host) ++ goto fail; ++ (*host)[l] = '\0'; ++ ++ *file = grub_strdup (file_off); ++ if (!*file) ++ goto fail; ++ ++ if (at) ++ *at = '@'; ++ return 0; ++fail: ++ if (at) ++ *at = '@'; ++ grub_free (*userinfo); ++ grub_free (*host); ++ grub_free (*file); ++ ++ return -1; ++} ++ ++static int ++extract_tftp_url_info (char *url, int ssl, char **host, char **file, int *port) ++{ ++ char *slash, *semi; ++ ++ char *host_off = url; ++ char *host_end; ++ char *file_off; ++ ++ int c; ++ ++ if (!url || !host || !file || !port) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); ++ ++ if (ssl) ++ *port = 3713; ++ else ++ *port = 69; ++ ++ slash = grub_strchr (url, '/'); ++ if (!slash) ++ return -1; ++ ++ host_end = file_off = slash; ++ ++ semi = grub_strchrnul (slash, ';'); ++ if (!grub_strncmp (semi, ";mode=", 6) && grub_strcmp (semi+6, "octet")) ++ { ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ N_("TFTP mode `%s' is not implemented."), semi+6); ++ return -1; ++ } ++ ++ /* ++ * Maybe somebody added a new method, I dunno. Anyway, semi is a reserved ++ * character, so if it's there, it's the start of the mode block or it's ++ * invalid. So set it to \0 unconditionally, not just for ;mode=octet ++ */ ++ *semi = '\0'; ++ ++ c = *host_end; ++ *host_end = '\0'; ++ *host = grub_strdup (host_off); ++ *host_end = c; ++ ++ *file = grub_strdup (file_off); ++ ++ if (!*file || !*host) ++ { ++ grub_free (*file); ++ grub_free (*host); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++int ++extract_url_info (const char *urlbuf, grub_size_t buflen, ++ char **scheme, char **userinfo, ++ char **host, int *port, char **file) ++{ ++ char *url; ++ char *colon; ++ ++ char *scheme_off; ++ char *specific_off; ++ ++ int rc; ++ int c; ++ ++ int https; ++ ++ if (!urlbuf || !buflen || !scheme || !userinfo || !host || !port || !file) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid argument"); ++ ++ *scheme = *userinfo = *host = *file = NULL; ++ *port = -1; ++ ++ /* make sure we have our own coherent grub_string. */ ++ url = grub_malloc (buflen + 1); ++ if (!url) ++ return -1; ++ ++ grub_memcpy (url, urlbuf, buflen); ++ url[buflen] = '\0'; ++ ++ grub_dprintf ("net", "dhcpv6 boot-file-url: `%s'\n", url); ++ ++ /* get rid of any backslashes */ ++ url = translate_slashes (url); ++ ++ /* find the constituent parts */ ++ colon = grub_strstr (url, "://"); ++ if (!colon) ++ goto fail; ++ ++ scheme_off = url; ++ c = *colon; ++ *colon = '\0'; ++ specific_off = colon + 3; ++ ++ https = !grub_strcasecmp (scheme_off, "https"); ++ ++ rc = 0; ++ if (!grub_strcasecmp (scheme_off, "tftp")) ++ { ++ rc = extract_tftp_url_info (specific_off, 0, host, file, port); ++ } ++#ifdef URL_TEST ++ else if (!grub_strcasecmp (scheme_off, "http") || https) ++#else ++ else if (!grub_strcasecmp (scheme_off, "http")) ++#endif ++ { ++ rc = extract_http_url_info (specific_off, ++ https, userinfo, host, port, file); ++ } ++#ifdef URL_TEST ++ else if (!grub_strcasecmp (scheme_off, "iscsi")) ++ { ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ N_("Unimplemented URL scheme `%s'"), scheme_off); ++ *colon = c; ++ goto fail; ++ } ++ else if (!grub_strcasecmp (scheme_off, "tftps")) ++ { ++ rc = extract_tftp_url_info (specific_off, 1, host, file, port); ++ } ++#endif ++ else ++ { ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ N_("Unimplemented URL scheme `%s'"), scheme_off); ++ *colon = c; ++ goto fail; ++ } ++ ++ if (rc < 0) ++ { ++ *colon = c; ++ goto fail; ++ } ++ ++ *scheme = grub_strdup (scheme_off); ++ *colon = c; ++ if (!*scheme) ++ goto fail; ++ ++ if (*userinfo) ++ { ++ rc = url_unescape (*userinfo, grub_strlen (*userinfo)); ++ if (rc < 0) ++ goto fail; ++ } ++ ++ if (*host) ++ { ++ rc = url_unescape (*host, grub_strlen (*host)); ++ if (rc < 0) ++ goto fail; ++ } ++ ++ if (*file) ++ { ++ rc = url_unescape (*file, grub_strlen (*file)); ++ if (rc < 0) ++ goto fail; ++ } ++ ++ grub_free (url); ++ return 0; ++fail: ++ grub_free (*scheme); ++ grub_free (*userinfo); ++ grub_free (*host); ++ grub_free (*file); ++ ++ if (!grub_errno) ++ grub_error (GRUB_ERR_NET_BAD_ADDRESS, N_("Invalid boot-file-url `%s'"), ++ url); ++ grub_free (url); ++ return -1; ++} ++ ++#ifdef URL_TEST ++ ++struct test { ++ char *url; ++ int rc; ++ char *scheme; ++ char *userinfo; ++ char *host; ++ int port; ++ char *file; ++} tests[] = { ++ {.url = "http://foo.example.com/", ++ .rc = 0, ++ .scheme = "http", ++ .host = "foo.example.com", ++ .port = 80, ++ .file = "/", ++ }, ++ {.url = "http://foo.example.com/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .host = "foo.example.com", ++ .port = 80, ++ .file = "/?foobar", ++ }, ++ {.url = "http://[foo.example.com/", ++ .rc = -1, ++ }, ++ {.url = "http://[foo.example.com/?foobar", ++ .rc = -1, ++ }, ++ {.url = "http://foo.example.com:/", ++ .rc = -1, ++ }, ++ {.url = "http://foo.example.com:81/", ++ .rc = 0, ++ .scheme = "http", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "http://foo.example.com:81/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "http://[1234::1]/", ++ .rc = 0, ++ .scheme = "http", ++ .host = "[1234::1]", ++ .port = 80, ++ .file = "/", ++ }, ++ {.url = "http://[1234::1]/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .host = "[1234::1]", ++ .port = 80, ++ .file = "/?foobar", ++ }, ++ {.url = "http://[1234::1]:81/", ++ .rc = 0, ++ .scheme = "http", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "http://[1234::1]:81/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "http://foo@foo.example.com/", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 80, ++ .file = "/", ++ }, ++ {.url = "http://foo@foo.example.com/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 80, ++ .file = "/?foobar", ++ }, ++ {.url = "http://foo@[foo.example.com/", ++ .rc = -1, ++ }, ++ {.url = "http://foo@[foo.example.com/?foobar", ++ .rc = -1, ++ }, ++ {.url = "http://foo@foo.example.com:81/", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "http://foo@foo.example.com:81/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "http://foo@[1234::1]/", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 80, ++ .file = "/", ++ }, ++ {.url = "http://foo@[1234::1]/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 80, ++ .file = "/?foobar", ++ }, ++ {.url = "http://foo@[1234::1]:81/", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "http://foo@[1234::1]:81/?foobar", ++ .rc = 0, ++ .scheme = "http", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "https://foo.example.com/", ++ .rc = 0, ++ .scheme = "https", ++ .host = "foo.example.com", ++ .port = 443, ++ .file = "/", ++ }, ++ {.url = "https://foo.example.com/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .host = "foo.example.com", ++ .port = 443, ++ .file = "/?foobar", ++ }, ++ {.url = "https://[foo.example.com/", ++ .rc = -1, ++ }, ++ {.url = "https://[foo.example.com/?foobar", ++ .rc = -1, ++ }, ++ {.url = "https://foo.example.com:81/", ++ .rc = 0, ++ .scheme = "https", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "https://foo.example.com:81/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "https://[1234::1]/", ++ .rc = 0, ++ .scheme = "https", ++ .host = "[1234::1]", ++ .port = 443, ++ .file = "/", ++ }, ++ {.url = "https://[1234::1]/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .host = "[1234::1]", ++ .port = 443, ++ .file = "/?foobar", ++ }, ++ {.url = "https://[1234::1]:81/", ++ .rc = 0, ++ .scheme = "https", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "https://[1234::1]:81/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "https://foo@foo.example.com/", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 443, ++ .file = "/", ++ }, ++ {.url = "https://foo@foo.example.com/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 443, ++ .file = "/?foobar", ++ }, ++ {.url = "https://foo@[foo.example.com/", ++ .rc = -1, ++ }, ++ {.url = "https://f%6fo@[foo.example.com/?fooba%72", ++ .rc = -1, ++ }, ++ {.url = "https://foo@foo.example.com:81/", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "https://foo@foo.example.com:81/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "foo.example.com", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "https://foo@[1234::1]/", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 443, ++ .file = "/", ++ }, ++ {.url = "https://foo@[1234::1]/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 443, ++ .file = "/?foobar", ++ }, ++ {.url = "https://f%6fo@[12%334::1]:81/", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/", ++ }, ++ {.url = "https://foo@[1234::1]:81/?foobar", ++ .rc = 0, ++ .scheme = "https", ++ .userinfo = "foo", ++ .host = "[1234::1]", ++ .port = 81, ++ .file = "/?foobar", ++ }, ++ {.url = "tftp://foo.e%78ample.com/foo/bar/b%61%7a", ++ .rc = 0, ++ .scheme = "tftp", ++ .host = "foo.example.com", ++ .port = 69, ++ .file = "/foo/bar/baz", ++ }, ++ {.url = "tftp://foo.example.com/foo/bar/baz", ++ .rc = 0, ++ .scheme = "tftp", ++ .host = "foo.example.com", ++ .port = 69, ++ .file = "/foo/bar/baz", ++ }, ++ {.url = "tftps://foo.example.com/foo/bar/baz", ++ .rc = 0, ++ .scheme = "tftps", ++ .host = "foo.example.com", ++ .port = 3713, ++ .file = "/foo/bar/baz", ++ }, ++ {.url = "tftps://foo.example.com/foo/bar/baz;mode=netascii", ++ .rc = -1, ++ }, ++ {.url = "tftps://foo.example.com/foo/bar/baz;mode=octet", ++ .rc = 0, ++ .scheme = "tftps", ++ .host = "foo.example.com", ++ .port = 3713, ++ .file = "/foo/bar/baz", ++ }, ++ {.url = "tftps://foo.example.com/foo/bar/baz;mode=invalid", ++ .rc = -1, ++ }, ++ {.url = "", ++ }, ++}; ++ ++static int ++string_test (char *name, char *a, char *b) ++{ ++ if ((a && !b) || (!a && b)) ++ { ++ printf("expected %s \"%s\", got \"%s\"\n", name, a, b); ++ return -1; ++ } ++ if (a && b && strcmp(a, b)) ++ { ++ printf("expected %s \"%s\", got \"%s\"\n", name, a, b); ++ return -1; ++ } ++ return 0; ++} ++ ++int ++main(void) ++{ ++ unsigned int i; ++ int rc; ++ ++ for (i = 0; tests[i].url[0] != '\0'; i++) ++ { ++ char *scheme, *userinfo, *host, *file; ++ int port; ++ ++ printf("======= url: \"%s\"\n", tests[i].url); ++ rc = extract_url_info(tests[i].url, strlen(tests[i].url) + 1, ++ &scheme, &userinfo, &host, &port, &file); ++ if (tests[i].rc != rc) ++ { ++ printf(" extract_url_info(...) = %d\n", rc); ++ exit(1); ++ } ++ else if (rc >= 0) ++ { ++ if (string_test("scheme", tests[i].scheme, scheme) < 0) ++ exit(1); ++ if (string_test("userinfo", tests[i].userinfo, userinfo) < 0) ++ exit(1); ++ if (string_test("host", tests[i].host, host) < 0) ++ exit(1); ++ if (port != tests[i].port) ++ { ++ printf(" bad port \"%d\" should have been \"%d\"\n", ++ port, tests[i].port); ++ exit(1); ++ } ++ if (string_test("file", tests[i].file, file) < 0) ++ exit(1); ++ } ++ free(scheme); ++ free(userinfo); ++ free(host); ++ free(file); ++ } ++ printf("everything worked?!?\n"); ++} ++#endif +diff --git a/include/grub/misc.h b/include/grub/misc.h +index f9135b62e35..b4339222ecb 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -85,6 +85,7 @@ int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size_t n); + + char *EXPORT_FUNC(grub_strchr) (const char *s, int c); + char *EXPORT_FUNC(grub_strrchr) (const char *s, int c); ++char *EXPORT_FUNC(grub_strchrnul) (const char *s, int c); + int EXPORT_FUNC(grub_strword) (const char *s, const char *w); + + /* Copied from gnulib. +@@ -207,6 +208,50 @@ grub_toupper (int c) + return c; + } + ++static inline char * ++grub_strcasestr (const char *haystack, const char *needle) ++{ ++ /* Be careful not to look at the entire extent of haystack or needle ++ until needed. This is useful because of these two cases: ++ - haystack may be very long, and a match of needle found early, ++ - needle may be very long, and not even a short initial segment of ++ needle may be found in haystack. */ ++ if (*needle != '\0') ++ { ++ /* Speed up the following searches of needle by caching its first ++ character. */ ++ char b = *needle++; ++ ++ for (;; haystack++) ++ { ++ if (*haystack == '\0') ++ /* No match. */ ++ return 0; ++ if (grub_tolower(*haystack) == grub_tolower(b)) ++ /* The first character matches. */ ++ { ++ const char *rhaystack = haystack + 1; ++ const char *rneedle = needle; ++ ++ for (;; rhaystack++, rneedle++) ++ { ++ if (*rneedle == '\0') ++ /* Found a match. */ ++ return (char *) haystack; ++ if (*rhaystack == '\0') ++ /* No match. */ ++ return 0; ++ if (grub_tolower(*rhaystack) != grub_tolower(*rneedle)) ++ /* Nothing in this round. */ ++ break; ++ } ++ } ++ } ++ } ++ else ++ return (char *) haystack; ++} ++ + static inline int + grub_strcasecmp (const char *s1, const char *s2) + { +diff --git a/include/grub/net/url.h b/include/grub/net/url.h +new file mode 100644 +index 00000000000..a215fa27d0a +--- /dev/null ++++ b/include/grub/net/url.h +@@ -0,0 +1,28 @@ ++/* url.h - prototypes for url parsing functions */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2016 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_URL_HEADER ++#define GRUB_URL_HEADER 1 ++ ++int ++EXPORT_FUNC(extract_url_info) (const char *urlbuf, grub_size_t buflen, ++ char **scheme, char **userinfo, ++ char **host, int *port, char **file); ++ ++#endif /* GRUB_URL_HEADER */ diff --git a/0064-efinet-and-bootp-add-support-for-dhcpv6.patch b/0064-efinet-and-bootp-add-support-for-dhcpv6.patch new file mode 100644 index 0000000..0e60b8a --- /dev/null +++ b/0064-efinet-and-bootp-add-support-for-dhcpv6.patch @@ -0,0 +1,661 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jul 2019 11:47:37 +0200 +Subject: [PATCH] efinet and bootp: add support for dhcpv6 + +Signed-off-by: Peter Jones +--- + grub-core/net/bootp.c | 174 +++++++++++++++++++++++++++++++++++++ + grub-core/net/drivers/efi/efinet.c | 54 ++++++++++-- + grub-core/net/net.c | 72 +++++++++++++++ + grub-core/net/tftp.c | 4 + + include/grub/efi/api.h | 129 +++++++++++++++++++++++++-- + include/grub/net.h | 60 +++++++++++++ + 6 files changed, 479 insertions(+), 14 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 0e6e41a1699..8c969595a7b 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + + struct grub_dhcp_discover_options +@@ -935,6 +936,179 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + + static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp; + ++struct grub_net_network_level_interface * ++grub_net_configure_by_dhcpv6_ack (const char *name, ++ struct grub_net_card *card, ++ grub_net_interface_flags_t flags ++ __attribute__((__unused__)), ++ const grub_net_link_level_address_t *hwaddr, ++ const struct grub_net_dhcpv6_packet *packet, ++ int is_def, char **device, char **path) ++{ ++ struct grub_net_network_level_interface *inter = NULL; ++ struct grub_net_network_level_address addr; ++ int mask = -1; ++ ++ if (!device || !path) ++ return NULL; ++ ++ *device = 0; ++ *path = 0; ++ ++ grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n", ++ hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2], ++ hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]); ++ ++ if (is_def) ++ grub_net_default_server = 0; ++ ++ if (is_def && !grub_net_default_server && packet) ++ { ++ const grub_uint8_t *options = packet->dhcp_options; ++ unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet); ++ unsigned int i; ++ ++ for (i = 0; i < option_max - sizeof (grub_net_dhcpv6_option_t); ) ++ { ++ grub_uint16_t num, len; ++ grub_net_dhcpv6_option_t *opt = ++ (grub_net_dhcpv6_option_t *)(options + i); ++ ++ num = grub_be_to_cpu16(opt->option_num); ++ len = grub_be_to_cpu16(opt->option_len); ++ ++ grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len); ++ ++ if (len == 0) ++ break; ++ ++ if (len + i > 1024) ++ break; ++ ++ if (num == GRUB_NET_DHCP6_BOOTFILE_URL) ++ { ++ char *scheme, *userinfo, *host, *file; ++ char *tmp; ++ int hostlen; ++ int port; ++ int rc = extract_url_info ((const char *)opt->option_data, ++ (grub_size_t)len, ++ &scheme, &userinfo, &host, &port, ++ &file); ++ if (rc < 0) ++ continue; ++ ++ /* right now this only handles tftp. */ ++ if (grub_strcmp("tftp", scheme)) ++ { ++ grub_free (scheme); ++ grub_free (userinfo); ++ grub_free (host); ++ grub_free (file); ++ continue; ++ } ++ grub_free (userinfo); ++ ++ hostlen = grub_strlen (host); ++ if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']') ++ { ++ tmp = host+1; ++ host[hostlen-1] = '\0'; ++ } ++ else ++ tmp = host; ++ ++ *device = grub_xasprintf ("%s,%s", scheme, tmp); ++ grub_free (scheme); ++ grub_free (host); ++ ++ if (file && *file) ++ { ++ tmp = grub_strrchr (file, '/'); ++ if (tmp) ++ *(tmp+1) = '\0'; ++ else ++ file[0] = '\0'; ++ } ++ else if (!file) ++ file = grub_strdup (""); ++ ++ if (file[0] == '/') ++ { ++ *path = grub_strdup (file+1); ++ grub_free (file); ++ } ++ else ++ *path = file; ++ } ++ else if (num == GRUB_NET_DHCP6_IA_NA) ++ { ++ const grub_net_dhcpv6_option_t *ia_na_opt; ++ const grub_net_dhcpv6_opt_ia_na_t *ia_na = ++ (const grub_net_dhcpv6_opt_ia_na_t *)opt; ++ unsigned int left = len - OFFSET_OF (options, ia_na); ++ unsigned int j; ++ ++ if ((grub_uint8_t *)ia_na + left > ++ (grub_uint8_t *)options + option_max) ++ left -= ((grub_uint8_t *)ia_na + left) ++ - ((grub_uint8_t *)options + option_max); ++ ++ if (len < OFFSET_OF (option_data, opt) ++ + sizeof (grub_net_dhcpv6_option_t)) ++ { ++ grub_dprintf ("net", ++ "found dhcpv6 ia_na option with no address\n"); ++ continue; ++ } ++ ++ for (j = 0; left > sizeof (grub_net_dhcpv6_option_t); ) ++ { ++ ia_na_opt = (const grub_net_dhcpv6_option_t *) ++ (ia_na->options + j); ++ grub_uint16_t ia_na_opt_num, ia_na_opt_len; ++ ++ ia_na_opt_num = grub_be_to_cpu16 (ia_na_opt->option_num); ++ ia_na_opt_len = grub_be_to_cpu16 (ia_na_opt->option_len); ++ if (ia_na_opt_len == 0) ++ break; ++ if (j + ia_na_opt_len > left) ++ break; ++ if (ia_na_opt_num == GRUB_NET_DHCP6_IA_ADDRESS) ++ { ++ const grub_net_dhcpv6_opt_ia_address_t *ia_addr; ++ ++ ia_addr = (const grub_net_dhcpv6_opt_ia_address_t *) ++ ia_na_opt; ++ addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ grub_memcpy(addr.ipv6, ia_addr->ipv6_address, ++ sizeof (ia_addr->ipv6_address)); ++ inter = grub_net_add_addr (name, card, &addr, hwaddr, 0); ++ } ++ ++ j += ia_na_opt_len; ++ left -= ia_na_opt_len; ++ } ++ } ++ ++ i += len + 4; ++ } ++ ++ grub_print_error (); ++ } ++ ++ if (is_def) ++ { ++ grub_env_set ("net_default_interface", name); ++ grub_env_export ("net_default_interface"); ++ } ++ ++ if (inter) ++ grub_net_add_ipv6_local (inter, mask); ++ return inter; ++} ++ ++ + void + grub_bootp_init (void) + { +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 5388f952ba9..a57189e8bb3 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -18,11 +18,15 @@ + + #include + #include ++#include + #include ++#include + #include + #include + #include + #include ++#include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -329,7 +333,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + char **path) + { + struct grub_net_card *card; +- grub_efi_device_path_t *dp; ++ grub_efi_device_path_t *dp, *ldp = NULL; + + dp = grub_efi_get_device_path (hnd); + if (! dp) +@@ -340,14 +344,19 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + grub_efi_device_path_t *cdp; + struct grub_efi_pxe *pxe; + struct grub_efi_pxe_mode *pxe_mode; ++ + if (card->driver != &efidriver) + continue; ++ + cdp = grub_efi_get_device_path (card->efi_handle); + if (! cdp) + continue; ++ ++ ldp = grub_efi_find_last_device_path (dp); ++ + if (grub_efi_compare_device_paths (dp, cdp) != 0) + { +- grub_efi_device_path_t *ldp, *dup_dp, *dup_ldp; ++ grub_efi_device_path_t *dup_dp, *dup_ldp; + int match; + + /* EDK2 UEFI PXE driver creates pseudo devices with type IPv4/IPv6 +@@ -356,7 +365,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + devices. We skip them when enumerating cards, so here we need to + find matching MAC device. + */ +- ldp = grub_efi_find_last_device_path (dp); + if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE + || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE + && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) +@@ -373,16 +381,46 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + if (!match) + continue; + } ++ + pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (! pxe) + continue; ++ + pxe_mode = pxe->mode; +- grub_net_configure_by_dhcp_ack (card->name, card, 0, +- (struct grub_net_bootp_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), +- 1, device, path); ++ if (pxe_mode->using_ipv6) ++ { ++ grub_net_link_level_address_t hwaddr; ++ struct grub_net_network_level_interface *intf; ++ ++ grub_dprintf ("efinet", "using ipv6 and dhcpv6\n"); ++ grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", ++ pxe_mode->dhcp_ack_received ? "yes" : "no", ++ pxe_mode->dhcp_ack_received ? "" : " cannot continue"); ++ if (!pxe_mode->dhcp_ack_received) ++ continue; ++ ++ hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ grub_memcpy (hwaddr.mac, ++ card->efi_net->mode->current_address, ++ sizeof (hwaddr.mac)); ++ ++ intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, ++ (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6, ++ 1, device, path); ++ if (intf && device && path) ++ grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); ++ } ++ else ++ { ++ grub_dprintf ("efinet", "using ipv4 and dhcp\n"); ++ grub_net_configure_by_dhcp_ack (card->name, card, 0, ++ (struct grub_net_bootp_packet *) ++ &pxe_mode->dhcp_ack, ++ sizeof (pxe_mode->dhcp_ack), ++ 1, device, path); ++ grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); ++ } + return; + } + } +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 4b7972b8e7e..f24f1fd63f6 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -955,6 +955,78 @@ grub_net_network_level_interface_register (struct grub_net_network_level_interfa + grub_net_network_level_interfaces = inter; + } + ++int ++grub_ipv6_get_masksize (grub_uint16_t be_mask[8]) ++{ ++ grub_uint8_t *mask; ++ grub_uint16_t mask16[8]; ++ int x, y; ++ int ret = 128; ++ ++ grub_memcpy (mask16, be_mask, sizeof (mask16)); ++ for (x = 0; x < 8; x++) ++ mask16[x] = grub_be_to_cpu16 (mask16[x]); ++ ++ mask = (grub_uint8_t *)mask16; ++ ++ for (x = 15; x >= 0; x--) ++ { ++ grub_uint8_t octet = mask[x]; ++ if (!octet) ++ { ++ ret -= 8; ++ continue; ++ } ++ for (y = 0; y < 8; y++) ++ { ++ if (octet & (1 << y)) ++ break; ++ else ++ ret--; ++ } ++ break; ++ } ++ ++ return ret; ++} ++ ++grub_err_t ++grub_net_add_ipv6_local (struct grub_net_network_level_interface *inter, ++ int mask) ++{ ++ struct grub_net_route *route; ++ ++ if (inter->address.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6) ++ return 0; ++ ++ if (mask == -1) ++ mask = grub_ipv6_get_masksize ((grub_uint16_t *)inter->address.ipv6); ++ ++ if (mask == -1) ++ return 0; ++ ++ route = grub_zalloc (sizeof (*route)); ++ if (!route) ++ return grub_errno; ++ ++ route->name = grub_xasprintf ("%s:local", inter->name); ++ if (!route->name) ++ { ++ grub_free (route); ++ return grub_errno; ++ } ++ ++ route->target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ grub_memcpy (route->target.ipv6.base, inter->address.ipv6, ++ sizeof (inter->address.ipv6)); ++ route->target.ipv6.masksize = mask; ++ route->is_gateway = 0; ++ route->interface = inter; ++ ++ grub_net_route_register (route); ++ ++ return 0; ++} + + grub_err_t + grub_net_add_ipv4_local (struct grub_net_network_level_interface *inter, +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 7d90bf66e76..a5c5038130a 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -379,19 +379,23 @@ tftp_open (struct grub_file *file, const char *filename) + return grub_errno; + } + ++ grub_dprintf ("tftp", "resolving address for %s\n", file->device->net->server); + err = grub_net_resolve_address (file->device->net->server, &addr); + if (err) + { ++ grub_dprintf("tftp", "Address resolution failed: %d\n", err); + destroy_pq (data); + grub_free (data); + return err; + } + ++ grub_dprintf ("tftp", "opening connection\n"); + data->sock = grub_net_udp_open (addr, + TFTP_SERVER_PORT, tftp_receive, + file); + if (!data->sock) + { ++ grub_dprintf ("tftp", "connection failed\n"); + destroy_pq (data); + grub_free (data); + return grub_errno; +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index addcbfa8fb7..d97cdf98c80 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -572,10 +572,16 @@ typedef void *grub_efi_handle_t; + typedef void *grub_efi_event_t; + typedef grub_efi_uint64_t grub_efi_lba_t; + typedef grub_efi_uintn_t grub_efi_tpl_t; +-typedef grub_uint8_t grub_efi_mac_address_t[32]; +-typedef grub_uint8_t grub_efi_ipv4_address_t[4]; +-typedef grub_uint16_t grub_efi_ipv6_address_t[8]; +-typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4))); ++typedef grub_efi_uint8_t grub_efi_mac_address_t[32]; ++typedef grub_efi_uint8_t grub_efi_ipv4_address_t[4]; ++typedef grub_efi_uint8_t grub_efi_ipv6_address_t[16]; ++typedef union ++{ ++ grub_efi_uint32_t addr[4]; ++ grub_efi_ipv4_address_t v4; ++ grub_efi_ipv6_address_t v6; ++} grub_efi_ip_address_t __attribute__ ((aligned(4))); ++ + typedef grub_efi_uint64_t grub_efi_physical_address_t; + typedef grub_efi_uint64_t grub_efi_virtual_address_t; + +@@ -1450,16 +1456,127 @@ struct grub_efi_simple_text_output_interface + }; + typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t; + +-typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; ++typedef struct grub_efi_pxe_dhcpv4_packet ++{ ++ grub_efi_uint8_t bootp_opcode; ++ grub_efi_uint8_t bootp_hwtype; ++ grub_efi_uint8_t bootp_hwaddr_len; ++ grub_efi_uint8_t bootp_gate_hops; ++ grub_efi_uint32_t bootp_ident; ++ grub_efi_uint16_t bootp_seconds; ++ grub_efi_uint16_t bootp_flags; ++ grub_efi_uint8_t bootp_ci_addr[4]; ++ grub_efi_uint8_t bootp_yi_addr[4]; ++ grub_efi_uint8_t bootp_si_addr[4]; ++ grub_efi_uint8_t bootp_gi_addr[4]; ++ grub_efi_uint8_t bootp_hw_addr[16]; ++ grub_efi_uint8_t bootp_srv_name[64]; ++ grub_efi_uint8_t bootp_boot_file[128]; ++ grub_efi_uint32_t dhcp_magik; ++ grub_efi_uint8_t dhcp_options[56]; ++} grub_efi_pxe_dhcpv4_packet_t; ++ ++struct grub_efi_pxe_dhcpv6_packet ++{ ++ grub_efi_uint32_t message_type:8; ++ grub_efi_uint32_t transaction_id:24; ++ grub_efi_uint8_t dhcp_options[1024]; ++} GRUB_PACKED; ++typedef struct grub_efi_pxe_dhcpv6_packet grub_efi_pxe_dhcpv6_packet_t; ++ ++typedef union ++{ ++ grub_efi_uint8_t raw[1472]; ++ grub_efi_pxe_dhcpv4_packet_t dhcpv4; ++ grub_efi_pxe_dhcpv6_packet_t dhcpv6; ++} grub_efi_pxe_packet_t; ++ ++#define GRUB_EFI_PXE_MAX_IPCNT 8 ++#define GRUB_EFI_PXE_MAX_ARP_ENTRIES 8 ++#define GRUB_EFI_PXE_MAX_ROUTE_ENTRIES 8 ++ ++typedef struct grub_efi_pxe_ip_filter ++{ ++ grub_efi_uint8_t filters; ++ grub_efi_uint8_t ip_count; ++ grub_efi_uint8_t reserved; ++ grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT]; ++} grub_efi_pxe_ip_filter_t; ++ ++typedef struct grub_efi_pxe_arp_entry ++{ ++ grub_efi_ip_address_t ip_addr; ++ grub_efi_mac_address_t mac_addr; ++} grub_efi_pxe_arp_entry_t; ++ ++typedef struct grub_efi_pxe_route_entry ++{ ++ grub_efi_ip_address_t ip_addr; ++ grub_efi_ip_address_t subnet_mask; ++ grub_efi_ip_address_t gateway_addr; ++} grub_efi_pxe_route_entry_t; ++ ++typedef struct grub_efi_pxe_icmp_error ++{ ++ grub_efi_uint8_t type; ++ grub_efi_uint8_t code; ++ grub_efi_uint16_t checksum; ++ union ++ { ++ grub_efi_uint32_t reserved; ++ grub_efi_uint32_t mtu; ++ grub_efi_uint32_t pointer; ++ struct ++ { ++ grub_efi_uint16_t identifier; ++ grub_efi_uint16_t sequence; ++ } echo; ++ } u; ++ grub_efi_uint8_t data[494]; ++} grub_efi_pxe_icmp_error_t; ++ ++typedef struct grub_efi_pxe_tftp_error ++{ ++ grub_efi_uint8_t error_code; ++ grub_efi_char8_t error_string[127]; ++} grub_efi_pxe_tftp_error_t; + + typedef struct grub_efi_pxe_mode + { +- grub_uint8_t unused[52]; ++ grub_efi_boolean_t started; ++ grub_efi_boolean_t ipv6_available; ++ grub_efi_boolean_t ipv6_supported; ++ grub_efi_boolean_t using_ipv6; ++ grub_efi_boolean_t bis_supported; ++ grub_efi_boolean_t bis_detected; ++ grub_efi_boolean_t auto_arp; ++ grub_efi_boolean_t send_guid; ++ grub_efi_boolean_t dhcp_discover_valid; ++ grub_efi_boolean_t dhcp_ack_received; ++ grub_efi_boolean_t proxy_offer_received; ++ grub_efi_boolean_t pxe_discover_valid; ++ grub_efi_boolean_t pxe_reply_received; ++ grub_efi_boolean_t pxe_bis_reply_received; ++ grub_efi_boolean_t icmp_error_received; ++ grub_efi_boolean_t tftp_error_received; ++ grub_efi_boolean_t make_callbacks; ++ grub_efi_uint8_t ttl; ++ grub_efi_uint8_t tos; ++ grub_efi_ip_address_t station_ip; ++ grub_efi_ip_address_t subnet_mask; + grub_efi_pxe_packet_t dhcp_discover; + grub_efi_pxe_packet_t dhcp_ack; + grub_efi_pxe_packet_t proxy_offer; + grub_efi_pxe_packet_t pxe_discover; + grub_efi_pxe_packet_t pxe_reply; ++ grub_efi_pxe_packet_t pxe_bis_reply; ++ grub_efi_pxe_ip_filter_t ip_filter; ++ grub_efi_uint32_t arp_cache_entries; ++ grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_MAX_ARP_ENTRIES]; ++ grub_efi_uint32_t route_table_entries; ++ grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_MAX_ROUTE_ENTRIES]; ++ grub_efi_pxe_icmp_error_t icmp_error; ++ grub_efi_pxe_tftp_error_t tftp_error; + } grub_efi_pxe_mode_t; + + typedef struct grub_efi_pxe +diff --git a/include/grub/net.h b/include/grub/net.h +index ff6d347f7da..3647012374b 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -447,6 +447,51 @@ struct grub_net_bootp_packet + grub_uint8_t vendor[0]; + } GRUB_PACKED; + ++enum ++ { ++ GRUB_NET_DHCP6_IA_NA = 3, ++ GRUB_NET_DHCP6_IA_ADDRESS = 5, ++ GRUB_NET_DHCP6_BOOTFILE_URL = 59, ++ }; ++ ++struct grub_net_dhcpv6_option ++{ ++ grub_uint16_t option_num; ++ grub_uint16_t option_len; ++ grub_uint8_t option_data[]; ++} GRUB_PACKED; ++typedef struct grub_net_dhcpv6_option grub_net_dhcpv6_option_t; ++ ++struct grub_net_dhcpv6_opt_ia_na ++{ ++ grub_uint16_t option_num; ++ grub_uint16_t option_len; ++ grub_uint32_t iaid; ++ grub_uint32_t t1; ++ grub_uint32_t t2; ++ grub_uint8_t options[]; ++} GRUB_PACKED; ++typedef struct grub_net_dhcpv6_opt_ia_na grub_net_dhcpv6_opt_ia_na_t; ++ ++struct grub_net_dhcpv6_opt_ia_address ++{ ++ grub_uint16_t option_num; ++ grub_uint16_t option_len; ++ grub_uint64_t ipv6_address[2]; ++ grub_uint32_t preferred_lifetime; ++ grub_uint32_t valid_lifetime; ++ grub_uint8_t options[]; ++} GRUB_PACKED; ++typedef struct grub_net_dhcpv6_opt_ia_address grub_net_dhcpv6_opt_ia_address_t; ++ ++struct grub_net_dhcpv6_packet ++{ ++ grub_uint32_t message_type:8; ++ grub_uint32_t transaction_id:24; ++ grub_uint8_t dhcp_options[1024]; ++} GRUB_PACKED; ++typedef struct grub_net_dhcpv6_packet grub_net_dhcpv6_packet_t; ++ + #define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63 + #define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82 + #define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53 +@@ -482,6 +527,21 @@ grub_net_configure_by_dhcp_ack (const char *name, + grub_size_t size, + int is_def, char **device, char **path); + ++struct grub_net_network_level_interface * ++grub_net_configure_by_dhcpv6_ack (const char *name, ++ struct grub_net_card *card, ++ grub_net_interface_flags_t flags, ++ const grub_net_link_level_address_t *hwaddr, ++ const struct grub_net_dhcpv6_packet *packet, ++ int is_def, char **device, char **path); ++ ++int ++grub_ipv6_get_masksize(grub_uint16_t *mask); ++ ++grub_err_t ++grub_net_add_ipv6_local (struct grub_net_network_level_interface *inf, ++ int mask); ++ + grub_err_t + grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf, + int mask); diff --git a/0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch b/0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch new file mode 100644 index 0000000..00611dc --- /dev/null +++ b/0065-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch @@ -0,0 +1,296 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 23 Jun 2016 11:01:39 -0400 +Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux + +This patch adds grub-get-kernel-settings, which reads the system kernel +installation configuration from /etc/sysconfig/kernel, and outputs +${GRUB_...} variables suitable for evaluation by grub-mkconfig. Those +variables are then used by 10_linux to choose whether or not to create +debug stanzas. + +Resolves: rhbz#1226325 +--- + configure.ac | 2 + + Makefile.util.def | 7 ++ + util/bash-completion.d/grub-completion.bash.in | 22 +++++++ + util/grub-get-kernel-settings.3 | 20 ++++++ + util/grub-get-kernel-settings.in | 88 ++++++++++++++++++++++++++ + util/grub-mkconfig.in | 3 + + util/grub.d/10_linux.in | 23 +++++-- + 7 files changed, 160 insertions(+), 5 deletions(-) + create mode 100644 util/grub-get-kernel-settings.3 + create mode 100644 util/grub-get-kernel-settings.in + +diff --git a/configure.ac b/configure.ac +index 68501662e8d..fc3c2b44d60 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -62,6 +62,7 @@ grub_TRANSFORM([grub-install]) + grub_TRANSFORM([grub-mkconfig]) + grub_TRANSFORM([grub-mkfont]) + grub_TRANSFORM([grub-mkimage]) ++grub_TRANSFORM([grub-get-kernel-settings]) + grub_TRANSFORM([grub-glue-efi]) + grub_TRANSFORM([grub-mklayout]) + grub_TRANSFORM([grub-mkpasswd-pbkdf2]) +@@ -79,6 +80,7 @@ grub_TRANSFORM([grub-file]) + grub_TRANSFORM([grub-bios-setup.3]) + grub_TRANSFORM([grub-editenv.1]) + grub_TRANSFORM([grub-fstest.3]) ++grub_TRANSFORM([grub-get-kernel-settings.3]) + grub_TRANSFORM([grub-glue-efi.3]) + grub_TRANSFORM([grub-install.1]) + grub_TRANSFORM([grub-kbdcomp.3]) +diff --git a/Makefile.util.def b/Makefile.util.def +index e50436a4987..2215cc759c0 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -725,6 +725,13 @@ script = { + installdir = sbin; + }; + ++script = { ++ name = grub-get-kernel-settings; ++ common = util/grub-get-kernel-settings.in; ++ mansection = 3; ++ installdir = sbin; ++}; ++ + script = { + name = grub-set-default; + common = util/grub-set-default.in; +diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in +index 44bf135b9f8..5c4acd496d4 100644 +--- a/util/bash-completion.d/grub-completion.bash.in ++++ b/util/bash-completion.d/grub-completion.bash.in +@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \ + unset __grub_sparc64_setup_program + + ++# ++# grub-get-kernel-settings ++# ++_grub_get_kernel_settings () { ++ local cur ++ ++ COMPREPLY=() ++ cur=`_get_cword` ++ ++ if [[ "$cur" == -* ]]; then ++ __grubcomp "$(__grub_get_options_from_help)" ++ else ++ # Default complete with a filename ++ _filedir ++ fi ++} ++__grub_get_kernel_settings_program="@grub_get_kernel_settings@" ++have ${__grub_get_kernel_settings_program} && \ ++ complete -F _grub_get_kernel_settings -o filenames ${__grub_get_kernel_settings_program} ++unset __grub_get_kernel_settings_program ++ ++ + # + # grub-install + # +diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3 +new file mode 100644 +index 00000000000..ba33330e28d +--- /dev/null ++++ b/util/grub-get-kernel-settings.3 +@@ -0,0 +1,20 @@ ++.TH GRUB-GET-KERNEL-SETTINGS 3 "Thu Jun 25 2015" ++.SH NAME ++\fBgrub-get-kernel-settings\fR \(em Evaluate the system's kernel installation settings for use while making a grub configuration file. ++ ++.SH SYNOPSIS ++\fBgrub-get-kernel-settings\fR [OPTION] ++ ++.SH DESCRIPTION ++\fBgrub-get-kernel-settings\fR reads the kernel installation settings on the host system, and emits a set of grub settings suitable for use when creating a grub configuration file. ++ ++.SH OPTIONS ++.TP ++-h, --help ++Display program usage and exit. ++.TP ++-v, --version ++Display the current version. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in +new file mode 100644 +index 00000000000..7e87dfccc0e +--- /dev/null ++++ b/util/grub-get-kernel-settings.in +@@ -0,0 +1,88 @@ ++#!/bin/sh ++set -e ++ ++# Evaluate new-kernel-pkg's configuration file. ++# Copyright (C) 2016 Free Software Foundation, Inc. ++# ++# GRUB is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# GRUB is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GRUB. If not, see . ++ ++PACKAGE_NAME=@PACKAGE_NAME@ ++PACKAGE_VERSION=@PACKAGE_VERSION@ ++datadir="@datadir@" ++if [ "x$pkgdatadir" = x ]; then ++ pkgdatadir="${datadir}/@PACKAGE@" ++fi ++ ++self=`basename $0` ++ ++export TEXTDOMAIN=@PACKAGE@ ++export TEXTDOMAINDIR="@localedir@" ++ ++. "${pkgdatadir}/grub-mkconfig_lib" ++ ++# Usage: usage ++# Print the usage. ++usage () { ++ gettext_printf "Usage: %s [OPTION]\n" "$self" ++ gettext "Evaluate new-kernel-pkg configuration"; echo ++ echo ++ print_option_help "-h, --help" "$(gettext "print this message and exit")" ++ print_option_help "-v, --version" "$(gettext "print the version information and exit")" ++ echo ++} ++ ++# Check the arguments. ++while test $# -gt 0 ++do ++ option=$1 ++ shift ++ ++ case "$option" in ++ -h | --help) ++ usage ++ exit 0 ;; ++ -v | --version) ++ echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" ++ exit 0 ;; ++ -*) ++ gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 ++ usage ++ exit 1 ++ ;; ++ # Explicitly ignore non-option arguments, for compatibility. ++ esac ++done ++ ++if test -f /etc/sysconfig/kernel ; then ++ . /etc/sysconfig/kernel ++fi ++ ++if [ "$MAKEDEBUG" = "yes" ]; then ++ echo GRUB_LINUX_MAKE_DEBUG=true ++ echo export GRUB_LINUX_MAKE_DEBUG ++ echo GRUB_CMDLINE_LINUX_DEBUG=\"systemd.log_level=debug systemd.log_target=kmsg\" ++ echo export GRUB_CMDLINE_LINUX_DEBUG ++ echo GRUB_LINUX_DEBUG_TITLE_POSTFIX=\" with debugging\" ++ echo export GRUB_LINUX_DEBUG_TITLE_POSTFIX ++fi ++if [ "$DEFAULTDEBUG" = "yes" ]; then ++ echo GRUB_DEFAULT_TO_DEBUG=true ++else ++ echo GRUB_DEFAULT_TO_DEBUG=false ++fi ++echo export GRUB_DEFAULT_TO_DEBUG ++if [ "$UPDATEDEFAULT" = "yes" ]; then ++ echo GRUB_UPDATE_DEFAULT_KERNEL=true ++ echo export GRUB_UPDATE_DEFAULT_KERNEL ++fi +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 4e7a875309e..6247a0ba850 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@" + grub_file="${bindir}/@grub_file@" + grub_editenv="${bindir}/@grub_editenv@" + grub_script_check="${bindir}/@grub_script_check@" ++grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@" + + export TEXTDOMAIN=@PACKAGE@ + export TEXTDOMAINDIR="@localedir@" +@@ -158,6 +159,8 @@ if test -f ${sysconfdir}/default/grub ; then + . ${sysconfdir}/default/grub + fi + ++eval "$("${grub_get_kernel_settings}")" || true ++ + if [ "x$GRUB_DISABLE_UUID" != "xtrue" ]; then + if [ -z "$GRUB_DEVICE_UUID" ]; then + GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED" +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 12a20c9ad73..55f4aa783cf 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -111,7 +111,8 @@ linux_entry () + os="$1" + version="$2" + type="$3" +- args="$4" ++ isdebug="$4" ++ args="$5" + + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" +@@ -123,6 +124,9 @@ linux_entry () + quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" + title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" + fi ++ if [ x$isdebug = xdebug ]; then ++ title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}" ++ fi + echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" + else + echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" +@@ -295,11 +299,15 @@ while [ "x$list" != "x" ] ; do + fi + + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then +- linux_entry "${OS}" "${version}" simple \ ++ linux_entry "${OS}" "${version}" simple standard \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ linux_entry "${OS}" "${version}" simple debug \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi + + submenu_indentation="$grub_tab" +- ++ + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi +@@ -308,10 +316,15 @@ while [ "x$list" != "x" ] ; do + is_top_level=false + fi + +- linux_entry "${OS}" "${version}" advanced \ ++ linux_entry "${OS}" "${version}" advanced standard \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ linux_entry "${OS}" "${version}" advanced debug \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi ++ + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then +- linux_entry "${OS}" "${version}" recovery \ ++ linux_entry "${OS}" "${version}" recovery standard \ + "single ${GRUB_CMDLINE_LINUX}" + fi + diff --git a/0066-Normalize-slashes-in-tftp-paths.patch b/0066-Normalize-slashes-in-tftp-paths.patch new file mode 100644 index 0000000..57f5e5e --- /dev/null +++ b/0066-Normalize-slashes-in-tftp-paths.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lenny Szubowicz +Date: Mon, 29 Aug 2016 11:04:48 -0400 +Subject: [PATCH] Normalize slashes in tftp paths. + +Some tftp servers do not handle multiple consecutive slashes correctly; +this patch avoids sending tftp requests with non-normalized paths. + +Signed-off-by: Lenny Szubowicz +[msalter: fix malformed tftp packets] +Signed-off-by: Mark Salter +--- + grub-core/net/tftp.c | 28 +++++++++++++++++++++++++--- + 1 file changed, 25 insertions(+), 3 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index a5c5038130a..e6d831f1bc9 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -300,6 +300,25 @@ destroy_pq (tftp_data_t data) + grub_priority_queue_destroy (data->pq); + } + ++/* Create a normalized copy of the filename. ++ Compress any string of consecutive forward slashes to a single forward ++ slash. */ ++static void ++grub_normalize_filename (char *normalized, const char *filename) ++{ ++ char *dest = normalized; ++ char *src = filename; ++ ++ while (*src != '\0') ++ { ++ if (src[0] == '/' && src[1] == '/') ++ src++; ++ else ++ *dest++ = *src++; ++ } ++ *dest = '\0'; ++} ++ + static grub_err_t + tftp_open (struct grub_file *file, const char *filename) + { +@@ -337,9 +356,12 @@ tftp_open (struct grub_file *file, const char *filename) + rrqlen = 0; + + tftph->opcode = grub_cpu_to_be16_compile_time (TFTP_RRQ); +- grub_strcpy (rrq, filename); +- rrqlen += grub_strlen (filename) + 1; +- rrq += grub_strlen (filename) + 1; ++ ++ /* Copy and normalize the filename to work-around issues on some tftp ++ servers when file names are being matched for remapping. */ ++ grub_normalize_filename (rrq, filename); ++ rrqlen += grub_strlen (rrq) + 1; ++ rrq += grub_strlen (rrq) + 1; + + grub_strcpy (rrq, "octet"); + rrqlen += grub_strlen ("octet") + 1; diff --git a/0067-bz1374141-fix-incorrect-mask-for-ppc64.patch b/0067-bz1374141-fix-incorrect-mask-for-ppc64.patch new file mode 100644 index 0000000..1bb2658 --- /dev/null +++ b/0067-bz1374141-fix-incorrect-mask-for-ppc64.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Masahiro Matsuya +Date: Sat, 29 Oct 2016 08:35:26 +0900 +Subject: [PATCH] bz1374141 fix incorrect mask for ppc64 + +The netmask configured in firmware is not respected on ppc64 (big endian). +When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath(). + + /vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512 + +The netmask in this bootpath is no problem, since it's a value specified in firmware. But, +The value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22). +As a result, 16 was used for netmask wrongly. + +1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) +0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) +1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4) + +And, the count of zero with __builtin_ctz can be 16. +This patch changes it as below. + +1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) +0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) +1111 1111 1111 1111 1111 1100 0000 0000 # grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) +0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)) + +The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit) +--- + grub-core/net/drivers/ieee1275/ofnet.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c +index ac4e62a95c9..3860b6f78d8 100644 +--- a/grub-core/net/drivers/ieee1275/ofnet.c ++++ b/grub-core/net/drivers/ieee1275/ofnet.c +@@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, + flags); + inter->vlantag = vlantag; + grub_net_add_ipv4_local (inter, +- __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4))); +- ++ __builtin_clz (~grub_swap_bytes32(grub_le_to_cpu32 (subnet_mask.ipv4)))); + } + + if (gateway_addr.ipv4 != 0) diff --git a/0068-Make-grub_fatal-also-backtrace.patch b/0068-Make-grub_fatal-also-backtrace.patch new file mode 100644 index 0000000..de1de20 --- /dev/null +++ b/0068-Make-grub_fatal-also-backtrace.patch @@ -0,0 +1,172 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 27 Jan 2016 09:22:42 -0500 +Subject: [PATCH] Make grub_fatal() also backtrace. + +--- + grub-core/Makefile.core.def | 3 ++ + grub-core/kern/misc.c | 8 +++++- + grub-core/lib/arm64/backtrace.c | 62 +++++++++++++++++++++++++++++++++++++++++ + grub-core/lib/backtrace.c | 2 ++ + grub-core/lib/i386/backtrace.c | 14 +++++++++- + 5 files changed, 87 insertions(+), 2 deletions(-) + create mode 100644 grub-core/lib/arm64/backtrace.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 99466b1e47e..ebc558019cd 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -186,6 +186,9 @@ kernel = { + + softdiv = lib/division.c; + ++ x86 = lib/i386/backtrace.c; ++ x86 = lib/backtrace.c; ++ + i386 = kern/i386/dl.c; + i386_xen = kern/i386/dl.c; + i386_xen_pvh = kern/i386/dl.c; +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 1c560ea570a..04371ac49f2 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + union printf_arg + { +@@ -1101,8 +1102,13 @@ grub_xasprintf (const char *fmt, ...) + static void __attribute__ ((noreturn)) + grub_abort (void) + { ++#ifndef GRUB_UTIL ++#if defined(__i386__) || defined(__x86_64__) ++ grub_backtrace(); ++#endif ++#endif + grub_printf ("\nAborted."); +- ++ + #ifndef GRUB_UTIL + if (grub_term_inputs) + #endif +diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c +new file mode 100644 +index 00000000000..1079b5380e1 +--- /dev/null ++++ b/grub-core/lib/arm64/backtrace.c +@@ -0,0 +1,62 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2009 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define MAX_STACK_FRAME 102400 ++ ++void ++grub_backtrace_pointer (int frame) ++{ ++ while (1) ++ { ++ void *lp = __builtin_return_address (frame); ++ if (!lp) ++ break; ++ ++ lp = __builtin_extract_return_addr (lp); ++ ++ grub_printf ("%p: ", lp); ++ grub_backtrace_print_address (lp); ++ grub_printf (" ("); ++ for (i = 0; i < 2; i++) ++ grub_printf ("%p,", ((void **)ptr) [i + 2]); ++ grub_printf ("%p)\n", ((void **)ptr) [i + 2]); ++ nptr = *(void **)ptr; ++ if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME ++ || nptr == ptr) ++ { ++ grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr); ++ break; ++ } ++ ptr = nptr; ++ } ++} ++ ++void ++grub_backtrace (void) ++{ ++ grub_backtrace_pointer (1); ++} ++ +diff --git a/grub-core/lib/backtrace.c b/grub-core/lib/backtrace.c +index 825a8800e25..c0ad6ab8be1 100644 +--- a/grub-core/lib/backtrace.c ++++ b/grub-core/lib/backtrace.c +@@ -29,6 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + void + grub_backtrace_print_address (void *addr) + { ++#ifndef GRUB_UTIL + grub_dl_t mod; + + FOR_DL_MODULES (mod) +@@ -44,6 +45,7 @@ grub_backtrace_print_address (void *addr) + } + } + ++#endif + grub_printf ("%p", addr); + } + +diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c +index c3e03c7275c..c67273db3ae 100644 +--- a/grub-core/lib/i386/backtrace.c ++++ b/grub-core/lib/i386/backtrace.c +@@ -15,11 +15,23 @@ + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ ++#include ++#ifdef GRUB_UTIL ++#define REALLY_GRUB_UTIL GRUB_UTIL ++#undef GRUB_UTIL ++#endif ++ ++#include ++#include ++ ++#ifdef REALLY_GRUB_UTIL ++#define GRUB_UTIL REALLY_GRUB_UTIL ++#undef REALLY_GRUB_UTIL ++#endif + + #include + #include + #include +-#include + #include + #include + #include diff --git a/0069-Fix-up-some-man-pages-rpmdiff-noticed.patch b/0069-Fix-up-some-man-pages-rpmdiff-noticed.patch new file mode 100644 index 0000000..80257e3 --- /dev/null +++ b/0069-Fix-up-some-man-pages-rpmdiff-noticed.patch @@ -0,0 +1,150 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 23 Sep 2014 09:58:49 -0400 +Subject: [PATCH] Fix up some man pages rpmdiff noticed. + +--- + configure.ac | 2 ++ + util/grub-macbless.8 | 26 +++++++++++++++++++ + util/grub-mkimage.1 | 2 +- + util/grub-syslinux2cfg.1 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 94 insertions(+), 1 deletion(-) + create mode 100644 util/grub-macbless.8 + create mode 100644 util/grub-syslinux2cfg.1 + +diff --git a/configure.ac b/configure.ac +index fc3c2b44d60..eb851b8d722 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -84,6 +84,7 @@ grub_TRANSFORM([grub-get-kernel-settings.3]) + grub_TRANSFORM([grub-glue-efi.3]) + grub_TRANSFORM([grub-install.1]) + grub_TRANSFORM([grub-kbdcomp.3]) ++grub_TRANSFORM([grub-macbless.8]) + grub_TRANSFORM([grub-menulst2cfg.1]) + grub_TRANSFORM([grub-mkconfig.1]) + grub_TRANSFORM([grub-mkfont.3]) +@@ -102,6 +103,7 @@ grub_TRANSFORM([grub-render-label.3]) + grub_TRANSFORM([grub-script-check.3]) + grub_TRANSFORM([grub-set-default.1]) + grub_TRANSFORM([grub-sparc64-setup.3]) ++grub_TRANSFORM([grub-syslinux2cfg.1]) + + # Optimization flag. Allow user to override. + if test "x$TARGET_CFLAGS" = x; then +diff --git a/util/grub-macbless.8 b/util/grub-macbless.8 +new file mode 100644 +index 00000000000..ae842f3a606 +--- /dev/null ++++ b/util/grub-macbless.8 +@@ -0,0 +1,26 @@ ++.TH GRUB-MACBLESS 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-macbless\fR \(em Mac-style bless utility for HFS or HFS+ ++ ++.SH SYNOPSIS ++\fBgrub-macbless\fR [-p | --ppc] [-v | --verbose] [-x | --x86] \fIFILE\fR ++ ++.SH DESCRIPTION ++\fBgrub-mkimage\fR blesses a file on an HFS or HFS+ file system, so that it ++can be used to boot a Mac. ++ ++.SH OPTIONS ++.TP ++--ppc ++Bless the file for use on PPC-based Macs. ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.TP ++--x86 ++Bless the file for use on x86-based Macs. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-mkimage.1 b/util/grub-mkimage.1 +index 4dea4f54597..0eaaafe505b 100644 +--- a/util/grub-mkimage.1 ++++ b/util/grub-mkimage.1 +@@ -17,7 +17,7 @@ + [-v | --verbose] \fIMODULES\fR + + .SH DESCRIPTION +-\fBgrub-mkimage\fI builds a bootable image of GRUB. ++\fBgrub-mkimage\fR builds a bootable image of GRUB. + + .SH OPTIONS + .TP +diff --git a/util/grub-syslinux2cfg.1 b/util/grub-syslinux2cfg.1 +new file mode 100644 +index 00000000000..85309482718 +--- /dev/null ++++ b/util/grub-syslinux2cfg.1 +@@ -0,0 +1,65 @@ ++.TH GRUB-SYSLINUX2CFG 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-syslinux2cfg\fR \(em Transform a syslinux config file into a GRUB config. ++ ++.SH SYNOPSIS ++\fBgrub-syslinux2cfg\fR [-c | --cwd=\fRDIR\fI] [-r | --root=\fIDIR\fR] [-v | --verbose] ++.RE ++.RS 25 ++[-t | --target-root=\fIDIR\fR] [-T | --target-cwd=\fIDIR\fR] ++.RE ++.RS 25 ++[-o | --output=\fIFILE\fR] [[-i | --isolinux] | ++.RE ++.RS 46 ++ [-s | --syslinux] | ++.RE ++.RS 46 ++ [-p | --pxelinux]] \fIFILE\fR ++ ++.SH DESCRIPTION ++\fBgrub-syslinux2cfg\fR builds a GRUB configuration file out of an existing ++syslinux configuration file. ++ ++.SH OPTIONS ++.TP ++--cwd=\fIDIR\fR ++Set \fIDIR\fR as syslinux's working directory. The default is to use the ++parent directory of the input file. ++ ++.TP ++--root=\fIDIR\fR ++Set \fIDIR\fR as the root directory of the syslinux disk. The default value ++is "/". ++ ++.TP ++--verbose ++Print verbose messages. ++ ++.TP ++--target-root=\fIDIR\fR ++Root directory as it will be seen at runtime. The default value is "/". ++ ++.TP ++--target-cwd=\fIDIR\fR ++Working directory of syslinux as it will be seen at runtime. The default ++value is the parent directory of the input file. ++ ++.TP ++--output=\fIFILE\fR ++Write the new config file to \fIFILE\fR. The default value is standard output. ++ ++.TP ++--isolinux ++Assume that the input file is an isolinux configuration file. ++ ++.TP ++--pxelinux ++Assume that the input file is a pxelinux configuration file. ++ ++.TP ++--syslinux ++Assume that the input file is a syslinux configuration file. ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch b/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch new file mode 100644 index 0000000..f0e491e --- /dev/null +++ b/0070-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Mark Salter +Date: Mon, 17 Apr 2017 08:44:29 -0400 +Subject: [PATCH] arm64: make sure fdt has #address-cells and #size-cells + properties + +Recent upstream changes to kexec-tools relies on #address-cells +and #size-cells properties in the FDT. If grub2 needs to create +a chosen node, it is likely because firmware did not provide one. +In that case, set #address-cells and #size-cells properties to +make sure they exist. +--- + grub-core/loader/arm64/linux.c | 16 +++++++++++++++- + 1 file changed, 15 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index 04994d5c67d..4c0a09c06de 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -81,7 +81,21 @@ finalize_params_linux (void) + + node = grub_fdt_find_subnode (fdt, 0, "chosen"); + if (node < 0) +- node = grub_fdt_add_subnode (fdt, 0, "chosen"); ++ { ++ /* ++ * If we have to create a chosen node, Make sure we ++ * have #address-cells and #size-cells properties. ++ */ ++ retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2); ++ if (retval) ++ goto failure; ++ ++ retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2); ++ if (retval) ++ goto failure; ++ ++ node = grub_fdt_add_subnode (fdt, 0, "chosen"); ++ } + + if (node < 1) + goto failure; diff --git a/0071-Make-our-info-pages-say-grub2-where-appropriate.patch b/0071-Make-our-info-pages-say-grub2-where-appropriate.patch new file mode 100644 index 0000000..eea4e6f --- /dev/null +++ b/0071-Make-our-info-pages-say-grub2-where-appropriate.patch @@ -0,0 +1,1013 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jul 2019 12:59:58 +0200 +Subject: [PATCH] Make our info pages say "grub2" where appropriate. + +This needs to be hooked up to --program-transform=, but I haven't had +time. + +Signed-off-by: Peter Jones +--- + docs/grub-dev.texi | 4 +- + docs/grub.texi | 318 ++++++++++++++++++++++++++--------------------------- + 2 files changed, 161 insertions(+), 161 deletions(-) + +diff --git a/docs/grub-dev.texi b/docs/grub-dev.texi +index ee389fd83c3..e3fed7312a3 100644 +--- a/docs/grub-dev.texi ++++ b/docs/grub-dev.texi +@@ -1,7 +1,7 @@ + \input texinfo + @c -*-texinfo-*- + @c %**start of header +-@setfilename grub-dev.info ++@setfilename grub2-dev.info + @include version-dev.texi + @settitle GNU GRUB Developers Manual @value{VERSION} + @c Unify all our little indices for now. +@@ -32,7 +32,7 @@ Invariant Sections. + + @dircategory Kernel + @direntry +-* grub-dev: (grub-dev). The GRand Unified Bootloader Dev ++* grub2-dev: (grub2-dev). The GRand Unified Bootloader Dev + @end direntry + + @setchapternewpage odd +diff --git a/docs/grub.texi b/docs/grub.texi +index 221064b5679..960e5f3ba41 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -1,7 +1,7 @@ + \input texinfo + @c -*-texinfo-*- + @c %**start of header +-@setfilename grub.info ++@setfilename grub2.info + @include version.texi + @settitle GNU GRUB Manual @value{VERSION} + @c Unify all our little indices for now. +@@ -32,15 +32,15 @@ Invariant Sections. + + @dircategory Kernel + @direntry +-* GRUB: (grub). The GRand Unified Bootloader +-* grub-install: (grub)Invoking grub-install. Install GRUB on your drive +-* grub-mkconfig: (grub)Invoking grub-mkconfig. Generate GRUB configuration +-* grub-mkpasswd-pbkdf2: (grub)Invoking grub-mkpasswd-pbkdf2. +-* grub-mkrelpath: (grub)Invoking grub-mkrelpath. +-* grub-mkrescue: (grub)Invoking grub-mkrescue. Make a GRUB rescue image +-* grub-mount: (grub)Invoking grub-mount. Mount a file system using GRUB +-* grub-probe: (grub)Invoking grub-probe. Probe device information +-* grub-script-check: (grub)Invoking grub-script-check. ++* GRUB2: (grub2). The GRand Unified Bootloader ++* grub2-install: (grub2)Invoking grub2-install. Install GRUB on your drive ++* grub2-mkconfig: (grub2)Invoking grub2-mkconfig. Generate GRUB configuration ++* grub2-mkpasswd-pbkdf2: (grub2)Invoking grub2-mkpasswd-pbkdf2. ++* grub2-mkrelpath: (grub2)Invoking grub2-mkrelpath. ++* grub2-mkrescue: (grub2)Invoking grub2-mkrescue. Make a GRUB rescue image ++* grub2-mount: (grub2)Invoking grub2-mount. Mount a file system using GRUB ++* grub2-probe: (grub2)Invoking grub2-probe. Probe device information ++* grub2-script-check: (grub2)Invoking grub2-script-check. + @end direntry + + @setchapternewpage odd +@@ -103,15 +103,15 @@ This edition documents version @value{VERSION}. + * Platform-specific operations:: Platform-specific operations + * Supported kernels:: The list of supported kernels + * Troubleshooting:: Error messages produced by GRUB +-* Invoking grub-install:: How to use the GRUB installer +-* Invoking grub-mkconfig:: Generate a GRUB configuration file +-* Invoking grub-mkpasswd-pbkdf2:: ++* Invoking grub2-install:: How to use the GRUB installer ++* Invoking grub2-mkconfig:: Generate a GRUB configuration file ++* Invoking grub2-mkpasswd-pbkdf2:: + Generate GRUB password hashes +-* Invoking grub-mkrelpath:: Make system path relative to its root +-* Invoking grub-mkrescue:: Make a GRUB rescue image +-* Invoking grub-mount:: Mount a file system using GRUB +-* Invoking grub-probe:: Probe device information for GRUB +-* Invoking grub-script-check:: Check GRUB script file for syntax errors ++* Invoking grub2-mkrelpath:: Make system path relative to its root ++* Invoking grub2-mkrescue:: Make a GRUB rescue image ++* Invoking grub2-mount:: Mount a file system using GRUB ++* Invoking grub2-probe:: Probe device information for GRUB ++* Invoking grub2-script-check:: Check GRUB script file for syntax errors + * Obtaining and Building GRUB:: How to obtain and build GRUB + * Reporting bugs:: Where you should send a bug report + * Future:: Some future plans on GRUB +@@ -230,7 +230,7 @@ surprising. + + @item + @file{grub.cfg} is typically automatically generated by +-@command{grub-mkconfig} (@pxref{Simple configuration}). This makes it ++@command{grub2-mkconfig} (@pxref{Simple configuration}). This makes it + easier to handle versioned kernel upgrades. + + @item +@@ -244,7 +244,7 @@ scripting language: variables, conditionals, and loops are available. + @item + A small amount of persistent storage is available across reboots, using the + @command{save_env} and @command{load_env} commands in GRUB and the +-@command{grub-editenv} utility. This is not available in all configurations ++@command{grub2-editenv} utility. This is not available in all configurations + (@pxref{Environment block}). + + @item +@@ -549,7 +549,7 @@ On OS which have device nodes similar to Unix-like OS GRUB tools use the + OS name. E.g. for GNU/Linux: + + @example +-# @kbd{grub-install /dev/sda} ++# @kbd{grub2-install /dev/sda} + @end example + + On AROS we use another syntax. For volumes: +@@ -572,7 +572,7 @@ For disks we use syntax: + E.g. + + @example +-# @kbd{grub-install //:ata.device/0/0} ++# @kbd{grub2-install //:ata.device/0/0} + @end example + + On Windows we use UNC path. For volumes it's typically +@@ -599,7 +599,7 @@ For disks it's + E.g. + + @example +-# @kbd{grub-install \\?\PhysicalDrive0} ++# @kbd{grub2-install \\?\PhysicalDrive0} + @end example + + Beware that you may need to further escape the backslashes depending on your +@@ -609,7 +609,7 @@ When compiled with cygwin support then cygwin drive names are automatically + when needed. E.g. + + @example +-# @kbd{grub-install /dev/sda} ++# @kbd{grub2-install /dev/sda} + @end example + + @node Installation +@@ -622,7 +622,7 @@ from the source tarball, or as a package for your OS. + + After you have done that, you need to install the boot loader on a + drive (floppy or hard disk) by using the utility +-@command{grub-install} (@pxref{Invoking grub-install}) on a UNIX-like OS. ++@command{grub2-install} (@pxref{Invoking grub2-install}) on a UNIX-like OS. + + GRUB comes with boot images, which are normally put in the directory + @file{/usr/lib/grub/-} (for BIOS-based machines +@@ -633,22 +633,22 @@ loader needs to find them (usually @file{/boot}) will be called + the @dfn{boot directory}. + + @menu +-* Installing GRUB using grub-install:: ++* Installing GRUB using grub2-install:: + * Making a GRUB bootable CD-ROM:: + * Device map:: + * BIOS installation:: + @end menu + + +-@node Installing GRUB using grub-install +-@section Installing GRUB using grub-install ++@node Installing GRUB using grub2-install ++@section Installing GRUB using grub2-install + + For information on where GRUB should be installed on PC BIOS platforms, + @pxref{BIOS installation}. + + In order to install GRUB under a UNIX-like OS (such +-as @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invoking +-grub-install}) as the superuser (@dfn{root}). ++as @sc{gnu}), invoke the program @command{grub2-install} (@pxref{Invoking ++grub2-install}) as the superuser (@dfn{root}). + + The usage is basically very simple. You only need to specify one + argument to the program, namely, where to install the boot loader. The +@@ -657,13 +657,13 @@ For example, under Linux the following will install GRUB into the MBR + of the first IDE disk: + + @example +-# @kbd{grub-install /dev/sda} ++# @kbd{grub2-install /dev/sda} + @end example + + Likewise, under GNU/Hurd, this has the same effect: + + @example +-# @kbd{grub-install /dev/hd0} ++# @kbd{grub2-install /dev/hd0} + @end example + + But all the above examples assume that GRUB should put images under +@@ -677,7 +677,7 @@ boot floppy with a filesystem. Here is an example: + # @kbd{mke2fs /dev/fd0} + # @kbd{mount -t ext2 /dev/fd0 /mnt} + # @kbd{mkdir /mnt/boot} +-# @kbd{grub-install --boot-directory=/mnt/boot /dev/fd0} ++# @kbd{grub2-install --boot-directory=/mnt/boot /dev/fd0} + # @kbd{umount /mnt} + @end group + @end example +@@ -689,16 +689,16 @@ floppy instead of exposing the USB drive as a hard disk (they call it + @example + # @kbd{losetup /dev/loop0 /dev/sdb1} + # @kbd{mount /dev/loop0 /mnt/usb} +-# @kbd{grub-install --boot-directory=/mnt/usb/bugbios --force --allow-floppy /dev/loop0} ++# @kbd{grub2-install --boot-directory=/mnt/usb/bugbios --force --allow-floppy /dev/loop0} + @end example + + This install doesn't conflict with standard install as long as they are in + separate directories. + +-Note that @command{grub-install} is actually just a shell script and the +-real task is done by other tools such as @command{grub-mkimage}. Therefore, ++Note that @command{grub2-install} is actually just a shell script and the ++real task is done by other tools such as @command{grub2-mkimage}. Therefore, + you may run those commands directly to install GRUB, without using +-@command{grub-install}. Don't do that, however, unless you are very familiar ++@command{grub2-install}. Don't do that, however, unless you are very familiar + with the internals of GRUB. Installing a boot loader on a running OS may be + extremely dangerous. + +@@ -706,20 +706,20 @@ On EFI systems for fixed disk install you have to mount EFI System Partition. + If you mount it at @file{/boot/efi} then you don't need any special arguments: + + @example +-# @kbd{grub-install} ++# @kbd{grub2-install} + @end example + + Otherwise you need to specify where your EFI System partition is mounted: + + @example +-# @kbd{grub-install --efi-directory=/mnt/efi} ++# @kbd{grub2-install --efi-directory=/mnt/efi} + @end example + + For removable installs you have to use @option{--removable} and specify both + @option{--boot-directory} and @option{--efi-directory}: + + @example +-# @kbd{grub-install --efi-directory=/mnt/usb --boot-directory=/mnt/usb/boot --removable} ++# @kbd{grub2-install --efi-directory=/mnt/usb --boot-directory=/mnt/usb/boot --removable} + @end example + + @node Making a GRUB bootable CD-ROM +@@ -739,10 +739,10 @@ usually also need to include a configuration file @file{grub.cfg} and some + other GRUB modules. + + To make a simple generic GRUB rescue CD, you can use the +-@command{grub-mkrescue} program (@pxref{Invoking grub-mkrescue}): ++@command{grub2-mkrescue} program (@pxref{Invoking grub2-mkrescue}): + + @example +-$ @kbd{grub-mkrescue -o grub.iso} ++$ @kbd{grub2-mkrescue -o grub.iso} + @end example + + You will often need to include other files in your image. To do this, first +@@ -765,7 +765,7 @@ directory @file{iso/}. + Finally, make the image: + + @example +-$ @kbd{grub-mkrescue -o grub.iso iso} ++$ @kbd{grub2-mkrescue -o grub.iso iso} + @end example + + This produces a file named @file{grub.iso}, which then can be burned +@@ -781,7 +781,7 @@ storage devices. + @node Device map + @section The map between BIOS drives and OS devices + +-If the device map file exists, the GRUB utilities (@command{grub-probe}, ++If the device map file exists, the GRUB utilities (@command{grub2-probe}, + etc.) read it to map BIOS drives to OS devices. This file consists of lines + like this: + +@@ -1225,23 +1225,23 @@ need to write the whole thing by hand. + @node Simple configuration + @section Simple configuration handling + +-The program @command{grub-mkconfig} (@pxref{Invoking grub-mkconfig}) ++The program @command{grub2-mkconfig} (@pxref{Invoking grub2-mkconfig}) + generates @file{grub.cfg} files suitable for most cases. It is suitable for + use when upgrading a distribution, and will discover available kernels and + attempt to generate menu entries for them. + +-@command{grub-mkconfig} does have some limitations. While adding extra ++@command{grub2-mkconfig} does have some limitations. While adding extra + custom menu entries to the end of the list can be done by editing +-@file{/etc/grub.d/40_custom} or creating @file{/boot/grub/custom.cfg}, ++@file{/etc/grub.d/40_custom} or creating @file{/boot/grub2/custom.cfg}, + changing the order of menu entries or changing their titles may require + making complex changes to shell scripts stored in @file{/etc/grub.d/}. This + may be improved in the future. In the meantime, those who feel that it + would be easier to write @file{grub.cfg} directly are encouraged to do so + (@pxref{Booting}, and @ref{Shell-like scripting}), and to disable any system +-provided by their distribution to automatically run @command{grub-mkconfig}. ++provided by their distribution to automatically run @command{grub2-mkconfig}. + + The file @file{/etc/default/grub} controls the operation of +-@command{grub-mkconfig}. It is sourced by a shell script, and so must be ++@command{grub2-mkconfig}. It is sourced by a shell script, and so must be + valid POSIX shell input; normally, it will just be a sequence of + @samp{KEY=value} lines, but if the value contains spaces or other special + characters then it must be quoted. For example: +@@ -1279,7 +1279,7 @@ works it's not recommended since titles often contain unstable device names + and may be translated + + If you set this to @samp{saved}, then the default menu entry will be that +-saved by @samp{GRUB_SAVEDEFAULT} or @command{grub-set-default}. This relies on ++saved by @samp{GRUB_SAVEDEFAULT} or @command{grub2-set-default}. This relies on + the environment block, which may not be available in all situations + (@pxref{Environment block}). + +@@ -1290,7 +1290,7 @@ If this option is set to @samp{true}, then, when an entry is selected, save + it as a new default entry for use by future runs of GRUB. This is only + useful if @samp{GRUB_DEFAULT=saved}; it is a separate option because + @samp{GRUB_DEFAULT=saved} is useful without this option, in conjunction with +-@command{grub-set-default}. Unset by default. ++@command{grub2-set-default}. Unset by default. + This option relies on the environment block, which may not be available in + all situations (@pxref{Environment block}). + +@@ -1420,7 +1420,7 @@ intel-uc.img intel-ucode.img amd-uc.img amd-ucode.img early_ucode.cpio microcode + @end example + + @item GRUB_DISABLE_LINUX_UUID +-Normally, @command{grub-mkconfig} will generate menu entries that use ++Normally, @command{grub2-mkconfig} will generate menu entries that use + universally-unique identifiers (UUIDs) to identify the root filesystem to + the Linux kernel, using a @samp{root=UUID=...} kernel parameter. This is + usually more reliable, but in some cases it may not be appropriate. To +@@ -1442,7 +1442,7 @@ If this option is set to @samp{true}, disable the generation of recovery + mode menu entries. + + @item GRUB_DISABLE_UUID +-Normally, @command{grub-mkconfig} will generate menu entries that use ++Normally, @command{grub2-mkconfig} will generate menu entries that use + universally-unique identifiers (UUIDs) to identify various filesystems to + search for files. This is usually more reliable, but in some cases it may + not be appropriate. To disable this use of UUIDs, set this option to +@@ -1451,12 +1451,12 @@ not be appropriate. To disable this use of UUIDs, set this option to + @item GRUB_VIDEO_BACKEND + If graphical video support is required, either because the @samp{gfxterm} + graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, +-then @command{grub-mkconfig} will normally load all available GRUB video ++then @command{grub2-mkconfig} will normally load all available GRUB video + drivers and use the one most appropriate for your hardware. If you need to + override this for some reason, then you can set this option. + +-After @command{grub-install} has been run, the available video drivers are +-listed in @file{/boot/grub/video.lst}. ++After @command{grub2-install} has been run, the available video drivers are ++listed in @file{/boot/grub2/video.lst}. + + @item GRUB_GFXMODE + Set the resolution used on the @samp{gfxterm} graphical terminal. Note that +@@ -1488,7 +1488,7 @@ boot sequence. If you have problems, set this option to @samp{text} and + GRUB will tell Linux to boot in normal text mode. + + @item GRUB_DISABLE_OS_PROBER +-Normally, @command{grub-mkconfig} will try to use the external ++Normally, @command{grub2-mkconfig} will try to use the external + @command{os-prober} program, if installed, to discover other operating + systems installed on the same system and generate appropriate menu entries + for them. Set this option to @samp{true} to disable this. +@@ -1498,7 +1498,7 @@ List of space-separated FS UUIDs of filesystems to be ignored from os-prober + output. For efi chainloaders it's @@ + + @item GRUB_DISABLE_SUBMENU +-Normally, @command{grub-mkconfig} will generate top level menu entry for ++Normally, @command{grub2-mkconfig} will generate top level menu entry for + the kernel with highest version number and put all other found kernels + or alternative menu entries for recovery mode in submenu. For entries returned + by @command{os-prober} first entry will be put on top level and all others +@@ -1506,11 +1506,11 @@ in submenu. If this option is set to @samp{y}, flat menu with all entries + on top level will be generated instead. Changing this option will require + changing existing values of @samp{GRUB_DEFAULT}, @samp{fallback} (@pxref{fallback}) + and @samp{default} (@pxref{default}) environment variables as well as saved +-default entry using @command{grub-set-default} and value used with +-@command{grub-reboot}. ++default entry using @command{grub2-set-default} and value used with ++@command{grub2-reboot}. + + @item GRUB_ENABLE_CRYPTODISK +-If set to @samp{y}, @command{grub-mkconfig} and @command{grub-install} will ++If set to @samp{y}, @command{grub2-mkconfig} and @command{grub2-install} will + check for encrypted disks and generate additional commands needed to access + them during boot. Note that in this case unattended boot is not possible + because GRUB will wait for passphrase to unlock encrypted container. +@@ -1569,7 +1569,7 @@ confusing @samp{GRUB_TIMEOUT_STYLE=countdown} or + + @end table + +-For more detailed customisation of @command{grub-mkconfig}'s output, you may ++For more detailed customisation of @command{grub2-mkconfig}'s output, you may + edit the scripts in @file{/etc/grub.d} directly. + @file{/etc/grub.d/40_custom} is particularly useful for adding entire custom + menu entries; simply type the menu entries you want to add at the end of +@@ -1831,7 +1831,7 @@ images as well. + Mount this partition on/mnt/boot and disable GRUB in all OSes and manually + install self-compiled latest GRUB with: + +-@code{grub-install --boot-directory=/mnt/boot /dev/sda} ++@code{grub2-install --boot-directory=/mnt/boot /dev/sda} + + In all the OSes install GRUB tools but disable installing GRUB in bootsector, + so you'll have menu.lst and grub.cfg available for use. Also disable os-prober +@@ -1841,20 +1841,20 @@ use by setting: + + in /etc/default/grub + +-Then write a grub.cfg (/mnt/boot/grub/grub.cfg): ++Then write a grub.cfg (/mnt/boot/grub2/grub.cfg): + + @example + + menuentry "OS using grub2" @{ + insmod xfs + search --set=root --label OS1 --hint hd0,msdos8 +- configfile /boot/grub/grub.cfg ++ configfile /boot/grub2/grub.cfg + @} + + menuentry "OS using grub2-legacy" @{ + insmod ext2 + search --set=root --label OS2 --hint hd0,msdos6 +- legacy_configfile /boot/grub/menu.lst ++ legacy_configfile /boot/grub2/menu.lst + @} + + menuentry "Windows XP" @{ +@@ -1917,15 +1917,15 @@ GRUB supports embedding a configuration file directly into the core image, + so that it is loaded before entering normal mode. This is useful, for + example, when it is not straightforward to find the real configuration file, + or when you need to debug problems with loading that file. +-@command{grub-install} uses this feature when it is not using BIOS disk ++@command{grub2-install} uses this feature when it is not using BIOS disk + functions or when installing to a different disk from the one containing + @file{/boot/grub}, in which case it needs to use the @command{search} + command (@pxref{search}) to find @file{/boot/grub}. + + To embed a configuration file, use the @option{-c} option to +-@command{grub-mkimage}. The file is copied into the core image, so it may ++@command{grub2-mkimage}. The file is copied into the core image, so it may + reside anywhere on the file system, and may be removed after running +-@command{grub-mkimage}. ++@command{grub2-mkimage}. + + After the embedded configuration file (if any) is executed, GRUB will load + the @samp{normal} module (@pxref{normal}), which will then read the real +@@ -1960,13 +1960,13 @@ included in the core image: + @example + @group + search.fs_label grub root +-if [ -e /boot/grub/example/test1.cfg ]; then ++if [ -e /boot/grub2/example/test1.cfg ]; then + set prefix=($root)/boot/grub +- configfile /boot/grub/example/test1.cfg ++ configfile /boot/grub2/example/test1.cfg + else +- if [ -e /boot/grub/example/test2.cfg ]; then ++ if [ -e /boot/grub2/example/test2.cfg ]; then + set prefix=($root)/boot/grub +- configfile /boot/grub/example/test2.cfg ++ configfile /boot/grub2/example/test2.cfg + else + echo "Could not find an example configuration file!" + fi +@@ -2490,7 +2490,7 @@ grub-mknetdir --net-directory=/srv/tftp --subdir=/boot/grub -d /usr/lib/grub/i38 + @end group + @end example + +-Then follow instructions printed out by grub-mknetdir on configuring your DHCP ++Then follow instructions printed out by grub2-mknetdir on configuring your DHCP + server. + + The grub.cfg file is placed in the same directory as the path output by +@@ -2675,7 +2675,7 @@ team are: + @end table + + To take full advantage of this function, install GRUB into the MBR +-(@pxref{Installing GRUB using grub-install}). ++(@pxref{Installing GRUB using grub2-install}). + + If you have a laptop which has a similar feature and not in the above list + could you figure your address and contribute? +@@ -2736,7 +2736,7 @@ bytes. + The sole function of @file{boot.img} is to read the first sector of the core + image from a local disk and jump to it. Because of the size restriction, + @file{boot.img} cannot understand any file system structure, so +-@command{grub-install} hardcodes the location of the first sector of the ++@command{grub2-install} hardcodes the location of the first sector of the + core image into @file{boot.img} when installing GRUB. + + @item diskboot.img +@@ -2766,7 +2766,7 @@ images. + + @item core.img + This is the core image of GRUB. It is built dynamically from the kernel +-image and an arbitrary list of modules by the @command{grub-mkimage} ++image and an arbitrary list of modules by the @command{grub2-mkimage} + program. Usually, it contains enough modules to access @file{/boot/grub}, + and loads everything else (including menu handling, the ability to load + target operating systems, and so on) from the file system at run-time. The +@@ -2818,7 +2818,7 @@ GRUB 2 has no single Stage 2 image. Instead, it loads modules from + In GRUB 2, images for booting from CD-ROM drives are now constructed using + @file{cdboot.img} and @file{core.img}, making sure that the core image + contains the @samp{iso9660} module. It is usually best to use the +-@command{grub-mkrescue} program for this. ++@command{grub2-mkrescue} program for this. + + @item nbgrub + There is as yet no equivalent for @file{nbgrub} in GRUB 2; it was used by +@@ -2974,8 +2974,8 @@ There are two ways to specify files, by @dfn{absolute file name} and by + + An absolute file name resembles a Unix absolute file name, using + @samp{/} for the directory separator (not @samp{\} as in DOS). One +-example is @samp{(hd0,1)/boot/grub/grub.cfg}. This means the file +-@file{/boot/grub/grub.cfg} in the first partition of the first hard ++example is @samp{(hd0,1)/boot/grub2/grub.cfg}. This means the file ++@file{/boot/grub2/grub.cfg} in the first partition of the first hard + disk. If you omit the device name in an absolute file name, GRUB uses + GRUB's @dfn{root device} implicitly. So if you set the root device to, + say, @samp{(hd1,1)} by the command @samp{set root=(hd1,1)} (@pxref{set}), +@@ -2983,8 +2983,8 @@ then @code{/boot/kernel} is the same as @code{(hd1,1)/boot/kernel}. + + On ZFS filesystem the first path component must be + @var{volume}@samp{@@}[@var{snapshot}]. +-So @samp{/rootvol@@snap-129/boot/grub/grub.cfg} refers to file +-@samp{/boot/grub/grub.cfg} in snapshot of volume @samp{rootvol} with name ++So @samp{/rootvol@@snap-129/boot/grub2/grub.cfg} refers to file ++@samp{/boot/grub2/grub.cfg} in snapshot of volume @samp{rootvol} with name + @samp{snap-129}. Trailing @samp{@@} after volume name is mandatory even if + snapshot name is omitted. + +@@ -3387,7 +3387,7 @@ The more recent release of Minix would then be identified as + @samp{other>minix>minix-3.4.0}. + + This variable is often set by @samp{GRUB_DEFAULT} (@pxref{Simple +-configuration}), @command{grub-set-default}, or @command{grub-reboot}. ++configuration}), @command{grub2-set-default}, or @command{grub2-reboot}. + + + @node fallback +@@ -3477,7 +3477,7 @@ If this variable is set, it names the language code that the + example, French would be named as @samp{fr}, and Simplified Chinese as + @samp{zh_CN}. + +-@command{grub-mkconfig} (@pxref{Simple configuration}) will try to set a ++@command{grub2-mkconfig} (@pxref{Simple configuration}) will try to set a + reasonable default for this variable based on the system locale. + + +@@ -3485,10 +3485,10 @@ reasonable default for this variable based on the system locale. + @subsection locale_dir + + If this variable is set, it names the directory where translation files may +-be found (@pxref{gettext}), usually @file{/boot/grub/locale}. Otherwise, ++be found (@pxref{gettext}), usually @file{/boot/grub2/locale}. Otherwise, + internationalization is disabled. + +-@command{grub-mkconfig} (@pxref{Simple configuration}) will set a reasonable ++@command{grub2-mkconfig} (@pxref{Simple configuration}) will set a reasonable + default for this variable if internationalization is needed and any + translation files are available. + +@@ -3606,7 +3606,7 @@ input. The default is not to pause output. + + The location of the @samp{/boot/grub} directory as an absolute file name + (@pxref{File name syntax}). This is normally set by GRUB at startup based +-on information provided by @command{grub-install}. GRUB modules are ++on information provided by @command{grub2-install}. GRUB modules are + dynamically loaded from this directory, so it must be set correctly in order + for many parts of GRUB to work. + +@@ -3697,17 +3697,17 @@ GRUB provides an ``environment block'' which can be used to save a small + amount of state. + + The environment block is a preallocated 1024-byte file, which normally lives +-in @file{/boot/grub/grubenv} (although you should not assume this). At boot ++in @file{/boot/grub2/grubenv} (although you should not assume this). At boot + time, the @command{load_env} command (@pxref{load_env}) loads environment + variables from it, and the @command{save_env} (@pxref{save_env}) command + saves environment variables to it. From a running system, the +-@command{grub-editenv} utility can be used to edit the environment block. ++@command{grub2-editenv} utility can be used to edit the environment block. + + For safety reasons, this storage is only available when installed on a plain + disk (no LVM or RAID), using a non-checksumming filesystem (no ZFS), and + using BIOS or EFI functions (no ATA, USB or IEEE1275). + +-@command{grub-mkconfig} uses this facility to implement ++@command{grub2-mkconfig} uses this facility to implement + @samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}). + + +@@ -4398,7 +4398,7 @@ Translate @var{string} into the current language. + + The current language code is stored in the @samp{lang} variable in GRUB's + environment (@pxref{lang}). Translation files in MO format are read from +-@samp{locale_dir} (@pxref{locale_dir}), usually @file{/boot/grub/locale}. ++@samp{locale_dir} (@pxref{locale_dir}), usually @file{/boot/grub2/locale}. + @end deffn + + +@@ -4793,7 +4793,7 @@ Define a user named @var{user} with password @var{clear-password}. + + @deffn Command password_pbkdf2 user hashed-password + Define a user named @var{user} with password hash @var{hashed-password}. +-Use @command{grub-mkpasswd-pbkdf2} (@pxref{Invoking grub-mkpasswd-pbkdf2}) ++Use @command{grub2-mkpasswd-pbkdf2} (@pxref{Invoking grub2-mkpasswd-pbkdf2}) + to generate password hashes. @xref{Security}. + @end deffn + +@@ -5651,8 +5651,8 @@ The @samp{password} (@pxref{password}) and @samp{password_pbkdf2} + which has an associated password. @samp{password} sets the password in + plain text, requiring @file{grub.cfg} to be secure; @samp{password_pbkdf2} + sets the password hashed using the Password-Based Key Derivation Function +-(RFC 2898), requiring the use of @command{grub-mkpasswd-pbkdf2} +-(@pxref{Invoking grub-mkpasswd-pbkdf2}) to generate password hashes. ++(RFC 2898), requiring the use of @command{grub2-mkpasswd-pbkdf2} ++(@pxref{Invoking grub2-mkpasswd-pbkdf2}) to generate password hashes. + + In order to enable authentication support, the @samp{superusers} environment + variable must be set to a list of usernames, separated by any of spaces, +@@ -5696,7 +5696,7 @@ menuentry "May be run by user1 or a superuser" --users user1 @{ + @end group + @end example + +-The @command{grub-mkconfig} program does not yet have built-in support for ++The @command{grub2-mkconfig} program does not yet have built-in support for + generating configuration files with authentication. You can use + @file{/etc/grub.d/40_custom} to add simple superuser authentication, by + adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2} +@@ -5721,15 +5721,15 @@ verified with a public key currently trusted by GRUB + validation fails, then file @file{foo} cannot be opened. This failure + may halt or otherwise impact the boot process. + +-@comment Unfortunately --pubkey is not yet supported by grub-install, +-@comment but we should not bring up internal detail grub-mkimage here ++@comment Unfortunately --pubkey is not yet supported by grub2-install, ++@comment but we should not bring up internal detail grub2-mkimage here + @comment in the user guide (as opposed to developer's manual). + + @comment An initial trusted public key can be embedded within the GRUB + @comment @file{core.img} using the @code{--pubkey} option to +-@comment @command{grub-mkimage} (@pxref{Invoking grub-install}). Presently it +-@comment is necessary to write a custom wrapper around @command{grub-mkimage} +-@comment using the @code{--grub-mkimage} flag to @command{grub-install}. ++@comment @command{grub2-mkimage} (@pxref{Invoking grub2-install}). Presently it ++@comment is necessary to write a custom wrapper around @command{grub2-mkimage} ++@comment using the @code{--grub-mkimage} flag to @command{grub2-install}. + + GRUB uses GPG-style detached signatures (meaning that a file + @file{foo.sig} will be produced when file @file{foo} is signed), and +@@ -5749,8 +5749,8 @@ gpg --detach-sign /path/to/file + For successful validation of all of GRUB's subcomponents and the + loaded OS kernel, they must all be signed. One way to accomplish this + is the following (after having already produced the desired +-@file{grub.cfg} file, e.g., by running @command{grub-mkconfig} +-(@pxref{Invoking grub-mkconfig}): ++@file{grub.cfg} file, e.g., by running @command{grub2-mkconfig} ++(@pxref{Invoking grub2-mkconfig}): + + @example + @group +@@ -5772,7 +5772,7 @@ See also: @ref{check_signatures}, @ref{verify_detached}, @ref{trust}, + Note that internally signature enforcement is controlled by setting + the environment variable @code{check_signatures} equal to + @code{enforce}. Passing one or more @code{--pubkey} options to +-@command{grub-mkimage} implicitly defines @code{check_signatures} ++@command{grub2-mkimage} implicitly defines @code{check_signatures} + equal to @code{enforce} in @file{core.img} prior to processing any + configuration files. + +@@ -6189,10 +6189,10 @@ Required files are: + + GRUB's normal start-up procedure involves setting the @samp{prefix} + environment variable to a value set in the core image by +-@command{grub-install}, setting the @samp{root} variable to match, loading ++@command{grub2-install}, setting the @samp{root} variable to match, loading + the @samp{normal} module from the prefix, and running the @samp{normal} + command (@pxref{normal}). This command is responsible for reading +-@file{/boot/grub/grub.cfg}, running the menu, and doing all the useful ++@file{/boot/grub2/grub.cfg}, running the menu, and doing all the useful + things GRUB is supposed to do. + + If, instead, you only get a rescue shell, this usually means that GRUB +@@ -6218,8 +6218,8 @@ normal + + However, any problem that leaves you in the rescue shell probably means that + GRUB was not correctly installed. It may be more useful to try to reinstall +-it properly using @kbd{grub-install @var{device}} (@pxref{Invoking +-grub-install}). When doing this, there are a few things to remember: ++it properly using @kbd{grub2-install @var{device}} (@pxref{Invoking ++grub2-install}). When doing this, there are a few things to remember: + + @itemize @bullet{} + @item +@@ -6231,7 +6231,7 @@ is usually better to use UUIDs or file system labels and avoid depending on + drive ordering entirely. + + @item +-At least on BIOS systems, if you tell @command{grub-install} to install GRUB ++At least on BIOS systems, if you tell @command{grub2-install} to install GRUB + to a partition but GRUB has already been installed in the master boot + record, then the GRUB installation in the partition will be ignored. + +@@ -6262,21 +6262,21 @@ entry which claims partition start at block 0. This change will not hamper + bootability on other machines. + + +-@node Invoking grub-install +-@chapter Invoking grub-install ++@node Invoking grub2-install ++@chapter Invoking grub2-install + +-The program @command{grub-install} generates a GRUB core image using +-@command{grub-mkimage} and installs it on your system. You must specify the ++The program @command{grub2-install} generates a GRUB core image using ++@command{grub2-mkimage} and installs it on your system. You must specify the + device name on which you want to install GRUB, like this: + + @example +-grub-install @var{install_device} ++grub2-install @var{install_device} + @end example + + The device name @var{install_device} is an OS device name or a GRUB + device name. + +-@command{grub-install} accepts the following options: ++@command{grub2-install} accepts the following options: + + @table @option + @item --help +@@ -6292,13 +6292,13 @@ separate partition or a removable disk. + If this option is not specified then it defaults to @file{/boot}, so + + @example +-@kbd{grub-install /dev/sda} ++@kbd{grub2-install /dev/sda} + @end example + + is equivalent to + + @example +-@kbd{grub-install --boot-directory=/boot/ /dev/sda} ++@kbd{grub2-install --boot-directory=/boot/ /dev/sda} + @end example + + Here is an example in which you have a separate @dfn{boot} partition which is +@@ -6306,16 +6306,16 @@ mounted on + @file{/mnt/boot}: + + @example +-@kbd{grub-install --boot-directory=/mnt/boot /dev/sdb} ++@kbd{grub2-install --boot-directory=/mnt/boot /dev/sdb} + @end example + + @item --recheck +-Recheck the device map, even if @file{/boot/grub/device.map} already ++Recheck the device map, even if @file{/boot/grub2/device.map} already + exists. You should use this option whenever you add/remove a disk + into/from your computer. + + @item --no-rs-codes +-By default on x86 BIOS systems, @command{grub-install} will use some ++By default on x86 BIOS systems, @command{grub2-install} will use some + extra space in the bootloader embedding area for Reed-Solomon + error-correcting codes. This enables GRUB to still boot successfully + if some blocks are corrupted. The exact amount of protection offered +@@ -6328,17 +6328,17 @@ installation}) where GRUB does not reside in any unpartitioned space + outside of the MBR. Disable the Reed-Solomon codes with this option. + @end table + +-@node Invoking grub-mkconfig +-@chapter Invoking grub-mkconfig ++@node Invoking grub2-mkconfig ++@chapter Invoking grub2-mkconfig + +-The program @command{grub-mkconfig} generates a configuration file for GRUB ++The program @command{grub2-mkconfig} generates a configuration file for GRUB + (@pxref{Simple configuration}). + + @example +-grub-mkconfig -o /boot/grub/grub.cfg ++grub-mkconfig -o /boot/grub2/grub.cfg + @end example + +-@command{grub-mkconfig} accepts the following options: ++@command{grub2-mkconfig} accepts the following options: + + @table @option + @item --help +@@ -6354,17 +6354,17 @@ it to standard output. + @end table + + +-@node Invoking grub-mkpasswd-pbkdf2 +-@chapter Invoking grub-mkpasswd-pbkdf2 ++@node Invoking grub2-mkpasswd-pbkdf2 ++@chapter Invoking grub2-mkpasswd-pbkdf2 + +-The program @command{grub-mkpasswd-pbkdf2} generates password hashes for ++The program @command{grub2-mkpasswd-pbkdf2} generates password hashes for + GRUB (@pxref{Security}). + + @example + grub-mkpasswd-pbkdf2 + @end example + +-@command{grub-mkpasswd-pbkdf2} accepts the following options: ++@command{grub2-mkpasswd-pbkdf2} accepts the following options: + + @table @option + @item -c @var{number} +@@ -6382,23 +6382,23 @@ Length of the salt. Defaults to 64. + @end table + + +-@node Invoking grub-mkrelpath +-@chapter Invoking grub-mkrelpath ++@node Invoking grub2-mkrelpath ++@chapter Invoking grub2-mkrelpath + +-The program @command{grub-mkrelpath} makes a file system path relative to ++The program @command{grub2-mkrelpath} makes a file system path relative to + the root of its containing file system. For instance, if @file{/usr} is a + mount point, then: + + @example +-$ @kbd{grub-mkrelpath /usr/share/grub/unicode.pf2} ++$ @kbd{grub2-mkrelpath /usr/share/grub/unicode.pf2} + @samp{/share/grub/unicode.pf2} + @end example + + This is mainly used internally by other GRUB utilities such as +-@command{grub-mkconfig} (@pxref{Invoking grub-mkconfig}), but may ++@command{grub2-mkconfig} (@pxref{Invoking grub2-mkconfig}), but may + occasionally also be useful for debugging. + +-@command{grub-mkrelpath} accepts the following options: ++@command{grub2-mkrelpath} accepts the following options: + + @table @option + @item --help +@@ -6409,17 +6409,17 @@ Print the version number of GRUB and exit. + @end table + + +-@node Invoking grub-mkrescue +-@chapter Invoking grub-mkrescue ++@node Invoking grub2-mkrescue ++@chapter Invoking grub2-mkrescue + +-The program @command{grub-mkrescue} generates a bootable GRUB rescue image ++The program @command{grub2-mkrescue} generates a bootable GRUB rescue image + (@pxref{Making a GRUB bootable CD-ROM}). + + @example + grub-mkrescue -o grub.iso + @end example + +-All arguments not explicitly listed as @command{grub-mkrescue} options are ++All arguments not explicitly listed as @command{grub2-mkrescue} options are + passed on directly to @command{xorriso} in @command{mkisofs} emulation mode. + Options passed to @command{xorriso} will normally be interpreted as + @command{mkisofs} options; if the option @samp{--} is used, then anything +@@ -6434,7 +6434,7 @@ mkdir -p disk/boot/grub + grub-mkrescue -o grub.iso disk + @end example + +-@command{grub-mkrescue} accepts the following options: ++@command{grub2-mkrescue} accepts the following options: + + @table @option + @item --help +@@ -6462,15 +6462,15 @@ Use @var{file} as the @command{xorriso} program, rather than the built-in + default. + + @item --grub-mkimage=@var{file} +-Use @var{file} as the @command{grub-mkimage} program, rather than the ++Use @var{file} as the @command{grub2-mkimage} program, rather than the + built-in default. + @end table + + +-@node Invoking grub-mount +-@chapter Invoking grub-mount ++@node Invoking grub2-mount ++@chapter Invoking grub2-mount + +-The program @command{grub-mount} performs a read-only mount of any file ++The program @command{grub2-mount} performs a read-only mount of any file + system or file system image that GRUB understands, using GRUB's file system + drivers via FUSE. (It is only available if FUSE development files were + present when GRUB was built.) This has a number of uses: +@@ -6502,13 +6502,13 @@ even if nobody has yet written a FUSE module specifically for that file + system type. + @end itemize + +-Using @command{grub-mount} is normally as simple as: ++Using @command{grub2-mount} is normally as simple as: + + @example + grub-mount /dev/sda1 /mnt + @end example + +-@command{grub-mount} must be given one or more images and a mount point as ++@command{grub2-mount} must be given one or more images and a mount point as + non-option arguments (if it is given more than one image, it will treat them + as a RAID set), and also accepts the following options: + +@@ -6530,13 +6530,13 @@ Show debugging output for conditions matching @var{string}. + @item -K prompt|@var{file} + @itemx --zfs-key=prompt|@var{file} + Load a ZFS encryption key. If you use @samp{prompt} as the argument, +-@command{grub-mount} will read a passphrase from the terminal; otherwise, it ++@command{grub2-mount} will read a passphrase from the terminal; otherwise, it + will read key material from the specified file. + + @item -r @var{device} + @itemx --root=@var{device} + Set the GRUB root device to @var{device}. You do not normally need to set +-this; @command{grub-mount} will automatically set the root device to the ++this; @command{grub2-mount} will automatically set the root device to the + root of the supplied file system. + + If @var{device} is just a number, then it will be treated as a partition +@@ -6554,10 +6554,10 @@ Print verbose messages. + @end table + + +-@node Invoking grub-probe +-@chapter Invoking grub-probe ++@node Invoking grub2-probe ++@chapter Invoking grub2-probe + +-The program @command{grub-probe} probes device information for a given path ++The program @command{grub2-probe} probes device information for a given path + or device. + + @example +@@ -6565,7 +6565,7 @@ grub-probe --target=fs /boot/grub + grub-probe --target=drive --device /dev/sda1 + @end example + +-@command{grub-probe} must be given a path or device as a non-option ++@command{grub2-probe} must be given a path or device as a non-option + argument, and also accepts the following options: + + @table @option +@@ -6578,16 +6578,16 @@ Print the version number of GRUB and exit. + @item -d + @itemx --device + If this option is given, then the non-option argument is a system device +-name (such as @samp{/dev/sda1}), and @command{grub-probe} will print ++name (such as @samp{/dev/sda1}), and @command{grub2-probe} will print + information about that device. If it is not given, then the non-option + argument is a filesystem path (such as @samp{/boot/grub}), and +-@command{grub-probe} will print information about the device containing that ++@command{grub2-probe} will print information about the device containing that + part of the filesystem. + + @item -m @var{file} + @itemx --device-map=@var{file} + Use @var{file} as the device map (@pxref{Device map}) rather than the +-default, usually @samp{/boot/grub/device.map}. ++default, usually @samp{/boot/grub2/device.map}. + + @item -t @var{target} + @itemx --target=@var{target} +@@ -6640,19 +6640,19 @@ Print verbose messages. + @end table + + +-@node Invoking grub-script-check +-@chapter Invoking grub-script-check ++@node Invoking grub2-script-check ++@chapter Invoking grub2-script-check + +-The program @command{grub-script-check} takes a GRUB script file ++The program @command{grub2-script-check} takes a GRUB script file + (@pxref{Shell-like scripting}) and checks it for syntax errors, similar to + commands such as @command{sh -n}. It may take a @var{path} as a non-option + argument; if none is supplied, it will read from standard input. + + @example +-grub-script-check /boot/grub/grub.cfg ++grub-script-check /boot/grub2/grub.cfg + @end example + +-@command{grub-script-check} accepts the following options: ++@command{grub2-script-check} accepts the following options: + + @table @option + @item --help diff --git a/0072-print-more-debug-info-in-our-module-loader.patch b/0072-print-more-debug-info-in-our-module-loader.patch new file mode 100644 index 0000000..48f48e3 --- /dev/null +++ b/0072-print-more-debug-info-in-our-module-loader.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 1 May 2017 11:19:40 -0400 +Subject: [PATCH] print more debug info in our module loader. + +Signed-off-by: Peter Jones +--- + grub-core/kern/efi/efi.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 370ce03c5d7..a1af9b46559 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -313,13 +313,23 @@ grub_efi_modules_addr (void) + } + + if (i == coff_header->num_sections) +- return 0; ++ { ++ grub_dprintf("sections", "section %d is last section; invalid.\n", i); ++ return 0; ++ } + + info = (struct grub_module_info *) ((char *) image->image_base + + section->virtual_address); +- if (info->magic != GRUB_MODULE_MAGIC) +- return 0; ++ if (section->name[0] != '.' && info->magic != GRUB_MODULE_MAGIC) ++ { ++ grub_dprintf("sections", ++ "section %d has bad magic %08x, should be %08x\n", ++ i, info->magic, GRUB_MODULE_MAGIC); ++ return 0; ++ } + ++ grub_dprintf("sections", "returning section info for section %d: \"%s\"\n", ++ i, section->name); + return (grub_addr_t) info; + } + diff --git a/0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch b/0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch new file mode 100644 index 0000000..3a761c0 --- /dev/null +++ b/0073-macos-just-build-chainloader-entries-don-t-try-any-x.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 24 May 2017 12:42:32 -0400 +Subject: [PATCH] macos: just build chainloader entries, don't try any xnu xnu. + +Since our bugs tell us that the xnu boot entries really just don't work +most of the time, and they create piles of extra boot entries, because +they can't quite figure out 32-vs-64 and other stuff like that. + +It's rediculous, and we should just boot their bootloader through the +chainloader instead. + +So this patch does that. + +Resolves: rhbz#893179 + +Signed-off-by: Peter Jones +--- + util/grub.d/30_os-prober.in | 78 +++++++++++---------------------------------- + 1 file changed, 18 insertions(+), 60 deletions(-) + +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 9b8f5968e2d..13a3a6bc752 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -42,68 +42,25 @@ if [ -z "${OSPROBED}" ] ; then + fi + + osx_entry() { +- if [ x$2 = x32 ]; then +- # TRANSLATORS: it refers to kernel architecture (32-bit) +- bitstr="$(gettext "(32-bit)")" +- else +- # TRANSLATORS: it refers to kernel architecture (64-bit) +- bitstr="$(gettext "(64-bit)")" +- fi + # TRANSLATORS: it refers on the OS residing on device %s + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" +- cat << EOF +-menuentry '$(echo "${LONGNAME} $bitstr $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")' { ++ hints="" ++ for hint in `"${grub_probe}" --device ${device} --target=efi_hints 2> /dev/null` ; do ++ hints="${hints} --hint=${hint}" ++ done ++ cat << EOF ++menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class osx --class darwin --class os \$menuentry_id_option 'osprober-xnu-$2-$(grub_get_device_id "${DEVICE}")' { + EOF + save_default_entry | grub_add_tab + prepare_grub_to_access_device ${DEVICE} | grub_add_tab + cat << EOF ++ set gfxpayload=keep + load_video +- set do_resume=0 +- if [ /var/vm/sleepimage -nt10 / ]; then +- if xnu_resume /var/vm/sleepimage; then +- set do_resume=1 +- fi +- fi +- if [ \$do_resume = 0 ]; then +- xnu_uuid ${OSXUUID} uuid +- if [ -f /Extra/DSDT.aml ]; then +- acpi -e /Extra/DSDT.aml +- fi +- if [ /kernelcache -nt /System/Library/Extensions ]; then +- $1 /kernelcache boot-uuid=\${uuid} rd=*uuid +- elif [ -f /System/Library/Kernels/kernel ]; then +- $1 /System/Library/Kernels/kernel boot-uuid=\${uuid} rd=*uuid +- xnu_kextdir /System/Library/Extensions +- else +- $1 /mach_kernel boot-uuid=\${uuid} rd=*uuid +- if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then +- xnu_mkext /System/Library/Extensions.mkext +- else +- xnu_kextdir /System/Library/Extensions +- fi +- fi +- if [ -f /Extra/Extensions.mkext ]; then +- xnu_mkext /Extra/Extensions.mkext +- fi +- if [ -d /Extra/Extensions ]; then +- xnu_kextdir /Extra/Extensions +- fi +- if [ -f /Extra/devprop.bin ]; then +- xnu_devprop_load /Extra/devprop.bin +- fi +- if [ -f /Extra/splash.jpg ]; then +- insmod jpeg +- xnu_splash /Extra/splash.jpg +- fi +- if [ -f /Extra/splash.png ]; then +- insmod png +- xnu_splash /Extra/splash.png +- fi +- if [ -f /Extra/splash.tga ]; then +- insmod tga +- xnu_splash /Extra/splash.tga +- fi +- fi ++ insmod part_gpt ++ insmod hfsplus ++ search --no-floppy --fs-uuid --set=root ${hints} $(grub_get_device_id "${DEVICE}") ++ chainloader (\$root)/System/Library/CoreServices/boot.efi ++ boot + } + EOF + } +@@ -284,11 +241,12 @@ EOF + echo "$title_correction_code" + ;; + macosx) +- if [ "${UUID}" ]; then +- OSXUUID="${UUID}" +- osx_entry xnu_kernel 32 +- osx_entry xnu_kernel64 64 +- fi ++ for subdevice in ${DEVICE%[[:digit:]]*}* ; do ++ parttype="`"${grub_probe}" --device ${device} --target=gpt_parttype "${subdevice}" 2> /dev/null`" ++ if [[ "$parttype" = "426f6f74-0000-11aa-aa11-00306543ecac" ]]; then ++ DEVICE="${subdevice}" osx_entry ++ fi ++ done + ;; + hurd) + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" diff --git a/0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch b/0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch new file mode 100644 index 0000000..41616b0 --- /dev/null +++ b/0074-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch @@ -0,0 +1,703 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jeff Mahoney +Date: Tue, 9 Jul 2019 13:39:45 +0200 +Subject: [PATCH] grub2/btrfs: Add ability to boot from subvolumes + +This patch adds the ability to specify a different root on a btrfs +filesystem too boot from other than the default one. + +btrfs-list-snapshots will list the subvolumes available on the +filesystem. + +set btrfs_subvol= and set btrfs_subvolid= will specify +which subvolume to use and any pathnames provided with either of those +variables set will start using that root. If the subvolume or subvolume id +doesn't exist, then an error case will result. + +It is possible to boot into a separate GRUB instance by exporting the +variable and loading the config file from the subvolume. + +Signed-off-by: Jeff Mahoney +--- + grub-core/fs/btrfs.c | 552 +++++++++++++++++++++++++++++++++++++++++++++++++-- + include/grub/btrfs.h | 1 + + 2 files changed, 533 insertions(+), 20 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 48bd3d04a5e..6823d9765c4 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -38,6 +38,9 @@ + #include + #include + #include ++#include ++#include ++#include + #include + #include + +@@ -78,9 +81,11 @@ struct grub_btrfs_superblock + grub_uint64_t generation; + grub_uint64_t root_tree; + grub_uint64_t chunk_tree; +- grub_uint8_t dummy2[0x20]; ++ grub_uint8_t dummy2[0x18]; ++ grub_uint64_t bytes_used; + grub_uint64_t root_dir_objectid; +- grub_uint8_t dummy3[0x41]; ++ grub_uint64_t num_devices; ++ grub_uint8_t dummy3[0x39]; + struct grub_btrfs_device this_device; + char label[0x100]; + grub_uint8_t dummy4[0x100]; +@@ -120,6 +125,7 @@ struct grub_btrfs_data + grub_uint64_t exttree; + grub_size_t extsize; + struct grub_btrfs_extent_data *extent; ++ grub_uint64_t fs_tree; + }; + + struct grub_btrfs_chunk_item +@@ -188,6 +194,14 @@ struct grub_btrfs_leaf_descriptor + } *data; + }; + ++struct grub_btrfs_root_ref ++{ ++ grub_uint64_t dirid; ++ grub_uint64_t sequence; ++ grub_uint16_t name_len; ++ const char name[0]; ++} __attribute__ ((packed)); ++ + struct grub_btrfs_time + { + grub_int64_t sec; +@@ -233,6 +247,14 @@ struct grub_btrfs_extent_data + + #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 + ++#define GRUB_BTRFS_ROOT_TREE_OBJECTID 1ULL ++#define GRUB_BTRFS_FS_TREE_OBJECTID 5ULL ++#define GRUB_BTRFS_ROOT_REF_KEY 156 ++#define GRUB_BTRFS_ROOT_ITEM_KEY 132 ++ ++static grub_uint64_t btrfs_default_subvolid = 0; ++static char *btrfs_default_subvol = NULL; ++ + static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, + 256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 + }; +@@ -1153,6 +1175,62 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, + return GRUB_ERR_NONE; + } + ++static grub_err_t ++get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, ++ grub_uint64_t objectid, grub_uint64_t offset, ++ grub_uint64_t *fs_root); ++ ++static grub_err_t ++lookup_root_by_id(struct grub_btrfs_data *data, grub_uint64_t id) ++{ ++ grub_err_t err; ++ grub_uint64_t tree; ++ ++ err = get_fs_root(data, data->sblock.root_tree, id, -1, &tree); ++ if (!err) ++ data->fs_tree = tree; ++ return err; ++} ++ ++static grub_err_t ++find_path (struct grub_btrfs_data *data, ++ const char *path, struct grub_btrfs_key *key, ++ grub_uint64_t *tree, grub_uint8_t *type); ++ ++static grub_err_t ++lookup_root_by_name(struct grub_btrfs_data *data, const char *path) ++{ ++ grub_err_t err; ++ grub_uint64_t tree = 0; ++ grub_uint8_t type; ++ struct grub_btrfs_key key; ++ ++ err = find_path (data, path, &key, &tree, &type); ++ if (err) ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path); ++ ++ if (key.object_id != grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0) ++ return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path); ++ ++ data->fs_tree = tree; ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused))) ++{ ++ if (btrfs_default_subvol) ++ return lookup_root_by_name(data, btrfs_default_subvol); ++ ++ if (btrfs_default_subvolid) ++ return lookup_root_by_id(data, btrfs_default_subvolid); ++ ++ data->fs_tree = 0; ++ ++ return GRUB_ERR_NONE; ++} ++ ++ + static struct grub_btrfs_data * + grub_btrfs_mount (grub_device_t dev) + { +@@ -1188,6 +1266,13 @@ grub_btrfs_mount (grub_device_t dev) + data->devices_attached[0].dev = dev; + data->devices_attached[0].id = data->sblock.this_device.device_id; + ++ err = btrfs_handle_subvol (data); ++ if (err) ++ { ++ grub_free (data); ++ return NULL; ++ } ++ + return data; + } + +@@ -1653,6 +1738,91 @@ get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, + return GRUB_ERR_NONE; + } + ++static grub_err_t ++find_pathname(struct grub_btrfs_data *data, grub_uint64_t objectid, ++ grub_uint64_t fs_root, const char *name, char **pathname) ++{ ++ grub_err_t err; ++ struct grub_btrfs_key key = { ++ .object_id = objectid, ++ .type = GRUB_BTRFS_ITEM_TYPE_INODE_REF, ++ .offset = 0, ++ }; ++ struct grub_btrfs_key key_out; ++ struct grub_btrfs_leaf_descriptor desc; ++ char *p = grub_strdup (name); ++ grub_disk_addr_t elemaddr; ++ grub_size_t elemsize; ++ grub_size_t alloc = grub_strlen(name) + 1; ++ ++ err = lower_bound(data, &key, &key_out, fs_root, ++ &elemaddr, &elemsize, &desc, 0); ++ if (err) ++ return grub_error(err, "lower_bound caught %d\n", err); ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_INODE_REF) ++ next(data, &desc, &elemaddr, &elemsize, &key_out); ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_INODE_REF) ++ { ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, ++ "Can't find inode ref for {%"PRIuGRUB_UINT64_T ++ ", %u, %"PRIuGRUB_UINT64_T"} %"PRIuGRUB_UINT64_T ++ "/%"PRIuGRUB_SIZE"\n", ++ key_out.object_id, key_out.type, ++ key_out.offset, elemaddr, elemsize); ++ } ++ ++ ++ while (key_out.type == GRUB_BTRFS_ITEM_TYPE_INODE_REF && ++ key_out.object_id != key_out.offset) { ++ struct grub_btrfs_inode_ref *inode_ref; ++ char *new; ++ ++ inode_ref = grub_malloc(elemsize + 1); ++ if (!inode_ref) ++ return grub_error(GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't allocate memory for inode_ref (%"PRIuGRUB_SIZE")\n", elemsize); ++ ++ err = grub_btrfs_read_logical(data, elemaddr, inode_ref, elemsize, 0); ++ if (err) ++ return grub_error(err, "read_logical caught %d\n", err); ++ ++ alloc += grub_le_to_cpu16 (inode_ref->n) + 2; ++ new = grub_malloc(alloc); ++ if (!new) ++ return grub_error(GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't allocate memory for name (%"PRIuGRUB_SIZE")\n", alloc); ++ ++ grub_memcpy(new, inode_ref->name, grub_le_to_cpu16 (inode_ref->n)); ++ if (p) ++ { ++ new[grub_le_to_cpu16 (inode_ref->n)] = '/'; ++ grub_strcpy (new + grub_le_to_cpu16 (inode_ref->n) + 1, p); ++ grub_free(p); ++ } ++ else ++ new[grub_le_to_cpu16 (inode_ref->n)] = 0; ++ grub_free(inode_ref); ++ ++ p = new; ++ ++ key.object_id = key_out.offset; ++ ++ err = lower_bound(data, &key, &key_out, fs_root, &elemaddr, ++ &elemsize, &desc, 0); ++ if (err) ++ return grub_error(err, "lower_bound caught %d\n", err); ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_INODE_REF) ++ next(data, &desc, &elemaddr, &elemsize, &key_out); ++ ++ } ++ ++ *pathname = p; ++ return 0; ++} ++ + static grub_err_t + find_path (struct grub_btrfs_data *data, + const char *path, struct grub_btrfs_key *key, +@@ -1671,14 +1841,26 @@ find_path (struct grub_btrfs_data *data, + char *origpath = NULL; + unsigned symlinks_max = 32; + +- err = get_root (data, key, tree, type); +- if (err) +- return err; +- + origpath = grub_strdup (path); + if (!origpath) + return grub_errno; + ++ if (data->fs_tree) ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->fs_tree; ++ /* This is a tree root, so everything starts at objectid 256 */ ++ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ } ++ else ++ { ++ err = get_root (data, key, tree, type); ++ if (err) ++ return err; ++ } ++ + while (1) + { + while (path[0] == '/') +@@ -1851,9 +2033,21 @@ find_path (struct grub_btrfs_data *data, + path = path_alloc = tmp; + if (path[0] == '/') + { +- err = get_root (data, key, tree, type); +- if (err) +- return err; ++ if (data->fs_tree) ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->fs_tree; ++ /* This is a tree root, so everything starts at objectid 256 */ ++ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ } ++ else ++ { ++ err = get_root (data, key, tree, type); ++ if (err) ++ return err; ++ } + } + continue; + } +@@ -2094,18 +2288,10 @@ grub_btrfs_read (grub_file_t file, char *buf, grub_size_t len) + data->tree, file->offset, buf, len); + } + +-static grub_err_t +-grub_btrfs_uuid (grub_device_t device, char **uuid) ++static char * ++btrfs_unparse_uuid(struct grub_btrfs_data *data) + { +- struct grub_btrfs_data *data; +- +- *uuid = NULL; +- +- data = grub_btrfs_mount (device); +- if (!data) +- return grub_errno; +- +- *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", ++ return grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + grub_be_to_cpu16 (data->sblock.uuid[0]), + grub_be_to_cpu16 (data->sblock.uuid[1]), + grub_be_to_cpu16 (data->sblock.uuid[2]), +@@ -2114,6 +2300,20 @@ grub_btrfs_uuid (grub_device_t device, char **uuid) + grub_be_to_cpu16 (data->sblock.uuid[5]), + grub_be_to_cpu16 (data->sblock.uuid[6]), + grub_be_to_cpu16 (data->sblock.uuid[7])); ++} ++ ++static grub_err_t ++grub_btrfs_uuid (grub_device_t device, char **uuid) ++{ ++ struct grub_btrfs_data *data; ++ ++ *uuid = NULL; ++ ++ data = grub_btrfs_mount (device); ++ if (!data) ++ return grub_errno; ++ ++ *uuid = btrfs_unparse_uuid(data); + + grub_btrfs_unmount (data); + +@@ -2170,6 +2370,242 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), + } + #endif + ++static grub_err_t ++grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, ++ char **argv) ++{ ++ grub_device_t dev; ++ char *devname; ++ struct grub_btrfs_data *data; ++ char *uuid; ++ ++ if (argc < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); ++ ++ devname = grub_file_get_device_name(argv[0]); ++ ++ if (!devname) ++ return grub_errno; ++ ++ dev = grub_device_open (devname); ++ grub_free (devname); ++ if (!dev) ++ return grub_errno; ++ ++ data = grub_btrfs_mount (dev); ++ if (!data) ++ { ++ grub_device_close(dev); ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "failed to open fs"); ++ } ++ ++ if (data->sblock.label) ++ grub_printf("Label: '%s' ", data->sblock.label); ++ else ++ grub_printf("Label: none "); ++ ++ uuid = btrfs_unparse_uuid(data); ++ ++ grub_printf(" uuid: %s\n\tTotal devices %" PRIuGRUB_UINT64_T ++ " FS bytes used %" PRIuGRUB_UINT64_T "\n", ++ uuid, grub_cpu_to_le64(data->sblock.num_devices), ++ grub_cpu_to_le64(data->sblock.bytes_used)); ++ ++ grub_btrfs_unmount (data); ++ ++ return 0; ++} ++ ++static grub_err_t ++get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, ++ grub_uint64_t objectid, grub_uint64_t offset, ++ grub_uint64_t *fs_root) ++{ ++ grub_err_t err; ++ struct grub_btrfs_key key_in = { ++ .object_id = objectid, ++ .type = GRUB_BTRFS_ROOT_ITEM_KEY, ++ .offset = offset, ++ }, key_out; ++ struct grub_btrfs_leaf_descriptor desc; ++ grub_disk_addr_t elemaddr; ++ grub_size_t elemsize; ++ struct grub_btrfs_root_item ri; ++ ++ err = lower_bound(data, &key_in, &key_out, tree, ++ &elemaddr, &elemsize, &desc, 0); ++ ++ if (err) ++ return err; ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM || elemaddr == 0) ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, ++ N_("can't find fs root for subvol %"PRIuGRUB_UINT64_T"\n"), ++ key_in.object_id); ++ ++ err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri), 0); ++ if (err) ++ return err; ++ ++ *fs_root = ri.tree; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static const struct grub_arg_option options[] = { ++ {"output", 'o', 0, N_("Output to a variable instead of the console."), ++ N_("VARNAME"), ARG_TYPE_STRING}, ++ {"path-only", 'p', 0, N_("Show only the path of the subvolume."), 0, 0}, ++ {"id-only", 'i', 0, N_("Show only the id of the subvolume."), 0, 0}, ++ {0, 0, 0, 0, 0, 0} ++}; ++ ++static grub_err_t ++grub_cmd_btrfs_list_subvols (struct grub_extcmd_context *ctxt, ++ int argc, char **argv) ++{ ++ struct grub_btrfs_data *data; ++ grub_device_t dev; ++ char *devname; ++ grub_uint64_t tree; ++ struct grub_btrfs_key key_in = { ++ .object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_FS_TREE_OBJECTID), ++ .type = GRUB_BTRFS_ROOT_REF_KEY, ++ .offset = 0, ++ }, key_out; ++ struct grub_btrfs_leaf_descriptor desc; ++ grub_disk_addr_t elemaddr; ++ grub_uint64_t fs_root = 0; ++ grub_size_t elemsize; ++ grub_size_t allocated = 0; ++ int r = 0; ++ grub_err_t err; ++ char *buf = NULL; ++ int print = 1; ++ int path_only = ctxt->state[1].set; ++ int num_only = ctxt->state[2].set; ++ char *varname = NULL; ++ char *output = NULL; ++ ++ if (ctxt->state[0].set) { ++ varname = ctxt->state[0].arg; ++ print = 0; ++ } ++ ++ if (argc < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); ++ ++ devname = grub_file_get_device_name(argv[0]); ++ if (!devname) ++ return grub_errno; ++ ++ dev = grub_device_open (devname); ++ grub_free (devname); ++ if (!dev) ++ return grub_errno; ++ ++ data = grub_btrfs_mount(dev); ++ if (!data) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "could not open device"); ++ ++ tree = data->sblock.root_tree; ++ err = get_fs_root(data, tree, grub_cpu_to_le64_compile_time (GRUB_BTRFS_FS_TREE_OBJECTID), ++ 0, &fs_root); ++ if (err) ++ goto out; ++ ++ err = lower_bound(data, &key_in, &key_out, tree, ++ &elemaddr, &elemsize, &desc, 0); ++ ++ if (err) ++ { ++ grub_btrfs_unmount(data); ++ return err; ++ } ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_REF || elemaddr == 0) ++ { ++ r = next(data, &desc, &elemaddr, &elemsize, &key_out); ++ } ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_REF) { ++ err = GRUB_ERR_FILE_NOT_FOUND; ++ grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root refs")); ++ goto out; ++ } ++ ++ do ++ { ++ struct grub_btrfs_root_ref *ref; ++ char *p = NULL; ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_REF) ++ { ++ r = 0; ++ break; ++ } ++ ++ if (elemsize > allocated) ++ { ++ grub_free(buf); ++ allocated = 2 * elemsize; ++ buf = grub_malloc(allocated + 1); ++ if (!buf) ++ { ++ r = -grub_errno; ++ break; ++ } ++ } ++ ref = (struct grub_btrfs_root_ref *)buf; ++ ++ err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0); ++ if (err) ++ { ++ r = -err; ++ break; ++ } ++ buf[elemsize] = 0; ++ ++ find_pathname(data, ref->dirid, fs_root, ref->name, &p); ++ ++ if (print) ++ { ++ if (num_only) ++ grub_printf("ID %"PRIuGRUB_UINT64_T"\n", key_out.offset); ++ else if (path_only) ++ grub_printf("%s\n", p); ++ else ++ grub_printf("ID %"PRIuGRUB_UINT64_T" path %s\n", key_out.offset, p); ++ } else { ++ char *old = output; ++ if (num_only) ++ output = grub_xasprintf("%s%"PRIuGRUB_UINT64_T"\n", ++ old ?: "", key_out.offset); ++ else if (path_only) ++ output = grub_xasprintf("%s%s\n", old ?: "", p); ++ else ++ output = grub_xasprintf("%sID %"PRIuGRUB_UINT64_T" path %s\n", ++ old ?: "", key_out.offset, p); ++ ++ if (old) ++ grub_free(old); ++ } ++ ++ r = next(data, &desc, &elemaddr, &elemsize, &key_out); ++ } while(r > 0); ++ ++ if (output) ++ grub_env_set(varname, output); ++ ++out: ++ free_iterator(&desc); ++ grub_btrfs_unmount(data); ++ ++ grub_device_close (dev); ++ ++ return 0; ++} ++ + static struct grub_fs grub_btrfs_fs = { + .name = "btrfs", + .fs_dir = grub_btrfs_dir, +@@ -2185,12 +2621,88 @@ static struct grub_fs grub_btrfs_fs = { + #endif + }; + ++static grub_command_t cmd_info; ++static grub_extcmd_t cmd_list_subvols; ++ ++static char * ++subvolid_set_env (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val) ++{ ++ unsigned long long result = 0; ++ ++ grub_errno = GRUB_ERR_NONE; ++ if (*val) ++ { ++ result = grub_strtoull(val, NULL, 10); ++ if (grub_errno) ++ return NULL; ++ } ++ ++ grub_free (btrfs_default_subvol); ++ btrfs_default_subvol = NULL; ++ btrfs_default_subvolid = result; ++ return grub_strdup(val); ++} ++ ++static const char * ++subvolid_get_env (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ if (btrfs_default_subvol) ++ return grub_xasprintf("subvol:%s", btrfs_default_subvol); ++ else if (btrfs_default_subvolid) ++ return grub_xasprintf("%"PRIuGRUB_UINT64_T, btrfs_default_subvolid); ++ else ++ return ""; ++} ++ ++static char * ++subvol_set_env (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val) ++{ ++ grub_free (btrfs_default_subvol); ++ btrfs_default_subvol = grub_strdup (val); ++ btrfs_default_subvolid = 0; ++ return grub_strdup(val); ++} ++ ++static const char * ++subvol_get_env (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ if (btrfs_default_subvol) ++ return btrfs_default_subvol; ++ else if (btrfs_default_subvolid) ++ return grub_xasprintf("subvolid:%" PRIuGRUB_UINT64_T, ++ btrfs_default_subvolid); ++ else ++ return ""; ++} ++ + GRUB_MOD_INIT (btrfs) + { + grub_fs_register (&grub_btrfs_fs); ++ cmd_info = grub_register_command("btrfs-info", grub_cmd_btrfs_info, ++ "DEVICE", ++ "Print BtrFS info about DEVICE."); ++ cmd_list_subvols = grub_register_extcmd("btrfs-list-subvols", ++ grub_cmd_btrfs_list_subvols, 0, ++ "[-p|-n] [-o var] DEVICE", ++ "Print list of BtrFS subvolumes on " ++ "DEVICE.", options); ++ grub_register_variable_hook ("btrfs_subvol", subvol_get_env, ++ subvol_set_env); ++ grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, ++ subvolid_set_env); + } + + GRUB_MOD_FINI (btrfs) + { ++ grub_register_variable_hook ("btrfs_subvol", NULL, NULL); ++ grub_register_variable_hook ("btrfs_subvolid", NULL, NULL); ++ grub_unregister_command (cmd_info); ++ grub_unregister_extcmd (cmd_list_subvols); + grub_fs_unregister (&grub_btrfs_fs); + } ++ ++// vim: si et sw=2: +diff --git a/include/grub/btrfs.h b/include/grub/btrfs.h +index 9d93fb6c182..234ad976771 100644 +--- a/include/grub/btrfs.h ++++ b/include/grub/btrfs.h +@@ -29,6 +29,7 @@ enum + GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM = 0x84, + GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF = 0x90, + GRUB_BTRFS_ITEM_TYPE_DEVICE = 0xd8, ++ GRUB_BTRFS_ITEM_TYPE_ROOT_REF = 0x9c, + GRUB_BTRFS_ITEM_TYPE_CHUNK = 0xe4 + }; + diff --git a/0075-export-btrfs_subvol-and-btrfs_subvolid.patch b/0075-export-btrfs_subvol-and-btrfs_subvolid.patch new file mode 100644 index 0000000..5af81e7 --- /dev/null +++ b/0075-export-btrfs_subvol-and-btrfs_subvolid.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 18 Dec 2013 09:57:04 +0000 +Subject: [PATCH] export btrfs_subvol and btrfs_subvolid + +We should export btrfs_subvol and btrfs_subvolid to have both visible +to subsidiary configuration files loaded using configfile. + +Signed-off-by: Michael Chang +--- + grub-core/fs/btrfs.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 6823d9765c4..2d099b18ea1 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2694,6 +2694,8 @@ GRUB_MOD_INIT (btrfs) + subvol_set_env); + grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, + subvolid_set_env); ++ grub_env_export ("btrfs_subvol"); ++ grub_env_export ("btrfs_subvolid"); + } + + GRUB_MOD_FINI (btrfs) diff --git a/0076-grub2-btrfs-03-follow_default.patch b/0076-grub2-btrfs-03-follow_default.patch new file mode 100644 index 0000000..b28aa78 --- /dev/null +++ b/0076-grub2-btrfs-03-follow_default.patch @@ -0,0 +1,196 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 21 Aug 2014 03:39:11 +0000 +Subject: [PATCH] grub2-btrfs-03-follow_default + +--- + grub-core/fs/btrfs.c | 107 ++++++++++++++++++++++++++++++++++++--------------- + 1 file changed, 76 insertions(+), 31 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 2d099b18ea1..2db89f71ea5 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -1236,6 +1236,7 @@ grub_btrfs_mount (grub_device_t dev) + { + struct grub_btrfs_data *data; + grub_err_t err; ++ const char *relpath = grub_env_get ("btrfs_relative_path"); + + if (!dev->disk) + { +@@ -1266,11 +1267,14 @@ grub_btrfs_mount (grub_device_t dev) + data->devices_attached[0].dev = dev; + data->devices_attached[0].id = data->sblock.this_device.device_id; + +- err = btrfs_handle_subvol (data); +- if (err) ++ if (relpath && (relpath[0] == '1' || relpath[0] == 'y')) + { +- grub_free (data); +- return NULL; ++ err = btrfs_handle_subvol (data); ++ if (err) ++ { ++ grub_free (data); ++ return NULL; ++ } + } + + return data; +@@ -1835,24 +1839,39 @@ find_path (struct grub_btrfs_data *data, + grub_size_t allocated = 0; + struct grub_btrfs_dir_item *direl = NULL; + struct grub_btrfs_key key_out; ++ int follow_default; + const char *ctoken; + grub_size_t ctokenlen; + char *path_alloc = NULL; + char *origpath = NULL; + unsigned symlinks_max = 32; ++ const char *relpath = grub_env_get ("btrfs_relative_path"); + ++ follow_default = 0; + origpath = grub_strdup (path); + if (!origpath) + return grub_errno; + +- if (data->fs_tree) ++ if (relpath && (relpath[0] == '1' || relpath[0] == 'y')) + { +- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; +- *tree = data->fs_tree; +- /* This is a tree root, so everything starts at objectid 256 */ +- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); +- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; +- key->offset = 0; ++ if (data->fs_tree) ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->fs_tree; ++ /* This is a tree root, so everything starts at objectid 256 */ ++ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ } ++ else ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->sblock.root_tree; ++ key->object_id = data->sblock.root_dir_objectid; ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ follow_default = 1; ++ } + } + else + { +@@ -1863,15 +1882,23 @@ find_path (struct grub_btrfs_data *data, + + while (1) + { +- while (path[0] == '/') +- path++; +- if (!path[0]) +- break; +- slash = grub_strchr (path, '/'); +- if (!slash) +- slash = path + grub_strlen (path); +- ctoken = path; +- ctokenlen = slash - path; ++ if (!follow_default) ++ { ++ while (path[0] == '/') ++ path++; ++ if (!path[0]) ++ break; ++ slash = grub_strchr (path, '/'); ++ if (!slash) ++ slash = path + grub_strlen (path); ++ ctoken = path; ++ ctokenlen = slash - path; ++ } ++ else ++ { ++ ctoken = "default"; ++ ctokenlen = sizeof ("default") - 1; ++ } + + if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) + { +@@ -1882,7 +1909,9 @@ find_path (struct grub_btrfs_data *data, + + if (ctokenlen == 1 && ctoken[0] == '.') + { +- path = slash; ++ if (!follow_default) ++ path = slash; ++ follow_default = 0; + continue; + } + if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.') +@@ -1913,8 +1942,9 @@ find_path (struct grub_btrfs_data *data, + *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; + key->object_id = key_out.offset; + +- path = slash; +- ++ if (!follow_default) ++ path = slash; ++ follow_default = 0; + continue; + } + +@@ -1983,7 +2013,9 @@ find_path (struct grub_btrfs_data *data, + return err; + } + +- path = slash; ++ if (!follow_default) ++ path = slash; ++ follow_default = 0; + if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK) + { + struct grub_btrfs_inode inode; +@@ -2033,14 +2065,26 @@ find_path (struct grub_btrfs_data *data, + path = path_alloc = tmp; + if (path[0] == '/') + { +- if (data->fs_tree) ++ if (relpath && (relpath[0] == '1' || relpath[0] == 'y')) + { +- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; +- *tree = data->fs_tree; +- /* This is a tree root, so everything starts at objectid 256 */ +- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); +- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; +- key->offset = 0; ++ if (data->fs_tree) ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->fs_tree; ++ /* This is a tree root, so everything starts at objectid 256 */ ++ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK); ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ } ++ else ++ { ++ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY; ++ *tree = data->sblock.root_tree; ++ key->object_id = data->sblock.root_dir_objectid; ++ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key->offset = 0; ++ follow_default = 1; ++ } + } + else + { +@@ -2696,6 +2740,7 @@ GRUB_MOD_INIT (btrfs) + subvolid_set_env); + grub_env_export ("btrfs_subvol"); + grub_env_export ("btrfs_subvolid"); ++ grub_env_export ("btrfs_relative_path"); + } + + GRUB_MOD_FINI (btrfs) diff --git a/0077-grub2-btrfs-04-grub2-install.patch b/0077-grub2-btrfs-04-grub2-install.patch new file mode 100644 index 0000000..b490f8d --- /dev/null +++ b/0077-grub2-btrfs-04-grub2-install.patch @@ -0,0 +1,174 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 21 Aug 2014 03:39:11 +0000 +Subject: [PATCH] grub2-btrfs-04-grub2-install + +--- + grub-core/osdep/linux/getroot.c | 7 +++++++ + grub-core/osdep/unix/config.c | 17 +++++++++++++++-- + util/config.c | 10 ++++++++++ + util/grub-install.c | 15 +++++++++++++++ + util/grub-mkrelpath.c | 6 ++++++ + include/grub/emu/config.h | 1 + + 6 files changed, 54 insertions(+), 2 deletions(-) + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 6d9f4e5faa2..5d50dd6f8dc 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -376,6 +376,7 @@ get_btrfs_fs_prefix (const char *mount_path) + return NULL; + } + ++int use_relative_path_on_btrfs = 0; + + char ** + grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) +@@ -519,6 +520,12 @@ again: + { + ret = grub_find_root_devices_from_btrfs (dir); + fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); ++ if (use_relative_path_on_btrfs) ++ { ++ if (fs_prefix) ++ free (fs_prefix); ++ fs_prefix = xstrdup ("/"); ++ } + } + else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) + { +diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c +index 65effa9f3a7..b637c58efb7 100644 +--- a/grub-core/osdep/unix/config.c ++++ b/grub-core/osdep/unix/config.c +@@ -82,6 +82,19 @@ grub_util_load_config (struct grub_util_config *cfg) + if (v) + cfg->grub_distributor = xstrdup (v); + ++ v = getenv ("SUSE_BTRFS_SNAPSHOT_BOOTING"); ++ if (v) ++ { ++ if (grub_strncmp(v, "true", sizeof ("true") - 1) == 0) ++ { ++ cfg->is_suse_btrfs_snapshot_enabled = 1; ++ } ++ else ++ { ++ cfg->is_suse_btrfs_snapshot_enabled = 0; ++ } ++ } ++ + cfgfile = grub_util_get_config_filename (); + if (!grub_util_is_regular (cfgfile)) + return; +@@ -105,8 +118,8 @@ grub_util_load_config (struct grub_util_config *cfg) + *ptr++ = *iptr; + } + +- strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\n\" " +- "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\""); ++ strcpy (ptr, "'; printf \"GRUB_ENABLE_CRYPTODISK=%s\\nGRUB_DISTRIBUTOR=%s\\nSUSE_BTRFS_SNAPSHOT_BOOTING=%s\\n\" " ++ "\"$GRUB_ENABLE_CRYPTODISK\" \"$GRUB_DISTRIBUTOR\" \"$SUSE_BTRFS_SNAPSHOT_BOOTING\""); + + argv[2] = script; + argv[3] = '\0'; +diff --git a/util/config.c b/util/config.c +index ebcdd8f5e22..f044a880a76 100644 +--- a/util/config.c ++++ b/util/config.c +@@ -42,6 +42,16 @@ grub_util_parse_config (FILE *f, struct grub_util_config *cfg, int simple) + cfg->is_cryptodisk_enabled = 1; + continue; + } ++ if (grub_strncmp (ptr, "SUSE_BTRFS_SNAPSHOT_BOOTING=", ++ sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1) == 0) ++ { ++ ptr += sizeof ("SUSE_BTRFS_SNAPSHOT_BOOTING=") - 1; ++ if (*ptr == '"' || *ptr == '\'') ++ ptr++; ++ if (grub_strncmp(ptr, "true", sizeof ("true") - 1) == 0) ++ cfg->is_suse_btrfs_snapshot_enabled = 1; ++ continue; ++ } + if (grub_strncmp (ptr, "GRUB_DISTRIBUTOR=", + sizeof ("GRUB_DISTRIBUTOR=") - 1) == 0) + { +diff --git a/util/grub-install.c b/util/grub-install.c +index 8a55ad4b8dc..0e807b09c36 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -819,6 +819,8 @@ fill_core_services (const char *core_services) + free (sysv_plist); + } + ++extern int use_relative_path_on_btrfs; ++ + int + main (int argc, char *argv[]) + { +@@ -852,6 +854,9 @@ main (int argc, char *argv[]) + + grub_util_load_config (&config); + ++ if (config.is_suse_btrfs_snapshot_enabled) ++ use_relative_path_on_btrfs = 1; ++ + if (!bootloader_id && config.grub_distributor) + { + char *ptr; +@@ -1344,6 +1349,16 @@ main (int argc, char *argv[]) + fprintf (load_cfg_f, "set debug='%s'\n", + debug_image); + } ++ ++ if (config.is_suse_btrfs_snapshot_enabled ++ && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0) ++ { ++ if (!load_cfg_f) ++ load_cfg_f = grub_util_fopen (load_cfg, "wb"); ++ have_load_cfg = 1; ++ fprintf (load_cfg_f, "set btrfs_relative_path='y'\n"); ++ } ++ + char *prefix_drive = NULL; + char *install_drive = NULL; + +diff --git a/util/grub-mkrelpath.c b/util/grub-mkrelpath.c +index 47a241a391b..5db7a9a7d97 100644 +--- a/util/grub-mkrelpath.c ++++ b/util/grub-mkrelpath.c +@@ -40,9 +40,12 @@ struct arguments + }; + + static struct argp_option options[] = { ++ {"relative", 'r', 0, 0, "use relative path on btrfs", 0}, + { 0, 0, 0, 0, 0, 0 } + }; + ++extern int use_relative_path_on_btrfs; ++ + static error_t + argp_parser (int key, char *arg, struct argp_state *state) + { +@@ -52,6 +55,9 @@ argp_parser (int key, char *arg, struct argp_state *state) + + switch (key) + { ++ case 'r': ++ use_relative_path_on_btrfs = 1; ++ break; + case ARGP_KEY_ARG: + if (state->arg_num == 0) + arguments->pathname = xstrdup (arg); +diff --git a/include/grub/emu/config.h b/include/grub/emu/config.h +index 875d5896ce1..c9a7e5f4ade 100644 +--- a/include/grub/emu/config.h ++++ b/include/grub/emu/config.h +@@ -37,6 +37,7 @@ struct grub_util_config + { + int is_cryptodisk_enabled; + char *grub_distributor; ++ int is_suse_btrfs_snapshot_enabled; + }; + + void diff --git a/0078-grub2-btrfs-05-grub2-mkconfig.patch b/0078-grub2-btrfs-05-grub2-mkconfig.patch new file mode 100644 index 0000000..2320e89 --- /dev/null +++ b/0078-grub2-btrfs-05-grub2-mkconfig.patch @@ -0,0 +1,129 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 21 Aug 2014 03:39:11 +0000 +Subject: [PATCH] grub2-btrfs-05-grub2-mkconfig + +Signed-off-by: Michael Chang +--- + util/grub-mkconfig.in | 3 ++- + util/grub-mkconfig_lib.in | 4 ++++ + util/grub.d/00_header.in | 25 ++++++++++++++++++++++++- + util/grub.d/10_linux.in | 4 ++++ + util/grub.d/20_linux_xen.in | 4 ++++ + 5 files changed, 38 insertions(+), 2 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 6247a0ba850..4649e92eb0f 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -258,7 +258,8 @@ export GRUB_DEFAULT \ + GRUB_BADRAM \ + GRUB_OS_PROBER_SKIP_LIST \ + GRUB_DISABLE_SUBMENU \ +- GRUB_DEFAULT_DTB ++ GRUB_DEFAULT_DTB \ ++ SUSE_BTRFS_SNAPSHOT_BOOTING + + if test "x${grub_cfg}" != "x"; then + rm -f "${grub_cfg}.new" +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 113a41f9409..b3aae534ddc 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -52,7 +52,11 @@ grub_warn () + + make_system_path_relative_to_its_root () + { ++ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then ++ "${grub_mkrelpath}" -r "$1" ++ else + "${grub_mkrelpath}" "$1" ++ fi + } + + is_path_readable_by_grub () +diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in +index 858b526c925..de727e6ee6b 100644 +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@" + + . "$pkgdatadir/grub-mkconfig_lib" + ++if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] && ++ [ "x${GRUB_FS}" = "xbtrfs" ] ; then ++ cat </dev/null || true` +diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in +index 47e0d3f5cd6..1519ec692fe 100644 +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -73,10 +73,14 @@ fi + + case x"$GRUB_FS" in + xbtrfs) ++ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then ++ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}" ++ else + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" ++ fi + fi;; + xzfs) + rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` diff --git a/0079-grub2-btrfs-06-subvol-mount.patch b/0079-grub2-btrfs-06-subvol-mount.patch new file mode 100644 index 0000000..36824c8 --- /dev/null +++ b/0079-grub2-btrfs-06-subvol-mount.patch @@ -0,0 +1,537 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Tue, 9 Jul 2019 13:56:16 +0200 +Subject: [PATCH] grub2-btrfs-06-subvol-mount + +--- + grub-core/fs/btrfs.c | 195 +++++++++++++++++++++++++++++++++++++++- + grub-core/osdep/linux/getroot.c | 148 +++++++++++++++++++++++++++++- + util/grub-install.c | 49 ++++++++++ + include/grub/emu/getroot.h | 5 ++ + 4 files changed, 392 insertions(+), 5 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 2db89f71ea5..162723423ca 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -41,6 +41,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -263,6 +264,12 @@ static grub_err_t + grub_btrfs_read_logical (struct grub_btrfs_data *data, + grub_disk_addr_t addr, void *buf, grub_size_t size, + int recursion_depth); ++static grub_err_t ++get_root (struct grub_btrfs_data *data, struct grub_btrfs_key *key, ++ grub_uint64_t *tree, grub_uint8_t *type); ++ ++grub_uint64_t ++find_mtab_subvol_tree (const char *path, char **path_in_subvol); + + static grub_err_t + read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) +@@ -1203,9 +1210,26 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) + grub_err_t err; + grub_uint64_t tree = 0; + grub_uint8_t type; ++ grub_uint64_t saved_tree; + struct grub_btrfs_key key; + ++ if (path[0] == '\0') ++ { ++ data->fs_tree = 0; ++ return GRUB_ERR_NONE; ++ } ++ ++ err = get_root (data, &key, &tree, &type); ++ if (err) ++ return err; ++ ++ saved_tree = data->fs_tree; ++ data->fs_tree = tree; ++ + err = find_path (data, path, &key, &tree, &type); ++ ++ data->fs_tree = saved_tree; ++ + if (err) + return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path); + +@@ -2179,11 +2203,20 @@ grub_btrfs_dir (grub_device_t device, const char *path, + int r = 0; + grub_uint64_t tree; + grub_uint8_t type; ++ char *new_path = NULL; + + if (!data) + return grub_errno; + +- err = find_path (data, path, &key_in, &tree, &type); ++ tree = find_mtab_subvol_tree (path, &new_path); ++ ++ if (tree) ++ data->fs_tree = tree; ++ ++ err = find_path (data, new_path ? new_path : path, &key_in, &tree, &type); ++ if (new_path) ++ grub_free (new_path); ++ + if (err) + { + grub_btrfs_unmount (data); +@@ -2285,11 +2318,21 @@ grub_btrfs_open (struct grub_file *file, const char *name) + struct grub_btrfs_inode inode; + grub_uint8_t type; + struct grub_btrfs_key key_in; ++ grub_uint64_t tree; ++ char *new_path = NULL; + + if (!data) + return grub_errno; + +- err = find_path (data, name, &key_in, &data->tree, &type); ++ tree = find_mtab_subvol_tree (name, &new_path); ++ ++ if (tree) ++ data->fs_tree = tree; ++ ++ err = find_path (data, new_path ? new_path : name, &key_in, &data->tree, &type); ++ if (new_path) ++ grub_free (new_path); ++ + if (err) + { + grub_btrfs_unmount (data); +@@ -2460,6 +2503,150 @@ grub_cmd_btrfs_info (grub_command_t cmd __attribute__ ((unused)), int argc, + return 0; + } + ++struct grub_btrfs_mtab ++{ ++ struct grub_btrfs_mtab *next; ++ struct grub_btrfs_mtab **prev; ++ char *path; ++ char *subvol; ++ grub_uint64_t tree; ++}; ++ ++typedef struct grub_btrfs_mtab* grub_btrfs_mtab_t; ++ ++static struct grub_btrfs_mtab *btrfs_mtab; ++ ++#define FOR_GRUB_MTAB(var) FOR_LIST_ELEMENTS (var, btrfs_mtab) ++#define FOR_GRUB_MTAB_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), btrfs_mtab) ++ ++static void ++add_mountpoint (const char *path, const char *subvol, grub_uint64_t tree) ++{ ++ grub_btrfs_mtab_t m = grub_malloc (sizeof (*m)); ++ ++ m->path = grub_strdup (path); ++ m->subvol = grub_strdup (subvol); ++ m->tree = tree; ++ grub_list_push (GRUB_AS_LIST_P (&btrfs_mtab), GRUB_AS_LIST (m)); ++} ++ ++static grub_err_t ++grub_cmd_btrfs_mount_subvol (grub_command_t cmd __attribute__ ((unused)), int argc, ++ char **argv) ++{ ++ char *devname, *dirname, *subvol; ++ struct grub_btrfs_key key_in; ++ grub_uint8_t type; ++ grub_uint64_t tree; ++ grub_uint64_t saved_tree; ++ grub_err_t err; ++ struct grub_btrfs_data *data = NULL; ++ grub_device_t dev = NULL; ++ ++ if (argc < 3) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "required and "); ++ ++ devname = grub_file_get_device_name(argv[0]); ++ dev = grub_device_open (devname); ++ grub_free (devname); ++ ++ if (!dev) ++ { ++ err = grub_errno; ++ goto err_out; ++ } ++ ++ dirname = argv[1]; ++ subvol = argv[2]; ++ ++ data = grub_btrfs_mount (dev); ++ if (!data) ++ { ++ err = grub_errno; ++ goto err_out; ++ } ++ ++ err = find_path (data, dirname, &key_in, &tree, &type); ++ if (err) ++ goto err_out; ++ ++ if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY) ++ { ++ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("not a directory")); ++ goto err_out; ++ } ++ ++ err = get_root (data, &key_in, &tree, &type); ++ ++ if (err) ++ goto err_out; ++ ++ saved_tree = data->fs_tree; ++ data->fs_tree = tree; ++ err = find_path (data, subvol, &key_in, &tree, &type); ++ data->fs_tree = saved_tree; ++ ++ if (err) ++ goto err_out; ++ ++ if (key_in.object_id != grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0) ++ { ++ err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", subvol); ++ goto err_out; ++ } ++ ++ grub_btrfs_unmount (data); ++ grub_device_close (dev); ++ add_mountpoint (dirname, subvol, tree); ++ ++ return GRUB_ERR_NONE; ++ ++err_out: ++ ++ if (data) ++ grub_btrfs_unmount (data); ++ ++ if (dev) ++ grub_device_close (dev); ++ ++ return err; ++} ++ ++grub_uint64_t ++find_mtab_subvol_tree (const char *path, char **path_in_subvol) ++{ ++ grub_btrfs_mtab_t m, cm; ++ grub_uint64_t tree; ++ ++ if (!path || !path_in_subvol) ++ return 0; ++ ++ *path_in_subvol = NULL; ++ tree = 0; ++ cm = NULL; ++ ++ FOR_GRUB_MTAB (m) ++ { ++ if (grub_strncmp (path, m->path, grub_strlen (m->path)) == 0) ++ { ++ if (!cm) ++ cm = m; ++ else ++ if (grub_strcmp (m->path, cm->path) > 0) ++ cm = m; ++ } ++ } ++ ++ if (cm) ++ { ++ const char *s = path + grub_strlen (cm->path); ++ *path_in_subvol = (s[0] == '\0') ? grub_strdup ("/") : grub_strdup (s); ++ tree = cm->tree; ++ } ++ ++ return tree; ++} ++ + static grub_err_t + get_fs_root(struct grub_btrfs_data *data, grub_uint64_t tree, + grub_uint64_t objectid, grub_uint64_t offset, +@@ -2666,6 +2853,7 @@ static struct grub_fs grub_btrfs_fs = { + }; + + static grub_command_t cmd_info; ++static grub_command_t cmd_mount_subvol; + static grub_extcmd_t cmd_list_subvols; + + static char * +@@ -2729,6 +2917,9 @@ GRUB_MOD_INIT (btrfs) + cmd_info = grub_register_command("btrfs-info", grub_cmd_btrfs_info, + "DEVICE", + "Print BtrFS info about DEVICE."); ++ cmd_mount_subvol = grub_register_command("btrfs-mount-subvol", grub_cmd_btrfs_mount_subvol, ++ "DEVICE DIRECTORY SUBVOL", ++ "Set btrfs DEVICE the DIRECTORY a mountpoint of SUBVOL."); + cmd_list_subvols = grub_register_extcmd("btrfs-list-subvols", + grub_cmd_btrfs_list_subvols, 0, + "[-p|-n] [-o var] DEVICE", +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 5d50dd6f8dc..4c5a13022dc 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -107,6 +107,14 @@ struct btrfs_ioctl_search_key + grub_uint32_t unused[9]; + }; + ++struct btrfs_ioctl_search_header { ++ grub_uint64_t transid; ++ grub_uint64_t objectid; ++ grub_uint64_t offset; ++ grub_uint32_t type; ++ grub_uint32_t len; ++}; ++ + struct btrfs_ioctl_search_args { + struct btrfs_ioctl_search_key key; + grub_uint64_t buf[(4096 - sizeof(struct btrfs_ioctl_search_key)) +@@ -378,6 +386,109 @@ get_btrfs_fs_prefix (const char *mount_path) + + int use_relative_path_on_btrfs = 0; + ++static char * ++get_btrfs_subvol (const char *path) ++{ ++ struct btrfs_ioctl_ino_lookup_args args; ++ grub_uint64_t tree_id; ++ int fd = -1; ++ char *ret = NULL; ++ ++ fd = open (path, O_RDONLY); ++ ++ if (fd < 0) ++ return NULL; ++ ++ memset (&args, 0, sizeof(args)); ++ args.objectid = GRUB_BTRFS_TREE_ROOT_OBJECTID; ++ ++ if (ioctl (fd, BTRFS_IOC_INO_LOOKUP, &args) < 0) ++ goto error; ++ ++ tree_id = args.treeid; ++ ++ while (tree_id != GRUB_BTRFS_ROOT_VOL_OBJECTID) ++ { ++ struct btrfs_ioctl_search_args sargs; ++ struct grub_btrfs_root_backref *br; ++ struct btrfs_ioctl_search_header *search_header; ++ char *old; ++ grub_uint16_t len; ++ grub_uint64_t inode_id; ++ ++ memset (&sargs, 0, sizeof(sargs)); ++ ++ sargs.key.tree_id = 1; ++ sargs.key.min_objectid = tree_id; ++ sargs.key.max_objectid = tree_id; ++ ++ sargs.key.min_offset = 0; ++ sargs.key.max_offset = ~0ULL; ++ sargs.key.min_transid = 0; ++ sargs.key.max_transid = ~0ULL; ++ sargs.key.min_type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF; ++ sargs.key.max_type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF; ++ ++ sargs.key.nr_items = 1; ++ ++ if (ioctl (fd, BTRFS_IOC_TREE_SEARCH, &sargs) < 0) ++ goto error; ++ ++ if (sargs.key.nr_items == 0) ++ goto error; ++ ++ search_header = (struct btrfs_ioctl_search_header *)sargs.buf; ++ br = (struct grub_btrfs_root_backref *) (search_header + 1); ++ ++ len = grub_le_to_cpu16 (br->n); ++ inode_id = grub_le_to_cpu64 (br->inode_id); ++ tree_id = search_header->offset; ++ ++ old = ret; ++ ret = malloc (len + 1); ++ memcpy (ret, br->name, len); ++ ret[len] = '\0'; ++ ++ if (inode_id != GRUB_BTRFS_TREE_ROOT_OBJECTID) ++ { ++ char *s; ++ ++ memset(&args, 0, sizeof(args)); ++ args.treeid = search_header->offset; ++ args.objectid = inode_id; ++ ++ if (ioctl (fd, BTRFS_IOC_INO_LOOKUP, &args) < 0) ++ goto error; ++ ++ s = xasprintf ("%s%s", args.name, ret); ++ free (ret); ++ ret = s; ++ } ++ ++ if (old) ++ { ++ char *s = xasprintf ("%s/%s", ret, old); ++ free (ret); ++ free (old); ++ ret = s; ++ } ++ } ++ ++ close (fd); ++ return ret; ++ ++error: ++ ++ if (fd >= 0) ++ close (fd); ++ if (ret) ++ free (ret); ++ ++ return NULL; ++} ++ ++void (*grub_find_root_btrfs_mount_path_hook)(const char *mount_path); ++ + char ** + grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) + { +@@ -519,12 +630,15 @@ again: + else if (grub_strcmp (entries[i].fstype, "btrfs") == 0) + { + ret = grub_find_root_devices_from_btrfs (dir); +- fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); + if (use_relative_path_on_btrfs) + { +- if (fs_prefix) +- free (fs_prefix); + fs_prefix = xstrdup ("/"); ++ if (grub_find_root_btrfs_mount_path_hook) ++ grub_find_root_btrfs_mount_path_hook (entries[i].enc_path); ++ } ++ else ++ { ++ fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); + } + } + else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) +@@ -1150,6 +1264,34 @@ grub_util_get_grub_dev_os (const char *os_dev) + return grub_dev; + } + ++ ++char * ++grub_util_get_btrfs_subvol (const char *path, char **mount_path) ++{ ++ char *mp = NULL; ++ ++ if (mount_path) ++ *mount_path = NULL; ++ ++ auto void ++ mount_path_hook (const char *m) ++ { ++ mp = strdup (m); ++ } ++ ++ grub_find_root_btrfs_mount_path_hook = mount_path_hook; ++ grub_free (grub_find_root_devices_from_mountinfo (path, NULL)); ++ grub_find_root_btrfs_mount_path_hook = NULL; ++ ++ if (!mp) ++ return NULL; ++ ++ if (mount_path) ++ *mount_path = mp; ++ ++ return get_btrfs_subvol (mp); ++} ++ + char * + grub_make_system_path_relative_to_its_root_os (const char *path) + { +diff --git a/util/grub-install.c b/util/grub-install.c +index 0e807b09c36..3e718b9e3fb 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -1561,6 +1561,55 @@ main (int argc, char *argv[]) + prefix_drive = xasprintf ("(%s)", grub_drives[0]); + } + ++#ifdef __linux__ ++ ++ if (config.is_suse_btrfs_snapshot_enabled ++ && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0) ++ { ++ char *subvol = NULL; ++ char *mount_path = NULL; ++ char **rootdir_devices = NULL; ++ char *rootdir_path = grub_util_path_concat (2, "/", rootdir); ++ ++ if (grub_util_is_directory (rootdir_path)) ++ rootdir_devices = grub_guess_root_devices (rootdir_path); ++ ++ free (rootdir_path); ++ ++ if (rootdir_devices && rootdir_devices[0]) ++ if (grub_strcmp (rootdir_devices[0], grub_devices[0]) == 0) ++ subvol = grub_util_get_btrfs_subvol (platdir, &mount_path); ++ ++ if (subvol && mount_path) ++ { ++ char *def_subvol; ++ ++ def_subvol = grub_util_get_btrfs_subvol ("/", NULL); ++ ++ if (def_subvol) ++ { ++ if (!load_cfg_f) ++ load_cfg_f = grub_util_fopen (load_cfg, "wb"); ++ have_load_cfg = 1; ++ ++ if (grub_strcmp (subvol, def_subvol) != 0) ++ fprintf (load_cfg_f, "btrfs-mount-subvol ($root) %s %s\n", mount_path, subvol); ++ free (def_subvol); ++ } ++ } ++ ++ for (curdev = rootdir_devices; *curdev; curdev++) ++ free (*curdev); ++ if (rootdir_devices) ++ free (rootdir_devices); ++ if (subvol) ++ free (subvol); ++ if (mount_path) ++ free (mount_path); ++ } ++ ++#endif ++ + char mkimage_target[200]; + const char *core_name = NULL; + +diff --git a/include/grub/emu/getroot.h b/include/grub/emu/getroot.h +index 73fa2d34abb..9c642ae3fe3 100644 +--- a/include/grub/emu/getroot.h ++++ b/include/grub/emu/getroot.h +@@ -53,6 +53,11 @@ char ** + grub_find_root_devices_from_mountinfo (const char *dir, char **relroot); + #endif + ++#ifdef __linux__ ++char * ++grub_util_get_btrfs_subvol (const char *path, char **mount_path); ++#endif ++ + /* Devmapper functions provided by getroot_devmapper.c. */ + void + grub_util_pull_devmapper (const char *os_dev); diff --git a/0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch b/0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch new file mode 100644 index 0000000..f023ca2 --- /dev/null +++ b/0080-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrei Borzenkov +Date: Tue, 21 Jun 2016 16:44:17 +0000 +Subject: [PATCH] Fallback to old subvol name scheme to support old snapshot + config + +Ref: bsc#953538 +--- + grub-core/fs/btrfs.c | 32 +++++++++++++++++++++++++++++++- + 1 file changed, 31 insertions(+), 1 deletion(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 162723423ca..69c30e62354 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -1240,11 +1240,41 @@ lookup_root_by_name(struct grub_btrfs_data *data, const char *path) + return GRUB_ERR_NONE; + } + ++static grub_err_t ++lookup_root_by_name_fallback(struct grub_btrfs_data *data, const char *path) ++{ ++ grub_err_t err; ++ grub_uint64_t tree = 0; ++ grub_uint8_t type; ++ struct grub_btrfs_key key; ++ ++ err = find_path (data, path, &key, &tree, &type); ++ if (err) ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, "couldn't locate %s\n", path); ++ ++ if (key.object_id != grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK) || tree == 0) ++ return grub_error(GRUB_ERR_BAD_FILE_TYPE, "%s: not a subvolume\n", path); ++ ++ data->fs_tree = tree; ++ return GRUB_ERR_NONE; ++} ++ + static grub_err_t + btrfs_handle_subvol(struct grub_btrfs_data *data __attribute__ ((unused))) + { + if (btrfs_default_subvol) +- return lookup_root_by_name(data, btrfs_default_subvol); ++ { ++ grub_err_t err; ++ err = lookup_root_by_name(data, btrfs_default_subvol); ++ ++ /* Fallback to old schemes */ ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ { ++ err = GRUB_ERR_NONE; ++ return lookup_root_by_name_fallback(data, btrfs_default_subvol); ++ } ++ return err; ++ } + + if (btrfs_default_subvolid) + return lookup_root_by_id(data, btrfs_default_subvolid); diff --git a/0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch b/0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch new file mode 100644 index 0000000..f88b891 --- /dev/null +++ b/0081-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch @@ -0,0 +1,272 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 11 May 2017 08:56:57 +0000 +Subject: [PATCH] Grub not working correctly with btrfs snapshots (bsc#1026511) + +--- + grub-core/fs/btrfs.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 238 insertions(+) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 69c30e62354..ba99d04f8ed 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2867,6 +2867,238 @@ out: + return 0; + } + ++static grub_err_t ++grub_btrfs_get_parent_subvol_path (struct grub_btrfs_data *data, ++ grub_uint64_t child_id, ++ const char *child_path, ++ grub_uint64_t *parent_id, ++ char **path_out) ++{ ++ grub_uint64_t fs_root = 0; ++ struct grub_btrfs_key key_in = { ++ .object_id = child_id, ++ .type = GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF, ++ .offset = 0, ++ }, key_out; ++ struct grub_btrfs_root_ref *ref; ++ char *buf; ++ struct grub_btrfs_leaf_descriptor desc; ++ grub_size_t elemsize; ++ grub_disk_addr_t elemaddr; ++ grub_err_t err; ++ char *parent_path; ++ ++ *parent_id = 0; ++ *path_out = 0; ++ ++ err = lower_bound(data, &key_in, &key_out, data->sblock.root_tree, ++ &elemaddr, &elemsize, &desc, 0); ++ if (err) ++ return err; ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF || elemaddr == 0) ++ next(data, &desc, &elemaddr, &elemsize, &key_out); ++ ++ if (key_out.type != GRUB_BTRFS_ITEM_TYPE_ROOT_BACKREF) ++ { ++ free_iterator(&desc); ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("can't find root backrefs")); ++ } ++ ++ buf = grub_malloc(elemsize + 1); ++ if (!buf) ++ { ++ free_iterator(&desc); ++ return grub_errno; ++ } ++ ++ err = grub_btrfs_read_logical(data, elemaddr, buf, elemsize, 0); ++ if (err) ++ { ++ grub_free(buf); ++ free_iterator(&desc); ++ return err; ++ } ++ ++ buf[elemsize] = 0; ++ ref = (struct grub_btrfs_root_ref *)buf; ++ ++ err = get_fs_root(data, data->sblock.root_tree, grub_le_to_cpu64 (key_out.offset), ++ 0, &fs_root); ++ if (err) ++ { ++ grub_free(buf); ++ free_iterator(&desc); ++ return err; ++ } ++ ++ find_pathname(data, grub_le_to_cpu64 (ref->dirid), fs_root, ref->name, &parent_path); ++ ++ if (child_path) ++ { ++ *path_out = grub_xasprintf ("%s/%s", parent_path, child_path); ++ grub_free (parent_path); ++ } ++ else ++ *path_out = parent_path; ++ ++ *parent_id = grub_le_to_cpu64 (key_out.offset); ++ ++ grub_free(buf); ++ free_iterator(&desc); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_btrfs_get_default_subvolume_id (struct grub_btrfs_data *data, grub_uint64_t *id) ++{ ++ grub_err_t err; ++ grub_disk_addr_t elemaddr; ++ grub_size_t elemsize; ++ struct grub_btrfs_key key, key_out; ++ struct grub_btrfs_dir_item *direl = NULL; ++ const char *ctoken = "default"; ++ grub_size_t ctokenlen = sizeof ("default") - 1; ++ ++ *id = 0; ++ key.object_id = data->sblock.root_dir_objectid; ++ key.type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; ++ key.offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen)); ++ err = lower_bound (data, &key, &key_out, data->sblock.root_tree, &elemaddr, &elemsize, ++ NULL, 0); ++ if (err) ++ return err; ++ ++ if (key_cmp (&key, &key_out) != 0) ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found")); ++ ++ struct grub_btrfs_dir_item *cdirel; ++ direl = grub_malloc (elemsize + 1); ++ err = grub_btrfs_read_logical (data, elemaddr, direl, elemsize, 0); ++ if (err) ++ { ++ grub_free (direl); ++ return err; ++ } ++ for (cdirel = direl; ++ (grub_uint8_t *) cdirel - (grub_uint8_t *) direl ++ < (grub_ssize_t) elemsize; ++ cdirel = (void *) ((grub_uint8_t *) (direl + 1) ++ + grub_le_to_cpu16 (cdirel->n) ++ + grub_le_to_cpu16 (cdirel->m))) ++ { ++ if (ctokenlen == grub_le_to_cpu16 (cdirel->n) ++ && grub_memcmp (cdirel->name, ctoken, ctokenlen) == 0) ++ break; ++ } ++ if ((grub_uint8_t *) cdirel - (grub_uint8_t *) direl ++ >= (grub_ssize_t) elemsize) ++ { ++ grub_free (direl); ++ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found")); ++ return err; ++ } ++ ++ if (cdirel->key.type != GRUB_BTRFS_ITEM_TYPE_ROOT_ITEM) ++ { ++ grub_free (direl); ++ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("file not found")); ++ return err; ++ } ++ ++ *id = grub_le_to_cpu64 (cdirel->key.object_id); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_btrfs_get_default_subvol (struct grub_extcmd_context *ctxt, ++ int argc, char **argv) ++{ ++ char *devname; ++ grub_device_t dev; ++ struct grub_btrfs_data *data; ++ grub_err_t err; ++ grub_uint64_t id; ++ char *subvol = NULL; ++ grub_uint64_t subvolid = 0; ++ char *varname = NULL; ++ char *output = NULL; ++ int path_only = ctxt->state[1].set; ++ int num_only = ctxt->state[2].set; ++ ++ if (ctxt->state[0].set) ++ varname = ctxt->state[0].arg; ++ ++ if (argc < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); ++ ++ devname = grub_file_get_device_name(argv[0]); ++ if (!devname) ++ return grub_errno; ++ ++ dev = grub_device_open (devname); ++ grub_free (devname); ++ if (!dev) ++ return grub_errno; ++ ++ data = grub_btrfs_mount(dev); ++ if (!data) ++ { ++ grub_device_close (dev); ++ grub_dprintf ("btrfs", "failed to open fs\n"); ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ ++ err = grub_btrfs_get_default_subvolume_id (data, &subvolid); ++ if (err) ++ { ++ grub_btrfs_unmount (data); ++ grub_device_close (dev); ++ return err; ++ } ++ ++ id = subvolid; ++ while (id != GRUB_BTRFS_ROOT_VOL_OBJECTID) ++ { ++ grub_uint64_t parent_id; ++ char *path_out; ++ ++ err = grub_btrfs_get_parent_subvol_path (data, grub_cpu_to_le64 (id), subvol, &parent_id, &path_out); ++ if (err) ++ { ++ grub_btrfs_unmount (data); ++ grub_device_close (dev); ++ return err; ++ } ++ ++ if (subvol) ++ grub_free (subvol); ++ subvol = path_out; ++ id = parent_id; ++ } ++ ++ if (num_only && path_only) ++ output = grub_xasprintf ("%"PRIuGRUB_UINT64_T" /%s", subvolid, subvol); ++ else if (num_only) ++ output = grub_xasprintf ("%"PRIuGRUB_UINT64_T, subvolid); ++ else ++ output = grub_xasprintf ("/%s", subvol); ++ ++ if (varname) ++ grub_env_set(varname, output); ++ else ++ grub_printf ("%s\n", output); ++ ++ grub_free (output); ++ grub_free (subvol); ++ ++ grub_btrfs_unmount (data); ++ grub_device_close (dev); ++ ++ return GRUB_ERR_NONE; ++} ++ + static struct grub_fs grub_btrfs_fs = { + .name = "btrfs", + .fs_dir = grub_btrfs_dir, +@@ -2885,6 +3117,7 @@ static struct grub_fs grub_btrfs_fs = { + static grub_command_t cmd_info; + static grub_command_t cmd_mount_subvol; + static grub_extcmd_t cmd_list_subvols; ++static grub_extcmd_t cmd_get_default_subvol; + + static char * + subvolid_set_env (struct grub_env_var *var __attribute__ ((unused)), +@@ -2955,6 +3188,11 @@ GRUB_MOD_INIT (btrfs) + "[-p|-n] [-o var] DEVICE", + "Print list of BtrFS subvolumes on " + "DEVICE.", options); ++ cmd_get_default_subvol = grub_register_extcmd("btrfs-get-default-subvol", ++ grub_cmd_btrfs_get_default_subvol, 0, ++ "[-p|-n] [-o var] DEVICE", ++ "Print default BtrFS subvolume on " ++ "DEVICE.", options); + grub_register_variable_hook ("btrfs_subvol", subvol_get_env, + subvol_set_env); + grub_register_variable_hook ("btrfs_subvolid", subvolid_get_env, diff --git a/0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch b/0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch new file mode 100644 index 0000000..ccb1947 --- /dev/null +++ b/0082-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 1 Jun 2017 09:59:56 -0400 +Subject: [PATCH] Add grub_efi_allocate_pool() and grub_efi_free_pool() + wrappers. + +Signed-off-by: Peter Jones +--- + include/grub/efi/efi.h | 36 ++++++++++++++++++++++++++++++++---- + 1 file changed, 32 insertions(+), 4 deletions(-) + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 090c8621066..5e2b479daec 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -24,6 +24,10 @@ + #include + #include + ++/* Variables. */ ++extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table); ++extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle); ++ + /* Functions. */ + void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol, + void *registration); +@@ -60,6 +64,33 @@ EXPORT_FUNC(grub_efi_get_memory_map) (grub_efi_uintn_t *memory_map_size, + grub_efi_uintn_t *descriptor_size, + grub_efi_uint32_t *descriptor_version); + void grub_efi_memory_fini (void); ++ ++static inline grub_efi_status_t ++__attribute__((__unused__)) ++grub_efi_allocate_pool (grub_efi_memory_type_t pool_type, ++ grub_efi_uintn_t buffer_size, ++ void **buffer) ++{ ++ grub_efi_boot_services_t *b; ++ grub_efi_status_t status; ++ ++ b = grub_efi_system_table->boot_services; ++ status = efi_call_3 (b->allocate_pool, pool_type, buffer_size, buffer); ++ return status; ++} ++ ++static inline grub_efi_status_t ++__attribute__((__unused__)) ++grub_efi_free_pool (void *buffer) ++{ ++ grub_efi_boot_services_t *b; ++ grub_efi_status_t status; ++ ++ b = grub_efi_system_table->boot_services; ++ status = efi_call_1 (b->free_pool, buffer); ++ return status; ++} ++ + grub_efi_loaded_image_t *EXPORT_FUNC(grub_efi_get_loaded_image) (grub_efi_handle_t image_handle); + void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp); + char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp); +@@ -109,10 +140,7 @@ void grub_efi_init (void); + void grub_efi_fini (void); + void grub_efi_set_prefix (void); + +-/* Variables. */ +-extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table); +-extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle); +- ++/* More variables. */ + extern int EXPORT_VAR(grub_efi_is_finished); + + struct grub_net_card; diff --git a/0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch new file mode 100644 index 0000000..a9e1a2b --- /dev/null +++ b/0083-Use-grub_efi_.-memory-helpers-where-reasonable.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 1 Jun 2017 10:06:38 -0400 +Subject: [PATCH] Use grub_efi_...() memory helpers where reasonable. + +This uses grub_efi_allocate_pool(), grub_efi_free_pool(), and +grub_efi_free_pages() instead of open-coded efi_call_N() calls, so we +get more reasonable type checking. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/chainloader.c | 24 +++++++++--------------- + 1 file changed, 9 insertions(+), 15 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 5aa3a5dc7dd..3a724a9fcbf 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -65,7 +65,7 @@ grub_chainloader_unload (void) + + b = grub_efi_system_table->boot_services; + efi_call_1 (b->unload_image, image_handle); +- efi_call_2 (b->free_pages, address, pages); ++ grub_efi_free_pages (address, pages); + + grub_free (file_path); + grub_free (cmdline); +@@ -108,7 +108,7 @@ grub_chainloader_boot (void) + } + + if (exit_data) +- efi_call_1 (b->free_pool, exit_data); ++ grub_efi_free_pool (exit_data); + + grub_loader_unset (); + +@@ -506,10 +506,9 @@ grub_efi_get_media_file_path (grub_efi_device_path_t *dp) + static grub_efi_boolean_t + handle_image (void *data, grub_efi_uint32_t datasize) + { +- grub_efi_boot_services_t *b; + grub_efi_loaded_image_t *li, li_bak; + grub_efi_status_t efi_status; +- char *buffer = NULL; ++ void *buffer = NULL; + char *buffer_aligned = NULL; + grub_efi_uint32_t i; + struct grub_pe32_section_table *section; +@@ -520,8 +519,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) + int found_entry_point = 0; + int rc; + +- b = grub_efi_system_table->boot_services; +- + rc = read_header (data, datasize, &context); + if (rc < 0) + { +@@ -561,8 +558,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_dprintf ("chain", "image size is %08"PRIxGRUB_UINT64_T", datasize is %08x\n", + context.image_size, datasize); + +- efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, +- buffer_size, &buffer); ++ efi_status = grub_efi_allocate_pool (GRUB_EFI_LOADER_DATA, buffer_size, ++ &buffer); + + if (efi_status != GRUB_EFI_SUCCESS) + { +@@ -794,14 +791,14 @@ handle_image (void *data, grub_efi_uint32_t datasize) + + grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); + grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); +- efi_status = efi_call_1 (b->free_pool, buffer); ++ efi_status = grub_efi_free_pool (buffer); + + return 1; + + error_exit: + grub_dprintf ("chain", "error_exit: grub_errno: %d\n", grub_errno); + if (buffer) +- efi_call_1 (b->free_pool, buffer); ++ grub_efi_free_pool (buffer); + + return 0; + } +@@ -809,10 +806,7 @@ error_exit: + static grub_err_t + grub_secureboot_chainloader_unload (void) + { +- grub_efi_boot_services_t *b; +- +- b = grub_efi_system_table->boot_services; +- efi_call_2 (b->free_pages, address, pages); ++ grub_efi_free_pages (address, pages); + grub_free (file_path); + grub_free (cmdline); + cmdline = 0; +@@ -1079,7 +1073,7 @@ fail: + grub_free (file_path); + + if (address) +- efi_call_2 (b->free_pages, address, pages); ++ grub_efi_free_pages (address, pages); + + if (cmdline) + grub_free (cmdline); diff --git a/0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch new file mode 100644 index 0000000..d438465 --- /dev/null +++ b/0084-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 1 Jun 2017 10:07:50 -0400 +Subject: [PATCH] Add PRIxGRUB_EFI_STATUS and use it. + +This avoids syntax checkers getting confused about if it's llx or lx. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/chainloader.c | 3 ++- + include/grub/efi/api.h | 8 ++++++++ + 2 files changed, 10 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 3a724a9fcbf..f4ddbeda687 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -789,7 +789,8 @@ handle_image (void *data, grub_efi_uint32_t datasize) + efi_status = efi_call_2 (entry_point, grub_efi_image_handle, + grub_efi_system_table); + +- grub_dprintf ("chain", "entry_point returned %ld\n", efi_status); ++ grub_dprintf ("chain", "entry_point returned 0x%"PRIxGRUB_EFI_STATUS"\n", ++ efi_status); + grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); + efi_status = grub_efi_free_pool (buffer); + +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index d97cdf98c80..955973ed484 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -527,6 +527,14 @@ typedef grub_uint8_t grub_efi_char8_t; + typedef grub_uint16_t grub_efi_char16_t; + + typedef grub_efi_intn_t grub_efi_status_t; ++/* Make grub_efi_status_t reasonably printable. */ ++#if GRUB_CPU_SIZEOF_VOID_P == 8 ++#define PRIxGRUB_EFI_STATUS "lx" ++#define PRIdGRUB_EFI_STATUS "ld" ++#else ++#define PRIxGRUB_EFI_STATUS "llx" ++#define PRIdGRUB_EFI_STATUS "lld" ++#endif + + #define GRUB_EFI_ERROR_CODE(value) \ + ((((grub_efi_status_t) 1) << (sizeof (grub_efi_status_t) * 8 - 1)) | (value)) diff --git a/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch b/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch new file mode 100644 index 0000000..a53ecb4 --- /dev/null +++ b/0085-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 26 Jun 2017 12:42:57 -0400 +Subject: [PATCH] Don't use dynamic sized arrays since we don't build with + -std=c99 + +--- + grub-core/net/net.c | 17 ++++++++++++++--- + 1 file changed, 14 insertions(+), 3 deletions(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index f24f1fd63f6..5366e443d2a 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1853,14 +1853,25 @@ grub_net_search_configfile (char *config) + { + /* By the Client UUID. */ + +- char client_uuid_var[sizeof ("net_") + grub_strlen (inf->name) + +- sizeof ("_clientuuid") + 1]; +- grub_snprintf (client_uuid_var, sizeof (client_uuid_var), ++ char *client_uuid_var; ++ grub_size_t client_uuid_var_size; ++ ++ client_uuid_var_size = grub_snprintf (NULL, 0, ++ "net_%s_clientuuid", inf->name); ++ if (client_uuid_var_size <= 0) ++ continue; ++ client_uuid_var_size += 1; ++ client_uuid_var = grub_malloc(client_uuid_var_size); ++ if (!client_uuid_var) ++ continue; ++ grub_snprintf (client_uuid_var, client_uuid_var_size, + "net_%s_clientuuid", inf->name); + + const char *client_uuid; + client_uuid = grub_env_get (client_uuid_var); + ++ grub_free(client_uuid_var); ++ + if (client_uuid) + { + grub_strcpy (suffix, client_uuid); diff --git a/0086-don-t-ignore-const.patch b/0086-don-t-ignore-const.patch new file mode 100644 index 0000000..81a2025 --- /dev/null +++ b/0086-don-t-ignore-const.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 26 Jun 2017 12:43:22 -0400 +Subject: [PATCH] don't ignore const + +--- + grub-core/net/tftp.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index e6d831f1bc9..0c02a00255b 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -307,7 +307,7 @@ static void + grub_normalize_filename (char *normalized, const char *filename) + { + char *dest = normalized; +- char *src = filename; ++ const char *src = filename; + + while (*src != '\0') + { diff --git a/0087-don-t-use-int-for-efi-status.patch b/0087-don-t-use-int-for-efi-status.patch new file mode 100644 index 0000000..9cdf63e --- /dev/null +++ b/0087-don-t-use-int-for-efi-status.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 26 Jun 2017 12:44:59 -0400 +Subject: [PATCH] don't use int for efi status + +--- + grub-core/kern/efi/efi.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index a1af9b46559..2cf6a5ad526 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -166,7 +166,7 @@ grub_reboot (void) + void + grub_exit (int retval) + { +- int rc = GRUB_EFI_LOAD_ERROR; ++ grub_efi_status_t rc = GRUB_EFI_LOAD_ERROR; + + if (retval == 0) + rc = GRUB_EFI_SUCCESS; diff --git a/0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch b/0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch new file mode 100644 index 0000000..993034f --- /dev/null +++ b/0088-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 26 Jun 2017 12:46:23 -0400 +Subject: [PATCH] make GRUB_MOD_INIT() declare its function prototypes. + +--- + include/grub/dl.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/include/grub/dl.h b/include/grub/dl.h +index f03c03561a1..90dc9bb1017 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -54,6 +54,7 @@ grub_mod_fini (void) + + #define GRUB_MOD_INIT(name) \ + static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ ++extern void grub_##name##_init (void); \ + void \ + grub_##name##_init (void) { grub_mod_init (0); } \ + static void \ +@@ -61,6 +62,7 @@ grub_mod_init (grub_dl_t mod __attribute__ ((unused))) + + #define GRUB_MOD_FINI(name) \ + static void grub_mod_fini (void) __attribute__ ((used)); \ ++extern void grub_##name##_fini (void); \ + void \ + grub_##name##_fini (void) { grub_mod_fini (); } \ + static void \ diff --git a/0089-editenv-handle-relative-symlinks.patch b/0089-editenv-handle-relative-symlinks.patch new file mode 100644 index 0000000..06adca7 --- /dev/null +++ b/0089-editenv-handle-relative-symlinks.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jonathan Lebon +Date: Mon, 14 Aug 2017 14:37:20 -0400 +Subject: [PATCH] editenv: handle relative symlinks + +Handle symlinks with targets relative to the containing dir. This +ensures that the rename operation does not depend on the cwd. + +Resolves: rhbz#1479960 + +Signed-off-by: Jonathan Lebon +--- + util/editenv.c | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/util/editenv.c b/util/editenv.c +index e61dc1283a4..1f7f6f3ae18 100644 +--- a/util/editenv.c ++++ b/util/editenv.c +@@ -28,6 +28,7 @@ + + #include + #include ++#include + + #define DEFAULT_ENVBLK_SIZE 1024 + +@@ -88,9 +89,20 @@ grub_util_create_envblk_file (const char *name) + continue; + } + +- free (rename_target); + linkbuf[retsize] = '\0'; +- rename_target = linkbuf; ++ if (linkbuf[0] == '/') ++ { ++ free (rename_target); ++ rename_target = linkbuf; ++ } ++ else ++ { ++ char *dbuf = xstrdup (rename_target); ++ const char *dir = dirname (dbuf); ++ free (rename_target); ++ rename_target = xasprintf("%s/%s", dir, linkbuf); ++ free (dbuf); ++ } + } + + int rc = grub_util_rename (namenew, rename_target); diff --git a/0090-Make-libgrub.pp-depend-on-config-util.h.patch b/0090-Make-libgrub.pp-depend-on-config-util.h.patch new file mode 100644 index 0000000..9a7d85f --- /dev/null +++ b/0090-Make-libgrub.pp-depend-on-config-util.h.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 23 Aug 2017 10:37:27 -0400 +Subject: [PATCH] Make libgrub.pp depend on config-util.h + +If you build with "make -j48" a lot, sometimes you see: + +gcc -E -DHAVE_CONFIG_H -I. -I.. -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I../grub-core/lib/minilzo -I../grub-core/lib/xzembed -DMINILZO_HAVE_CONFIG_H -Wall -W -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./include -DGRUB_FILE=\"grub_script.tab.h\" -I. -I.. -I. -I.. -I../include -I./include -I../grub-core/lib/libgcrypt-grub/src/ -I./grub-core/gnulib -I../grub-core/gnulib -I/builddir/build/BUILD/grub-2.02/grub-aarch64-efi-2.02 -D_FILE_OFFSET_BITS=64 \ + -D'GRUB_MOD_INIT(x)=@MARKER@x@' grub_script.tab.h grub_script.yy.h ../grub-core/commands/blocklist.c ../grub-core/commands/macbless.c ../grub-core/commands/xnu_uuid.c ../grub-core/commands/testload.c ../grub-core/commands/ls.c ../grub-core/disk/dmraid_nvidia.c ../grub-core/disk/loopback.c ../grub-core/disk/lvm.c ../grub-core/disk/mdraid_linux.c ../grub-core/disk/mdraid_linux_be.c ../grub-core/disk/mdraid1x_linux.c ../grub-core/disk/raid5_recover.c ../grub-core/disk/raid6_recover.c ../grub-core/font/font.c ../grub-core/gfxmenu/font.c ../grub-core/normal/charset.c ../grub-core/video/fb/fbblit.c ../grub-core/video/fb/fbutil.c ../grub-core/video/fb/fbfill.c ../grub-core/video/fb/video_fb.c ../grub-core/video/video.c ../grub-core/video/capture.c ../grub-core/video/colors.c ../grub-core/unidata.c ../grub-core/io/bufio.c ../grub-core/fs/affs.c ../grub-core/fs/afs.c ../grub-core/fs/bfs.c ../grub-core/fs/btrfs.c ../grub-core/fs/cbfs.c ../grub-core/fs/cpio.c ../grub-core/fs/cpio_be.c ../grub-core/fs/odc.c ../grub-core/fs/newc.c ../grub-core/fs/ext2.c ../grub-core/fs/fat.c ../grub-core/fs/exfat.c ../grub-core/fs/fshelp.c ../grub-core/fs/hfs.c ../grub-core/fs/hfsplus.c ../grub-core/fs/hfspluscomp.c ../grub-core/fs/iso9660.c ../grub-core/fs/jfs.c ../grub-core/fs/minix.c ../grub-core/fs/minix2.c ../grub-core/fs/minix3.c ../grub-core/fs/minix_be.c ../grub-core/fs/minix2_be.c ../grub-core/fs/minix3_be.c ../grub-core/fs/nilfs2.c ../grub-core/fs/ntfs.c ../grub-core/fs/ntfscomp.c ../grub-core/fs/reiserfs.c ../grub-core/fs/romfs.c ../grub-core/fs/sfs.c ../grub-core/fs/squash4.c ../grub-core/fs/tar.c ../grub-core/fs/udf.c ../grub-core/fs/ufs2.c ../grub-core/fs/ufs.c ../grub-core/fs/ufs_be.c ../grub-core/fs/xfs.c ../grub-core/fs/zfs/zfscrypt.c ../grub-core/fs/zfs/zfs.c ../grub-core/fs/zfs/zfsinfo.c ../grub-core/fs/zfs/zfs_lzjb.c ../grub-core/fs/zfs/zfs_lz4.c ../grub-core/fs/zfs/zfs_sha256.c ../grub-core/fs/zfs/zfs_fletcher.c ../grub-core/lib/envblk.c ../grub-core/lib/hexdump.c ../grub-core/lib/LzFind.c ../grub-core/lib/LzmaEnc.c ../grub-core/lib/crc.c ../grub-core/lib/adler32.c ../grub-core/lib/crc64.c ../grub-core/normal/datetime.c ../grub-core/normal/misc.c ../grub-core/partmap/acorn.c ../grub-core/partmap/amiga.c ../grub-core/partmap/apple.c ../grub-core/partmap/sun.c ../grub-core/partmap/plan.c ../grub-core/partmap/dvh.c ../grub-core/partmap/sunpc.c ../grub-core/partmap/bsdlabel.c ../grub-core/partmap/dfly.c ../grub-core/script/function.c ../grub-core/script/lexer.c ../grub-core/script/main.c ../grub-core/script/script.c ../grub-core/script/argv.c ../grub-core/io/gzio.c ../grub-core/io/xzio.c ../grub-core/io/lzopio.c ../grub-core/kern/ia64/dl_helper.c ../grub-core/kern/arm/dl_helper.c ../grub-core/kern/arm64/dl_helper.c ../grub-core/lib/minilzo/minilzo.c ../grub-core/lib/xzembed/xz_dec_bcj.c ../grub-core/lib/xzembed/xz_dec_lzma2.c ../grub-core/lib/xzembed/xz_dec_stream.c ../util/misc.c ../grub-core/kern/command.c ../grub-core/kern/device.c ../grub-core/kern/disk.c ../grub-core/lib/disk.c ../util/getroot.c ../grub-core/osdep/unix/getroot.c ../grub-core/osdep/getroot.c ../grub-core/osdep/devmapper/getroot.c ../grub-core/osdep/relpath.c ../grub-core/kern/emu/hostdisk.c ../grub-core/osdep/devmapper/hostdisk.c ../grub-core/osdep/hostdisk.c ../grub-core/osdep/unix/hostdisk.c ../grub-core/osdep/exec.c ../grub-core/osdep/sleep.c ../grub-core/osdep/password.c ../grub-core/kern/emu/misc.c ../grub-core/kern/emu/mm.c ../grub-core/kern/env.c ../grub-core/kern/err.c ../grub-core/kern/file.c ../grub-core/kern/fs.c ../grub-core/kern/list.c ../grub-core/kern/misc.c ../grub-core/kern/partition.c ../grub-core/lib/crypto.c ../grub-core/disk/luks.c ../grub-core/disk/geli.c ../grub-core/disk/cryptodisk.c ../grub-core/disk/AFSplitter.c ../grub-core/lib/pbkdf2.c ../grub-core/commands/extcmd.c ../grub-core/lib/arg.c ../grub-core/disk/ldm.c ../grub-core/disk/diskfilter.c ../grub-core/partmap/gpt.c ../grub-core/partmap/msdos.c ../grub-core/fs/proc.c ../grub-core/fs/archelp.c > libgrub.pp || (rm -f libgrub.pp; exit 1) +rm -f stamp-h1 +touch ../config-util.h.in +cd . && /bin/sh ./config.status config-util.h +config.status: creating config-util.h +In file included from ../include/grub/mm.h:25:0, + from ../include/grub/disk.h:29, + from ../include/grub/file.h:26, + from ../grub-core/fs/btrfs.c:21: +./config.h:38:10: fatal error: ./config-util.h: No such file or directory + #include + ^~~~~~~~~~~~~~~ +compilation terminated. +make: *** [Makefile:13098: libgrub.pp] Error 1 + +This is because libgrub.pp is built with -DGRUB_UTIL=1, which means +it'll try to include config-util.h, but a parallel make is actually +building that file. I think. + +Signed-off-by: Peter Jones +--- + Makefile.am | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile.am b/Makefile.am +index 1f4bb9b8c5a..bf9c1ba64c9 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -37,7 +37,7 @@ grub_script.yy.c: grub_script.yy.h + CLEANFILES += grub_script.yy.c grub_script.yy.h + + # For libgrub.a +-libgrub.pp: grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) ++libgrub.pp: config-util.h grub_script.tab.h grub_script.yy.h $(libgrubmods_a_SOURCES) $(libgrubkern_a_SOURCES) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgrubmods_a_CPPFLAGS) $(libgrubkern_a_CPPFLAGS) $(CPPFLAGS) \ + -D'GRUB_MOD_INIT(x)=@MARKER@x@' $^ > $@ || (rm -f $@; exit 1) + CLEANFILES += libgrub.pp diff --git a/0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch b/0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch new file mode 100644 index 0000000..1e8743a --- /dev/null +++ b/0091-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 20 Apr 2017 13:29:06 -0400 +Subject: [PATCH] Don't guess /boot/efi/ as HFS+ on ppc machines in + grub-install + +This should never be trying this, and since we've consolidated the +grubenv to always be on /boot/efi/EFI/fedora/, this code causes it to +always make the wrong decision. + +Resolves: rhbz#1484474 + +Signed-off-by: Peter Jones +--- + util/grub-install.c | 12 +----------- + 1 file changed, 1 insertion(+), 11 deletions(-) + +diff --git a/util/grub-install.c b/util/grub-install.c +index 3e718b9e3fb..37fcdac12cc 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -1182,18 +1182,8 @@ main (int argc, char *argv[]) + char *d; + + is_guess = 1; +- d = grub_util_path_concat (2, bootdir, "macppc"); +- if (!grub_util_is_directory (d)) +- { +- free (d); +- d = grub_util_path_concat (2, bootdir, "efi"); +- } + /* Find the Mac HFS(+) System Partition. */ +- if (!grub_util_is_directory (d)) +- { +- free (d); +- d = grub_util_path_concat (2, bootdir, "EFI"); +- } ++ d = grub_util_path_concat (2, bootdir, "macppc"); + if (!grub_util_is_directory (d)) + { + free (d); diff --git a/0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch b/0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch new file mode 100644 index 0000000..c8e8c4a --- /dev/null +++ b/0092-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jul 2019 14:31:19 +0200 +Subject: [PATCH] 20_linux_xen: load xen or multiboot{,2} modules as needed. + +Signed-off-by: Peter Jones +--- + util/grub.d/20_linux_xen.in | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in +index 1519ec692fe..9aa23bc7d51 100644 +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -136,6 +136,8 @@ linux_entry () + else + xen_rm_opts="no-real-mode edd=off" + fi ++ insmod ${module_loader} ++ insmod ${xen_loader} + ${xen_loader} ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts} + echo '$(echo "$lmessage" | grub_quote)' + ${module_loader} ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args} +@@ -149,6 +151,7 @@ EOF + done + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' ++ insmod ${module_loader} + ${module_loader} --nounzip $(echo $initrd_path) + EOF + fi diff --git a/0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch b/0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch new file mode 100644 index 0000000..acfb116 --- /dev/null +++ b/0093-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch @@ -0,0 +1,211 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 7 Nov 2017 17:12:17 -0500 +Subject: [PATCH] Make pmtimer tsc calibration not take 51 seconds to fail. + +On my laptop running at 2.4GHz, if I run a VM where tsc calibration +using pmtimer will fail presuming a broken pmtimer, it takes ~51 seconds +to do so (as measured with the stopwatch on my phone), with a tsc delta +of 0x1cd1c85300, or around 125 billion cycles. + +If instead of trying to wait for 5-200ms to show up on the pmtimer, we try +to wait for 5-200us, it decides it's broken in ~0x2626aa0 TSCs, aka ~2.4 +million cycles, or more or less instantly. + +Additionally, this reading the pmtimer was returning 0xffffffff anyway, +and that's obviously an invalid return. I've added a check for that and +0 so we don't bother waiting for the test if what we're seeing is dead +pins with no response at all. + +If "debug" is includes "pmtimer", you will see one of the following +three outcomes. If pmtimer gives all 0 or all 1 bits, you will see: + +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 1 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 2 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 3 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 4 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 5 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 6 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 7 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 8 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 9 +kern/i386/tsc_pmtimer.c:77: pmtimer: 0xffffff bad_reads: 10 +kern/i386/tsc_pmtimer.c:78: timer is broken; giving up. + +This outcome was tested using qemu+kvm with UEFI (OVMF) firmware and +these options: -machine pc-q35-2.10 -cpu Broadwell-noTSX + +If pmtimer gives any other bit patterns but is not actually marching +forward fast enough to use for clock calibration, you will see: + +kern/i386/tsc_pmtimer.c:121: pmtimer delta is 0x0 (1904 iterations) +kern/i386/tsc_pmtimer.c:124: tsc delta is implausible: 0x2626aa0 + +This outcome was tested using grub compiled with GRUB_PMTIMER_IGNORE_BAD_READS +defined (so as not to trip the bad read test) using qemu+kvm with UEFI +(OVMF) firmware, and these options: -machine pc-q35-2.10 -cpu Broadwell-noTSX + +If pmtimer actually works, you'll see something like: + +kern/i386/tsc_pmtimer.c:121: pmtimer delta is 0x0 (1904 iterations) +kern/i386/tsc_pmtimer.c:124: tsc delta is implausible: 0x2626aa0 + +This outcome was tested using qemu+kvm with UEFI (OVMF) firmware, and +these options: -machine pc-i440fx-2.4 -cpu Broadwell-noTSX + +I've also tested this outcome on a real Intel Xeon E3-1275v3 on an Intel +Server Board S1200V3RPS using the SDV.RP.B8 "Release" build here: +https://firmware.intel.com/sites/default/files/UEFIDevKit_S1200RP_vB8.zip + +Signed-off-by: Peter Jones +--- + grub-core/kern/i386/tsc_pmtimer.c | 109 +++++++++++++++++++++++++++++++------- + 1 file changed, 89 insertions(+), 20 deletions(-) + +diff --git a/grub-core/kern/i386/tsc_pmtimer.c b/grub-core/kern/i386/tsc_pmtimer.c +index c9c36169978..ca15c3aacd7 100644 +--- a/grub-core/kern/i386/tsc_pmtimer.c ++++ b/grub-core/kern/i386/tsc_pmtimer.c +@@ -28,40 +28,101 @@ + #include + #include + ++/* ++ * Define GRUB_PMTIMER_IGNORE_BAD_READS if you're trying to test a timer that's ++ * present but doesn't keep time well. ++ */ ++// #define GRUB_PMTIMER_IGNORE_BAD_READS ++ + grub_uint64_t + grub_pmtimer_wait_count_tsc (grub_port_t pmtimer, + grub_uint16_t num_pm_ticks) + { + grub_uint32_t start; +- grub_uint32_t last; +- grub_uint32_t cur, end; ++ grub_uint64_t cur, end; + grub_uint64_t start_tsc; + grub_uint64_t end_tsc; +- int num_iter = 0; ++ unsigned int num_iter = 0; ++#ifndef GRUB_PMTIMER_IGNORE_BAD_READS ++ int bad_reads = 0; ++#endif + +- start = grub_inl (pmtimer) & 0xffffff; +- last = start; ++ /* ++ * Some timers are 24-bit and some are 32-bit, but it doesn't make much ++ * difference to us. Caring which one we have isn't really worth it since ++ * the low-order digits will give us enough data to calibrate TSC. So just ++ * mask the top-order byte off. ++ */ ++ cur = start = grub_inl (pmtimer) & 0xffffffUL; + end = start + num_pm_ticks; + start_tsc = grub_get_tsc (); + while (1) + { +- cur = grub_inl (pmtimer) & 0xffffff; +- if (cur < last) +- cur |= 0x1000000; +- num_iter++; ++ cur &= 0xffffffffff000000ULL; ++ cur |= grub_inl (pmtimer) & 0xffffffUL; ++ ++ end_tsc = grub_get_tsc(); ++ ++#ifndef GRUB_PMTIMER_IGNORE_BAD_READS ++ /* ++ * If we get 10 reads in a row that are obviously dead pins, there's no ++ * reason to do this thousands of times. ++ */ ++ if (cur == 0xffffffUL || cur == 0) ++ { ++ bad_reads++; ++ grub_dprintf ("pmtimer", ++ "pmtimer: 0x%"PRIxGRUB_UINT64_T" bad_reads: %d\n", ++ cur, bad_reads); ++ grub_dprintf ("pmtimer", "timer is broken; giving up.\n"); ++ ++ if (bad_reads == 10) ++ return 0; ++ } ++#endif ++ ++ if (cur < start) ++ cur += 0x1000000; ++ + if (cur >= end) + { +- end_tsc = grub_get_tsc (); ++ grub_dprintf ("pmtimer", "pmtimer delta is 0x%"PRIxGRUB_UINT64_T"\n", ++ cur - start); ++ grub_dprintf ("pmtimer", "tsc delta is 0x%"PRIxGRUB_UINT64_T"\n", ++ end_tsc - start_tsc); + return end_tsc - start_tsc; + } +- /* Check for broken PM timer. +- 50000000 TSCs is between 5 ms (10GHz) and 200 ms (250 MHz) +- if after this time we still don't have 1 ms on pmtimer, then +- pmtimer is broken. ++ ++ /* ++ * Check for broken PM timer. 1ms at 10GHz should be 1E+7 TSCs; at ++ * 250MHz it should be 2.5E6. So if after 4E+7 TSCs on a 10GHz machine, ++ * we should have seen pmtimer show 4ms of change (i.e. cur =~ ++ * start+14320); on a 250MHz machine that should be 16ms (start+57280). ++ * If after this a time we still don't have 1ms on pmtimer, then pmtimer ++ * is broken. ++ * ++ * Likewise, if our code is perfectly efficient and introduces no delays ++ * whatsoever, on a 10GHz system we should see a TSC delta of 3580 in ++ * ~3580 iterations. On a 250MHz machine that should be ~900 iterations. ++ * ++ * With those factors in mind, there are two limits here. There's a hard ++ * limit here at 8x our desired pm timer delta, picked as an arbitrarily ++ * large value that's still not a lot of time to humans, because if we ++ * get that far this is either an implausibly fast machine or the pmtimer ++ * is not running. And there's another limit on 4x our 10GHz tsc delta ++ * without seeing cur converge on our target value. + */ +- if ((num_iter & 0xffffff) == 0 && grub_get_tsc () - start_tsc > 5000000) { +- return 0; +- } ++ if ((++num_iter > (grub_uint32_t)num_pm_ticks << 3UL) || ++ end_tsc - start_tsc > 40000000) ++ { ++ grub_dprintf ("pmtimer", ++ "pmtimer delta is 0x%"PRIxGRUB_UINT64_T" (%u iterations)\n", ++ cur - start, num_iter); ++ grub_dprintf ("pmtimer", ++ "tsc delta is implausible: 0x%"PRIxGRUB_UINT64_T"\n", ++ end_tsc - start_tsc); ++ return 0; ++ } + } + } + +@@ -74,12 +135,20 @@ grub_tsc_calibrate_from_pmtimer (void) + + fadt = grub_acpi_find_fadt (); + if (!fadt) +- return 0; ++ { ++ grub_dprintf ("pmtimer", "No FADT found; not using pmtimer.\n"); ++ return 0; ++ } + pmtimer = fadt->pmtimer; + if (!pmtimer) +- return 0; ++ { ++ grub_dprintf ("pmtimer", "FADT does not specify pmtimer; skipping.\n"); ++ return 0; ++ } + +- /* It's 3.579545 MHz clock. Wait 1 ms. */ ++ /* ++ * It's 3.579545 MHz clock. Wait 1 ms. ++ */ + tsc_diff = grub_pmtimer_wait_count_tsc (pmtimer, 3580); + if (tsc_diff == 0) + return 0; diff --git a/0094-align-struct-efi_variable-better.patch b/0094-align-struct-efi_variable-better.patch new file mode 100644 index 0000000..0afd935 --- /dev/null +++ b/0094-align-struct-efi_variable-better.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 27 Feb 2018 13:55:35 -0500 +Subject: [PATCH] align struct efi_variable better... + +--- + include/grub/efiemu/runtime.h | 2 +- + include/grub/types.h | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) + +diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h +index 36d2dedf47e..9d93ba88bac 100644 +--- a/include/grub/efiemu/runtime.h ++++ b/include/grub/efiemu/runtime.h +@@ -33,5 +33,5 @@ struct efi_variable + grub_uint32_t namelen; + grub_uint32_t size; + grub_efi_uint32_t attributes; +-} GRUB_PACKED; ++} GRUB_PACKED GRUB_ALIGNED(8); + #endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */ +diff --git a/include/grub/types.h b/include/grub/types.h +index 035a4b528fc..2fc4be4039a 100644 +--- a/include/grub/types.h ++++ b/include/grub/types.h +@@ -29,6 +29,7 @@ + #else + #define GRUB_PACKED __attribute__ ((packed)) + #endif ++#define GRUB_ALIGNED(x) __attribute__((aligned (x))) + + #ifdef GRUB_BUILD + # define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P diff --git a/0095-Add-BLS-support-to-grub-mkconfig.patch b/0095-Add-BLS-support-to-grub-mkconfig.patch new file mode 100644 index 0000000..70277ef --- /dev/null +++ b/0095-Add-BLS-support-to-grub-mkconfig.patch @@ -0,0 +1,741 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 9 Dec 2016 15:40:29 -0500 +Subject: [PATCH] Add BLS support to grub-mkconfig + +GRUB now has BootLoaderSpec support, the user can choose to use this by +setting GRUB_ENABLE_BLSCFG to true in /etc/default/grub. On this setup, +the boot menu entries are not added to the grub.cfg, instead BLS config +files are parsed by blscfg command and the entries created dynamically. + +A 10_linux_bls grub.d snippet to generate menu entries from BLS files +is also added that can be used on platforms where the bootloader doesn't +have BLS support and only can parse a normal grub configuration file. + +Portions of the 10_linux_bls were taken from the ostree-grub-generator +script that's included in the OSTree project. + +Fixes to support multi-devices and generate a BLS section even if no +kernels are found in the boot directory were proposed by Yclept Nemo +and Tom Gundersen respectively. + +Signed-off-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +--- + Makefile.util.def | 7 + + util/grub-mkconfig.8 | 4 + + util/grub-mkconfig.in | 9 +- + util/grub-mkconfig_lib.in | 20 +- + util/grub.d/10_linux.in | 67 ++++++- + util/grub.d/10_linux_bls.in | 478 ++++++++++++++++++++++++++++++++++++++++++++ + 6 files changed, 580 insertions(+), 5 deletions(-) + create mode 100644 util/grub.d/10_linux_bls.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 2215cc759c0..a61613656d1 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -499,6 +499,13 @@ script = { + condition = COND_HOST_LINUX; + }; + ++script = { ++ name = '10_linux_bls'; ++ common = util/grub.d/10_linux_bls.in; ++ installdir = grubconf; ++ condition = COND_HOST_LINUX; ++}; ++ + script = { + name = '10_xnu'; + common = util/grub.d/10_xnu.in; +diff --git a/util/grub-mkconfig.8 b/util/grub-mkconfig.8 +index a2d1f577b9b..434fa4deda4 100644 +--- a/util/grub-mkconfig.8 ++++ b/util/grub-mkconfig.8 +@@ -13,5 +13,9 @@ + \fB--output\fR=\fIFILE\fR + Write generated output to \fIFILE\fR. + ++.TP ++\fB--no-grubenv-update\fR ++Do not update variables in the grubenv file. ++ + .SH SEE ALSO + .BR "info grub" +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 4649e92eb0f..2601bdc0711 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -50,6 +50,8 @@ grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@" + export TEXTDOMAIN=@PACKAGE@ + export TEXTDOMAINDIR="@localedir@" + ++export GRUB_GRUBENV_UPDATE="yes" ++ + . "${pkgdatadir}/grub-mkconfig_lib" + + # Usage: usage +@@ -59,6 +61,7 @@ usage () { + gettext "Generate a grub config file"; echo + echo + print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")" ++ print_option_help "--no-grubenv-update" "$(gettext "do not update variables in the grubenv file")" + print_option_help "-h, --help" "$(gettext "print this message and exit")" + print_option_help "-v, --version" "$(gettext "print the version information and exit")" + echo +@@ -94,6 +97,9 @@ do + --output=*) + grub_cfg=`echo "$option" | sed 's/--output=//'` + ;; ++ --no-grubenv-update) ++ GRUB_GRUBENV_UPDATE="no" ++ ;; + -*) + gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 + usage +@@ -259,7 +265,8 @@ export GRUB_DEFAULT \ + GRUB_OS_PROBER_SKIP_LIST \ + GRUB_DISABLE_SUBMENU \ + GRUB_DEFAULT_DTB \ +- SUSE_BTRFS_SNAPSHOT_BOOTING ++ SUSE_BTRFS_SNAPSHOT_BOOTING \ ++ GRUB_ENABLE_BLSCFG + + if test "x${grub_cfg}" != "x"; then + rm -f "${grub_cfg}.new" +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index b3aae534ddc..bc11df2bd84 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -30,6 +30,9 @@ fi + if test "x$grub_file" = x; then + grub_file="${bindir}/@grub_file@" + fi ++if test "x$grub_editenv" = x; then ++ grub_editenv="${bindir}/@grub_editenv@" ++fi + if test "x$grub_mkrelpath" = x; then + grub_mkrelpath="${bindir}/@grub_mkrelpath@" + fi +@@ -125,8 +128,19 @@ EOF + fi + } + ++prepare_grub_to_access_device_with_variable () ++{ ++ device_variable="$1" ++ shift ++ prepare_grub_to_access_device "$@" ++ unset "device_variable" ++} ++ + prepare_grub_to_access_device () + { ++ if [ -z "$device_variable" ]; then ++ device_variable="root" ++ fi + old_ifs="$IFS" + IFS=' + ' +@@ -161,14 +175,14 @@ prepare_grub_to_access_device () + # otherwise set root as per value in device.map. + fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`" + if [ "x$fs_hint" != x ]; then +- echo "set root='$fs_hint'" ++ echo "set ${device_variable}='$fs_hint'" + fi + if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device $@ --target=fs_uuid 2> /dev/null`" ; then + hints="`"${grub_probe}" --device $@ --target=hints_string 2> /dev/null`" || hints= + echo "if [ x\$feature_platform_search_hint = xy ]; then" +- echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}" ++ echo " search --no-floppy --fs-uuid --set=${device_variable} ${hints} ${fs_uuid}" + echo "else" +- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" ++ echo " search --no-floppy --fs-uuid --set=${device_variable} ${fs_uuid}" + echo "fi" + fi + IFS="$old_ifs" +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 5cab299dc08..301594a0c9e 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -82,6 +82,67 @@ case x"$GRUB_FS" in + ;; + esac + ++populate_header_warn() ++{ ++cat <$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then +@@ -224,6 +286,7 @@ is_top_level=true + while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + gettext_printf "Found linux image: %s\n" "$linux" >&2 ++ + basename=`basename $linux` + dirname=`dirname $linux` + rel_dirname=`make_system_path_relative_to_its_root $dirname` +@@ -262,7 +325,9 @@ while [ "x$list" != "x" ] ; do + for i in ${initrd}; do + initrd_display="${initrd_display} ${dirname}/${i}" + done +- gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 ++ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then ++ gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 ++ fi + fi + + fdt= +diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in +new file mode 100644 +index 00000000000..1b7536435f1 +--- /dev/null ++++ b/util/grub.d/10_linux_bls.in +@@ -0,0 +1,478 @@ ++#! /bin/sh ++set -e ++ ++# grub-mkconfig helper script. ++# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. ++# ++# GRUB is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# GRUB is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GRUB. If not, see . ++ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++. "$pkgdatadir/grub-mkconfig_lib" ++ ++export TEXTDOMAIN=@PACKAGE@ ++export TEXTDOMAINDIR="@localedir@" ++ ++CLASS="--class gnu-linux --class gnu --class os --unrestricted" ++ ++if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then ++ OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})" ++ CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}" ++else ++ OS="${GRUB_DISTRIBUTOR}" ++ CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" ++fi ++ ++# loop-AES arranges things so that /dev/loop/X can be our root device, but ++# the initrds that Linux uses don't like that. ++case ${GRUB_DEVICE} in ++ /dev/loop/*|/dev/loop[0-9]) ++ GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` ++ ;; ++esac ++ ++# Default to disabling partition uuid support to maintian compatibility with ++# older kernels. ++GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} ++ ++# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter ++# and mounting btrfs requires user space scanning, so force UUID in this case. ++if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ ++ || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ ++ && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ ++ || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ ++ && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ ++ || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then ++ LINUX_ROOT_DEVICE=${GRUB_DEVICE} ++elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ ++ || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then ++ LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} ++else ++ LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} ++fi ++ ++case x"$GRUB_FS" in ++ xbtrfs) ++ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then ++ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}" ++ else ++ rootsubvol="`make_system_path_relative_to_its_root /`" ++ rootsubvol="${rootsubvol#/}" ++ if [ "x${rootsubvol}" != x ]; then ++ GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" ++ fi ++ fi;; ++ xzfs) ++ rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` ++ bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" ++ LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" ++ ;; ++esac ++ ++mktitle () ++{ ++ local title_type ++ local version ++ local OS_NAME ++ local OS_VERS ++ ++ title_type=$1 && shift ++ version=$1 && shift ++ ++ OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" ++ OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" ++ ++ case $title_type in ++ recovery) ++ title=$(printf '%s (%s) %s (recovery mode)' \ ++ "${OS_NAME}" "${version}" "${OS_VERS}") ++ ;; ++ *) ++ title=$(printf '%s (%s) %s' \ ++ "${OS_NAME}" "${version}" "${OS_VERS}") ++ ;; ++ esac ++ echo -n ${title} ++} ++ ++title_correction_code= ++ ++populate_header_warn() ++{ ++cat <&2 ++ ++ files=($(for bls in ${blsdir}/*.conf ; do ++ if ! [[ -e "${bls}" ]] ; then ++ continue ++ fi ++ bls="${bls%.conf}" ++ bls="${bls##*/}" ++ echo "${bls}" ++ done | ${kernel_sort} | tac)) || : ++ ++ for bls in "${files[@]}" ; do ++ read_config "${blsdir}/${bls}.conf" ++ ++ menu="${menu}menuentry '${title}' --class ${grub_class} ${grub_arg} --id=${bls} {\n" ++ menu="${menu}\t linux ${linux} ${options}\n" ++ if [ -n "${initrd}" ] ; then ++ menu="${menu}\t initrd ${boot_prefix}${initrd}\n" ++ fi ++ menu="${menu}}\n\n" ++ done ++ # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation ++ printf "$menu" ++} ++ ++linux_entry () ++{ ++ os="$1" ++ version="$2" ++ type="$3" ++ isdebug="$4" ++ args="$5" ++ ++ if [ -z "$boot_device_id" ]; then ++ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" ++ fi ++ ++ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then ++ if [ x$dirname = x/ ]; then ++ if [ -z "${prepare_root_cache}" ]; then ++ prepare_grub_to_access_device ${GRUB_DEVICE} ++ fi ++ else ++ if [ -z "${prepare_boot_cache}" ]; then ++ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} ++ fi ++ fi ++ ++ if [ -d /sys/firmware/efi ]; then ++ bootefi_device="`${grub_probe} --target=device /boot/efi/`" ++ prepare_grub_to_access_device_with_variable boot ${bootefi_device} ++ else ++ boot_device="`${grub_probe} --target=device /boot/`" ++ prepare_grub_to_access_device_with_variable boot ${boot_device} ++ fi ++ ++ populate_header_warn ++ populate_menu ++ ++ if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then ++ blsdir="/boot/loader/entries" ++ [ -d "${blsdir}" ] && GRUB_BLS_FS="$(${grub_probe} --target=fs ${blsdir})" ++ if [ "x${GRUB_BLS_FS}" = "xbtrfs" ] || [ "x${GRUB_BLS_FS}" = "xzfs" ]; then ++ blsdir=$(make_system_path_relative_to_its_root "${blsdir}") ++ if [ "x${blsdir}" != "x/loader/entries" ] && [ "x${blsdir}" != "x/boot/loader/entries" ]; then ++ ${grub_editenv} - set blsdir="${blsdir}" ++ fi ++ fi ++ ++ ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" ++ if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then ++ ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ++ fi ++ fi ++ ++ exit 0 ++ fi ++ ++ if [ x$type != xsimple ] ; then ++ title=$(mktitle "$type" "$version") ++ if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then ++ replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" ++ quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" ++ title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" ++ fi ++ if [ x$isdebug = xdebug ]; then ++ title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}" ++ fi ++ echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" ++ else ++ echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" ++ fi ++ if [ x$type != xrecovery ] ; then ++ save_default_entry | grub_add_tab ++ fi ++ ++ # Use ELILO's generic "efifb" when it's known to be available. ++ # FIXME: We need an interface to select vesafb in case efifb can't be used. ++ if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then ++ echo " load_video" | sed "s/^/$submenu_indentation/" ++ if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ ++ && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then ++ echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" ++ fi ++ else ++ if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then ++ echo " load_video" | sed "s/^/$submenu_indentation/" ++ fi ++ echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" ++ fi ++ ++ echo " insmod gzio" | sed "s/^/$submenu_indentation/" ++ ++ if [ x$dirname = x/ ]; then ++ if [ -z "${prepare_root_cache}" ]; then ++ prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" ++ fi ++ printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" ++ else ++ if [ -z "${prepare_boot_cache}" ]; then ++ prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" ++ fi ++ printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" ++ fi ++ sed "s/^/$submenu_indentation/" << EOF ++ linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} ++EOF ++ if test -n "${initrd}" ; then ++ initrd_path= ++ for i in ${initrd}; do ++ initrd_path="${initrd_path} ${rel_dirname}/${i}" ++ done ++ sed "s/^/$submenu_indentation/" << EOF ++ initrd $(echo $initrd_path) ++EOF ++ fi ++ if test -n "${fdt}" ; then ++ sed "s/^/$submenu_indentation/" << EOF ++ devicetree ${rel_dirname}/${fdt} ++EOF ++ fi ++ sed "s/^/$submenu_indentation/" << EOF ++} ++EOF ++} ++ ++machine=`uname -m` ++case "x$machine" in ++ xi?86 | xx86_64) ++ list= ++ for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do ++ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi ++ done ;; ++ *) ++ list= ++ for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do ++ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi ++ done ;; ++esac ++ ++if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then ++ for i in /boot/ostree/*/vmlinuz-* ; do ++ if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi ++ done ++fi ++ ++case "$machine" in ++ i?86) GENKERNEL_ARCH="x86" ;; ++ mips|mips64) GENKERNEL_ARCH="mips" ;; ++ mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; ++ arm*) GENKERNEL_ARCH="arm" ;; ++ *) GENKERNEL_ARCH="$machine" ;; ++esac ++ ++prepare_boot_cache= ++prepare_root_cache= ++boot_device_id= ++title_correction_code= ++ ++# Extra indentation to add to menu entries in a submenu. We're not in a submenu ++# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). ++submenu_indentation="" ++ ++is_top_level=true ++while [ "x$list" != "x" ] ; do ++ linux=`version_find_latest $list` ++ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then ++ gettext_printf "Found linux image: %s\n" "$linux" >&2 ++ fi ++ ++ basename=`basename $linux` ++ dirname=`dirname $linux` ++ rel_dirname=`make_system_path_relative_to_its_root $dirname` ++ version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` ++ alt_version=`echo $version | sed -e "s,\.old$,,g"` ++ linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" ++ ++ initrd_early= ++ for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ ++ ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do ++ if test -e "${dirname}/${i}" ; then ++ initrd_early="${initrd_early} ${i}" ++ fi ++ done ++ ++ initrd_real= ++ for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ ++ "initrd-${version}" "initramfs-${version}.img" \ ++ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ ++ "initrd-${alt_version}" "initramfs-${alt_version}.img" \ ++ "initramfs-genkernel-${version}" \ ++ "initramfs-genkernel-${alt_version}" \ ++ "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ ++ "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do ++ if test -e "${dirname}/${i}" ; then ++ initrd_real="${i}" ++ break ++ fi ++ done ++ ++ initrd= ++ if test -n "${initrd_early}" || test -n "${initrd_real}"; then ++ initrd="${initrd_early} ${initrd_real}" ++ ++ initrd_display= ++ for i in ${initrd}; do ++ initrd_display="${initrd_display} ${dirname}/${i}" ++ done ++ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then ++ gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 ++ fi ++ fi ++ ++ fdt= ++ for i in "dtb-${version}" "dtb-${alt_version}"; do ++ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then ++ fdt="${i}/${GRUB_DEFAULT_DTB}" ++ break ++ fi ++ done ++ ++ config= ++ for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do ++ if test -e "${i}" ; then ++ config="${i}" ++ break ++ fi ++ done ++ ++ initramfs= ++ if test -n "${config}" ; then ++ initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` ++ fi ++ ++ if test -z "${initramfs}" && test -z "${initrd_real}" ; then ++ # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's ++ # no initrd or builtin initramfs, it can't work here. ++ if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ ++ || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then ++ ++ linux_root_device_thisversion=${GRUB_DEVICE} ++ else ++ linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} ++ fi ++ fi ++ ++ if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then ++ GRUB_DISABLE_SUBMENU="true" ++ fi ++ ++ if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then ++ linux_entry "${OS}" "${version}" simple standard \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ linux_entry "${OS}" "${version}" simple debug \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi ++ ++ submenu_indentation="$grub_tab" ++ ++ if [ -z "$boot_device_id" ]; then ++ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" ++ fi ++ # TRANSLATORS: %s is replaced with an OS name ++ echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" ++ is_top_level=false ++ fi ++ ++ linux_entry "${OS}" "${version}" advanced standard \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ linux_entry "${OS}" "${version}" advanced debug \ ++ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi ++ ++ if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then ++ linux_entry "${OS}" "${version}" recovery standard \ ++ "single ${GRUB_CMDLINE_LINUX}" ++ fi ++ ++ list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` ++done ++ ++# If at least one kernel was found, then we need to ++# add a closing '}' for the submenu command. ++if [ x"$is_top_level" != xtrue ]; then ++ echo '}' ++fi ++ ++echo "$title_correction_code" diff --git a/0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch b/0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch new file mode 100644 index 0000000..204abbc --- /dev/null +++ b/0096-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 6 Feb 2018 11:16:28 +0100 +Subject: [PATCH] Don't attempt to backtrace on grub_abort() for grub-emu + +The emu platform doesn't have a grub_backtrace() implementation, so this +causes a build error. Don't attempt to call this when building grub-emu. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/misc.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 04371ac49f2..636f97e1ba1 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1103,7 +1103,7 @@ static void __attribute__ ((noreturn)) + grub_abort (void) + { + #ifndef GRUB_UTIL +-#if defined(__i386__) || defined(__x86_64__) ++#if (defined(__i386__) || defined(__x86_64__)) && !defined(GRUB_MACHINE_EMU) + grub_backtrace(); + #endif + #endif diff --git a/0097-Add-linux-and-initrd-commands-for-grub-emu.patch b/0097-Add-linux-and-initrd-commands-for-grub-emu.patch new file mode 100644 index 0000000..f956667 --- /dev/null +++ b/0097-Add-linux-and-initrd-commands-for-grub-emu.patch @@ -0,0 +1,347 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Tue, 6 Feb 2018 09:09:00 +0100 +Subject: [PATCH] Add linux and initrd commands for grub-emu + +When using grub-emu, the linux and initrd commands are used as arguments +to the kexec command line tool, to allow booting the selected menu entry. +--- + grub-core/Makefile.core.def | 1 - + grub-core/kern/emu/main.c | 4 + + grub-core/kern/emu/misc.c | 18 ++++- + grub-core/loader/emu/linux.c | 172 +++++++++++++++++++++++++++++++++++++++++++ + include/grub/emu/exec.h | 4 +- + include/grub/emu/hostfile.h | 3 +- + include/grub/emu/misc.h | 3 + + grub-core/Makefile.am | 1 + + 8 files changed, 202 insertions(+), 4 deletions(-) + create mode 100644 grub-core/loader/emu/linux.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index ebc558019cd..528f76a8c8e 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1802,7 +1802,6 @@ module = { + + common = loader/linux.c; + common = lib/cmdline.c; +- enable = noemu; + + efi = loader/efi/linux.c; + }; +diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c +index 55ea5a11ccd..846fe9715ec 100644 +--- a/grub-core/kern/emu/main.c ++++ b/grub-core/kern/emu/main.c +@@ -107,6 +107,7 @@ static struct argp_option options[] = { + N_("use GRUB files in the directory DIR [default=%s]"), 0}, + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, + {"hold", 'H', N_("SECS"), OPTION_ARG_OPTIONAL, N_("wait until a debugger will attach"), 0}, ++ {"kexec", 'X', 0, 0, N_("try the untryable."), 0}, + { 0, 0, 0, 0, 0, 0 } + }; + +@@ -164,6 +165,9 @@ argp_parser (int key, char *arg, struct argp_state *state) + case 'v': + verbosity++; + break; ++ case 'X': ++ grub_util_set_kexecute(); ++ break; + + case ARGP_KEY_ARG: + { +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 19cd007d448..245b69cab51 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -39,6 +39,7 @@ + #include + + int verbosity; ++int kexecute; + + void + grub_util_warn (const char *fmt, ...) +@@ -82,7 +83,7 @@ grub_util_error (const char *fmt, ...) + vfprintf (stderr, fmt, ap); + va_end (ap); + fprintf (stderr, ".\n"); +- exit (1); ++ grub_exit (1); + } + + void * +@@ -142,6 +143,9 @@ void + __attribute__ ((noreturn)) + grub_exit (int rc) + { ++#if defined (GRUB_KERNEL) ++ grub_reboot(); ++#endif + exit (rc < 0 ? 1 : rc); + } + #endif +@@ -203,3 +207,15 @@ grub_util_load_image (const char *path, char *buf) + + fclose (fp); + } ++ ++void ++grub_util_set_kexecute(void) ++{ ++ kexecute++; ++} ++ ++int ++grub_util_get_kexecute(void) ++{ ++ return kexecute; ++} +diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c +new file mode 100644 +index 00000000000..fda9e00d24c +--- /dev/null ++++ b/grub-core/loader/emu/linux.c +@@ -0,0 +1,172 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_dl_t my_mod; ++ ++static char *kernel_path; ++static char *initrd_path; ++static char *boot_cmdline; ++ ++static grub_err_t ++grub_linux_boot (void) ++{ ++ grub_err_t rc = GRUB_ERR_NONE; ++ char *initrd_param; ++ const char *kexec[] = { "kexec", "-l", kernel_path, boot_cmdline, NULL, NULL }; ++ const char *systemctl[] = { "systemctl", "kexec", NULL }; ++ int kexecute = grub_util_get_kexecute(); ++ ++ if (initrd_path) { ++ initrd_param = grub_xasprintf("--initrd=%s", initrd_path); ++ kexec[3] = initrd_param; ++ kexec[4] = boot_cmdline; ++ } else { ++ initrd_param = grub_xasprintf("%s", ""); ++ } ++ ++ grub_printf("%serforming 'kexec -l %s %s %s'\n", ++ (kexecute) ? "P" : "Not p", ++ kernel_path, initrd_param, boot_cmdline); ++ ++ if (kexecute) ++ rc = grub_util_exec(kexec); ++ ++ grub_free(initrd_param); ++ ++ if (rc != GRUB_ERR_NONE) { ++ grub_error (rc, N_("Error trying to perform kexec load operation.")); ++ grub_sleep (3); ++ return rc; ++ } ++ if (kexecute < 1) ++ grub_fatal (N_("Use '"PACKAGE"-emu --kexec' to force a system restart.")); ++ ++ grub_printf("Performing 'systemctl kexec' (%s) ", ++ (kexecute==1) ? "do-or-die" : "just-in-case"); ++ rc = grub_util_exec (systemctl); ++ ++ if (kexecute == 1) ++ grub_fatal (N_("Error trying to perform 'systemctl kexec'")); ++ ++ /* need to check read-only root before resetting hard!? */ ++ grub_printf("Performing 'kexec -e'"); ++ kexec[1] = "-e"; ++ kexec[2] = NULL; ++ rc = grub_util_exec(kexec); ++ if ( rc != GRUB_ERR_NONE ) ++ grub_fatal (N_("Error trying to directly perform 'kexec -e'.")); ++ ++ return rc; ++} ++ ++static grub_err_t ++grub_linux_unload (void) ++{ ++ grub_dl_unref (my_mod); ++ if ( boot_cmdline != NULL ) ++ grub_free (boot_cmdline); ++ boot_cmdline = NULL; ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) ++{ ++ int i; ++ char *tempstr; ++ ++ grub_dl_ref (my_mod); ++ ++ if (argc == 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); ++ ++ if ( !grub_util_is_regular(argv[0]) ) ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("Cannot find kernel file %s"), argv[0]); ++ ++ if ( kernel_path != NULL ) ++ grub_free(kernel_path); ++ ++ kernel_path = grub_xasprintf("%s", argv[0]); ++ ++ if ( boot_cmdline != NULL ) { ++ grub_free(boot_cmdline); ++ boot_cmdline = NULL; ++ } ++ ++ if ( argc > 1 ) ++ { ++ boot_cmdline = grub_xasprintf("--command-line=%s", argv[1]); ++ for ( i = 2; i < argc; i++ ) { ++ tempstr = grub_xasprintf("%s %s", boot_cmdline, argv[i]); ++ grub_free(boot_cmdline); ++ boot_cmdline = tempstr; ++ } ++ } ++ ++ grub_loader_set (grub_linux_boot, grub_linux_unload, 0); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) ++{ ++ if (argc == 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); ++ ++ if ( !grub_util_is_regular(argv[0]) ) ++ return grub_error(GRUB_ERR_FILE_NOT_FOUND, N_("Cannot find initrd file %s"), argv[0]); ++ ++ if ( initrd_path != NULL ) ++ grub_free(initrd_path); ++ ++ initrd_path = grub_xasprintf("%s", argv[0]); ++ ++ grub_dl_unref (my_mod); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_command_t cmd_linux, cmd_initrd; ++ ++GRUB_MOD_INIT(linux) ++{ ++ cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, N_("Load Linux.")); ++ cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, N_("Load initrd.")); ++ my_mod = mod; ++ kernel_path = NULL; ++ initrd_path = NULL; ++ boot_cmdline = NULL; ++} ++ ++GRUB_MOD_FINI(linux) ++{ ++ grub_unregister_command (cmd_linux); ++ grub_unregister_command (cmd_initrd); ++} +diff --git a/include/grub/emu/exec.h b/include/grub/emu/exec.h +index d1073ef86af..1b61b4a2e5d 100644 +--- a/include/grub/emu/exec.h ++++ b/include/grub/emu/exec.h +@@ -23,6 +23,8 @@ + #include + + #include ++#include ++ + pid_t + grub_util_exec_pipe (const char *const *argv, int *fd); + pid_t +@@ -32,7 +34,7 @@ int + grub_util_exec_redirect_all (const char *const *argv, const char *stdin_file, + const char *stdout_file, const char *stderr_file); + int +-grub_util_exec (const char *const *argv); ++EXPORT_FUNC(grub_util_exec) (const char *const *argv); + int + grub_util_exec_redirect (const char *const *argv, const char *stdin_file, + const char *stdout_file); +diff --git a/include/grub/emu/hostfile.h b/include/grub/emu/hostfile.h +index cfb1e2b5661..a61568e36e9 100644 +--- a/include/grub/emu/hostfile.h ++++ b/include/grub/emu/hostfile.h +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + #include + + int +@@ -29,7 +30,7 @@ grub_util_is_directory (const char *path); + int + grub_util_is_special_file (const char *path); + int +-grub_util_is_regular (const char *path); ++EXPORT_FUNC(grub_util_is_regular) (const char *path); + + char * + grub_util_path_concat (size_t n, ...); +diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h +index ce464cfd007..5ef4f79e689 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -56,6 +56,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( + void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2))); + void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 1, 2), noreturn)); + ++void EXPORT_FUNC(grub_util_set_kexecute) (void); ++int EXPORT_FUNC(grub_util_get_kexecute) (void) WARN_UNUSED_RESULT; ++ + grub_uint64_t EXPORT_FUNC (grub_util_get_cpu_time_ms) (void); + + #ifdef HAVE_DEVICE_MAPPER +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index c6ba5b2d763..5ff3afd62fa 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -304,6 +304,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/net.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostdisk.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/hostfile.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/extcmd.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/emu/exec.h + if COND_GRUB_EMU_SDL + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sdl.h + endif diff --git a/0098-Add-grub2-switch-to-blscfg.patch b/0098-Add-grub2-switch-to-blscfg.patch new file mode 100644 index 0000000..80c4042 --- /dev/null +++ b/0098-Add-grub2-switch-to-blscfg.patch @@ -0,0 +1,407 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 15 Mar 2018 14:12:40 -0400 +Subject: [PATCH] Add grub2-switch-to-blscfg + +Signed-off-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +[jhlavac: Use ${etcdefaultgrub} instead of /etc/default/grub] +Signed-off-by: Jan Hlavac +--- + Makefile.util.def | 7 + + util/grub-set-password.in | 2 +- + util/grub-switch-to-blscfg.8 | 33 +++++ + util/grub-switch-to-blscfg.in | 314 ++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 355 insertions(+), 1 deletion(-) + create mode 100644 util/grub-switch-to-blscfg.8 + create mode 100644 util/grub-switch-to-blscfg.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index a61613656d1..f55473c76aa 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -1364,6 +1364,13 @@ program = { + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + }; + ++script = { ++ name = grub-switch-to-blscfg; ++ common = util/grub-switch-to-blscfg.in; ++ mansection = 8; ++ installdir = sbin; ++}; ++ + program = { + name = grub-glue-efi; + mansection = 1; +diff --git a/util/grub-set-password.in b/util/grub-set-password.in +index 5ebf50576d6..c0b5ebbfdc5 100644 +--- a/util/grub-set-password.in ++++ b/util/grub-set-password.in +@@ -1,6 +1,6 @@ + #!/bin/sh -e + +-EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') ++EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') + if [ -d /sys/firmware/efi/efivars/ ]; then + grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` + else +diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 +new file mode 100644 +index 00000000000..9a886282976 +--- /dev/null ++++ b/util/grub-switch-to-blscfg.8 +@@ -0,0 +1,33 @@ ++.TH GRUB-SWITCH-TO-BLSCFG 1 "Wed Feb 26 2014" ++.SH NAME ++\fBgrub-switch-to-blscfg\fR \(em Switch to using BLS config files. ++ ++.SH SYNOPSIS ++\fBgrub-switch-to-blscfg\fR [--grub-directory=\fIDIR\fR] [--config-file=\fIFILE\fR] [--grub-defaults=\fIFILE\fR] ++ ++.SH DESCRIPTION ++\fBgrub-switch-to-blscfg\fR reconfigures grub-mkconfig to use BLS-style config files, and then regenerates the GRUB configuration. ++ ++.SH OPTIONS ++.TP ++--grub-directory=\fIDIR\fR ++Search for grub.cfg under \fIDIR\fR. The default value is \fI/boot/efi/EFI/\fBVENDOR\fR on UEFI machines and \fI/boot/grub2\fR elsewhere. ++ ++.TP ++--config-file=\fIFILE\fR ++The grub config file to use. The default value is \fI/etc/grub2-efi.cfg\fR on UEFI machines and \fI/etc/grub2.cfg\fR elsewhere. Symbolic links will be followed. ++ ++.TP ++--grub-defaults=\fIFILE\fR ++The defaults file for grub-mkconfig. The default value is \fI/etc/default/grub\fR. ++ ++.TP ++--bls-directory=\fIDIR\fR ++Create BootLoaderSpec fragments in \fIDIR\fR. The default value is \fI/boot/loader/entries\fR. ++ ++.TP ++--backup-suffix=\fSUFFIX\fR ++The suffix to use for saved backup files. The default value is \fI.bak\fR. ++ ++.SH SEE ALSO ++.BR "info grub" +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +new file mode 100644 +index 00000000000..49b3985fadb +--- /dev/null ++++ b/util/grub-switch-to-blscfg.in +@@ -0,0 +1,314 @@ ++#! /bin/sh ++# ++# Set a default boot entry for GRUB. ++# Copyright (C) 2004,2009 Free Software Foundation, Inc. ++# ++# GRUB is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# GRUB is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GRUB. If not, see . ++ ++#set -eu ++ ++# Initialize some variables. ++prefix=@prefix@ ++exec_prefix=@exec_prefix@ ++sbindir=@sbindir@ ++bindir=@bindir@ ++sysconfdir="@sysconfdir@" ++PACKAGE_NAME=@PACKAGE_NAME@ ++PACKAGE_VERSION=@PACKAGE_VERSION@ ++datarootdir="@datarootdir@" ++datadir="@datadir@" ++if [ ! -v pkgdatadir ]; then ++ pkgdatadir="${datadir}/@PACKAGE@" ++fi ++ ++self=`basename $0` ++ ++grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@" ++grub_editenv=${bindir}/@grub_editenv@ ++etcdefaultgrub=/etc/default/grub ++ ++eval "$("${grub_get_kernel_settings}")" || true ++ ++EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/' -e 's/\"//g') ++if [ -d /sys/firmware/efi/efivars/ ]; then ++ startlink=/etc/grub2-efi.cfg ++ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` ++else ++ startlink=/etc/grub2.cfg ++ grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` ++fi ++ ++blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` ++ ++backupsuffix=.bak ++ ++arch="$(uname -m)" ++ ++export TEXTDOMAIN=@PACKAGE@ ++export TEXTDOMAINDIR="@localedir@" ++ ++. "${pkgdatadir}/grub-mkconfig_lib" ++ ++# Usage: usage ++# Print the usage. ++usage () { ++ gettext_printf "Usage: %s\n" "$self" ++ gettext "Switch to BLS config files.\n"; echo ++ echo ++ print_option_help "-h, --help" "$(gettext "print this message and exit")" ++ print_option_help "-V, --version" "$(gettext "print the version information and exit")" ++ echo ++ print_option_help "--backup-suffix=$(gettext "SUFFIX")" "$backupsuffix" ++ print_option_help "--bls-directory=$(gettext "DIR")" "$blsdir" ++ print_option_help "--config-file=$(gettext "FILE")" "$startlink" ++ print_option_help "--grub-defaults=$(gettext "FILE")" "$etcdefaultgrub" ++ print_option_help "--grub-directory=$(gettext "DIR")" "$grubdir" ++ # echo ++ # gettext "Report bugs to ."; echo ++} ++ ++argument () { ++ opt=$1 ++ shift ++ ++ if test $# -eq 0; then ++ gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2 ++ exit 1 ++ fi ++ echo $1 ++} ++ ++# Check the arguments. ++while test $# -gt 0 ++do ++ option=$1 ++ shift ++ ++ case "$option" in ++ -h | --help) ++ usage ++ exit 0 ;; ++ -V | --version) ++ echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}" ++ exit 0 ;; ++ ++ --backup-suffix) ++ backupsuffix=`argument $option "$@"` ++ shift ++ ;; ++ --backup-suffix=*) ++ backupsuffix=`echo "$option" | sed 's/--backup-suffix=//'` ++ ;; ++ ++ --bls-directory) ++ blsdir=`argument $option "$@"` ++ shift ++ ;; ++ --bls-directory=*) ++ blsdir=`echo "$option" | sed 's/--bls-directory=//'` ++ ;; ++ ++ --config-file) ++ startlink=`argument $option "$@"` ++ shift ++ ;; ++ --config-file=*) ++ startlink=`echo "$option" | sed 's/--config-file=//'` ++ ;; ++ ++ --grub-defaults) ++ etcdefaultgrub=`argument $option "$@"` ++ shift ++ ;; ++ --grub-defaults=*) ++ etcdefaultgrub=`echo "$option" | sed 's/--grub-defaults=//'` ++ ;; ++ ++ --grub-directory) ++ grubdir=`argument $option "$@"` ++ shift ++ ;; ++ --grub-directory=*) ++ grubdir=`echo "$option" | sed 's/--grub-directory=//'` ++ ;; ++ ++ *) ++ gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2 ++ usage ++ exit 1 ++ ;; ++ esac ++done ++ ++find_grub_cfg() { ++ local candidate="" ++ while [ -e "${candidate}" -o $# -gt 0 ] ++ do ++ if [ ! -e "${candidate}" ] ; then ++ candidate="$1" ++ shift ++ fi ++ ++ if [ -L "${candidate}" ]; then ++ candidate="$(realpath "${candidate}")" ++ fi ++ ++ if [ -f "${candidate}" ]; then ++ export GRUB_CONFIG_FILE="${candidate}" ++ return 0 ++ fi ++ done ++ return 1 ++} ++ ++if ! find_grub_cfg ${startlink} ${grubdir}/grub.cfg ; then ++ gettext_printf "Couldn't find config file\n" 1>&2 ++ exit 1 ++fi ++ ++if [ ! -d "${blsdir}" ]; then ++ install -m 700 -d "${blsdir}" ++fi ++ ++if [ -f /etc/machine-id ]; then ++ MACHINE_ID=$(cat /etc/machine-id) ++else ++ MACHINE_ID=$(dmesg | sha256sum) ++fi ++ ++mkbls() { ++ local kernelver=$1 && shift ++ local datetime=$1 && shift ++ local bootprefix=$1 && shift ++ ++ local debugname="" ++ local debugid="" ++ local flavor="" ++ ++ if [ "$kernelver" == *\+* ] ; then ++ local flavor=-"${kernelver##*+}" ++ if [ "${flavor}" == "-debug" ]; then ++ local debugname=" with debugging" ++ local debugid="-debug" ++ fi ++ fi ++ ( ++ source /etc/os-release ++ ++ cat <"${bls_target}" ++ fi ++ ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")" ++ cp -aT "${bls_target}" "${bls_debug}" ++ title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')" ++ blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")" ++ sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}" ++ sed -i -e "s/^id.*/${blsid}/" "${bls_debug}" ++ sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}" ++ fi ++ done ++ ++ if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then ++ mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" ++ fi ++} ++ ++GENERATE=0 ++if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ ++ | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then ++ if ! sed -i"${backupsuffix}" \ ++ -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=true,' \ ++ "${etcdefaultgrub}" ; then ++ gettext_printf "Updating %s failed\n" "${etcdefaultgrub}" ++ exit 1 ++ fi ++ GENERATE=1 ++elif ! grep -q '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" ; then ++ if ! echo 'GRUB_ENABLE_BLSCFG=true' >> "${etcdefaultgrub}" ; then ++ gettext_printf "Updating %s failed\n" "${etcdefaultgrub}" ++ exit 1 ++ fi ++ GENERATE=1 ++fi ++ ++if [ "${GENERATE}" -eq 1 ] ; then ++ copy_bls ++ ++ if [ $arch = "x86_64" ] && [ ! -d /sys/firmware/efi ]; then ++ mod_dir="i386-pc" ++ elif [ $arch = "ppc64" -o $arch = "ppc64le" ] && [ ! -d /sys/firmware/opal ]; then ++ mod_dir="powerpc-ieee1275" ++ fi ++ ++ if [ -n "${mod_dir}" ]; then ++ for mod in blscfg increment; do ++ cp ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 ++ done ++ fi ++ ++ cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}" ++ if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then ++ cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" ++ sed -i"${backupsuffix}" \ ++ -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ ++ "${etcdefaultgrub}" ++ gettext_printf "Updating %s failed\n" "${GRUB_CONFIG_FILE}" ++ exit 1 ++ fi ++fi ++ ++# Bye. ++exit 0 diff --git a/0099-Add-grub_debug_enabled.patch b/0099-Add-grub_debug_enabled.patch new file mode 100644 index 0000000..838913c --- /dev/null +++ b/0099-Add-grub_debug_enabled.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 30 Nov 2017 15:11:39 -0500 +Subject: [PATCH] Add grub_debug_enabled() + +--- + grub-core/kern/misc.c | 21 ++++++++++++++++----- + include/grub/misc.h | 1 + + 2 files changed, 17 insertions(+), 5 deletions(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 636f97e1ba1..e758ab3416d 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -159,17 +159,28 @@ int grub_err_printf (const char *fmt, ...) + __attribute__ ((alias("grub_printf"))); + #endif + ++int ++grub_debug_enabled (const char * condition) ++{ ++ const char *debug; ++ ++ debug = grub_env_get ("debug"); ++ if (!debug) ++ return 0; ++ ++ if (grub_strword (debug, "all") || grub_strword (debug, condition)) ++ return 1; ++ ++ return 0; ++} ++ + void + grub_real_dprintf (const char *file, const int line, const char *condition, + const char *fmt, ...) + { + va_list args; +- const char *debug = grub_env_get ("debug"); + +- if (! debug) +- return; +- +- if (grub_strword (debug, "all") || grub_strword (debug, condition)) ++ if (grub_debug_enabled (condition)) + { + grub_printf ("%s:%d: ", file, line); + va_start (args, fmt); +diff --git a/include/grub/misc.h b/include/grub/misc.h +index b4339222ecb..4a4f485a5f6 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -367,6 +367,7 @@ grub_puts (const char *s) + } + + int EXPORT_FUNC(grub_puts_) (const char *s); ++int EXPORT_FUNC(grub_debug_enabled) (const char *condition); + void EXPORT_FUNC(grub_real_dprintf) (const char *file, + const int line, + const char *condition, diff --git a/0100-make-better-backtraces.patch b/0100-make-better-backtraces.patch new file mode 100644 index 0000000..56f4c4b --- /dev/null +++ b/0100-make-better-backtraces.patch @@ -0,0 +1,910 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 9 Jul 2019 17:05:03 +0200 +Subject: [PATCH] make better backtraces + +Signed-off-by: Peter Jones +--- + Makefile.util.def | 6 ++ + grub-core/Makefile.core.def | 16 ++-- + grub-core/{lib => commands}/backtrace.c | 2 +- + grub-core/gdb/cstub.c | 1 - + grub-core/kern/arm64/backtrace.c | 94 ++++++++++++++++++++++++ + grub-core/kern/backtrace.c | 97 +++++++++++++++++++++++++ + grub-core/kern/dl.c | 45 ++++++++++++ + grub-core/kern/i386/backtrace.c | 125 ++++++++++++++++++++++++++++++++ + grub-core/kern/i386/pc/init.c | 4 +- + grub-core/kern/ieee1275/init.c | 1 - + grub-core/kern/misc.c | 13 ++-- + grub-core/kern/mm.c | 6 +- + grub-core/lib/arm64/backtrace.c | 62 ---------------- + grub-core/lib/i386/backtrace.c | 78 -------------------- + include/grub/backtrace.h | 10 ++- + include/grub/dl.h | 2 + + include/grub/kernel.h | 3 + + grub-core/kern/arm/efi/startup.S | 2 + + grub-core/kern/arm/startup.S | 2 + + grub-core/kern/arm64/efi/startup.S | 2 + + grub-core/kern/i386/qemu/startup.S | 3 +- + grub-core/kern/ia64/efi/startup.S | 3 +- + grub-core/kern/sparc64/ieee1275/crt0.S | 3 +- + grub-core/Makefile.am | 1 + + 24 files changed, 414 insertions(+), 167 deletions(-) + rename grub-core/{lib => commands}/backtrace.c (98%) + create mode 100644 grub-core/kern/arm64/backtrace.c + create mode 100644 grub-core/kern/backtrace.c + create mode 100644 grub-core/kern/i386/backtrace.c + delete mode 100644 grub-core/lib/arm64/backtrace.c + delete mode 100644 grub-core/lib/i386/backtrace.c + +diff --git a/Makefile.util.def b/Makefile.util.def +index f55473c76aa..c13ca685ce1 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -49,6 +49,12 @@ library = { + common = grub-core/partmap/msdos.c; + common = grub-core/fs/proc.c; + common = grub-core/fs/archelp.c; ++ common = grub-core/kern/backtrace.c; ++ ++ x86 = grub-core/kern/i386/backtrace.c; ++ i386_xen = grub-core/kern/i386/backtrace.c; ++ x86_64_xen = grub-core/kern/i386/backtrace.c; ++ arm64 = grub-core/kern/arm64/backtrace.c; + }; + + library = { +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 528f76a8c8e..49c5dc4c3b7 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -140,6 +140,12 @@ kernel = { + common = kern/rescue_parser.c; + common = kern/rescue_reader.c; + common = kern/term.c; ++ common = kern/backtrace.c; ++ ++ x86 = kern/i386/backtrace.c; ++ i386_xen = kern/i386/backtrace.c; ++ x86_64_xen = kern/i386/backtrace.c; ++ arm64 = kern/arm64/backtrace.c; + + noemu = kern/compiler-rt.c; + noemu = kern/mm.c; +@@ -186,9 +192,6 @@ kernel = { + + softdiv = lib/division.c; + +- x86 = lib/i386/backtrace.c; +- x86 = lib/backtrace.c; +- + i386 = kern/i386/dl.c; + i386_xen = kern/i386/dl.c; + i386_xen_pvh = kern/i386/dl.c; +@@ -2376,15 +2379,12 @@ module = { + + module = { + name = backtrace; +- x86 = lib/i386/backtrace.c; +- i386_xen_pvh = lib/i386/backtrace.c; +- i386_xen = lib/i386/backtrace.c; +- x86_64_xen = lib/i386/backtrace.c; +- common = lib/backtrace.c; ++ common = commands/backtrace.c; + enable = x86; + enable = i386_xen_pvh; + enable = i386_xen; + enable = x86_64_xen; ++ enable = arm64; + }; + + module = { +diff --git a/grub-core/lib/backtrace.c b/grub-core/commands/backtrace.c +similarity index 98% +rename from grub-core/lib/backtrace.c +rename to grub-core/commands/backtrace.c +index c0ad6ab8be1..8b5ec3913b5 100644 +--- a/grub-core/lib/backtrace.c ++++ b/grub-core/commands/backtrace.c +@@ -54,7 +54,7 @@ grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) + { +- grub_backtrace (); ++ grub_backtrace (1); + return 0; + } + +diff --git a/grub-core/gdb/cstub.c b/grub-core/gdb/cstub.c +index b64acd70fee..99281472d36 100644 +--- a/grub-core/gdb/cstub.c ++++ b/grub-core/gdb/cstub.c +@@ -215,7 +215,6 @@ grub_gdb_trap (int trap_no) + grub_printf ("Unhandled exception 0x%x at ", trap_no); + grub_backtrace_print_address ((void *) grub_gdb_regs[PC]); + grub_printf ("\n"); +- grub_backtrace_pointer ((void *) grub_gdb_regs[EBP]); + grub_fatal ("Unhandled exception"); + } + +diff --git a/grub-core/kern/arm64/backtrace.c b/grub-core/kern/arm64/backtrace.c +new file mode 100644 +index 00000000000..019c6fdfef2 +--- /dev/null ++++ b/grub-core/kern/arm64/backtrace.c +@@ -0,0 +1,94 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2009 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define MAX_STACK_FRAME 102400 ++ ++struct fplr ++{ ++ void *lr; ++ struct fplr *fp; ++}; ++ ++void ++grub_backtrace_pointer (void *frame, unsigned int skip) ++{ ++ unsigned int x = 0; ++ struct fplr *fplr = (struct fplr *)frame; ++ ++ while (fplr) ++ { ++ const char *name = NULL; ++ char *addr = NULL; ++ ++ grub_dprintf("backtrace", "fp is %p next_fp is %p\n", ++ fplr, fplr->fp); ++ ++ if (x >= skip) ++ { ++ name = grub_get_symbol_by_addr (fplr->lr, 1); ++ if (name) ++ addr = grub_resolve_symbol (name); ++ grub_backtrace_print_address (fplr->lr); ++ ++ if (addr && addr != fplr->lr) ++ grub_printf (" %s() %p+%p \n", name ? name : "unknown", addr, ++ (void *)((grub_uint64_t)fplr->lr - (grub_uint64_t)addr)); ++ else ++ grub_printf(" %s() %p \n", name ? name : "unknown", addr); ++ ++ } ++ ++ x += 1; ++ ++ if (fplr->fp < fplr || ++ (grub_uint64_t)fplr->fp - (grub_uint64_t)fplr > MAX_STACK_FRAME || ++ fplr->fp == fplr) ++ { ++ break; ++ } ++ fplr = fplr->fp; ++ } ++} ++ ++asm ("\t.global \"_text\"\n" ++ "_text:\n" ++ "\t.quad .text\n" ++ "\t.global \"_data\"\n" ++ "_data:\n" ++ "\t.quad .data\n" ++ ); ++ ++extern grub_uint64_t _text; ++extern grub_uint64_t _data; ++ ++void ++grub_backtrace_arch (unsigned int skip) ++{ ++ grub_printf ("Backtrace (.text %p .data %p):\n", ++ (void *)_text, (void *)_data); ++ skip += 1; ++ grub_backtrace_pointer(__builtin_frame_address(0), skip); ++} +diff --git a/grub-core/kern/backtrace.c b/grub-core/kern/backtrace.c +new file mode 100644 +index 00000000000..4a82e865cc6 +--- /dev/null ++++ b/grub-core/kern/backtrace.c +@@ -0,0 +1,97 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2009 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static void ++grub_backtrace_print_address_default (void *addr) ++{ ++#ifndef GRUB_UTIL ++ grub_dl_t mod; ++ void *start_addr; ++ ++ FOR_DL_MODULES (mod) ++ { ++ grub_dl_segment_t segment; ++ for (segment = mod->segment; segment; segment = segment->next) ++ if (segment->addr <= addr && (grub_uint8_t *) segment->addr ++ + segment->size > (grub_uint8_t *) addr) ++ { ++ grub_printf ("%s.%x+%" PRIxGRUB_SIZE, mod->name, ++ segment->section, ++ (grub_size_t) ++ ((grub_uint8_t *)addr - (grub_uint8_t *)segment->addr)); ++ return; ++ } ++ } ++ ++ start_addr = grub_resolve_symbol ("_start"); ++ if (start_addr && start_addr < addr) ++ grub_printf ("kernel+%" PRIxGRUB_SIZE, ++ (grub_size_t) ++ ((grub_uint8_t *)addr - (grub_uint8_t *)start_addr)); ++ else ++#endif ++ grub_printf ("%p", addr); ++} ++ ++static void ++grub_backtrace_pointer_default (void *frame __attribute__((__unused__)), ++ unsigned int skip __attribute__((__unused__))) ++{ ++ return; ++} ++ ++void ++grub_backtrace_pointer (void *frame, unsigned int skip) ++ __attribute__((__weak__, ++ __alias__(("grub_backtrace_pointer_default")))); ++ ++void ++grub_backtrace_print_address (void *addr) ++ __attribute__((__weak__, ++ __alias__(("grub_backtrace_print_address_default")))); ++ ++static void ++grub_backtrace_arch_default(unsigned int skip) ++{ ++ grub_backtrace_pointer(__builtin_frame_address(0), skip + 1); ++} ++ ++void grub_backtrace_arch (unsigned int skip) ++ __attribute__((__weak__, __alias__(("grub_backtrace_arch_default")))); ++ ++void grub_backtrace (unsigned int skip) ++{ ++ grub_backtrace_arch(skip + 1); ++} ++ ++void grub_debug_backtrace (const char * const debug, ++ unsigned int skip) ++{ ++ if (grub_debug_enabled (debug)) ++ grub_backtrace (skip + 1); ++} +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index d7718d26abc..2e57e5e6829 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -124,6 +124,50 @@ grub_dl_resolve_symbol (const char *name) + return 0; + } + ++void * ++grub_resolve_symbol (const char *name) ++{ ++ grub_symbol_t sym; ++ ++ sym = grub_dl_resolve_symbol (name); ++ if (sym) ++ return sym->addr; ++ return NULL; ++} ++ ++const char * ++grub_get_symbol_by_addr(const void *addr, int isfunc) ++{ ++ unsigned int i; ++ grub_symbol_t before = NULL, after = NULL; ++ for (i = 0; i < GRUB_SYMTAB_SIZE; i++) ++ { ++ grub_symbol_t sym; ++ for (sym = grub_symtab[i]; sym; sym = sym->next) ++ { ++ //grub_printf ("addr 0x%08llx symbol %s\n", (unsigned long long)sym->addr, sym->name); ++ if (sym->addr > addr) ++ { ++ if (!after || sym->addr > after->addr) ++ after = sym; ++ } ++ ++ if (isfunc != sym->isfunc) ++ continue; ++ if (sym->addr > addr) ++ continue; ++ ++ if ((!before && sym->addr <= addr) || (before && before->addr <= sym->addr)) ++ before = sym; ++ } ++ } ++ ++ if (before && addr < after->addr) ++ return before->name; ++ ++ return NULL; ++} ++ + /* Register a symbol with the name NAME and the address ADDR. */ + grub_err_t + grub_dl_register_symbol (const char *name, void *addr, int isfunc, +@@ -336,6 +380,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) + const char *str; + Elf_Word size, entsize; + ++ grub_dprintf ("modules", "Resolving symbols for \"%s\"\n", mod->name); + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) +diff --git a/grub-core/kern/i386/backtrace.c b/grub-core/kern/i386/backtrace.c +new file mode 100644 +index 00000000000..2413f9a57db +--- /dev/null ++++ b/grub-core/kern/i386/backtrace.c +@@ -0,0 +1,125 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2009 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define MAX_STACK_FRAME 102400 ++ ++void ++grub_backtrace_pointer (void *frame, unsigned int skip) ++{ ++ void **ebp = (void **)frame; ++ unsigned long x = 0; ++ ++ while (ebp) ++ { ++ void **next_ebp = (void **)ebp[0]; ++ const char *name = NULL; ++ char *addr = NULL; ++ ++ grub_dprintf("backtrace", "ebp is %p next_ebp is %p\n", ebp, next_ebp); ++ ++ if (x >= skip) ++ { ++ name = grub_get_symbol_by_addr (ebp[1], 1); ++ if (name) ++ addr = grub_resolve_symbol (name); ++ grub_backtrace_print_address (ebp[1]); ++ ++ if (addr && addr != ebp[1]) ++ grub_printf (" %s() %p+%p \n", name ? name : "unknown", addr, ++ (char *)((char *)ebp[1] - addr)); ++ else ++ grub_printf(" %s() %p \n", name ? name : "unknown", addr); ++ ++#if 0 ++ grub_printf ("("); ++ for (i = 0, arg = ebp[2]; arg != next_ebp && i < 12; arg++, i++) ++ grub_printf ("%p,", arg); ++ grub_printf (")\n"); ++#endif ++ } ++ ++ x += 1; ++ ++ if (next_ebp < ebp || next_ebp - ebp > MAX_STACK_FRAME || next_ebp == ebp) ++ { ++ //grub_printf ("Invalid stack frame at %p (%p)\n", ebp, next_ebp); ++ break; ++ } ++ ebp = next_ebp; ++ } ++} ++ ++#if defined (__x86_64__) ++asm ("\t.global \"_text\"\n" ++ "_text:\n" ++ "\t.quad .text\n" ++ "\t.global \"_data\"\n" ++ "_data:\n" ++ "\t.quad .data\n" ++ ); ++#elif defined(__i386__) ++asm ("\t.global \"_text\"\n" ++ "_text:\n" ++ "\t.long .text\n" ++ "\t.global \"_data\"\n" ++ "_data:\n" ++ "\t.long .data\n" ++ ); ++#else ++#warning I dunno... ++#endif ++ ++extern unsigned long _text; ++extern unsigned long _data; ++ ++#ifdef GRUB_UTIL ++#define EXT_C(x) x ++#endif ++ ++void ++grub_backtrace_arch (unsigned int skip) ++{ ++ grub_printf ("Backtrace (.text %p .data %p):\n", ++ (void *)_text, (void *)_data); ++ skip += 1; ++#if defined (__x86_64__) ++ asm volatile ("movq %%rbp, %%rdi\n" ++ "movq 0, %%rsi\n" ++ "movl %0, %%esi\n" ++ "call " EXT_C("grub_backtrace_pointer") ++ : ++ : "r" (skip)); ++#elif defined(__i386__) ++ asm volatile ("addl $8, %%esp\n" ++ "pushl %0\n" ++ "pushl %%ebp\n" ++ "call " EXT_C("grub_backtrace_pointer") ++ : ++ : "r" (skip)); ++#else ++ grub_backtrace_pointer(__builtin_frame_address(0), skip); ++#endif ++} +diff --git a/grub-core/kern/i386/pc/init.c b/grub-core/kern/i386/pc/init.c +index 27bc68b8a53..b51d0abfa6e 100644 +--- a/grub-core/kern/i386/pc/init.c ++++ b/grub-core/kern/i386/pc/init.c +@@ -153,7 +153,7 @@ compact_mem_regions (void) + } + + grub_addr_t grub_modbase; +-extern grub_uint8_t _start[], _edata[]; ++extern grub_uint8_t _edata[]; + + /* Helper for grub_machine_init. */ + static int +@@ -217,7 +217,7 @@ grub_machine_init (void) + /* This has to happen before any BIOS calls. */ + grub_via_workaround_init (); + +- grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + (_edata - _start); ++ grub_modbase = GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR + (_edata - (grub_uint8_t *)_start); + + /* Initialize the console as early as possible. */ + grub_console_init (); +diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c +index 0cd2a627231..937c1bc44cb 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -63,7 +63,6 @@ + #define HEAP_MAX_ADDR (unsigned long) (32 * 1024 * 1024) + #endif + +-extern char _start[]; + extern char _end[]; + + #ifdef __sparc__ +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index e758ab3416d..5c2d2039d0b 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1110,15 +1110,15 @@ grub_xasprintf (const char *fmt, ...) + } + + /* Abort GRUB. This function does not return. */ +-static void __attribute__ ((noreturn)) ++static inline void __attribute__ ((noreturn)) + grub_abort (void) + { +-#ifndef GRUB_UTIL +-#if (defined(__i386__) || defined(__x86_64__)) && !defined(GRUB_MACHINE_EMU) +- grub_backtrace(); ++#if !defined(GRUB_MACHINE_EMU) && !defined(GRUB_UTIL) ++ grub_backtrace (1); ++#else ++ grub_printf ("\n"); + #endif +-#endif +- grub_printf ("\nAborted."); ++ grub_printf ("Aborted."); + + #ifndef GRUB_UTIL + if (grub_term_inputs) +@@ -1145,6 +1145,7 @@ grub_fatal (const char *fmt, ...) + { + va_list ap; + ++ grub_printf ("\n"); + va_start (ap, fmt); + grub_vprintf (_(fmt), ap); + va_end (ap); +diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c +index ee88ff61187..002cbfa4f3d 100644 +--- a/grub-core/kern/mm.c ++++ b/grub-core/kern/mm.c +@@ -95,13 +95,13 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r) + break; + + if (! *r) +- grub_fatal ("out of range pointer %p", ptr); ++ grub_fatal ("out of range pointer %p\n", ptr); + + *p = (grub_mm_header_t) ptr - 1; + if ((*p)->magic == GRUB_MM_FREE_MAGIC) +- grub_fatal ("double free at %p", *p); ++ grub_fatal ("double free at %p\n", *p); + if ((*p)->magic != GRUB_MM_ALLOC_MAGIC) +- grub_fatal ("alloc magic is broken at %p: %lx", *p, ++ grub_fatal ("alloc magic is broken at %p: %lx\n", *p, + (unsigned long) (*p)->magic); + } + +diff --git a/grub-core/lib/arm64/backtrace.c b/grub-core/lib/arm64/backtrace.c +deleted file mode 100644 +index 1079b5380e1..00000000000 +--- a/grub-core/lib/arm64/backtrace.c ++++ /dev/null +@@ -1,62 +0,0 @@ +-/* +- * GRUB -- GRand Unified Bootloader +- * Copyright (C) 2009 Free Software Foundation, Inc. +- * +- * GRUB is free software: you can redistribute it and/or modify +- * it under the terms of the GNU General Public License as published by +- * the Free Software Foundation, either version 3 of the License, or +- * (at your option) any later version. +- * +- * GRUB is distributed in the hope that it will be useful, +- * but WITHOUT ANY WARRANTY; without even the implied warranty of +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- * GNU General Public License for more details. +- * +- * You should have received a copy of the GNU General Public License +- * along with GRUB. If not, see . +- */ +- +-#include +-#include +-#include +-#include +-#include +-#include +-#include +- +-#define MAX_STACK_FRAME 102400 +- +-void +-grub_backtrace_pointer (int frame) +-{ +- while (1) +- { +- void *lp = __builtin_return_address (frame); +- if (!lp) +- break; +- +- lp = __builtin_extract_return_addr (lp); +- +- grub_printf ("%p: ", lp); +- grub_backtrace_print_address (lp); +- grub_printf (" ("); +- for (i = 0; i < 2; i++) +- grub_printf ("%p,", ((void **)ptr) [i + 2]); +- grub_printf ("%p)\n", ((void **)ptr) [i + 2]); +- nptr = *(void **)ptr; +- if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME +- || nptr == ptr) +- { +- grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr); +- break; +- } +- ptr = nptr; +- } +-} +- +-void +-grub_backtrace (void) +-{ +- grub_backtrace_pointer (1); +-} +- +diff --git a/grub-core/lib/i386/backtrace.c b/grub-core/lib/i386/backtrace.c +deleted file mode 100644 +index c67273db3ae..00000000000 +--- a/grub-core/lib/i386/backtrace.c ++++ /dev/null +@@ -1,78 +0,0 @@ +-/* +- * GRUB -- GRand Unified Bootloader +- * Copyright (C) 2009 Free Software Foundation, Inc. +- * +- * GRUB is free software: you can redistribute it and/or modify +- * it under the terms of the GNU General Public License as published by +- * the Free Software Foundation, either version 3 of the License, or +- * (at your option) any later version. +- * +- * GRUB is distributed in the hope that it will be useful, +- * but WITHOUT ANY WARRANTY; without even the implied warranty of +- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- * GNU General Public License for more details. +- * +- * You should have received a copy of the GNU General Public License +- * along with GRUB. If not, see . +- */ +-#include +-#ifdef GRUB_UTIL +-#define REALLY_GRUB_UTIL GRUB_UTIL +-#undef GRUB_UTIL +-#endif +- +-#include +-#include +- +-#ifdef REALLY_GRUB_UTIL +-#define GRUB_UTIL REALLY_GRUB_UTIL +-#undef REALLY_GRUB_UTIL +-#endif +- +-#include +-#include +-#include +-#include +-#include +-#include +- +-#define MAX_STACK_FRAME 102400 +- +-void +-grub_backtrace_pointer (void *ebp) +-{ +- void *ptr, *nptr; +- unsigned i; +- +- ptr = ebp; +- while (1) +- { +- grub_printf ("%p: ", ptr); +- grub_backtrace_print_address (((void **) ptr)[1]); +- grub_printf (" ("); +- for (i = 0; i < 2; i++) +- grub_printf ("%p,", ((void **)ptr) [i + 2]); +- grub_printf ("%p)\n", ((void **)ptr) [i + 2]); +- nptr = *(void **)ptr; +- if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME +- || nptr == ptr) +- { +- grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr); +- break; +- } +- ptr = nptr; +- } +-} +- +-void +-grub_backtrace (void) +-{ +-#ifdef __x86_64__ +- asm volatile ("movq %%rbp, %%rdi\n" +- "callq *%%rax": :"a"(grub_backtrace_pointer)); +-#else +- asm volatile ("movl %%ebp, %%eax\n" +- "calll *%%ecx": :"c"(grub_backtrace_pointer)); +-#endif +-} +- +diff --git a/include/grub/backtrace.h b/include/grub/backtrace.h +index 395519762f0..275cf85e2d3 100644 +--- a/include/grub/backtrace.h ++++ b/include/grub/backtrace.h +@@ -19,8 +19,14 @@ + #ifndef GRUB_BACKTRACE_HEADER + #define GRUB_BACKTRACE_HEADER 1 + +-void grub_backtrace (void); +-void grub_backtrace_pointer (void *ptr); ++#include ++#include ++ ++void EXPORT_FUNC(grub_debug_backtrace) (const char * const debug, ++ unsigned int skip); ++void EXPORT_FUNC(grub_backtrace) (unsigned int skip); ++void grub_backtrace_arch (unsigned int skip); ++void grub_backtrace_pointer (void *ptr, unsigned int skip); + void grub_backtrace_print_address (void *addr); + + #endif +diff --git a/include/grub/dl.h b/include/grub/dl.h +index 90dc9bb1017..4fe2b524f73 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -257,6 +257,8 @@ grub_dl_is_persistent (grub_dl_t mod) + + #endif + ++void * EXPORT_FUNC(grub_resolve_symbol) (const char *name); ++const char * EXPORT_FUNC(grub_get_symbol_by_addr) (const void *addr, int isfunc); + grub_err_t grub_dl_register_symbol (const char *name, void *addr, + int isfunc, grub_dl_t mod); + +diff --git a/include/grub/kernel.h b/include/grub/kernel.h +index 133a37c8d03..e5a5f436709 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -110,6 +110,9 @@ grub_addr_t grub_modules_get_end (void); + + #endif + ++void EXPORT_FUNC(start) (void); ++void EXPORT_FUNC(_start) (void); ++ + /* The start point of the C code. */ + void grub_main (void) __attribute__ ((noreturn)); + +diff --git a/grub-core/kern/arm/efi/startup.S b/grub-core/kern/arm/efi/startup.S +index 9f8265315a9..f3bc41f9d0f 100644 +--- a/grub-core/kern/arm/efi/startup.S ++++ b/grub-core/kern/arm/efi/startup.S +@@ -23,6 +23,8 @@ + .file "startup.S" + .text + .arm ++ .globl start, _start ++FUNCTION(start) + FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in r1/r0. +diff --git a/grub-core/kern/arm/startup.S b/grub-core/kern/arm/startup.S +index 3946fe8e183..5679a1d00ad 100644 +--- a/grub-core/kern/arm/startup.S ++++ b/grub-core/kern/arm/startup.S +@@ -48,6 +48,8 @@ + + .text + .arm ++ .globl start, _start ++FUNCTION(start) + FUNCTION(_start) + b codestart + +diff --git a/grub-core/kern/arm64/efi/startup.S b/grub-core/kern/arm64/efi/startup.S +index 666a7ee3c92..41676bdb2b8 100644 +--- a/grub-core/kern/arm64/efi/startup.S ++++ b/grub-core/kern/arm64/efi/startup.S +@@ -19,7 +19,9 @@ + #include + + .file "startup.S" ++ .globl start, _start + .text ++FUNCTION(start) + FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in x1/x0. +diff --git a/grub-core/kern/i386/qemu/startup.S b/grub-core/kern/i386/qemu/startup.S +index 0d89858d9b3..939f182fc74 100644 +--- a/grub-core/kern/i386/qemu/startup.S ++++ b/grub-core/kern/i386/qemu/startup.S +@@ -24,7 +24,8 @@ + + .text + .code32 +- .globl _start ++ .globl start, _start ++start: + _start: + jmp codestart + +diff --git a/grub-core/kern/ia64/efi/startup.S b/grub-core/kern/ia64/efi/startup.S +index d75c6d7cc74..8f2a593e529 100644 +--- a/grub-core/kern/ia64/efi/startup.S ++++ b/grub-core/kern/ia64/efi/startup.S +@@ -24,8 +24,9 @@ + .psr lsb + .lsb + +- .global _start ++ .global start, _start + .proc _start ++start: + _start: + alloc loc0=ar.pfs,2,4,0,0 + mov loc1=rp +diff --git a/grub-core/kern/sparc64/ieee1275/crt0.S b/grub-core/kern/sparc64/ieee1275/crt0.S +index 03b916f0534..701bf63abcf 100644 +--- a/grub-core/kern/sparc64/ieee1275/crt0.S ++++ b/grub-core/kern/sparc64/ieee1275/crt0.S +@@ -22,7 +22,8 @@ + + .text + .align 4 +- .globl _start ++ .globl start, _start ++start: + _start: + ba codestart + mov %o4, %o0 +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 5ff3afd62fa..d9ad30052f1 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -66,6 +66,7 @@ CLEANFILES += grub_script.yy.c grub_script.yy.h + + include $(srcdir)/Makefile.core.am + ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/backtrace.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cache.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/command.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/device.h diff --git a/0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch b/0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch new file mode 100644 index 0000000..6777636 --- /dev/null +++ b/0101-normal-don-t-draw-our-startup-message-if-debug-is-se.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 9 Nov 2017 15:58:52 -0500 +Subject: [PATCH] normal: don't draw our startup message if debug is set + +--- + grub-core/normal/main.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index 2fe6743399d..f7ee912e715 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -425,6 +425,9 @@ grub_normal_reader_init (int nested) + const char *msg_esc = _("ESC at any time exits."); + char *msg_formatted; + ++ if (grub_env_get ("debug") != NULL) ++ return 0; ++ + msg_formatted = grub_xasprintf (_("Minimal BASH-like line editing is supported. For " + "the first word, TAB lists possible command completions. Anywhere " + "else TAB lists possible device or file completions. %s"), diff --git a/0102-Work-around-some-minor-include-path-weirdnesses.patch b/0102-Work-around-some-minor-include-path-weirdnesses.patch new file mode 100644 index 0000000..460d792 --- /dev/null +++ b/0102-Work-around-some-minor-include-path-weirdnesses.patch @@ -0,0 +1,137 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 16 Mar 2018 13:28:57 -0400 +Subject: [PATCH] Work around some minor include path weirdnesses + +Signed-off-by: Peter Jones +--- + include/grub/arm/efi/console.h | 24 ++++++++++++++++++++++++ + include/grub/arm64/efi/console.h | 24 ++++++++++++++++++++++++ + include/grub/i386/efi/console.h | 24 ++++++++++++++++++++++++ + include/grub/x86_64/efi/console.h | 24 ++++++++++++++++++++++++ + 4 files changed, 96 insertions(+) + create mode 100644 include/grub/arm/efi/console.h + create mode 100644 include/grub/arm64/efi/console.h + create mode 100644 include/grub/i386/efi/console.h + create mode 100644 include/grub/x86_64/efi/console.h + +diff --git a/include/grub/arm/efi/console.h b/include/grub/arm/efi/console.h +new file mode 100644 +index 00000000000..1592f6f76b5 +--- /dev/null ++++ b/include/grub/arm/efi/console.h +@@ -0,0 +1,24 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_ARM_EFI_CONSOLE_H ++#define GRUB_ARM_EFI_CONSOLE_H ++ ++#include ++ ++#endif /* ! GRUB_ARM_EFI_CONSOLE_H */ +diff --git a/include/grub/arm64/efi/console.h b/include/grub/arm64/efi/console.h +new file mode 100644 +index 00000000000..95689339384 +--- /dev/null ++++ b/include/grub/arm64/efi/console.h +@@ -0,0 +1,24 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_ARM64_EFI_CONSOLE_H ++#define GRUB_ARM64_EFI_CONSOLE_H ++ ++#include ++ ++#endif /* ! GRUB_ARM64_EFI_CONSOLE_H */ +diff --git a/include/grub/i386/efi/console.h b/include/grub/i386/efi/console.h +new file mode 100644 +index 00000000000..9231375cb07 +--- /dev/null ++++ b/include/grub/i386/efi/console.h +@@ -0,0 +1,24 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_I386_EFI_CONSOLE_H ++#define GRUB_I386_EFI_CONSOLE_H ++ ++#include ++ ++#endif /* ! GRUB_I386_EFI_CONSOLE_H */ +diff --git a/include/grub/x86_64/efi/console.h b/include/grub/x86_64/efi/console.h +new file mode 100644 +index 00000000000..dba9d8678d0 +--- /dev/null ++++ b/include/grub/x86_64/efi/console.h +@@ -0,0 +1,24 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_X86_64_EFI_CONSOLE_H ++#define GRUB_X86_64_EFI_CONSOLE_H ++ ++#include ++ ++#endif /* ! GRUB_X86_64_EFI_CONSOLE_H */ diff --git a/0103-Make-it-possible-to-enabled-build-id-sha1.patch b/0103-Make-it-possible-to-enabled-build-id-sha1.patch new file mode 100644 index 0000000..d77b6f6 --- /dev/null +++ b/0103-Make-it-possible-to-enabled-build-id-sha1.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 25 Jun 2015 15:41:06 -0400 +Subject: [PATCH] Make it possible to enabled --build-id=sha1 + +Signed-off-by: Peter Jones +--- + configure.ac | 8 ++++++++ + acinclude.m4 | 19 +++++++++++++++++++ + 2 files changed, 27 insertions(+) + +diff --git a/configure.ac b/configure.ac +index eb851b8d722..8ee18ba159a 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1414,7 +1414,15 @@ grub_PROG_TARGET_CC + if test "x$TARGET_APPLE_LINKER" != x1 ; then + grub_PROG_OBJCOPY_ABSOLUTE + fi ++ ++AC_ARG_ENABLE([build-id], ++ [AS_HELP_STRING([--enable-build-id], ++ [ask the linker to supply build-id notes (default=no)])]) ++if test x$enable_build_id = xyes; then ++grub_PROG_LD_BUILD_ID_SHA1 ++else + grub_PROG_LD_BUILD_ID_NONE ++fi + if test "x$target_cpu" = xi386; then + if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then + if test ! -z "$TARGET_IMG_LDSCRIPT"; then +diff --git a/acinclude.m4 b/acinclude.m4 +index 78cdf6e1d01..242e829ff23 100644 +--- a/acinclude.m4 ++++ b/acinclude.m4 +@@ -136,6 +136,25 @@ if test "x$grub_cv_prog_ld_build_id_none" = xyes; then + fi + ]) + ++dnl Supply --build-id=sha1 to ld if building modules. ++dnl This suppresses warnings from ld on some systems ++AC_DEFUN([grub_PROG_LD_BUILD_ID_SHA1], ++[AC_MSG_CHECKING([whether linker accepts --build-id=sha1]) ++AC_CACHE_VAL(grub_cv_prog_ld_build_id_sha1, ++[save_LDFLAGS="$LDFLAGS" ++LDFLAGS="$LDFLAGS -Wl,--build-id=sha1" ++AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], ++ [grub_cv_prog_ld_build_id_sha1=yes], ++ [grub_cv_prog_ld_build_id_sha1=no]) ++LDFLAGS="$save_LDFLAGS" ++]) ++AC_MSG_RESULT([$grub_cv_prog_ld_build_id_sha1]) ++ ++if test "x$grub_cv_prog_ld_build_id_sha1" = xyes; then ++ TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=sha1" ++fi ++]) ++ + dnl Check nm + AC_DEFUN([grub_PROG_NM_WORKS], + [AC_MSG_CHECKING([whether nm works]) diff --git a/0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch b/0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch new file mode 100644 index 0000000..b434d4c --- /dev/null +++ b/0104-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 28 Jun 2015 13:09:58 -0400 +Subject: [PATCH] Add grub_qdprintf() - grub_dprintf() without the file+line + number. + +This just makes copy+paste of our debug loading info easier. + +Signed-off-by: Peter Jones +--- + grub-core/kern/misc.c | 18 ++++++++++++++++++ + include/grub/misc.h | 2 ++ + 2 files changed, 20 insertions(+) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 5c2d2039d0b..0e89c483d5e 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -190,6 +190,24 @@ grub_real_dprintf (const char *file, const int line, const char *condition, + } + } + ++void ++grub_qdprintf (const char *condition, const char *fmt, ...) ++{ ++ va_list args; ++ const char *debug = grub_env_get ("debug"); ++ ++ if (! debug) ++ return; ++ ++ if (grub_strword (debug, "all") || grub_strword (debug, condition)) ++ { ++ va_start (args, fmt); ++ grub_vprintf (fmt, args); ++ va_end (args); ++ grub_refresh (); ++ } ++} ++ + #define PREALLOC_SIZE 255 + + int +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 4a4f485a5f6..960097fbd06 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -372,6 +372,8 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, + const int line, + const char *condition, + const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 4, 5))); ++void EXPORT_FUNC(grub_qdprintf) (const char *condition, ++ const char *fmt, ...) __attribute__ ((format (GNU_PRINTF, 2, 3))); + int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args); + int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...) + __attribute__ ((format (GNU_PRINTF, 3, 4))); diff --git a/0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch new file mode 100644 index 0000000..09cc7c6 --- /dev/null +++ b/0105-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch @@ -0,0 +1,178 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 25 Jun 2015 15:11:36 -0400 +Subject: [PATCH] Make a "gdb" dprintf that tells us load addresses. + +This makes a grub_dprintf() call during platform init and during module +loading that tells us the virtual addresses of the .text and .data +sections of grub-core/kernel.exec and any modules it loads. + +Specifically, it displays them in the gdb "add-symbol-file" syntax, with +the presumption that there's a variable $grubdir that reflects the path +to any such binaries. + +Signed-off-by: Peter Jones +--- + grub-core/kern/dl.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ + grub-core/kern/efi/efi.c | 4 ++-- + grub-core/kern/efi/init.c | 26 +++++++++++++++++++++++- + include/grub/efi/efi.h | 2 +- + 4 files changed, 78 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 2e57e5e6829..6a5e7706143 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -501,6 +501,23 @@ grub_dl_find_section (Elf_Ehdr *e, const char *name) + return s; + return NULL; + } ++static long ++grub_dl_find_section_index (Elf_Ehdr *e, const char *name) ++{ ++ Elf_Shdr *s; ++ const char *str; ++ unsigned i; ++ ++ s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shstrndx * e->e_shentsize); ++ str = (char *) e + s->sh_offset; ++ ++ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); ++ i < e->e_shnum; ++ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) ++ if (grub_strcmp (str + s->sh_name, name) == 0) ++ return (long)i; ++ return -1; ++} + + /* Me, Vladimir Serbinenko, hereby I add this module check as per new + GNU module policy. Note that this license check is informative only. +@@ -644,6 +661,37 @@ grub_dl_relocate_symbols (grub_dl_t mod, void *ehdr) + + return GRUB_ERR_NONE; + } ++static void ++grub_dl_print_gdb_info (grub_dl_t mod, Elf_Ehdr *e) ++{ ++ void *text, *data = NULL; ++ long idx; ++ ++ idx = grub_dl_find_section_index (e, ".text"); ++ if (idx < 0) ++ return; ++ ++ text = grub_dl_get_section_addr (mod, idx); ++ if (!text) ++ return; ++ ++ idx = grub_dl_find_section_index (e, ".data"); ++ if (idx >= 0) ++ data = grub_dl_get_section_addr (mod, idx); ++ ++ if (data) ++ grub_qdprintf ("gdb", "add-symbol-file \\\n" ++ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " ++ "\\\n %p -s .data %p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, ++ mod->name, text, data); ++ else ++ grub_qdprintf ("gdb", "add-symbol-file \\\n" ++ "/usr/lib/debug/usr/lib/grub/%s-%s/%s.debug " ++ "\\\n%p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, ++ mod->name, text); ++} + + /* Load a module from core memory. */ + grub_dl_t +@@ -703,6 +751,8 @@ grub_dl_load_core_noinit (void *addr, grub_size_t size) + grub_dprintf ("modules", "module name: %s\n", mod->name); + grub_dprintf ("modules", "init function: %p\n", mod->init); + ++ grub_dl_print_gdb_info (mod, e); ++ + if (grub_dl_add (mod)) + { + grub_dl_unload (mod); +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 2cf6a5ad526..19054b1465f 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -283,7 +283,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + /* Search the mods section from the PE32/PE32+ image. This code uses + a PE32 header, but should work with PE32+ as well. */ + grub_addr_t +-grub_efi_modules_addr (void) ++grub_efi_section_addr (const char *section_name) + { + grub_efi_loaded_image_t *image; + struct grub_pe32_header *header; +@@ -308,7 +308,7 @@ grub_efi_modules_addr (void) + i < coff_header->num_sections; + i++, section++) + { +- if (grub_strcmp (section->name, "mods") == 0) ++ if (grub_strcmp (section->name, section_name) == 0) + break; + } + +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index 71d2279a0c1..e6183a4c44d 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -59,10 +59,33 @@ grub_efi_env_init (void) + grub_free (envblk_s.buf); + } + ++static void ++grub_efi_print_gdb_info (void) ++{ ++ grub_addr_t text; ++ grub_addr_t data; ++ ++ text = grub_efi_section_addr (".text"); ++ if (!text) ++ return; ++ ++ data = grub_efi_section_addr (".data"); ++ if (data) ++ grub_qdprintf ("gdb", ++ "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/" ++ "kernel.exec %p -s .data %p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text, (void *)data); ++ else ++ grub_qdprintf ("gdb", ++ "add-symbol-file /usr/lib/debug/usr/lib/grub/%s-%s/" ++ "kernel.exec %p\n", ++ GRUB_TARGET_CPU, GRUB_PLATFORM, (void *)text); ++} ++ + void + grub_efi_init (void) + { +- grub_modbase = grub_efi_modules_addr (); ++ grub_modbase = grub_efi_section_addr ("mods"); + /* First of all, initialize the console so that GRUB can display + messages. */ + grub_console_init (); +@@ -74,6 +97,7 @@ grub_efi_init (void) + 0, 0, 0, NULL); + + grub_efi_env_init (); ++ grub_efi_print_gdb_info (); + grub_efidisk_init (); + } + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 5e2b479daec..8ca3981d7a1 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -132,7 +132,7 @@ grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh); + grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); + #endif + +-grub_addr_t grub_efi_modules_addr (void); ++grub_addr_t grub_efi_section_addr (const char *section); + + void grub_efi_mm_init (void); + void grub_efi_mm_fini (void); diff --git a/0106-Fixup-for-newer-compiler.patch b/0106-Fixup-for-newer-compiler.patch new file mode 100644 index 0000000..ae5ac89 --- /dev/null +++ b/0106-Fixup-for-newer-compiler.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 May 2018 13:40:19 -0400 +Subject: [PATCH] Fixup for newer compiler + +--- + grub-core/fs/btrfs.c | 2 +- + include/grub/gpt_partition.h | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index ba99d04f8ed..9cd7f4bdf65 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -215,7 +215,7 @@ struct grub_btrfs_inode + grub_uint64_t size; + grub_uint8_t dummy2[0x70]; + struct grub_btrfs_time mtime; +-} GRUB_PACKED; ++} GRUB_PACKED __attribute__ ((aligned(8))); + + struct grub_btrfs_extent_data + { +diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h +index 7a93f43291c..8212697bf6b 100644 +--- a/include/grub/gpt_partition.h ++++ b/include/grub/gpt_partition.h +@@ -76,7 +76,7 @@ struct grub_gpt_partentry + grub_uint64_t end; + grub_uint64_t attrib; + char name[72]; +-} GRUB_PACKED; ++} GRUB_PACKED __attribute__ ((aligned(8))); + + grub_err_t + grub_gpt_partition_map_iterate (grub_disk_t disk, diff --git a/0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch b/0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch new file mode 100644 index 0000000..f6c1185 --- /dev/null +++ b/0107-Don-t-attempt-to-export-the-start-and-_start-symbols.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Sat, 12 May 2018 11:29:07 +0200 +Subject: [PATCH] Don't attempt to export the start and _start symbols for + grub-emu + +Commit 318ee04aadc ("make better backtraces") reworked the backtrace logic +but the changes lead to the following build error on the grub-emu platform: + +grub_emu_lite-symlist.o:(.data+0xf08): undefined reference to `start' +collect2: error: ld returned 1 exit status +make[3]: *** [Makefile:25959: grub-emu-lite] Error 1 +make[3]: *** Waiting for unfinished jobs.... +cat kernel_syms.input | grep -v '^#' | sed -n \ + -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/defined kernel '""'\1/;p;}' \ + -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/defined kernel '""'\1/;p;}' \ + | sort -u >kernel_syms.lst + +The problem is that start and _start symbols are exported unconditionally, +but these aren't defined for grub-emu since is an emultaed platform so it +doesn't have a startup logic. Don't attempt to export those for grub-emu. + +Signed-off-by: Javier Martinez Canillas +--- + include/grub/kernel.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/include/grub/kernel.h b/include/grub/kernel.h +index e5a5f436709..de48cd44ccb 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -110,8 +110,10 @@ grub_addr_t grub_modules_get_end (void); + + #endif + ++#if !defined(GRUB_MACHINE_EMU) + void EXPORT_FUNC(start) (void); + void EXPORT_FUNC(_start) (void); ++#endif + + /* The start point of the C code. */ + void grub_main (void) __attribute__ ((noreturn)); diff --git a/0108-Fixup-for-newer-compiler.patch b/0108-Fixup-for-newer-compiler.patch new file mode 100644 index 0000000..e35dbdb --- /dev/null +++ b/0108-Fixup-for-newer-compiler.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 10 May 2018 13:40:19 -0400 +Subject: [PATCH] Fixup for newer compiler + +--- + conf/Makefile.common | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 4ba729e14d8..5e8ba2ae3b0 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -38,7 +38,7 @@ CFLAGS_KERNEL = $(CFLAGS_PLATFORM) -ffreestanding + LDFLAGS_KERNEL = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) + CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 + CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) +-STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx ++STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes + + CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding + LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d diff --git a/0109-Add-support-for-non-Ethernet-network-cards.patch b/0109-Add-support-for-non-Ethernet-network-cards.patch new file mode 100644 index 0000000..dc89c99 --- /dev/null +++ b/0109-Add-support-for-non-Ethernet-network-cards.patch @@ -0,0 +1,766 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrzej Kacprowski +Date: Wed, 10 Jul 2019 15:22:29 +0200 +Subject: [PATCH] Add support for non-Ethernet network cards + +This patch replaces fixed 6-byte link layer address with +up to 32-byte variable sized address. +This allows supporting Infiniband and Omni-Path fabric +which use 20-byte address, but other network card types +can also take advantage of this change. +The network card driver is responsible for replacing L2 +header provided by grub2 if needed. +This approach is compatible with UEFI network stack which +also allows up to 32-byte variable size link address. + +The BOOTP/DHCP packet format is limited to 16 byte client +hardware address, if link address is more that 16-bytes +then chaddr field in BOOTP it will be set to 0 as per rfc4390. + +Resolves: rhbz#1370642 + +Signed-off-by: Andrzej Kacprowski +[msalter: Fix max string calculation in grub_net_hwaddr_to_str] +Signed-off-by: Mark Salter +--- + grub-core/net/arp.c | 155 ++++++++++++++++++++++----------- + grub-core/net/bootp.c | 15 ++-- + grub-core/net/drivers/efi/efinet.c | 8 +- + grub-core/net/drivers/emu/emunet.c | 1 + + grub-core/net/drivers/i386/pc/pxe.c | 13 +-- + grub-core/net/drivers/ieee1275/ofnet.c | 2 + + grub-core/net/drivers/uboot/ubootnet.c | 1 + + grub-core/net/ethernet.c | 88 +++++++++---------- + grub-core/net/icmp6.c | 15 ++-- + grub-core/net/ip.c | 4 +- + grub-core/net/net.c | 50 ++++++----- + include/grub/net.h | 19 ++-- + 12 files changed, 219 insertions(+), 152 deletions(-) + +diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c +index 54306e3b16d..67b409a8acc 100644 +--- a/grub-core/net/arp.c ++++ b/grub-core/net/arp.c +@@ -31,22 +31,12 @@ enum + ARP_REPLY = 2 + }; + +-enum +- { +- /* IANA ARP constant to define hardware type as ethernet. */ +- GRUB_NET_ARPHRD_ETHERNET = 1 +- }; +- +-struct arppkt { ++struct arphdr { + grub_uint16_t hrd; + grub_uint16_t pro; + grub_uint8_t hln; + grub_uint8_t pln; + grub_uint16_t op; +- grub_uint8_t sender_mac[6]; +- grub_uint32_t sender_ip; +- grub_uint8_t recv_mac[6]; +- grub_uint32_t recv_ip; + } GRUB_PACKED; + + static int have_pending; +@@ -57,12 +47,16 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, + const grub_net_network_level_address_t *proto_addr) + { + struct grub_net_buff nb; +- struct arppkt *arp_packet; ++ struct arphdr *arp_header; + grub_net_link_level_address_t target_mac_addr; + grub_err_t err; + int i; + grub_uint8_t *nbd; + grub_uint8_t arp_data[128]; ++ grub_uint8_t hln; ++ grub_uint8_t pln; ++ grub_uint8_t arp_packet_len; ++ grub_uint8_t *tmp_ptr; + + if (proto_addr->type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4) + return grub_error (GRUB_ERR_BUG, "unsupported address family"); +@@ -73,23 +67,39 @@ grub_net_arp_send_request (struct grub_net_network_level_interface *inf, + grub_netbuff_clear (&nb); + grub_netbuff_reserve (&nb, 128); + +- err = grub_netbuff_push (&nb, sizeof (*arp_packet)); ++ hln = inf->card->default_address.len; ++ pln = sizeof (proto_addr->ipv4); ++ arp_packet_len = sizeof (*arp_header) + 2 * (hln + pln); ++ ++ err = grub_netbuff_push (&nb, arp_packet_len); + if (err) + return err; + +- arp_packet = (struct arppkt *) nb.data; +- arp_packet->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET); +- arp_packet->hln = 6; +- arp_packet->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP); +- arp_packet->pln = 4; +- arp_packet->op = grub_cpu_to_be16_compile_time (ARP_REQUEST); +- /* Sender hardware address. */ +- grub_memcpy (arp_packet->sender_mac, &inf->hwaddress.mac, 6); +- arp_packet->sender_ip = inf->address.ipv4; +- grub_memset (arp_packet->recv_mac, 0, 6); +- arp_packet->recv_ip = proto_addr->ipv4; +- /* Target protocol address */ +- grub_memset (&target_mac_addr.mac, 0xff, 6); ++ arp_header = (struct arphdr *) nb.data; ++ arp_header->hrd = grub_cpu_to_be16 (inf->card->default_address.type); ++ arp_header->hln = hln; ++ arp_header->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP); ++ arp_header->pln = pln; ++ arp_header->op = grub_cpu_to_be16_compile_time (ARP_REQUEST); ++ tmp_ptr = nb.data + sizeof (*arp_header); ++ ++ /* The source hardware address. */ ++ grub_memcpy (tmp_ptr, inf->hwaddress.mac, hln); ++ tmp_ptr += hln; ++ ++ /* The source protocol address. */ ++ grub_memcpy (tmp_ptr, &inf->address.ipv4, pln); ++ tmp_ptr += pln; ++ ++ /* The target hardware address. */ ++ grub_memset (tmp_ptr, 0, hln); ++ tmp_ptr += hln; ++ ++ /* The target protocol address */ ++ grub_memcpy (tmp_ptr, &proto_addr->ipv4, pln); ++ tmp_ptr += pln; ++ ++ grub_memset (&target_mac_addr.mac, 0xff, hln); + + nbd = nb.data; + send_ethernet_packet (inf, &nb, target_mac_addr, GRUB_NET_ETHERTYPE_ARP); +@@ -114,28 +124,53 @@ grub_err_t + grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + grub_uint16_t *vlantag) + { +- struct arppkt *arp_packet = (struct arppkt *) nb->data; ++ struct arphdr *arp_header = (struct arphdr *) nb->data; + grub_net_network_level_address_t sender_addr, target_addr; + grub_net_link_level_address_t sender_mac_addr; + struct grub_net_network_level_interface *inf; ++ grub_uint16_t hw_type; ++ grub_uint8_t hln; ++ grub_uint8_t pln; ++ grub_uint8_t arp_packet_len; ++ grub_uint8_t *tmp_ptr; + +- if (arp_packet->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP) +- || arp_packet->pln != 4 || arp_packet->hln != 6 +- || nb->tail - nb->data < (int) sizeof (*arp_packet)) ++ hw_type = card->default_address.type; ++ hln = card->default_address.len; ++ pln = sizeof(sender_addr.ipv4); ++ arp_packet_len = sizeof (*arp_header) + 2 * (pln + hln); ++ ++ if (arp_header->pro != grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP) ++ || arp_header->hrd != grub_cpu_to_be16 (hw_type) ++ || arp_header->hln != hln || arp_header->pln != pln ++ || nb->tail - nb->data < (int) arp_packet_len) { + return GRUB_ERR_NONE; ++ } + ++ tmp_ptr = nb->data + sizeof (*arp_header); ++ ++ /* The source hardware address. */ ++ sender_mac_addr.type = hw_type; ++ sender_mac_addr.len = hln; ++ grub_memcpy (sender_mac_addr.mac, tmp_ptr, hln); ++ tmp_ptr += hln; ++ ++ /* The source protocol address. */ + sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; ++ grub_memcpy(&sender_addr.ipv4, tmp_ptr, pln); ++ tmp_ptr += pln; ++ ++ grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); ++ ++ /* The target hardware address. */ ++ tmp_ptr += hln; ++ ++ /* The target protocol address. */ + target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; +- sender_addr.ipv4 = arp_packet->sender_ip; +- target_addr.ipv4 = arp_packet->recv_ip; +- if (arp_packet->sender_ip == pending_req) ++ grub_memcpy(&target_addr.ipv4, tmp_ptr, pln); ++ ++ if (sender_addr.ipv4 == pending_req) + have_pending = 1; + +- sender_mac_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (sender_mac_addr.mac, arp_packet->sender_mac, +- sizeof (sender_mac_addr.mac)); +- grub_net_link_layer_add_address (card, &sender_addr, &sender_mac_addr, 1); +- + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + { + /* Verify vlantag id */ +@@ -148,11 +183,11 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + + /* Am I the protocol address target? */ + if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 +- && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) ++ && arp_header->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) + { + grub_net_link_level_address_t target; + struct grub_net_buff nb_reply; +- struct arppkt *arp_reply; ++ struct arphdr *arp_reply; + grub_uint8_t arp_data[128]; + grub_err_t err; + +@@ -161,25 +196,39 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + grub_netbuff_clear (&nb_reply); + grub_netbuff_reserve (&nb_reply, 128); + +- err = grub_netbuff_push (&nb_reply, sizeof (*arp_packet)); ++ err = grub_netbuff_push (&nb_reply, arp_packet_len); + if (err) + return err; + +- arp_reply = (struct arppkt *) nb_reply.data; ++ arp_reply = (struct arphdr *) nb_reply.data; + +- arp_reply->hrd = grub_cpu_to_be16_compile_time (GRUB_NET_ARPHRD_ETHERNET); ++ arp_reply->hrd = grub_cpu_to_be16 (hw_type); + arp_reply->pro = grub_cpu_to_be16_compile_time (GRUB_NET_ETHERTYPE_IP); +- arp_reply->pln = 4; +- arp_reply->hln = 6; ++ arp_reply->pln = pln; ++ arp_reply->hln = hln; + arp_reply->op = grub_cpu_to_be16_compile_time (ARP_REPLY); +- arp_reply->sender_ip = arp_packet->recv_ip; +- arp_reply->recv_ip = arp_packet->sender_ip; +- arp_reply->hln = 6; +- +- target.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (target.mac, arp_packet->sender_mac, 6); +- grub_memcpy (arp_reply->sender_mac, inf->hwaddress.mac, 6); +- grub_memcpy (arp_reply->recv_mac, arp_packet->sender_mac, 6); ++ ++ tmp_ptr = nb_reply.data + sizeof (*arp_reply); ++ ++ /* The source hardware address. */ ++ grub_memcpy (tmp_ptr, inf->hwaddress.mac, hln); ++ tmp_ptr += hln; ++ ++ /* The source protocol address. */ ++ grub_memcpy (tmp_ptr, &target_addr.ipv4, pln); ++ tmp_ptr += pln; ++ ++ /* The target hardware address. */ ++ grub_memcpy (tmp_ptr, sender_mac_addr.mac, hln); ++ tmp_ptr += hln; ++ ++ /* The target protocol address */ ++ grub_memcpy (tmp_ptr, &sender_addr.ipv4, pln); ++ tmp_ptr += pln; ++ ++ target.type = hw_type; ++ target.len = hln; ++ grub_memcpy (target.mac, sender_mac_addr.mac, hln); + + /* Change operation to REPLY and send packet */ + send_ethernet_packet (inf, &nb_reply, target, GRUB_NET_ETHERTYPE_ARP); +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 8c969595a7b..3cf6dbf0e72 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -269,7 +269,6 @@ grub_net_configure_by_dhcp_ack (const char *name, + int is_def, char **device, char **path) + { + grub_net_network_level_address_t addr; +- grub_net_link_level_address_t hwaddr; + struct grub_net_network_level_interface *inter; + int mask = -1; + char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; +@@ -286,12 +285,8 @@ grub_net_configure_by_dhcp_ack (const char *name, + if (path) + *path = 0; + +- grub_memcpy (hwaddr.mac, bp->mac_addr, +- bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len +- : sizeof (hwaddr.mac)); +- hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- +- inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags); ++ grub_dprintf("dhcp", "configuring dhcp for %s\n", name); ++ inter = grub_net_add_addr (name, card, &addr, &card->default_address, flags); + if (!inter) + return 0; + +@@ -601,7 +596,9 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) + grub_memset (pack, 0, sizeof (*pack)); + pack->opcode = 1; + pack->hw_type = 1; +- pack->hw_len = 6; ++ pack->hw_len = iface->hwaddress.len > 16 ? 0 ++ : iface->hwaddress.len; ++ + err = grub_get_datetime (&date); + if (err || !grub_datetime2unixtime (&date, &t)) + { +@@ -614,7 +611,7 @@ send_dhcp_packet (struct grub_net_network_level_interface *iface) + else + pack->ident = iface->xid; + +- grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, 6); ++ grub_memcpy (&pack->mac_addr, &iface->hwaddress.mac, pack->hw_len); + + grub_netbuff_push (nb, sizeof (*udph)); + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index a57189e8bb3..4444e8e60ee 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -280,6 +280,9 @@ grub_efinet_findcards (void) + /* This should not happen... Why? */ + continue; + ++ if (net->mode->hwaddr_size > GRUB_NET_MAX_LINK_ADDRESS_SIZE) ++ continue; ++ + if (net->mode->state == GRUB_EFI_NETWORK_STOPPED + && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) + continue; +@@ -316,10 +319,11 @@ grub_efinet_findcards (void) + card->name = grub_xasprintf ("efinet%d", i++); + card->driver = &efidriver; + card->flags = 0; +- card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ card->default_address.type = net->mode->if_type; ++ card->default_address.len = net->mode->hwaddr_size; + grub_memcpy (card->default_address.mac, + net->mode->current_address, +- sizeof (card->default_address.mac)); ++ net->mode->hwaddr_size); + card->efi_net = net; + card->efi_handle = *handle; + +diff --git a/grub-core/net/drivers/emu/emunet.c b/grub-core/net/drivers/emu/emunet.c +index b194920861f..5b6c5e16a6d 100644 +--- a/grub-core/net/drivers/emu/emunet.c ++++ b/grub-core/net/drivers/emu/emunet.c +@@ -46,6 +46,7 @@ static struct grub_net_card emucard = + .mtu = 1500, + .default_address = { + .type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET, ++ . len = 6, + {.mac = {0, 1, 2, 3, 4, 5}} + }, + .flags = 0 +diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c +index 3f4152d036c..9f8fb4b6d2b 100644 +--- a/grub-core/net/drivers/i386/pc/pxe.c ++++ b/grub-core/net/drivers/i386/pc/pxe.c +@@ -386,20 +386,21 @@ GRUB_MOD_INIT(pxe) + grub_memset (ui, 0, sizeof (*ui)); + grub_pxe_call (GRUB_PXENV_UNDI_GET_INFORMATION, ui, pxe_rm_entry); + ++ grub_pxe_card.default_address.len = 6; + grub_memcpy (grub_pxe_card.default_address.mac, ui->current_addr, +- sizeof (grub_pxe_card.default_address.mac)); +- for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++) ++ grub_pxe_card.default_address.len); ++ for (i = 0; i < grub_pxe_card.default_address.len; i++) + if (grub_pxe_card.default_address.mac[i] != 0) + break; +- if (i != sizeof (grub_pxe_card.default_address.mac)) ++ if (i != grub_pxe_card.default_address.len) + { +- for (i = 0; i < sizeof (grub_pxe_card.default_address.mac); i++) ++ for (i = 0; i < grub_pxe_card.default_address.len; i++) + if (grub_pxe_card.default_address.mac[i] != 0xff) + break; + } +- if (i == sizeof (grub_pxe_card.default_address.mac)) ++ if (i == grub_pxe_card.default_address.len) + grub_memcpy (grub_pxe_card.default_address.mac, ui->permanent_addr, +- sizeof (grub_pxe_card.default_address.mac)); ++ grub_pxe_card.default_address.len); + grub_pxe_card.mtu = ui->mtu; + + grub_pxe_card.default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c +index 3860b6f78d8..bcb3f9ea02d 100644 +--- a/grub-core/net/drivers/ieee1275/ofnet.c ++++ b/grub-core/net/drivers/ieee1275/ofnet.c +@@ -160,6 +160,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, + grub_uint16_t vlantag = 0; + + hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ hw_addr.len = 6; + + args = bootpath + grub_strlen (devpath) + 1; + do +@@ -503,6 +504,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias) + grub_memcpy (&lla.mac, pprop, 6); + + lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ lla.len = 6; + card->default_address = lla; + + card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; +diff --git a/grub-core/net/drivers/uboot/ubootnet.c b/grub-core/net/drivers/uboot/ubootnet.c +index 056052e40d5..22ebcbf211e 100644 +--- a/grub-core/net/drivers/uboot/ubootnet.c ++++ b/grub-core/net/drivers/uboot/ubootnet.c +@@ -131,6 +131,7 @@ GRUB_MOD_INIT (ubootnet) + + grub_memcpy (&(card->default_address.mac), &devinfo->di_net.hwaddr, 6); + card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ card->default_address.len = 6; + + card->txbufsize = ALIGN_UP (card->mtu, 64) + 256; + card->txbuf = grub_zalloc (card->txbufsize); +diff --git a/grub-core/net/ethernet.c b/grub-core/net/ethernet.c +index 4d7ceed6f93..9aae83a5eb4 100644 +--- a/grub-core/net/ethernet.c ++++ b/grub-core/net/ethernet.c +@@ -29,13 +29,6 @@ + + #define LLCADDRMASK 0x7f + +-struct etherhdr +-{ +- grub_uint8_t dst[6]; +- grub_uint8_t src[6]; +- grub_uint16_t type; +-} GRUB_PACKED; +- + struct llchdr + { + grub_uint8_t dsap; +@@ -55,13 +48,15 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, + grub_net_link_level_address_t target_addr, + grub_net_ethertype_t ethertype) + { +- struct etherhdr *eth; ++ grub_uint8_t *eth; + grub_err_t err; +- grub_uint8_t etherhdr_size; +- grub_uint16_t vlantag_id = VLANTAG_IDENTIFIER; ++ grub_uint32_t vlantag = 0; ++ grub_uint8_t hw_addr_len = inf->card->default_address.len; ++ grub_uint8_t etherhdr_size = 2 * hw_addr_len + 2; + +- etherhdr_size = sizeof (*eth); +- COMPILE_TIME_ASSERT (sizeof (*eth) + 4 < GRUB_NET_MAX_LINK_HEADER_SIZE); ++ /* Source and destination link addresses + ethertype + vlan tag */ ++ COMPILE_TIME_ASSERT ((GRUB_NET_MAX_LINK_ADDRESS_SIZE * 2 + 2 + 4) < ++ GRUB_NET_MAX_LINK_HEADER_SIZE); + + /* Increase ethernet header in case of vlantag */ + if (inf->vlantag != 0) +@@ -70,11 +65,22 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, + err = grub_netbuff_push (nb, etherhdr_size); + if (err) + return err; +- eth = (struct etherhdr *) nb->data; +- grub_memcpy (eth->dst, target_addr.mac, 6); +- grub_memcpy (eth->src, inf->hwaddress.mac, 6); ++ eth = nb->data; ++ grub_memcpy (eth, target_addr.mac, hw_addr_len); ++ eth += hw_addr_len; ++ grub_memcpy (eth, inf->hwaddress.mac, hw_addr_len); ++ eth += hw_addr_len; ++ ++ /* Check if a vlan-tag is present. */ ++ if (vlantag != 0) ++ { ++ *((grub_uint32_t *)eth) = grub_cpu_to_be32 (vlantag); ++ eth += sizeof (vlantag); ++ } ++ ++ /* Write ethertype */ ++ *((grub_uint16_t*) eth) = grub_cpu_to_be16 (ethertype); + +- eth->type = grub_cpu_to_be16 (ethertype); + if (!inf->card->opened) + { + err = GRUB_ERR_NONE; +@@ -85,18 +91,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf, + inf->card->opened = 1; + } + +- /* Check and add a vlan-tag if needed. */ +- if (inf->vlantag != 0) +- { +- /* Move eth type to the right */ +- grub_memcpy ((char *) nb->data + etherhdr_size - 2, +- (char *) nb->data + etherhdr_size - 6, 2); +- +- /* Add the tag in the middle */ +- grub_memcpy ((char *) nb->data + etherhdr_size - 6, &vlantag_id, 2); +- grub_memcpy ((char *) nb->data + etherhdr_size - 4, (char *) &(inf->vlantag), 2); +- } +- + return inf->card->driver->send (inf->card, nb); + } + +@@ -104,31 +98,40 @@ grub_err_t + grub_net_recv_ethernet_packet (struct grub_net_buff *nb, + struct grub_net_card *card) + { +- struct etherhdr *eth; ++ grub_uint8_t *eth; + struct llchdr *llch; + struct snaphdr *snaph; + grub_net_ethertype_t type; + grub_net_link_level_address_t hwaddress; + grub_net_link_level_address_t src_hwaddress; + grub_err_t err; +- grub_uint8_t etherhdr_size = sizeof (*eth); ++ grub_uint8_t hw_addr_len = card->default_address.len; ++ grub_uint8_t etherhdr_size = 2 * hw_addr_len + 2; + grub_uint16_t vlantag = 0; + ++ eth = nb->data; + +- /* Check if a vlan-tag is present. If so, the ethernet header is 4 bytes */ +- /* longer than the original one. The vlantag id is extracted and the header */ +- /* is reseted to the original size. */ +- if (grub_get_unaligned16 (nb->data + etherhdr_size - 2) == VLANTAG_IDENTIFIER) ++ hwaddress.type = card->default_address.type; ++ hwaddress.len = hw_addr_len; ++ grub_memcpy (hwaddress.mac, eth, hw_addr_len); ++ eth += hw_addr_len; ++ ++ src_hwaddress.type = card->default_address.type; ++ src_hwaddress.len = hw_addr_len; ++ grub_memcpy (src_hwaddress.mac, eth, hw_addr_len); ++ eth += hw_addr_len; ++ ++ type = grub_be_to_cpu16 (*(grub_uint16_t*)(eth)); ++ if (type == VLANTAG_IDENTIFIER) + { +- vlantag = grub_get_unaligned16 (nb->data + etherhdr_size); ++ /* Skip vlan tag */ ++ eth += 2; ++ vlantag = grub_be_to_cpu16 (*(grub_uint16_t*)(eth)); + etherhdr_size += 4; +- /* Move eth type to the original position */ +- grub_memcpy((char *) nb->data + etherhdr_size - 6, +- (char *) nb->data + etherhdr_size - 2, 2); ++ eth += 2; ++ type = grub_be_to_cpu16 (*(grub_uint16_t*)(eth)); + } + +- eth = (struct etherhdr *) nb->data; +- type = grub_be_to_cpu16 (eth->type); + err = grub_netbuff_pull (nb, etherhdr_size); + if (err) + return err; +@@ -148,11 +151,6 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb, + } + } + +- hwaddress.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (hwaddress.mac, eth->dst, sizeof (hwaddress.mac)); +- src_hwaddress.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (src_hwaddress.mac, eth->src, sizeof (src_hwaddress.mac)); +- + switch (type) + { + /* ARP packet. */ +diff --git a/grub-core/net/icmp6.c b/grub-core/net/icmp6.c +index 2cbd95dce25..56a3ec5c8e8 100644 +--- a/grub-core/net/icmp6.c ++++ b/grub-core/net/icmp6.c +@@ -231,8 +231,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, + && ohdr->len == 1) + { + grub_net_link_level_address_t ll_address; +- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac)); ++ ll_address.type = card->default_address.type; ++ ll_address.len = card->default_address.len; ++ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len); + grub_net_link_layer_add_address (card, source, &ll_address, 0); + } + } +@@ -335,8 +336,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, + && ohdr->len == 1) + { + grub_net_link_level_address_t ll_address; +- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac)); ++ ll_address.type = card->default_address.type; ++ ll_address.len = card->default_address.len; ++ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len); + grub_net_link_layer_add_address (card, source, &ll_address, 0); + } + } +@@ -384,8 +386,9 @@ grub_net_recv_icmp6_packet (struct grub_net_buff *nb, + && ohdr->len == 1) + { + grub_net_link_level_address_t ll_address; +- ll_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (ll_address.mac, ohdr + 1, sizeof (ll_address.mac)); ++ ll_address.type = card->default_address.type; ++ ll_address.len = card->default_address.len; ++ grub_memcpy (ll_address.mac, ohdr + 1, ll_address.len); + grub_net_link_layer_add_address (card, source, &ll_address, 0); + } + if (ohdr->type == OPTION_PREFIX && ohdr->len == 4) +diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c +index ea5edf8f1f6..a5896f6dc26 100644 +--- a/grub-core/net/ip.c ++++ b/grub-core/net/ip.c +@@ -276,8 +276,8 @@ handle_dgram (struct grub_net_buff *nb, + if (inf->card == card + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV + && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET +- && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr, +- sizeof (inf->hwaddress.mac)) == 0) ++ && (grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr, ++ bootp->hw_len) == 0 || bootp->hw_len == 0)) + { + grub_net_process_dhcp (nb, inf); + grub_netbuff_free (nb); +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 5366e443d2a..6468eb24596 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -128,8 +128,9 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, + << 48) + && proto_addr->ipv6[1] == (grub_be_to_cpu64_compile_time (1)))) + { +- hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memset (hw_addr->mac, -1, 6); ++ hw_addr->type = inf->card->default_address.type; ++ hw_addr->len = inf->card->default_address.len; ++ grub_memset (hw_addr->mac, -1, hw_addr->len); + return GRUB_ERR_NONE; + } + +@@ -137,6 +138,7 @@ grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, + && ((grub_be_to_cpu64 (proto_addr->ipv6[0]) >> 56) == 0xff)) + { + hw_addr->type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; ++ hw_addr->len = inf->card->default_address.len; + hw_addr->mac[0] = 0x33; + hw_addr->mac[1] = 0x33; + hw_addr->mac[2] = ((grub_be_to_cpu64 (proto_addr->ipv6[1]) >> 24) & 0xff); +@@ -757,23 +759,23 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf) + void + grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) + { +- str[0] = 0; +- switch (addr->type) ++ char *ptr; ++ unsigned i; ++ int maxstr; ++ ++ if (addr->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE) + { +- case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET: +- { +- char *ptr; +- unsigned i; +- for (ptr = str, i = 0; i < ARRAY_SIZE (addr->mac); i++) +- { +- grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str), +- "%02x:", addr->mac[i] & 0xff); +- ptr += (sizeof ("XX:") - 1); +- } +- return; +- } ++ str[0] = 0; ++ grub_printf (_("Unsupported hw address type %d len %d\n"), ++ addr->type, addr->len); ++ return; ++ } ++ maxstr = addr->len * grub_strlen ("XX:"); ++ for (ptr = str, i = 0; i < addr->len; i++) ++ { ++ ptr += grub_snprintf (ptr, maxstr - (ptr - str), ++ "%02x:", addr->mac[i] & 0xff); + } +- grub_printf (_("Unsupported hw address type %d\n"), addr->type); + } + + int +@@ -784,13 +786,17 @@ grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, + return -1; + if (a->type > b->type) + return +1; +- switch (a->type) ++ if (a->len < b->len) ++ return -1; ++ if (a->len > b->len) ++ return +1; ++ if (a->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE) + { +- case GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET: +- return grub_memcmp (a->mac, b->mac, sizeof (a->mac)); ++ grub_printf (_("Unsupported hw address type %d len %d\n"), ++ a->type, a->len); ++ return + 1; + } +- grub_printf (_("Unsupported hw address type %d\n"), a->type); +- return 1; ++ return grub_memcmp (a->mac, b->mac, a->len); + } + + int +diff --git a/include/grub/net.h b/include/grub/net.h +index 3647012374b..fc1fc44baef 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -29,7 +29,8 @@ + + enum + { +- GRUB_NET_MAX_LINK_HEADER_SIZE = 64, ++ GRUB_NET_MAX_LINK_HEADER_SIZE = 96, ++ GRUB_NET_MAX_LINK_ADDRESS_SIZE = 32, + GRUB_NET_UDP_HEADER_SIZE = 8, + GRUB_NET_TCP_HEADER_SIZE = 20, + GRUB_NET_OUR_IPV4_HEADER_SIZE = 20, +@@ -42,15 +43,17 @@ enum + + typedef enum grub_link_level_protocol_id + { +- GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET ++ /* IANA ARP constant to define hardware type. */ ++ GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET = 1, + } grub_link_level_protocol_id_t; + + typedef struct grub_net_link_level_address + { + grub_link_level_protocol_id_t type; ++ grub_uint8_t len; + union + { +- grub_uint8_t mac[6]; ++ grub_uint8_t mac[GRUB_NET_MAX_LINK_ADDRESS_SIZE]; + }; + } grub_net_link_level_address_t; + +@@ -566,11 +569,13 @@ grub_net_addr_cmp (const grub_net_network_level_address_t *a, + #define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX") + + /* +- Currently suppoerted adresses: +- ethernet: XX:XX:XX:XX:XX:XX ++ Up to 32 byte hardware address supported, see GRUB_NET_MAX_LINK_ADDRESS_SIZE + */ +- +-#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof ("XX:XX:XX:XX:XX:XX")) ++#define GRUB_NET_MAX_STR_HWADDR_LEN (sizeof (\ ++ "XX:XX:XX:XX:XX:XX:XX:XX:"\ ++ "XX:XX:XX:XX:XX:XX:XX:XX:"\ ++ "XX:XX:XX:XX:XX:XX:XX:XX:"\ ++ "XX:XX:XX:XX:XX:XX:XX:XX")) + + void + grub_net_addr_to_str (const grub_net_network_level_address_t *target, diff --git a/0110-misc-fix-invalid-character-recongition-in-strto-l.patch b/0110-misc-fix-invalid-character-recongition-in-strto-l.patch new file mode 100644 index 0000000..4006028 --- /dev/null +++ b/0110-misc-fix-invalid-character-recongition-in-strto-l.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aaron Miller +Date: Fri, 29 Jul 2016 17:41:27 +0800 +Subject: [PATCH] misc: fix invalid character recongition in strto*l + +Would previously allow digits larger than the base and didn't check that +subtracting the difference from 0-9 to lowercase letters for characters +larger than 9 didn't result in a value lower than 9, which allowed the +parses: ` = 9, _ = 8, ^ = 7, ] = 6, \ = 5, and [ = 4 +--- + grub-core/kern/misc.c | 13 ++++++++----- + 1 file changed, 8 insertions(+), 5 deletions(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 0e89c483d5e..5c3899f0e5b 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -434,11 +434,14 @@ grub_strtoull (const char *str, char **end, int base) + unsigned long digit; + + digit = grub_tolower (*str) - '0'; +- if (digit >= 'a' - '0') +- digit += '0' - 'a' + 10; +- else if (digit > 9) +- break; +- ++ if (digit > 9) ++ { ++ digit += '0' - 'a' + 10; ++ /* digit <= 9 check is needed to keep chars larger than ++ '9' but less than 'a' from being read as numbers */ ++ if (digit >= (unsigned long) base || digit <= 9) ++ break; ++ } + if (digit >= (unsigned long) base) + break; + diff --git a/0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch b/0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch new file mode 100644 index 0000000..a2701b3 --- /dev/null +++ b/0111-net-read-bracketed-ipv6-addrs-and-port-numbers.patch @@ -0,0 +1,273 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aaron Miller +Date: Fri, 29 Jul 2016 17:41:38 +0800 +Subject: [PATCH] net: read bracketed ipv6 addrs and port numbers + +Allow specifying port numbers for http and tftp paths, and allow ipv6 addresses +to be recognized with brackets around them, which is required to specify a port +number + +Signed-off-by: Aaron Miller +[pjones: various bug fixes] +Signed-off-by: Peter Jones +--- + grub-core/net/http.c | 27 ++++++++++++---- + grub-core/net/net.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++--- + grub-core/net/tftp.c | 8 +++-- + include/grub/net.h | 1 + + 4 files changed, 110 insertions(+), 13 deletions(-) + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index 5aa4ad3befc..00737c52750 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -289,7 +289,9 @@ http_receive (grub_net_tcp_socket_t sock __attribute__ ((unused)), + nb2 = grub_netbuff_alloc (data->chunk_rem); + if (!nb2) + return grub_errno; +- grub_netbuff_put (nb2, data->chunk_rem); ++ err = grub_netbuff_put (nb2, data->chunk_rem); ++ if (err) ++ return grub_errno; + grub_memcpy (nb2->data, nb->data, data->chunk_rem); + if (file->device->net->packs.count >= 20) + { +@@ -312,12 +314,14 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) + int i; + struct grub_net_buff *nb; + grub_err_t err; ++ char* server = file->device->net->server; ++ int port = file->device->net->port; + + nb = grub_netbuff_alloc (GRUB_NET_TCP_RESERVE_SIZE + + sizeof ("GET ") - 1 + + grub_strlen (data->filename) + + sizeof (" HTTP/1.1\r\nHost: ") - 1 +- + grub_strlen (file->device->net->server) ++ + grub_strlen (server) + sizeof (":XXXXXXXXXX") + + sizeof ("\r\nUser-Agent: " PACKAGE_STRING + "\r\n") - 1 + + sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX" +@@ -356,7 +360,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) + sizeof (" HTTP/1.1\r\nHost: ") - 1); + + ptr = nb->tail; +- err = grub_netbuff_put (nb, grub_strlen (file->device->net->server)); ++ err = grub_netbuff_put (nb, grub_strlen (server)); + if (err) + { + grub_netbuff_free (nb); +@@ -365,6 +369,15 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) + grub_memcpy (ptr, file->device->net->server, + grub_strlen (file->device->net->server)); + ++ if (port) ++ { ++ ptr = nb->tail; ++ grub_snprintf ((char *) ptr, ++ sizeof (":XXXXXXXXXX"), ++ ":%d", ++ port); ++ } ++ + ptr = nb->tail; + err = grub_netbuff_put (nb, + sizeof ("\r\nUser-Agent: " PACKAGE_STRING "\r\n") +@@ -390,9 +403,11 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) + grub_netbuff_put (nb, 2); + grub_memcpy (ptr, "\r\n", 2); + +- data->sock = grub_net_tcp_open (file->device->net->server, +- HTTP_PORT, http_receive, +- http_err, http_err, ++ grub_dprintf ("http", "opening path %s on host %s TCP port %d\n", ++ data->filename, server, port ? port : HTTP_PORT); ++ data->sock = grub_net_tcp_open (server, ++ port ? port : HTTP_PORT, http_receive, ++ http_err, NULL, + file); + if (!data->sock) + { +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 6468eb24596..2734f70d22f 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -439,6 +439,13 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + grub_uint16_t newip[8]; + const char *ptr = val; + int word, quaddot = -1; ++ int bracketed = 0; ++ ++ if (ptr[0] == '[') ++ { ++ bracketed = 1; ++ ptr++; ++ } + + if (ptr[0] == ':' && ptr[1] != ':') + return 0; +@@ -477,6 +484,8 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0])); + } + grub_memcpy (ip, newip, 16); ++ if (bracketed && *ptr == ']') ++ ptr++; + if (rest) + *rest = ptr; + return 1; +@@ -1338,8 +1347,10 @@ grub_net_open_real (const char *name) + { + grub_net_app_level_t proto; + const char *protname, *server; ++ char *host; + grub_size_t protnamelen; + int try; ++ int port = 0; + + if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) + { +@@ -1377,6 +1388,72 @@ grub_net_open_real (const char *name) + return NULL; + } + ++ char* port_start; ++ /* ipv6 or port specified? */ ++ if ((port_start = grub_strchr (server, ':'))) ++ { ++ char* ipv6_begin; ++ if((ipv6_begin = grub_strchr (server, '['))) ++ { ++ char* ipv6_end = grub_strchr (server, ']'); ++ if(!ipv6_end) ++ { ++ grub_error (GRUB_ERR_NET_BAD_ADDRESS, ++ N_("mismatched [ in address")); ++ return NULL; ++ } ++ /* port number after bracketed ipv6 addr */ ++ if(ipv6_end[1] == ':') ++ { ++ port = grub_strtoul (ipv6_end + 2, NULL, 10); ++ if(port > 65535) ++ { ++ grub_error (GRUB_ERR_NET_BAD_ADDRESS, ++ N_("bad port number")); ++ return NULL; ++ } ++ } ++ host = grub_strndup (ipv6_begin, (ipv6_end - ipv6_begin) + 1); ++ } ++ else ++ { ++ if (grub_strchr (port_start + 1, ':')) ++ { ++ int iplen = grub_strlen (server); ++ /* bracket bare ipv6 addrs */ ++ host = grub_malloc (iplen + 3); ++ if(!host) ++ { ++ return NULL; ++ } ++ host[0] = '['; ++ grub_memcpy (host + 1, server, iplen); ++ host[iplen + 1] = ']'; ++ host[iplen + 2] = '\0'; ++ } ++ else ++ { ++ /* hostname:port or ipv4:port */ ++ port = grub_strtol (port_start + 1, NULL, 10); ++ if(port > 65535) ++ { ++ grub_error (GRUB_ERR_NET_BAD_ADDRESS, ++ N_("bad port number")); ++ return NULL; ++ } ++ host = grub_strndup (server, port_start - server); ++ } ++ } ++ } ++ else ++ { ++ host = grub_strdup (server); ++ } ++ if (!host) ++ { ++ return NULL; ++ } ++ + for (try = 0; try < 2; try++) + { + FOR_NET_APP_LEVEL (proto) +@@ -1386,14 +1463,13 @@ grub_net_open_real (const char *name) + { + grub_net_t ret = grub_zalloc (sizeof (*ret)); + if (!ret) +- return NULL; +- ret->protocol = proto; +- ret->server = grub_strdup (server); +- if (!ret->server) + { +- grub_free (ret); ++ grub_free (host); + return NULL; + } ++ ret->protocol = proto; ++ ret->port = port; ++ ret->server = host; + ret->fs = &grub_net_fs; + return ret; + } +@@ -1468,6 +1544,7 @@ grub_net_open_real (const char *name) + grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"), + name); + ++ grub_free (host); + return NULL; + } + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 0c02a00255b..4920c3a9783 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -333,6 +333,7 @@ tftp_open (struct grub_file *file, const char *filename) + grub_err_t err; + grub_uint8_t *nbd; + grub_net_network_level_address_t addr; ++ int port = file->device->net->port; + + data = grub_zalloc (sizeof (*data)); + if (!data) +@@ -405,7 +406,10 @@ tftp_open (struct grub_file *file, const char *filename) + err = grub_net_resolve_address (file->device->net->server, &addr); + if (err) + { +- grub_dprintf("tftp", "Address resolution failed: %d\n", err); ++ grub_dprintf ("tftp", "Address resolution failed: %d\n", err); ++ grub_dprintf ("tftp", "file_size is %llu, block_size is %llu\n", ++ (unsigned long long)data->file_size, ++ (unsigned long long)data->block_size); + destroy_pq (data); + grub_free (data); + return err; +@@ -413,7 +417,7 @@ tftp_open (struct grub_file *file, const char *filename) + + grub_dprintf ("tftp", "opening connection\n"); + data->sock = grub_net_udp_open (addr, +- TFTP_SERVER_PORT, tftp_receive, ++ port ? port : TFTP_SERVER_PORT, tftp_receive, + file); + if (!data->sock) + { +diff --git a/include/grub/net.h b/include/grub/net.h +index fc1fc44baef..fa7a8c39704 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -273,6 +273,7 @@ typedef struct grub_net + { + char *server; + char *name; ++ int port; + grub_net_app_level_t protocol; + grub_net_packets_t packs; + grub_off_t offset; diff --git a/0112-bootp-New-net_bootp6-command.patch b/0112-bootp-New-net_bootp6-command.patch new file mode 100644 index 0000000..8cb4ed8 --- /dev/null +++ b/0112-bootp-New-net_bootp6-command.patch @@ -0,0 +1,1368 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 10 Jul 2019 15:42:36 +0200 +Subject: [PATCH] bootp: New net_bootp6 command + +Implement new net_bootp6 command for IPv6 network auto configuration via the +DHCPv6 protocol (RFC3315). + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +[pjones: Put back our code to add a local route] +Signed-off-by: Peter Jones +--- + grub-core/net/bootp.c | 1059 ++++++++++++++++++++++++++++++------ + grub-core/net/drivers/efi/efinet.c | 20 +- + grub-core/net/ip.c | 39 ++ + include/grub/efi/api.h | 2 +- + include/grub/net.h | 91 ++-- + 5 files changed, 1002 insertions(+), 209 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 3cf6dbf0e72..85adc9cb447 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -25,6 +25,98 @@ + #include + #include + #include ++#include ++#include ++ ++static int ++dissect_url (const char *url, char **proto, char **host, char **path) ++{ ++ const char *p, *ps; ++ grub_size_t l; ++ ++ *proto = *host = *path = NULL; ++ ps = p = url; ++ ++ while ((p = grub_strchr (p, ':'))) ++ { ++ if (grub_strlen (p) < sizeof ("://") - 1) ++ break; ++ if (grub_memcmp (p, "://", sizeof ("://") - 1) == 0) ++ { ++ l = p - ps; ++ *proto = grub_malloc (l + 1); ++ if (!*proto) ++ { ++ grub_print_error (); ++ return 0; ++ } ++ ++ grub_memcpy (*proto, ps, l); ++ (*proto)[l] = '\0'; ++ p += sizeof ("://") - 1; ++ break; ++ } ++ ++p; ++ } ++ ++ if (!*proto) ++ { ++ grub_dprintf ("bootp", "url: %s is not valid, protocol not found\n", url); ++ return 0; ++ } ++ ++ ps = p; ++ p = grub_strchr (p, '/'); ++ ++ if (!p) ++ { ++ grub_dprintf ("bootp", "url: %s is not valid, host/path not found\n", url); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ ++ l = p - ps; ++ ++ if (l > 2 && ps[0] == '[' && ps[l - 1] == ']') ++ { ++ *host = grub_malloc (l - 1); ++ if (!*host) ++ { ++ grub_print_error (); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ grub_memcpy (*host, ps + 1, l - 2); ++ (*host)[l - 2] = 0; ++ } ++ else ++ { ++ *host = grub_malloc (l + 1); ++ if (!*host) ++ { ++ grub_print_error (); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ grub_memcpy (*host, ps, l); ++ (*host)[l] = 0; ++ } ++ ++ *path = grub_strdup (p); ++ if (!*path) ++ { ++ grub_print_error (); ++ grub_free (*host); ++ grub_free (*proto); ++ *host = NULL; ++ *proto = NULL; ++ return 0; ++ } ++ return 1; ++} + + struct grub_dhcp_discover_options + { +@@ -638,6 +730,584 @@ out: + return err; + } + ++/* The default netbuff size for sending DHCPv6 packets which should be ++ large enough to hold the information */ ++#define GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE 512 ++ ++struct grub_dhcp6_options ++{ ++ grub_uint8_t *client_duid; ++ grub_uint16_t client_duid_len; ++ grub_uint8_t *server_duid; ++ grub_uint16_t server_duid_len; ++ grub_uint32_t iaid; ++ grub_uint32_t t1; ++ grub_uint32_t t2; ++ grub_net_network_level_address_t *ia_addr; ++ grub_uint32_t preferred_lifetime; ++ grub_uint32_t valid_lifetime; ++ grub_net_network_level_address_t *dns_server_addrs; ++ grub_uint16_t num_dns_server; ++ char *boot_file_proto; ++ char *boot_file_server_ip; ++ char *boot_file_path; ++}; ++ ++typedef struct grub_dhcp6_options *grub_dhcp6_options_t; ++ ++struct grub_dhcp6_session ++{ ++ struct grub_dhcp6_session *next; ++ struct grub_dhcp6_session **prev; ++ grub_uint32_t iaid; ++ grub_uint32_t transaction_id:24; ++ grub_uint64_t start_time; ++ struct grub_net_dhcp6_option_duid_ll duid; ++ struct grub_net_network_level_interface *iface; ++ ++ /* The associated dhcpv6 options */ ++ grub_dhcp6_options_t adv; ++ grub_dhcp6_options_t reply; ++}; ++ ++typedef struct grub_dhcp6_session *grub_dhcp6_session_t; ++ ++typedef void (*dhcp6_option_hook_fn) (const struct grub_net_dhcp6_option *opt, void *data); ++ ++static void ++foreach_dhcp6_option (const struct grub_net_dhcp6_option *opt, grub_size_t size, ++ dhcp6_option_hook_fn hook, void *hook_data); ++ ++static void ++parse_dhcp6_iaaddr (const struct grub_net_dhcp6_option *opt, void *data) ++{ ++ grub_dhcp6_options_t dhcp6 = (grub_dhcp6_options_t )data; ++ ++ grub_uint16_t code = grub_be_to_cpu16 (opt->code); ++ grub_uint16_t len = grub_be_to_cpu16 (opt->len); ++ ++ if (code == GRUB_NET_DHCP6_OPTION_IAADDR) ++ { ++ const struct grub_net_dhcp6_option_iaaddr *iaaddr; ++ iaaddr = (const struct grub_net_dhcp6_option_iaaddr *)opt->data; ++ ++ if (len < sizeof (*iaaddr)) ++ { ++ grub_dprintf ("bootp", "DHCPv6: code %u with insufficient length %u\n", code, len); ++ return; ++ } ++ if (!dhcp6->ia_addr) ++ { ++ dhcp6->ia_addr = grub_malloc (sizeof(*dhcp6->ia_addr)); ++ dhcp6->ia_addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ dhcp6->ia_addr->ipv6[0] = grub_get_unaligned64 (iaaddr->addr); ++ dhcp6->ia_addr->ipv6[1] = grub_get_unaligned64 (iaaddr->addr + 8); ++ dhcp6->preferred_lifetime = grub_be_to_cpu32 (iaaddr->preferred_lifetime); ++ dhcp6->valid_lifetime = grub_be_to_cpu32 (iaaddr->valid_lifetime); ++ } ++ } ++} ++ ++static void ++parse_dhcp6_option (const struct grub_net_dhcp6_option *opt, void *data) ++{ ++ grub_dhcp6_options_t dhcp6 = (grub_dhcp6_options_t)data; ++ grub_uint16_t code = grub_be_to_cpu16 (opt->code); ++ grub_uint16_t len = grub_be_to_cpu16 (opt->len); ++ ++ switch (code) ++ { ++ case GRUB_NET_DHCP6_OPTION_CLIENTID: ++ ++ if (dhcp6->client_duid || !len) ++ { ++ grub_dprintf ("bootp", "Skipped DHCPv6 CLIENTID with length %u\n", len); ++ break; ++ } ++ dhcp6->client_duid = grub_malloc (len); ++ grub_memcpy (dhcp6->client_duid, opt->data, len); ++ dhcp6->client_duid_len = len; ++ break; ++ ++ case GRUB_NET_DHCP6_OPTION_SERVERID: ++ ++ if (dhcp6->server_duid || !len) ++ { ++ grub_dprintf ("bootp", "Skipped DHCPv6 SERVERID with length %u\n", len); ++ break; ++ } ++ dhcp6->server_duid = grub_malloc (len); ++ grub_memcpy (dhcp6->server_duid, opt->data, len); ++ dhcp6->server_duid_len = len; ++ break; ++ ++ case GRUB_NET_DHCP6_OPTION_IA_NA: ++ { ++ const struct grub_net_dhcp6_option_iana *ia_na; ++ grub_uint16_t data_len; ++ ++ if (dhcp6->iaid || len < sizeof (*ia_na)) ++ { ++ grub_dprintf ("bootp", "Skipped DHCPv6 IA_NA with length %u\n", len); ++ break; ++ } ++ ia_na = (const struct grub_net_dhcp6_option_iana *)opt->data; ++ dhcp6->iaid = grub_be_to_cpu32 (ia_na->iaid); ++ dhcp6->t1 = grub_be_to_cpu32 (ia_na->t1); ++ dhcp6->t2 = grub_be_to_cpu32 (ia_na->t2); ++ ++ data_len = len - sizeof (*ia_na); ++ if (data_len) ++ foreach_dhcp6_option ((const struct grub_net_dhcp6_option *)ia_na->data, data_len, parse_dhcp6_iaaddr, dhcp6); ++ } ++ break; ++ ++ case GRUB_NET_DHCP6_OPTION_DNS_SERVERS: ++ { ++ const grub_uint8_t *po; ++ grub_uint16_t ln; ++ grub_net_network_level_address_t *la; ++ ++ if (!len || len & 0xf) ++ { ++ grub_dprintf ("bootp", "Skip invalid length DHCPv6 DNS_SERVERS \n"); ++ break; ++ } ++ dhcp6->num_dns_server = ln = len >> 4; ++ dhcp6->dns_server_addrs = la = grub_zalloc (ln * sizeof (*la)); ++ ++ for (po = opt->data; ln > 0; po += 0x10, la++, ln--) ++ { ++ la->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ la->ipv6[0] = grub_get_unaligned64 (po); ++ la->ipv6[1] = grub_get_unaligned64 (po + 8); ++ la->option = DNS_OPTION_PREFER_IPV6; ++ } ++ } ++ break; ++ ++ case GRUB_NET_DHCP6_OPTION_BOOTFILE_URL: ++ dissect_url ((const char *)opt->data, ++ &dhcp6->boot_file_proto, ++ &dhcp6->boot_file_server_ip, ++ &dhcp6->boot_file_path); ++ break; ++ ++ default: ++ break; ++ } ++} ++ ++static void ++foreach_dhcp6_option (const struct grub_net_dhcp6_option *opt, grub_size_t size, dhcp6_option_hook_fn hook, void *hook_data) ++{ ++ while (size) ++ { ++ grub_uint16_t code, len; ++ ++ if (size < sizeof (*opt)) ++ { ++ grub_dprintf ("bootp", "DHCPv6: Options stopped with remaining size %" PRIxGRUB_SIZE "\n", size); ++ break; ++ } ++ size -= sizeof (*opt); ++ len = grub_be_to_cpu16 (opt->len); ++ code = grub_be_to_cpu16 (opt->code); ++ if (size < len) ++ { ++ grub_dprintf ("bootp", "DHCPv6: Options stopped at out of bound length %u for option %u\n", len, code); ++ break; ++ } ++ if (!len) ++ { ++ grub_dprintf ("bootp", "DHCPv6: Options stopped at zero length option %u\n", code); ++ break; ++ } ++ else ++ { ++ if (hook) ++ hook (opt, hook_data); ++ size -= len; ++ opt = (const struct grub_net_dhcp6_option *)((grub_uint8_t *)opt + len + sizeof (*opt)); ++ } ++ } ++} ++ ++static grub_dhcp6_options_t ++grub_dhcp6_options_get (const struct grub_net_dhcp6_packet *v6h, ++ grub_size_t size) ++{ ++ grub_dhcp6_options_t options; ++ ++ if (size < sizeof (*v6h)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("DHCPv6 packet size too small")); ++ return NULL; ++ } ++ ++ options = grub_zalloc (sizeof(*options)); ++ if (!options) ++ return NULL; ++ ++ foreach_dhcp6_option ((const struct grub_net_dhcp6_option *)v6h->dhcp_options, ++ size - sizeof (*v6h), parse_dhcp6_option, options); ++ ++ return options; ++} ++ ++static void ++grub_dhcp6_options_free (grub_dhcp6_options_t options) ++{ ++ if (options->client_duid) ++ grub_free (options->client_duid); ++ if (options->server_duid) ++ grub_free (options->server_duid); ++ if (options->ia_addr) ++ grub_free (options->ia_addr); ++ if (options->dns_server_addrs) ++ grub_free (options->dns_server_addrs); ++ if (options->boot_file_proto) ++ grub_free (options->boot_file_proto); ++ if (options->boot_file_server_ip) ++ grub_free (options->boot_file_server_ip); ++ if (options->boot_file_path) ++ grub_free (options->boot_file_path); ++ ++ grub_free (options); ++} ++ ++static grub_dhcp6_session_t grub_dhcp6_sessions; ++#define FOR_DHCP6_SESSIONS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE (var, next, grub_dhcp6_sessions) ++#define FOR_DHCP6_SESSIONS(var) FOR_LIST_ELEMENTS (var, grub_dhcp6_sessions) ++ ++static void ++grub_net_configure_by_dhcp6_info (const char *name, ++ struct grub_net_card *card, ++ grub_dhcp6_options_t dhcp6, ++ int is_def, ++ int flags, ++ struct grub_net_network_level_interface **ret_inf) ++{ ++ grub_net_network_level_netaddress_t netaddr; ++ struct grub_net_network_level_interface *inf; ++ ++ if (dhcp6->ia_addr) ++ { ++ inf = grub_net_add_addr (name, card, dhcp6->ia_addr, &card->default_address, flags); ++ ++ netaddr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ netaddr.ipv6.base[0] = dhcp6->ia_addr->ipv6[0]; ++ netaddr.ipv6.base[1] = 0; ++ netaddr.ipv6.masksize = 64; ++ grub_net_add_route (name, netaddr, inf); ++ ++ if (ret_inf) ++ *ret_inf = inf; ++ } ++ ++ if (dhcp6->dns_server_addrs) ++ { ++ grub_uint16_t i; ++ ++ for (i = 0; i < dhcp6->num_dns_server; ++i) ++ grub_net_add_dns_server (dhcp6->dns_server_addrs + i); ++ } ++ ++ if (dhcp6->boot_file_path) ++ grub_env_set_net_property (name, "boot_file", dhcp6->boot_file_path, ++ grub_strlen (dhcp6->boot_file_path)); ++ ++ if (is_def && dhcp6->boot_file_server_ip) ++ { ++ grub_net_default_server = grub_strdup (dhcp6->boot_file_server_ip); ++ grub_env_set ("net_default_interface", name); ++ grub_env_export ("net_default_interface"); ++ } ++} ++ ++static void ++grub_dhcp6_session_add (struct grub_net_network_level_interface *iface, ++ grub_uint32_t iaid) ++{ ++ grub_dhcp6_session_t se; ++ struct grub_datetime date; ++ grub_err_t err; ++ grub_int32_t t = 0; ++ ++ se = grub_malloc (sizeof (*se)); ++ ++ err = grub_get_datetime (&date); ++ if (err || !grub_datetime2unixtime (&date, &t)) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ t = 0; ++ } ++ ++ se->iface = iface; ++ se->iaid = iaid; ++ se->transaction_id = t; ++ se->start_time = grub_get_time_ms (); ++ se->duid.type = grub_cpu_to_be16_compile_time (3) ; ++ se->duid.hw_type = grub_cpu_to_be16_compile_time (1); ++ grub_memcpy (&se->duid.hwaddr, &iface->hwaddress.mac, sizeof (se->duid.hwaddr)); ++ se->adv = NULL; ++ se->reply = NULL; ++ grub_list_push (GRUB_AS_LIST_P (&grub_dhcp6_sessions), GRUB_AS_LIST (se)); ++} ++ ++static void ++grub_dhcp6_session_remove (grub_dhcp6_session_t se) ++{ ++ grub_list_remove (GRUB_AS_LIST (se)); ++ if (se->adv) ++ grub_dhcp6_options_free (se->adv); ++ if (se->reply) ++ grub_dhcp6_options_free (se->reply); ++ grub_free (se); ++} ++ ++static void ++grub_dhcp6_session_remove_all (void) ++{ ++ grub_dhcp6_session_t se, next; ++ ++ FOR_DHCP6_SESSIONS_SAFE (se, next) ++ { ++ grub_dhcp6_session_remove (se); ++ } ++ grub_dhcp6_sessions = NULL; ++} ++ ++static grub_err_t ++grub_dhcp6_session_configure_network (grub_dhcp6_session_t se) ++{ ++ char *name; ++ ++ name = grub_xasprintf ("%s:dhcp6", se->iface->card->name); ++ if (!name) ++ return grub_errno; ++ ++ grub_net_configure_by_dhcp6_info (name, se->iface->card, se->reply, 1, 0, 0); ++ grub_free (name); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_dhcp6_session_send_request (grub_dhcp6_session_t se) ++{ ++ struct grub_net_buff *nb; ++ struct grub_net_dhcp6_option *opt; ++ struct grub_net_dhcp6_packet *v6h; ++ struct grub_net_dhcp6_option_iana *ia_na; ++ struct grub_net_dhcp6_option_iaaddr *iaaddr; ++ struct udphdr *udph; ++ grub_net_network_level_address_t multicast; ++ grub_net_link_level_address_t ll_multicast; ++ grub_uint64_t elapsed; ++ struct grub_net_network_level_interface *inf = se->iface; ++ grub_dhcp6_options_t dhcp6 = se->adv; ++ grub_err_t err = GRUB_ERR_NONE; ++ ++ multicast.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ multicast.ipv6[0] = grub_cpu_to_be64_compile_time (0xff02ULL << 48); ++ multicast.ipv6[1] = grub_cpu_to_be64_compile_time (0x10002ULL); ++ ++ err = grub_net_link_layer_resolve (inf, &multicast, &ll_multicast); ++ if (err) ++ return err; ++ ++ nb = grub_netbuff_alloc (GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE); ++ ++ if (!nb) ++ return grub_errno; ++ ++ err = grub_netbuff_reserve (nb, GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ err = grub_netbuff_push (nb, dhcp6->client_duid_len + sizeof (*opt)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_CLIENTID); ++ opt->len = grub_cpu_to_be16 (dhcp6->client_duid_len); ++ grub_memcpy (opt->data, dhcp6->client_duid , dhcp6->client_duid_len); ++ ++ err = grub_netbuff_push (nb, dhcp6->server_duid_len + sizeof (*opt)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_SERVERID); ++ opt->len = grub_cpu_to_be16 (dhcp6->server_duid_len); ++ grub_memcpy (opt->data, dhcp6->server_duid , dhcp6->server_duid_len); ++ ++ err = grub_netbuff_push (nb, sizeof (*ia_na) + sizeof (*opt)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ if (dhcp6->ia_addr) ++ { ++ err = grub_netbuff_push (nb, sizeof(*iaaddr) + sizeof (*opt)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ } ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IA_NA); ++ opt->len = grub_cpu_to_be16 (sizeof (*ia_na)); ++ if (dhcp6->ia_addr) ++ opt->len += grub_cpu_to_be16 (sizeof(*iaaddr) + sizeof (*opt)); ++ ++ ia_na = (struct grub_net_dhcp6_option_iana *)opt->data; ++ ia_na->iaid = grub_cpu_to_be32 (dhcp6->iaid); ++ ++ ia_na->t1 = grub_cpu_to_be32 (dhcp6->t1); ++ ia_na->t2 = grub_cpu_to_be32 (dhcp6->t2); ++ ++ if (dhcp6->ia_addr) ++ { ++ opt = (struct grub_net_dhcp6_option *)ia_na->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IAADDR); ++ opt->len = grub_cpu_to_be16 (sizeof (*iaaddr)); ++ iaaddr = (struct grub_net_dhcp6_option_iaaddr *)opt->data; ++ grub_set_unaligned64 (iaaddr->addr, dhcp6->ia_addr->ipv6[0]); ++ grub_set_unaligned64 (iaaddr->addr + 8, dhcp6->ia_addr->ipv6[1]); ++ ++ iaaddr->preferred_lifetime = grub_cpu_to_be32 (dhcp6->preferred_lifetime); ++ iaaddr->valid_lifetime = grub_cpu_to_be32 (dhcp6->valid_lifetime); ++ } ++ ++ err = grub_netbuff_push (nb, sizeof (*opt) + 2 * sizeof (grub_uint16_t)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ opt = (struct grub_net_dhcp6_option*) nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_ORO); ++ opt->len = grub_cpu_to_be16_compile_time (2 * sizeof (grub_uint16_t)); ++ grub_set_unaligned16 (opt->data, grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_BOOTFILE_URL)); ++ grub_set_unaligned16 (opt->data + 2, grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_DNS_SERVERS)); ++ ++ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (grub_uint16_t)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ opt = (struct grub_net_dhcp6_option*) nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_ELAPSED_TIME); ++ opt->len = grub_cpu_to_be16_compile_time (sizeof (grub_uint16_t)); ++ ++ /* the time is expressed in hundredths of a second */ ++ elapsed = grub_divmod64 (grub_get_time_ms () - se->start_time, 10, 0); ++ ++ if (elapsed > 0xffff) ++ elapsed = 0xffff; ++ ++ grub_set_unaligned16 (opt->data, grub_cpu_to_be16 ((grub_uint16_t)elapsed)); ++ ++ err = grub_netbuff_push (nb, sizeof (*v6h)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ v6h = (struct grub_net_dhcp6_packet *) nb->data; ++ v6h->message_type = GRUB_NET_DHCP6_REQUEST; ++ v6h->transaction_id = se->transaction_id; ++ ++ err = grub_netbuff_push (nb, sizeof (*udph)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ udph = (struct udphdr *) nb->data; ++ udph->src = grub_cpu_to_be16_compile_time (DHCP6_CLIENT_PORT); ++ udph->dst = grub_cpu_to_be16_compile_time (DHCP6_SERVER_PORT); ++ udph->chksum = 0; ++ udph->len = grub_cpu_to_be16 (nb->tail - nb->data); ++ ++ udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP, ++ &inf->address, ++ &multicast); ++ err = grub_net_send_ip_packet (inf, &multicast, &ll_multicast, nb, ++ GRUB_NET_IP_UDP); ++ ++ grub_netbuff_free (nb); ++ ++ return err; ++} ++ ++struct grub_net_network_level_interface * ++grub_net_configure_by_dhcpv6_reply (const char *name, ++ struct grub_net_card *card, ++ grub_net_interface_flags_t flags, ++ const struct grub_net_dhcp6_packet *v6h, ++ grub_size_t size, ++ int is_def, ++ char **device, char **path) ++{ ++ struct grub_net_network_level_interface *inf; ++ grub_dhcp6_options_t dhcp6; ++ int mask = -1; ++ ++ dhcp6 = grub_dhcp6_options_get (v6h, size); ++ if (!dhcp6) ++ { ++ grub_print_error (); ++ return NULL; ++ } ++ ++ grub_net_configure_by_dhcp6_info (name, card, dhcp6, is_def, flags, &inf); ++ ++ if (device && dhcp6->boot_file_proto && dhcp6->boot_file_server_ip) ++ { ++ *device = grub_xasprintf ("%s,%s", dhcp6->boot_file_proto, dhcp6->boot_file_server_ip); ++ grub_print_error (); ++ } ++ if (path && dhcp6->boot_file_path) ++ { ++ *path = grub_strdup (dhcp6->boot_file_path); ++ grub_print_error (); ++ if (*path) ++ { ++ char *slash; ++ slash = grub_strrchr (*path, '/'); ++ if (slash) ++ *slash = 0; ++ else ++ **path = 0; ++ } ++ } ++ ++ grub_dhcp6_options_free (dhcp6); ++ ++ if (inf) ++ grub_net_add_ipv6_local (inf, mask); ++ ++ return inf; ++} ++ + /* + * This is called directly from net/ip.c:handle_dgram(), because those + * BOOTP/DHCP packets are a bit special due to their improper +@@ -706,6 +1376,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb, + } + } + ++grub_err_t ++grub_net_process_dhcp6 (struct grub_net_buff *nb, ++ struct grub_net_card *card __attribute__ ((unused))) ++{ ++ const struct grub_net_dhcp6_packet *v6h; ++ grub_dhcp6_session_t se; ++ grub_size_t size; ++ grub_dhcp6_options_t options; ++ ++ v6h = (const struct grub_net_dhcp6_packet *) nb->data; ++ size = nb->tail - nb->data; ++ ++ options = grub_dhcp6_options_get (v6h, size); ++ if (!options) ++ return grub_errno; ++ ++ if (!options->client_duid || !options->server_duid || !options->ia_addr) ++ { ++ grub_dhcp6_options_free (options); ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Bad DHCPv6 Packet"); ++ } ++ ++ FOR_DHCP6_SESSIONS (se) ++ { ++ if (se->transaction_id == v6h->transaction_id && ++ grub_memcmp (options->client_duid, &se->duid, sizeof (se->duid)) == 0 && ++ se->iaid == options->iaid) ++ break; ++ } ++ ++ if (!se) ++ { ++ grub_dprintf ("bootp", "DHCPv6 session not found\n"); ++ grub_dhcp6_options_free (options); ++ return GRUB_ERR_NONE; ++ } ++ ++ if (v6h->message_type == GRUB_NET_DHCP6_ADVERTISE) ++ { ++ if (se->adv) ++ { ++ grub_dprintf ("bootp", "Skipped DHCPv6 Advertised .. \n"); ++ grub_dhcp6_options_free (options); ++ return GRUB_ERR_NONE; ++ } ++ ++ se->adv = options; ++ return grub_dhcp6_session_send_request (se); ++ } ++ else if (v6h->message_type == GRUB_NET_DHCP6_REPLY) ++ { ++ if (!se->adv) ++ { ++ grub_dprintf ("bootp", "Skipped DHCPv6 Reply .. \n"); ++ grub_dhcp6_options_free (options); ++ return GRUB_ERR_NONE; ++ } ++ ++ se->reply = options; ++ grub_dhcp6_session_configure_network (se); ++ grub_dhcp6_session_remove (se); ++ return GRUB_ERR_NONE; ++ } ++ else ++ { ++ grub_dhcp6_options_free (options); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ + static grub_err_t + grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)), + int argc, char **args) +@@ -931,180 +1672,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + return err; + } + +-static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp; +- +-struct grub_net_network_level_interface * +-grub_net_configure_by_dhcpv6_ack (const char *name, +- struct grub_net_card *card, +- grub_net_interface_flags_t flags +- __attribute__((__unused__)), +- const grub_net_link_level_address_t *hwaddr, +- const struct grub_net_dhcpv6_packet *packet, +- int is_def, char **device, char **path) ++static grub_err_t ++grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)), ++ int argc, char **args) + { +- struct grub_net_network_level_interface *inter = NULL; +- struct grub_net_network_level_address addr; +- int mask = -1; ++ struct grub_net_card *card; ++ grub_uint32_t iaid = 0; ++ int interval; ++ grub_err_t err; ++ grub_dhcp6_session_t se; + +- if (!device || !path) +- return NULL; ++ err = GRUB_ERR_NONE; + +- *device = 0; +- *path = 0; ++ FOR_NET_CARDS (card) ++ { ++ struct grub_net_network_level_interface *iface; + +- grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n", +- hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2], +- hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]); ++ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) ++ continue; + +- if (is_def) +- grub_net_default_server = 0; ++ iface = grub_net_ipv6_get_link_local (card, &card->default_address); ++ if (!iface) ++ { ++ grub_dhcp6_session_remove_all (); ++ return grub_errno; ++ } + +- if (is_def && !grub_net_default_server && packet) ++ grub_dhcp6_session_add (iface, iaid++); ++ } ++ ++ for (interval = 200; interval < 10000; interval *= 2) + { +- const grub_uint8_t *options = packet->dhcp_options; +- unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet); +- unsigned int i; +- +- for (i = 0; i < option_max - sizeof (grub_net_dhcpv6_option_t); ) +- { +- grub_uint16_t num, len; +- grub_net_dhcpv6_option_t *opt = +- (grub_net_dhcpv6_option_t *)(options + i); +- +- num = grub_be_to_cpu16(opt->option_num); +- len = grub_be_to_cpu16(opt->option_len); +- +- grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len); +- +- if (len == 0) +- break; +- +- if (len + i > 1024) +- break; +- +- if (num == GRUB_NET_DHCP6_BOOTFILE_URL) +- { +- char *scheme, *userinfo, *host, *file; +- char *tmp; +- int hostlen; +- int port; +- int rc = extract_url_info ((const char *)opt->option_data, +- (grub_size_t)len, +- &scheme, &userinfo, &host, &port, +- &file); +- if (rc < 0) +- continue; +- +- /* right now this only handles tftp. */ +- if (grub_strcmp("tftp", scheme)) +- { +- grub_free (scheme); +- grub_free (userinfo); +- grub_free (host); +- grub_free (file); +- continue; +- } +- grub_free (userinfo); +- +- hostlen = grub_strlen (host); +- if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']') +- { +- tmp = host+1; +- host[hostlen-1] = '\0'; +- } +- else +- tmp = host; +- +- *device = grub_xasprintf ("%s,%s", scheme, tmp); +- grub_free (scheme); +- grub_free (host); +- +- if (file && *file) +- { +- tmp = grub_strrchr (file, '/'); +- if (tmp) +- *(tmp+1) = '\0'; +- else +- file[0] = '\0'; +- } +- else if (!file) +- file = grub_strdup (""); +- +- if (file[0] == '/') +- { +- *path = grub_strdup (file+1); +- grub_free (file); +- } +- else +- *path = file; +- } +- else if (num == GRUB_NET_DHCP6_IA_NA) +- { +- const grub_net_dhcpv6_option_t *ia_na_opt; +- const grub_net_dhcpv6_opt_ia_na_t *ia_na = +- (const grub_net_dhcpv6_opt_ia_na_t *)opt; +- unsigned int left = len - OFFSET_OF (options, ia_na); +- unsigned int j; +- +- if ((grub_uint8_t *)ia_na + left > +- (grub_uint8_t *)options + option_max) +- left -= ((grub_uint8_t *)ia_na + left) +- - ((grub_uint8_t *)options + option_max); +- +- if (len < OFFSET_OF (option_data, opt) +- + sizeof (grub_net_dhcpv6_option_t)) +- { +- grub_dprintf ("net", +- "found dhcpv6 ia_na option with no address\n"); +- continue; +- } +- +- for (j = 0; left > sizeof (grub_net_dhcpv6_option_t); ) +- { +- ia_na_opt = (const grub_net_dhcpv6_option_t *) +- (ia_na->options + j); +- grub_uint16_t ia_na_opt_num, ia_na_opt_len; +- +- ia_na_opt_num = grub_be_to_cpu16 (ia_na_opt->option_num); +- ia_na_opt_len = grub_be_to_cpu16 (ia_na_opt->option_len); +- if (ia_na_opt_len == 0) +- break; +- if (j + ia_na_opt_len > left) +- break; +- if (ia_na_opt_num == GRUB_NET_DHCP6_IA_ADDRESS) +- { +- const grub_net_dhcpv6_opt_ia_address_t *ia_addr; +- +- ia_addr = (const grub_net_dhcpv6_opt_ia_address_t *) +- ia_na_opt; +- addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; +- grub_memcpy(addr.ipv6, ia_addr->ipv6_address, +- sizeof (ia_addr->ipv6_address)); +- inter = grub_net_add_addr (name, card, &addr, hwaddr, 0); +- } +- +- j += ia_na_opt_len; +- left -= ia_na_opt_len; +- } +- } +- +- i += len + 4; +- } +- +- grub_print_error (); ++ int done = 1; ++ ++ FOR_DHCP6_SESSIONS (se) ++ { ++ struct grub_net_buff *nb; ++ struct grub_net_dhcp6_option *opt; ++ struct grub_net_dhcp6_packet *v6h; ++ struct grub_net_dhcp6_option_duid_ll *duid; ++ struct grub_net_dhcp6_option_iana *ia_na; ++ grub_net_network_level_address_t multicast; ++ grub_net_link_level_address_t ll_multicast; ++ struct udphdr *udph; ++ ++ multicast.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; ++ multicast.ipv6[0] = grub_cpu_to_be64_compile_time (0xff02ULL << 48); ++ multicast.ipv6[1] = grub_cpu_to_be64_compile_time (0x10002ULL); ++ ++ err = grub_net_link_layer_resolve (se->iface, ++ &multicast, &ll_multicast); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ return err; ++ } ++ ++ nb = grub_netbuff_alloc (GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE); ++ ++ if (!nb) ++ { ++ grub_dhcp6_session_remove_all (); ++ return grub_errno; ++ } ++ ++ err = grub_netbuff_reserve (nb, GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (grub_uint16_t)); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_ELAPSED_TIME); ++ opt->len = grub_cpu_to_be16_compile_time (sizeof (grub_uint16_t)); ++ grub_set_unaligned16 (opt->data, 0); ++ ++ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*duid)); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_CLIENTID); ++ opt->len = grub_cpu_to_be16 (sizeof (*duid)); ++ ++ duid = (struct grub_net_dhcp6_option_duid_ll *) opt->data; ++ grub_memcpy (duid, &se->duid, sizeof (*duid)); ++ ++ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*ia_na)); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ opt = (struct grub_net_dhcp6_option *)nb->data; ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IA_NA); ++ opt->len = grub_cpu_to_be16 (sizeof (*ia_na)); ++ ia_na = (struct grub_net_dhcp6_option_iana *)opt->data; ++ ia_na->iaid = grub_cpu_to_be32 (se->iaid); ++ ia_na->t1 = 0; ++ ia_na->t2 = 0; ++ ++ err = grub_netbuff_push (nb, sizeof (*v6h)); ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ v6h = (struct grub_net_dhcp6_packet *)nb->data; ++ v6h->message_type = GRUB_NET_DHCP6_SOLICIT; ++ v6h->transaction_id = se->transaction_id; ++ ++ grub_netbuff_push (nb, sizeof (*udph)); ++ ++ udph = (struct udphdr *) nb->data; ++ udph->src = grub_cpu_to_be16_compile_time (DHCP6_CLIENT_PORT); ++ udph->dst = grub_cpu_to_be16_compile_time (DHCP6_SERVER_PORT); ++ udph->chksum = 0; ++ udph->len = grub_cpu_to_be16 (nb->tail - nb->data); ++ ++ udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP, ++ &se->iface->address, &multicast); ++ ++ err = grub_net_send_ip_packet (se->iface, &multicast, ++ &ll_multicast, nb, GRUB_NET_IP_UDP); ++ done = 0; ++ grub_netbuff_free (nb); ++ ++ if (err) ++ { ++ grub_dhcp6_session_remove_all (); ++ return err; ++ } ++ } ++ if (!done) ++ grub_net_poll_cards (interval, 0); + } + +- if (is_def) ++ FOR_DHCP6_SESSIONS (se) + { +- grub_env_set ("net_default_interface", name); +- grub_env_export ("net_default_interface"); ++ grub_error_push (); ++ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, ++ N_("couldn't autoconfigure %s"), ++ se->iface->card->name); + } + +- if (inter) +- grub_net_add_ipv6_local (inter, mask); +- return inter; ++ grub_dhcp6_session_remove_all (); ++ ++ return err; + } + ++static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp, cmd_bootp6; + + void + grub_bootp_init (void) +@@ -1118,11 +1853,15 @@ grub_bootp_init (void) + cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, + N_("VAR INTERFACE NUMBER DESCRIPTION"), + N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); ++ cmd_bootp6 = grub_register_command ("net_bootp6", grub_cmd_bootp6, ++ N_("[CARD]"), ++ N_("perform a DHCPv6 autoconfiguration")); + } + + void + grub_bootp_fini (void) + { ++ grub_unregister_command (cmd_bootp6); + grub_unregister_command (cmd_getdhcp); + grub_unregister_command (cmd_bootp); + grub_unregister_command (cmd_dhcp); +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 4444e8e60ee..00d7d37b8de 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -394,9 +394,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + pxe_mode = pxe->mode; + if (pxe_mode->using_ipv6) + { +- grub_net_link_level_address_t hwaddr; +- struct grub_net_network_level_interface *intf; +- + grub_dprintf ("efinet", "using ipv6 and dhcpv6\n"); + grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", + pxe_mode->dhcp_ack_received ? "yes" : "no", +@@ -404,15 +401,14 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + if (!pxe_mode->dhcp_ack_received) + continue; + +- hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +- grub_memcpy (hwaddr.mac, +- card->efi_net->mode->current_address, +- sizeof (hwaddr.mac)); +- +- intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr, +- (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6, +- 1, device, path); +- if (intf && device && path) ++ grub_net_configure_by_dhcpv6_reply (card->name, card, 0, ++ (struct grub_net_dhcp6_packet *) ++ &pxe_mode->dhcp_ack, ++ sizeof (pxe_mode->dhcp_ack), ++ 1, device, path); ++ if (grub_errno) ++ grub_print_error (); ++ if (device && path) + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); + } + else +diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c +index a5896f6dc26..ce6bdc75c6d 100644 +--- a/grub-core/net/ip.c ++++ b/grub-core/net/ip.c +@@ -239,6 +239,45 @@ handle_dgram (struct grub_net_buff *nb, + { + struct udphdr *udph; + udph = (struct udphdr *) nb->data; ++ ++ if (proto == GRUB_NET_IP_UDP && udph->dst == grub_cpu_to_be16_compile_time (DHCP6_CLIENT_PORT)) ++ { ++ if (udph->chksum) ++ { ++ grub_uint16_t chk, expected; ++ chk = udph->chksum; ++ udph->chksum = 0; ++ expected = grub_net_ip_transport_checksum (nb, ++ GRUB_NET_IP_UDP, ++ source, ++ dest); ++ if (expected != chk) ++ { ++ grub_dprintf ("net", "Invalid UDP checksum. " ++ "Expected %x, got %x\n", ++ grub_be_to_cpu16 (expected), ++ grub_be_to_cpu16 (chk)); ++ grub_netbuff_free (nb); ++ return GRUB_ERR_NONE; ++ } ++ udph->chksum = chk; ++ } ++ ++ err = grub_netbuff_pull (nb, sizeof (*udph)); ++ if (err) ++ { ++ grub_netbuff_free (nb); ++ return err; ++ } ++ ++ err = grub_net_process_dhcp6 (nb, card); ++ if (err) ++ grub_print_error (); ++ ++ grub_netbuff_free (nb); ++ return GRUB_ERR_NONE; ++ } ++ + if (proto == GRUB_NET_IP_UDP && grub_be_to_cpu16 (udph->dst) == 68) + { + const struct grub_net_bootp_packet *bootp; +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 955973ed484..71d972a3d89 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -1507,7 +1507,7 @@ typedef struct grub_efi_pxe_ip_filter + { + grub_efi_uint8_t filters; + grub_efi_uint8_t ip_count; +- grub_efi_uint8_t reserved; ++ grub_efi_uint16_t reserved; + grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT]; + } grub_efi_pxe_ip_filter_t; + +diff --git a/include/grub/net.h b/include/grub/net.h +index fa7a8c39704..aedf4b59cfe 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -451,50 +451,65 @@ struct grub_net_bootp_packet + grub_uint8_t vendor[0]; + } GRUB_PACKED; + +-enum +- { +- GRUB_NET_DHCP6_IA_NA = 3, +- GRUB_NET_DHCP6_IA_ADDRESS = 5, +- GRUB_NET_DHCP6_BOOTFILE_URL = 59, +- }; +- +-struct grub_net_dhcpv6_option ++struct grub_net_dhcp6_packet + { +- grub_uint16_t option_num; +- grub_uint16_t option_len; +- grub_uint8_t option_data[]; ++ grub_uint32_t message_type:8; ++ grub_uint32_t transaction_id:24; ++ grub_uint8_t dhcp_options[0]; + } GRUB_PACKED; +-typedef struct grub_net_dhcpv6_option grub_net_dhcpv6_option_t; + +-struct grub_net_dhcpv6_opt_ia_na +-{ +- grub_uint16_t option_num; +- grub_uint16_t option_len; ++struct grub_net_dhcp6_option { ++ grub_uint16_t code; ++ grub_uint16_t len; ++ grub_uint8_t data[0]; ++} GRUB_PACKED; ++ ++struct grub_net_dhcp6_option_iana { + grub_uint32_t iaid; + grub_uint32_t t1; + grub_uint32_t t2; +- grub_uint8_t options[]; ++ grub_uint8_t data[0]; + } GRUB_PACKED; +-typedef struct grub_net_dhcpv6_opt_ia_na grub_net_dhcpv6_opt_ia_na_t; + +-struct grub_net_dhcpv6_opt_ia_address +-{ +- grub_uint16_t option_num; +- grub_uint16_t option_len; +- grub_uint64_t ipv6_address[2]; ++struct grub_net_dhcp6_option_iaaddr { ++ grub_uint8_t addr[16]; + grub_uint32_t preferred_lifetime; + grub_uint32_t valid_lifetime; +- grub_uint8_t options[]; ++ grub_uint8_t data[0]; + } GRUB_PACKED; +-typedef struct grub_net_dhcpv6_opt_ia_address grub_net_dhcpv6_opt_ia_address_t; + +-struct grub_net_dhcpv6_packet ++struct grub_net_dhcp6_option_duid_ll + { +- grub_uint32_t message_type:8; +- grub_uint32_t transaction_id:24; +- grub_uint8_t dhcp_options[1024]; ++ grub_uint16_t type; ++ grub_uint16_t hw_type; ++ grub_uint8_t hwaddr[6]; + } GRUB_PACKED; +-typedef struct grub_net_dhcpv6_packet grub_net_dhcpv6_packet_t; ++ ++enum ++ { ++ GRUB_NET_DHCP6_SOLICIT = 1, ++ GRUB_NET_DHCP6_ADVERTISE = 2, ++ GRUB_NET_DHCP6_REQUEST = 3, ++ GRUB_NET_DHCP6_REPLY = 7 ++ }; ++ ++enum ++ { ++ DHCP6_CLIENT_PORT = 546, ++ DHCP6_SERVER_PORT = 547 ++ }; ++ ++enum ++ { ++ GRUB_NET_DHCP6_OPTION_CLIENTID = 1, ++ GRUB_NET_DHCP6_OPTION_SERVERID = 2, ++ GRUB_NET_DHCP6_OPTION_IA_NA = 3, ++ GRUB_NET_DHCP6_OPTION_IAADDR = 5, ++ GRUB_NET_DHCP6_OPTION_ORO = 6, ++ GRUB_NET_DHCP6_OPTION_ELAPSED_TIME = 8, ++ GRUB_NET_DHCP6_OPTION_DNS_SERVERS = 23, ++ GRUB_NET_DHCP6_OPTION_BOOTFILE_URL = 59 ++ }; + + #define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63 + #define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82 +@@ -532,12 +547,12 @@ grub_net_configure_by_dhcp_ack (const char *name, + int is_def, char **device, char **path); + + struct grub_net_network_level_interface * +-grub_net_configure_by_dhcpv6_ack (const char *name, +- struct grub_net_card *card, +- grub_net_interface_flags_t flags, +- const grub_net_link_level_address_t *hwaddr, +- const struct grub_net_dhcpv6_packet *packet, +- int is_def, char **device, char **path); ++grub_net_configure_by_dhcpv6_reply (const char *name, ++ struct grub_net_card *card, ++ grub_net_interface_flags_t flags, ++ const struct grub_net_dhcp6_packet *v6, ++ grub_size_t size, ++ int is_def, char **device, char **path); + + int + grub_ipv6_get_masksize(grub_uint16_t *mask); +@@ -554,6 +569,10 @@ void + grub_net_process_dhcp (struct grub_net_buff *nb, + struct grub_net_network_level_interface *iface); + ++grub_err_t ++grub_net_process_dhcp6 (struct grub_net_buff *nb, ++ struct grub_net_card *card); ++ + int + grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a, + const grub_net_link_level_address_t *b); diff --git a/0113-efinet-UEFI-IPv6-PXE-support.patch b/0113-efinet-UEFI-IPv6-PXE-support.patch new file mode 100644 index 0000000..50d680a --- /dev/null +++ b/0113-efinet-UEFI-IPv6-PXE-support.patch @@ -0,0 +1,126 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 15 Apr 2015 14:48:30 +0800 +Subject: [PATCH] efinet: UEFI IPv6 PXE support + +When grub2 image is booted from UEFI IPv6 PXE, the DHCPv6 Reply packet is +cached in firmware buffer which can be obtained by PXE Base Code protocol. The +network interface can be setup through the parameters in that obtained packet. + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +--- + grub-core/net/drivers/efi/efinet.c | 2 ++ + include/grub/efi/api.h | 71 +++++++++++++++++++++++--------------- + 2 files changed, 46 insertions(+), 27 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 00d7d37b8de..c3db3285b97 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -410,6 +410,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + grub_print_error (); + if (device && path) + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); ++ if (grub_errno) ++ grub_print_error (); + } + else + { +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 71d972a3d89..186cf398840 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -1499,31 +1499,6 @@ typedef union + grub_efi_pxe_dhcpv6_packet_t dhcpv6; + } grub_efi_pxe_packet_t; + +-#define GRUB_EFI_PXE_MAX_IPCNT 8 +-#define GRUB_EFI_PXE_MAX_ARP_ENTRIES 8 +-#define GRUB_EFI_PXE_MAX_ROUTE_ENTRIES 8 +- +-typedef struct grub_efi_pxe_ip_filter +-{ +- grub_efi_uint8_t filters; +- grub_efi_uint8_t ip_count; +- grub_efi_uint16_t reserved; +- grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT]; +-} grub_efi_pxe_ip_filter_t; +- +-typedef struct grub_efi_pxe_arp_entry +-{ +- grub_efi_ip_address_t ip_addr; +- grub_efi_mac_address_t mac_addr; +-} grub_efi_pxe_arp_entry_t; +- +-typedef struct grub_efi_pxe_route_entry +-{ +- grub_efi_ip_address_t ip_addr; +- grub_efi_ip_address_t subnet_mask; +- grub_efi_ip_address_t gateway_addr; +-} grub_efi_pxe_route_entry_t; +- + typedef struct grub_efi_pxe_icmp_error + { + grub_efi_uint8_t type; +@@ -1549,6 +1524,48 @@ typedef struct grub_efi_pxe_tftp_error + grub_efi_char8_t error_string[127]; + } grub_efi_pxe_tftp_error_t; + ++typedef struct { ++ grub_uint8_t addr[4]; ++} grub_efi_pxe_ipv4_address_t; ++ ++typedef struct { ++ grub_uint8_t addr[16]; ++} grub_efi_pxe_ipv6_address_t; ++ ++typedef struct { ++ grub_uint8_t addr[32]; ++} grub_efi_pxe_mac_address_t; ++ ++typedef union { ++ grub_uint32_t addr[4]; ++ grub_efi_pxe_ipv4_address_t v4; ++ grub_efi_pxe_ipv6_address_t v6; ++} grub_efi_pxe_ip_address_t; ++ ++#define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 ++typedef struct grub_efi_pxe_ip_filter ++{ ++ grub_efi_uint8_t filters; ++ grub_efi_uint8_t ip_count; ++ grub_efi_uint16_t reserved; ++ grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT]; ++} grub_efi_pxe_ip_filter_t; ++ ++typedef struct { ++ grub_efi_pxe_ip_address_t ip_addr; ++ grub_efi_pxe_mac_address_t mac_addr; ++} grub_efi_pxe_arp_entry_t; ++ ++typedef struct { ++ grub_efi_pxe_ip_address_t ip_addr; ++ grub_efi_pxe_ip_address_t subnet_mask; ++ grub_efi_pxe_ip_address_t gw_addr; ++} grub_efi_pxe_route_entry_t; ++ ++ ++#define GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES 8 ++#define GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES 8 ++ + typedef struct grub_efi_pxe_mode + { + grub_efi_boolean_t started; +@@ -1580,9 +1597,9 @@ typedef struct grub_efi_pxe_mode + grub_efi_pxe_packet_t pxe_bis_reply; + grub_efi_pxe_ip_filter_t ip_filter; + grub_efi_uint32_t arp_cache_entries; +- grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_MAX_ARP_ENTRIES]; ++ grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES]; + grub_efi_uint32_t route_table_entries; +- grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_MAX_ROUTE_ENTRIES]; ++ grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES]; + grub_efi_pxe_icmp_error_t icmp_error; + grub_efi_pxe_tftp_error_t tftp_error; + } grub_efi_pxe_mode_t; diff --git a/0114-grub.texi-Add-net_bootp6-doument.patch b/0114-grub.texi-Add-net_bootp6-doument.patch new file mode 100644 index 0000000..fdca976 --- /dev/null +++ b/0114-grub.texi-Add-net_bootp6-doument.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Tue, 5 May 2015 14:19:24 +0800 +Subject: [PATCH] grub.texi: Add net_bootp6 doument + +Update grub documentation for net_bootp6 command. + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +--- + docs/grub.texi | 17 +++++++++++++++++ + 1 file changed, 17 insertions(+) + +diff --git a/docs/grub.texi b/docs/grub.texi +index 960e5f3ba41..495462b8e48 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -5338,6 +5338,7 @@ This command is only available on AArch64 systems. + * net_add_dns:: Add a DNS server + * net_add_route:: Add routing entry + * net_bootp:: Perform a bootp autoconfiguration ++* net_bootp6:: Perform a DHCPv6 autoconfiguration + * net_del_addr:: Remove IP address from interface + * net_del_dns:: Remove a DNS server + * net_del_route:: Remove a route entry +@@ -5419,6 +5420,22 @@ Sets environment variable @samp{net_}@var{}@samp{_dhcp_extensionspath} + + @end deffn + ++@node net_bootp6 ++@subsection net_bootp6 ++ ++@deffn Command net_bootp6 [@var{card}] ++Perform configuration of @var{card} using DHCPv6 protocol. If no card name is ++specified, try to configure all existing cards. If configuration was ++successful, interface with name @var{card}@samp{:dhcp6} and configured address ++is added to @var{card}. ++ ++@table @samp ++@item 1 (Domain Name Server) ++Adds all servers from option value to the list of servers used during name ++resolution. ++@end table ++ ++@end deffn + + @node net_del_addr + @subsection net_del_addr diff --git a/0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch b/0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch new file mode 100644 index 0000000..301e781 --- /dev/null +++ b/0115-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch @@ -0,0 +1,108 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 10 Jul 2019 23:58:28 +0200 +Subject: [PATCH] bootp: Add processing DHCPACK packet from HTTP Boot + +The vendor class identifier with the string "HTTPClient" is used to denote the +packet as responding to HTTP boot request. In DHCP4 config, the filename for +HTTP boot is the URL of the boot file while for PXE boot it is the path to the +boot file. As a consequence, the next-server becomes obseleted because the HTTP +URL already contains the server address for the boot file. For DHCP6 config, +there's no difference definition in existing config as dhcp6.bootfile-url can +be used to specify URL for both HTTP and PXE boot file. + +This patch adds processing for "HTTPClient" vendor class identifier in DHCPACK +packet by treating it as HTTP format, not as the PXE format. + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +--- + grub-core/net/bootp.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ + include/grub/net.h | 1 + + 2 files changed, 56 insertions(+) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 85adc9cb447..2e46842e829 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -567,6 +568,60 @@ grub_net_configure_by_dhcp_ack (const char *name, + if (opt && opt_len) + grub_env_set_net_property (name, "rootpath", (const char *) opt, opt_len); + ++ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER, &opt_len); ++ if (opt && opt_len) ++ { ++ grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len); ++ if (opt && grub_strcmp (opt, "HTTPClient") == 0) ++ { ++ char *proto, *ip, *pa; ++ ++ if (!dissect_url (bp->boot_file, &proto, &ip, &pa)) ++ return inter; ++ ++ grub_env_set_net_property (name, "boot_file", pa, grub_strlen (pa)); ++ if (is_def) ++ { ++ grub_net_default_server = grub_strdup (ip); ++ grub_env_set ("net_default_interface", name); ++ grub_env_export ("net_default_interface"); ++ } ++ if (device && !*device) ++ { ++ *device = grub_xasprintf ("%s,%s", proto, ip); ++ grub_print_error (); ++ } ++ if (path) ++ { ++ *path = grub_strdup (pa); ++ grub_print_error (); ++ if (*path) ++ { ++ char *slash; ++ slash = grub_strrchr (*path, '/'); ++ if (slash) ++ *slash = 0; ++ else ++ **path = 0; ++ } ++ } ++ grub_net_add_ipv4_local (inter, mask); ++ inter->dhcp_ack = grub_malloc (size); ++ if (inter->dhcp_ack) ++ { ++ grub_memcpy (inter->dhcp_ack, bp, size); ++ inter->dhcp_acklen = size; ++ } ++ else ++ grub_errno = GRUB_ERR_NONE; ++ ++ grub_free (proto); ++ grub_free (ip); ++ grub_free (pa); ++ return inter; ++ } ++ } ++ + opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_EXTENSIONS_PATH, &opt_len); + if (opt && opt_len) + grub_env_set_net_property (name, "extensionspath", (const char *) opt, opt_len); +diff --git a/include/grub/net.h b/include/grub/net.h +index aedf4b59cfe..ebb569bd86e 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -526,6 +526,7 @@ enum + GRUB_NET_BOOTP_DOMAIN = 0x0f, + GRUB_NET_BOOTP_ROOT_PATH = 0x11, + GRUB_NET_BOOTP_EXTENSIONS_PATH = 0x12, ++ GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 0x3C, + GRUB_NET_BOOTP_CLIENT_ID = 0x3d, + GRUB_NET_BOOTP_CLIENT_UUID = 0x61, + GRUB_NET_DHCP_REQUESTED_IP_ADDRESS = 50, diff --git a/0116-efinet-Setting-network-from-UEFI-device-path.patch b/0116-efinet-Setting-network-from-UEFI-device-path.patch new file mode 100644 index 0000000..f017295 --- /dev/null +++ b/0116-efinet-Setting-network-from-UEFI-device-path.patch @@ -0,0 +1,405 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Sun, 10 Jul 2016 23:46:31 +0800 +Subject: [PATCH] efinet: Setting network from UEFI device path + +The PXE Base Code protocol used to obtain cached PXE DHCPACK packet is no +longer provided for HTTP Boot. Instead, we have to get the HTTP boot +information from the device path nodes defined in following UEFI Specification +sections. + + 9.3.5.12 IPv4 Device Path + 9.3.5.13 IPv6 Device Path + 9.3.5.23 Uniform Resource Identifiers (URI) Device Path + +This patch basically does: + +include/grub/efi/api.h: +Add new structure of Uniform Resource Identifiers (URI) Device Path + +grub-core/net/drivers/efi/efinet.c: +Check if PXE Base Code is available, if not it will try to obtain the netboot +information from the device path where the image booted from. The DHCPACK +packet is recoverd from the information in device patch and feed into the same +DHCP packet processing functions to ensure the network interface is setting up +the same way it used to be. + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +--- + grub-core/net/drivers/efi/efinet.c | 284 +++++++++++++++++++++++++++++++++++-- + include/grub/efi/api.h | 11 ++ + 2 files changed, 280 insertions(+), 15 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index c3db3285b97..2817b6f8fb9 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -332,6 +333,227 @@ grub_efinet_findcards (void) + grub_free (handles); + } + ++static struct grub_net_buff * ++grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *use_ipv6) ++{ ++ grub_efi_uint16_t uri_len; ++ grub_efi_device_path_t *ldp, *ddp; ++ grub_efi_uri_device_path_t *uri_dp; ++ struct grub_net_buff *nb; ++ grub_err_t err; ++ ++ ddp = grub_efi_duplicate_device_path (dp); ++ if (!ddp) ++ return NULL; ++ ++ ldp = grub_efi_find_last_device_path (ddp); ++ ++ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE ++ || GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_URI_DEVICE_PATH_SUBTYPE) ++ { ++ grub_free (ddp); ++ return NULL; ++ } ++ ++ uri_len = GRUB_EFI_DEVICE_PATH_LENGTH (ldp) > 4 ? GRUB_EFI_DEVICE_PATH_LENGTH (ldp) - 4 : 0; ++ ++ if (!uri_len) ++ { ++ grub_free (ddp); ++ return NULL; ++ } ++ ++ uri_dp = (grub_efi_uri_device_path_t *) ldp; ++ ++ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ ldp->length = sizeof (*ldp); ++ ++ ldp = grub_efi_find_last_device_path (ddp); ++ ++ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE ++ || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE ++ && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) ++ { ++ grub_free (ddp); ++ return NULL; ++ } ++ ++ nb = grub_netbuff_alloc (512); ++ if (!nb) ++ { ++ grub_free (ddp); ++ return NULL; ++ } ++ ++ if (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE) ++ { ++ grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) ldp; ++ struct grub_net_bootp_packet *bp; ++ grub_uint8_t *ptr; ++ ++ bp = (struct grub_net_bootp_packet *) nb->tail; ++ err = grub_netbuff_put (nb, sizeof (*bp) + 4); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ ++ if (sizeof(bp->boot_file) < uri_len) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ grub_memcpy (bp->boot_file, uri_dp->uri, uri_len); ++ grub_memcpy (&bp->your_ip, ipv4->local_ip_address, sizeof (bp->your_ip)); ++ grub_memcpy (&bp->server_ip, ipv4->remote_ip_address, sizeof (bp->server_ip)); ++ ++ bp->vendor[0] = GRUB_NET_BOOTP_RFC1048_MAGIC_0; ++ bp->vendor[1] = GRUB_NET_BOOTP_RFC1048_MAGIC_1; ++ bp->vendor[2] = GRUB_NET_BOOTP_RFC1048_MAGIC_2; ++ bp->vendor[3] = GRUB_NET_BOOTP_RFC1048_MAGIC_3; ++ ++ ptr = nb->tail; ++ err = grub_netbuff_put (nb, sizeof (ipv4->subnet_mask) + 2); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ *ptr++ = GRUB_NET_BOOTP_NETMASK; ++ *ptr++ = sizeof (ipv4->subnet_mask); ++ grub_memcpy (ptr, ipv4->subnet_mask, sizeof (ipv4->subnet_mask)); ++ ++ ptr = nb->tail; ++ err = grub_netbuff_put (nb, sizeof (ipv4->gateway_ip_address) + 2); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ *ptr++ = GRUB_NET_BOOTP_ROUTER; ++ *ptr++ = sizeof (ipv4->gateway_ip_address); ++ grub_memcpy (ptr, ipv4->gateway_ip_address, sizeof (ipv4->gateway_ip_address)); ++ ++ ptr = nb->tail; ++ err = grub_netbuff_put (nb, sizeof ("HTTPClient") + 1); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ *ptr++ = GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER; ++ *ptr++ = sizeof ("HTTPClient") - 1; ++ grub_memcpy (ptr, "HTTPClient", sizeof ("HTTPClient") - 1); ++ ++ ptr = nb->tail; ++ err = grub_netbuff_put (nb, 1); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ *ptr = GRUB_NET_BOOTP_END; ++ *use_ipv6 = 0; ++ ++ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ ldp->length = sizeof (*ldp); ++ ldp = grub_efi_find_last_device_path (ddp); ++ ++ if (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE) ++ { ++ grub_efi_mac_address_device_path_t *mac = (grub_efi_mac_address_device_path_t *) ldp; ++ bp->hw_type = mac->if_type; ++ bp->hw_len = sizeof (bp->mac_addr); ++ grub_memcpy (bp->mac_addr, mac->mac_address, bp->hw_len); ++ } ++ } ++ else ++ { ++ grub_efi_ipv6_device_path_t *ipv6 = (grub_efi_ipv6_device_path_t *) ldp; ++ ++ struct grub_net_dhcp6_packet *d6p; ++ struct grub_net_dhcp6_option *opt; ++ struct grub_net_dhcp6_option_iana *iana; ++ struct grub_net_dhcp6_option_iaaddr *iaaddr; ++ ++ d6p = (struct grub_net_dhcp6_packet *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*d6p)); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ d6p->message_type = GRUB_NET_DHCP6_REPLY; ++ ++ opt = (struct grub_net_dhcp6_option *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*opt)); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IA_NA); ++ opt->len = grub_cpu_to_be16_compile_time (sizeof(*iana) + sizeof(*opt) + sizeof(*iaaddr)); ++ ++ err = grub_netbuff_put (nb, sizeof(*iana)); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ ++ opt = (struct grub_net_dhcp6_option *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*opt)); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IAADDR); ++ opt->len = grub_cpu_to_be16_compile_time (sizeof (*iaaddr)); ++ ++ iaaddr = (struct grub_net_dhcp6_option_iaaddr *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*iaaddr)); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ grub_memcpy (iaaddr->addr, ipv6->local_ip_address, sizeof(ipv6->local_ip_address)); ++ ++ opt = (struct grub_net_dhcp6_option *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*opt) + uri_len); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_BOOTFILE_URL); ++ opt->len = grub_cpu_to_be16 (uri_len); ++ grub_memcpy (opt->data, uri_dp->uri, uri_len); ++ ++ *use_ipv6 = 1; ++ } ++ ++ grub_free (ddp); ++ return nb; ++} ++ + static void + grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + char **path) +@@ -347,7 +569,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + { + grub_efi_device_path_t *cdp; + struct grub_efi_pxe *pxe; +- struct grub_efi_pxe_mode *pxe_mode; ++ struct grub_efi_pxe_mode *pxe_mode = NULL; ++ grub_uint8_t *packet_buf; ++ grub_size_t packet_bufsz ; ++ int ipv6; ++ struct grub_net_buff *nb = NULL; + + if (card->driver != &efidriver) + continue; +@@ -371,11 +597,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + */ + if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE + || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE +- && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) ++ && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE ++ && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) + continue; + dup_dp = grub_efi_duplicate_device_path (dp); + if (!dup_dp) + continue; ++ ++ if (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_URI_DEVICE_PATH_SUBTYPE) ++ { ++ dup_ldp = grub_efi_find_last_device_path (dup_dp); ++ dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ dup_ldp->length = sizeof (*dup_ldp); ++ } ++ + dup_ldp = grub_efi_find_last_device_path (dup_dp); + dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; + dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; +@@ -388,23 +624,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + + pxe = grub_efi_open_protocol (hnd, &pxe_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); +- if (! pxe) +- continue; ++ if (!pxe) ++ { ++ nb = grub_efinet_create_dhcp_ack_from_device_path (dp, &ipv6); ++ if (!nb) ++ { ++ grub_print_error (); ++ continue; ++ } ++ packet_buf = nb->head; ++ packet_bufsz = nb->tail - nb->head; ++ } ++ else ++ { ++ pxe_mode = pxe->mode; ++ packet_buf = (grub_uint8_t *) &pxe_mode->dhcp_ack; ++ packet_bufsz = sizeof (pxe_mode->dhcp_ack); ++ ipv6 = pxe_mode->using_ipv6; ++ } + +- pxe_mode = pxe->mode; +- if (pxe_mode->using_ipv6) ++ if (ipv6) + { + grub_dprintf ("efinet", "using ipv6 and dhcpv6\n"); +- grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", +- pxe_mode->dhcp_ack_received ? "yes" : "no", +- pxe_mode->dhcp_ack_received ? "" : " cannot continue"); +- if (!pxe_mode->dhcp_ack_received) +- continue; ++ if (pxe_mode) ++ grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n", ++ pxe_mode->dhcp_ack_received ? "yes" : "no", ++ pxe_mode->dhcp_ack_received ? "" : " cannot continue"); + + grub_net_configure_by_dhcpv6_reply (card->name, card, 0, + (struct grub_net_dhcp6_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), ++ packet_buf, ++ packet_bufsz, + 1, device, path); + if (grub_errno) + grub_print_error (); +@@ -418,11 +668,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + grub_dprintf ("efinet", "using ipv4 and dhcp\n"); + grub_net_configure_by_dhcp_ack (card->name, card, 0, + (struct grub_net_bootp_packet *) +- &pxe_mode->dhcp_ack, +- sizeof (pxe_mode->dhcp_ack), ++ packet_buf, ++ packet_bufsz, + 1, device, path); + grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path); + } ++ ++ if (nb) ++ grub_netbuff_free (nb); ++ + return; + } + } +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 186cf398840..0d4839a41f1 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -839,6 +839,8 @@ struct grub_efi_ipv4_device_path + grub_efi_uint16_t remote_port; + grub_efi_uint16_t protocol; + grub_efi_uint8_t static_ip_address; ++ grub_efi_ipv4_address_t gateway_ip_address; ++ grub_efi_ipv4_address_t subnet_mask; + } GRUB_PACKED; + typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t; + +@@ -893,6 +895,15 @@ struct grub_efi_sata_device_path + } GRUB_PACKED; + typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t; + ++#define GRUB_EFI_URI_DEVICE_PATH_SUBTYPE 24 ++ ++struct grub_efi_uri_device_path ++{ ++ grub_efi_device_path_t header; ++ grub_efi_uint8_t uri[0]; ++} GRUB_PACKED; ++typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t; ++ + #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 + + /* Media Device Path. */ diff --git a/0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch b/0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch new file mode 100644 index 0000000..d79b34a --- /dev/null +++ b/0117-efinet-Setting-DNS-server-from-UEFI-protocol.patch @@ -0,0 +1,337 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 14 Jul 2016 17:48:45 +0800 +Subject: [PATCH] efinet: Setting DNS server from UEFI protocol + +In the URI device path node, any name rahter than address can be used for +looking up the resources so that DNS service become needed to get answer of the +name's address. Unfortunately the DNS is not defined in any of the device path +nodes so that we use the EFI_IP4_CONFIG2_PROTOCOL and EFI_IP6_CONFIG_PROTOCOL +to obtain it. + +These two protcols are defined the sections of UEFI specification. + + 27.5 EFI IPv4 Configuration II Protocol + 27.7 EFI IPv6 Configuration Protocol + +include/grub/efi/api.h: +Add new structure and protocol UUID of EFI_IP4_CONFIG2_PROTOCOL and +EFI_IP6_CONFIG_PROTOCOL. + +grub-core/net/drivers/efi/efinet.c: +Use the EFI_IP4_CONFIG2_PROTOCOL and EFI_IP6_CONFIG_PROTOCOL to obtain the list +of DNS server address for IPv4 and IPv6 respectively. The address of DNS +servers is structured into DHCPACK packet and feed into the same DHCP packet +processing functions to ensure the network interface is setting up the same way +it used to be. + +Signed-off-by: Michael Chang +Signed-off-by: Ken Lin +--- + grub-core/net/drivers/efi/efinet.c | 163 +++++++++++++++++++++++++++++++++++++ + include/grub/efi/api.h | 76 +++++++++++++++++ + 2 files changed, 239 insertions(+) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 2817b6f8fb9..c843654b830 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -34,6 +34,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); + /* GUID. */ + static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID; + static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; ++static grub_efi_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; ++static grub_efi_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; + + static grub_err_t + send_card_buffer (struct grub_net_card *dev, +@@ -333,6 +335,125 @@ grub_efinet_findcards (void) + grub_free (handles); + } + ++static grub_efi_handle_t ++grub_efi_locate_device_path (grub_efi_guid_t *protocol, grub_efi_device_path_t *device_path, ++ grub_efi_device_path_t **r_device_path) ++{ ++ grub_efi_handle_t handle; ++ grub_efi_status_t status; ++ ++ status = efi_call_3 (grub_efi_system_table->boot_services->locate_device_path, ++ protocol, &device_path, &handle); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ ++ if (r_device_path) ++ *r_device_path = device_path; ++ ++ return handle; ++} ++ ++static grub_efi_ipv4_address_t * ++grub_dns_server_ip4_address (grub_efi_device_path_t *dp, grub_efi_uintn_t *num_dns) ++{ ++ grub_efi_handle_t hnd; ++ grub_efi_status_t status; ++ grub_efi_ip4_config2_protocol_t *conf; ++ grub_efi_ipv4_address_t *addrs; ++ grub_efi_uintn_t data_size = 1 * sizeof (grub_efi_ipv4_address_t); ++ ++ hnd = grub_efi_locate_device_path (&ip4_config_guid, dp, NULL); ++ ++ if (!hnd) ++ return 0; ++ ++ conf = grub_efi_open_protocol (hnd, &ip4_config_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!conf) ++ return 0; ++ ++ addrs = grub_malloc (data_size); ++ if (!addrs) ++ return 0; ++ ++ status = efi_call_4 (conf->get_data, conf, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL) ++ { ++ grub_free (addrs); ++ addrs = grub_malloc (data_size); ++ if (!addrs) ++ return 0; ++ ++ status = efi_call_4 (conf->get_data, conf, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (addrs); ++ return 0; ++ } ++ ++ *num_dns = data_size / sizeof (grub_efi_ipv4_address_t); ++ return addrs; ++} ++ ++static grub_efi_ipv6_address_t * ++grub_dns_server_ip6_address (grub_efi_device_path_t *dp, grub_efi_uintn_t *num_dns) ++{ ++ grub_efi_handle_t hnd; ++ grub_efi_status_t status; ++ grub_efi_ip6_config_protocol_t *conf; ++ grub_efi_ipv6_address_t *addrs; ++ grub_efi_uintn_t data_size = 1 * sizeof (grub_efi_ipv6_address_t); ++ ++ hnd = grub_efi_locate_device_path (&ip6_config_guid, dp, NULL); ++ ++ if (!hnd) ++ return 0; ++ ++ conf = grub_efi_open_protocol (hnd, &ip6_config_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!conf) ++ return 0; ++ ++ addrs = grub_malloc (data_size); ++ if (!addrs) ++ return 0; ++ ++ status = efi_call_4 (conf->get_data, conf, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL) ++ { ++ grub_free (addrs); ++ addrs = grub_malloc (data_size); ++ if (!addrs) ++ return 0; ++ ++ status = efi_call_4 (conf->get_data, conf, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ &data_size, addrs); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (addrs); ++ return 0; ++ } ++ ++ *num_dns = data_size / sizeof (grub_efi_ipv6_address_t); ++ return addrs; ++} ++ + static struct grub_net_buff * + grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *use_ipv6) + { +@@ -391,6 +512,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u + grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) ldp; + struct grub_net_bootp_packet *bp; + grub_uint8_t *ptr; ++ grub_efi_ipv4_address_t *dns; ++ grub_efi_uintn_t num_dns; + + bp = (struct grub_net_bootp_packet *) nb->tail; + err = grub_netbuff_put (nb, sizeof (*bp) + 4); +@@ -452,6 +575,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u + *ptr++ = sizeof ("HTTPClient") - 1; + grub_memcpy (ptr, "HTTPClient", sizeof ("HTTPClient") - 1); + ++ dns = grub_dns_server_ip4_address (dp, &num_dns); ++ if (dns) ++ { ++ grub_efi_uintn_t size_dns = sizeof (*dns) * num_dns; ++ ++ ptr = nb->tail; ++ err = grub_netbuff_put (nb, size_dns + 2); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ *ptr++ = GRUB_NET_BOOTP_DNS; ++ *ptr++ = size_dns; ++ grub_memcpy (ptr, dns, size_dns); ++ grub_free (dns); ++ } ++ + ptr = nb->tail; + err = grub_netbuff_put (nb, 1); + if (err) +@@ -484,6 +626,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u + struct grub_net_dhcp6_option *opt; + struct grub_net_dhcp6_option_iana *iana; + struct grub_net_dhcp6_option_iaaddr *iaaddr; ++ grub_efi_ipv6_address_t *dns; ++ grub_efi_uintn_t num_dns; + + d6p = (struct grub_net_dhcp6_packet *)nb->tail; + err = grub_netbuff_put (nb, sizeof(*d6p)); +@@ -547,6 +691,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u + opt->len = grub_cpu_to_be16 (uri_len); + grub_memcpy (opt->data, uri_dp->uri, uri_len); + ++ dns = grub_dns_server_ip6_address (dp, &num_dns); ++ if (dns) ++ { ++ grub_efi_uintn_t size_dns = sizeof (*dns) * num_dns; ++ ++ opt = (struct grub_net_dhcp6_option *)nb->tail; ++ err = grub_netbuff_put (nb, sizeof(*opt) + size_dns); ++ if (err) ++ { ++ grub_free (ddp); ++ grub_netbuff_free (nb); ++ return NULL; ++ } ++ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_DNS_SERVERS); ++ opt->len = grub_cpu_to_be16 (size_dns); ++ grub_memcpy (opt->data, dns, size_dns); ++ grub_free (dns); ++ } ++ + *use_ipv6 = 1; + } + +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 0d4839a41f1..716f121728b 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -334,6 +334,16 @@ + { 0x8B, 0x8C, 0xE2, 0x1B, 0x01, 0xAE, 0xF2, 0xB7 } \ + } + ++#define GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID \ ++ { 0x5b446ed1, 0xe30b, 0x4faa, \ ++ { 0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80 } \ ++ } ++ ++#define GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID \ ++ { 0x937fe521, 0x95ae, 0x4d1a, \ ++ { 0x89, 0x29, 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a } \ ++ } ++ + struct grub_efi_sal_system_table + { + grub_uint32_t signature; +@@ -1838,6 +1848,72 @@ struct grub_efi_block_io + }; + typedef struct grub_efi_block_io grub_efi_block_io_t; + ++enum grub_efi_ip4_config2_data_type { ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_POLICY, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MAXIMUM ++}; ++typedef enum grub_efi_ip4_config2_data_type grub_efi_ip4_config2_data_type_t; ++ ++struct grub_efi_ip4_config2_protocol ++{ ++ grub_efi_status_t (*set_data) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_ip4_config2_data_type_t data_type, ++ grub_efi_uintn_t data_size, ++ void *data); ++ ++ grub_efi_status_t (*get_data) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_ip4_config2_data_type_t data_type, ++ grub_efi_uintn_t *data_size, ++ void *data); ++ ++ grub_efi_status_t (*register_data_notify) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_ip4_config2_data_type_t data_type, ++ grub_efi_event_t event); ++ ++ grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip4_config2_protocol *this, ++ grub_efi_ip4_config2_data_type_t data_type, ++ grub_efi_event_t event); ++}; ++typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t; ++ ++enum grub_efi_ip6_config_data_type { ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_POLICY, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DUP_ADDR_DETECT_TRANSMITS, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_GATEWAY, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MAXIMUM ++}; ++typedef enum grub_efi_ip6_config_data_type grub_efi_ip6_config_data_type_t; ++ ++struct grub_efi_ip6_config_protocol ++{ ++ grub_efi_status_t (*set_data) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_ip6_config_data_type_t data_type, ++ grub_efi_uintn_t data_size, ++ void *data); ++ ++ grub_efi_status_t (*get_data) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_ip6_config_data_type_t data_type, ++ grub_efi_uintn_t *data_size, ++ void *data); ++ ++ grub_efi_status_t (*register_data_notify) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_ip6_config_data_type_t data_type, ++ grub_efi_event_t event); ++ ++ grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip6_config_protocol *this, ++ grub_efi_ip6_config_data_type_t data_type, ++ grub_efi_event_t event); ++}; ++typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t; ++ + #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ + || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ + || defined(__riscv) diff --git a/0118-Fix-one-more-coverity-complaint.patch b/0118-Fix-one-more-coverity-complaint.patch new file mode 100644 index 0000000..41f4d0a --- /dev/null +++ b/0118-Fix-one-more-coverity-complaint.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 25 May 2017 11:27:40 -0400 +Subject: [PATCH] Fix one more coverity complaint + +No idea why covscan thinks this is an "added" bug, since the file hasn't +changed in 3 years, but... yeah. + +Signed-off-by: Peter Jones +--- + grub-core/normal/completion.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c +index 596102848c1..c07100a8de3 100644 +--- a/grub-core/normal/completion.c ++++ b/grub-core/normal/completion.c +@@ -284,7 +284,8 @@ complete_file (void) + + /* Cut away the filename part. */ + dirfile = grub_strrchr (dir, '/'); +- dirfile[1] = '\0'; ++ if (dirfile) ++ dirfile[1] = '\0'; + + /* Iterate the directory. */ + (fs->fs_dir) (dev, dir, iterate_dir, NULL); diff --git a/0119-Support-UEFI-networking-protocols.patch b/0119-Support-UEFI-networking-protocols.patch new file mode 100644 index 0000000..3b0ff4a --- /dev/null +++ b/0119-Support-UEFI-networking-protocols.patch @@ -0,0 +1,5053 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Wed, 22 Feb 2017 14:27:50 +0800 +Subject: [PATCH] Support UEFI networking protocols + +References: fate#320130, bsc#1015589, bsc#1076132 +Patch-Mainline: no + +V1: + * Add preliminary support of UEFI networking protocols + * Support UEFI HTTPS Boot + +V2: + * Workaround http data access in firmware + * Fix DNS device path parsing for efinet device + * Relaxed UEFI Protocol requirement + * Support Intel OPA (Omni-Path Architecture) PXE Boot + +V3: + * Fix bufio in calculating address of next_buf + * Check HTTP respond code + * Use HEAD request method to test before GET + * Finish HTTP transaction in one go + * Fix bsc#1076132 + +Signed-off-by: Michael Chang +[pjones: make efi_netfs not duplicate symbols from efinet] +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 12 + + grub-core/io/bufio.c | 2 +- + grub-core/kern/efi/efi.c | 96 ++- + grub-core/net/drivers/efi/efinet.c | 27 + + grub-core/net/efi/dhcp.c | 397 ++++++++++ + grub-core/net/efi/efi_netfs.c | 57 ++ + grub-core/net/efi/http.c | 419 +++++++++++ + grub-core/net/efi/ip4_config.c | 398 ++++++++++ + grub-core/net/efi/ip6_config.c | 422 +++++++++++ + grub-core/net/efi/net.c | 1428 ++++++++++++++++++++++++++++++++++++ + grub-core/net/efi/pxe.c | 424 +++++++++++ + grub-core/net/net.c | 74 ++ + util/grub-mknetdir.c | 23 +- + include/grub/efi/api.h | 180 ++++- + include/grub/efi/dhcp.h | 343 +++++++++ + include/grub/efi/http.h | 215 ++++++ + include/grub/net/efi.h | 144 ++++ + 17 files changed, 4620 insertions(+), 41 deletions(-) + create mode 100644 grub-core/net/efi/dhcp.c + create mode 100644 grub-core/net/efi/efi_netfs.c + create mode 100644 grub-core/net/efi/http.c + create mode 100644 grub-core/net/efi/ip4_config.c + create mode 100644 grub-core/net/efi/ip6_config.c + create mode 100644 grub-core/net/efi/net.c + create mode 100644 grub-core/net/efi/pxe.c + create mode 100644 include/grub/efi/dhcp.h + create mode 100644 include/grub/efi/http.h + create mode 100644 include/grub/net/efi.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 49c5dc4c3b7..48491b50683 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2276,6 +2276,12 @@ module = { + common = hook/datehook.c; + }; + ++module = { ++ name = efi_netfs; ++ common = net/efi/efi_netfs.c; ++ enable = efi; ++}; ++ + module = { + name = net; + common = net/net.c; +@@ -2290,6 +2296,12 @@ module = { + common = net/arp.c; + common = net/netbuff.c; + common = net/url.c; ++ efi = net/efi/net.c; ++ efi = net/efi/http.c; ++ efi = net/efi/pxe.c; ++ efi = net/efi/ip4_config.c; ++ efi = net/efi/ip6_config.c; ++ efi = net/efi/dhcp.c; + }; + + module = { +diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c +index a458c3aca78..1637731535e 100644 +--- a/grub-core/io/bufio.c ++++ b/grub-core/io/bufio.c +@@ -139,7 +139,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t len) + return res; + + /* Need to read some more. */ +- next_buf = (file->offset + res + len - 1) & ~((grub_off_t) bufio->block_size - 1); ++ next_buf = (grub_divmod64 (file->offset + res + len - 1, bufio->block_size, NULL)) * bufio->block_size; + /* Now read between file->offset + res and bufio->buffer_at. */ + if (file->offset + res < next_buf) + { +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 19054b1465f..ada3004cfba 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -709,7 +709,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) + { + grub_efi_ipv4_device_path_t *ipv4 + = (grub_efi_ipv4_device_path_t *) dp; +- grub_printf ("/IPv4(%u.%u.%u.%u,%u.%u.%u.%u,%u,%u,%x,%x)", ++ grub_printf ("/IPv4(%u.%u.%u.%u,%u.%u.%u.%u,%u,%u,%x,%x", + (unsigned) ipv4->local_ip_address[0], + (unsigned) ipv4->local_ip_address[1], + (unsigned) ipv4->local_ip_address[2], +@@ -722,33 +722,60 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) + (unsigned) ipv4->remote_port, + (unsigned) ipv4->protocol, + (unsigned) ipv4->static_ip_address); ++ if (len == sizeof (*ipv4)) ++ { ++ grub_printf (",%u.%u.%u.%u,%u.%u.%u.%u", ++ (unsigned) ipv4->gateway_ip_address[0], ++ (unsigned) ipv4->gateway_ip_address[1], ++ (unsigned) ipv4->gateway_ip_address[2], ++ (unsigned) ipv4->gateway_ip_address[3], ++ (unsigned) ipv4->subnet_mask[0], ++ (unsigned) ipv4->subnet_mask[1], ++ (unsigned) ipv4->subnet_mask[2], ++ (unsigned) ipv4->subnet_mask[3]); ++ } ++ grub_printf (")"); + } + break; + case GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE: + { + grub_efi_ipv6_device_path_t *ipv6 + = (grub_efi_ipv6_device_path_t *) dp; +- grub_printf ("/IPv6(%x:%x:%x:%x:%x:%x:%x:%x,%x:%x:%x:%x:%x:%x:%x:%x,%u,%u,%x,%x)", +- (unsigned) ipv6->local_ip_address[0], +- (unsigned) ipv6->local_ip_address[1], +- (unsigned) ipv6->local_ip_address[2], +- (unsigned) ipv6->local_ip_address[3], +- (unsigned) ipv6->local_ip_address[4], +- (unsigned) ipv6->local_ip_address[5], +- (unsigned) ipv6->local_ip_address[6], +- (unsigned) ipv6->local_ip_address[7], +- (unsigned) ipv6->remote_ip_address[0], +- (unsigned) ipv6->remote_ip_address[1], +- (unsigned) ipv6->remote_ip_address[2], +- (unsigned) ipv6->remote_ip_address[3], +- (unsigned) ipv6->remote_ip_address[4], +- (unsigned) ipv6->remote_ip_address[5], +- (unsigned) ipv6->remote_ip_address[6], +- (unsigned) ipv6->remote_ip_address[7], ++ grub_printf ("/IPv6(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x,%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x,%u,%u,%x,%x", ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[0]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[1]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[2]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[3]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[4]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[5]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[6]), ++ (unsigned) grub_be_to_cpu16 (ipv6->local_ip_address[7]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[0]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[1]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[2]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[3]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[4]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[5]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[6]), ++ (unsigned) grub_be_to_cpu16 (ipv6->remote_ip_address[7]), + (unsigned) ipv6->local_port, + (unsigned) ipv6->remote_port, + (unsigned) ipv6->protocol, + (unsigned) ipv6->static_ip_address); ++ if (len == sizeof (*ipv6)) ++ { ++ grub_printf (",%u,%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", ++ (unsigned) ipv6->prefix_length, ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[0]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[1]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[2]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[3]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[4]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[5]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[6]), ++ (unsigned) grub_be_to_cpu16 (ipv6->gateway_ip_address[7])); ++ } ++ grub_printf (")"); + } + break; + case GRUB_EFI_INFINIBAND_DEVICE_PATH_SUBTYPE: +@@ -788,6 +815,39 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) + dump_vendor_path ("Messaging", + (grub_efi_vendor_device_path_t *) dp); + break; ++ case GRUB_EFI_URI_DEVICE_PATH_SUBTYPE: ++ { ++ grub_efi_uri_device_path_t *uri ++ = (grub_efi_uri_device_path_t *) dp; ++ grub_printf ("/URI(%s)", uri->uri); ++ } ++ break; ++ case GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE: ++ { ++ grub_efi_dns_device_path_t *dns ++ = (grub_efi_dns_device_path_t *) dp; ++ if (dns->is_ipv6) ++ { ++ grub_printf ("/DNS(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x)", ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[0]) >> 16), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[0])), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[1]) >> 16), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[1])), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[2]) >> 16), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[2])), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[3]) >> 16), ++ (grub_uint16_t)(grub_be_to_cpu32(dns->dns_server_ip[0].addr[3]))); ++ } ++ else ++ { ++ grub_printf ("/DNS(%d.%d.%d.%d)", ++ dns->dns_server_ip[0].v4.addr[0], ++ dns->dns_server_ip[0].v4.addr[1], ++ dns->dns_server_ip[0].v4.addr[2], ++ dns->dns_server_ip[0].v4.addr[3]); ++ } ++ } ++ break; + default: + grub_printf ("/UnknownMessaging(%x)", (unsigned) subtype); + break; +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index c843654b830..ca8bd3c2301 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -492,6 +493,17 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u + + ldp = grub_efi_find_last_device_path (ddp); + ++ /* Skip the DNS Device */ ++ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE ++ && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE) ++ { ++ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ ldp->length = sizeof (*ldp); ++ ++ ldp = grub_efi_find_last_device_path (ddp); ++ } ++ + if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE + || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE + && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE)) +@@ -761,6 +773,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE + || (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE + && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE ++ && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE + && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) + continue; + dup_dp = grub_efi_duplicate_device_path (dp); +@@ -775,6 +788,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + dup_ldp->length = sizeof (*dup_ldp); + } + ++ dup_ldp = grub_efi_find_last_device_path (dup_dp); ++ if (GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE) ++ { ++ dup_ldp = grub_efi_find_last_device_path (dup_dp); ++ dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ dup_ldp->length = sizeof (*dup_ldp); ++ } ++ + dup_ldp = grub_efi_find_last_device_path (dup_dp); + dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; + dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; +@@ -846,6 +868,9 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + + GRUB_MOD_INIT(efinet) + { ++ if (grub_efi_net_config) ++ return; ++ + grub_efinet_findcards (); + grub_efi_net_config = grub_efi_net_config_real; + } +@@ -857,5 +882,7 @@ GRUB_MOD_FINI(efinet) + FOR_NET_CARDS_SAFE (card, next) + if (card->driver == &efidriver) + grub_net_card_unregister (card); ++ ++ grub_efi_net_config = NULL; + } + +diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c +new file mode 100644 +index 00000000000..dbef63d8c08 +--- /dev/null ++++ b/grub-core/net/efi/dhcp.c +@@ -0,0 +1,397 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef GRUB_EFI_NET_DEBUG ++static void ++dhcp4_mode_print (grub_efi_dhcp4_mode_data_t *mode) ++{ ++ switch (mode->state) ++ { ++ case GRUB_EFI_DHCP4_STOPPED: ++ grub_printf ("STATE: STOPPED\n"); ++ break; ++ case GRUB_EFI_DHCP4_INIT: ++ grub_printf ("STATE: INIT\n"); ++ break; ++ case GRUB_EFI_DHCP4_SELECTING: ++ grub_printf ("STATE: SELECTING\n"); ++ break; ++ case GRUB_EFI_DHCP4_REQUESTING: ++ grub_printf ("STATE: REQUESTING\n"); ++ break; ++ case GRUB_EFI_DHCP4_BOUND: ++ grub_printf ("STATE: BOUND\n"); ++ break; ++ case GRUB_EFI_DHCP4_RENEWING: ++ grub_printf ("STATE: RENEWING\n"); ++ break; ++ case GRUB_EFI_DHCP4_REBINDING: ++ grub_printf ("STATE: REBINDING\n"); ++ break; ++ case GRUB_EFI_DHCP4_INIT_REBOOT: ++ grub_printf ("STATE: INIT_REBOOT\n"); ++ break; ++ case GRUB_EFI_DHCP4_REBOOTING: ++ grub_printf ("STATE: REBOOTING\n"); ++ break; ++ default: ++ grub_printf ("STATE: UNKNOWN\n"); ++ break; ++ } ++ ++ grub_printf ("CLIENT_ADDRESS: %u.%u.%u.%u\n", ++ mode->client_address[0], ++ mode->client_address[1], ++ mode->client_address[2], ++ mode->client_address[3]); ++ grub_printf ("SERVER_ADDRESS: %u.%u.%u.%u\n", ++ mode->server_address[0], ++ mode->server_address[1], ++ mode->server_address[2], ++ mode->server_address[3]); ++ grub_printf ("SUBNET_MASK: %u.%u.%u.%u\n", ++ mode->subnet_mask[0], ++ mode->subnet_mask[1], ++ mode->subnet_mask[2], ++ mode->subnet_mask[3]); ++ grub_printf ("ROUTER_ADDRESS: %u.%u.%u.%u\n", ++ mode->router_address[0], ++ mode->router_address[1], ++ mode->router_address[2], ++ mode->router_address[3]); ++} ++#endif ++ ++static grub_efi_ipv4_address_t * ++grub_efi_dhcp4_parse_dns (grub_efi_dhcp4_protocol_t *dhcp4, grub_efi_dhcp4_packet_t *reply_packet) ++{ ++ grub_efi_dhcp4_packet_option_t **option_list; ++ grub_efi_status_t status; ++ grub_efi_uint32_t option_count = 0; ++ grub_efi_uint32_t i; ++ ++ status = efi_call_4 (dhcp4->parse, dhcp4, reply_packet, &option_count, NULL); ++ ++ if (status != GRUB_EFI_BUFFER_TOO_SMALL) ++ return NULL; ++ ++ option_list = grub_malloc (option_count * sizeof(*option_list)); ++ if (!option_list) ++ return NULL; ++ ++ status = efi_call_4 (dhcp4->parse, dhcp4, reply_packet, &option_count, option_list); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (option_list); ++ return NULL; ++ } ++ ++ for (i = 0; i < option_count; ++i) ++ { ++ if (option_list[i]->op_code == 6) ++ { ++ grub_efi_ipv4_address_t *dns_address; ++ ++ if (((option_list[i]->length & 0x3) != 0) || (option_list[i]->length == 0)) ++ continue; ++ ++ /* We only contact primary dns */ ++ dns_address = grub_malloc (sizeof (*dns_address)); ++ if (!dns_address) ++ { ++ grub_free (option_list); ++ return NULL; ++ } ++ grub_memcpy (dns_address, option_list[i]->data, sizeof (dns_address)); ++ grub_free (option_list); ++ return dns_address; ++ } ++ } ++ ++ grub_free (option_list); ++ return NULL; ++} ++ ++#if 0 ++/* Somehow this doesn't work ... */ ++static grub_err_t ++grub_cmd_efi_bootp (struct grub_command *cmd __attribute__ ((unused)), ++ int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ struct grub_efi_net_device *dev; ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ grub_efi_pxe_t *pxe = dev->ip4_pxe; ++ grub_efi_pxe_mode_t *mode = pxe->mode; ++ grub_efi_status_t status; ++ ++ if (!mode->started) ++ { ++ status = efi_call_2 (pxe->start, pxe, 0); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ grub_printf ("Couldn't start PXE\n"); ++ } ++ ++ status = efi_call_2 (pxe->dhcp, pxe, 0); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp4 configure failed, %d\n", (int)status); ++ continue; ++ } ++ ++ dev->prefer_ip6 = 0; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++#endif ++ ++static grub_err_t ++grub_cmd_efi_bootp (struct grub_command *cmd __attribute__ ((unused)), ++ int argc, ++ char **args) ++{ ++ struct grub_efi_net_device *netdev; ++ ++ for (netdev = net_devices; netdev; netdev = netdev->next) ++ { ++ grub_efi_status_t status; ++ grub_efi_dhcp4_mode_data_t mode; ++ grub_efi_dhcp4_config_data_t config; ++ grub_efi_dhcp4_packet_option_t *options; ++ grub_efi_ipv4_address_t *dns_address; ++ grub_efi_net_ip_manual_address_t net_ip; ++ grub_efi_net_ip_address_t ip_addr; ++ grub_efi_net_interface_t *inf = NULL; ++ ++ if (argc > 0 && grub_strcmp (netdev->card_name, args[0]) != 0) ++ continue; ++ ++ grub_memset (&config, 0, sizeof(config)); ++ ++ config.option_count = 1; ++ options = grub_malloc (sizeof(*options) + 2); ++ /* Parameter request list */ ++ options->op_code = 55; ++ options->length = 3; ++ /* subnet mask */ ++ options->data[0] = 1; ++ /* router */ ++ options->data[1] = 3; ++ /* DNS */ ++ options->data[2] = 6; ++ config.option_list = &options; ++ ++ /* FIXME: What if the dhcp has bounded */ ++ status = efi_call_2 (netdev->dhcp4->configure, netdev->dhcp4, &config); ++ grub_free (options); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp4 configure failed, %d\n", (int)status); ++ continue; ++ } ++ ++ status = efi_call_2 (netdev->dhcp4->start, netdev->dhcp4, NULL); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp4 start failed, %d\n", (int)status); ++ continue; ++ } ++ ++ status = efi_call_2 (netdev->dhcp4->get_mode_data, netdev->dhcp4, &mode); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp4 get mode failed, %d\n", (int)status); ++ continue; ++ } ++ ++#ifdef GRUB_EFI_NET_DEBUG ++ dhcp4_mode_print (&mode); ++#endif ++ ++ for (inf = netdev->net_interfaces; inf; inf = inf->next) ++ if (inf->prefer_ip6 == 0) ++ break; ++ ++ grub_memcpy (net_ip.ip4.address, mode.client_address, sizeof (net_ip.ip4.address)); ++ grub_memcpy (net_ip.ip4.subnet_mask, mode.subnet_mask, sizeof (net_ip.ip4.subnet_mask)); ++ ++ if (!inf) ++ { ++ char *name = grub_xasprintf ("%s:dhcp", netdev->card_name); ++ ++ net_ip.is_ip6 = 0; ++ inf = grub_efi_net_create_interface (netdev, ++ name, ++ &net_ip, ++ 1); ++ grub_free (name); ++ } ++ else ++ { ++ efi_net_interface_set_address (inf, &net_ip, 1); ++ } ++ ++ grub_memcpy (ip_addr.ip4, mode.router_address, sizeof (ip_addr.ip4)); ++ efi_net_interface_set_gateway (inf, &ip_addr); ++ ++ dns_address = grub_efi_dhcp4_parse_dns (netdev->dhcp4, mode.reply_packet); ++ if (dns_address) ++ efi_net_interface_set_dns (inf, (grub_efi_net_ip_address_t *)&dns_address); ++ ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++ ++static grub_err_t ++grub_cmd_efi_bootp6 (struct grub_command *cmd __attribute__ ((unused)), ++ int argc, ++ char **args) ++{ ++ struct grub_efi_net_device *dev; ++ grub_efi_uint32_t ia_id; ++ ++ for (dev = net_devices, ia_id = 0; dev; dev = dev->next, ia_id++) ++ { ++ grub_efi_dhcp6_config_data_t config; ++ grub_efi_dhcp6_packet_option_t *option_list[1]; ++ grub_efi_dhcp6_packet_option_t *opt; ++ grub_efi_status_t status; ++ grub_efi_dhcp6_mode_data_t mode; ++ grub_efi_dhcp6_retransmission_t retrans; ++ grub_efi_net_ip_manual_address_t net_ip; ++ grub_efi_boot_services_t *b = grub_efi_system_table->boot_services; ++ grub_efi_net_interface_t *inf = NULL; ++ ++ if (argc > 0 && grub_strcmp (dev->card_name, args[0]) != 0) ++ continue; ++ ++ opt = grub_malloc (sizeof(*opt) + 2 * sizeof (grub_efi_uint16_t)); ++ ++#define GRUB_EFI_DHCP6_OPT_ORO 6 ++ ++ opt->op_code = grub_cpu_to_be16_compile_time (GRUB_EFI_DHCP6_OPT_ORO); ++ opt->op_len = grub_cpu_to_be16_compile_time (2 * sizeof (grub_efi_uint16_t)); ++ ++#define GRUB_EFI_DHCP6_OPT_BOOT_FILE_URL 59 ++#define GRUB_EFI_DHCP6_OPT_DNS_SERVERS 23 ++ ++ grub_set_unaligned16 (opt->data, grub_cpu_to_be16_compile_time(GRUB_EFI_DHCP6_OPT_BOOT_FILE_URL)); ++ grub_set_unaligned16 (opt->data + 1 * sizeof (grub_efi_uint16_t), ++ grub_cpu_to_be16_compile_time(GRUB_EFI_DHCP6_OPT_DNS_SERVERS)); ++ ++ option_list[0] = opt; ++ retrans.irt = 4; ++ retrans.mrc = 4; ++ retrans.mrt = 32; ++ retrans.mrd = 60; ++ ++ config.dhcp6_callback = NULL; ++ config.callback_context = NULL; ++ config.option_count = 1; ++ config.option_list = option_list; ++ config.ia_descriptor.ia_id = ia_id; ++ config.ia_descriptor.type = GRUB_EFI_DHCP6_IA_TYPE_NA; ++ config.ia_info_event = NULL; ++ config.reconfigure_accept = 0; ++ config.rapid_commit = 0; ++ config.solicit_retransmission = &retrans; ++ ++ status = efi_call_2 (dev->dhcp6->configure, dev->dhcp6, &config); ++ grub_free (opt); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp6 configure failed, %d\n", (int)status); ++ continue; ++ } ++ status = efi_call_1 (dev->dhcp6->start, dev->dhcp6); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp6 start failed, %d\n", (int)status); ++ continue; ++ } ++ ++ status = efi_call_3 (dev->dhcp6->get_mode_data, dev->dhcp6, &mode, NULL); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("dhcp4 get mode failed, %d\n", (int)status); ++ continue; ++ } ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (inf->prefer_ip6 == 1) ++ break; ++ ++ grub_memcpy (net_ip.ip6.address, mode.ia->ia_address[0].ip_address, sizeof (net_ip.ip6.address)); ++ net_ip.ip6.prefix_length = 64; ++ net_ip.ip6.is_anycast = 0; ++ net_ip.is_ip6 = 1; ++ ++ if (!inf) ++ { ++ char *name = grub_xasprintf ("%s:dhcp", dev->card_name); ++ ++ inf = grub_efi_net_create_interface (dev, ++ name, ++ &net_ip, ++ 1); ++ grub_free (name); ++ } ++ else ++ { ++ efi_net_interface_set_address (inf, &net_ip, 1); ++ } ++ ++ { ++ grub_efi_uint32_t count = 0; ++ grub_efi_dhcp6_packet_option_t **options = NULL; ++ grub_efi_uint32_t i; ++ ++ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, NULL); ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL && count) ++ { ++ options = grub_malloc (count * sizeof(*options)); ++ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ if (options) ++ grub_free (options); ++ continue; ++ } ++ ++ for (i = 0; i < count; ++i) ++ { ++ if (options[i]->op_code == grub_cpu_to_be16_compile_time(GRUB_EFI_DHCP6_OPT_DNS_SERVERS)) ++ { ++ grub_efi_net_ip_address_t dns; ++ grub_memcpy (dns.ip6, options[i]->data, sizeof(net_ip.ip6)); ++ efi_net_interface_set_dns (inf, &dns); ++ break; ++ } ++ } ++ ++ if (options) ++ grub_free (options); ++ } ++ ++ efi_call_1 (b->free_pool, mode.client_id); ++ efi_call_1 (b->free_pool, mode.ia); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++grub_command_func_t grub_efi_net_bootp = grub_cmd_efi_bootp; ++grub_command_func_t grub_efi_net_bootp6 = grub_cmd_efi_bootp6; +diff --git a/grub-core/net/efi/efi_netfs.c b/grub-core/net/efi/efi_netfs.c +new file mode 100644 +index 00000000000..ef371d885ea +--- /dev/null ++++ b/grub-core/net/efi/efi_netfs.c +@@ -0,0 +1,57 @@ ++#include ++#include ++#define EFI_NET_CMD_PREFIX "net_efi" ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_command_t cmd_efi_lsroutes; ++static grub_command_t cmd_efi_lscards; ++static grub_command_t cmd_efi_lsaddrs; ++static grub_command_t cmd_efi_addaddr; ++static grub_command_t cmd_efi_bootp; ++static grub_command_t cmd_efi_bootp6; ++ ++static int initialized; ++ ++GRUB_MOD_INIT(efi_netfs) ++{ ++ if (grub_net_open) ++ return; ++ ++ if (grub_efi_net_fs_init ()) ++ { ++ cmd_efi_lsroutes = grub_register_command ("net_efi_ls_routes", grub_efi_net_list_routes, ++ "", N_("list network routes")); ++ cmd_efi_lscards = grub_register_command ("net_efi_ls_cards", grub_efi_net_list_cards, ++ "", N_("list network cards")); ++ cmd_efi_lsaddrs = grub_register_command ("net_efi_ls_addr", grub_efi_net_list_addrs, ++ "", N_("list network addresses")); ++ cmd_efi_addaddr = grub_register_command ("net_efi_add_addr", grub_efi_net_add_addr, ++ N_("SHORTNAME CARD ADDRESS [HWADDRESS]"), ++ N_("Add a network address.")); ++ cmd_efi_bootp = grub_register_command ("net_efi_bootp", grub_efi_net_bootp, ++ N_("[CARD]"), ++ N_("perform a bootp autoconfiguration")); ++ cmd_efi_bootp6 = grub_register_command ("net_efi_bootp6", grub_efi_net_bootp6, ++ N_("[CARD]"), ++ N_("perform a bootp autoconfiguration")); ++ initialized = 1; ++ } ++} ++ ++GRUB_MOD_FINI(efi_netfs) ++{ ++ if (initialized) ++ { ++ grub_unregister_command (cmd_efi_lsroutes); ++ grub_unregister_command (cmd_efi_lscards); ++ grub_unregister_command (cmd_efi_lsaddrs); ++ grub_unregister_command (cmd_efi_addaddr); ++ grub_unregister_command (cmd_efi_bootp); ++ grub_unregister_command (cmd_efi_bootp6); ++ grub_efi_net_fs_fini (); ++ initialized = 0; ++ return; ++ } ++} +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +new file mode 100644 +index 00000000000..3f61fd2fa5b +--- /dev/null ++++ b/grub-core/net/efi/http.c +@@ -0,0 +1,419 @@ ++ ++#include ++#include ++#include ++#include ++#include ++ ++static void ++http_configure (struct grub_efi_net_device *dev, int prefer_ip6) ++{ ++ grub_efi_http_config_data_t http_config; ++ grub_efi_httpv4_access_point_t httpv4_node; ++ grub_efi_httpv6_access_point_t httpv6_node; ++ grub_efi_status_t status; ++ ++ grub_efi_http_t *http = dev->http; ++ ++ grub_memset (&http_config, 0, sizeof(http_config)); ++ http_config.http_version = GRUB_EFI_HTTPVERSION11; ++ http_config.timeout_millisec = 5000; ++ ++ if (prefer_ip6) ++ { ++ grub_efi_uintn_t sz; ++ grub_efi_ip6_config_manual_address_t manual_address; ++ ++ http_config.local_address_is_ipv6 = 1; ++ sz = sizeof (manual_address); ++ status = efi_call_4 (dev->ip6_config->get_data, dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, &manual_address); ++ ++ if (status == GRUB_EFI_NOT_FOUND) ++ { ++ grub_printf ("The MANUAL ADDRESS is not found\n"); ++ } ++ ++ /* FIXME: The manual interface would return BUFFER TOO SMALL !!! */ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_printf ("??? %d\n",(int) status); ++ return; ++ } ++ ++ grub_memcpy (httpv6_node.local_address, manual_address.address, sizeof (httpv6_node.local_address)); ++ httpv6_node.local_port = 0; ++ http_config.access_point.ipv6_node = &httpv6_node; ++ } ++ else ++ { ++ http_config.local_address_is_ipv6 = 0; ++ grub_memset (&httpv4_node, 0, sizeof(httpv4_node)); ++ httpv4_node.use_default_address = 1; ++ ++ /* Use random port here */ ++ /* See TcpBind() in edk2/NetworkPkg/TcpDxe/TcpDispatcher.c */ ++ httpv4_node.local_port = 0; ++ http_config.access_point.ipv4_node = &httpv4_node; ++ } ++ ++ status = efi_call_2 (http->configure, http, &http_config); ++ ++ if (status == GRUB_EFI_ALREADY_STARTED) ++ { ++ /* XXX: This hangs HTTPS boot */ ++#if 0 ++ if (efi_call_2 (http->configure, http, NULL) != GRUB_EFI_SUCCESS) ++ { ++ grub_error (GRUB_ERR_IO, N_("couldn't reset http instance")); ++ grub_print_error (); ++ return; ++ } ++ status = efi_call_2 (http->configure, http, &http_config); ++#endif ++ return; ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_error (GRUB_ERR_IO, N_("couldn't configure http protocol, reason: %d"), (int)status); ++ grub_print_error (); ++ return ; ++ } ++} ++ ++static grub_efi_boolean_t request_callback_done; ++static grub_efi_boolean_t response_callback_done; ++ ++static void ++grub_efi_http_request_callback (grub_efi_event_t event __attribute__ ((unused)), ++ void *context __attribute__ ((unused))) ++{ ++ request_callback_done = 1; ++} ++ ++static void ++grub_efi_http_response_callback (grub_efi_event_t event __attribute__ ((unused)), ++ void *context __attribute__ ((unused))) ++{ ++ response_callback_done = 1; ++} ++ ++static grub_err_t ++efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, int headeronly, grub_off_t *file_size) ++{ ++ grub_efi_http_request_data_t request_data; ++ grub_efi_http_message_t request_message; ++ grub_efi_http_token_t request_token; ++ grub_efi_http_response_data_t response_data; ++ grub_efi_http_message_t response_message; ++ grub_efi_http_token_t response_token; ++ grub_efi_http_header_t request_headers[3]; ++ ++ grub_efi_status_t status; ++ grub_efi_boot_services_t *b = grub_efi_system_table->boot_services; ++ char *url = NULL; ++ ++ request_headers[0].field_name = (grub_efi_char8_t *)"Host"; ++ request_headers[0].field_value = (grub_efi_char8_t *)server; ++ request_headers[1].field_name = (grub_efi_char8_t *)"Accept"; ++ request_headers[1].field_value = (grub_efi_char8_t *)"*/*"; ++ request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent"; ++ request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0"; ++ ++ { ++ grub_efi_ipv6_address_t address; ++ const char *rest; ++ grub_efi_char16_t *ucs2_url; ++ grub_size_t url_len, ucs2_url_len; ++ const char *protocol = (use_https == 1) ? "https" : "http"; ++ ++ if (grub_efi_string_to_ip6_address (server, &address, &rest) && *rest == 0) ++ url = grub_xasprintf ("%s://[%s]%s", protocol, server, name); ++ else ++ url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ ++ if (!url) ++ { ++ return grub_errno; ++ } ++ ++ url_len = grub_strlen (url); ++ ucs2_url_len = url_len * GRUB_MAX_UTF16_PER_UTF8; ++ ucs2_url = grub_malloc ((ucs2_url_len + 1) * sizeof (ucs2_url[0])); ++ ++ if (!ucs2_url) ++ { ++ grub_free (url); ++ return grub_errno; ++ } ++ ++ ucs2_url_len = grub_utf8_to_utf16 (ucs2_url, ucs2_url_len, (grub_uint8_t *)url, url_len, NULL); /* convert string format from ascii to usc2 */ ++ ucs2_url[ucs2_url_len] = 0; ++ grub_free (url); ++ request_data.url = ucs2_url; ++ } ++ ++ request_data.method = (headeronly > 0) ? GRUB_EFI_HTTPMETHODHEAD : GRUB_EFI_HTTPMETHODGET; ++ ++ request_message.data.request = &request_data; ++ request_message.header_count = 3; ++ request_message.headers = request_headers; ++ request_message.body_length = 0; ++ request_message.body = NULL; ++ ++ /* request token */ ++ request_token.event = NULL; ++ request_token.status = GRUB_EFI_NOT_READY; ++ request_token.message = &request_message; ++ ++ request_callback_done = 0; ++ status = efi_call_5 (b->create_event, ++ GRUB_EFI_EVT_NOTIFY_SIGNAL, ++ GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_request_callback, ++ NULL, ++ &request_token.event); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (request_data.url); ++ return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); ++ } ++ ++ status = efi_call_2 (http->request, http, &request_token); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ efi_call_1 (b->close_event, request_token.event); ++ grub_free (request_data.url); ++ return grub_error (GRUB_ERR_IO, "Fail to send a request! status=0x%x\n", status); ++ } ++ /* TODO: Add Timeout */ ++ while (!request_callback_done) ++ efi_call_1(http->poll, http); ++ ++ response_data.status_code = GRUB_EFI_HTTP_STATUS_UNSUPPORTED_STATUS; ++ response_message.data.response = &response_data; ++ /* herader_count will be updated by the HTTP driver on response */ ++ response_message.header_count = 0; ++ /* headers will be populated by the driver on response */ ++ response_message.headers = NULL; ++ /* use zero BodyLength to only receive the response headers */ ++ response_message.body_length = 0; ++ response_message.body = NULL; ++ response_token.event = NULL; ++ ++ status = efi_call_5 (b->create_event, ++ GRUB_EFI_EVT_NOTIFY_SIGNAL, ++ GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_response_callback, ++ NULL, ++ &response_token.event); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ efi_call_1 (b->close_event, request_token.event); ++ grub_free (request_data.url); ++ return grub_error (GRUB_ERR_IO, "Fail to create an event! status=0x%x\n", status); ++ } ++ ++ response_token.status = GRUB_EFI_SUCCESS; ++ response_token.message = &response_message; ++ ++ /* wait for HTTP response */ ++ response_callback_done = 0; ++ status = efi_call_2 (http->response, http, &response_token); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ efi_call_1 (b->close_event, response_token.event); ++ efi_call_1 (b->close_event, request_token.event); ++ grub_free (request_data.url); ++ return grub_error (GRUB_ERR_IO, "Fail to receive a response! status=%d\n", (int)status); ++ } ++ ++ /* TODO: Add Timeout */ ++ while (!response_callback_done) ++ efi_call_1 (http->poll, http); ++ ++ if (response_message.data.response->status_code != GRUB_EFI_HTTP_STATUS_200_OK) ++ { ++ grub_efi_http_status_code_t status_code = response_message.data.response->status_code; ++ ++ if (response_message.headers) ++ efi_call_1 (b->free_pool, response_message.headers); ++ efi_call_1 (b->close_event, response_token.event); ++ efi_call_1 (b->close_event, request_token.event); ++ grub_free (request_data.url); ++ if (status_code == GRUB_EFI_HTTP_STATUS_404_NOT_FOUND) ++ { ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, _("file `%s' not found"), name); ++ } ++ else ++ { ++ return grub_error (GRUB_ERR_NET_UNKNOWN_ERROR, ++ _("unsupported uefi http status code 0x%x"), status_code); ++ } ++ } ++ ++ if (file_size) ++ { ++ int i; ++ /* parse the length of the file from the ContentLength header */ ++ for (*file_size = 0, i = 0; i < (int)response_message.header_count; ++i) ++ { ++ if (!grub_strcmp((const char*)response_message.headers[i].field_name, "Content-Length")) ++ { ++ *file_size = grub_strtoul((const char*)response_message.headers[i].field_value, 0, 10); ++ break; ++ } ++ } ++ } ++ ++ if (response_message.headers) ++ efi_call_1 (b->free_pool, response_message.headers); ++ efi_call_1 (b->close_event, response_token.event); ++ efi_call_1 (b->close_event, request_token.event); ++ grub_free (request_data.url); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_ssize_t ++efihttp_read (struct grub_efi_net_device *dev, ++ char *buf, ++ grub_size_t len) ++{ ++ grub_efi_http_message_t response_message; ++ grub_efi_http_token_t response_token; ++ ++ grub_efi_status_t status; ++ grub_size_t sum = 0; ++ grub_efi_boot_services_t *b = grub_efi_system_table->boot_services; ++ grub_efi_http_t *http = dev->http; ++ ++ if (!len) ++ { ++ grub_error (GRUB_ERR_BUG, "Invalid arguments to EFI HTTP Read"); ++ return -1; ++ } ++ ++ efi_call_5 (b->create_event, ++ GRUB_EFI_EVT_NOTIFY_SIGNAL, ++ GRUB_EFI_TPL_CALLBACK, ++ grub_efi_http_response_callback, ++ NULL, ++ &response_token.event); ++ ++ while (len) ++ { ++ response_message.data.response = NULL; ++ response_message.header_count = 0; ++ response_message.headers = NULL; ++ response_message.body_length = len; ++ response_message.body = buf; ++ ++ response_token.message = &response_message; ++ response_token.status = GRUB_EFI_NOT_READY; ++ ++ response_callback_done = 0; ++ ++ status = efi_call_2 (http->response, http, &response_token); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ efi_call_1 (b->close_event, response_token.event); ++ grub_error (GRUB_ERR_IO, "Error! status=%d\n", (int)status); ++ return -1; ++ } ++ ++ while (!response_callback_done) ++ efi_call_1(http->poll, http); ++ ++ sum += response_message.body_length; ++ buf += response_message.body_length; ++ len -= response_message.body_length; ++ } ++ ++ efi_call_1 (b->close_event, response_token.event); ++ ++ return sum; ++} ++ ++static grub_err_t ++grub_efihttp_open (struct grub_efi_net_device *dev, ++ int prefer_ip6 __attribute__ ((unused)), ++ grub_file_t file, ++ const char *filename __attribute__ ((unused)), ++ int type) ++{ ++ grub_err_t err; ++ grub_off_t size; ++ char *buf; ++ ++ err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ ++ err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 0, &size); ++ if (err != GRUB_ERR_NONE) ++ return err; ++ ++ buf = grub_malloc (size); ++ efihttp_read (dev, buf, size); ++ ++ file->size = size; ++ file->data = buf; ++ file->not_easily_seekable = 0; ++ file->device->net->offset = 0; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_efihttp_close (struct grub_efi_net_device *dev __attribute__ ((unused)), ++ int prefer_ip6 __attribute__ ((unused)), ++ grub_file_t file) ++{ ++ if (file->data) ++ grub_free (file->data); ++ ++ file->data = 0; ++ file->offset = 0; ++ file->size = 0; ++ file->device->net->offset = 0; ++ return GRUB_ERR_NONE; ++} ++ ++static grub_ssize_t ++grub_efihttp_read (struct grub_efi_net_device *dev __attribute__((unused)), ++ int prefer_ip6 __attribute__((unused)), ++ grub_file_t file, ++ char *buf, ++ grub_size_t len) ++{ ++ grub_size_t r = len; ++ ++ if (!file->data || !buf || !len) ++ return 0; ++ ++ if ((file->device->net->offset + len) > file->size) ++ r = file->size - file->device->net->offset; ++ ++ if (r) ++ { ++ grub_memcpy (buf, (char *)file->data + file->device->net->offset, r); ++ file->device->net->offset += r; ++ } ++ ++ return r; ++} ++ ++struct grub_efi_net_io io_http = ++ { ++ .configure = http_configure, ++ .open = grub_efihttp_open, ++ .read = grub_efihttp_read, ++ .close = grub_efihttp_close ++ }; +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +new file mode 100644 +index 00000000000..b711a5d9457 +--- /dev/null ++++ b/grub-core/net/efi/ip4_config.c +@@ -0,0 +1,398 @@ ++ ++#include ++#include ++#include ++#include ++#include ++ ++char * ++grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_address_t hw_address) ++{ ++ char *hw_addr, *p; ++ int sz, s; ++ int i; ++ ++ sz = (int)hw_address_size * (sizeof ("XX:") - 1) + 1; ++ ++ hw_addr = grub_malloc (sz); ++ if (!hw_addr) ++ return NULL; ++ ++ p = hw_addr; ++ s = sz; ++ for (i = 0; i < (int)hw_address_size; i++) ++ { ++ grub_snprintf (p, sz, "%02x:", hw_address[i]); ++ p += sizeof ("XX:") - 1; ++ s -= sizeof ("XX:") - 1; ++ } ++ ++ hw_addr[sz - 2] = '\0'; ++ return hw_addr; ++} ++ ++char * ++grub_efi_ip4_address_to_string (grub_efi_ipv4_address_t *address) ++{ ++ char *addr; ++ ++ addr = grub_malloc (sizeof ("XXX.XXX.XXX.XXX")); ++ if (!addr) ++ return NULL; ++ ++ /* FIXME: Use grub_xasprintf ? */ ++ grub_snprintf (addr, ++ sizeof ("XXX.XXX.XXX.XXX"), ++ "%u.%u.%u.%u", ++ (*address)[0], ++ (*address)[1], ++ (*address)[2], ++ (*address)[3]); ++ ++ return addr; ++} ++ ++int ++grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest) ++{ ++ grub_uint32_t newip = 0; ++ int i; ++ const char *ptr = val; ++ ++ for (i = 0; i < 4; i++) ++ { ++ unsigned long t; ++ t = grub_strtoul (ptr, (char **) &ptr, 0); ++ if (grub_errno) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ if (*ptr != '.' && i == 0) ++ { ++ /* XXX: t is in host byte order */ ++ newip = t; ++ break; ++ } ++ if (t & ~0xff) ++ return 0; ++ newip <<= 8; ++ newip |= t; ++ if (i != 3 && *ptr != '.') ++ return 0; ++ ptr++; ++ } ++ ++ newip = grub_cpu_to_be32 (newip); ++ ++ grub_memcpy (address, &newip, sizeof(*address)); ++ ++ if (rest) ++ *rest = (ptr - 1); ++ return 1; ++} ++ ++static grub_efi_ip4_config2_interface_info_t * ++efi_ip4_config_interface_info (grub_efi_ip4_config2_protocol_t *ip4_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip4_config2_interface_info_t *interface_info; ++ ++ sz = sizeof (*interface_info) + sizeof (*interface_info->route_table); ++ interface_info = grub_malloc (sz); ++ if (!interface_info) ++ return NULL; ++ ++ status = efi_call_4 (ip4_config->get_data, ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL) ++ { ++ grub_free (interface_info); ++ interface_info = grub_malloc (sz); ++ status = efi_call_4 (ip4_config->get_data, ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (interface_info); ++ return NULL; ++ } ++ ++ return interface_info; ++} ++ ++static grub_efi_ip4_config2_manual_address_t * ++efi_ip4_config_manual_address (grub_efi_ip4_config2_protocol_t *ip4_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip4_config2_manual_address_t *manual_address; ++ ++ sz = sizeof (*manual_address); ++ manual_address = grub_malloc (sz); ++ if (!manual_address) ++ return NULL; ++ ++ status = efi_call_4 (ip4_config->get_data, ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, manual_address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (manual_address); ++ return NULL; ++ } ++ ++ return manual_address; ++} ++ ++char * ++grub_efi_ip4_interface_name (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip4_config2_interface_info_t *interface_info; ++ char *name; ++ ++ interface_info = efi_ip4_config_interface_info (dev->ip4_config); ++ ++ if (!interface_info) ++ return NULL; ++ ++ name = grub_malloc (GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE ++ * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ *grub_utf16_to_utf8 ((grub_uint8_t *)name, interface_info->name, ++ GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE) = 0; ++ grub_free (interface_info); ++ return name; ++} ++ ++static char * ++grub_efi_ip4_interface_hw_address (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip4_config2_interface_info_t *interface_info; ++ char *hw_addr; ++ ++ interface_info = efi_ip4_config_interface_info (dev->ip4_config); ++ ++ if (!interface_info) ++ return NULL; ++ ++ hw_addr = grub_efi_hw_address_to_string (interface_info->hw_address_size, interface_info->hw_address); ++ grub_free (interface_info); ++ ++ return hw_addr; ++} ++ ++static char * ++grub_efi_ip4_interface_address (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip4_config2_manual_address_t *manual_address; ++ char *addr; ++ ++ manual_address = efi_ip4_config_manual_address (dev->ip4_config); ++ ++ if (!manual_address) ++ return NULL; ++ ++ addr = grub_efi_ip4_address_to_string (&manual_address->address); ++ grub_free (manual_address); ++ return addr; ++} ++ ++ ++static int ++address_mask_size (grub_efi_ipv4_address_t *address) ++{ ++ grub_uint8_t i; ++ grub_uint32_t u32_addr = grub_be_to_cpu32 (grub_get_unaligned32 (address)); ++ ++ if (u32_addr == 0) ++ return 0; ++ ++ for (i = 0; i < 32 ; ++i) ++ { ++ if (u32_addr == ((0xffffffff >> i) << i)) ++ return (32 - i); ++ } ++ ++ return -1; ++} ++ ++static char ** ++grub_efi_ip4_interface_route_table (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip4_config2_interface_info_t *interface_info; ++ char **ret; ++ int i, id; ++ ++ interface_info = efi_ip4_config_interface_info (dev->ip4_config); ++ if (!interface_info) ++ return NULL; ++ ++ ret = grub_malloc (sizeof (*ret) * (interface_info->route_table_size + 1)); ++ ++ if (!ret) ++ { ++ grub_free (interface_info); ++ return NULL; ++ } ++ ++ id = 0; ++ for (i = 0; i < (int)interface_info->route_table_size; i++) ++ { ++ char *subnet, *gateway, *mask; ++ grub_uint32_t u32_subnet, u32_gateway; ++ int mask_size; ++ grub_efi_ip4_route_table_t *route_table = interface_info->route_table + i; ++ grub_efi_net_interface_t *inf; ++ char *interface_name = NULL; ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (!inf->prefer_ip6) ++ interface_name = inf->name; ++ ++ u32_gateway = grub_get_unaligned32 (&route_table->gateway_address); ++ gateway = grub_efi_ip4_address_to_string (&route_table->gateway_address); ++ u32_subnet = grub_get_unaligned32 (&route_table->subnet_address); ++ subnet = grub_efi_ip4_address_to_string (&route_table->subnet_address); ++ mask_size = address_mask_size (&route_table->subnet_mask); ++ mask = grub_efi_ip4_address_to_string (&route_table->subnet_mask); ++ if (u32_subnet && !u32_gateway && interface_name) ++ ret[id++] = grub_xasprintf ("%s:local %s/%d %s", dev->card_name, subnet, mask_size, interface_name); ++ else if (u32_subnet && u32_gateway) ++ ret[id++] = grub_xasprintf ("%s:gw %s/%d gw %s", dev->card_name, subnet, mask_size, gateway); ++ else if (!u32_subnet && u32_gateway) ++ ret[id++] = grub_xasprintf ("%s:default %s/%d gw %s", dev->card_name, subnet, mask_size, gateway); ++ grub_free (subnet); ++ grub_free (gateway); ++ grub_free (mask); ++ } ++ ++ ret[id] = NULL; ++ grub_free (interface_info); ++ return ret; ++} ++ ++static grub_efi_net_interface_t * ++grub_efi_ip4_interface_match (struct grub_efi_net_device *dev, grub_efi_net_ip_address_t *ip_address) ++{ ++ grub_efi_ip4_config2_interface_info_t *interface_info; ++ grub_efi_net_interface_t *inf; ++ int i; ++ grub_efi_ipv4_address_t *address = &ip_address->ip4; ++ ++ interface_info = efi_ip4_config_interface_info (dev->ip4_config); ++ if (!interface_info) ++ return NULL; ++ ++ for (i = 0; i < (int)interface_info->route_table_size; i++) ++ { ++ grub_efi_ip4_route_table_t *route_table = interface_info->route_table + i; ++ grub_uint32_t u32_address, u32_mask, u32_subnet; ++ ++ u32_address = grub_get_unaligned32 (address); ++ u32_subnet = grub_get_unaligned32 (route_table->subnet_address); ++ u32_mask = grub_get_unaligned32 (route_table->subnet_mask); ++ ++ /* SKIP Default GATEWAY */ ++ if (!u32_subnet && !u32_mask) ++ continue; ++ ++ if ((u32_address & u32_mask) == u32_subnet) ++ { ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (!inf->prefer_ip6) ++ { ++ grub_free (interface_info); ++ return inf; ++ } ++ } ++ } ++ ++ grub_free (interface_info); ++ return NULL; ++} ++ ++static int ++grub_efi_ip4_interface_set_manual_address (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_manual_address_t *net_ip, ++ int with_subnet) ++{ ++ grub_efi_status_t status; ++ grub_efi_ip4_config2_manual_address_t *address = &net_ip->ip4; ++ ++ if (!with_subnet) ++ { ++ grub_efi_ip4_config2_manual_address_t *manual_address = ++ efi_ip4_config_manual_address (dev->ip4_config); ++ ++ if (manual_address) ++ { ++ grub_memcpy (address->subnet_mask, manual_address->subnet_mask, sizeof(address->subnet_mask)); ++ grub_free (manual_address); ++ } ++ else ++ { ++ /* XXX: */ ++ address->subnet_mask[0] = 0xff; ++ address->subnet_mask[1] = 0xff; ++ address->subnet_mask[2] = 0xff; ++ address->subnet_mask[3] = 0; ++ } ++ } ++ ++ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, ++ sizeof(*address), address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ ++ return 1; ++} ++ ++static int ++grub_efi_ip4_interface_set_gateway (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_address_t *address) ++{ ++ grub_efi_status_t status; ++ ++ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_GATEWAY, ++ sizeof (address->ip4), &address->ip4); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ return 1; ++} ++ ++/* FIXME: Multiple DNS */ ++static int ++grub_efi_ip4_interface_set_dns (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_address_t *address) ++{ ++ grub_efi_status_t status; ++ ++ status = efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER, ++ sizeof (address->ip4), &address->ip4); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ return 1; ++} ++ ++grub_efi_net_ip_config_t *efi_net_ip4_config = &(grub_efi_net_ip_config_t) ++ { ++ .get_hw_address = grub_efi_ip4_interface_hw_address, ++ .get_address = grub_efi_ip4_interface_address, ++ .get_route_table = grub_efi_ip4_interface_route_table, ++ .best_interface = grub_efi_ip4_interface_match, ++ .set_address = grub_efi_ip4_interface_set_manual_address, ++ .set_gateway = grub_efi_ip4_interface_set_gateway, ++ .set_dns = grub_efi_ip4_interface_set_dns ++ }; +diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c +new file mode 100644 +index 00000000000..017c4d05bc7 +--- /dev/null ++++ b/grub-core/net/efi/ip6_config.c +@@ -0,0 +1,422 @@ ++#include ++#include ++#include ++#include ++#include ++ ++char * ++grub_efi_ip6_address_to_string (grub_efi_pxe_ipv6_address_t *address) ++{ ++ char *str = grub_malloc (sizeof ("XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX")); ++ char *p; ++ int i; ++ int squash; ++ ++ if (!str) ++ return NULL; ++ ++ p = str; ++ squash = 0; ++ for (i = 0; i < 8; ++i) ++ { ++ grub_uint16_t addr; ++ ++ if (i == 7) ++ squash = 2; ++ ++ addr = grub_get_unaligned16 (address->addr + i * 2); ++ ++ if (grub_be_to_cpu16 (addr)) ++ { ++ char buf[sizeof ("XXXX")]; ++ if (i > 0) ++ *p++ = ':'; ++ grub_snprintf (buf, sizeof (buf), "%x", grub_be_to_cpu16 (addr)); ++ grub_strcpy (p, buf); ++ p += grub_strlen (buf); ++ ++ if (squash == 1) ++ squash = 2; ++ } ++ else ++ { ++ if (squash == 0) ++ { ++ *p++ = ':'; ++ squash = 1; ++ } ++ else if (squash == 2) ++ { ++ *p++ = ':'; ++ *p++ = '0'; ++ } ++ } ++ } ++ *p = '\0'; ++ return str; ++} ++ ++int ++grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *address, const char **rest) ++{ ++ grub_uint16_t newip[8]; ++ const char *ptr = val; ++ int word, quaddot = -1; ++ int bracketed = 0; ++ ++ if (ptr[0] == '[') { ++ bracketed = 1; ++ ptr++; ++ } ++ ++ if (ptr[0] == ':' && ptr[1] != ':') ++ return 0; ++ if (ptr[0] == ':') ++ ptr++; ++ ++ for (word = 0; word < 8; word++) ++ { ++ unsigned long t; ++ if (*ptr == ':') ++ { ++ quaddot = word; ++ word--; ++ ptr++; ++ continue; ++ } ++ t = grub_strtoul (ptr, (char **) &ptr, 16); ++ if (grub_errno) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ break; ++ } ++ if (t & ~0xffff) ++ return 0; ++ newip[word] = grub_cpu_to_be16 (t); ++ if (*ptr != ':') ++ break; ++ ptr++; ++ } ++ if (quaddot == -1 && word < 7) ++ return 0; ++ if (quaddot != -1) ++ { ++ grub_memmove (&newip[quaddot + 7 - word], &newip[quaddot], ++ (word - quaddot + 1) * sizeof (newip[0])); ++ grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0])); ++ } ++ grub_memcpy (address, newip, 16); ++ if (bracketed && *ptr == ']') { ++ ptr++; ++ } ++ if (rest) ++ *rest = ptr; ++ return 1; ++} ++ ++static grub_efi_ip6_config_interface_info_t * ++efi_ip6_config_interface_info (grub_efi_ip6_config_protocol_t *ip6_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip6_config_interface_info_t *interface_info; ++ ++ sz = sizeof (*interface_info) + sizeof (*interface_info->route_table); ++ interface_info = grub_malloc (sz); ++ ++ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL) ++ { ++ grub_free (interface_info); ++ interface_info = grub_malloc (sz); ++ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, ++ &sz, interface_info); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (interface_info); ++ return NULL; ++ } ++ ++ return interface_info; ++} ++ ++static grub_efi_ip6_config_manual_address_t * ++efi_ip6_config_manual_address (grub_efi_ip6_config_protocol_t *ip6_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip6_config_manual_address_t *manual_address; ++ ++ sz = sizeof (*manual_address); ++ manual_address = grub_malloc (sz); ++ if (!manual_address) ++ return NULL; ++ ++ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, manual_address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (manual_address); ++ return NULL; ++ } ++ ++ return manual_address; ++} ++ ++char * ++grub_efi_ip6_interface_name (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip6_config_interface_info_t *interface_info; ++ char *name; ++ ++ interface_info = efi_ip6_config_interface_info (dev->ip6_config); ++ ++ if (!interface_info) ++ return NULL; ++ ++ name = grub_malloc (GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE ++ * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ *grub_utf16_to_utf8 ((grub_uint8_t *)name, interface_info->name, ++ GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE) = 0; ++ grub_free (interface_info); ++ return name; ++} ++ ++static char * ++grub_efi_ip6_interface_hw_address (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip6_config_interface_info_t *interface_info; ++ char *hw_addr; ++ ++ interface_info = efi_ip6_config_interface_info (dev->ip6_config); ++ ++ if (!interface_info) ++ return NULL; ++ ++ hw_addr = grub_efi_hw_address_to_string (interface_info->hw_address_size, interface_info->hw_address); ++ grub_free (interface_info); ++ ++ return hw_addr; ++} ++ ++static char * ++grub_efi_ip6_interface_address (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip6_config_manual_address_t *manual_address; ++ char *addr; ++ ++ manual_address = efi_ip6_config_manual_address (dev->ip6_config); ++ ++ if (!manual_address) ++ return NULL; ++ ++ addr = grub_efi_ip6_address_to_string ((grub_efi_pxe_ipv6_address_t *)&manual_address->address); ++ grub_free (manual_address); ++ return addr; ++} ++ ++static char ** ++grub_efi_ip6_interface_route_table (struct grub_efi_net_device *dev) ++{ ++ grub_efi_ip6_config_interface_info_t *interface_info; ++ char **ret; ++ int i, id; ++ ++ interface_info = efi_ip6_config_interface_info (dev->ip6_config); ++ if (!interface_info) ++ return NULL; ++ ++ ret = grub_malloc (sizeof (*ret) * (interface_info->route_count + 1)); ++ ++ if (!ret) ++ { ++ grub_free (interface_info); ++ return NULL; ++ } ++ ++ id = 0; ++ for (i = 0; i < (int)interface_info->route_count ; i++) ++ { ++ char *gateway, *destination; ++ grub_uint64_t u64_gateway[2]; ++ grub_uint64_t u64_destination[2]; ++ grub_efi_ip6_route_table_t *route_table = interface_info->route_table + i; ++ grub_efi_net_interface_t *inf; ++ char *interface_name = NULL; ++ ++ gateway = grub_efi_ip6_address_to_string (&route_table->gateway); ++ destination = grub_efi_ip6_address_to_string (&route_table->destination); ++ ++ u64_gateway[0] = grub_get_unaligned64 (route_table->gateway.addr); ++ u64_gateway[1] = grub_get_unaligned64 (route_table->gateway.addr + 8); ++ u64_destination[0] = grub_get_unaligned64 (route_table->destination.addr); ++ u64_destination[1] = grub_get_unaligned64 (route_table->destination.addr + 8); ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (inf->prefer_ip6) ++ interface_name = inf->name; ++ ++ if ((!u64_gateway[0] && !u64_gateway[1]) ++ && (u64_destination[0] || u64_destination[1])) ++ { ++ if (interface_name) ++ { ++ if ((grub_be_to_cpu64 (u64_destination[0]) == 0xfe80000000000000ULL) ++ && (!u64_destination[1]) ++ && (route_table->prefix_length == 64)) ++ ret[id++] = grub_xasprintf ("%s:link %s/%d %s", dev->card_name, destination, route_table->prefix_length, interface_name); ++ else ++ ret[id++] = grub_xasprintf ("%s:local %s/%d %s", dev->card_name, destination, route_table->prefix_length, interface_name); ++ } ++ } ++ else if ((u64_gateway[0] || u64_gateway[1]) ++ && (u64_destination[0] || u64_destination[1])) ++ ret[id++] = grub_xasprintf ("%s:gw %s/%d gw %s", dev->card_name, destination, route_table->prefix_length, gateway); ++ else if ((u64_gateway[0] || u64_gateway[1]) ++ && (!u64_destination[0] && !u64_destination[1])) ++ ret[id++] = grub_xasprintf ("%s:default %s/%d gw %s", dev->card_name, destination, route_table->prefix_length, gateway); ++ ++ grub_free (gateway); ++ grub_free (destination); ++ } ++ ++ ret[id] = NULL; ++ grub_free (interface_info); ++ return ret; ++} ++ ++static grub_efi_net_interface_t * ++grub_efi_ip6_interface_match (struct grub_efi_net_device *dev, grub_efi_net_ip_address_t *ip_address) ++{ ++ grub_efi_ip6_config_interface_info_t *interface_info; ++ grub_efi_net_interface_t *inf; ++ int i; ++ grub_efi_ipv6_address_t *address = &ip_address->ip6; ++ ++ interface_info = efi_ip6_config_interface_info (dev->ip6_config); ++ if (!interface_info) ++ return NULL; ++ ++ for (i = 0; i < (int)interface_info->route_count ; i++) ++ { ++ grub_uint64_t u64_addr[2]; ++ grub_uint64_t u64_subnet[2]; ++ grub_uint64_t u64_mask[2]; ++ ++ grub_efi_ip6_route_table_t *route_table = interface_info->route_table + i; ++ ++ /* SKIP Default GATEWAY */ ++ if (route_table->prefix_length == 0) ++ continue; ++ ++ u64_addr[0] = grub_get_unaligned64 (address); ++ u64_addr[1] = grub_get_unaligned64 (address + 4); ++ u64_subnet[0] = grub_get_unaligned64 (route_table->destination.addr); ++ u64_subnet[1] = grub_get_unaligned64 (route_table->destination.addr + 8); ++ u64_mask[0] = (route_table->prefix_length <= 64) ? ++ 0xffffffffffffffffULL << (64 - route_table->prefix_length) : ++ 0xffffffffffffffffULL; ++ u64_mask[1] = (route_table->prefix_length <= 64) ? ++ 0 : ++ 0xffffffffffffffffULL << (128 - route_table->prefix_length); ++ ++ if (((u64_addr[0] & u64_mask[0]) == u64_subnet[0]) ++ && ((u64_addr[1] & u64_mask[1]) == u64_subnet[1])) ++ { ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (inf->prefer_ip6) ++ { ++ grub_free (interface_info); ++ return inf; ++ } ++ } ++ } ++ ++ grub_free (interface_info); ++ return NULL; ++} ++ ++static int ++grub_efi_ip6_interface_set_manual_address (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_manual_address_t *net_ip, ++ int with_subnet) ++{ ++ grub_efi_status_t status; ++ grub_efi_ip6_config_manual_address_t *address = &net_ip->ip6; ++ ++ if (!with_subnet) ++ { ++ grub_efi_ip6_config_manual_address_t *manual_address = ++ efi_ip6_config_manual_address (dev->ip6_config); ++ ++ if (manual_address) ++ { ++ address->prefix_length = manual_address->prefix_length; ++ grub_free (manual_address); ++ } ++ else ++ { ++ /* XXX: */ ++ address->prefix_length = 64; ++ } ++ } ++ ++ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ sizeof(*address), address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ ++ return 1; ++} ++ ++static int ++grub_efi_ip6_interface_set_gateway (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_address_t *address) ++{ ++ grub_efi_status_t status; ++ ++ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_GATEWAY, ++ sizeof (address->ip6), &address->ip6); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ return 1; ++} ++ ++static int ++grub_efi_ip6_interface_set_dns (struct grub_efi_net_device *dev, ++ grub_efi_net_ip_address_t *address) ++{ ++ ++ grub_efi_status_t status; ++ ++ status = efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER, ++ sizeof (address->ip6), &address->ip6); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ return 1; ++} ++ ++grub_efi_net_ip_config_t *efi_net_ip6_config = &(grub_efi_net_ip_config_t) ++ { ++ .get_hw_address = grub_efi_ip6_interface_hw_address, ++ .get_address = grub_efi_ip6_interface_address, ++ .get_route_table = grub_efi_ip6_interface_route_table, ++ .best_interface = grub_efi_ip6_interface_match, ++ .set_address = grub_efi_ip6_interface_set_manual_address, ++ .set_gateway = grub_efi_ip6_interface_set_gateway, ++ .set_dns = grub_efi_ip6_interface_set_dns ++ }; +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +new file mode 100644 +index 00000000000..86bce6535d3 +--- /dev/null ++++ b/grub-core/net/efi/net.c +@@ -0,0 +1,1428 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++#define GRUB_EFI_IP6_PREFIX_LENGTH 64 ++ ++static grub_efi_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID; ++static grub_efi_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID; ++static grub_efi_guid_t http_service_binding_guid = GRUB_EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_efi_guid_t http_guid = GRUB_EFI_HTTP_PROTOCOL_GUID; ++static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID; ++static grub_efi_guid_t dhcp4_service_binding_guid = GRUB_EFI_DHCP4_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_efi_guid_t dhcp4_guid = GRUB_EFI_DHCP4_PROTOCOL_GUID; ++static grub_efi_guid_t dhcp6_service_binding_guid = GRUB_EFI_DHCP6_SERVICE_BINDING_PROTOCOL_GUID; ++static grub_efi_guid_t dhcp6_guid = GRUB_EFI_DHCP6_PROTOCOL_GUID; ++ ++struct grub_efi_net_device *net_devices; ++ ++static char *default_server; ++static grub_efi_net_interface_t *net_interface; ++static grub_efi_net_interface_t *net_default_interface; ++ ++#define efi_net_interface_configure(inf) inf->io->configure (inf->dev, inf->prefer_ip6) ++#define efi_net_interface_open(inf, file, name) inf->io->open (inf->dev, inf->prefer_ip6, file, name, inf->io_type) ++#define efi_net_interface_read(inf, file, buf, sz) inf->io->read (inf->dev, inf->prefer_ip6, file, buf, sz) ++#define efi_net_interface_close(inf, file) inf->io->close (inf->dev, inf->prefer_ip6, file) ++#define efi_net_interface(m,...) efi_net_interface_ ## m (net_interface, ## __VA_ARGS__) ++ ++static grub_efi_handle_t ++grub_efi_locate_device_path (grub_efi_guid_t *protocol, grub_efi_device_path_t *device_path, ++ grub_efi_device_path_t **r_device_path) ++{ ++ grub_efi_handle_t handle; ++ grub_efi_status_t status; ++ ++ status = efi_call_3 (grub_efi_system_table->boot_services->locate_device_path, ++ protocol, &device_path, &handle); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return 0; ++ ++ if (r_device_path) ++ *r_device_path = device_path; ++ ++ return handle; ++} ++ ++static int ++url_parse_fields (const char *url, char **proto, char **host, char **path) ++{ ++ const char *p, *ps; ++ grub_size_t l; ++ ++ *proto = *host = *path = NULL; ++ ps = p = url; ++ ++ while ((p = grub_strchr (p, ':'))) ++ { ++ if (grub_strlen (p) < sizeof ("://") - 1) ++ break; ++ if (grub_memcmp (p, "://", sizeof ("://") - 1) == 0) ++ { ++ l = p - ps; ++ *proto = grub_malloc (l + 1); ++ if (!*proto) ++ { ++ grub_print_error (); ++ return 0; ++ } ++ ++ grub_memcpy (*proto, ps, l); ++ (*proto)[l] = '\0'; ++ p += sizeof ("://") - 1; ++ break; ++ } ++ ++p; ++ } ++ ++ if (!*proto) ++ { ++ grub_dprintf ("bootp", "url: %s is not valid, protocol not found\n", url); ++ return 0; ++ } ++ ++ ps = p; ++ p = grub_strchr (p, '/'); ++ ++ if (!p) ++ { ++ grub_dprintf ("bootp", "url: %s is not valid, host/path not found\n", url); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ ++ l = p - ps; ++ ++ if (l > 2 && ps[0] == '[' && ps[l - 1] == ']') ++ { ++ *host = grub_malloc (l - 1); ++ if (!*host) ++ { ++ grub_print_error (); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ grub_memcpy (*host, ps + 1, l - 2); ++ (*host)[l - 2] = 0; ++ } ++ else ++ { ++ *host = grub_malloc (l + 1); ++ if (!*host) ++ { ++ grub_print_error (); ++ grub_free (*proto); ++ *proto = NULL; ++ return 0; ++ } ++ grub_memcpy (*host, ps, l); ++ (*host)[l] = 0; ++ } ++ ++ *path = grub_strdup (p); ++ if (!*path) ++ { ++ grub_print_error (); ++ grub_free (*host); ++ grub_free (*proto); ++ *host = NULL; ++ *proto = NULL; ++ return 0; ++ } ++ return 1; ++} ++ ++static void ++url_get_boot_location (const char *url, char **device, char **path, int is_default) ++{ ++ char *protocol, *server, *file; ++ char *slash; ++ ++ if (!url_parse_fields (url, &protocol, &server, &file)) ++ return; ++ ++ if ((slash = grub_strrchr (file, '/'))) ++ *slash = 0; ++ else ++ *file = 0; ++ ++ *device = grub_xasprintf ("%s,%s", protocol, server); ++ *path = grub_strdup(file); ++ ++ if (is_default) ++ default_server = server; ++ else ++ grub_free (server); ++ ++ grub_free (protocol); ++ grub_free (file); ++} ++ ++static void ++pxe_get_boot_location (const struct grub_net_bootp_packet *bp, ++ char **device, ++ char **path, ++ int is_default) ++{ ++ char *server = grub_xasprintf ("%d.%d.%d.%d", ++ ((grub_uint8_t *) &bp->server_ip)[0], ++ ((grub_uint8_t *) &bp->server_ip)[1], ++ ((grub_uint8_t *) &bp->server_ip)[2], ++ ((grub_uint8_t *) &bp->server_ip)[3]); ++ ++ *device = grub_xasprintf ("tftp,%s", server); ++ ++ *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file)); ++ ++ if (*path) ++ { ++ char *slash; ++ slash = grub_strrchr (*path, '/'); ++ if (slash) ++ *slash = 0; ++ else ++ **path = 0; ++ } ++ ++ if (is_default) ++ default_server = server; ++ else ++ grub_free (server); ++} ++ ++static void ++pxe_get_boot_location_v6 (const struct grub_net_dhcp6_packet *dp, ++ grub_size_t dhcp_size, ++ char **device, ++ char **path) ++{ ++ ++ struct grub_net_dhcp6_option *dhcp_opt; ++ grub_size_t dhcp_remain_size; ++ *device = *path = 0; ++ ++ if (dhcp_size < sizeof (*dp)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("DHCPv6 packet size too small")); ++ return; ++ } ++ ++ dhcp_remain_size = dhcp_size - sizeof (*dp); ++ dhcp_opt = (struct grub_net_dhcp6_option *)dp->dhcp_options; ++ ++ while (dhcp_remain_size) ++ { ++ grub_uint16_t code = grub_be_to_cpu16 (dhcp_opt->code); ++ grub_uint16_t len = grub_be_to_cpu16 (dhcp_opt->len); ++ grub_uint16_t option_size = sizeof (*dhcp_opt) + len; ++ ++ if (dhcp_remain_size < option_size || code == 0) ++ break; ++ ++ if (code == GRUB_NET_DHCP6_OPTION_BOOTFILE_URL) ++ { ++ char *url = grub_malloc (len + 1); ++ ++ grub_memcpy (url, dhcp_opt->data, len); ++ url[len] = 0; ++ ++ url_get_boot_location ((const char *)url, device, path, 1); ++ grub_free (url); ++ break; ++ } ++ ++ dhcp_remain_size -= option_size; ++ dhcp_opt = (struct grub_net_dhcp6_option *)((grub_uint8_t *)dhcp_opt + option_size); ++ } ++} ++ ++static grub_efi_net_interface_t * ++grub_efi_net_config_from_device_path (grub_efi_device_path_t *dp, ++ struct grub_efi_net_device *netdev, ++ char **device, ++ char **path) ++{ ++ grub_efi_net_interface_t *inf = NULL; ++ ++ while (1) ++ { ++ grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); ++ grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); ++ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ ++ if (type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE) ++ { ++ if (subtype == GRUB_EFI_URI_DEVICE_PATH_SUBTYPE) ++ { ++ grub_efi_uri_device_path_t *uri_dp; ++ uri_dp = (grub_efi_uri_device_path_t *) dp; ++ /* Beware that uri_dp->uri may not be null terminated */ ++ url_get_boot_location ((const char *)uri_dp->uri, device, path, 1); ++ } ++ else if (subtype == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE) ++ { ++ grub_efi_net_ip_manual_address_t net_ip; ++ grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) dp; ++ ++ if (inf) ++ continue; ++ grub_memcpy (net_ip.ip4.address, ipv4->local_ip_address, sizeof (net_ip.ip4.address)); ++ grub_memcpy (net_ip.ip4.subnet_mask, ipv4->subnet_mask, sizeof (net_ip.ip4.subnet_mask)); ++ net_ip.is_ip6 = 0; ++ inf = grub_efi_net_create_interface (netdev, ++ netdev->card_name, ++ &net_ip, ++ 1); ++ } ++ else if (subtype == GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) ++ { ++ grub_efi_net_ip_manual_address_t net_ip; ++ grub_efi_ipv6_device_path_t *ipv6 = (grub_efi_ipv6_device_path_t *) dp; ++ ++ if (inf) ++ continue; ++ grub_memcpy (net_ip.ip6.address, ipv6->local_ip_address, sizeof (net_ip.ip6.address)); ++ net_ip.ip6.prefix_length = GRUB_EFI_IP6_PREFIX_LENGTH; ++ net_ip.ip6.is_anycast = 0; ++ net_ip.is_ip6 = 1; ++ inf = grub_efi_net_create_interface (netdev, ++ netdev->card_name, ++ &net_ip, ++ 1); ++ } ++ } ++ ++ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) ++ break; ++ dp = (grub_efi_device_path_t *) ((char *) dp + len); ++ } ++ ++ return inf; ++} ++ ++static grub_efi_net_interface_t * ++grub_efi_net_config_from_handle (grub_efi_handle_t *hnd, ++ struct grub_efi_net_device *netdev, ++ char **device, ++ char **path) ++{ ++ grub_efi_pxe_t *pxe = NULL; ++ ++ if (hnd == netdev->ip4_pxe_handle) ++ pxe = netdev->ip4_pxe; ++ else if (hnd == netdev->ip6_pxe_handle) ++ pxe = netdev->ip6_pxe; ++ ++ if (!pxe) ++ return (grub_efi_net_config_from_device_path ( ++ grub_efi_get_device_path (hnd), ++ netdev, ++ device, ++ path)); ++ ++ if (pxe->mode->using_ipv6) ++ { ++ grub_efi_net_ip_manual_address_t net_ip; ++ ++ pxe_get_boot_location_v6 ( ++ (const struct grub_net_dhcp6_packet *) &pxe->mode->dhcp_ack, ++ sizeof (pxe->mode->dhcp_ack), ++ device, ++ path); ++ ++ grub_memcpy (net_ip.ip6.address, pxe->mode->station_ip.v6, sizeof(net_ip.ip6.address)); ++ net_ip.ip6.prefix_length = GRUB_EFI_IP6_PREFIX_LENGTH; ++ net_ip.ip6.is_anycast = 0; ++ net_ip.is_ip6 = 1; ++ return (grub_efi_net_create_interface (netdev, ++ netdev->card_name, ++ &net_ip, ++ 1)); ++ } ++ else ++ { ++ grub_efi_net_ip_manual_address_t net_ip; ++ ++ pxe_get_boot_location ( ++ (const struct grub_net_bootp_packet *) &pxe->mode->dhcp_ack, ++ device, ++ path, ++ 1); ++ ++ grub_memcpy (net_ip.ip4.address, pxe->mode->station_ip.v4, sizeof (net_ip.ip4.address)); ++ grub_memcpy (net_ip.ip4.subnet_mask, pxe->mode->subnet_mask.v4, sizeof (net_ip.ip4.subnet_mask)); ++ net_ip.is_ip6 = 0; ++ return (grub_efi_net_create_interface (netdev, ++ netdev->card_name, ++ &net_ip, ++ 1)); ++ } ++} ++ ++static const char * ++grub_efi_net_var_get_address (struct grub_env_var *var, ++ const char *val __attribute__ ((unused))) ++{ ++ struct grub_efi_net_device *dev; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ grub_efi_net_interface_t *inf; ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ { ++ char *var_name; ++ ++ var_name = grub_xasprintf ("net_%s_ip", inf->name); ++ if (grub_strcmp (var_name, var->name) == 0) ++ return efi_net_interface_get_address (inf); ++ grub_free (var_name); ++ var_name = grub_xasprintf ("net_%s_mac", inf->name); ++ if (grub_strcmp (var_name, var->name) == 0) ++ return efi_net_interface_get_hw_address (inf); ++ grub_free (var_name); ++ } ++ } ++ ++ return NULL; ++} ++ ++static char * ++grub_efi_net_var_set_interface (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val) ++{ ++ struct grub_efi_net_device *dev; ++ grub_efi_net_interface_t *inf; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ if (grub_strcmp (inf->name, val) == 0) ++ { ++ net_default_interface = inf; ++ return grub_strdup (val); ++ } ++ ++ return NULL; ++} ++ ++static char * ++grub_efi_net_var_set_server (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val) ++{ ++ grub_free (default_server); ++ default_server = grub_strdup (val); ++ return grub_strdup (val); ++} ++ ++static const char * ++grub_efi_net_var_get_server (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ return default_server ? : ""; ++} ++ ++static const char * ++grub_efi_net_var_get_ip (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ const char *intf = grub_env_get ("net_default_interface"); ++ const char *ret = NULL; ++ if (intf) ++ { ++ char *buf = grub_xasprintf ("net_%s_ip", intf); ++ if (buf) ++ ret = grub_env_get (buf); ++ grub_free (buf); ++ } ++ return ret; ++} ++ ++static const char * ++grub_efi_net_var_get_mac (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ const char *intf = grub_env_get ("net_default_interface"); ++ const char *ret = NULL; ++ if (intf) ++ { ++ char *buf = grub_xasprintf ("net_%s_mac", intf); ++ if (buf) ++ ret = grub_env_get (buf); ++ grub_free (buf); ++ } ++ return ret; ++} ++ ++static void ++grub_efi_net_export_interface_vars (void) ++{ ++ struct grub_efi_net_device *dev; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ grub_efi_net_interface_t *inf; ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ { ++ char *var; ++ ++ var = grub_xasprintf ("net_%s_ip", inf->name); ++ grub_register_variable_hook (var, grub_efi_net_var_get_address, 0); ++ grub_env_export (var); ++ grub_free (var); ++ var = grub_xasprintf ("net_%s_mac", inf->name); ++ grub_register_variable_hook (var, grub_efi_net_var_get_address, 0); ++ grub_env_export (var); ++ grub_free (var); ++ } ++ } ++} ++ ++static void ++grub_efi_net_unset_interface_vars (void) ++{ ++ struct grub_efi_net_device *dev; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ grub_efi_net_interface_t *inf; ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ { ++ char *var; ++ ++ var = grub_xasprintf ("net_%s_ip", inf->name); ++ grub_register_variable_hook (var, 0, 0); ++ grub_env_unset (var); ++ grub_free (var); ++ var = grub_xasprintf ("net_%s_mac", inf->name); ++ grub_register_variable_hook (var, 0, 0); ++ grub_env_unset (var); ++ grub_free (var); ++ } ++ } ++} ++ ++grub_efi_net_interface_t * ++grub_efi_net_create_interface (struct grub_efi_net_device *dev, ++ const char *interface_name, ++ grub_efi_net_ip_manual_address_t *net_ip, ++ int has_subnet) ++{ ++ grub_efi_net_interface_t *inf; ++ ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ { ++ if (inf->prefer_ip6 == net_ip->is_ip6) ++ break; ++ } ++ ++ if (!inf) ++ { ++ inf = grub_malloc (sizeof(*inf)); ++ inf->name = grub_strdup (interface_name); ++ inf->prefer_ip6 = net_ip->is_ip6; ++ inf->dev = dev; ++ inf->next = dev->net_interfaces; ++ inf->ip_config = (net_ip->is_ip6) ? efi_net_ip6_config : efi_net_ip4_config ; ++ dev->net_interfaces = inf; ++ } ++ else ++ { ++ grub_free (inf->name); ++ inf->name = grub_strdup (interface_name); ++ } ++ ++ if (!efi_net_interface_set_address (inf, net_ip, has_subnet)) ++ { ++ grub_error (GRUB_ERR_BUG, N_("Set Address Failed")); ++ return NULL; ++ } ++ ++ return inf; ++} ++ ++static void ++grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, ++ char **path) ++{ ++ grub_efi_handle_t config_hnd; ++ ++ struct grub_efi_net_device *netdev; ++ grub_efi_net_interface_t *inf; ++ ++ config_hnd = grub_efi_locate_device_path (&ip4_config_guid, grub_efi_get_device_path (hnd), NULL); ++ ++ if (!config_hnd) ++ return; ++ ++ for (netdev = net_devices; netdev; netdev = netdev->next) ++ if (netdev->handle == config_hnd) ++ break; ++ ++ if (!netdev) ++ return; ++ ++ if (!(inf = grub_efi_net_config_from_handle (hnd, netdev, device, path))) ++ return; ++ ++ grub_env_set ("net_default_interface", inf->name); ++ grub_efi_net_export_interface_vars (); ++} ++ ++static grub_err_t ++grub_efi_netfs_dir (grub_device_t device, const char *path __attribute__ ((unused)), ++ grub_fs_dir_hook_t hook __attribute__ ((unused)), ++ void *hook_data __attribute__ ((unused))) ++{ ++ if (!device->net) ++ return grub_error (GRUB_ERR_BUG, "invalid net device"); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_efi_netfs_open (struct grub_file *file_out __attribute__ ((unused)), ++ const char *name __attribute__ ((unused))) ++{ ++ struct grub_file *file, *bufio; ++ ++ file = grub_malloc (sizeof (*file)); ++ if (!file) ++ return grub_errno; ++ ++ grub_memcpy (file, file_out, sizeof (struct grub_file)); ++ file->device->net->name = grub_strdup (name); ++ ++ if (!file->device->net->name) ++ { ++ grub_free (file); ++ return grub_errno; ++ } ++ ++ efi_net_interface(open, file, name); ++ grub_print_error (); ++ ++ bufio = grub_bufio_open (file, 32768); ++ if (!bufio) ++ { ++ grub_free (file->device->net->name); ++ grub_free (file); ++ return grub_errno; ++ } ++ grub_memcpy (file_out, bufio, sizeof (struct grub_file)); ++ grub_free (bufio); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_ssize_t ++grub_efihttp_chunk_read (grub_file_t file, char *buf, ++ grub_size_t len, grub_size_t chunk_size) ++{ ++ char *chunk = grub_malloc (chunk_size); ++ grub_size_t sum = 0; ++ ++ while (len) ++ { ++ grub_ssize_t rd; ++ grub_size_t sz = (len > chunk_size) ? chunk_size : len; ++ ++ rd = efi_net_interface (read, file, chunk, sz); ++ ++ if (rd <= 0) ++ return rd; ++ ++ if (buf) ++ { ++ grub_memcpy (buf, chunk, rd); ++ buf += rd; ++ } ++ sum += rd; ++ len -= rd; ++ } ++ ++ grub_free (chunk); ++ return sum; ++} ++ ++static grub_ssize_t ++grub_efi_netfs_read (grub_file_t file __attribute__ ((unused)), ++ char *buf __attribute__ ((unused)), grub_size_t len __attribute__ ((unused))) ++{ ++ if (file->offset > file->device->net->offset) ++ { ++ grub_efihttp_chunk_read (file, NULL, file->offset - file->device->net->offset, 10240); ++ } ++ else if (file->offset < file->device->net->offset) ++ { ++ efi_net_interface (close, file); ++ efi_net_interface (open, file, file->device->net->name); ++ if (file->offset) ++ grub_efihttp_chunk_read (file, NULL, file->offset, 10240); ++ } ++ ++ return efi_net_interface (read, file, buf, len); ++} ++ ++static grub_err_t ++grub_efi_netfs_close (grub_file_t file) ++{ ++ efi_net_interface (close, file); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_efi_handle_t ++grub_efi_service_binding (grub_efi_handle_t dev, grub_efi_guid_t *service_binding_guid) ++{ ++ grub_efi_service_binding_t *service; ++ grub_efi_status_t status; ++ grub_efi_handle_t child_dev = NULL; ++ ++ service = grub_efi_open_protocol (dev, service_binding_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ if (!service) ++ { ++ grub_error (GRUB_ERR_IO, N_("couldn't open efi service binding protocol")); ++ return NULL; ++ } ++ ++ status = efi_call_2 (service->create_child, service, &child_dev); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_error (GRUB_ERR_IO, N_("Failed to create child device of http service %x"), status); ++ return NULL; ++ } ++ ++ return child_dev; ++} ++ ++static grub_err_t ++grub_efi_net_parse_address (const char *address, ++ grub_efi_ip4_config2_manual_address_t *ip4, ++ grub_efi_ip6_config_manual_address_t *ip6, ++ int *is_ip6, ++ int *has_cidr) ++{ ++ const char *rest; ++ ++ if (grub_efi_string_to_ip4_address (address, &ip4->address, &rest)) ++ { ++ *is_ip6 = 0; ++ if (*rest == '/') ++ { ++ grub_uint32_t subnet_mask_size; ++ ++ subnet_mask_size = grub_strtoul (rest + 1, (char **) &rest, 0); ++ ++ if (!grub_errno && subnet_mask_size <= 32 && *rest == 0) ++ { ++ grub_uint32_t subnet_mask; ++ ++ subnet_mask = grub_cpu_to_be32 ((0xffffffffU << (32 - subnet_mask_size))); ++ grub_memcpy (ip4->subnet_mask, &subnet_mask, sizeof (ip4->subnet_mask)); ++ if (has_cidr) ++ *has_cidr = 1; ++ return GRUB_ERR_NONE; ++ } ++ } ++ else if (*rest == 0) ++ { ++ grub_uint32_t subnet_mask = 0xffffffffU; ++ grub_memcpy (ip4->subnet_mask, &subnet_mask, sizeof (ip4->subnet_mask)); ++ if (has_cidr) ++ *has_cidr = 0; ++ return GRUB_ERR_NONE; ++ } ++ } ++ else if (grub_efi_string_to_ip6_address (address, &ip6->address, &rest)) ++ { ++ *is_ip6 = 1; ++ if (*rest == '/') ++ { ++ grub_efi_uint8_t prefix_length; ++ ++ prefix_length = grub_strtoul (rest + 1, (char **) &rest, 0); ++ if (!grub_errno && prefix_length <= 128 && *rest == 0) ++ { ++ ip6->prefix_length = prefix_length; ++ ip6->is_anycast = 0; ++ if (has_cidr) ++ *has_cidr = 1; ++ return GRUB_ERR_NONE; ++ } ++ } ++ else if (*rest == 0) ++ { ++ ip6->prefix_length = 128; ++ ip6->is_anycast = 0; ++ if (has_cidr) ++ *has_cidr = 0; ++ return GRUB_ERR_NONE; ++ } ++ } ++ ++ return grub_error (GRUB_ERR_NET_BAD_ADDRESS, ++ N_("unrecognised network address `%s'"), ++ address); ++} ++ ++static grub_efi_net_interface_t * ++match_route (const char *server) ++{ ++ grub_err_t err; ++ grub_efi_ip4_config2_manual_address_t ip4; ++ grub_efi_ip6_config_manual_address_t ip6; ++ grub_efi_net_interface_t *inf; ++ int is_ip6 = 0; ++ ++ err = grub_efi_net_parse_address (server, &ip4, &ip6, &is_ip6, 0); ++ ++ if (err) ++ { ++ grub_print_error (); ++ return NULL; ++ } ++ ++ if (is_ip6) ++ { ++ struct grub_efi_net_device *dev; ++ grub_efi_net_ip_address_t addr; ++ ++ grub_memcpy (addr.ip6, ip6.address, sizeof(ip6.address)); ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ if ((inf = efi_net_ip6_config->best_interface (dev, &addr))) ++ return inf; ++ } ++ else ++ { ++ struct grub_efi_net_device *dev; ++ grub_efi_net_ip_address_t addr; ++ ++ grub_memcpy (addr.ip4, ip4.address, sizeof(ip4.address)); ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ if ((inf = efi_net_ip4_config->best_interface (dev, &addr))) ++ return inf; ++ } ++ ++ return 0; ++} ++ ++static void ++grub_efi_net_add_pxebc_to_cards (void) ++{ ++ grub_efi_uintn_t num_handles; ++ grub_efi_handle_t *handles; ++ grub_efi_handle_t *handle; ++ ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &pxe_io_guid, ++ 0, &num_handles); ++ if (!handles) ++ return; ++ ++ for (handle = handles; num_handles--; handle++) ++ { ++ grub_efi_device_path_t *dp, *ddp, *ldp; ++ grub_efi_pxe_t *pxe; ++ struct grub_efi_net_device *d; ++ int is_ip6 = 0; ++ ++ dp = grub_efi_get_device_path (*handle); ++ if (!dp) ++ continue; ++ ++ ddp = grub_efi_duplicate_device_path (dp); ++ ldp = grub_efi_find_last_device_path (ddp); ++ ++ if (ldp->type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE ++ && ldp->subtype == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE) ++ { ++ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ ldp->length = sizeof (*ldp); ++ } ++ else if (ldp->type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE ++ && ldp->subtype == GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) ++ { ++ is_ip6 = 1; ++ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ ldp->length = sizeof (*ldp); ++ } ++ ++ for (d = net_devices; d; d = d->next) ++ if (grub_efi_compare_device_paths (ddp, grub_efi_get_device_path (d->handle)) == 0) ++ break; ++ ++ if (!d) ++ { ++ grub_free (ddp); ++ continue; ++ } ++ ++ pxe = grub_efi_open_protocol (*handle, &pxe_io_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!pxe) ++ { ++ grub_free (ddp); ++ continue; ++ } ++ ++ if (is_ip6) ++ { ++ d->ip6_pxe_handle = *handle; ++ d->ip6_pxe = pxe; ++ } ++ else ++ { ++ d->ip4_pxe_handle = *handle; ++ d->ip4_pxe = pxe; ++ } ++ ++ grub_free (ddp); ++ } ++ ++ grub_free (handles); ++} ++ ++static void ++set_ip_policy_to_static (void) ++{ ++ struct grub_efi_net_device *dev; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ grub_efi_ip4_config2_policy_t ip4_policy = GRUB_EFI_IP4_CONFIG2_POLICY_STATIC; ++ ++ if (efi_call_4 (dev->ip4_config->set_data, dev->ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_POLICY, ++ sizeof (ip4_policy), &ip4_policy) != GRUB_EFI_SUCCESS) ++ grub_dprintf ("efinetfs", "could not set GRUB_EFI_IP4_CONFIG2_POLICY_STATIC on dev `%s'", dev->card_name); ++ ++ if (dev->ip6_config) ++ { ++ grub_efi_ip6_config_policy_t ip6_policy = GRUB_EFI_IP6_CONFIG_POLICY_MANUAL; ++ ++ if (efi_call_4 (dev->ip6_config->set_data, dev->ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_POLICY, ++ sizeof (ip6_policy), &ip6_policy) != GRUB_EFI_SUCCESS) ++ grub_dprintf ("efinetfs", "could not set GRUB_EFI_IP6_CONFIG_POLICY_MANUAL on dev `%s'", dev->card_name); ++ } ++ } ++} ++ ++/* FIXME: Do not fail if the card did not support any of the protocol (Eg http) */ ++static void ++grub_efi_net_find_cards (void) ++{ ++ grub_efi_uintn_t num_handles; ++ grub_efi_handle_t *handles; ++ grub_efi_handle_t *handle; ++ int id; ++ ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &ip4_config_guid, ++ 0, &num_handles); ++ if (!handles) ++ return; ++ ++ for (id = 0, handle = handles; num_handles--; handle++, id++) ++ { ++ grub_efi_device_path_t *dp; ++ grub_efi_ip4_config2_protocol_t *ip4_config; ++ grub_efi_ip6_config_protocol_t *ip6_config; ++ grub_efi_handle_t http_handle; ++ grub_efi_http_t *http; ++ grub_efi_handle_t dhcp4_handle; ++ grub_efi_dhcp4_protocol_t *dhcp4; ++ grub_efi_handle_t dhcp6_handle; ++ grub_efi_dhcp6_protocol_t *dhcp6; ++ ++ struct grub_efi_net_device *d; ++ ++ dp = grub_efi_get_device_path (*handle); ++ if (!dp) ++ continue; ++ ++ ip4_config = grub_efi_open_protocol (*handle, &ip4_config_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ if (!ip4_config) ++ continue; ++ ++ ip6_config = grub_efi_open_protocol (*handle, &ip6_config_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ http_handle = grub_efi_service_binding (*handle, &http_service_binding_guid); ++ grub_errno = GRUB_ERR_NONE; ++ http = (http_handle) ++ ? grub_efi_open_protocol (http_handle, &http_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL) ++ : NULL; ++ ++ dhcp4_handle = grub_efi_service_binding (*handle, &dhcp4_service_binding_guid); ++ grub_errno = GRUB_ERR_NONE; ++ dhcp4 = (dhcp4_handle) ++ ? grub_efi_open_protocol (dhcp4_handle, &dhcp4_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL) ++ : NULL; ++ ++ ++ dhcp6_handle = grub_efi_service_binding (*handle, &dhcp6_service_binding_guid); ++ grub_errno = GRUB_ERR_NONE; ++ dhcp6 = (dhcp6_handle) ++ ? grub_efi_open_protocol (dhcp6_handle, &dhcp6_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL) ++ : NULL; ++ ++ d = grub_malloc (sizeof (*d)); ++ if (!d) ++ { ++ grub_free (handles); ++ while (net_devices) ++ { ++ d = net_devices->next; ++ grub_free (net_devices); ++ net_devices = d; ++ } ++ return; ++ } ++ d->handle = *handle; ++ d->ip4_config = ip4_config; ++ d->ip6_config = ip6_config; ++ d->http_handle = http_handle; ++ d->http = http; ++ d->dhcp4_handle = dhcp4_handle; ++ d->dhcp4 = dhcp4; ++ d->dhcp6_handle = dhcp6_handle; ++ d->dhcp6 = dhcp6; ++ d->next = net_devices; ++ d->card_name = grub_xasprintf ("efinet%d", id); ++ d->net_interfaces = NULL; ++ net_devices = d; ++ } ++ ++ grub_efi_net_add_pxebc_to_cards (); ++ grub_free (handles); ++ set_ip_policy_to_static (); ++} ++ ++static void ++listroutes_ip4 (struct grub_efi_net_device *netdev) ++{ ++ char **routes; ++ ++ routes = NULL; ++ ++ if ((routes = efi_net_ip4_config->get_route_table (netdev))) ++ { ++ char **r; ++ ++ for (r = routes; *r; ++r) ++ grub_printf ("%s\n", *r); ++ } ++ ++ if (routes) ++ { ++ char **r; ++ ++ for (r = routes; *r; ++r) ++ grub_free (*r); ++ grub_free (routes); ++ } ++} ++ ++static void ++listroutes_ip6 (struct grub_efi_net_device *netdev) ++{ ++ char **routes; ++ ++ routes = NULL; ++ ++ if ((routes = efi_net_ip6_config->get_route_table (netdev))) ++ { ++ char **r; ++ ++ for (r = routes; *r; ++r) ++ grub_printf ("%s\n", *r); ++ } ++ ++ if (routes) ++ { ++ char **r; ++ ++ for (r = routes; *r; ++r) ++ grub_free (*r); ++ grub_free (routes); ++ } ++} ++ ++static grub_err_t ++grub_cmd_efi_listroutes (struct grub_command *cmd __attribute__ ((unused)), ++ int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ struct grub_efi_net_device *netdev; ++ ++ for (netdev = net_devices; netdev; netdev = netdev->next) ++ { ++ listroutes_ip4 (netdev); ++ listroutes_ip6 (netdev); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++static grub_err_t ++grub_cmd_efi_listcards (struct grub_command *cmd __attribute__ ((unused)), ++ int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ struct grub_efi_net_device *dev; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ char *hw_addr; ++ ++ hw_addr = efi_net_ip4_config->get_hw_address (dev); ++ ++ if (hw_addr) ++ { ++ grub_printf ("%s %s\n", dev->card_name, hw_addr); ++ grub_free (hw_addr); ++ } ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_efi_listaddrs (struct grub_command *cmd __attribute__ ((unused)), ++ int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ struct grub_efi_net_device *dev; ++ grub_efi_net_interface_t *inf; ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ for (inf = dev->net_interfaces; inf; inf = inf->next) ++ { ++ char *hw_addr = NULL; ++ char *addr = NULL; ++ ++ if ((hw_addr = efi_net_interface_get_hw_address (inf)) ++ && (addr = efi_net_interface_get_address (inf))) ++ grub_printf ("%s %s %s\n", inf->name, hw_addr, addr); ++ ++ if (hw_addr) ++ grub_free (hw_addr); ++ if (addr) ++ grub_free (addr); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++/* FIXME: support MAC specifying. */ ++static grub_err_t ++grub_cmd_efi_addaddr (struct grub_command *cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ struct grub_efi_net_device *dev; ++ grub_err_t err; ++ grub_efi_ip4_config2_manual_address_t ip4; ++ grub_efi_ip6_config_manual_address_t ip6; ++ grub_efi_net_ip_manual_address_t net_ip; ++ int is_ip6 = 0; ++ int cidr = 0; ++ ++ if (argc != 3) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("three arguments expected")); ++ ++ for (dev = net_devices; dev; dev = dev->next) ++ { ++ if (grub_strcmp (dev->card_name, args[1]) == 0) ++ break; ++ } ++ ++ if (!dev) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("card not found")); ++ ++ err = grub_efi_net_parse_address (args[2], &ip4, &ip6, &is_ip6, &cidr); ++ ++ if (err) ++ return err; ++ ++ net_ip.is_ip6 = is_ip6; ++ if (is_ip6) ++ grub_memcpy (&net_ip.ip6, &ip6, sizeof(net_ip.ip6)); ++ else ++ grub_memcpy (&net_ip.ip4, &ip4, sizeof(net_ip.ip4)); ++ ++ if (!grub_efi_net_create_interface (dev, ++ args[0], ++ &net_ip, ++ cidr)) ++ return grub_errno; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static struct grub_fs grub_efi_netfs; ++ ++static grub_net_t ++grub_net_open_real (const char *name __attribute__ ((unused))) ++{ ++ grub_size_t protnamelen; ++ const char *protname, *server; ++ grub_net_t ret; ++ ++ net_interface = NULL; ++ ++ if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0) ++ { ++ protname = "tftp"; ++ protnamelen = sizeof ("tftp") - 1; ++ server = name + sizeof ("pxe:") - 1; ++ } ++ else if (grub_strcmp (name, "pxe") == 0) ++ { ++ protname = "tftp"; ++ protnamelen = sizeof ("tftp") - 1; ++ server = default_server; ++ } ++ else ++ { ++ const char *comma; ++ ++ comma = grub_strchr (name, ','); ++ if (comma) ++ { ++ protnamelen = comma - name; ++ server = comma + 1; ++ protname = name; ++ } ++ else ++ { ++ protnamelen = grub_strlen (name); ++ server = default_server; ++ protname = name; ++ } ++ } ++ ++ if (!server) ++ { ++ grub_error (GRUB_ERR_NET_BAD_ADDRESS, ++ N_("no server is specified")); ++ return NULL; ++ } ++ ++ /*FIXME: Use DNS translate name to address */ ++ net_interface = match_route (server); ++ ++ /*XXX: should we check device with default gateway ? */ ++ if (!net_interface && !(net_interface = net_default_interface)) ++ { ++ grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' no route found"), ++ name); ++ return NULL; ++ } ++ ++ if ((protnamelen == (sizeof ("https") - 1) ++ && grub_memcmp ("https", protname, protnamelen) == 0)) ++ { ++ net_interface->io = &io_http; ++ net_interface->io_type = 1; ++ } ++ else if ((protnamelen == (sizeof ("http") - 1) ++ && grub_memcmp ("http", protname, protnamelen) == 0)) ++ { ++ net_interface->io = &io_http; ++ net_interface->io_type = 0; ++ } ++ else if (protnamelen == (sizeof ("tftp") - 1) ++ && grub_memcmp ("tftp", protname, protnamelen) == 0) ++ { ++ net_interface->io = &io_pxe; ++ net_interface->io_type = 0; ++ } ++ else ++ { ++ grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' not found"), ++ name); ++ return NULL; ++ } ++ ++ /*XXX: Should we try to avoid doing excess "reconfigure" here ??? */ ++ efi_net_interface (configure); ++ ++ ret = grub_zalloc (sizeof (*ret)); ++ if (!ret) ++ return NULL; ++ ++ ret->server = grub_strdup (server); ++ if (!ret->server) ++ { ++ grub_free (ret); ++ return NULL; ++ } ++ ++ ret->fs = &grub_efi_netfs; ++ return ret; ++} ++#if 0 ++static grub_command_t cmd_efi_lsaddr; ++static grub_command_t cmd_efi_lscards; ++static grub_command_t cmd_efi_lsroutes; ++static grub_command_t cmd_efi_addaddr; ++#endif ++ ++static struct grub_fs grub_efi_netfs = ++ { ++ .name = "efi netfs", ++ .fs_dir = grub_efi_netfs_dir, ++ .fs_open = grub_efi_netfs_open, ++ .fs_read = grub_efi_netfs_read, ++ .fs_close = grub_efi_netfs_close, ++ .fs_label = NULL, ++ .fs_uuid = NULL, ++ .fs_mtime = NULL, ++ }; ++ ++int ++grub_efi_net_boot_from_https (void) ++{ ++ grub_efi_loaded_image_t *image = NULL; ++ grub_efi_device_path_t *dp; ++ ++ image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (!image) ++ return 0; ++ ++ dp = grub_efi_get_device_path (image->device_handle); ++ ++ while (1) ++ { ++ grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); ++ grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); ++ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ ++ if ((type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE) ++ && (subtype == GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) ++ { ++ grub_efi_uri_device_path_t *uri_dp = (grub_efi_uri_device_path_t *) dp; ++ return (grub_strncmp ((const char*)uri_dp->uri, "https://", sizeof ("https://") - 1) == 0) ? 1 : 0; ++ } ++ ++ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) ++ break; ++ dp = (grub_efi_device_path_t *) ((char *) dp + len); ++ } ++ ++ return 0; ++} ++ ++int ++grub_efi_net_boot_from_opa (void) ++{ ++ grub_efi_loaded_image_t *image = NULL; ++ grub_efi_device_path_t *dp; ++ ++ image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (!image) ++ return 0; ++ ++ dp = grub_efi_get_device_path (image->device_handle); ++ ++ while (1) ++ { ++ grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); ++ grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); ++ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ ++ if ((type == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE) ++ && (subtype == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE)) ++ { ++ grub_efi_mac_address_device_path_t *mac_dp = (grub_efi_mac_address_device_path_t *)dp; ++ return (mac_dp->if_type == 0xC7) ? 1 : 0; ++ } ++ ++ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) ++ break; ++ dp = (grub_efi_device_path_t *) ((char *) dp + len); ++ } ++ ++ return 0; ++} ++ ++static char * ++grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), ++ const char *val __attribute__ ((unused))) ++{ ++ return NULL; ++} ++ ++grub_command_func_t grub_efi_net_list_routes = grub_cmd_efi_listroutes; ++grub_command_func_t grub_efi_net_list_cards = grub_cmd_efi_listcards; ++grub_command_func_t grub_efi_net_list_addrs = grub_cmd_efi_listaddrs; ++grub_command_func_t grub_efi_net_add_addr = grub_cmd_efi_addaddr; ++ ++int ++grub_efi_net_fs_init () ++{ ++ grub_efi_net_find_cards (); ++ grub_efi_net_config = grub_efi_net_config_real; ++ grub_net_open = grub_net_open_real; ++ grub_register_variable_hook ("net_default_server", grub_efi_net_var_get_server, ++ grub_efi_net_var_set_server); ++ grub_env_export ("net_default_server"); ++ grub_register_variable_hook ("pxe_default_server", grub_efi_net_var_get_server, ++ grub_efi_net_var_set_server); ++ grub_env_export ("pxe_default_server"); ++ grub_register_variable_hook ("net_default_interface", 0, ++ grub_efi_net_var_set_interface); ++ grub_env_export ("net_default_interface"); ++ grub_register_variable_hook ("net_default_ip", grub_efi_net_var_get_ip, ++ 0); ++ grub_env_export ("net_default_ip"); ++ grub_register_variable_hook ("net_default_mac", grub_efi_net_var_get_mac, ++ 0); ++ grub_env_export ("net_default_mac"); ++ ++ grub_env_set ("grub_netfs_type", "efi"); ++ grub_register_variable_hook ("grub_netfs_type", 0, grub_env_write_readonly); ++ grub_env_export ("grub_netfs_type"); ++ ++ return 1; ++} ++ ++void ++grub_efi_net_fs_fini (void) ++{ ++ grub_env_unset ("grub_netfs_type"); ++ grub_efi_net_unset_interface_vars (); ++ grub_register_variable_hook ("net_default_server", 0, 0); ++ grub_env_unset ("net_default_server"); ++ grub_register_variable_hook ("net_default_interface", 0, 0); ++ grub_env_unset ("net_default_interface"); ++ grub_register_variable_hook ("pxe_default_server", 0, 0); ++ grub_env_unset ("pxe_default_server"); ++ grub_register_variable_hook ("net_default_ip", 0, 0); ++ grub_env_unset ("net_default_ip"); ++ grub_register_variable_hook ("net_default_mac", 0, 0); ++ grub_env_unset ("net_default_mac"); ++ grub_efi_net_config = NULL; ++ grub_net_open = NULL; ++ grub_fs_unregister (&grub_efi_netfs); ++} +diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c +new file mode 100644 +index 00000000000..531949cba5c +--- /dev/null ++++ b/grub-core/net/efi/pxe.c +@@ -0,0 +1,424 @@ ++ ++#include ++#include ++#include ++#include ++#include ++ ++static grub_efi_ip6_config_manual_address_t * ++efi_ip6_config_manual_address (grub_efi_ip6_config_protocol_t *ip6_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip6_config_manual_address_t *manual_address; ++ ++ sz = sizeof (*manual_address); ++ manual_address = grub_malloc (sz); ++ if (!manual_address) ++ return NULL; ++ ++ status = efi_call_4 (ip6_config->get_data, ip6_config, ++ GRUB_EFI_IP6_CONFIG_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, manual_address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (manual_address); ++ return NULL; ++ } ++ ++ return manual_address; ++} ++ ++static grub_efi_ip4_config2_manual_address_t * ++efi_ip4_config_manual_address (grub_efi_ip4_config2_protocol_t *ip4_config) ++{ ++ grub_efi_uintn_t sz; ++ grub_efi_status_t status; ++ grub_efi_ip4_config2_manual_address_t *manual_address; ++ ++ sz = sizeof (*manual_address); ++ manual_address = grub_malloc (sz); ++ if (!manual_address) ++ return NULL; ++ ++ status = efi_call_4 (ip4_config->get_data, ip4_config, ++ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_MANUAL_ADDRESS, ++ &sz, manual_address); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_free (manual_address); ++ return NULL; ++ } ++ ++ return manual_address; ++} ++ ++static void ++pxe_configure (struct grub_efi_net_device *dev, int prefer_ip6) ++{ ++ grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe; ++ ++ grub_efi_pxe_mode_t *mode = pxe->mode; ++ ++ if (!mode->started) ++ { ++ grub_efi_status_t status; ++ status = efi_call_2 (pxe->start, pxe, prefer_ip6); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ grub_printf ("Couldn't start PXE\n"); ++ } ++ ++#if 0 ++ grub_printf ("PXE STARTED: %u\n", mode->started); ++ grub_printf ("PXE USING IPV6: %u\n", mode->using_ipv6); ++#endif ++ ++ if (mode->using_ipv6) ++ { ++ grub_efi_ip6_config_manual_address_t *manual_address; ++ manual_address = efi_ip6_config_manual_address (dev->ip6_config); ++ ++ if (manual_address && ++ grub_memcmp (manual_address->address, mode->station_ip.v6, sizeof (manual_address->address)) != 0) ++ { ++ grub_efi_status_t status; ++ grub_efi_pxe_ip_address_t station_ip; ++ ++ grub_memcpy (station_ip.v6.addr, manual_address->address, sizeof (station_ip.v6.addr)); ++ status = efi_call_3 (pxe->set_station_ip, pxe, &station_ip, NULL); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ grub_printf ("Couldn't set station ip\n"); ++ ++ grub_free (manual_address); ++ } ++ } ++ else ++ { ++ grub_efi_ip4_config2_manual_address_t *manual_address; ++ manual_address = efi_ip4_config_manual_address (dev->ip4_config); ++ ++ if (manual_address && ++ grub_memcmp (manual_address->address, mode->station_ip.v4, sizeof (manual_address->address)) != 0) ++ { ++ grub_efi_status_t status; ++ grub_efi_pxe_ip_address_t station_ip; ++ grub_efi_pxe_ip_address_t subnet_mask; ++ ++ grub_memcpy (station_ip.v4.addr, manual_address->address, sizeof (station_ip.v4.addr)); ++ grub_memcpy (subnet_mask.v4.addr, manual_address->subnet_mask, sizeof (subnet_mask.v4.addr)); ++ ++ status = efi_call_3 (pxe->set_station_ip, pxe, &station_ip, &subnet_mask); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ grub_printf ("Couldn't set station ip\n"); ++ ++ grub_free (manual_address); ++ } ++ } ++ ++#if 0 ++ if (mode->using_ipv6) ++ { ++ grub_printf ("PXE STATION IP: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", ++ mode->station_ip.v6.addr[0], ++ mode->station_ip.v6.addr[1], ++ mode->station_ip.v6.addr[2], ++ mode->station_ip.v6.addr[3], ++ mode->station_ip.v6.addr[4], ++ mode->station_ip.v6.addr[5], ++ mode->station_ip.v6.addr[6], ++ mode->station_ip.v6.addr[7], ++ mode->station_ip.v6.addr[8], ++ mode->station_ip.v6.addr[9], ++ mode->station_ip.v6.addr[10], ++ mode->station_ip.v6.addr[11], ++ mode->station_ip.v6.addr[12], ++ mode->station_ip.v6.addr[13], ++ mode->station_ip.v6.addr[14], ++ mode->station_ip.v6.addr[15]); ++ } ++ else ++ { ++ grub_printf ("PXE STATION IP: %d.%d.%d.%d\n", ++ mode->station_ip.v4.addr[0], ++ mode->station_ip.v4.addr[1], ++ mode->station_ip.v4.addr[2], ++ mode->station_ip.v4.addr[3]); ++ grub_printf ("PXE SUBNET MASK: %d.%d.%d.%d\n", ++ mode->subnet_mask.v4.addr[0], ++ mode->subnet_mask.v4.addr[1], ++ mode->subnet_mask.v4.addr[2], ++ mode->subnet_mask.v4.addr[3]); ++ } ++#endif ++ ++ /* TODO: Set The Station IP to the IP2 Config */ ++} ++ ++static int ++parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) ++{ ++ grub_uint16_t newip[8]; ++ const char *ptr = val; ++ int word, quaddot = -1; ++ int bracketed = 0; ++ ++ if (ptr[0] == '[') { ++ bracketed = 1; ++ ptr++; ++ } ++ ++ if (ptr[0] == ':' && ptr[1] != ':') ++ return 0; ++ if (ptr[0] == ':') ++ ptr++; ++ ++ for (word = 0; word < 8; word++) ++ { ++ unsigned long t; ++ if (*ptr == ':') ++ { ++ quaddot = word; ++ word--; ++ ptr++; ++ continue; ++ } ++ t = grub_strtoul (ptr, (char **) &ptr, 16); ++ if (grub_errno) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ break; ++ } ++ if (t & ~0xffff) ++ return 0; ++ newip[word] = grub_cpu_to_be16 (t); ++ if (*ptr != ':') ++ break; ++ ptr++; ++ } ++ if (quaddot == -1 && word < 7) ++ return 0; ++ if (quaddot != -1) ++ { ++ grub_memmove (&newip[quaddot + 7 - word], &newip[quaddot], ++ (word - quaddot + 1) * sizeof (newip[0])); ++ grub_memset (&newip[quaddot], 0, (7 - word) * sizeof (newip[0])); ++ } ++ grub_memcpy (ip, newip, 16); ++ if (bracketed && *ptr == ']') { ++ ptr++; ++ } ++ if (rest) ++ *rest = ptr; ++ return 1; ++} ++ ++static grub_err_t ++pxe_open (struct grub_efi_net_device *dev, ++ int prefer_ip6, ++ grub_file_t file, ++ const char *filename, ++ int type __attribute__((unused))) ++{ ++ int i; ++ char *p; ++ grub_efi_status_t status; ++ grub_efi_pxe_ip_address_t server_ip; ++ grub_efi_uint64_t file_size = 0; ++ grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe; ++ ++ if (pxe->mode->using_ipv6) ++ { ++ const char *rest; ++ grub_uint64_t ip6[2]; ++ if (parse_ip6 (file->device->net->server, ip6, &rest) && *rest == 0) ++ grub_memcpy (server_ip.v6.addr, ip6, sizeof (server_ip.v6.addr)); ++ /* TODO: ERROR Handling Here */ ++#if 0 ++ grub_printf ("PXE SERVER IP: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", ++ server_ip.v6.addr[0], ++ server_ip.v6.addr[1], ++ server_ip.v6.addr[2], ++ server_ip.v6.addr[3], ++ server_ip.v6.addr[4], ++ server_ip.v6.addr[5], ++ server_ip.v6.addr[6], ++ server_ip.v6.addr[7], ++ server_ip.v6.addr[8], ++ server_ip.v6.addr[9], ++ server_ip.v6.addr[10], ++ server_ip.v6.addr[11], ++ server_ip.v6.addr[12], ++ server_ip.v6.addr[13], ++ server_ip.v6.addr[14], ++ server_ip.v6.addr[15]); ++#endif ++ } ++ else ++ { ++ for (i = 0, p = file->device->net->server; i < 4; ++i, ++p) ++ server_ip.v4.addr[i] = grub_strtoul (p, &p, 10); ++ } ++ ++ status = efi_call_10 (pxe->mtftp, ++ pxe, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, ++ NULL, ++ 0, ++ &file_size, ++ NULL, ++ &server_ip, ++ (grub_efi_char8_t *)filename, ++ NULL, ++ 0); ++ ++ if (status != GRUB_EFI_SUCCESS) ++ return grub_error (GRUB_ERR_IO, "Couldn't get file size"); ++ ++ file->size = (grub_off_t)file_size; ++ file->not_easily_seekable = 0; ++ file->data = 0; ++ file->device->net->offset = 0; ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++pxe_close (struct grub_efi_net_device *dev __attribute__((unused)), ++ int prefer_ip6 __attribute__((unused)), ++ grub_file_t file __attribute__((unused))) ++{ ++ file->offset = 0; ++ file->size = 0; ++ file->device->net->offset = 0; ++ ++ if (file->data) ++ { ++ grub_free (file->data); ++ file->data = NULL; ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_ssize_t ++pxe_read (struct grub_efi_net_device *dev, ++ int prefer_ip6, ++ grub_file_t file, ++ char *buf, ++ grub_size_t len) ++{ ++ int i; ++ char *p; ++ grub_efi_status_t status; ++ grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe; ++ grub_efi_uint64_t bufsz = len; ++ grub_efi_pxe_ip_address_t server_ip; ++ char *buf2 = NULL; ++ ++ if (file->data) ++ { ++ /* TODO: RANGE Check for offset and file size */ ++ grub_memcpy (buf, (char*)file->data + file->device->net->offset, len); ++ file->device->net->offset += len; ++ return len; ++ } ++ ++ if (file->device->net->offset) ++ { ++ grub_error (GRUB_ERR_BUG, "No Offet Read Possible"); ++ grub_print_error (); ++ return 0; ++ } ++ ++ if (pxe->mode->using_ipv6) ++ { ++ const char *rest; ++ grub_uint64_t ip6[2]; ++ if (parse_ip6 (file->device->net->server, ip6, &rest) && *rest == 0) ++ grub_memcpy (server_ip.v6.addr, ip6, sizeof (server_ip.v6.addr)); ++ /* TODO: ERROR Handling Here */ ++ } ++ else ++ { ++ for (i = 0, p = file->device->net->server; i < 4; ++i, ++p) ++ server_ip.v4.addr[i] = grub_strtoul (p, &p, 10); ++ } ++ ++ status = efi_call_10 (pxe->mtftp, ++ pxe, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_READ_FILE, ++ buf, ++ 0, ++ &bufsz, ++ NULL, ++ &server_ip, ++ (grub_efi_char8_t *)file->device->net->name, ++ NULL, ++ 0); ++ ++ if (bufsz != file->size) ++ { ++ grub_error (GRUB_ERR_BUG, "Short read should not happen here"); ++ grub_print_error (); ++ return 0; ++ } ++ ++ if (status == GRUB_EFI_BUFFER_TOO_SMALL) ++ { ++ ++ buf2 = grub_malloc (bufsz); ++ ++ if (!buf2) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, "ERROR OUT OF MEMORY"); ++ grub_print_error (); ++ return 0; ++ } ++ ++ status = efi_call_10 (pxe->mtftp, ++ pxe, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_READ_FILE, ++ buf2, ++ 0, ++ &bufsz, ++ NULL, ++ &server_ip, ++ (grub_efi_char8_t *)file->device->net->name, ++ NULL, ++ 0); ++ } ++ ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ if (buf2) ++ grub_free (buf2); ++ ++ grub_error (GRUB_ERR_IO, "Failed to Read File"); ++ grub_print_error (); ++ return 0; ++ } ++ ++ if (buf2) ++ grub_memcpy (buf, buf2, len); ++ ++ file->device->net->offset = len; ++ ++ if (buf2) ++ file->data = buf2; ++ ++ return len; ++} ++ ++struct grub_efi_net_io io_pxe = ++ { ++ .configure = pxe_configure, ++ .open = pxe_open, ++ .read = pxe_read, ++ .close = pxe_close ++ }; ++ +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 2734f70d22f..27a0a1d6961 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -32,6 +32,9 @@ + #include + #include + #include ++#ifdef GRUB_MACHINE_EFI ++#include ++#endif + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -2025,8 +2028,49 @@ static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute; + static grub_command_t cmd_lsroutes, cmd_lscards; + static grub_command_t cmd_lsaddr, cmd_slaac; + ++#ifdef GRUB_MACHINE_EFI ++ ++static enum { ++ INIT_MODE_NONE, ++ INIT_MODE_GRUB, ++ INIT_MODE_EFI ++} init_mode; ++ ++static grub_command_t cmd_bootp, cmd_bootp6; ++ ++#endif ++ + GRUB_MOD_INIT(net) + { ++#ifdef GRUB_MACHINE_EFI ++ if (grub_net_open) ++ return; ++ ++ if ((grub_efi_net_boot_from_https () || grub_efi_net_boot_from_opa ()) ++ && grub_efi_net_fs_init ()) ++ { ++ cmd_lsroutes = grub_register_command ("net_ls_routes", grub_efi_net_list_routes, ++ "", N_("list network routes")); ++ cmd_lscards = grub_register_command ("net_ls_cards", grub_efi_net_list_cards, ++ "", N_("list network cards")); ++ cmd_lsaddr = grub_register_command ("net_ls_addr", grub_efi_net_list_addrs, ++ "", N_("list network addresses")); ++ cmd_addaddr = grub_register_command ("net_add_addr", grub_efi_net_add_addr, ++ /* TRANSLATORS: HWADDRESS stands for ++ "hardware address". */ ++ N_("SHORTNAME CARD ADDRESS [HWADDRESS]"), ++ N_("Add a network address.")); ++ cmd_bootp = grub_register_command ("net_bootp", grub_efi_net_bootp, ++ N_("[CARD]"), ++ N_("perform a bootp autoconfiguration")); ++ cmd_bootp6 = grub_register_command ("net_bootp6", grub_efi_net_bootp6, ++ N_("[CARD]"), ++ N_("perform a bootp autoconfiguration")); ++ init_mode = INIT_MODE_EFI; ++ return; ++ } ++#endif ++ + grub_register_variable_hook ("net_default_server", defserver_get_env, + defserver_set_env); + grub_env_export ("net_default_server"); +@@ -2074,10 +2118,37 @@ GRUB_MOD_INIT(net) + grub_net_restore_hw, + GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK); + grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; ++ ++#ifdef GRUB_MACHINE_EFI ++ grub_env_set ("grub_netfs_type", "grub"); ++ grub_register_variable_hook ("grub_netfs_type", 0, grub_env_write_readonly); ++ grub_env_export ("grub_netfs_type"); ++ init_mode = INIT_MODE_GRUB; ++#endif ++ + } + + GRUB_MOD_FINI(net) + { ++ ++#ifdef GRUB_MACHINE_EFI ++ if (init_mode == INIT_MODE_NONE) ++ return; ++ ++ if (init_mode == INIT_MODE_EFI) ++ { ++ grub_unregister_command (cmd_lsroutes); ++ grub_unregister_command (cmd_lscards); ++ grub_unregister_command (cmd_lsaddr); ++ grub_unregister_command (cmd_addaddr); ++ grub_unregister_command (cmd_bootp); ++ grub_unregister_command (cmd_bootp6); ++ grub_efi_net_fs_fini (); ++ init_mode = INIT_MODE_NONE; ++ return; ++ } ++#endif ++ + grub_register_variable_hook ("net_default_server", 0, 0); + grub_register_variable_hook ("pxe_default_server", 0, 0); + +@@ -2096,4 +2167,7 @@ GRUB_MOD_FINI(net) + grub_net_fini_hw (0); + grub_loader_unregister_preboot_hook (fini_hnd); + grub_net_poll_cards_idle = grub_net_poll_cards_idle_real; ++#ifdef GRUB_MACHINE_EFI ++ init_mode = INIT_MODE_NONE; ++#endif + } +diff --git a/util/grub-mknetdir.c b/util/grub-mknetdir.c +index 602574d52e8..1a61e05c6ec 100644 +--- a/util/grub-mknetdir.c ++++ b/util/grub-mknetdir.c +@@ -32,13 +32,15 @@ + + static char *rootdir = NULL, *subdir = NULL; + static char *debug_image = NULL; ++static char efi_netfs = 0; + + enum + { + OPTION_NET_DIRECTORY = 0x301, + OPTION_SUBDIR, + OPTION_DEBUG, +- OPTION_DEBUG_IMAGE ++ OPTION_DEBUG_IMAGE, ++ OPTION_DEBUG_EFI_NETFS + }; + + static struct argp_option options[] = { +@@ -49,6 +51,7 @@ static struct argp_option options[] = { + 0, N_("relative subdirectory on network server"), 2}, + {"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2}, + {"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2}, ++ {"debug-efi-netfs", OPTION_DEBUG_EFI_NETFS, 0, OPTION_HIDDEN, 0, 2}, + {0, 0, 0, 0, 0, 0} + }; + +@@ -67,6 +70,9 @@ argp_parser (int key, char *arg, struct argp_state *state) + free (subdir); + subdir = xstrdup (arg); + return 0; ++ case OPTION_DEBUG_EFI_NETFS: ++ efi_netfs = 1; ++ return 0; + /* This is an undocumented feature... */ + case OPTION_DEBUG: + verbosity++; +@@ -82,7 +88,6 @@ argp_parser (int key, char *arg, struct argp_state *state) + } + } + +- + struct argp argp = { + options, argp_parser, NULL, + "\v"N_("Prepares GRUB network boot images at net_directory/subdir " +@@ -92,7 +97,7 @@ struct argp argp = { + + static char *base; + +-static const struct ++static struct + { + const char *mkimage_target; + const char *netmodule; +@@ -156,6 +161,7 @@ process_input_dir (const char *input_dir, enum grub_install_plat platform) + grub_install_push_module (targets[platform].netmodule); + + output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext); ++ + grub_install_make_image_wrap (input_dir, prefix, output, + 0, load_cfg, + targets[platform].mkimage_target, 0); +@@ -192,7 +198,16 @@ main (int argc, char *argv[]) + + grub_install_mkdir_p (base); + +- grub_install_push_module ("tftp"); ++ if (!efi_netfs) ++ { ++ grub_install_push_module ("tftp"); ++ grub_install_push_module ("http"); ++ } ++ else ++ { ++ targets[GRUB_INSTALL_PLATFORM_I386_EFI].netmodule = "efi_netfs"; ++ targets[GRUB_INSTALL_PLATFORM_X86_64_EFI].netmodule = "efi_netfs"; ++ } + + if (!grub_install_source_directory) + { +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 716f121728b..2ed9c26a450 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -602,6 +602,23 @@ typedef union + + typedef grub_efi_uint64_t grub_efi_physical_address_t; + typedef grub_efi_uint64_t grub_efi_virtual_address_t; ++typedef struct { ++ grub_uint8_t addr[4]; ++} grub_efi_pxe_ipv4_address_t; ++ ++typedef struct { ++ grub_uint8_t addr[16]; ++} grub_efi_pxe_ipv6_address_t; ++ ++typedef struct { ++ grub_uint8_t addr[32]; ++} grub_efi_pxe_mac_address_t; ++ ++typedef union { ++ grub_uint32_t addr[4]; ++ grub_efi_pxe_ipv4_address_t v4; ++ grub_efi_pxe_ipv6_address_t v6; ++} grub_efi_pxe_ip_address_t; + + struct grub_efi_guid + { +@@ -865,6 +882,8 @@ struct grub_efi_ipv6_device_path + grub_efi_uint16_t remote_port; + grub_efi_uint16_t protocol; + grub_efi_uint8_t static_ip_address; ++ grub_efi_uint8_t prefix_length; ++ grub_efi_ipv6_address_t gateway_ip_address; + } GRUB_PACKED; + typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t; + +@@ -914,6 +933,15 @@ struct grub_efi_uri_device_path + } GRUB_PACKED; + typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t; + ++#define GRUB_EFI_DNS_DEVICE_PATH_SUBTYPE 31 ++struct grub_efi_dns_device_path ++{ ++ grub_efi_device_path_t header; ++ grub_efi_uint8_t is_ipv6; ++ grub_efi_pxe_ip_address_t dns_server_ip[0]; ++} GRUB_PACKED; ++typedef struct grub_efi_dns_device_path grub_efi_dns_device_path_t; ++ + #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 + + /* Media Device Path. */ +@@ -996,6 +1024,23 @@ struct grub_efi_bios_device_path + } GRUB_PACKED; + typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t; + ++/* Service Binding definitions */ ++struct grub_efi_service_binding; ++ ++typedef grub_efi_status_t ++(*grub_efi_service_binding_create_child) (struct grub_efi_service_binding *this, ++ grub_efi_handle_t *child_handle); ++ ++typedef grub_efi_status_t ++(*grub_efi_service_binding_destroy_child) (struct grub_efi_service_binding *this, ++ grub_efi_handle_t *child_handle); ++ ++typedef struct grub_efi_service_binding ++{ ++ grub_efi_service_binding_create_child create_child; ++ grub_efi_service_binding_destroy_child destroy_child; ++} grub_efi_service_binding_t; ++ + struct grub_efi_open_protocol_information_entry + { + grub_efi_handle_t agent_handle; +@@ -1545,23 +1590,27 @@ typedef struct grub_efi_pxe_tftp_error + grub_efi_char8_t error_string[127]; + } grub_efi_pxe_tftp_error_t; + +-typedef struct { +- grub_uint8_t addr[4]; +-} grub_efi_pxe_ipv4_address_t; ++typedef grub_efi_uint16_t grub_efi_pxe_base_code_udp_port_t; + +-typedef struct { +- grub_uint8_t addr[16]; +-} grub_efi_pxe_ipv6_address_t; ++typedef enum { ++ GRUB_EFI_PXE_BASE_CODE_TFTP_FIRST, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_READ_FILE, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_WRITE_FILE, ++ GRUB_EFI_PXE_BASE_CODE_TFTP_READ_DIRECTORY, ++ GRUB_EFI_PXE_BASE_CODE_MTFTP_GET_FILE_SIZE, ++ GRUB_EFI_PXE_BASE_CODE_MTFTP_READ_FILE, ++ GRUB_EFI_PXE_BASE_CODE_MTFTP_READ_DIRECTORY, ++ GRUB_EFI_PXE_BASE_CODE_MTFTP_LAST ++} grub_efi_pxe_base_code_tftp_opcode_t; + + typedef struct { +- grub_uint8_t addr[32]; +-} grub_efi_pxe_mac_address_t; +- +-typedef union { +- grub_uint32_t addr[4]; +- grub_efi_pxe_ipv4_address_t v4; +- grub_efi_pxe_ipv6_address_t v6; +-} grub_efi_pxe_ip_address_t; ++ grub_efi_ip_address_t mcast_ip; ++ grub_efi_pxe_base_code_udp_port_t c_port; ++ grub_efi_pxe_base_code_udp_port_t s_port; ++ grub_efi_uint16_t listen_timeout; ++ grub_efi_uint16_t transmit_timeout; ++} grub_efi_pxe_base_code_mtftp_info_t; + + #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 + typedef struct grub_efi_pxe_ip_filter +@@ -1628,17 +1677,31 @@ typedef struct grub_efi_pxe_mode + typedef struct grub_efi_pxe + { + grub_uint64_t rev; +- void (*start) (void); ++ grub_efi_status_t (*start) (struct grub_efi_pxe *this, grub_efi_boolean_t use_ipv6); + void (*stop) (void); +- void (*dhcp) (void); ++ grub_efi_status_t (*dhcp) (struct grub_efi_pxe *this, ++ grub_efi_boolean_t sort_offers); + void (*discover) (void); +- void (*mftp) (void); ++ grub_efi_status_t (*mtftp) (struct grub_efi_pxe *this, ++ grub_efi_pxe_base_code_tftp_opcode_t operation, ++ void *buffer_ptr, ++ grub_efi_boolean_t overwrite, ++ grub_efi_uint64_t *buffer_size, ++ grub_efi_uintn_t *block_size, ++ grub_efi_pxe_ip_address_t *server_ip, ++ //grub_efi_ip_address_t *server_ip, ++ grub_efi_char8_t *filename, ++ grub_efi_pxe_base_code_mtftp_info_t *info, ++ grub_efi_boolean_t dont_use_buffer); + void (*udpwrite) (void); + void (*udpread) (void); + void (*setipfilter) (void); + void (*arp) (void); + void (*setparams) (void); +- void (*setstationip) (void); ++ grub_efi_status_t (*set_station_ip) (struct grub_efi_pxe *this, ++ grub_efi_pxe_ip_address_t *new_station_ip, ++ grub_efi_pxe_ip_address_t *new_subnet_mask); ++ //void (*setstationip) (void); + void (*setpackets) (void); + struct grub_efi_pxe_mode *mode; + } grub_efi_pxe_t; +@@ -1880,6 +1943,44 @@ struct grub_efi_ip4_config2_protocol + }; + typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t; + ++struct grub_efi_ip4_route_table { ++ grub_efi_ipv4_address_t subnet_address; ++ grub_efi_ipv4_address_t subnet_mask; ++ grub_efi_ipv4_address_t gateway_address; ++}; ++ ++typedef struct grub_efi_ip4_route_table grub_efi_ip4_route_table_t; ++ ++#define GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE 32 ++ ++struct grub_efi_ip4_config2_interface_info { ++ grub_efi_char16_t name[GRUB_EFI_IP4_CONFIG2_INTERFACE_INFO_NAME_SIZE]; ++ grub_efi_uint8_t if_type; ++ grub_efi_uint32_t hw_address_size; ++ grub_efi_mac_address_t hw_address; ++ grub_efi_ipv4_address_t station_address; ++ grub_efi_ipv4_address_t subnet_mask; ++ grub_efi_uint32_t route_table_size; ++ grub_efi_ip4_route_table_t *route_table; ++}; ++ ++typedef struct grub_efi_ip4_config2_interface_info grub_efi_ip4_config2_interface_info_t; ++ ++enum grub_efi_ip4_config2_policy { ++ GRUB_EFI_IP4_CONFIG2_POLICY_STATIC, ++ GRUB_EFI_IP4_CONFIG2_POLICY_DHCP, ++ GRUB_EFI_IP4_CONFIG2_POLICY_MAX ++}; ++ ++typedef enum grub_efi_ip4_config2_policy grub_efi_ip4_config2_policy_t; ++ ++struct grub_efi_ip4_config2_manual_address { ++ grub_efi_ipv4_address_t address; ++ grub_efi_ipv4_address_t subnet_mask; ++}; ++ ++typedef struct grub_efi_ip4_config2_manual_address grub_efi_ip4_config2_manual_address_t; ++ + enum grub_efi_ip6_config_data_type { + GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, + GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, +@@ -1914,6 +2015,49 @@ struct grub_efi_ip6_config_protocol + }; + typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t; + ++enum grub_efi_ip6_config_policy { ++ GRUB_EFI_IP6_CONFIG_POLICY_MANUAL, ++ GRUB_EFI_IP6_CONFIG_POLICY_AUTOMATIC ++}; ++typedef enum grub_efi_ip6_config_policy grub_efi_ip6_config_policy_t; ++ ++struct grub_efi_ip6_address_info { ++ grub_efi_ipv6_address_t address; ++ grub_efi_uint8_t prefix_length; ++}; ++typedef struct grub_efi_ip6_address_info grub_efi_ip6_address_info_t; ++ ++struct grub_efi_ip6_route_table { ++ grub_efi_pxe_ipv6_address_t gateway; ++ grub_efi_pxe_ipv6_address_t destination; ++ grub_efi_uint8_t prefix_length; ++}; ++typedef struct grub_efi_ip6_route_table grub_efi_ip6_route_table_t; ++ ++struct grub_efi_ip6_config_interface_info { ++ grub_efi_char16_t name[32]; ++ grub_efi_uint8_t if_type; ++ grub_efi_uint32_t hw_address_size; ++ grub_efi_mac_address_t hw_address; ++ grub_efi_uint32_t address_info_count; ++ grub_efi_ip6_address_info_t *address_info; ++ grub_efi_uint32_t route_count; ++ grub_efi_ip6_route_table_t *route_table; ++}; ++typedef struct grub_efi_ip6_config_interface_info grub_efi_ip6_config_interface_info_t; ++ ++struct grub_efi_ip6_config_dup_addr_detect_transmits { ++ grub_efi_uint32_t dup_addr_detect_transmits; ++}; ++typedef struct grub_efi_ip6_config_dup_addr_detect_transmits grub_efi_ip6_config_dup_addr_detect_transmits_t; ++ ++struct grub_efi_ip6_config_manual_address { ++ grub_efi_ipv6_address_t address; ++ grub_efi_boolean_t is_anycast; ++ grub_efi_uint8_t prefix_length; ++}; ++typedef struct grub_efi_ip6_config_manual_address grub_efi_ip6_config_manual_address_t; ++ + #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ + || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ + || defined(__riscv) +diff --git a/include/grub/efi/dhcp.h b/include/grub/efi/dhcp.h +new file mode 100644 +index 00000000000..fdb88eb810e +--- /dev/null ++++ b/include/grub/efi/dhcp.h +@@ -0,0 +1,343 @@ ++#ifndef GRUB_EFI_DHCP_HEADER ++#define GRUB_EFI_DHCP_HEADER 1 ++ ++#define GRUB_EFI_DHCP4_SERVICE_BINDING_PROTOCOL_GUID \ ++ { 0x9d9a39d8, 0xbd42, 0x4a73, \ ++ { 0xa4, 0xd5, 0x8e, 0xe9, 0x4b, 0xe1, 0x13, 0x80 } \ ++ } ++ ++#define GRUB_EFI_DHCP4_PROTOCOL_GUID \ ++ { 0x8a219718, 0x4ef5, 0x4761, \ ++ { 0x91, 0xc8, 0xc0, 0xf0, 0x4b, 0xda, 0x9e, 0x56 } \ ++ } ++ ++#define GRUB_EFI_DHCP6_SERVICE_BINDING_PROTOCOL_GUID \ ++ { 0x9fb9a8a1, 0x2f4a, 0x43a6, \ ++ { 0x88, 0x9c, 0xd0, 0xf7, 0xb6, 0xc4 ,0x7a, 0xd5 } \ ++ } ++ ++#define GRUB_EFI_DHCP6_PROTOCOL_GUID \ ++ { 0x87c8bad7, 0x595, 0x4053, \ ++ { 0x82, 0x97, 0xde, 0xde, 0x39, 0x5f, 0x5d, 0x5b } \ ++ } ++ ++typedef struct grub_efi_dhcp4_protocol grub_efi_dhcp4_protocol_t; ++ ++enum grub_efi_dhcp4_state { ++ GRUB_EFI_DHCP4_STOPPED, ++ GRUB_EFI_DHCP4_INIT, ++ GRUB_EFI_DHCP4_SELECTING, ++ GRUB_EFI_DHCP4_REQUESTING, ++ GRUB_EFI_DHCP4_BOUND, ++ GRUB_EFI_DHCP4_RENEWING, ++ GRUB_EFI_DHCP4_REBINDING, ++ GRUB_EFI_DHCP4_INIT_REBOOT, ++ GRUB_EFI_DHCP4_REBOOTING ++}; ++ ++typedef enum grub_efi_dhcp4_state grub_efi_dhcp4_state_t; ++ ++struct grub_efi_dhcp4_header { ++ grub_efi_uint8_t op_code; ++ grub_efi_uint8_t hw_type; ++ grub_efi_uint8_t hw_addr_len; ++ grub_efi_uint8_t hops; ++ grub_efi_uint32_t xid; ++ grub_efi_uint16_t seconds; ++ grub_efi_uint16_t reserved; ++ grub_efi_ipv4_address_t client_addr; ++ grub_efi_ipv4_address_t your_addr; ++ grub_efi_ipv4_address_t server_addr; ++ grub_efi_ipv4_address_t gateway_addr; ++ grub_efi_uint8_t client_hw_addr[16]; ++ grub_efi_char8_t server_name[64]; ++ grub_efi_char8_t boot_file_name[128]; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp4_header grub_efi_dhcp4_header_t; ++ ++struct grub_efi_dhcp4_packet { ++ grub_efi_uint32_t size; ++ grub_efi_uint32_t length; ++ struct { ++ grub_efi_dhcp4_header_t header; ++ grub_efi_uint32_t magik; ++ grub_efi_uint8_t option[1]; ++ } dhcp4; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp4_packet grub_efi_dhcp4_packet_t; ++ ++struct grub_efi_dhcp4_listen_point { ++ grub_efi_ipv4_address_t listen_address; ++ grub_efi_ipv4_address_t subnet_mask; ++ grub_efi_uint16_t listen_port; ++}; ++ ++typedef struct grub_efi_dhcp4_listen_point grub_efi_dhcp4_listen_point_t; ++ ++struct grub_efi_dhcp4_transmit_receive_token { ++ grub_efi_status_t status; ++ grub_efi_event_t completion_event; ++ grub_efi_ipv4_address_t remote_address; ++ grub_efi_uint16_t remote_port; ++ grub_efi_ipv4_address_t gateway_address; ++ grub_efi_uint32_t listen_point_count; ++ grub_efi_dhcp4_listen_point_t *listen_points; ++ grub_efi_uint32_t timeout_value; ++ grub_efi_dhcp4_packet_t *packet; ++ grub_efi_uint32_t response_count; ++ grub_efi_dhcp4_packet_t *response_list; ++}; ++ ++typedef struct grub_efi_dhcp4_transmit_receive_token grub_efi_dhcp4_transmit_receive_token_t; ++ ++enum grub_efi_dhcp4_event { ++ GRUB_EFI_DHCP4_SEND_DISCOVER = 0X01, ++ GRUB_EFI_DHCP4_RCVD_OFFER, ++ GRUB_EFI_DHCP4_SELECT_OFFER, ++ GRUB_EFI_DHCP4_SEND_REQUEST, ++ GRUB_EFI_DHCP4_RCVD_ACK, ++ GRUB_EFI_DHCP4_RCVD_NAK, ++ GRUB_EFI_DHCP4_SEND_DECLINE, ++ GRUB_EFI_DHCP4_BOUND_COMPLETED, ++ GRUB_EFI_DHCP4_ENTER_RENEWING, ++ GRUB_EFI_DHCP4_ENTER_REBINDING, ++ GRUB_EFI_DHCP4_ADDRESS_LOST, ++ GRUB_EFI_DHCP4_FAIL ++}; ++ ++typedef enum grub_efi_dhcp4_event grub_efi_dhcp4_event_t; ++ ++struct grub_efi_dhcp4_packet_option { ++ grub_efi_uint8_t op_code; ++ grub_efi_uint8_t length; ++ grub_efi_uint8_t data[1]; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp4_packet_option grub_efi_dhcp4_packet_option_t; ++ ++struct grub_efi_dhcp4_config_data { ++ grub_efi_uint32_t discover_try_count; ++ grub_efi_uint32_t *discover_timeout; ++ grub_efi_uint32_t request_try_count; ++ grub_efi_uint32_t *request_timeout; ++ grub_efi_ipv4_address_t client_address; ++ grub_efi_status_t (*dhcp4_callback) ( ++ grub_efi_dhcp4_protocol_t *this, ++ void *context, ++ grub_efi_dhcp4_state_t current_state, ++ grub_efi_dhcp4_event_t dhcp4_event, ++ grub_efi_dhcp4_packet_t *packet, ++ grub_efi_dhcp4_packet_t **new_packet ++ ); ++ void *callback_context; ++ grub_efi_uint32_t option_count; ++ grub_efi_dhcp4_packet_option_t **option_list; ++}; ++ ++typedef struct grub_efi_dhcp4_config_data grub_efi_dhcp4_config_data_t; ++ ++struct grub_efi_dhcp4_mode_data { ++ grub_efi_dhcp4_state_t state; ++ grub_efi_dhcp4_config_data_t config_data; ++ grub_efi_ipv4_address_t client_address; ++ grub_efi_mac_address_t client_mac_address; ++ grub_efi_ipv4_address_t server_address; ++ grub_efi_ipv4_address_t router_address; ++ grub_efi_ipv4_address_t subnet_mask; ++ grub_efi_uint32_t lease_time; ++ grub_efi_dhcp4_packet_t *reply_packet; ++}; ++ ++typedef struct grub_efi_dhcp4_mode_data grub_efi_dhcp4_mode_data_t; ++ ++struct grub_efi_dhcp4_protocol { ++ grub_efi_status_t (*get_mode_data) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_dhcp4_mode_data_t *dhcp4_mode_data); ++ grub_efi_status_t (*configure) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_dhcp4_config_data_t *dhcp4_cfg_data); ++ grub_efi_status_t (*start) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_event_t completion_event); ++ grub_efi_status_t (*renew_rebind) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_boolean_t rebind_request, ++ grub_efi_event_t completion_event); ++ grub_efi_status_t (*release) (grub_efi_dhcp4_protocol_t *this); ++ grub_efi_status_t (*stop) (grub_efi_dhcp4_protocol_t *this); ++ grub_efi_status_t (*build) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_dhcp4_packet_t *seed_packet, ++ grub_efi_uint32_t delete_count, ++ grub_efi_uint8_t *delete_list, ++ grub_efi_uint32_t append_count, ++ grub_efi_dhcp4_packet_option_t *append_list[], ++ grub_efi_dhcp4_packet_t **new_packet); ++ grub_efi_status_t (*transmit_receive) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_dhcp4_transmit_receive_token_t *token); ++ grub_efi_status_t (*parse) (grub_efi_dhcp4_protocol_t *this, ++ grub_efi_dhcp4_packet_t *packet, ++ grub_efi_uint32_t *option_count, ++ grub_efi_dhcp4_packet_option_t *packet_option_list[]); ++}; ++ ++typedef struct grub_efi_dhcp6_protocol grub_efi_dhcp6_protocol_t; ++ ++struct grub_efi_dhcp6_retransmission { ++ grub_efi_uint32_t irt; ++ grub_efi_uint32_t mrc; ++ grub_efi_uint32_t mrt; ++ grub_efi_uint32_t mrd; ++}; ++ ++typedef struct grub_efi_dhcp6_retransmission grub_efi_dhcp6_retransmission_t; ++ ++enum grub_efi_dhcp6_event { ++ GRUB_EFI_DHCP6_SEND_SOLICIT, ++ GRUB_EFI_DHCP6_RCVD_ADVERTISE, ++ GRUB_EFI_DHCP6_SELECT_ADVERTISE, ++ GRUB_EFI_DHCP6_SEND_REQUEST, ++ GRUB_EFI_DHCP6_RCVD_REPLY, ++ GRUB_EFI_DHCP6_RCVD_RECONFIGURE, ++ GRUB_EFI_DHCP6_SEND_DECLINE, ++ GRUB_EFI_DHCP6_SEND_CONFIRM, ++ GRUB_EFI_DHCP6_SEND_RELEASE, ++ GRUB_EFI_DHCP6_SEND_RENEW, ++ GRUB_EFI_DHCP6_SEND_REBIND ++}; ++ ++typedef enum grub_efi_dhcp6_event grub_efi_dhcp6_event_t; ++ ++struct grub_efi_dhcp6_packet_option { ++ grub_efi_uint16_t op_code; ++ grub_efi_uint16_t op_len; ++ grub_efi_uint8_t data[1]; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp6_packet_option grub_efi_dhcp6_packet_option_t; ++ ++struct grub_efi_dhcp6_header { ++ grub_efi_uint32_t transaction_id:24; ++ grub_efi_uint32_t message_type:8; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp6_header grub_efi_dhcp6_header_t; ++ ++struct grub_efi_dhcp6_packet { ++ grub_efi_uint32_t size; ++ grub_efi_uint32_t length; ++ struct { ++ grub_efi_dhcp6_header_t header; ++ grub_efi_uint8_t option[1]; ++ } dhcp6; ++} GRUB_PACKED; ++ ++typedef struct grub_efi_dhcp6_packet grub_efi_dhcp6_packet_t; ++ ++struct grub_efi_dhcp6_ia_address { ++ grub_efi_ipv6_address_t ip_address; ++ grub_efi_uint32_t preferred_lifetime; ++ grub_efi_uint32_t valid_lifetime; ++}; ++ ++typedef struct grub_efi_dhcp6_ia_address grub_efi_dhcp6_ia_address_t; ++ ++enum grub_efi_dhcp6_state { ++ GRUB_EFI_DHCP6_INIT, ++ GRUB_EFI_DHCP6_SELECTING, ++ GRUB_EFI_DHCP6_REQUESTING, ++ GRUB_EFI_DHCP6_DECLINING, ++ GRUB_EFI_DHCP6_CONFIRMING, ++ GRUB_EFI_DHCP6_RELEASING, ++ GRUB_EFI_DHCP6_BOUND, ++ GRUB_EFI_DHCP6_RENEWING, ++ GRUB_EFI_DHCP6_REBINDING ++}; ++ ++typedef enum grub_efi_dhcp6_state grub_efi_dhcp6_state_t; ++ ++#define GRUB_EFI_DHCP6_IA_TYPE_NA 3 ++#define GRUB_EFI_DHCP6_IA_TYPE_TA 4 ++ ++struct grub_efi_dhcp6_ia_descriptor { ++ grub_efi_uint16_t type; ++ grub_efi_uint32_t ia_id; ++}; ++ ++typedef struct grub_efi_dhcp6_ia_descriptor grub_efi_dhcp6_ia_descriptor_t; ++ ++struct grub_efi_dhcp6_ia { ++ grub_efi_dhcp6_ia_descriptor_t descriptor; ++ grub_efi_dhcp6_state_t state; ++ grub_efi_dhcp6_packet_t *reply_packet; ++ grub_efi_uint32_t ia_address_count; ++ grub_efi_dhcp6_ia_address_t ia_address[1]; ++}; ++ ++typedef struct grub_efi_dhcp6_ia grub_efi_dhcp6_ia_t; ++ ++struct grub_efi_dhcp6_duid { ++ grub_efi_uint16_t length; ++ grub_efi_uint8_t duid[1]; ++}; ++ ++typedef struct grub_efi_dhcp6_duid grub_efi_dhcp6_duid_t; ++ ++struct grub_efi_dhcp6_mode_data { ++ grub_efi_dhcp6_duid_t *client_id; ++ grub_efi_dhcp6_ia_t *ia; ++}; ++ ++typedef struct grub_efi_dhcp6_mode_data grub_efi_dhcp6_mode_data_t; ++ ++struct grub_efi_dhcp6_config_data { ++ grub_efi_status_t (*dhcp6_callback) (grub_efi_dhcp6_protocol_t this, ++ void *context, ++ grub_efi_dhcp6_state_t current_state, ++ grub_efi_dhcp6_event_t dhcp6_event, ++ grub_efi_dhcp6_packet_t *packet, ++ grub_efi_dhcp6_packet_t **new_packet); ++ void *callback_context; ++ grub_efi_uint32_t option_count; ++ grub_efi_dhcp6_packet_option_t **option_list; ++ grub_efi_dhcp6_ia_descriptor_t ia_descriptor; ++ grub_efi_event_t ia_info_event; ++ grub_efi_boolean_t reconfigure_accept; ++ grub_efi_boolean_t rapid_commit; ++ grub_efi_dhcp6_retransmission_t *solicit_retransmission; ++}; ++ ++typedef struct grub_efi_dhcp6_config_data grub_efi_dhcp6_config_data_t; ++ ++struct grub_efi_dhcp6_protocol { ++ grub_efi_status_t (*get_mode_data) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_dhcp6_mode_data_t *dhcp6_mode_data, ++ grub_efi_dhcp6_config_data_t *dhcp6_config_data); ++ grub_efi_status_t (*configure) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_dhcp6_config_data_t *dhcp6_cfg_data); ++ grub_efi_status_t (*start) (grub_efi_dhcp6_protocol_t *this); ++ grub_efi_status_t (*info_request) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_boolean_t send_client_id, ++ grub_efi_dhcp6_packet_option_t *option_request, ++ grub_efi_uint32_t option_count, ++ grub_efi_dhcp6_packet_option_t *option_list[], ++ grub_efi_dhcp6_retransmission_t *retransmission, ++ grub_efi_event_t timeout_event, ++ grub_efi_status_t (*reply_callback) (grub_efi_dhcp6_protocol_t *this, ++ void *context, ++ grub_efi_dhcp6_packet_t *packet), ++ void *callback_context); ++ grub_efi_status_t (*renew_rebind) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_boolean_t rebind_request); ++ grub_efi_status_t (*decline) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_uint32_t address_count, ++ grub_efi_ipv6_address_t *addresses); ++ grub_efi_status_t (*release) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_uint32_t address_count, ++ grub_efi_ipv6_address_t *addresses); ++ grub_efi_status_t (*stop) (grub_efi_dhcp6_protocol_t *this); ++ grub_efi_status_t (*parse) (grub_efi_dhcp6_protocol_t *this, ++ grub_efi_dhcp6_packet_t *packet, ++ grub_efi_uint32_t *option_count, ++ grub_efi_dhcp6_packet_option_t *packet_option_list[]); ++}; ++ ++#endif /* ! GRUB_EFI_DHCP_HEADER */ +diff --git a/include/grub/efi/http.h b/include/grub/efi/http.h +new file mode 100644 +index 00000000000..c5e9a89f505 +--- /dev/null ++++ b/include/grub/efi/http.h +@@ -0,0 +1,215 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_EFI_HTTP_HEADER ++#define GRUB_EFI_HTTP_HEADER 1 ++ ++#include ++#include ++#include ++ ++#define GRUB_EFI_HTTP_SERVICE_BINDING_PROTOCOL_GUID \ ++ { 0xbdc8e6af, 0xd9bc, 0x4379, \ ++ { 0xa7, 0x2a, 0xe0, 0xc4, 0xe7, 0x5d, 0xae, 0x1c } \ ++ } ++ ++#define GRUB_EFI_HTTP_PROTOCOL_GUID \ ++ { 0x7A59B29B, 0x910B, 0x4171, \ ++ { 0x82, 0x42, 0xA8, 0x5A, 0x0D, 0xF2, 0x5B, 0x5B } \ ++ } ++ ++#define EFIHTTP_WAIT_TIME 10000 // 10000ms = 10s ++#define EFIHTTP_RX_BUF_LEN 10240 ++ ++//****************************************** ++// Protocol Interface Structure ++//****************************************** ++struct grub_efi_http; ++ ++//****************************************** ++// EFI_HTTP_VERSION ++//****************************************** ++typedef enum { ++ GRUB_EFI_HTTPVERSION10, ++ GRUB_EFI_HTTPVERSION11, ++ GRUB_EFI_HTTPVERSIONUNSUPPORTED ++} grub_efi_http_version_t; ++ ++//****************************************** ++// EFI_HTTPv4_ACCESS_POINT ++//****************************************** ++typedef struct { ++ grub_efi_boolean_t use_default_address; ++ grub_efi_ipv4_address_t local_address; ++ grub_efi_ipv4_address_t local_subnet; ++ grub_efi_uint16_t local_port; ++} grub_efi_httpv4_access_point_t; ++ ++//****************************************** ++// EFI_HTTPv6_ACCESS_POINT ++//****************************************** ++typedef struct { ++ grub_efi_ipv6_address_t local_address; ++ grub_efi_uint16_t local_port; ++} grub_efi_httpv6_access_point_t; ++ ++//****************************************** ++// EFI_HTTP_CONFIG_DATA ++//****************************************** ++typedef struct { ++ grub_efi_http_version_t http_version; ++ grub_efi_uint32_t timeout_millisec; ++ grub_efi_boolean_t local_address_is_ipv6; ++ union { ++ grub_efi_httpv4_access_point_t *ipv4_node; ++ grub_efi_httpv6_access_point_t *ipv6_node; ++ } access_point; ++} grub_efi_http_config_data_t; ++ ++//****************************************** ++// EFI_HTTP_METHOD ++//****************************************** ++typedef enum { ++ GRUB_EFI_HTTPMETHODGET, ++ GRUB_EFI_HTTPMETHODPOST, ++ GRUB_EFI_HTTPMETHODPATCH, ++ GRUB_EFI_HTTPMETHODOPTIONS, ++ GRUB_EFI_HTTPMETHODCONNECT, ++ GRUB_EFI_HTTPMETHODHEAD, ++ GRUB_EFI_HTTPMETHODPUT, ++ GRUB_EFI_HTTPMETHODDELETE, ++ GRUB_EFI_HTTPMETHODTRACE, ++} grub_efi_http_method_t; ++ ++//****************************************** ++// EFI_HTTP_REQUEST_DATA ++//****************************************** ++typedef struct { ++ grub_efi_http_method_t method; ++ grub_efi_char16_t *url; ++} grub_efi_http_request_data_t; ++ ++typedef enum { ++ GRUB_EFI_HTTP_STATUS_UNSUPPORTED_STATUS = 0, ++ GRUB_EFI_HTTP_STATUS_100_CONTINUE, ++ GRUB_EFI_HTTP_STATUS_101_SWITCHING_PROTOCOLS, ++ GRUB_EFI_HTTP_STATUS_200_OK, ++ GRUB_EFI_HTTP_STATUS_201_CREATED, ++ GRUB_EFI_HTTP_STATUS_202_ACCEPTED, ++ GRUB_EFI_HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION, ++ GRUB_EFI_HTTP_STATUS_204_NO_CONTENT, ++ GRUB_EFI_HTTP_STATUS_205_RESET_CONTENT, ++ GRUB_EFI_HTTP_STATUS_206_PARTIAL_CONTENT, ++ GRUB_EFI_HTTP_STATUS_300_MULTIPLE_CHIOCES, ++ GRUB_EFI_HTTP_STATUS_301_MOVED_PERMANENTLY, ++ GRUB_EFI_HTTP_STATUS_302_FOUND, ++ GRUB_EFI_HTTP_STATUS_303_SEE_OTHER, ++ GRUB_EFI_HTTP_STATUS_304_NOT_MODIFIED, ++ GRUB_EFI_HTTP_STATUS_305_USE_PROXY, ++ GRUB_EFI_HTTP_STATUS_307_TEMPORARY_REDIRECT, ++ GRUB_EFI_HTTP_STATUS_400_BAD_REQUEST, ++ GRUB_EFI_HTTP_STATUS_401_UNAUTHORIZED, ++ GRUB_EFI_HTTP_STATUS_402_PAYMENT_REQUIRED, ++ GRUB_EFI_HTTP_STATUS_403_FORBIDDEN, ++ GRUB_EFI_HTTP_STATUS_404_NOT_FOUND, ++ GRUB_EFI_HTTP_STATUS_405_METHOD_NOT_ALLOWED, ++ GRUB_EFI_HTTP_STATUS_406_NOT_ACCEPTABLE, ++ GRUB_EFI_HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED, ++ GRUB_EFI_HTTP_STATUS_408_REQUEST_TIME_OUT, ++ GRUB_EFI_HTTP_STATUS_409_CONFLICT, ++ GRUB_EFI_HTTP_STATUS_410_GONE, ++ GRUB_EFI_HTTP_STATUS_411_LENGTH_REQUIRED, ++ GRUB_EFI_HTTP_STATUS_412_PRECONDITION_FAILED, ++ GRUB_EFI_HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE, ++ GRUB_EFI_HTTP_STATUS_414_REQUEST_URI_TOO_LARGE, ++ GRUB_EFI_HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE, ++ GRUB_EFI_HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED, ++ GRUB_EFI_HTTP_STATUS_417_EXPECTATION_FAILED, ++ GRUB_EFI_HTTP_STATUS_500_INTERNAL_SERVER_ERROR, ++ GRUB_EFI_HTTP_STATUS_501_NOT_IMPLEMENTED, ++ GRUB_EFI_HTTP_STATUS_502_BAD_GATEWAY, ++ GRUB_EFI_HTTP_STATUS_503_SERVICE_UNAVAILABLE, ++ GRUB_EFI_HTTP_STATUS_504_GATEWAY_TIME_OUT, ++ GRUB_EFI_HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED ++} grub_efi_http_status_code_t; ++ ++//****************************************** ++// EFI_HTTP_RESPONSE_DATA ++//****************************************** ++typedef struct { ++ grub_efi_http_status_code_t status_code; ++} grub_efi_http_response_data_t; ++ ++//****************************************** ++// EFI_HTTP_HEADER ++//****************************************** ++typedef struct { ++ grub_efi_char8_t *field_name; ++ grub_efi_char8_t *field_value; ++} grub_efi_http_header_t; ++ ++//****************************************** ++// EFI_HTTP_MESSAGE ++//****************************************** ++typedef struct { ++ union { ++ grub_efi_http_request_data_t *request; ++ grub_efi_http_response_data_t *response; ++ } data; ++ grub_efi_uint32_t header_count; ++ grub_efi_http_header_t *headers; ++ grub_efi_uint32_t body_length; ++ void *body; ++} grub_efi_http_message_t; ++ ++//****************************************** ++// EFI_HTTP_TOKEN ++//****************************************** ++typedef struct { ++ grub_efi_event_t event; ++ grub_efi_status_t status; ++ grub_efi_http_message_t *message; ++} grub_efi_http_token_t; ++ ++struct grub_efi_http { ++ grub_efi_status_t ++ (*get_mode_data) (struct grub_efi_http *this, ++ grub_efi_http_config_data_t *http_config_data); ++ ++ grub_efi_status_t ++ (*configure) (struct grub_efi_http *this, ++ grub_efi_http_config_data_t *http_config_data); ++ ++ grub_efi_status_t ++ (*request) (struct grub_efi_http *this, ++ grub_efi_http_token_t *token); ++ ++ grub_efi_status_t ++ (*cancel) (struct grub_efi_http *this, ++ grub_efi_http_token_t *token); ++ ++ grub_efi_status_t ++ (*response) (struct grub_efi_http *this, ++ grub_efi_http_token_t *token); ++ ++ grub_efi_status_t ++ (*poll) (struct grub_efi_http *this); ++}; ++typedef struct grub_efi_http grub_efi_http_t; ++ ++#endif /* !GRUB_EFI_HTTP_HEADER */ +diff --git a/include/grub/net/efi.h b/include/grub/net/efi.h +new file mode 100644 +index 00000000000..de90d223e8e +--- /dev/null ++++ b/include/grub/net/efi.h +@@ -0,0 +1,144 @@ ++#ifndef GRUB_NET_EFI_HEADER ++#define GRUB_NET_EFI_HEADER 1 ++ ++#include ++#include ++#include ++#include ++ ++typedef struct grub_efi_net_interface grub_efi_net_interface_t; ++typedef struct grub_efi_net_ip_config grub_efi_net_ip_config_t; ++typedef union grub_efi_net_ip_address grub_efi_net_ip_address_t; ++typedef struct grub_efi_net_ip_manual_address grub_efi_net_ip_manual_address_t; ++ ++struct grub_efi_net_interface ++{ ++ char *name; ++ int prefer_ip6; ++ struct grub_efi_net_device *dev; ++ struct grub_efi_net_io *io; ++ grub_efi_net_ip_config_t *ip_config; ++ int io_type; ++ struct grub_efi_net_interface *next; ++}; ++ ++#define efi_net_interface_get_hw_address(inf) inf->ip_config->get_hw_address (inf->dev) ++#define efi_net_interface_get_address(inf) inf->ip_config->get_address (inf->dev) ++#define efi_net_interface_get_route_table(inf) inf->ip_config->get_route_table (inf->dev) ++#define efi_net_interface_set_address(inf, addr, with_subnet) inf->ip_config->set_address (inf->dev, addr, with_subnet) ++#define efi_net_interface_set_gateway(inf, addr) inf->ip_config->set_gateway (inf->dev, addr) ++#define efi_net_interface_set_dns(inf, addr) inf->ip_config->set_dns (inf->dev, addr) ++ ++struct grub_efi_net_ip_config ++{ ++ char * (*get_hw_address) (struct grub_efi_net_device *dev); ++ char * (*get_address) (struct grub_efi_net_device *dev); ++ char ** (*get_route_table) (struct grub_efi_net_device *dev); ++ grub_efi_net_interface_t * (*best_interface) (struct grub_efi_net_device *dev, grub_efi_net_ip_address_t *address); ++ int (*set_address) (struct grub_efi_net_device *dev, grub_efi_net_ip_manual_address_t *net_ip, int with_subnet); ++ int (*set_gateway) (struct grub_efi_net_device *dev, grub_efi_net_ip_address_t *address); ++ int (*set_dns) (struct grub_efi_net_device *dev, grub_efi_net_ip_address_t *dns); ++}; ++ ++union grub_efi_net_ip_address ++{ ++ grub_efi_ipv4_address_t ip4; ++ grub_efi_ipv6_address_t ip6; ++}; ++ ++struct grub_efi_net_ip_manual_address ++{ ++ int is_ip6; ++ union ++ { ++ grub_efi_ip4_config2_manual_address_t ip4; ++ grub_efi_ip6_config_manual_address_t ip6; ++ }; ++}; ++ ++struct grub_efi_net_device ++{ ++ grub_efi_handle_t handle; ++ grub_efi_ip4_config2_protocol_t *ip4_config; ++ grub_efi_ip6_config_protocol_t *ip6_config; ++ grub_efi_handle_t http_handle; ++ grub_efi_http_t *http; ++ grub_efi_handle_t ip4_pxe_handle; ++ grub_efi_pxe_t *ip4_pxe; ++ grub_efi_handle_t ip6_pxe_handle; ++ grub_efi_pxe_t *ip6_pxe; ++ grub_efi_handle_t dhcp4_handle; ++ grub_efi_dhcp4_protocol_t *dhcp4; ++ grub_efi_handle_t dhcp6_handle; ++ grub_efi_dhcp6_protocol_t *dhcp6; ++ char *card_name; ++ grub_efi_net_interface_t *net_interfaces; ++ struct grub_efi_net_device *next; ++}; ++ ++struct grub_efi_net_io ++{ ++ void (*configure) (struct grub_efi_net_device *dev, int prefer_ip6); ++ grub_err_t (*open) (struct grub_efi_net_device *dev, ++ int prefer_ip6, ++ grub_file_t file, ++ const char *filename, ++ int type); ++ grub_ssize_t (*read) (struct grub_efi_net_device *dev, ++ int prefer_ip6, ++ grub_file_t file, ++ char *buf, ++ grub_size_t len); ++ grub_err_t (*close) (struct grub_efi_net_device *dev, ++ int prefer_ip6, ++ grub_file_t file); ++}; ++ ++extern struct grub_efi_net_device *net_devices; ++ ++extern struct grub_efi_net_io io_http; ++extern struct grub_efi_net_io io_pxe; ++ ++extern grub_efi_net_ip_config_t *efi_net_ip4_config; ++extern grub_efi_net_ip_config_t *efi_net_ip6_config; ++ ++char * ++grub_efi_ip4_address_to_string (grub_efi_ipv4_address_t *address); ++ ++char * ++grub_efi_ip6_address_to_string (grub_efi_pxe_ipv6_address_t *address); ++ ++char * ++grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_address_t hw_address); ++ ++int ++grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest); ++ ++int ++grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *address, const char **rest); ++ ++char * ++grub_efi_ip6_interface_name (struct grub_efi_net_device *dev); ++ ++char * ++grub_efi_ip4_interface_name (struct grub_efi_net_device *dev); ++ ++grub_efi_net_interface_t * ++grub_efi_net_create_interface (struct grub_efi_net_device *dev, ++ const char *interface_name, ++ grub_efi_net_ip_manual_address_t *net_ip, ++ int has_subnet); ++ ++int grub_efi_net_fs_init (void); ++void grub_efi_net_fs_fini (void); ++int grub_efi_net_boot_from_https (void); ++int grub_efi_net_boot_from_opa (void); ++ ++extern grub_command_func_t grub_efi_net_list_routes; ++extern grub_command_func_t grub_efi_net_list_cards; ++extern grub_command_func_t grub_efi_net_list_addrs; ++extern grub_command_func_t grub_efi_net_add_addr; ++extern grub_command_func_t grub_efi_net_bootp; ++extern grub_command_func_t grub_efi_net_bootp6; ++ ++#endif /* ! GRUB_NET_EFI_HEADER */ diff --git a/0120-AUDIT-0-http-boot-tracker-bug.patch b/0120-AUDIT-0-http-boot-tracker-bug.patch new file mode 100644 index 0000000..78a78e4 --- /dev/null +++ b/0120-AUDIT-0-http-boot-tracker-bug.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Sebastian Krahmer +Date: Tue, 28 Nov 2017 17:24:38 +0800 +Subject: [PATCH] AUDIT-0: http boot tracker bug + +Fixing a memory leak in case of error, and a integer overflow, leading to a +heap overflow due to overly large chunk sizes. + +We need to check against some maximum value, otherwise values like 0xffffffff +will eventually lead in the allocation functions to small sized buffers, since +the len is rounded up to the next reasonable alignment. The following memcpy +will then smash the heap, leading to RCE. + +This is no big issue for pure http boot, since its going to execute an +untrusted kernel anyway, but it will break trusted boot scenarios, where only +signed code is allowed to be executed. + +Signed-off-by: Michael Chang +--- + grub-core/net/efi/net.c | 4 +++- + grub-core/net/http.c | 5 ++++- + 2 files changed, 7 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 86bce6535d3..4bb308026ce 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -645,8 +645,10 @@ grub_efihttp_chunk_read (grub_file_t file, char *buf, + + rd = efi_net_interface (read, file, chunk, sz); + +- if (rd <= 0) ++ if (rd <= 0) { ++ grub_free (chunk); + return rd; ++ } + + if (buf) + { +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index 00737c52750..c9c59690a98 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -31,7 +31,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + enum + { +- HTTP_PORT = 80 ++ HTTP_PORT = 80, ++ HTTP_MAX_CHUNK_SIZE = 0x80000000 + }; + + +@@ -78,6 +79,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + if (data->in_chunk_len == 2) + { + data->chunk_rem = grub_strtoul (ptr, 0, 16); ++ if (data->chunk_rem > HTTP_MAX_CHUNK_SIZE) ++ return GRUB_ERR_NET_PACKET_TOO_BIG; + grub_errno = GRUB_ERR_NONE; + if (data->chunk_rem == 0) + { diff --git a/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch b/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch new file mode 100644 index 0000000..33cde3b --- /dev/null +++ b/0121-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexander Graf +Date: Wed, 1 Feb 2017 23:10:45 +0100 +Subject: [PATCH] grub-core/video/efi_gop.c: Add support for BLT_ONLY adapters + +EFI GOP has support for multiple different bitness types of frame buffers +and for a special "BLT only" type which is always defined to be RGBx. + +Because grub2 doesn't ever directly access the frame buffer but instead +only renders graphics via the BLT interface anyway, we can easily support +these adapters. + +The reason this has come up now is the emerging support for virtio-gpu +in OVMF. That adapter does not have the notion of a memory mapped frame +buffer and thus is BLT only. + +Signed-off-by: Alexander Graf +--- + grub-core/video/efi_gop.c | 2 ++ + include/grub/efi/graphics_output.h | 3 ++- + 2 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c +index 7f9d1c2dfa1..c9e40e8d4e9 100644 +--- a/grub-core/video/efi_gop.c ++++ b/grub-core/video/efi_gop.c +@@ -121,6 +121,7 @@ grub_video_gop_get_bpp (struct grub_efi_gop_mode_info *in) + { + case GRUB_EFI_GOT_BGRA8: + case GRUB_EFI_GOT_RGBA8: ++ case GRUB_EFI_GOT_BLT_ONLY: + return 32; + + case GRUB_EFI_GOT_BITMASK: +@@ -187,6 +188,7 @@ grub_video_gop_fill_real_mode_info (unsigned mode, + switch (in->pixel_format) + { + case GRUB_EFI_GOT_RGBA8: ++ case GRUB_EFI_GOT_BLT_ONLY: + out->red_mask_size = 8; + out->red_field_pos = 0; + out->green_mask_size = 8; +diff --git a/include/grub/efi/graphics_output.h b/include/grub/efi/graphics_output.h +index 12977741192..e4388127c66 100644 +--- a/include/grub/efi/graphics_output.h ++++ b/include/grub/efi/graphics_output.h +@@ -28,7 +28,8 @@ typedef enum + { + GRUB_EFI_GOT_RGBA8, + GRUB_EFI_GOT_BGRA8, +- GRUB_EFI_GOT_BITMASK ++ GRUB_EFI_GOT_BITMASK, ++ GRUB_EFI_GOT_BLT_ONLY, + } + grub_efi_gop_pixel_format_t; + diff --git a/0122-efi-uga-use-64-bit-for-fb_base.patch b/0122-efi-uga-use-64-bit-for-fb_base.patch new file mode 100644 index 0000000..bafcb64 --- /dev/null +++ b/0122-efi-uga-use-64-bit-for-fb_base.patch @@ -0,0 +1,105 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrei Borzenkov +Date: Wed, 16 May 2018 13:06:04 -0400 +Subject: [PATCH] efi/uga: use 64 bit for fb_base + +We get 64 bit from PCI BAR but then truncate by assigning to 32 bit. +Make sure to check that pointer does not overflow on 32 bit platform. + +Closes: 50931 +--- + grub-core/video/efi_uga.c | 31 ++++++++++++++++--------------- + 1 file changed, 16 insertions(+), 15 deletions(-) + +diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c +index 044af1d20d3..97a607c01a5 100644 +--- a/grub-core/video/efi_uga.c ++++ b/grub-core/video/efi_uga.c +@@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; + static struct grub_efi_uga_draw_protocol *uga; +-static grub_uint32_t uga_fb; ++static grub_uint64_t uga_fb; + static grub_uint32_t uga_pitch; + + static struct +@@ -52,7 +52,7 @@ static struct + #define FBTEST_COUNT 8 + + static int +-find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) ++find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) + { + grub_uint32_t *base = (grub_uint32_t *) (grub_addr_t) *fb_base; + int i; +@@ -67,7 +67,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) + { + if ((base[j] & RGB_MASK) == RGB_MAGIC) + { +- *fb_base = (grub_uint32_t) (grub_addr_t) base; ++ *fb_base = (grub_uint64_t) (grub_addr_t) base; + *line_len = j << 2; + + return 1; +@@ -84,7 +84,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) + /* Context for find_framebuf. */ + struct find_framebuf_ctx + { +- grub_uint32_t *fb_base; ++ grub_uint64_t *fb_base; + grub_uint32_t *line_len; + int found; + }; +@@ -129,7 +129,9 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + if (i == 5) + break; + +- old_bar2 = grub_pci_read (addr + 4); ++ i++; ++ addr += 4; ++ old_bar2 = grub_pci_read (addr); + } + else + old_bar2 = 0; +@@ -138,10 +140,15 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + base64 <<= 32; + base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); + +- grub_dprintf ("fb", "%s(%d): 0x%llx\n", ++ grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", + ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? +- "VMEM" : "MMIO"), i, +- (unsigned long long) base64); ++ "VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i, ++ base64); ++ ++#if GRUB_CPU_SIZEOF_VOID_P == 4 ++ if (old_bar2) ++ continue; ++#endif + + if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! ctx->found)) + { +@@ -149,12 +156,6 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + if (find_line_len (ctx->fb_base, ctx->line_len)) + ctx->found++; + } +- +- if (type == GRUB_PCI_ADDR_MEM_TYPE_64) +- { +- i++; +- addr += 4; +- } + } + } + +@@ -162,7 +163,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + } + + static int +-find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) ++find_framebuf (grub_uint64_t *fb_base, grub_uint32_t *line_len) + { + struct find_framebuf_ctx ctx = { + .fb_base = fb_base, diff --git a/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch b/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch new file mode 100644 index 0000000..20aadf6 --- /dev/null +++ b/0123-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch @@ -0,0 +1,184 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 6 Mar 2018 17:11:15 +0100 +Subject: [PATCH] EFI: console: Do not set text-mode until we actually need it + +If we're running with a hidden menu we may never need text mode, so do not +change the video-mode to text until we actually need it. + +Signed-off-by: Hans de Goede +--- + grub-core/term/efi/console.c | 65 ++++++++++++++++++++++++++++++-------------- + 1 file changed, 44 insertions(+), 21 deletions(-) + +diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c +index 4840cc59d3f..051633d71e9 100644 +--- a/grub-core/term/efi/console.c ++++ b/grub-core/term/efi/console.c +@@ -24,6 +24,11 @@ + #include + #include + ++static grub_err_t grub_prepare_for_text_output(struct grub_term_output *term); ++ ++static int text_mode_available = -1; ++static int text_colorstate = -1; ++ + static grub_uint32_t + map_char (grub_uint32_t c) + { +@@ -66,14 +71,14 @@ map_char (grub_uint32_t c) + } + + static void +-grub_console_putchar (struct grub_term_output *term __attribute__ ((unused)), ++grub_console_putchar (struct grub_term_output *term, + const struct grub_unicode_glyph *c) + { + grub_efi_char16_t str[2 + 30]; + grub_efi_simple_text_output_interface_t *o; + unsigned i, j; + +- if (grub_efi_is_finished) ++ if (grub_prepare_for_text_output (term)) + return; + + o = grub_efi_system_table->con_out; +@@ -223,14 +228,15 @@ grub_console_getkey (struct grub_term_input *term) + } + + static struct grub_term_coordinate +-grub_console_getwh (struct grub_term_output *term __attribute__ ((unused))) ++grub_console_getwh (struct grub_term_output *term) + { + grub_efi_simple_text_output_interface_t *o; + grub_efi_uintn_t columns, rows; + + o = grub_efi_system_table->con_out; +- if (grub_efi_is_finished || efi_call_4 (o->query_mode, o, o->mode->mode, +- &columns, &rows) != GRUB_EFI_SUCCESS) ++ if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE || ++ efi_call_4 (o->query_mode, o, o->mode->mode, ++ &columns, &rows) != GRUB_EFI_SUCCESS) + { + /* Why does this fail? */ + columns = 80; +@@ -245,7 +251,7 @@ grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) + { + grub_efi_simple_text_output_interface_t *o; + +- if (grub_efi_is_finished) ++ if (grub_efi_is_finished || text_mode_available != 1) + return (struct grub_term_coordinate) { 0, 0 }; + + o = grub_efi_system_table->con_out; +@@ -253,12 +259,12 @@ grub_console_getxy (struct grub_term_output *term __attribute__ ((unused))) + } + + static void +-grub_console_gotoxy (struct grub_term_output *term __attribute__ ((unused)), ++grub_console_gotoxy (struct grub_term_output *term, + struct grub_term_coordinate pos) + { + grub_efi_simple_text_output_interface_t *o; + +- if (grub_efi_is_finished) ++ if (grub_prepare_for_text_output (term)) + return; + + o = grub_efi_system_table->con_out; +@@ -271,7 +277,7 @@ grub_console_cls (struct grub_term_output *term __attribute__ ((unused))) + grub_efi_simple_text_output_interface_t *o; + grub_efi_int32_t orig_attr; + +- if (grub_efi_is_finished) ++ if (grub_efi_is_finished || text_mode_available != 1) + return; + + o = grub_efi_system_table->con_out; +@@ -291,6 +297,12 @@ grub_console_setcolorstate (struct grub_term_output *term + if (grub_efi_is_finished) + return; + ++ if (text_mode_available != 1) { ++ /* Avoid "color_normal" environment writes causing a switch to textmode */ ++ text_colorstate = state; ++ return; ++ } ++ + o = grub_efi_system_table->con_out; + + switch (state) { +@@ -315,7 +327,7 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), + { + grub_efi_simple_text_output_interface_t *o; + +- if (grub_efi_is_finished) ++ if (grub_efi_is_finished || text_mode_available != 1) + return; + + o = grub_efi_system_table->con_out; +@@ -323,18 +335,38 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)), + } + + static grub_err_t +-grub_efi_console_output_init (struct grub_term_output *term) ++grub_prepare_for_text_output(struct grub_term_output *term) + { +- grub_efi_set_text_mode (1); ++ if (grub_efi_is_finished) ++ return GRUB_ERR_BAD_DEVICE; ++ ++ if (text_mode_available != -1) ++ return text_mode_available ? 0 : GRUB_ERR_BAD_DEVICE; ++ ++ if (! grub_efi_set_text_mode (1)) ++ { ++ /* This really should never happen */ ++ grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); ++ text_mode_available = 0; ++ return GRUB_ERR_BAD_DEVICE; ++ } ++ + grub_console_setcursor (term, 1); ++ if (text_colorstate != -1) ++ grub_console_setcolorstate (term, text_colorstate); ++ text_mode_available = 1; + return 0; + } + + static grub_err_t + grub_efi_console_output_fini (struct grub_term_output *term) + { ++ if (text_mode_available != 1) ++ return 0; ++ + grub_console_setcursor (term, 0); + grub_efi_set_text_mode (0); ++ text_mode_available = -1; + return 0; + } + +@@ -348,7 +380,6 @@ static struct grub_term_input grub_console_term_input = + static struct grub_term_output grub_console_term_output = + { + .name = "console", +- .init = grub_efi_console_output_init, + .fini = grub_efi_console_output_fini, + .putchar = grub_console_putchar, + .getwh = grub_console_getwh, +@@ -364,14 +395,6 @@ static struct grub_term_output grub_console_term_output = + void + grub_console_init (void) + { +- /* FIXME: it is necessary to consider the case where no console control +- is present but the default is already in text mode. */ +- if (! grub_efi_set_text_mode (1)) +- { +- grub_error (GRUB_ERR_BAD_DEVICE, "cannot set text mode"); +- return; +- } +- + grub_term_register_output ("console", &grub_console_term_output); + grub_term_register_input ("console", &grub_console_term_input); + } diff --git a/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch b/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch new file mode 100644 index 0000000..6da36b2 --- /dev/null +++ b/0124-EFI-console-Add-grub_console_read_key_stroke-helper-.patch @@ -0,0 +1,102 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 6 Jun 2018 15:54:44 +0200 +Subject: [PATCH] EFI: console: Add grub_console_read_key_stroke() helper + function + +This is a preparation patch for adding getkeystatus() support to the +EFI console terminal input driver. + +We can get modifier status through the simple_text_input read_key_stroke +method, but if a non-modifier key is (also) pressed the read_key_stroke +call will consume that key from the firmware's queue. + +The new grub_console_read_key_stroke() helper buffers upto 1 key-stroke. +If it has a non-modifier key buffered, it will return that one, if its +buffer is empty, it will fills its buffer by getting a new key-stroke. + +If called with consume=1 it will empty its buffer after copying the +key-data to the callers buffer, this is how getkey() will use it. + +If called with consume=0 it will keep the last key-stroke buffered, this +is how getkeystatus() will call it. This means that if a non-modifier +key gets pressed, repeated getkeystatus() calls will return the modifiers +of that key-press until it is consumed by a getkey() call. + +Signed-off-by: Hans de Goede +--- + grub-core/term/efi/console.c | 51 ++++++++++++++++++++++++++++++++++---------- + 1 file changed, 40 insertions(+), 11 deletions(-) + +diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c +index 051633d71e9..3d36c5c701b 100644 +--- a/grub-core/term/efi/console.c ++++ b/grub-core/term/efi/console.c +@@ -157,27 +157,56 @@ grub_console_getkey_con (struct grub_term_input *term __attribute__ ((unused))) + return grub_efi_translate_key(key); + } + ++/* ++ * When more then just modifiers are pressed, our getkeystatus() consumes a ++ * press from the queue, this function buffers the press for the regular ++ * getkey() so that it does not get lost. ++ */ ++static int ++grub_console_read_key_stroke ( ++ grub_efi_simple_text_input_ex_interface_t *text_input, ++ grub_efi_key_data_t *key_data_ret, int *key_ret, ++ int consume) ++{ ++ static grub_efi_key_data_t key_data; ++ grub_efi_status_t status; ++ int key; ++ ++ if (!text_input) ++ return GRUB_ERR_EOF; ++ ++ key = grub_efi_translate_key (key_data.key); ++ if (key == GRUB_TERM_NO_KEY) { ++ status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data); ++ if (status != GRUB_EFI_SUCCESS) ++ return GRUB_ERR_EOF; ++ ++ key = grub_efi_translate_key (key_data.key); ++ } ++ ++ *key_data_ret = key_data; ++ *key_ret = key; ++ ++ if (consume) { ++ key_data.key.scan_code = 0; ++ key_data.key.unicode_char = 0; ++ } ++ ++ return 0; ++} ++ + static int + grub_console_getkey_ex(struct grub_term_input *term) + { + grub_efi_key_data_t key_data; +- grub_efi_status_t status; + grub_efi_uint32_t kss; + int key = -1; + +- grub_efi_simple_text_input_ex_interface_t *text_input = term->data; +- +- status = efi_call_2 (text_input->read_key_stroke, text_input, &key_data); +- +- if (status != GRUB_EFI_SUCCESS) ++ if (grub_console_read_key_stroke (term->data, &key_data, &key, 1) || ++ key == GRUB_TERM_NO_KEY) + return GRUB_TERM_NO_KEY; + + kss = key_data.key_state.key_shift_state; +- key = grub_efi_translate_key(key_data.key); +- +- if (key == GRUB_TERM_NO_KEY) +- return GRUB_TERM_NO_KEY; +- + if (kss & GRUB_EFI_SHIFT_STATE_VALID) + { + if ((kss & GRUB_EFI_LEFT_SHIFT_PRESSED diff --git a/0125-EFI-console-Implement-getkeystatus-support.patch b/0125-EFI-console-Implement-getkeystatus-support.patch new file mode 100644 index 0000000..74fa253 --- /dev/null +++ b/0125-EFI-console-Implement-getkeystatus-support.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 6 Jun 2018 16:16:47 +0200 +Subject: [PATCH] EFI: console: Implement getkeystatus() support + +Implement getkeystatus() support. + +Note that if a non-modifier key gets pressed and repeated calls to +getkeystatus() are made then it will return the modifier status at the +time of the non-modifier key, until that key-press gets consumed by a +getkey() call. + +This is a side-effect of how the EFI simple-text-input protocol works +and cannot be avoided. + +Signed-off-by: Hans de Goede +--- + grub-core/term/efi/console.c | 34 ++++++++++++++++++++++++++++++++++ + 1 file changed, 34 insertions(+) + +diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c +index 3d36c5c701b..92dd4996bb7 100644 +--- a/grub-core/term/efi/console.c ++++ b/grub-core/term/efi/console.c +@@ -223,6 +223,39 @@ grub_console_getkey_ex(struct grub_term_input *term) + return key; + } + ++static int ++grub_console_getkeystatus(struct grub_term_input *term) ++{ ++ grub_efi_key_data_t key_data; ++ grub_efi_uint32_t kss; ++ int key, mods = 0; ++ ++ if (grub_efi_is_finished) ++ return 0; ++ ++ if (grub_console_read_key_stroke (term->data, &key_data, &key, 0)) ++ return 0; ++ ++ kss = key_data.key_state.key_shift_state; ++ if (kss & GRUB_EFI_SHIFT_STATE_VALID) ++ { ++ if (kss & GRUB_EFI_LEFT_SHIFT_PRESSED) ++ mods |= GRUB_TERM_STATUS_LSHIFT; ++ if (kss & GRUB_EFI_RIGHT_SHIFT_PRESSED) ++ mods |= GRUB_TERM_STATUS_RSHIFT; ++ if (kss & GRUB_EFI_LEFT_ALT_PRESSED) ++ mods |= GRUB_TERM_STATUS_LALT; ++ if (kss & GRUB_EFI_RIGHT_ALT_PRESSED) ++ mods |= GRUB_TERM_STATUS_RALT; ++ if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED) ++ mods |= GRUB_TERM_STATUS_LCTRL; ++ if (kss & GRUB_EFI_RIGHT_CONTROL_PRESSED) ++ mods |= GRUB_TERM_STATUS_RCTRL; ++ } ++ ++ return mods; ++} ++ + static grub_err_t + grub_efi_console_input_init (struct grub_term_input *term) + { +@@ -403,6 +436,7 @@ static struct grub_term_input grub_console_term_input = + { + .name = "console", + .getkey = grub_console_getkey, ++ .getkeystatus = grub_console_getkeystatus, + .init = grub_efi_console_input_init, + }; + diff --git a/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch b/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch new file mode 100644 index 0000000..9840a55 --- /dev/null +++ b/0126-Make-grub_getkeystatus-helper-funtion-available-ever.patch @@ -0,0 +1,87 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 6 Jun 2018 16:47:11 +0200 +Subject: [PATCH] Make grub_getkeystatus helper funtion available everywhere + +Move the grub_getkeystatus helper function from +grub-core/commands/keystatus.c to grub-core/kern/term.c +and export it so that it can be used outside of the +keystatus command code too. + +Signed-off-by: Hans de Goede +--- + grub-core/commands/keystatus.c | 18 ------------------ + grub-core/kern/term.c | 18 ++++++++++++++++++ + include/grub/term.h | 1 + + 3 files changed, 19 insertions(+), 18 deletions(-) + +diff --git a/grub-core/commands/keystatus.c b/grub-core/commands/keystatus.c +index 460cf4e7e50..ff3f5878163 100644 +--- a/grub-core/commands/keystatus.c ++++ b/grub-core/commands/keystatus.c +@@ -35,24 +35,6 @@ static const struct grub_arg_option options[] = + {0, 0, 0, 0, 0, 0} + }; + +-static int +-grub_getkeystatus (void) +-{ +- int status = 0; +- grub_term_input_t term; +- +- if (grub_term_poll_usb) +- grub_term_poll_usb (0); +- +- FOR_ACTIVE_TERM_INPUTS(term) +- { +- if (term->getkeystatus) +- status |= term->getkeystatus (term); +- } +- +- return status; +-} +- + static grub_err_t + grub_cmd_keystatus (grub_extcmd_context_t ctxt, + int argc __attribute__ ((unused)), +diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c +index 07720ee6746..93bd3378d18 100644 +--- a/grub-core/kern/term.c ++++ b/grub-core/kern/term.c +@@ -120,6 +120,24 @@ grub_getkey (void) + } + } + ++int ++grub_getkeystatus (void) ++{ ++ int status = 0; ++ grub_term_input_t term; ++ ++ if (grub_term_poll_usb) ++ grub_term_poll_usb (0); ++ ++ FOR_ACTIVE_TERM_INPUTS(term) ++ { ++ if (term->getkeystatus) ++ status |= term->getkeystatus (term); ++ } ++ ++ return status; ++} ++ + void + grub_refresh (void) + { +diff --git a/include/grub/term.h b/include/grub/term.h +index 8117e2a24da..c215133383f 100644 +--- a/include/grub/term.h ++++ b/include/grub/term.h +@@ -327,6 +327,7 @@ grub_term_unregister_output (grub_term_output_t term) + void grub_putcode (grub_uint32_t code, struct grub_term_output *term); + int EXPORT_FUNC(grub_getkey) (void); + int EXPORT_FUNC(grub_getkey_noblock) (void); ++int EXPORT_FUNC(grub_getkeystatus) (void); + void grub_cls (void); + void EXPORT_FUNC(grub_refresh) (void); + void grub_puts_terminal (const char *str, struct grub_term_output *term); diff --git a/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch b/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch new file mode 100644 index 0000000..e62a619 --- /dev/null +++ b/0127-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch @@ -0,0 +1,94 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Mon, 26 Mar 2018 16:15:53 +0200 +Subject: [PATCH] Accept ESC, F8 and holding SHIFT as user interrupt keys + +On some devices the ESC key is the hotkey to enter the BIOS/EFI setup +screen, making it really hard to time pressing it right. Besides that +ESC is also pretty hard to discover for a user who does not know it +will unhide the menu. + +This commit makes F8, which used to be the hotkey to show the Windows +boot menu during boot for a long long time, also interrupt sleeps / +stop the menu countdown. + +This solves the ESC gets into the BIOS setup and also somewhat solves +the discoverability issue, but leaves the timing issue unresolved. + +This commit fixes the timing issue by also adding support for keeping +SHIFT pressed during boot to stop the menu countdown. This matches +what Ubuntu is doing, which should also help with discoverability. + +Signed-off-by: Hans de Goede +--- + grub-core/commands/sleep.c | 2 +- + grub-core/kern/term.c | 16 ++++++++++++++++ + grub-core/normal/menu.c | 2 +- + include/grub/term.h | 1 + + 4 files changed, 19 insertions(+), 2 deletions(-) + +diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c +index e77e7900fac..a1370b710c9 100644 +--- a/grub-core/commands/sleep.c ++++ b/grub-core/commands/sleep.c +@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) + start = grub_get_time_ms (); + + while (grub_get_time_ms () - start < ms) +- if (grub_getkey_noblock () == GRUB_TERM_ESC) ++ if (grub_key_is_interrupt (grub_getkey_noblock ())) + return 1; + + return 0; +diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c +index 93bd3378d18..6cae4c23e7a 100644 +--- a/grub-core/kern/term.c ++++ b/grub-core/kern/term.c +@@ -138,6 +138,22 @@ grub_getkeystatus (void) + return status; + } + ++int ++grub_key_is_interrupt (int key) ++{ ++ /* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also ++ check F8, which was the key to get the Windows bootmenu for a long time. */ ++ if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F8) ++ return 1; ++ ++ /* Pressing keys at the right time during boot is hard to time, also allow ++ interrupting sleeps / the menu countdown by keeping shift pressed. */ ++ if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT|GRUB_TERM_STATUS_RSHIFT)) ++ return 1; ++ ++ return 0; ++} ++ + void + grub_refresh (void) + { +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 783bde55b9e..046a1fb2c84 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -655,7 +655,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) + if (entry >= 0) + break; + } +- if (key == GRUB_TERM_ESC) ++ if (grub_key_is_interrupt (key)) + { + timeout = -1; + break; +diff --git a/include/grub/term.h b/include/grub/term.h +index c215133383f..2b079c29b80 100644 +--- a/include/grub/term.h ++++ b/include/grub/term.h +@@ -328,6 +328,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term_output *term); + int EXPORT_FUNC(grub_getkey) (void); + int EXPORT_FUNC(grub_getkey_noblock) (void); + int EXPORT_FUNC(grub_getkeystatus) (void); ++int EXPORT_FUNC(grub_key_is_interrupt) (int key); + void grub_cls (void); + void EXPORT_FUNC(grub_refresh) (void); + void grub_puts_terminal (const char *str, struct grub_term_output *term); diff --git a/0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch b/0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch new file mode 100644 index 0000000..5da986f --- /dev/null +++ b/0128-grub-editenv-Add-incr-command-to-increment-integer-v.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Mon, 4 Jun 2018 19:49:47 +0200 +Subject: [PATCH] grub-editenv: Add "incr" command to increment integer value + env. variables + +To be able to automatically detect if the last boot was successful, +We want to keep count of succesful / failed boots in some integer +environment variable. + +This commit adds a grub-editenvt "incr" command to increment such +integer value env. variables by 1 for use from various boot scripts. + +Signed-off-by: Hans de Goede +--- + util/grub-editenv.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +diff --git a/util/grub-editenv.c b/util/grub-editenv.c +index f3662c95ba6..d848038abea 100644 +--- a/util/grub-editenv.c ++++ b/util/grub-editenv.c +@@ -53,6 +53,9 @@ static struct argp_option options[] = { + /* TRANSLATORS: "unset" is a keyword. It's a summary of "unset" subcommand. */ + {N_("unset [NAME ...]"), 0, 0, OPTION_DOC|OPTION_NO_USAGE, + N_("Delete variables."), 0}, ++ /* TRANSLATORS: "incr" is a keyword. It's a summary of "incr" subcommand. */ ++ {N_("incr [NAME ...]"), 0, 0, OPTION_DOC|OPTION_NO_USAGE, ++ N_("Increase value of integer variables."), 0}, + + {0, 0, 0, OPTION_DOC, N_("Options:"), -1}, + {"verbose", 'v', 0, 0, N_("print verbose messages."), 0}, +@@ -247,6 +250,51 @@ unset_variables (const char *name, int argc, char *argv[]) + grub_envblk_close (envblk); + } + ++struct get_int_value_params { ++ char *varname; ++ int value; ++}; ++ ++static int ++get_int_value (const char *varname, const char *value, void *hook_data) ++{ ++ struct get_int_value_params *params = hook_data; ++ ++ if (strcmp (varname, params->varname) == 0) { ++ params->value = strtol (value, NULL, 10); ++ return 1; ++ } ++ return 0; ++} ++ ++static void ++incr_variables (const char *name, int argc, char *argv[]) ++{ ++ grub_envblk_t envblk; ++ char buf[16]; ++ ++ envblk = open_envblk_file (name); ++ while (argc) ++ { ++ struct get_int_value_params params = { ++ .varname = argv[0], ++ .value = 0, /* Consider unset variables 0 */ ++ }; ++ ++ grub_envblk_iterate (envblk, ¶ms, get_int_value); ++ snprintf(buf, sizeof(buf), "%d", params.value + 1); ++ ++ if (! grub_envblk_set (envblk, argv[0], buf)) ++ grub_util_error ("%s", _("environment block too small")); ++ ++ argc--; ++ argv++; ++ } ++ ++ write_envblk (name, envblk); ++ grub_envblk_close (envblk); ++} ++ + int + main (int argc, char *argv[]) + { +@@ -286,6 +334,8 @@ main (int argc, char *argv[]) + set_variables (filename, argc - curindex, argv + curindex); + else if (strcmp (command, "unset") == 0) + unset_variables (filename, argc - curindex, argv + curindex); ++ else if (strcmp (command, "incr") == 0) ++ incr_variables (filename, argc - curindex, argv + curindex); + else + { + char *program = xstrdup(program_name); diff --git a/0129-Add-auto-hide-menu-support.patch b/0129-Add-auto-hide-menu-support.patch new file mode 100644 index 0000000..0afa74a --- /dev/null +++ b/0129-Add-auto-hide-menu-support.patch @@ -0,0 +1,189 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 6 Jun 2018 08:44:11 +0200 +Subject: [PATCH] Add auto-hide menu support + +On single-os systems we do not want to show the menu, unless something +went wrong with the previous boot, in which case the user may need the +menu to debug/fix the problem. + +This commit adds a new grub.d/00_menu_auto_hide file which emits a +config snippet implementing this. I've chosen to do this in a separate +grub.d file because chances of this going upstream are small and this way +it will be easier to rebase. + +Since auto-hiding the menu requires detecting the previous boot was ok, +we get fastboot support (where we don't check for a key at all) for free +so this commit also adds support for this. + +The new config-file code uses the following variables: + +menu_auto_hide Set this to "1" to activate the new auto-hide feature + Set this to "2" to auto-hide the menu even when multiple + operating systems are installed. Note the menu will still + auto show after booting an other os as that won't set + boot_success. +menu_show_once Set this to "1" to force showing the menu once. +boot_success The OS sets this to "1" to indicate a successful boot. +boot_indeterminate The OS increments this integer when rebooting after e.g. + installing updates or a selinux relabel. +fastboot If set to "1" and the conditions for auto-hiding the menu + are met, the menu is not shown and all checks for keypresses + are skipped, booting the default immediately. + +30_os-prober.in changes somewhat inspired by: +https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/quick_boot.patch + +Signed-off-by: Hans de Goede +--- +Changes in v2: +-Drop shutdown_success tests, there is no meaningful way for systemd to set + this flag (by the time it knows all filesystems are unmounted or read-only +-Drop fwsetup_once support, systemd already supports booting directly into + the fwsetup by doing "systemctl reboot --firmware" +--- + Makefile.util.def | 6 +++++ + util/grub.d/01_menu_auto_hide.in | 48 ++++++++++++++++++++++++++++++++++++++++ + util/grub.d/30_os-prober.in | 18 +++++++++++++++ + 3 files changed, 72 insertions(+) + create mode 100644 util/grub.d/01_menu_auto_hide.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index c13ca685ce1..026b458bb85 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -457,6 +457,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '01_menu_auto_hide'; ++ common = util/grub.d/01_menu_auto_hide.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '01_users'; + common = util/grub.d/01_users.in; +diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/01_menu_auto_hide.in +new file mode 100644 +index 00000000000..ad175870a54 +--- /dev/null ++++ b/util/grub.d/01_menu_auto_hide.in +@@ -0,0 +1,48 @@ ++#! /bin/sh ++ ++# Disable / skip generating menu-auto-hide config parts on serial terminals ++for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do ++ case "$x" in ++ serial*) ++ exit 0 ++ ;; ++ esac ++done ++ ++cat << EOF ++if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then ++ set last_boot_ok=1 ++else ++ set last_boot_ok=0 ++fi ++ ++# Reset boot_indeterminate after a successful boot ++if [ "\${boot_success}" = "1" ] ; then ++ set boot_indeterminate=0 ++# Avoid boot_indeterminate causing the menu to be hidden more then once ++elif [ "\${boot_indeterminate}" = "1" ]; then ++ set boot_indeterminate=2 ++fi ++set boot_success=0 ++save_env boot_success boot_indeterminate ++ ++if [ x\$feature_timeout_style = xy ] ; then ++ if [ "\${menu_show_once}" ]; then ++ unset menu_show_once ++ save_env menu_show_once ++ set timeout_style=menu ++ set timeout=60 ++ elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then ++ set orig_timeout_style=\${timeout_style} ++ set orig_timeout=\${timeout} ++ if [ "\${fastboot}" = "1" ]; then ++ # timeout_style=menu + timeout=0 avoids the countdown code keypress check ++ set timeout_style=menu ++ set timeout=0 ++ else ++ set timeout_style=hidden ++ set timeout=1 ++ fi ++ fi ++fi ++EOF +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 13a3a6bc752..ab634393a31 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -42,6 +42,7 @@ if [ -z "${OSPROBED}" ] ; then + fi + + osx_entry() { ++ found_other_os=1 + # TRANSLATORS: it refers on the OS residing on device %s + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" + hints="" +@@ -102,6 +103,7 @@ for OS in ${OSPROBED} ; do + + case ${BOOT} in + chain) ++ found_other_os=1 + + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" + cat << EOF +@@ -132,6 +134,7 @@ EOF + EOF + ;; + efi) ++ found_other_os=1 + + EFIPATH=${DEVICE#*@} + DEVICE=${DEVICE%@*} +@@ -176,6 +179,7 @@ EOF + LINITRD="${LINITRD#/boot}" + fi + ++ found_other_os=1 + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" + recovery_params="$(echo "${LPARAMS}" | grep single)" || true + counter=1 +@@ -249,6 +253,7 @@ EOF + done + ;; + hurd) ++ found_other_os=1 + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" + cat << EOF + menuentry '$(echo "${LONGNAME} $onstr" | grub_quote)' --class hurd --class gnu --class os \$menuentry_id_option 'osprober-gnuhurd-/boot/gnumach.gz-false-$(grub_get_device_id "${DEVICE}")' { +@@ -275,6 +280,7 @@ EOF + EOF + ;; + minix) ++ found_other_os=1 + cat << EOF + menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" { + EOF +@@ -306,3 +312,15 @@ EOF + esac + esac + done ++ ++# We override the results of the menu_auto_hide code here, this is a bit ugly, ++# but grub-mkconfig writes out the file linearly, so this is the only way ++if [ "${found_other_os}" = "1" ]; then ++ cat << EOF ++# Other OS found, undo autohiding of menu unless menu_auto_hide=2 ++if [ "\${orig_timeout_style}" -a "\${menu_auto_hide}" != "2" ]; then ++ set timeout_style=\${orig_timeout_style} ++ set timeout=\${orig_timeout} ++fi ++EOF ++fi diff --git a/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch b/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch new file mode 100644 index 0000000..e461de9 --- /dev/null +++ b/0130-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch @@ -0,0 +1,94 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Steve Langasek +Date: Mon, 13 Jan 2014 12:13:12 +0000 +Subject: [PATCH] Output a menu entry for firmware setup on UEFI FastBoot + systems + +If fastboot is enabled in the BIOS then often it is not possible to +enter the firmware setup menu, add a menu entry for this. + +hdegoede: Cherry picked the Ubuntu patch from: +https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/patches/uefi_firmware_setup.patch +Into the Fedora / RH grub version + +According to: +https://git.launchpad.net/~ubuntu-core-dev/grub/+git/ubuntu/tree/debian/copyright +The patch is licensed under GPL-3+ + +[hdegoede: fix use with /sys/firmware/efi/efivars] +Signed-off-by: Hans de Goede +--- + Makefile.util.def | 6 ++++++ + util/grub.d/30_uefi-firmware.in | 46 +++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 52 insertions(+) + create mode 100644 util/grub.d/30_uefi-firmware.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 026b458bb85..89a9da1b9f7 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -545,6 +545,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '30_uefi-firmware'; ++ common = util/grub.d/30_uefi-firmware.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '40_custom'; + common = util/grub.d/40_custom.in; +diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in +new file mode 100644 +index 00000000000..93ececffea7 +--- /dev/null ++++ b/util/grub.d/30_uefi-firmware.in +@@ -0,0 +1,46 @@ ++#! /bin/sh ++set -e ++ ++# grub-mkconfig helper script. ++# Copyright (C) 2012 Free Software Foundation, Inc. ++# ++# GRUB is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# GRUB is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with GRUB. If not, see . ++ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++export TEXTDOMAIN=@PACKAGE@ ++export TEXTDOMAINDIR="@localedir@" ++ ++. "@datadir@/@PACKAGE@/grub-mkconfig_lib" ++ ++efi_vars_dir=/sys/firmware/efi/efivars ++EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c ++OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" ++ ++if [ -e "$OsIndications" ] && \ ++ [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b5)") & 1 ))" = 1 ]; then ++ LABEL="System setup" ++ ++ gettext_printf "Adding boot menu entry for EFI firmware configuration\n" >&2 ++ ++ onstr="$(gettext_printf "(on %s)" "${DEVICE}")" ++ ++ cat << EOF ++menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { ++ fwsetup ++} ++EOF ++fi diff --git a/0131-Add-grub-set-bootflag-utility.patch b/0131-Add-grub-set-bootflag-utility.patch new file mode 100644 index 0000000..d5fd262 --- /dev/null +++ b/0131-Add-grub-set-bootflag-utility.patch @@ -0,0 +1,291 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 12 Jun 2018 13:25:16 +0200 +Subject: [PATCH] Add grub-set-bootflag utility + +This commit adds a new grub-set-bootflag utility, which can be used +to set known bootflags in the grubenv: boot_success or menu_show_once. + +grub-set-bootflag is different from grub-editenv in 2 ways: + +1) It is intended to be executed by regular users so must be installed +as suid root. As such it is written to not use any existing grubenv +related code for easy auditing. + +It can't be executed through pkexec because we want to call it under gdm +and pkexec does not work under gdm due the gdm user having /sbin/nologin +as shell. + +2) Since it can be executed by regular users it only allows setting +(assigning a value of 1 to) bootflags which it knows about. Currently +those are just boot_success and menu_show_once. + +This commit also adds a couple of example systemd and files which show +how this can be used to set boot_success from a user-session: + +docs/grub-boot-success.service +docs/grub-boot-success.timer + +The 2 grub-boot-success.systemd files should be placed in /lib/systemd/user +and a symlink to grub-boot-success.timer should be added to +/lib/systemd/user/timers.target.wants. + +Signed-off-by: Hans de Goede +--- + Makefile.util.def | 7 ++ + util/grub-set-bootflag.c | 160 +++++++++++++++++++++++++++++++++++++++++ + conf/Makefile.extra-dist | 3 + + docs/grub-boot-success.service | 6 ++ + docs/grub-boot-success.timer | 6 ++ + util/grub-set-bootflag.1 | 20 ++++++ + 6 files changed, 202 insertions(+) + create mode 100644 util/grub-set-bootflag.c + create mode 100644 docs/grub-boot-success.service + create mode 100644 docs/grub-boot-success.timer + create mode 100644 util/grub-set-bootflag.1 + +diff --git a/Makefile.util.def b/Makefile.util.def +index 89a9da1b9f7..125ad6209b2 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -1451,3 +1451,10 @@ program = { + ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + }; ++ ++program = { ++ name = grub-set-bootflag; ++ installdir = sbin; ++ mansection = 1; ++ common = util/grub-set-bootflag.c; ++}; +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +new file mode 100644 +index 00000000000..bb198f02351 +--- /dev/null ++++ b/util/grub-set-bootflag.c +@@ -0,0 +1,160 @@ ++/* grub-set-bootflag.c - tool to set boot-flags in the grubenv. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2018 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++/* ++ * NOTE this gets run by users as root (through pkexec), so this does not ++ * use any grub library / util functions to allow for easy auditing. ++ * The grub headers are only included to get certain defines. ++ */ ++ ++#include /* For *_DIR_NAME defines */ ++#include ++#include /* For GRUB_ENVBLK_DEFCFG define */ ++#include ++#include ++#include ++#include ++ ++#define GRUBENV "/" GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME "/" GRUB_ENVBLK_DEFCFG ++#define GRUBENV_SIZE 1024 ++ ++const char *bootflags[] = { ++ "boot_success", ++ "menu_show_once", ++ NULL ++}; ++ ++static void usage(void) ++{ ++ int i; ++ ++ fprintf (stderr, "Usage: 'grub-set-bootflag ', where is one of:\n"); ++ for (i = 0; bootflags[i]; i++) ++ fprintf (stderr, " %s\n", bootflags[i]); ++} ++ ++int main(int argc, char *argv[]) ++{ ++ /* NOTE buf must be at least the longest bootflag length + 4 bytes */ ++ char env[GRUBENV_SIZE + 1], buf[64], *s; ++ const char *bootflag; ++ int i, len, ret; ++ FILE *f; ++ ++ if (argc != 2) ++ { ++ usage(); ++ return 1; ++ } ++ ++ for (i = 0; bootflags[i]; i++) ++ if (!strcmp (argv[1], bootflags[i])) ++ break; ++ if (!bootflags[i]) ++ { ++ fprintf (stderr, "Invalid bootflag: '%s'\n", argv[1]); ++ usage(); ++ return 1; ++ } ++ ++ bootflag = bootflags[i]; ++ len = strlen (bootflag); ++ ++ f = fopen (GRUBENV, "r"); ++ if (!f) ++ { ++ perror ("Error opening " GRUBENV " for reading"); ++ return 1; ++ } ++ ++ ret = fread (env, 1, GRUBENV_SIZE, f); ++ fclose (f); ++ if (ret != GRUBENV_SIZE) ++ { ++ errno = EINVAL; ++ perror ("Error reading from " GRUBENV); ++ return 1; ++ } ++ ++ /* 0 terminate env */ ++ env[GRUBENV_SIZE] = 0; ++ ++ if (strncmp (env, GRUB_ENVBLK_SIGNATURE, strlen (GRUB_ENVBLK_SIGNATURE))) ++ { ++ fprintf (stderr, "Error invalid environment block\n"); ++ return 1; ++ } ++ ++ /* Find a pre-existing definition of the bootflag */ ++ s = strstr (env, bootflag); ++ while (s && s[len] != '=') ++ s = strstr (s + len, bootflag); ++ ++ if (s && ((s[len + 1] != '0' && s[len + 1] != '1') || s[len + 2] != '\n')) ++ { ++ fprintf (stderr, "Pre-existing bootflag '%s' has unexpected value\n", bootflag); ++ return 1; ++ } ++ ++ /* No pre-existing bootflag? -> find free space */ ++ if (!s) ++ { ++ for (i = 0; i < (len + 3); i++) ++ buf[i] = '#'; ++ buf[i] = 0; ++ s = strstr (env, buf); ++ } ++ ++ if (!s) ++ { ++ fprintf (stderr, "No space in grubenv to store bootflag '%s'\n", bootflag); ++ return 1; ++ } ++ ++ /* The grubenv is not 0 terminated, so memcpy the name + '=' , '1', '\n' */ ++ snprintf(buf, sizeof(buf), "%s=1\n", bootflag); ++ memcpy(s, buf, len + 3); ++ ++ /* "r+", don't truncate so that the diskspace stays reserved */ ++ f = fopen (GRUBENV, "r+"); ++ if (!f) ++ { ++ perror ("Error opening " GRUBENV " for writing"); ++ return 1; ++ } ++ ++ ret = fwrite (env, 1, GRUBENV_SIZE, f); ++ if (ret != GRUBENV_SIZE) ++ { ++ perror ("Error writing to " GRUBENV); ++ return 1; ++ } ++ ++ ret = fflush (f); ++ if (ret) ++ { ++ perror ("Error flushing " GRUBENV); ++ return 1; ++ } ++ ++ fsync (fileno (f)); ++ fclose (f); ++ ++ return 0; ++} +diff --git a/conf/Makefile.extra-dist b/conf/Makefile.extra-dist +index 58d7d9540be..375b1bf9b02 100644 +--- a/conf/Makefile.extra-dist ++++ b/conf/Makefile.extra-dist +@@ -14,6 +14,9 @@ EXTRA_DIST += util/import_unicode.py + EXTRA_DIST += docs/autoiso.cfg + EXTRA_DIST += docs/grub.cfg + EXTRA_DIST += docs/osdetect.cfg ++EXTRA_DIST += docs/org.gnu.grub.policy ++EXTRA_DIST += docs/grub-boot-success.service ++EXTRA_DIST += docs/grub-boot-success.timer + + EXTRA_DIST += conf/i386-cygwin-img-ld.sc + +diff --git a/docs/grub-boot-success.service b/docs/grub-boot-success.service +new file mode 100644 +index 00000000000..80e79584c91 +--- /dev/null ++++ b/docs/grub-boot-success.service +@@ -0,0 +1,6 @@ ++[Unit] ++Description=Mark boot as successful ++ ++[Service] ++Type=oneshot ++ExecStart=/usr/sbin/grub2-set-bootflag boot_success +diff --git a/docs/grub-boot-success.timer b/docs/grub-boot-success.timer +new file mode 100644 +index 00000000000..5d8fcba21aa +--- /dev/null ++++ b/docs/grub-boot-success.timer +@@ -0,0 +1,6 @@ ++[Unit] ++Description=Mark boot as successful after the user session has run 2 minutes ++ConditionUser=!@system ++ ++[Timer] ++OnActiveSec=2min +diff --git a/util/grub-set-bootflag.1 b/util/grub-set-bootflag.1 +new file mode 100644 +index 00000000000..57801da22a0 +--- /dev/null ++++ b/util/grub-set-bootflag.1 +@@ -0,0 +1,20 @@ ++.TH GRUB-SET-BOOTFLAG 1 "Tue Jun 12 2018" ++.SH NAME ++\fBgrub-set-bootflag\fR \(em Set a bootflag in the GRUB environment block. ++ ++.SH SYNOPSIS ++\fBgrub-set-bootflag\fR <\fIBOOTFLAG\fR> ++ ++.SH DESCRIPTION ++\fBgrub-set-bootflag\fR is a command line to set bootflags in GRUB's ++stored environment. ++ ++.SH COMMANDS ++.TP ++\fBBOOTFLAG\fR ++.RS 7 ++Bootflag to set, one of \fIboot_success\fR or \fIshow_menu_once\fR. ++.RE ++ ++.SH SEE ALSO ++.BR "info grub" diff --git a/0132-docs-Add-grub-boot-indeterminate.service-example.patch b/0132-docs-Add-grub-boot-indeterminate.service-example.patch new file mode 100644 index 0000000..44f6ad3 --- /dev/null +++ b/0132-docs-Add-grub-boot-indeterminate.service-example.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 19 Jun 2018 15:20:54 +0200 +Subject: [PATCH] docs: Add grub-boot-indeterminate.service example + +This is an example service file, for use from +/lib/systemd/system/system-update.target.wants +to increment the boot_indeterminate variable when +doing offline updates. + +Signed-off-by: Hans de Goede +--- + docs/grub-boot-indeterminate.service | 11 +++++++++++ + 1 file changed, 11 insertions(+) + create mode 100644 docs/grub-boot-indeterminate.service + +diff --git a/docs/grub-boot-indeterminate.service b/docs/grub-boot-indeterminate.service +new file mode 100644 +index 00000000000..6c8dcb186b6 +--- /dev/null ++++ b/docs/grub-boot-indeterminate.service +@@ -0,0 +1,11 @@ ++[Unit] ++Description=Mark boot as indeterminate ++DefaultDependencies=false ++Requires=sysinit.target ++After=sysinit.target ++Wants=system-update-pre.target ++Before=system-update-pre.target ++ ++[Service] ++Type=oneshot ++ExecStart=/usr/bin/grub2-editenv - incr boot_indeterminate diff --git a/0133-gentpl-add-disable-support.patch b/0133-gentpl-add-disable-support.patch new file mode 100644 index 0000000..90308d8 --- /dev/null +++ b/0133-gentpl-add-disable-support.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:43:15 -0400 +Subject: [PATCH] gentpl: add 'disable = ' support + +Signed-off-by: Peter Jones +--- + gentpl.py | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +diff --git a/gentpl.py b/gentpl.py +index f05812eace3..3a0c04963aa 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -592,11 +592,21 @@ def platform_conditional(platform, closure): + # }; + # + def foreach_enabled_platform(defn, closure): ++ enabled = False ++ disabled = False + if 'enable' in defn: ++ enabled = True + for platform in GRUB_PLATFORMS: + if platform_tagged(defn, platform, "enable"): + platform_conditional(platform, closure) +- else: ++ ++ if 'disable' in defn: ++ disabled = True ++ for platform in GRUB_PLATFORMS: ++ if not platform_tagged(defn, platform, "disable"): ++ platform_conditional(platform, closure) ++ ++ if not enabled and not disabled: + for platform in GRUB_PLATFORMS: + platform_conditional(platform, closure) + +@@ -655,6 +665,8 @@ def first_time(defn, snippet): + def is_platform_independent(defn): + if 'enable' in defn: + return False ++ if 'disable' in defn: ++ return False + for suffix in [ "", "_nodist" ]: + template = platform_values(defn, GRUB_PLATFORMS[0], suffix) + for platform in GRUB_PLATFORMS[1:]: diff --git a/0134-gentpl-add-pc-firmware-type.patch b/0134-gentpl-add-pc-firmware-type.patch new file mode 100644 index 0000000..9f0fd47 --- /dev/null +++ b/0134-gentpl-add-pc-firmware-type.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 11:04:24 +0200 +Subject: [PATCH] gentpl: add 'pc' firmware type + +Signed-off-by: Peter Jones +--- + gentpl.py | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/gentpl.py b/gentpl.py +index 3a0c04963aa..1d9dda430e7 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -51,6 +51,7 @@ GROUPS["riscv32"] = [ "riscv32_efi" ] + GROUPS["riscv64"] = [ "riscv64_efi" ] + + # Groups based on firmware ++GROUPS["pc"] = [ "i386_pc" ] + GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi", + "riscv32_efi", "riscv64_efi" ] + GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] diff --git a/0135-efinet-also-use-the-firmware-acceleration-for-http.patch b/0135-efinet-also-use-the-firmware-acceleration-for-http.patch new file mode 100644 index 0000000..915b5aa --- /dev/null +++ b/0135-efinet-also-use-the-firmware-acceleration-for-http.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 30 Jul 2018 14:06:42 -0400 +Subject: [PATCH] efinet: also use the firmware acceleration for http + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/net.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 4bb308026ce..6603cd83edc 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -1324,7 +1324,9 @@ grub_efi_net_boot_from_https (void) + && (subtype == GRUB_EFI_URI_DEVICE_PATH_SUBTYPE)) + { + grub_efi_uri_device_path_t *uri_dp = (grub_efi_uri_device_path_t *) dp; +- return (grub_strncmp ((const char*)uri_dp->uri, "https://", sizeof ("https://") - 1) == 0) ? 1 : 0; ++ grub_dprintf ("efinet", "url:%s\n", (const char *)uri_dp->uri); ++ return (grub_strncmp ((const char *)uri_dp->uri, "https://", sizeof ("https://") - 1) == 0 || ++ grub_strncmp ((const char *)uri_dp->uri, "http://", sizeof ("http://") - 1) == 0); + } + + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) diff --git a/0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch b/0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch new file mode 100644 index 0000000..985a037 --- /dev/null +++ b/0136-efi-http-Make-root_url-reflect-the-protocol-hostname.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 30 Jul 2018 16:39:57 -0400 +Subject: [PATCH] efi/http: Make root_url reflect the protocol+hostname of our + boot url. + +This lets you write config files that don't know urls. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/http.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 3f61fd2fa5b..243acbaa35b 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + + static void + http_configure (struct grub_efi_net_device *dev, int prefer_ip6) +@@ -351,6 +352,24 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + grub_err_t err; + grub_off_t size; + char *buf; ++ char *root_url; ++ grub_efi_ipv6_address_t address; ++ const char *rest; ++ ++ if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0) ++ root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server); ++ else ++ root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server); ++ if (root_url) ++ { ++ grub_env_unset ("root_url"); ++ grub_env_set ("root_url", root_url); ++ grub_free (root_url); ++ } ++ else ++ { ++ return grub_errno; ++ } + + err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0); + if (err != GRUB_ERR_NONE) diff --git a/0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch b/0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch new file mode 100644 index 0000000..403412b --- /dev/null +++ b/0137-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch @@ -0,0 +1,149 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 26 Jun 2018 17:16:06 -0400 +Subject: [PATCH] Make it so we can tell configure which cflags utils are built + with + +This lets us have kernel.img be built with TARGET_CFLAGS but grub-mkimage and +friends built with HOST_CFLAGS. That in turn lets us build with an ARM compiler +that only has hard-float ABI versions of crt*.o and libgcc*, but still use soft +float for grub.efi. + +Signed-off-by: Peter Jones +--- + configure.ac | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- + conf/Makefile.common | 23 ++++++++++++----------- + gentpl.py | 8 ++++---- + 3 files changed, 64 insertions(+), 16 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 8ee18ba159a..cf327482e8a 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -868,11 +868,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p + TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" + fi + ++# Should grub utils get the host CFLAGS, or the target CFLAGS? ++AC_ARG_WITH([utils], ++ AS_HELP_STRING([--with-utils=host|target|build], ++ [choose which flags to build utilities with. (default=target)]), ++ [have_with_utils=y], ++ [have_with_utils=n]) ++if test x"$have_with_utils" = xy ; then ++ with_utils="$withval" ++else ++ with_utils=target ++fi ++ + # GRUB doesn't use float or doubles at all. Yet some toolchains may decide + # that floats are a good fit to run instead of what's written in the code. + # Given that floating point unit is disabled (if present to begin with) + # when GRUB is running which may result in various hard crashes. +-if test x"$platform" != xemu ; then ++if test x"$platform" != xemu -a x"$with_utils" == xtarget ; then + AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [ + grub_cv_target_cc_soft_float=no + if test "x$target_cpu" = xarm64; then +@@ -1951,6 +1963,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" + ++case "$with_utils" in ++ host) ++ UTILS_CFLAGS=$HOST_CFLAGS ++ UTILS_CPPFLAGS=$HOST_CPPFLAGS ++ UTILS_CCASFLAGS=$HOST_CCASFLAGS ++ UTILS_LDFLAGS=$HOST_LDFLAGS ++ ;; ++ target) ++ UTILS_CFLAGS=$TARGET_CFLAGS ++ UTILS_CPPFLAGS=$TARGET_CPPFLAGS ++ UTILS_CCASFLAGS=$TARGET_CCASFLAGS ++ UTILS_LDFLAGS=$TARGET_LDFLAGS ++ ;; ++ build) ++ UTILS_CFLAGS=$BUILD_CFLAGS ++ UTILS_CPPFLAGS=$BUILD_CPPFLAGS ++ UTILS_CCASFLAGS=$BUILD_CCASFLAGS ++ UTILS_LDFLAGS=$BUILD_LDFLAGS ++ ;; ++ *) ++ AC_MSG_ERROR([--with-utils must be either host, target, or build]) ++ ;; ++esac ++AC_MSG_NOTICE([Using $with_utils flags for utilities.]) ++ ++unset CFLAGS ++unset CPPFLAGS ++unset CCASFLAGS ++unset LDFLAGS ++ ++AC_SUBST(UTILS_CFLAGS) ++AC_SUBST(UTILS_CPPFLAGS) ++AC_SUBST(UTILS_CCASFLAGS) ++AC_SUBST(UTILS_LDFLAGS) ++ + GRUB_TARGET_CPU="${target_cpu}" + GRUB_PLATFORM="${platform}" + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 5e8ba2ae3b0..bbf33b0bc4a 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1 + CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes + +-CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding +-LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +-CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) +-CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) ++CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding ++LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d ++CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) ++CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + + CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin + LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S + CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) + CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) + +-CFLAGS_PROGRAM = +-LDFLAGS_PROGRAM = +-CPPFLAGS_PROGRAM = +-CCASFLAGS_PROGRAM = ++CFLAGS_PROGRAM = $(UTILS_CFLAGS) ++LDFLAGS_PROGRAM = $(UTILS_LDFLAGS) ++CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS) ++CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS) + +-CFLAGS_LIBRARY = +-CPPFLAGS_LIBRARY = +-CCASFLAGS_LIBRARY = ++CFLAGS_LIBRARY = $(UTILS_CFLAGS) ++LDFLAGS_LIBRARY = $(UTILS_LDFLAGS) ++CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS) ++CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) + + # Other variables + +diff --git a/gentpl.py b/gentpl.py +index 1d9dda430e7..95fe1a24d8a 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -697,10 +697,10 @@ def module(defn, platform): + var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources") + var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources") + var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform)) +- var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform)) +- var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform)) +- var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform)) +- var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform)) ++ var_set(cname(defn) + "_CFLAGS", "$(CFLAGS_MODULE) " + platform_cflags(defn, platform)) ++ var_set(cname(defn) + "_LDFLAGS", "$(LDFLAGS_MODULE) " + platform_ldflags(defn, platform)) ++ var_set(cname(defn) + "_CPPFLAGS", "$(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform)) ++ var_set(cname(defn) + "_CCASFLAGS", "$(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform)) + var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform)) + + gvar_add("dist_noinst_DATA", extra_dist(defn)) diff --git a/0138-module-verifier-make-it-possible-to-run-checkers-on-.patch b/0138-module-verifier-make-it-possible-to-run-checkers-on-.patch new file mode 100644 index 0000000..e31b38f --- /dev/null +++ b/0138-module-verifier-make-it-possible-to-run-checkers-on-.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 1 Aug 2018 10:24:52 -0400 +Subject: [PATCH] module-verifier: make it possible to run checkers on + grub-module-verifierxx.c + +This makes it so you can treat grub-module-verifierxx.c as a file you can +build directly, so syntax checkers like vim's "syntastic" plugin, which uses +"gcc -x c -fsyntax-only" to build it, will work. + +One still has to do whatever setup is required to make it pick the right +include dirs, which -W options we use, etc., but this makes it so you can do +the checking on the file you're editing, rather than on a different file. + +v2: fix the typo in the #else clause in util/grub-module-verifierXX.c + +Signed-off-by: Peter Jones +--- + util/grub-module-verifier32.c | 2 ++ + util/grub-module-verifier64.c | 2 ++ + util/grub-module-verifierXX.c | 9 +++++++++ + 3 files changed, 13 insertions(+) + +diff --git a/util/grub-module-verifier32.c b/util/grub-module-verifier32.c +index 257229f8f08..ba7d41aafea 100644 +--- a/util/grub-module-verifier32.c ++++ b/util/grub-module-verifier32.c +@@ -1,2 +1,4 @@ + #define MODULEVERIFIER_ELF32 1 ++#ifndef GRUB_MODULE_VERIFIERXX + #include "grub-module-verifierXX.c" ++#endif +diff --git a/util/grub-module-verifier64.c b/util/grub-module-verifier64.c +index 4db6b4bedd1..fc23ef800b3 100644 +--- a/util/grub-module-verifier64.c ++++ b/util/grub-module-verifier64.c +@@ -1,2 +1,4 @@ + #define MODULEVERIFIER_ELF64 1 ++#ifndef GRUB_MODULE_VERIFIERXX + #include "grub-module-verifierXX.c" ++#endif +diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c +index ceb24309aec..a98e2f9b1ac 100644 +--- a/util/grub-module-verifierXX.c ++++ b/util/grub-module-verifierXX.c +@@ -1,3 +1,12 @@ ++#define GRUB_MODULE_VERIFIERXX ++#if !defined(MODULEVERIFIER_ELF32) && !defined(MODULEVERIFIER_ELF64) ++#if __SIZEOF_POINTER__ == 8 ++#include "grub-module-verifier64.c" ++#else ++#include "grub-module-verifier32.c" ++#endif ++#endif ++ + #include + + #include diff --git a/0139-Rework-how-the-fdt-command-builds.patch b/0139-Rework-how-the-fdt-command-builds.patch new file mode 100644 index 0000000..9936858 --- /dev/null +++ b/0139-Rework-how-the-fdt-command-builds.patch @@ -0,0 +1,118 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 13:01:41 +0200 +Subject: [PATCH] Rework how the fdt command builds. + +Trying to avoid all variants of: +cat syminfo.lst | sort | gawk -f ../../grub-core/genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1) +grub_fdt_install in linux is not defined +grub_fdt_load in linux is not defined +grub_fdt_unload in linux is not defined +grub_fdt_install in xen_boot is not defined +grub_fdt_load in xen_boot is not defined +grub_fdt_unload in xen_boot is not defined + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 5 ++--- + grub-core/lib/fdt.c | 2 -- + grub-core/loader/efi/fdt.c | 2 ++ + include/grub/fdt.h | 4 ++++ + grub-core/Makefile.am | 1 + + 5 files changed, 9 insertions(+), 5 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 48491b50683..556adca7074 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -175,7 +175,6 @@ kernel = { + arm_coreboot = kern/arm/coreboot/init.c; + arm_coreboot = kern/arm/coreboot/timer.c; + arm_coreboot = kern/arm/coreboot/coreboot.S; +- arm_coreboot = lib/fdt.c; + arm_coreboot = bus/fdt.c; + arm_coreboot = term/ps2.c; + arm_coreboot = term/arm/pl050.c; +@@ -348,6 +347,8 @@ kernel = { + riscv64 = kern/riscv/cache_flush.S; + riscv64 = kern/riscv/dl.c; + ++ fdt = lib/fdt.c; ++ + emu = disk/host.c; + emu = kern/emu/cache_s.S; + emu = kern/emu/hostdisk.c; +@@ -1801,7 +1802,6 @@ module = { + riscv32 = loader/riscv/linux.c; + riscv64 = loader/riscv/linux.c; + emu = loader/emu/linux.c; +- fdt = lib/fdt.c; + + common = loader/linux.c; + common = lib/cmdline.c; +@@ -1812,7 +1812,6 @@ module = { + module = { + name = fdt; + efi = loader/efi/fdt.c; +- common = lib/fdt.c; + enable = fdt; + }; + +diff --git a/grub-core/lib/fdt.c b/grub-core/lib/fdt.c +index 0d371c5633e..37e04bd69e7 100644 +--- a/grub-core/lib/fdt.c ++++ b/grub-core/lib/fdt.c +@@ -21,8 +21,6 @@ + #include + #include + +-GRUB_MOD_LICENSE ("GPLv3+"); +- + #define FDT_SUPPORTED_VERSION 17 + + #define FDT_BEGIN_NODE 0x00000001 +diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c +index ee9c5592c70..37ca407bb36 100644 +--- a/grub-core/loader/efi/fdt.c ++++ b/grub-core/loader/efi/fdt.c +@@ -26,6 +26,8 @@ + #include + #include + ++GRUB_MOD_LICENSE ("GPLv3+"); ++ + static void *loaded_fdt; + static void *fdt; + +diff --git a/include/grub/fdt.h b/include/grub/fdt.h +index e609c7e4111..22b7c5463fc 100644 +--- a/include/grub/fdt.h ++++ b/include/grub/fdt.h +@@ -19,6 +19,8 @@ + #ifndef GRUB_FDT_HEADER + #define GRUB_FDT_HEADER 1 + ++#if defined(__arm__) || defined(__aarch64__) ++ + #include + #include + +@@ -144,4 +146,6 @@ 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 /* ! GRUB_FDT_HEADER */ +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index d9ad30052f1..ee9c4e4eb88 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -76,6 +76,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/sb.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/env_private.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/err.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fdt.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/file.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/fs.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i18n.h diff --git a/0140-Disable-non-wordsize-allocations-on-arm.patch b/0140-Disable-non-wordsize-allocations-on-arm.patch new file mode 100644 index 0000000..64da8e6 --- /dev/null +++ b/0140-Disable-non-wordsize-allocations-on-arm.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 2 Aug 2018 10:56:38 -0400 +Subject: [PATCH] Disable non-wordsize allocations on arm + +Signed-off-by: Peter Jones +--- + configure.ac | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/configure.ac b/configure.ac +index cf327482e8a..9b0946c27bf 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1262,6 +1262,26 @@ if test "x$target_cpu" = xarm; then + done + ]) + ++ AC_CACHE_CHECK([for options to disable movt and movw relocations], ++ grub_cv_target_cc_mword_relocations, ++ [grub_cv_target_cc_mword_relocations=no ++ for cand in "-mword-relocations" ; do ++ if test x"$grub_cv_target_cc_mword_relocations" != xno ; then ++ break ++ fi ++ CFLAGS="$TARGET_CFLAGS $cand -Werror" ++ CPPFLAGS="$TARGET_CPPFLAGS" ++ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], ++ [grub_cv_target_cc_mword_relocations="$cand"], ++ []) ++ done ++ ]) ++ if test x"$grub_cv_target_cc_mword_relocations" = xno ; then ++ AC_MSG_ERROR(["your compiler doesn't support disabling movw/movt relocations"]) ++ else ++ TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mword_relocations" ++ fi ++ + if test x"$grub_cv_target_cc_mno_movt" != xno ; then + # A trick so that clang doesn't see it on link stage + TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt" diff --git a/0141-strip-R-.note.gnu.property-at-more-places.patch b/0141-strip-R-.note.gnu.property-at-more-places.patch new file mode 100644 index 0000000..d568422 --- /dev/null +++ b/0141-strip-R-.note.gnu.property-at-more-places.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 3 Aug 2018 15:07:23 -0400 +Subject: [PATCH] strip "-R .note.gnu.property" at more places. + +For whatever reason, sometimes I see: + + lzma_decompress.image: file format elf32-i386 + lzma_decompress.image + architecture: i386, flags 0x00000012: + EXEC_P, HAS_SYMS + start address 0x00008200 + + Program Header: + LOAD off 0x000000c0 vaddr 0x00008200 paddr 0x00008200 align 2**5 + filesz 0x00000b10 memsz 0x00000b10 flags rwx + LOAD off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2 + filesz 0x0000001c memsz 0x0000001c flags r-- + NOTE off 0x00000bd0 vaddr 0x080480b4 paddr 0x080480b4 align 2**2 + filesz 0x0000001c memsz 0x0000001c flags r-- + STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4 + filesz 0x00000000 memsz 0x00000000 flags rw- + + Sections: + Idx Name Size VMA LMA File off Algn + 0 .note.gnu.property 0000001c 080480b4 080480b4 00000bd0 2**2 + CONTENTS, ALLOC, LOAD, READONLY, DATA + 1 .text 00000b10 00008200 00008200 000000c0 2**5 + CONTENTS, ALLOC, LOAD, CODE + SYMBOL TABLE: + 080480b4 l d .note.gnu.property 00000000 .note.gnu.property + 00008200 l d .text 00000000 .text + 00000000 l df *ABS* 00000000 startup_raw.S + ... + +Which just looks wrong no matter what to my eyes (seriously it's at +128M? Why?), and when we fail to strip it, we get: + +trillian:~/tmp/f29$ hexdump -C usr/lib/grub/i386-pc/lzma_decompress.img | tail -6 +00000b00 ff 45 e8 5a 83 c2 02 89 d1 e9 df fe ff ff 66 90 |.E.Z..........f.| +00000b10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +* +0803feb0 00 00 00 00 04 00 00 00 0c 00 00 00 05 00 00 00 |................| +0803fec0 47 4e 55 00 02 00 00 c0 04 00 00 00 03 00 00 00 |GNU.............| +0803fed0 + +Which is very very much not what we want. + +Cut it out. + +Signed-off-by: Peter Jones +--- + Makefile.am | 2 +- + gentpl.py | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Makefile.am b/Makefile.am +index bf9c1ba64c9..0d4dd7c2e90 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -209,7 +209,7 @@ pc-chainloader.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub- + $(TARGET_CC) -o $@ $< -static -DTARGET_CHAINLOADER=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0x7c00 -m32 + + pc-chainloader.bin: pc-chainloader.elf +- $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; ++ $(TARGET_OBJCOPY) -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property $< $@; + + ntldr.elf: $(srcdir)/grub-core/tests/boot/kernel-8086.S $(srcdir)/grub-core/tests/boot/qemu-shutdown-x86.S + $(TARGET_CC) -o $@ $< -DTARGET_NTLDR=1 -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\" -static -ffreestanding -nostdlib -nostdinc -Wl,--build-id=none -Wl,-N -Wl,-Ttext,0 -m32 +diff --git a/gentpl.py b/gentpl.py +index 95fe1a24d8a..32cf7456b72 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -779,7 +779,7 @@ def image(defn, platform): + if test x$(TARGET_APPLE_LINKER) = x1; then \ + $(MACHO2IMG) $< $@; \ + else \ +- $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx $< $@; \ ++ $(TARGET_OBJCOPY) $(""" + cname(defn) + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx -R .note.gnu.property $< $@; \ + fi + """) + diff --git a/0142-Prepend-prefix-when-HTTP-path-is-relative.patch b/0142-Prepend-prefix-when-HTTP-path-is-relative.patch new file mode 100644 index 0000000..1b1af53 --- /dev/null +++ b/0142-Prepend-prefix-when-HTTP-path-is-relative.patch @@ -0,0 +1,150 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stephen Benjamin +Date: Thu, 16 Aug 2018 16:58:51 -0400 +Subject: [PATCH] Prepend prefix when HTTP path is relative + +This sets a couple of variables. With the url http://www.example.com/foo/bar : +http_path: /foo/bar +http_url: http://www.example.com/foo/bar + +Signed-off-by: Peter Jones +--- + grub-core/kern/main.c | 10 +++++- + grub-core/net/efi/http.c | 82 ++++++++++++++++++++++++++++++++++++------------ + 2 files changed, 71 insertions(+), 21 deletions(-) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index da47b18b50e..dcf48726d54 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -130,11 +130,19 @@ grub_set_prefix_and_root (void) + if (fwdevice && fwpath) + { + char *fw_path; ++ char separator[3] = ")"; + +- fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath); ++ grub_dprintf ("fw_path", "\n"); ++ grub_dprintf ("fw_path", "fwdevice:\"%s\" fwpath:\"%s\"\n", fwdevice, fwpath); ++ ++ if (!grub_strncmp(fwdevice, "http", 4) && fwpath[0] != '/') ++ grub_strcpy(separator, ")/"); ++ ++ fw_path = grub_xasprintf ("(%s%s%s", fwdevice, separator, fwpath); + if (fw_path) + { + grub_env_set ("fw_path", fw_path); ++ grub_dprintf ("fw_path", "fw_path:\"%s\"\n", fw_path); + grub_free (fw_path); + } + } +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 243acbaa35b..de351b2cd03 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -9,10 +9,52 @@ + static void + http_configure (struct grub_efi_net_device *dev, int prefer_ip6) + { ++ grub_efi_ipv6_address_t address; + grub_efi_http_config_data_t http_config; + grub_efi_httpv4_access_point_t httpv4_node; + grub_efi_httpv6_access_point_t httpv6_node; + grub_efi_status_t status; ++ int https; ++ char *http_url; ++ const char *rest, *http_server, *http_path = NULL; ++ ++ http_server = grub_env_get ("root"); ++ https = (grub_strncmp (http_server, "https", 5) == 0) ? 1 : 0; ++ ++ /* extract http server + port */ ++ if (http_server) ++ { ++ http_server = grub_strchr (http_server, ','); ++ if (http_server) ++ http_server++; ++ } ++ ++ /* fw_path is like (http,192.168.1.1:8000)/httpboot, extract path part */ ++ http_path = grub_env_get ("fw_path"); ++ if (http_path) ++ { ++ http_path = grub_strchr (http_path, ')'); ++ if (http_path) ++ { ++ http_path++; ++ grub_env_unset ("http_path"); ++ grub_env_set ("http_path", http_path); ++ } ++ } ++ ++ if (http_server && http_path) ++ { ++ if (grub_efi_string_to_ip6_address (http_server, &address, &rest) && *rest == 0) ++ http_url = grub_xasprintf ("%s://[%s]%s", https ? "https" : "http", http_server, http_path); ++ else ++ http_url = grub_xasprintf ("%s://%s%s", https ? "https" : "http", http_server, http_path); ++ if (http_url) ++ { ++ grub_env_unset ("http_url"); ++ grub_env_set ("http_url", http_url); ++ grub_free (http_url); ++ } ++ } + + grub_efi_http_t *http = dev->http; + +@@ -352,32 +394,32 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + grub_err_t err; + grub_off_t size; + char *buf; +- char *root_url; +- grub_efi_ipv6_address_t address; +- const char *rest; ++ char *file_name = NULL; ++ const char *http_path; + +- if (grub_efi_string_to_ip6_address (file->device->net->server, &address, &rest) && *rest == 0) +- root_url = grub_xasprintf ("%s://[%s]", type ? "https" : "http", file->device->net->server); +- else +- root_url = grub_xasprintf ("%s://%s", type ? "https" : "http", file->device->net->server); +- if (root_url) +- { +- grub_env_unset ("root_url"); +- grub_env_set ("root_url", root_url); +- grub_free (root_url); +- } +- else +- { ++ /* If path is relative, prepend http_path */ ++ http_path = grub_env_get ("http_path"); ++ if (http_path && file->device->net->name[0] != '/') { ++ file_name = grub_xasprintf ("%s/%s", http_path, file->device->net->name); ++ if (!file_name) + return grub_errno; +- } ++ } + +- err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 1, 0); ++ err = efihttp_request (dev->http, file->device->net->server, ++ file_name ? file_name : file->device->net->name, type, 1, 0); + if (err != GRUB_ERR_NONE) +- return err; ++ { ++ grub_free (file_name); ++ return err; ++ } + +- err = efihttp_request (dev->http, file->device->net->server, file->device->net->name, type, 0, &size); ++ err = efihttp_request (dev->http, file->device->net->server, ++ file_name ? file_name : file->device->net->name, type, 0, &size); ++ grub_free (file_name); + if (err != GRUB_ERR_NONE) +- return err; ++ { ++ return err; ++ } + + buf = grub_malloc (size); + efihttp_read (dev, buf, size); diff --git a/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch b/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch new file mode 100644 index 0000000..a3c3213 --- /dev/null +++ b/0143-Make-linux_arm_kernel_header.hdr_offset-be-at-the-ri.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 16 Aug 2018 11:08:11 -0400 +Subject: [PATCH] Make linux_arm_kernel_header.hdr_offset be at the right place + +The kernel in front of me (slightly edited to make objdump work) looks like: + +00000000 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 |MZ..MZ..MZ..MZ..| +00000010 4d 5a 10 13 4d 5a 10 13 4d 5a 10 13 00 00 a0 e1 |MZ..MZ..MZ......| +00000020 f6 03 00 ea 18 28 6f 01 00 00 00 00 00 32 74 00 |.....(o......2t.| +00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...| +00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........| +00000050 00 00 00 00 90 00 06 03 0b 01 02 14 00 20 74 00 |............. t.| +00000060 00 14 00 00 00 00 00 00 b4 19 00 00 00 10 00 00 |................| +00000070 00 30 74 00 00 00 00 00 00 10 00 00 00 02 00 00 |.0t.............| +00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000090 00 44 74 00 00 10 00 00 00 00 00 00 0a 00 00 00 |.Dt.............| +000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +000000b0 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 |................| +000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +* + +(I don't know why the MZ header is there 7 times, but the offsets work out, so +it's merely a surprising distraction.) + +If linux_arm_kernel_header.reserved2 is 16 bytes, that means hdr_offset is +here: + +00000030 01 02 03 04 45 45 45 45 74 a2 00 00 40 00 00 00 |....EEEEt...@...| +00000040 50 45 00 00 4c 01 04 00 00 00 00 00 00 00 00 00 |PE..L...........| + ^^^^^^^^^^^ + +But it's supposed to be 4 bytes before that. + +This patch makes the reserved field be 3*32 instead of 4*32, and that means we +can find the PE header correcrtly at 0x40 by reading the value at 0x3c. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/linux.c | 3 +++ + include/grub/arm/linux.h | 2 +- + 2 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 0622dfa48d4..b56ea0bc041 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -79,7 +79,10 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, + offset = 512; + #endif + ++ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", ++ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); + hf = (handover_func)((char *)kernel_addr + handover_offset + offset); ++ grub_dprintf ("linux", "handover_func() = %p\n", hf); + hf (grub_efi_image_handle, grub_efi_system_table, kernel_params); + + return GRUB_ERR_BUG; +diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h +index 775297db869..b582f67f661 100644 +--- a/include/grub/arm/linux.h ++++ b/include/grub/arm/linux.h +@@ -31,7 +31,7 @@ struct linux_arm_kernel_header { + grub_uint32_t magic; + grub_uint32_t start; /* _start */ + grub_uint32_t end; /* _edata */ +- grub_uint32_t reserved2[4]; ++ grub_uint32_t reserved2[3]; + grub_uint32_t hdr_offset; + }; + diff --git a/0144-Make-grub_error-more-verbose.patch b/0144-Make-grub_error-more-verbose.patch new file mode 100644 index 0000000..ec4a3eb --- /dev/null +++ b/0144-Make-grub_error-more-verbose.patch @@ -0,0 +1,98 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 27 Aug 2018 13:14:06 -0400 +Subject: [PATCH] Make grub_error() more verbose + +Signed-off-by: Peter Jones +--- + grub-core/kern/efi/mm.c | 17 ++++++++++++++--- + grub-core/kern/err.c | 13 +++++++++++-- + include/grub/err.h | 5 ++++- + 3 files changed, 29 insertions(+), 6 deletions(-) + +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index a9e37108c6d..15595a46e23 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -157,12 +157,20 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + + /* Limit the memory access to less than 4GB for 32-bit platforms. */ + if (address > GRUB_EFI_MAX_USABLE_ADDRESS) +- return 0; ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("invalid memory address (0x%llx > 0x%llx)"), ++ address, GRUB_EFI_MAX_USABLE_ADDRESS); ++ return NULL; ++ } + + b = grub_efi_system_table->boot_services; + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); + if (status != GRUB_EFI_SUCCESS) +- return 0; ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ return NULL; ++ } + + if (address == 0) + { +@@ -172,7 +180,10 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); + grub_efi_free_pages (0, pages); + if (status != GRUB_EFI_SUCCESS) +- return 0; ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ return NULL; ++ } + } + + grub_efi_store_alloc (address, pages); +diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c +index 53c734de70e..aebfe0cf839 100644 +--- a/grub-core/kern/err.c ++++ b/grub-core/kern/err.c +@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE]; + static int grub_error_stack_pos; + static int grub_error_stack_assert; + ++#ifdef grub_error ++#undef grub_error ++#endif ++ + grub_err_t +-grub_error (grub_err_t n, const char *fmt, ...) ++grub_error (grub_err_t n, const char *file, const int line, const char *fmt, ...) + { + va_list ap; ++ int m; + + grub_errno = n; + ++ m = grub_snprintf (grub_errmsg, sizeof (grub_errmsg), "%s:%d:", file, line); ++ if (m < 0) ++ m = 0; ++ + va_start (ap, fmt); +- grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap); ++ grub_vsnprintf (grub_errmsg + m, sizeof (grub_errmsg) - m, _(fmt), ap); + va_end (ap); + + return n; +diff --git a/include/grub/err.h b/include/grub/err.h +index 24ba9f5f592..b68bbec3c72 100644 +--- a/include/grub/err.h ++++ b/include/grub/err.h +@@ -85,7 +85,10 @@ struct grub_error_saved + extern grub_err_t EXPORT_VAR(grub_errno); + extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG]; + +-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...); ++grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...); ++ ++#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__) ++ + void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn)); + void EXPORT_FUNC(grub_error_push) (void); + int EXPORT_FUNC(grub_error_pop) (void); diff --git a/0145-Make-reset-an-alias-for-the-reboot-command.patch b/0145-Make-reset-an-alias-for-the-reboot-command.patch new file mode 100644 index 0000000..c86acf1 --- /dev/null +++ b/0145-Make-reset-an-alias-for-the-reboot-command.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 31 Aug 2018 16:42:03 -0400 +Subject: [PATCH] Make "reset" an alias for the "reboot" command. + +I'm really tired of half the tools I get to use having one and the other half +having the other. + +Signed-off-by: Peter Jones +--- + grub-core/commands/reboot.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/grub-core/commands/reboot.c b/grub-core/commands/reboot.c +index 46d364c99a9..f5cc2283636 100644 +--- a/grub-core/commands/reboot.c ++++ b/grub-core/commands/reboot.c +@@ -32,15 +32,18 @@ grub_cmd_reboot (grub_command_t cmd __attribute__ ((unused)), + grub_reboot (); + } + +-static grub_command_t cmd; ++static grub_command_t reboot_cmd, reset_cmd; + + GRUB_MOD_INIT(reboot) + { +- cmd = grub_register_command ("reboot", grub_cmd_reboot, +- 0, N_("Reboot the computer.")); ++ reboot_cmd = grub_register_command ("reboot", grub_cmd_reboot, ++ 0, N_("Reboot the computer.")); ++ reset_cmd = grub_register_command ("reset", grub_cmd_reboot, ++ 0, N_("Reboot the computer.")); + } + + GRUB_MOD_FINI(reboot) + { +- grub_unregister_command (cmd); ++ grub_unregister_command (reboot_cmd); ++ grub_unregister_command (reset_cmd); + } diff --git a/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch b/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch new file mode 100644 index 0000000..37d6f4d --- /dev/null +++ b/0146-EFI-more-debug-output-on-GOP-and-UGA-probing.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 10 Sep 2018 13:01:24 -0400 +Subject: [PATCH] EFI: more debug output on GOP and UGA probing. + +Signed-off-by: Peter Jones +--- + grub-core/video/efi_gop.c | 8 +++++++- + grub-core/video/efi_uga.c | 4 ++-- + 2 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/grub-core/video/efi_gop.c b/grub-core/video/efi_gop.c +index c9e40e8d4e9..be446f8d291 100644 +--- a/grub-core/video/efi_gop.c ++++ b/grub-core/video/efi_gop.c +@@ -71,7 +71,10 @@ check_protocol (void) + handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, + &graphics_output_guid, NULL, &num_handles); + if (!handles || num_handles == 0) +- return 0; ++ { ++ grub_dprintf ("video", "GOP: no handles\n"); ++ return 0; ++ } + + for (i = 0; i < num_handles; i++) + { +@@ -81,6 +84,7 @@ check_protocol (void) + grub_video_gop_iterate (check_protocol_hook, &have_usable_mode); + if (have_usable_mode) + { ++ grub_dprintf ("video", "GOP: found usable mode\n"); + grub_free (handles); + return 1; + } +@@ -89,6 +93,8 @@ check_protocol (void) + gop = 0; + gop_handle = 0; + ++ grub_dprintf ("video", "GOP: no usable mode\n"); ++ + return 0; + } + +diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c +index 97a607c01a5..e74d6c23500 100644 +--- a/grub-core/video/efi_uga.c ++++ b/grub-core/video/efi_uga.c +@@ -110,7 +110,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + { + int i; + +- grub_dprintf ("fb", "Display controller: %d:%d.%d\nDevice id: %x\n", ++ grub_dprintf ("video", "Display controller: %d:%d.%d\nDevice id: %x\n", + grub_pci_get_bus (dev), grub_pci_get_device (dev), + grub_pci_get_function (dev), pciid); + addr += 8; +@@ -140,7 +140,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data) + base64 <<= 32; + base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); + +- grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", ++ grub_dprintf ("video", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", + ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? + "VMEM" : "MMIO"), type == GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 : i, + base64); diff --git a/0147-Add-a-version-command.patch b/0147-Add-a-version-command.patch new file mode 100644 index 0000000..f08559b --- /dev/null +++ b/0147-Add-a-version-command.patch @@ -0,0 +1,132 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 11 Sep 2018 14:20:37 -0400 +Subject: [PATCH] Add a "version" command. + +This adds a command that shows you info about grub's version, the grub target +platform, the compiler version, and if you built with +--with-rpm-version=, the rpm package version. + +Signed-off-by: Peter Jones +--- + configure.ac | 13 ++++++++++ + grub-core/Makefile.core.def | 5 ++++ + grub-core/commands/version.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ + config.h.in | 1 + + 4 files changed, 75 insertions(+) + create mode 100644 grub-core/commands/version.c + +diff --git a/configure.ac b/configure.ac +index 9b0946c27bf..bca7c2818af 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -303,6 +303,19 @@ AC_SUBST(target_cpu) + AC_SUBST(platform) + + # Define default variables ++have_with_rpm_version=n ++AC_ARG_WITH([rpm_version], ++ AS_HELP_STRING([--with-rpm-version=VERSION], ++ [set the rpm package version [[guessed]]]), ++ [have_with_rpm_version=y], ++ [have_with_rpm_version=n]) ++if test x$have_with_rpm_version = xy; then ++ rpm_version="$with_rpm_version" ++else ++ rpm_version="" ++fi ++GRUB_RPM_VERSION="$rpm_version" ++AC_SUBST(GRUB_RPM_VERSION) + + have_with_bootdir=n + AC_ARG_WITH([bootdir], +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 556adca7074..8bb1dafd0ac 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -576,6 +576,11 @@ image = { + enable = mips_loongson; + }; + ++module = { ++ name = version; ++ common = commands/version.c; ++}; ++ + module = { + name = disk; + common = lib/disk.c; +diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c +new file mode 100644 +index 00000000000..f0966a518f7 +--- /dev/null ++++ b/grub-core/commands/version.c +@@ -0,0 +1,56 @@ ++/* version.c - Command to print the grub version and build info. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_err_t ++grub_cmd_version (grub_command_t cmd UNUSED, int argc, char **args UNUSED) ++{ ++ if (argc != 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no arguments expected")); ++ ++ grub_printf (_("GNU GRUB version %s\n"), PACKAGE_VERSION); ++ grub_printf (_("Platform %s-%s\n"), GRUB_TARGET_CPU, GRUB_PLATFORM); ++ if (grub_strlen(GRUB_RPM_VERSION) != 0) ++ grub_printf (_("RPM package version %s\n"), GRUB_RPM_VERSION); ++ grub_printf (_("Compiler version %s\n"), __VERSION__); ++ ++ return 0; ++} ++ ++static grub_command_t cmd; ++ ++GRUB_MOD_INIT(version) ++{ ++ cmd = grub_register_command ("version", grub_cmd_version, NULL, ++ N_("Print version and build information.")); ++} ++ ++GRUB_MOD_FINI(version) ++{ ++ grub_unregister_command (cmd); ++} +diff --git a/config.h.in b/config.h.in +index 9e8f9911b18..c7e316f0f1f 100644 +--- a/config.h.in ++++ b/config.h.in +@@ -59,6 +59,7 @@ + + #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@" + #define GRUB_PLATFORM "@GRUB_PLATFORM@" ++#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@" + + #define RE_ENABLE_I18N 1 + diff --git a/0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch b/0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch new file mode 100644 index 0000000..ac8ed7f --- /dev/null +++ b/0148-Add-more-dprintf-and-nerf-dprintf-in-script.c.patch @@ -0,0 +1,74 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 11 Sep 2018 15:58:29 -0400 +Subject: [PATCH] Add more dprintf, and nerf dprintf in script.c + +Signed-off-by: Peter Jones +--- + grub-core/disk/diskfilter.c | 3 +++ + grub-core/disk/efi/efidisk.c | 1 + + grub-core/kern/device.c | 1 + + grub-core/script/script.c | 5 +++++ + 4 files changed, 10 insertions(+) + +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index c3b578acf25..1a3eb6b8d77 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -188,6 +188,8 @@ scan_disk (const char *name, int accept_diskfilter) + grub_disk_t disk; + static int scan_depth = 0; + ++ grub_dprintf ("diskfilter", "scanning %s\n", name); ++ + if (!accept_diskfilter && is_valid_diskfilter_name (name)) + return 0; + +@@ -1211,6 +1213,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, + the same. */ + if (pv->disk && grub_disk_get_size (disk) >= pv->part_size) + return GRUB_ERR_NONE; ++ grub_dprintf ("diskfilter", "checking %s\n", disk->name); + pv->disk = grub_disk_open (disk->name); + if (!pv->disk) + return grub_errno; +diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c +index 9e20af70ee0..54c227b1c84 100644 +--- a/grub-core/disk/efi/efidisk.c ++++ b/grub-core/disk/efi/efidisk.c +@@ -855,6 +855,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) + return 0; + } + ++ grub_dprintf ("efidisk", "getting disk for %s\n", device_name); + parent = grub_disk_open (device_name); + grub_free (dup_dp); + +diff --git a/grub-core/kern/device.c b/grub-core/kern/device.c +index 73b8ecc0c09..f58b58c89d5 100644 +--- a/grub-core/kern/device.c ++++ b/grub-core/kern/device.c +@@ -34,6 +34,7 @@ grub_device_open (const char *name) + { + grub_device_t dev = 0; + ++ grub_dprintf ("device", "opening device %s\n", name); + if (! name) + { + name = grub_env_get ("root"); +diff --git a/grub-core/script/script.c b/grub-core/script/script.c +index ec4d4337c66..844e8343ca7 100644 +--- a/grub-core/script/script.c ++++ b/grub-core/script/script.c +@@ -22,6 +22,11 @@ + #include + #include + ++#ifdef grub_dprintf ++#undef grub_dprintf ++#endif ++#define grub_dprintf(no, fmt, ...) ++ + /* It is not possible to deallocate the memory when a syntax error was + found. Because of that it is required to keep track of all memory + allocations. The memory is freed in case of an error, or assigned diff --git a/0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch b/0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch new file mode 100644 index 0000000..c912d24 --- /dev/null +++ b/0149-arm-arm64-loader-Better-memory-allocation-and-error-.patch @@ -0,0 +1,298 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 14:38:57 +0200 +Subject: [PATCH] arm/arm64 loader: Better memory allocation and error + messages. + +On mustang, our memory map looks like: + +Type Physical start - end #Pages Size Attributes +reserved 0000004000000000-00000040001fffff 00000200 2MiB UC WC WT WB +conv-mem 0000004000200000-0000004393ffffff 00393e00 14654MiB UC WC WT WB +ldr-code 0000004394000000-00000043f7ffffff 00064000 1600MiB UC WC WT WB +BS-data 00000043f8000000-00000043f801ffff 00000020 128KiB UC WC WT WB +conv-mem 00000043f8020000-00000043fa15bfff 0000213c 34032KiB UC WC WT WB +ldr-code 00000043fa15c000-00000043fa2a1fff 00000146 1304KiB UC WC WT WB +ldr-data 00000043fa2a2000-00000043fa3e8fff 00000147 1308KiB UC WC WT WB +conv-mem 00000043fa3e9000-00000043fa3e9fff 00000001 4KiB UC WC WT WB +ldr-data 00000043fa3ea000-00000043fa3eafff 00000001 4KiB UC WC WT WB +ldr-code 00000043fa3eb000-00000043fa4affff 000000c5 788KiB UC WC WT WB +BS-code 00000043fa4b0000-00000043fa59ffff 000000f0 960KiB UC WC WT WB +RT-code 00000043fa5a0000-00000043fa5affff 00000010 64KiB RT UC WC WT WB +RT-data 00000043fa5b0000-00000043fa5bffff 00000010 64KiB RT UC WC WT WB +RT-code 00000043fa5c0000-00000043fa5cffff 00000010 64KiB RT UC WC WT WB +ldr-data 00000043fa5d0000-00000043fa5d0fff 00000001 4KiB UC WC WT WB +BS-code 00000043fa5d1000-00000043fa5ddfff 0000000d 52KiB UC WC WT WB +reserved 00000043fa5de000-00000043fa60ffff 00000032 200KiB UC WC WT WB +ACPI-rec 00000043fa610000-00000043fa6affff 000000a0 640KiB UC WC WT WB +ACPI-nvs 00000043fa6b0000-00000043fa6bffff 00000010 64KiB UC WC WT WB +ACPI-rec 00000043fa6c0000-00000043fa70ffff 00000050 320KiB UC WC WT WB +RT-code 00000043fa710000-00000043fa72ffff 00000020 128KiB RT UC WC WT WB +RT-data 00000043fa730000-00000043fa78ffff 00000060 384KiB RT UC WC WT WB +RT-code 00000043fa790000-00000043fa79ffff 00000010 64KiB RT UC WC WT WB +RT-data 00000043fa7a0000-00000043fa99ffff 00000200 2MiB RT UC WC WT WB +RT-code 00000043fa9a0000-00000043fa9affff 00000010 64KiB RT UC WC WT WB +RT-data 00000043fa9b0000-00000043fa9cffff 00000020 128KiB RT UC WC WT WB +BS-code 00000043fa9d0000-00000043fa9d9fff 0000000a 40KiB UC WC WT WB +reserved 00000043fa9da000-00000043fa9dbfff 00000002 8KiB UC WC WT WB +conv-mem 00000043fa9dc000-00000043fc29dfff 000018c2 25352KiB UC WC WT WB +BS-data 00000043fc29e000-00000043fc78afff 000004ed 5044KiB UC WC WT WB +conv-mem 00000043fc78b000-00000043fca01fff 00000277 2524KiB UC WC WT WB +BS-data 00000043fca02000-00000043fcea3fff 000004a2 4744KiB UC WC WT WB +conv-mem 00000043fcea4000-00000043fcea4fff 00000001 4KiB UC WC WT WB +BS-data 00000043fcea5000-00000043fd192fff 000002ee 3000KiB UC WC WT WB +conv-mem 00000043fd193000-00000043fd2b0fff 0000011e 1144KiB UC WC WT WB +BS-data 00000043fd2b1000-00000043ff80ffff 0000255f 38268KiB UC WC WT WB +BS-code 00000043ff810000-00000043ff99ffff 00000190 1600KiB UC WC WT WB +RT-code 00000043ff9a0000-00000043ff9affff 00000010 64KiB RT UC WC WT WB +conv-mem 00000043ff9b0000-00000043ff9bffff 00000010 64KiB UC WC WT WB +RT-data 00000043ff9c0000-00000043ff9effff 00000030 192KiB RT UC WC WT WB +conv-mem 00000043ff9f0000-00000043ffa05fff 00000016 88KiB UC WC WT WB +BS-data 00000043ffa06000-00000043ffffffff 000005fa 6120KiB UC WC WT WB +MMIO 0000000010510000-0000000010510fff 00000001 4KiB RT +MMIO 0000000010548000-0000000010549fff 00000002 8KiB RT +MMIO 0000000017000000-0000000017001fff 00000002 8KiB RT +MMIO 000000001c025000-000000001c025fff 00000001 4KiB RT + +This patch adds a requirement when we're trying to find the base of ram, that +the memory we choose is actually /allocatable/ conventional memory, not merely +write-combining. On this machine that means we wind up with an allocation +around 0x4392XXXXXX, which is a reasonable address. + +This also changes grub_efi_allocate_pages_real() so that if 0 is allocated, it +tries to allocate again starting with the same max address it did the first +time, rather than interposing GRUB_EFI_MAX_USABLE_ADDRESS there, so that any +per-platform constraints on its given address are maintained. + +Signed-off-by: Peter Jones +--- + grub-core/kern/efi/mm.c | 33 +++++++++++++----- + grub-core/loader/arm64/linux.c | 78 ++++++++++++++++++++++++++++++++---------- + 2 files changed, 84 insertions(+), 27 deletions(-) + +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 15595a46e23..1b14fa0694c 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -154,6 +154,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + { + grub_efi_status_t status; + grub_efi_boot_services_t *b; ++ grub_efi_physical_address_t ret = address; + + /* Limit the memory access to less than 4GB for 32-bit platforms. */ + if (address > GRUB_EFI_MAX_USABLE_ADDRESS) +@@ -165,19 +166,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + } + + b = grub_efi_system_table->boot_services; +- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); ++ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret); + if (status != GRUB_EFI_SUCCESS) + { ++ grub_dprintf ("efi", ++ "allocate_pages(%d, %d, 0x%0lx, 0x%016lx) = 0x%016lx\n", ++ alloctype, memtype, pages, address, status); + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); + return NULL; + } + +- if (address == 0) ++ if (ret == 0) + { + /* Uggh, the address 0 was allocated... This is too annoying, + so reallocate another one. */ +- address = GRUB_EFI_MAX_USABLE_ADDRESS; +- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address); ++ ret = address; ++ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret); + grub_efi_free_pages (0, pages); + if (status != GRUB_EFI_SUCCESS) + { +@@ -186,9 +190,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address, + } + } + +- grub_efi_store_alloc (address, pages); ++ grub_efi_store_alloc (ret, pages); + +- return (void *) ((grub_addr_t) address); ++ return (void *) ((grub_addr_t) ret); + } + + void * +@@ -699,8 +703,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) + for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS; + (grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size); + desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) +- if (desc->attribute & GRUB_EFI_MEMORY_WB) +- *base_addr = grub_min (*base_addr, desc->physical_start); ++ { ++ if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY && ++ (desc->attribute & GRUB_EFI_MEMORY_WB)) ++ { ++ *base_addr = grub_min (*base_addr, desc->physical_start); ++ grub_dprintf ("efi", "setting base_addr=0x%016lx\n", *base_addr); ++ } ++ else ++ { ++ grub_dprintf ("efi", "ignoring address 0x%016lx\n", desc->physical_start); ++ } ++ } ++ ++ if (*base_addr == GRUB_EFI_MAX_USABLE_ADDRESS) ++ grub_dprintf ("efi", "base_addr 0x%016lx is probably wrong.\n", *base_addr); + + grub_free(memory_map); + +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index 4c0a09c06de..8791b35b6fe 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -71,13 +71,15 @@ finalize_params_linux (void) + { + grub_efi_loaded_image_t *loaded_image = NULL; + int node, retval, len; +- ++ grub_err_t err = GRUB_ERR_NONE; + void *fdt; + + fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); +- + if (!fdt) +- goto failure; ++ { ++ err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT"); ++ goto failure; ++ } + + node = grub_fdt_find_subnode (fdt, 0, "chosen"); + if (node < 0) +@@ -88,17 +90,26 @@ finalize_params_linux (void) + */ + retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2); + if (retval) +- goto failure; ++ { ++ err = grub_error(retval, "Could not find #address-cells"); ++ goto failure; ++ } + + retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2); + if (retval) +- goto failure; ++ { ++ err = grub_error(retval, "Could not find #size-cells"); ++ goto failure; ++ } + + node = grub_fdt_add_subnode (fdt, 0, "chosen"); + } + + if (node < 1) +- goto failure; ++ { ++ err = grub_error(grub_errno, "failed to load chosen fdt node."); ++ goto failure; ++ } + + /* Set initrd info */ + if (initrd_start && initrd_end > initrd_start) +@@ -109,15 +120,26 @@ finalize_params_linux (void) + retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", + initrd_start); + if (retval) +- goto failure; ++ { ++ err = grub_error(retval, "Failed to set linux,initrd-start property"); ++ goto failure; ++ } ++ + retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end", + initrd_end); + if (retval) +- goto failure; ++ { ++ err = grub_error(retval, "Failed to set linux,initrd-end property"); ++ goto failure; ++ } + } + +- if (grub_fdt_install() != GRUB_ERR_NONE) +- goto failure; ++ retval = grub_fdt_install(); ++ if (retval != GRUB_ERR_NONE) ++ { ++ err = grub_error(retval, "Failed to install fdt"); ++ goto failure; ++ } + + grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", + fdt); +@@ -125,14 +147,20 @@ finalize_params_linux (void) + /* Convert command line to UCS-2 */ + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); + if (!loaded_image) +- goto failure; ++ { ++ err = grub_error(grub_errno, "Failed to install fdt"); ++ goto failure; ++ } + + loaded_image->load_options_size = len = + (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); + loaded_image->load_options = + grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); + if (!loaded_image->load_options) +- return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); ++ { ++ err = grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); ++ goto failure; ++ } + + loaded_image->load_options_size = + 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, +@@ -142,7 +170,7 @@ finalize_params_linux (void) + + failure: + grub_fdt_unload(); +- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); ++ return err; + } + + static void +@@ -226,16 +254,28 @@ grub_linux_unload (void) + static void * + allocate_initrd_mem (int initrd_pages) + { +- grub_addr_t max_addr; ++ grub_addr_t max_addr = 0; ++ grub_err_t err; ++ void *ret; + +- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) +- return NULL; ++ err = grub_efi_get_ram_base (&max_addr); ++ if (err != GRUB_ERR_NONE) ++ { ++ grub_error (err, "grub_efi_get_ram_base() failed"); ++ return NULL; ++ } ++ ++ grub_dprintf ("linux", "max_addr: 0x%016lx, INITRD_MAX_ADDRESS_OFFSET: 0x%016llx\n", ++ max_addr, INITRD_MAX_ADDRESS_OFFSET); + + max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; ++ grub_dprintf ("linux", "calling grub_efi_allocate_pages_real (0x%016lx, 0x%08x, EFI_ALLOCATE_MAX_ADDRESS, EFI_LOADER_DATA)", max_addr, initrd_pages); + +- return grub_efi_allocate_pages_real (max_addr, initrd_pages, +- GRUB_EFI_ALLOCATE_MAX_ADDRESS, +- GRUB_EFI_LOADER_DATA); ++ ret = grub_efi_allocate_pages_real (max_addr, initrd_pages, ++ GRUB_EFI_ALLOCATE_MAX_ADDRESS, ++ GRUB_EFI_LOADER_DATA); ++ grub_dprintf ("linux", "got 0x%016llx\n", (unsigned long long)ret); ++ return ret; + } + + static grub_err_t diff --git a/0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch b/0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch new file mode 100644 index 0000000..25ad649 --- /dev/null +++ b/0150-Try-to-pick-better-locations-for-kernel-and-initrd.patch @@ -0,0 +1,196 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 17:17:02 +0200 +Subject: [PATCH] Try to pick better locations for kernel and initrd + +- Don't limit allocations on 64-bit platforms to < 0x[37f]fffffff if + we're using the "large" code model ; use __UINTPTR_MAX__. +- Get the comparison right to check the address we've allocated. +- Fix the allocation for the command line as well. + +*But*, when we did this some systems started failing badly; coudln't +parse partition tables, etc. What's going on here is the disk controller +is silently failing DMAs to addresses above 4GB, so we're trying to parse +uninitialized (or HW zeroed) ram when looking for the partition table, +etc. + +So to limit this, we make grub_malloc() pick addresses below 4GB on +x86_64, but the direct EFI page allocation functions can get addresses +above that. + +Additionally, we now try to locate kernel+initrd+cmdline+etc below +0x7fffffff, and if they're too big to fit any memory window there, then +we try a higher address. + +Signed-off-by: Peter Jones +--- + grub-core/kern/efi/mm.c | 8 ++++---- + grub-core/loader/i386/efi/linux.c | 24 +++++++++++++++++------- + include/grub/arm/efi/memory.h | 1 + + include/grub/arm64/efi/memory.h | 1 + + include/grub/i386/efi/memory.h | 1 + + include/grub/ia64/efi/memory.h | 1 + + include/grub/x86_64/efi/memory.h | 4 +++- + 7 files changed, 28 insertions(+), 12 deletions(-) + +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 1b14fa0694c..d70e5b45b7c 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -122,7 +122,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max, + grub_efi_boot_services_t *b; + grub_efi_physical_address_t address = max; + +- if (max > 0xffffffff) ++ if (max > GRUB_EFI_MAX_USABLE_ADDRESS) + return 0; + + b = grub_efi_system_table->boot_services; +@@ -466,7 +466,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, + { + if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY + #if 1 +- && desc->physical_start <= GRUB_EFI_MAX_USABLE_ADDRESS ++ && desc->physical_start <= GRUB_EFI_MAX_ALLOCATION_ADDRESS + #endif + && desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000 + && desc->num_pages != 0) +@@ -484,9 +484,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map, + #if 1 + if (BYTES_TO_PAGES (filtered_desc->physical_start) + + filtered_desc->num_pages +- > BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS)) ++ > BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_ALLOCATION_ADDRESS)) + filtered_desc->num_pages +- = (BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_USABLE_ADDRESS) ++ = (BYTES_TO_PAGES_DOWN (GRUB_EFI_MAX_ALLOCATION_ADDRESS) + - BYTES_TO_PAGES (filtered_desc->physical_start)); + #endif + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 3017d0f3e52..33e981e76e7 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -106,7 +107,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + size += ALIGN_UP (grub_file_size (files[i]), 4); + } + +- initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size)); ++ initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, BYTES_TO_PAGES(size)); ++ if (!initrd_mem) ++ initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, BYTES_TO_PAGES(size)); + if (!initrd_mem) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd")); +@@ -202,8 +205,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- params = grub_efi_allocate_pages_max (0x3fffffff, ++ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, + BYTES_TO_PAGES(sizeof(*params))); ++ if (!params) ++ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, ++ BYTES_TO_PAGES(sizeof(*params))); + if (! params) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); +@@ -273,8 +279,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + #endif + + grub_dprintf ("linux", "setting up cmdline\n"); +- linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff, +- BYTES_TO_PAGES(lh->cmdline_size + 1)); ++ linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS, ++ BYTES_TO_PAGES(lh->cmdline_size + 1)); ++ if (!linux_cmdline) ++ linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_USABLE_ADDRESS, ++ BYTES_TO_PAGES(lh->cmdline_size + 1)); + if (!linux_cmdline) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline")); +@@ -301,11 +310,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + kernel_mem = grub_efi_allocate_pages_max(lh->pref_address, + BYTES_TO_PAGES(lh->init_size)); +- + if (!kernel_mem) +- kernel_mem = grub_efi_allocate_pages_max(0x3fffffff, ++ kernel_mem = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS, ++ BYTES_TO_PAGES(lh->init_size)); ++ if (!kernel_mem) ++ kernel_mem = grub_efi_allocate_pages_max(GRUB_EFI_MAX_USABLE_ADDRESS, + BYTES_TO_PAGES(lh->init_size)); +- + if (!kernel_mem) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel")); +diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h +index 2c64918e3f7..a4c2ec83502 100644 +--- a/include/grub/arm/efi/memory.h ++++ b/include/grub/arm/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h +index c6cb3241714..acb61dca44b 100644 +--- a/include/grub/arm64/efi/memory.h ++++ b/include/grub/arm64/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/i386/efi/memory.h b/include/grub/i386/efi/memory.h +index 2c64918e3f7..a4c2ec83502 100644 +--- a/include/grub/i386/efi/memory.h ++++ b/include/grub/i386/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/ia64/efi/memory.h b/include/grub/ia64/efi/memory.h +index 2c64918e3f7..a4c2ec83502 100644 +--- a/include/grub/ia64/efi/memory.h ++++ b/include/grub/ia64/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ +diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h +index 46e9145a308..e81cfb32213 100644 +--- a/include/grub/x86_64/efi/memory.h ++++ b/include/grub/x86_64/efi/memory.h +@@ -2,9 +2,11 @@ + #include + + #if defined (__code_model_large__) +-#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff ++#define GRUB_EFI_MAX_USABLE_ADDRESS __UINTPTR_MAX__ ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS 0x7fffffff + #else + #define GRUB_EFI_MAX_USABLE_ADDRESS 0x7fffffff ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + #endif + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch b/0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch new file mode 100644 index 0000000..db05a0f --- /dev/null +++ b/0151-Attempt-to-fix-up-all-the-places-Wsign-compare-error.patch @@ -0,0 +1,396 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 18:03:25 +0200 +Subject: [PATCH] Attempt to fix up all the places -Wsign-compare=error finds. + +Signed-off-by: Peter Jones +--- + grub-core/kern/emu/misc.c | 2 +- + grub-core/lib/reed_solomon.c | 4 +- + grub-core/osdep/linux/blocklist.c | 2 +- + grub-core/osdep/linux/getroot.c | 2 +- + grub-core/osdep/linux/hostdisk.c | 2 +- + util/grub-fstest.c | 2 +- + util/grub-menulst2cfg.c | 2 +- + util/grub-mkfont.c | 13 +- + util/grub-probe.c | 2 +- + util/grub-rpm-sort.c | 2 +- + util/setup.c | 2 +- + bootstrap.conf | 2 +- + .../gnulib-patches/fix-sign-compare-errors.patch | 161 +++++++++++++++++++++ + 13 files changed, 180 insertions(+), 18 deletions(-) + create mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch + +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 245b69cab51..7a8d9e62300 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -177,7 +177,7 @@ grub_util_get_image_size (const char *path) + sz = ftello (f); + if (sz < 0) + grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); +- if (sz != (size_t) sz) ++ if (sz > (off_t)(GRUB_SIZE_MAX >> 1)) + grub_util_error (_("file `%s' is too big"), path); + ret = (size_t) sz; + +diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c +index ee9fa7b4feb..19c20085279 100644 +--- a/grub-core/lib/reed_solomon.c ++++ b/grub-core/lib/reed_solomon.c +@@ -156,7 +156,7 @@ static void + rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) + { + gf_single_t *rs_polynomial; +- int i, j; ++ unsigned int i, j; + gf_single_t *m; + m = xmalloc ((s + rs) * sizeof (gf_single_t)); + grub_memcpy (m, data, s * sizeof (gf_single_t)); +@@ -325,7 +325,7 @@ static void + encode_block (gf_single_t *ptr, grub_size_t s, + gf_single_t *rptr, grub_size_t rs) + { +- int i, j; ++ unsigned int i, j; + for (i = 0; i < SECTOR_SIZE; i++) + { + grub_size_t ds = (s + SECTOR_SIZE - 1 - i) / SECTOR_SIZE; +diff --git a/grub-core/osdep/linux/blocklist.c b/grub-core/osdep/linux/blocklist.c +index c77d6085ccb..42a315031ff 100644 +--- a/grub-core/osdep/linux/blocklist.c ++++ b/grub-core/osdep/linux/blocklist.c +@@ -109,7 +109,7 @@ grub_install_get_blocklist (grub_device_t root_dev, + else + { + struct fiemap *fie2; +- int i; ++ unsigned int i; + fie2 = xmalloc (sizeof (*fie2) + + fie1.fm_mapped_extents + * sizeof (fie1.fm_extents[1])); +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 4c5a13022dc..2b7a626d5ea 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -236,7 +236,7 @@ grub_find_root_devices_from_btrfs (const char *dir) + { + int fd; + struct btrfs_ioctl_fs_info_args fsi; +- int i, j = 0; ++ unsigned int i, j = 0; + char **ret; + + fd = open (dir, 0); +diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c +index 8b92f8528f9..370d02787cd 100644 +--- a/grub-core/osdep/linux/hostdisk.c ++++ b/grub-core/osdep/linux/hostdisk.c +@@ -83,7 +83,7 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec + if (sector_size & (sector_size - 1) || !sector_size) + return -1; + for (log_sector_size = 0; +- (1 << log_sector_size) < sector_size; ++ (1U << log_sector_size) < sector_size; + log_sector_size++); + + if (log_secsize) +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index f14e02d9727..88f9c5d4ad8 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -323,7 +323,7 @@ cmd_cmp (char *src, char *dest) + read_file (src, cmp_hook, ff); + + { +- grub_uint64_t pre; ++ long long pre; + pre = ftell (ff); + fseek (ff, 0, SEEK_END); + if (pre != ftell (ff)) +diff --git a/util/grub-menulst2cfg.c b/util/grub-menulst2cfg.c +index a39f8693947..358d604210b 100644 +--- a/util/grub-menulst2cfg.c ++++ b/util/grub-menulst2cfg.c +@@ -34,7 +34,7 @@ main (int argc, char **argv) + char *buf = NULL; + size_t bufsize = 0; + char *suffix = xstrdup (""); +- int suffixlen = 0; ++ size_t suffixlen = 0; + const char *out_fname = 0; + + grub_util_host_init (&argc, &argv); +diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c +index 0fe45a6103d..3e09240b99f 100644 +--- a/util/grub-mkfont.c ++++ b/util/grub-mkfont.c +@@ -138,7 +138,8 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + int width, height; + int cuttop, cutbottom, cutleft, cutright; + grub_uint8_t *data; +- int mask, i, j, bitmap_size; ++ int mask, i, bitmap_size; ++ unsigned int j; + FT_GlyphSlot glyph; + int flag = FT_LOAD_RENDER | FT_LOAD_MONOCHROME; + FT_Error err; +@@ -183,7 +184,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + cuttop = cutbottom = cutleft = cutright = 0; + else + { +- for (cuttop = 0; cuttop < glyph->bitmap.rows; cuttop++) ++ for (cuttop = 0; cuttop < (long)glyph->bitmap.rows; cuttop++) + { + for (j = 0; j < glyph->bitmap.width; j++) + if (glyph->bitmap.buffer[j / 8 + cuttop * glyph->bitmap.pitch] +@@ -203,10 +204,10 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + break; + } + cutbottom = glyph->bitmap.rows - 1 - cutbottom; +- if (cutbottom + cuttop >= glyph->bitmap.rows) ++ if (cutbottom + cuttop >= (long)glyph->bitmap.rows) + cutbottom = 0; + +- for (cutleft = 0; cutleft < glyph->bitmap.width; cutleft++) ++ for (cutleft = 0; cutleft < (long)glyph->bitmap.width; cutleft++) + { + for (j = 0; j < glyph->bitmap.rows; j++) + if (glyph->bitmap.buffer[cutleft / 8 + j * glyph->bitmap.pitch] +@@ -225,7 +226,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + break; + } + cutright = glyph->bitmap.width - 1 - cutright; +- if (cutright + cutleft >= glyph->bitmap.width) ++ if (cutright + cutleft >= (long)glyph->bitmap.width) + cutright = 0; + } + +@@ -262,7 +263,7 @@ add_glyph (struct grub_font_info *font_info, FT_UInt glyph_idx, FT_Face face, + + mask = 0; + data = &glyph_info->bitmap[0] - 1; +- for (j = cuttop; j < height + cuttop; j++) ++ for (j = cuttop; j < (long)height + cuttop; j++) + for (i = cutleft; i < width + cutleft; i++) + add_pixel (&data, &mask, + glyph->bitmap.buffer[i / 8 + j * glyph->bitmap.pitch] & +diff --git a/util/grub-probe.c b/util/grub-probe.c +index 81d27eead59..7481e487211 100644 +--- a/util/grub-probe.c ++++ b/util/grub-probe.c +@@ -798,7 +798,7 @@ argp_parser (int key, char *arg, struct argp_state *state) + + case 't': + { +- int i; ++ unsigned int i; + + for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++) + if (strcmp (arg, targets[i]) == 0) +diff --git a/util/grub-rpm-sort.c b/util/grub-rpm-sort.c +index f33bd1ed568..8345944105f 100644 +--- a/util/grub-rpm-sort.c ++++ b/util/grub-rpm-sort.c +@@ -232,7 +232,7 @@ main (int argc, char *argv[]) + struct arguments arguments; + char **package_names = NULL; + size_t n_package_names = 0; +- int i; ++ unsigned int i; + + grub_util_host_init (&argc, &argv); + +diff --git a/util/setup.c b/util/setup.c +index 6f88f3cc43f..864094de682 100644 +--- a/util/setup.c ++++ b/util/setup.c +@@ -402,7 +402,7 @@ SETUP (const char *dir, + int is_ldm; + grub_err_t err; + grub_disk_addr_t *sectors; +- int i; ++ unsigned int i; + grub_fs_t fs; + unsigned int nsec, maxsec; + +diff --git a/bootstrap.conf b/bootstrap.conf +index 988dda099ac..8804d5beb89 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -78,7 +78,7 @@ cp -a INSTALL INSTALL.grub + + bootstrap_post_import_hook () { + set -e +- for patchname in fix-null-deref fix-width no-abort; do ++ for patchname in fix-null-deref fix-width no-abort fix-sign-compare-errors; do + patch -d grub-core/lib/gnulib -p2 \ + < "grub-core/lib/gnulib-patches/$patchname.patch" + done +diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +new file mode 100644 +index 00000000000..479029c0565 +--- /dev/null ++++ b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +@@ -0,0 +1,161 @@ ++diff --git a/lib/regcomp.c b/lib/regcomp.c ++index cc85f35ac58..361079d82d6 100644 ++--- a/lib/regcomp.c +++++ b/lib/regcomp.c ++@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, ++ *p++ = dfa->nodes[node].opr.c; ++ memset (&state, '\0', sizeof (state)); ++ if (__mbrtowc (&wc, (const char *) buf, p - buf, ++- &state) == p - buf +++ &state) == (size_t)(p - buf) ++ && (__wcrtomb ((char *) buf, __towlower (wc), &state) ++ != (size_t) -1)) ++ re_set_fastmap (fastmap, false, buf[0]); ++@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) ++ num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) ++ ? -2 ++ : num == -1 ++- ? c - '0' +++ ? (Idx)(c - '0') ++ : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); ++ } ++ return num; ++diff --git a/lib/regex_internal.c b/lib/regex_internal.c ++index 9004ce809eb..193a1e3d332 100644 ++--- a/lib/regex_internal.c +++++ b/lib/regex_internal.c ++@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) ++ /* Apply the translation if we need. */ ++ if (__glibc_unlikely (pstr->trans != NULL)) ++ { ++- int i, ch; +++ unsigned int i, ch; ++ ++ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) ++ { ++@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) ++ prev_st = pstr->cur_state; ++ if (__glibc_unlikely (pstr->trans != NULL)) ++ { ++- int i, ch; +++ unsigned int i, ch; ++ ++ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) ++ { ++@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) ++ memset (&cur_state, 0, sizeof (cur_state)); ++ mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, ++ &cur_state); ++- if (raw + offset - p <= mbclen +++ if ((size_t)(raw + offset - p) <= mbclen ++ && mbclen < (size_t) -2) ++ { ++ memset (&pstr->cur_state, '\0', ++diff --git a/lib/regex_internal.h b/lib/regex_internal.h ++index 5462419b787..e0f8292395d 100644 ++--- a/lib/regex_internal.h +++++ b/lib/regex_internal.h ++@@ -425,7 +425,7 @@ struct re_string_t ++ unsigned char offsets_needed; ++ unsigned char newline_anchor; ++ unsigned char word_ops_used; ++- int mb_cur_max; +++ unsigned int mb_cur_max; ++ }; ++ typedef struct re_string_t re_string_t; ++ ++@@ -702,7 +702,7 @@ struct re_dfa_t ++ unsigned int is_utf8 : 1; ++ unsigned int map_notascii : 1; ++ unsigned int word_ops_used : 1; ++- int mb_cur_max; +++ unsigned int mb_cur_max; ++ bitset_t word_char; ++ reg_syntax_t syntax; ++ Idx *subexp_map; ++diff --git a/lib/regexec.c b/lib/regexec.c ++index 0a7a27b772e..b57d4f9141d 100644 ++--- a/lib/regexec.c +++++ b/lib/regexec.c ++@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, ++ { ++ if (ret_len) ++ { ++- assert (pmatch[0].rm_so == start); +++ assert (pmatch[0].rm_so == (long)start); ++ rval = pmatch[0].rm_eo - start; ++ } ++ else ++@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, ++ if (__glibc_unlikely (mctx.input.offsets_needed != 0)) ++ { ++ pmatch[reg_idx].rm_so = ++- (pmatch[reg_idx].rm_so == mctx.input.valid_len +++ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len ++ ? mctx.input.valid_raw_len ++ : mctx.input.offsets[pmatch[reg_idx].rm_so]); ++ pmatch[reg_idx].rm_eo = ++- (pmatch[reg_idx].rm_eo == mctx.input.valid_len +++ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len ++ ? mctx.input.valid_raw_len ++ : mctx.input.offsets[pmatch[reg_idx].rm_eo]); ++ } ++@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, ++ } ++ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); ++ ++- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) +++ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) ++ { ++ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); ++ ++- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) +++ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) ++ { ++ Idx reg_idx; ++ if (fs) ++@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, ++ if (reg_num < nmatch) ++ { ++ /* We are at the last node of this sub expression. */ ++- if (pmatch[reg_num].rm_so < cur_idx) +++ if (pmatch[reg_num].rm_so < (long)cur_idx) ++ { ++ pmatch[reg_num].rm_eo = cur_idx; ++ /* This is a non-empty match or we are not inside an optional ++@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, ++ mctx->state_log[str_idx] = cur_state; ++ } ++ ++- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) +++ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) ++ { ++ re_node_set_empty (&next_nodes); ++ if (mctx->state_log[str_idx + 1]) ++@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, ++ const re_string_t *input, Idx str_idx) ++ { ++ const re_token_t *node = dfa->nodes + node_idx; ++- int char_len, elem_len; +++ unsigned int char_len, elem_len; ++ Idx i; ++ ++ if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) ++@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) ++ /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ ++ ret = re_string_realloc_buffers (pstr, ++ MAX (min_len, ++- MIN (pstr->len, pstr->bufs_len * 2))); +++ MIN ((long)pstr->len, pstr->bufs_len * 2))); ++ if (__glibc_unlikely (ret != REG_NOERROR)) ++ return ret; ++ ++@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, ++ = (from == to ? -1 : 0); ++ ++ mctx->bkref_ents[mctx->nbkref_ents++].more = 0; ++- if (mctx->max_mb_elem_len < to - from) +++ if (mctx->max_mb_elem_len < (long)(to - from)) ++ mctx->max_mb_elem_len = to - from; ++ return REG_NOERROR; ++ } diff --git a/0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch b/0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch new file mode 100644 index 0000000..b2e5de0 --- /dev/null +++ b/0152-Don-t-use-Wno-sign-compare-Wno-conversion-Wno-error-.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 11 Jul 2019 18:20:37 +0200 +Subject: [PATCH] Don't use -Wno-sign-compare -Wno-conversion -Wno-error, do + use -Wextra. + +Signed-off-by: Peter Jones +--- + configure.ac | 14 +++++++++++--- + conf/Makefile.common | 2 +- + 2 files changed, 12 insertions(+), 4 deletions(-) + +diff --git a/configure.ac b/configure.ac +index bca7c2818af..38d978bd650 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1424,11 +1424,11 @@ fi + # Set them to their new values for the tests below. + CC="$TARGET_CC" + if test x"$platform" = xemu ; then +-CFLAGS="$TARGET_CFLAGS -Wno-error" ++CFLAGS="$TARGET_CFLAGS" + elif test "x$TARGET_APPLE_LINKER" = x1 ; then +-CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error" ++CFLAGS="$TARGET_CFLAGS -nostdlib -static" + else +-CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error" ++CFLAGS="$TARGET_CFLAGS -nostdlib" + fi + CPPFLAGS="$TARGET_CPPFLAGS" + +@@ -1987,6 +1987,14 @@ if test x"$enable_werror" != xno ; then + HOST_CFLAGS="$HOST_CFLAGS -Werror" + fi + ++AC_ARG_ENABLE([wextra], ++ [AS_HELP_STRING([--disable-wextra], ++ [do not use -Wextra when building GRUB])]) ++if test x"$enable_wextra" != xno ; then ++ TARGET_CFLAGS="$TARGET_CFLAGS -Wextra" ++ HOST_CFLAGS="$HOST_CFLAGS -Wextra" ++fi ++ + TARGET_CPP="$TARGET_CC -E" + TARGET_CCAS=$TARGET_CC + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index bbf33b0bc4a..b867691f125 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield + +-CFLAGS_GNULIB = -Wno-undef -Wno-sign-compare -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Wno-conversion ++CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib + + CFLAGS_POSIX = -fno-builtin diff --git a/0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch b/0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch new file mode 100644 index 0000000..fdd3096 --- /dev/null +++ b/0153-x86-efi-Use-bounce-buffers-for-reading-to-addresses-.patch @@ -0,0 +1,101 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 12 Jul 2019 09:53:32 +0200 +Subject: [PATCH] x86-efi: Use bounce buffers for reading to addresses > 4GB + +Lots of machines apparently can't DMA correctly above 4GB during UEFI, +so use bounce buffers for the initramfs read. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 52 +++++++++++++++++++++++++++++++++------ + 1 file changed, 45 insertions(+), 7 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 33e981e76e7..2f0336809e7 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -35,11 +35,16 @@ static grub_dl_t my_mod; + static int loaded; + static void *kernel_mem; + static grub_uint64_t kernel_size; +-static grub_uint8_t *initrd_mem; ++static void *initrd_mem; + static grub_uint32_t handover_offset; + struct linux_kernel_params *params; + static char *linux_cmdline; + ++#define MIN(a, b) \ ++ ({ typeof (a) _a = (a); \ ++ typeof (b) _b = (b); \ ++ _a < _b ? _a : _b; }) ++ + #define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) + + static grub_err_t +@@ -73,6 +78,44 @@ grub_linuxefi_unload (void) + return GRUB_ERR_NONE; + } + ++#define BOUNCE_BUFFER_MAX 0x10000000ull ++ ++static grub_ssize_t ++read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len) ++{ ++ grub_ssize_t bufpos = 0; ++ static grub_size_t bbufsz = 0; ++ static char *bbuf = NULL; ++ ++ if (bbufsz == 0) ++ bbufsz = MIN(BOUNCE_BUFFER_MAX, len); ++ ++ while (!bbuf && bbufsz) ++ { ++ bbuf = grub_malloc(bbufsz); ++ if (!bbuf) ++ bbufsz >>= 1; ++ } ++ if (!bbuf) ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate bounce buffer")); ++ ++ while (bufpos < (long long)len) ++ { ++ grub_ssize_t sz; ++ ++ sz = grub_file_read (file, bbuf, MIN(bbufsz, len - bufpos)); ++ if (sz < 0) ++ return sz; ++ if (sz == 0) ++ break; ++ ++ grub_memcpy(bufp + bufpos, bbuf, sz); ++ bufpos += sz; ++ } ++ ++ return bufpos; ++} ++ + static grub_err_t + grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +@@ -126,7 +169,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + for (i = 0; i < nfiles; i++) + { + grub_ssize_t cursize = grub_file_size (files[i]); +- if (grub_file_read (files[i], ptr, cursize) != cursize) ++ if (read (files[i], ptr, cursize) != cursize) + { + if (!grub_errno) + grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), +@@ -152,11 +195,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + return grub_errno; + } + +-#define MIN(a, b) \ +- ({ typeof (a) _a = (a); \ +- typeof (b) _b = (b); \ +- _a < _b ? _a : _b; }) +- + static grub_err_t + grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) diff --git a/0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch b/0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch new file mode 100644 index 0000000..f8284ec --- /dev/null +++ b/0154-x86-efi-Re-arrange-grub_cmd_linux-a-little-bit.patch @@ -0,0 +1,133 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 13 Sep 2018 14:42:34 -0400 +Subject: [PATCH] x86-efi: Re-arrange grub_cmd_linux() a little bit. + +This just helps the next patch be easier to read. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 75 +++++++++++++++++++++------------------ + 1 file changed, 41 insertions(+), 34 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 2f0336809e7..5f48fa55619 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -243,32 +243,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, +- BYTES_TO_PAGES(sizeof(*params))); +- if (!params) +- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, +- BYTES_TO_PAGES(sizeof(*params))); +- if (! params) +- { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); +- goto fail; +- } ++ lh = (struct linux_i386_kernel_header *)kernel; ++ grub_dprintf ("linux", "original lh is at %p\n", kernel); + +- grub_dprintf ("linux", "params = %p\n", params); +- +- grub_memset (params, 0, sizeof(*params)); +- +- setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); +- grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", +- MIN((grub_size_t)0x202+setup_header_end_offset, +- sizeof (*params)) - 0x1f1, +- (grub_uint8_t *)kernel + 0x1f1, +- (grub_uint8_t *)params + 0x1f1); +- grub_memcpy ((grub_uint8_t *)params + 0x1f1, +- (grub_uint8_t *)kernel + 0x1f1, +- MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); +- lh = (struct linux_i386_kernel_header *)params; +- grub_dprintf ("linux", "lh is at %p\n", lh); + grub_dprintf ("linux", "checking lh->boot_flag\n"); + if (lh->boot_flag != grub_cpu_to_le16 (0xaa55)) + { +@@ -316,6 +293,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + ++ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, ++ BYTES_TO_PAGES(sizeof(*params))); ++ if (!params) ++ params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, ++ BYTES_TO_PAGES(sizeof(*params))); ++ if (! params) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); ++ goto fail; ++ } ++ ++ grub_dprintf ("linux", "params = %p\n", params); ++ ++ grub_memset (params, 0, sizeof(*params)); ++ ++ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); ++ grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", ++ MIN((grub_size_t)0x202+setup_header_end_offset, ++ sizeof (*params)) - 0x1f1, ++ (grub_uint8_t *)kernel + 0x1f1, ++ (grub_uint8_t *)params + 0x1f1); ++ grub_memcpy ((grub_uint8_t *)params + 0x1f1, ++ (grub_uint8_t *)kernel + 0x1f1, ++ MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); ++ ++ lh = (struct linux_i386_kernel_header *)params; ++ grub_dprintf ("linux", "new lh is at %p\n", lh); ++ + grub_dprintf ("linux", "setting up cmdline\n"); + linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS, + BYTES_TO_PAGES(lh->cmdline_size + 1)); +@@ -341,8 +346,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "setting lh->cmd_line_ptr\n"); + lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; + +- grub_dprintf ("linux", "computing handover offset\n"); + handover_offset = lh->handover_offset; ++ grub_dprintf("linux", "handover_offset: %08x\n", handover_offset); + + start = (lh->setup_sects + 1) * 512; + +@@ -359,26 +364,28 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel")); + goto fail; + } +- +- grub_dprintf ("linux", "kernel_mem = %lx\n", (unsigned long) kernel_mem); ++ grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); + + grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); +- loaded=1; ++ ++ loaded = 1; ++ + grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem); + lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem; + + grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); + +- grub_dprintf ("linux", "setting lh->type_of_loader\n"); + lh->type_of_loader = 0x6; ++ grub_dprintf ("linux", "setting lh->type_of_loader = 0x%02x\n", ++ lh->type_of_loader); + +- grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n"); + params->ext_loader_type = 0; + params->ext_loader_ver = 2; +- grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n", +- kernel_mem, handover_offset); ++ grub_dprintf ("linux", ++ "setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n", ++ params->ext_loader_type, params->ext_loader_ver); + +- fail: ++fail: + if (file) + grub_file_close (file); + diff --git a/0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch b/0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch new file mode 100644 index 0000000..3bfb482 --- /dev/null +++ b/0155-x86-efi-Make-our-own-allocator-for-kernel-stuff.patch @@ -0,0 +1,258 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 12 Sep 2018 16:03:55 -0400 +Subject: [PATCH] x86-efi: Make our own allocator for kernel stuff + +This helps enable allocations above 4GB. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 167 +++++++++++++++++++++----------------- + 1 file changed, 94 insertions(+), 73 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 5f48fa55619..075b77eb3e4 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -47,6 +47,65 @@ static char *linux_cmdline; + + #define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) + ++struct allocation_choice { ++ grub_efi_physical_address_t addr; ++ grub_efi_allocate_type_t alloc_type; ++}; ++ ++static struct allocation_choice max_addresses[] = ++ { ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ { 0, 0 } ++ }; ++ ++static inline void ++kernel_free(void *addr, grub_efi_uintn_t size) ++{ ++ if (addr && size) ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)addr, ++ BYTES_TO_PAGES(size)); ++} ++ ++static void * ++kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) ++{ ++ void *addr = 0; ++ unsigned int i; ++ grub_efi_physical_address_t prev_max = 0; ++ ++ for (i = 0; max_addresses[i].addr != 0 && addr == 0; i++) ++ { ++ grub_uint64_t max = max_addresses[i].addr; ++ grub_efi_uintn_t pages; ++ ++ if (max == prev_max) ++ continue; ++ ++ pages = BYTES_TO_PAGES(size); ++ grub_dprintf ("linux", "Trying to allocate %lu pages from %p\n", ++ pages, (void *)max); ++ ++ prev_max = max; ++ addr = grub_efi_allocate_pages_real (max, pages, ++ max_addresses[i].alloc_type, ++ GRUB_EFI_LOADER_DATA); ++ if (addr) ++ grub_dprintf ("linux", "Allocated at %p\n", addr); ++ } ++ ++ while (grub_error_pop ()) ++ { ++ ; ++ } ++ ++ if (addr == NULL) ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, errmsg); ++ ++ return addr; ++} ++ + static grub_err_t + grub_linuxefi_boot (void) + { +@@ -62,19 +121,12 @@ grub_linuxefi_unload (void) + { + grub_dl_unref (my_mod); + loaded = 0; +- if (initrd_mem) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, +- BYTES_TO_PAGES(params->ramdisk_size)); +- if (linux_cmdline) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) +- linux_cmdline, +- BYTES_TO_PAGES(params->cmdline_size + 1)); +- if (kernel_mem) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, +- BYTES_TO_PAGES(kernel_size)); +- if (params) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, +- BYTES_TO_PAGES(16384)); ++ ++ kernel_free(initrd_mem, params->ramdisk_size); ++ kernel_free(linux_cmdline, params->cmdline_size + 1); ++ kernel_free(kernel_mem, kernel_size); ++ kernel_free(params, sizeof(*params)); ++ + return GRUB_ERR_NONE; + } + +@@ -150,19 +202,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + size += ALIGN_UP (grub_file_size (files[i]), 4); + } + +- initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, BYTES_TO_PAGES(size)); +- if (!initrd_mem) +- initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, BYTES_TO_PAGES(size)); +- if (!initrd_mem) +- { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd")); +- goto fail; +- } +- +- grub_dprintf ("linux", "initrd_mem = %lx\n", (unsigned long) initrd_mem); ++ initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); ++ if (initrd_mem == NULL) ++ goto fail; ++ grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); + + params->ramdisk_size = size; +- params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; ++ params->ramdisk_image = initrd_mem; + + ptr = initrd_mem; + +@@ -221,7 +267,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + filelen = grub_file_size (file); + + kernel = grub_malloc(filelen); +- + if (!kernel) + { + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer")); +@@ -274,7 +319,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +-#if defined(__x86_64__) || defined(__aarch64__) ++#if defined(__x86_64__) + grub_dprintf ("linux", "checking lh->xloadflags\n"); + if (!(lh->xloadflags & LINUX_XLF_KERNEL_64)) + { +@@ -293,17 +338,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + +- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, +- BYTES_TO_PAGES(sizeof(*params))); ++ params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters"); + if (!params) +- params = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, +- BYTES_TO_PAGES(sizeof(*params))); +- if (! params) +- { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters"); +- goto fail; +- } +- ++ goto fail; + grub_dprintf ("linux", "params = %p\n", params); + + grub_memset (params, 0, sizeof(*params)); +@@ -322,19 +359,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_dprintf ("linux", "new lh is at %p\n", lh); + + grub_dprintf ("linux", "setting up cmdline\n"); +- linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS, +- BYTES_TO_PAGES(lh->cmdline_size + 1)); ++ linux_cmdline = kernel_alloc (lh->cmdline_size + 1, N_("can't allocate cmdline")); + if (!linux_cmdline) +- linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_USABLE_ADDRESS, +- BYTES_TO_PAGES(lh->cmdline_size + 1)); +- if (!linux_cmdline) +- { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline")); +- goto fail; +- } +- +- grub_dprintf ("linux", "linux_cmdline = %lx\n", +- (unsigned long)linux_cmdline); ++ goto fail; ++ grub_dprintf ("linux", "linux_cmdline = %p\n", linux_cmdline); + + grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE)); + grub_create_loader_cmdline (argc, argv, +@@ -343,27 +371,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + GRUB_VERIFY_KERNEL_CMDLINE); + + grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); +- grub_dprintf ("linux", "setting lh->cmd_line_ptr\n"); +- lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; ++ grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", ++ linux_cmdline); ++ lh->cmd_line_ptr = linux_cmdline; + + handover_offset = lh->handover_offset; +- grub_dprintf("linux", "handover_offset: %08x\n", handover_offset); ++ grub_dprintf("linux", "handover_offset: 0x%08x\n", handover_offset); + + start = (lh->setup_sects + 1) * 512; + +- kernel_mem = grub_efi_allocate_pages_max(lh->pref_address, +- BYTES_TO_PAGES(lh->init_size)); +- if (!kernel_mem) +- kernel_mem = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS, +- BYTES_TO_PAGES(lh->init_size)); +- if (!kernel_mem) +- kernel_mem = grub_efi_allocate_pages_max(GRUB_EFI_MAX_USABLE_ADDRESS, +- BYTES_TO_PAGES(lh->init_size)); +- if (!kernel_mem) ++ grub_dprintf ("linux", "lh->pref_address: %p\n", (void *)(grub_addr_t)lh->pref_address); ++ if (lh->pref_address < (grub_uint64_t)GRUB_EFI_MAX_ALLOCATION_ADDRESS) + { +- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel")); +- goto fail; ++ max_addresses[0].addr = lh->pref_address; ++ max_addresses[0].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS; + } ++ kernel_mem = kernel_alloc (lh->init_size, N_("can't allocate kernel")); ++ if (!kernel_mem) ++ goto fail; + grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); + + grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); +@@ -398,18 +423,14 @@ fail: + loaded = 0; + } + +- if (linux_cmdline && lh && !loaded) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t) +- linux_cmdline, +- BYTES_TO_PAGES(lh->cmdline_size + 1)); ++ if (!loaded) ++ { ++ if (lh) ++ kernel_free (linux_cmdline, lh->cmdline_size + 1); + +- if (kernel_mem && !loaded) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, +- BYTES_TO_PAGES(kernel_size)); +- +- if (params && !loaded) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, +- BYTES_TO_PAGES(16384)); ++ kernel_free (kernel_mem, kernel_size); ++ kernel_free (params, sizeof(*params)); ++ } + + return grub_errno; + } diff --git a/0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch b/0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch new file mode 100644 index 0000000..f545a06 --- /dev/null +++ b/0156-x86-efi-Allow-initrd-params-cmdline-allocations-abov.patch @@ -0,0 +1,171 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 12 Sep 2018 16:12:27 -0400 +Subject: [PATCH] x86-efi: Allow initrd+params+cmdline allocations above 4GB. + +This enables everything except the kernel itself to be above 4GB. +Putting the kernel up there still doesn't work, because of the way +params->code32_start is used. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 67 +++++++++++++++++++++++++++++++++++---- + include/grub/i386/linux.h | 6 +++- + 2 files changed, 65 insertions(+), 8 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 075b77eb3e4..50b7798d6e5 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -52,13 +52,22 @@ struct allocation_choice { + grub_efi_allocate_type_t alloc_type; + }; + +-static struct allocation_choice max_addresses[] = ++static struct allocation_choice max_addresses[4] = + { ++ /* the kernel overrides this one with pref_address and ++ * GRUB_EFI_ALLOCATE_ADDRESS */ + { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ /* this one is always below 4GB, which we still *prefer* even if the flag ++ * is set. */ + { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, ++ /* If the flag in params is set, this one gets changed to be above 4GB. */ + { GRUB_EFI_MAX_ALLOCATION_ADDRESS, GRUB_EFI_ALLOCATE_MAX_ADDRESS }, + { 0, 0 } + }; ++static struct allocation_choice saved_addresses[4]; ++ ++#define save_addresses() grub_memcpy(saved_addresses, max_addresses, sizeof(max_addresses)) ++#define restore_addresses() grub_memcpy(max_addresses, saved_addresses, sizeof(max_addresses)) + + static inline void + kernel_free(void *addr, grub_efi_uintn_t size) +@@ -80,6 +89,11 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + grub_uint64_t max = max_addresses[i].addr; + grub_efi_uintn_t pages; + ++ /* ++ * When we're *not* loading the kernel, or >4GB allocations aren't ++ * supported, these entries are basically all the same, so don't re-try ++ * the same parameters. ++ */ + if (max == prev_max) + continue; + +@@ -168,6 +182,9 @@ read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len) + return bufpos; + } + ++#define LOW_U32(val) ((grub_uint32_t)(((grub_addr_t)(val)) & 0xffffffffull)) ++#define HIGH_U32(val) ((grub_uint32_t)(((grub_addr_t)(val) >> 32) & 0xffffffffull)) ++ + static grub_err_t + grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +@@ -207,8 +224,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem); + +- params->ramdisk_size = size; +- params->ramdisk_image = initrd_mem; ++ params->ramdisk_size = LOW_U32(size); ++ params->ramdisk_image = LOW_U32(initrd_mem); ++#if defined(__x86_64__) ++ params->ext_ramdisk_size = HIGH_U32(size); ++ params->ext_ramdisk_image = HIGH_U32(initrd_mem); ++#endif + + ptr = initrd_mem; + +@@ -338,6 +359,18 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + #endif + ++#if defined(__x86_64__) ++ if (lh->xloadflags & LINUX_XLF_CAN_BE_LOADED_ABOVE_4G) ++ { ++ grub_dprintf ("linux", "Loading kernel above 4GB is supported; enabling.\n"); ++ max_addresses[2].addr = GRUB_EFI_MAX_USABLE_ADDRESS; ++ } ++ else ++ { ++ grub_dprintf ("linux", "Loading kernel above 4GB is not supported\n"); ++ } ++#endif ++ + params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters"); + if (!params) + goto fail; +@@ -372,21 +405,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline); + grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n", +- linux_cmdline); +- lh->cmd_line_ptr = linux_cmdline; ++ LOW_U32(linux_cmdline)); ++ lh->cmd_line_ptr = LOW_U32(linux_cmdline); ++#if defined(__x86_64__) ++ if ((grub_efi_uintn_t)linux_cmdline > 0xffffffffull) ++ { ++ grub_dprintf ("linux", "setting params->ext_cmd_line_ptr to 0x%08x\n", ++ HIGH_U32(linux_cmdline)); ++ params->ext_cmd_line_ptr = HIGH_U32(linux_cmdline); ++ } ++#endif + + handover_offset = lh->handover_offset; + grub_dprintf("linux", "handover_offset: 0x%08x\n", handover_offset); + + start = (lh->setup_sects + 1) * 512; + ++ /* ++ * AFAICS >4GB for kernel *cannot* work because of params->code32_start being ++ * 32-bit and getting called unconditionally in head_64.S from either entry ++ * point. ++ * ++ * so nerf that out here... ++ */ ++ save_addresses(); + grub_dprintf ("linux", "lh->pref_address: %p\n", (void *)(grub_addr_t)lh->pref_address); + if (lh->pref_address < (grub_uint64_t)GRUB_EFI_MAX_ALLOCATION_ADDRESS) + { + max_addresses[0].addr = lh->pref_address; + max_addresses[0].alloc_type = GRUB_EFI_ALLOCATE_ADDRESS; + } ++ max_addresses[1].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; ++ max_addresses[2].addr = GRUB_EFI_MAX_ALLOCATION_ADDRESS; + kernel_mem = kernel_alloc (lh->init_size, N_("can't allocate kernel")); ++ restore_addresses(); + if (!kernel_mem) + goto fail; + grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem); +@@ -395,8 +447,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + loaded = 1; + +- grub_dprintf ("linux", "setting lh->code32_start to %p\n", kernel_mem); +- lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem; ++ grub_dprintf ("linux", "setting lh->code32_start to 0x%08x\n", ++ LOW_U32(kernel_mem)); ++ lh->code32_start = LOW_U32(kernel_mem); + + grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start); + +diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h +index a093679cb80..91123b1eb5c 100644 +--- a/include/grub/i386/linux.h ++++ b/include/grub/i386/linux.h +@@ -234,7 +234,11 @@ struct linux_kernel_params + grub_uint32_t ofw_cif_handler; /* b8 */ + grub_uint32_t ofw_idt; /* bc */ + +- grub_uint8_t padding7[0x1b8 - 0xc0]; ++ grub_uint32_t ext_ramdisk_image; /* 0xc0 */ ++ grub_uint32_t ext_ramdisk_size; /* 0xc4 */ ++ grub_uint32_t ext_cmd_line_ptr; /* 0xc8 */ ++ ++ grub_uint8_t padding7[0x1b8 - 0xcc]; + + union + { diff --git a/0157-Fix-getroot.c-s-trampolines.patch b/0157-Fix-getroot.c-s-trampolines.patch new file mode 100644 index 0000000..85fe933 --- /dev/null +++ b/0157-Fix-getroot.c-s-trampolines.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 28 Sep 2018 15:42:19 -0400 +Subject: [PATCH] Fix getroot.c's trampolines. + +This makes the stack executable on most of the grub utilities, which is +bad, and rpmdiff complains about it. + +Signed-off-by: Peter Jones +--- + grub-core/osdep/linux/getroot.c | 16 +++++++--------- + 1 file changed, 7 insertions(+), 9 deletions(-) + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 2b7a626d5ea..36429a7cd25 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -1264,22 +1264,20 @@ grub_util_get_grub_dev_os (const char *os_dev) + return grub_dev; + } + ++static void *mp = NULL; ++static void ++btrfs_mount_path_hook(const char *m) ++{ ++ mp = strdup (m); ++} + + char * + grub_util_get_btrfs_subvol (const char *path, char **mount_path) + { +- char *mp = NULL; +- + if (mount_path) + *mount_path = NULL; + +- auto void +- mount_path_hook (const char *m) +- { +- mp = strdup (m); +- } +- +- grub_find_root_btrfs_mount_path_hook = mount_path_hook; ++ grub_find_root_btrfs_mount_path_hook = btrfs_mount_path_hook; + grub_free (grub_find_root_devices_from_mountinfo (path, NULL)); + grub_find_root_btrfs_mount_path_hook = NULL; + diff --git a/0158-Do-not-allow-stack-trampolines-anywhere.patch b/0158-Do-not-allow-stack-trampolines-anywhere.patch new file mode 100644 index 0000000..62b9463 --- /dev/null +++ b/0158-Do-not-allow-stack-trampolines-anywhere.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 12 Jul 2019 10:06:50 +0200 +Subject: [PATCH] Do not allow stack trampolines, anywhere. + +Signed-off-by: Peter Jones +--- + configure.ac | 3 +++ + conf/Makefile.common | 2 +- + 2 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 38d978bd650..5076d635c57 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1995,6 +1995,9 @@ if test x"$enable_wextra" != xno ; then + HOST_CFLAGS="$HOST_CFLAGS -Wextra" + fi + ++TARGET_CFLAGS="$TARGET_CFLAGS -Werror=trampolines -fno-trampolines" ++HOST_CFLAGS="$HOST_CFLAGS -Werror=trampolines -fno-trampolines" ++ + TARGET_CPP="$TARGET_CC -E" + TARGET_CCAS=$TARGET_CC + +diff --git a/conf/Makefile.common b/conf/Makefile.common +index b867691f125..87c1f0e809b 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -66,7 +66,7 @@ grubconfdir = $(sysconfdir)/grub.d + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield + +-CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code ++CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib + + CFLAGS_POSIX = -fno-builtin diff --git a/0159-Reimplement-boot_counter.patch b/0159-Reimplement-boot_counter.patch new file mode 100644 index 0000000..08c8c58 --- /dev/null +++ b/0159-Reimplement-boot_counter.patch @@ -0,0 +1,196 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 4 Oct 2018 14:22:09 -0400 +Subject: [PATCH] Reimplement boot_counter + +This adds "increment" and "decrement" commands, and uses them to maintain our +variables in 01_fallback_counter. It also simplifies the counter logic, so +that there are no nested tests that conflict with each other. + +Apparently, this *really* wasn't tested well enough. + +Resolves: rhbz#1614637 +Signed-off-by: Peter Jones +[lorbus: add comments and revert logic changes in 01_fallback_counting] +Signed-off-by: Christian Glombek +--- + Makefile.util.def | 6 +++ + grub-core/Makefile.core.def | 5 ++ + grub-core/commands/increment.c | 105 ++++++++++++++++++++++++++++++++++++ + util/grub.d/01_fallback_counting.in | 22 ++++++++ + 4 files changed, 138 insertions(+) + create mode 100644 grub-core/commands/increment.c + create mode 100644 util/grub.d/01_fallback_counting.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 125ad6209b2..2019ebd0207 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -457,6 +457,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '01_fallback_counting'; ++ common = util/grub.d/01_fallback_counting.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '01_menu_auto_hide'; + common = util/grub.d/01_menu_auto_hide.in; +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 8bb1dafd0ac..65ca74f9ad9 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -395,6 +395,11 @@ kernel = { + extra_dist = kern/mips/cache_flush.S; + }; + ++module = { ++ name = increment; ++ common = commands/increment.c; ++}; ++ + program = { + name = grub-emu; + mansection = 1; +diff --git a/grub-core/commands/increment.c b/grub-core/commands/increment.c +new file mode 100644 +index 00000000000..79cf137656c +--- /dev/null ++++ b/grub-core/commands/increment.c +@@ -0,0 +1,105 @@ ++/* increment.c - Commands to increment and decrement variables. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++typedef enum { ++ INCREMENT, ++ DECREMENT, ++} operation; ++ ++static grub_err_t ++incr_decr(operation op, int argc, char **args) ++{ ++ const char *old; ++ char *new; ++ long value; ++ ++ if (argc < 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no variable specified")); ++ if (argc > 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("too many arguments")); ++ ++ old = grub_env_get (*args); ++ if (!old) ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("No such variable \"%s\""), ++ *args); ++ ++ value = grub_strtol (old, NULL, 0); ++ if (grub_errno != GRUB_ERR_NONE) ++ return grub_errno; ++ ++ switch (op) ++ { ++ case INCREMENT: ++ value += 1; ++ break; ++ case DECREMENT: ++ value -= 1; ++ break; ++ } ++ ++ new = grub_xasprintf ("%ld", value); ++ if (!new) ++ return grub_errno; ++ ++ grub_env_set (*args, new); ++ grub_free (new); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_cmd_incr(struct grub_command *cmd UNUSED, ++ int argc, char **args) ++{ ++ return incr_decr(INCREMENT, argc, args); ++} ++ ++static grub_err_t ++grub_cmd_decr(struct grub_command *cmd UNUSED, ++ int argc, char **args) ++{ ++ return incr_decr(DECREMENT, argc, args); ++} ++ ++static grub_command_t cmd_incr, cmd_decr; ++ ++GRUB_MOD_INIT(increment) ++{ ++ cmd_incr = grub_register_command ("increment", grub_cmd_incr, N_("VARIABLE"), ++ N_("increment VARIABLE")); ++ cmd_decr = grub_register_command ("decrement", grub_cmd_decr, N_("VARIABLE"), ++ N_("decrement VARIABLE")); ++} ++ ++GRUB_MOD_FINI(increment) ++{ ++ grub_unregister_command (cmd_incr); ++ grub_unregister_command (cmd_decr); ++} +diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/01_fallback_counting.in +new file mode 100644 +index 00000000000..be0e770ea82 +--- /dev/null ++++ b/util/grub.d/01_fallback_counting.in +@@ -0,0 +1,22 @@ ++#! /bin/sh -e ++ ++# Boot Counting ++# The boot_counter env var can be used to count down boot attempts after an ++# OSTree upgrade and choose the rollback deployment when 0 is reached. Both ++# boot_counter and boot_success need to be (re-)set from userspace. ++cat << EOF ++insmod increment ++# Check if boot_counter exists and boot_success=0 to activate this behaviour. ++if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then ++ # if countdown has ended, choose to boot rollback deployment (default=1 on ++ # OSTree-based systems) ++ if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then ++ set default=1 ++ set boot_counter=-1 ++ # otherwise decrement boot_counter ++ else ++ decrement boot_counter ++ fi ++ save_env boot_counter ++fi ++EOF diff --git a/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch b/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch new file mode 100644 index 0000000..30c0828 --- /dev/null +++ b/0160-Make-grub_strtol-end-pointers-have-safer-const-quali.patch @@ -0,0 +1,987 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 19 Oct 2018 13:41:48 -0400 +Subject: [PATCH] Make grub_strtol() "end" pointers have safer const + qualifiers. (v2) + +Currently the string functions grub_strtol(), grub_strtoul(), and +grub_strtoull() don't declare the "end" pointer in such a way as to +require the pointer itself or the character array to be immutable to the +implementation, nor does the C standard do so in its similar functions, +though it does require us not to change any of it. + +The typical declarations of these functions follow this pattern: + +long +strtol(const char * restrict nptr, char ** restrict endptr, int base); + +Much of the reason for this is historic, and a discussion of that +follows below, after the explanation of this change. (GRUB currently +does not include the "restrict" qualifiers, and we name the arguments a +bit differently.) + +The implementation is semantically required to treat the character array +as immutable, but such accidental modifications aren't stopped by the +compiler, and the semantics for both the callers and the implementation +of these functions are sometimes also helped by adding that requirement. + +This patch changes these declarations to follow this pattern instead: + +long +strtol(const char * restrict nptr, + const char ** const restrict endptr, + int base); + +This means that if any modification to these functions accidentally +introduces either an errant modification to the underlying character +array, or an accidental assignment to endptr rather than *endptr, the +compiler should generate an error. (The two uses of "restrict" in this +case basically mean strtol() isn't allowed to modify the character array +by going through *endptr, and endptr isn't allowed to point inside the +array.) + +It also means the typical use case changes to: + + char *s = ...; + const char *end; + long l; + + l = strtol(s, &end, 10); + +Or even: + + const char *p = str; + while (p && *p) { + long l = strtol(p, &p, 10); + ... + } + +This fixes 26 places where we discard our attempts at treating the data +safely by doing: + + const char *p = str; + long l; + + l = strtol(p, (char **)&ptr, 10); + +It also adds 5 places where we do: + + char *p = str; + while (p && *p) { + long l = strtol(p, (const char ** const)&p, 10); + ... + /* more calls that need p not to be pointer-to-const */ + } + +While moderately distasteful, this is a better problem to have. + +With one minor exception, I have tested that all of this compiles +without relevant warnings or errors, and that /much/ of it behaves +correctly, with gcc 9 using 'gcc -W -Wall -Wextra'. The one exception +is the changes in grub-core/osdep/aros/hostdisk.c , which I have no idea +how to build. + +Because the C standard defined type-qualifiers in a way that can be +confusing, in the past there's been a slow but fairly regular stream of +churn within our patches, which add and remove the const qualifier in many +of the users of these functions. This change should help avoid that in +the future, and in order to help ensure this, I've added an explanation +in misc.h so that when someone does get a compiler warning about a type +error, they have the fix at hand. + +The reason we don't have "const" in these calls in the standard is +purely anachronistic: C78 (de facto) did not have type qualifiers in the +syntax, and the "const" type qualifier was added for C89 (I think; it +may have been later). strtol() appears to date from 4.3BSD in 1986, +which means it could not be added to those functions in the standard +without breaking compatibility, which is usually avoided. + +The syntax chosen for type qualifiers is what has led to the churn +regarding usage of const, and is especially confusing on string +functions due to the lack of a string type. Quoting from C99, the +syntax is: + + declarator: + pointer[opt] direct-declarator + direct-declarator: + identifier + ( declarator ) + direct-declarator [ type-qualifier-list[opt] assignment-expression[opt] ] + ... + direct-declarator [ type-qualifier-list[opt] * ] + ... + pointer: + * type-qualifier-list[opt] + * type-qualifier-list[opt] pointer + type-qualifier-list: + type-qualifier + type-qualifier-list type-qualifier + ... + type-qualifier: + const + restrict + volatile + +So the examples go like: + +const char foo; // immutable object +const char *foo; // mutable pointer to object +char * const foo; // immutable pointer to mutable object +const char * const foo; // immutable pointer to immutable object +const char const * const foo; // XXX extra const keyword in the middle +const char * const * const foo; // immutable pointer to immutable + // pointer to immutable object +const char ** const foo; // immutable pointer to mutable pointer + // to immutable object + +Making const left-associative for * and right-associative for everything +else may not have been the best choice ever, but here we are, and the +inevitable result is people using trying to use const (as they should!), +putting it at the wrong place, fighting with the compiler for a bit, and +then either removing it or typecasting something in a bad way. I won't +go into describing restrict, but its syntax has exactly the same issue +as with const. + +Anyway, the last example above actually represents the *behavior* that's +required of strtol()-like functions, so that's our choice for the "end" +pointer. + +Signed-off-by: Peter Jones +--- + grub-core/commands/date.c | 3 ++- + grub-core/commands/i386/cmostest.c | 2 +- + grub-core/commands/i386/pc/play.c | 2 +- + grub-core/commands/i386/rdmsr.c | 2 +- + grub-core/commands/i386/wrmsr.c | 2 +- + grub-core/commands/password_pbkdf2.c | 2 +- + grub-core/commands/pcidump.c | 13 ++++++------- + grub-core/commands/regexp.c | 2 +- + grub-core/commands/setpci.c | 21 ++++++++++----------- + grub-core/commands/test.c | 2 +- + grub-core/commands/videoinfo.c | 2 +- + grub-core/disk/diskfilter.c | 3 ++- + grub-core/disk/lvm.c | 9 +++++---- + grub-core/efiemu/pnvram.c | 5 +++-- + grub-core/gfxmenu/gui_circular_progress.c | 2 +- + grub-core/gfxmenu/theme_loader.c | 2 +- + grub-core/kern/fs.c | 2 +- + grub-core/kern/misc.c | 10 ++++++---- + grub-core/kern/partition.c | 2 +- + grub-core/lib/arg.c | 2 +- + grub-core/lib/legacy_parse.c | 2 +- + grub-core/lib/syslinux_parse.c | 6 +++--- + grub-core/loader/i386/bsd.c | 6 +++--- + grub-core/loader/i386/linux.c | 2 +- + grub-core/loader/i386/pc/linux.c | 2 +- + grub-core/loader/i386/xen_fileXX.c | 2 +- + grub-core/mmap/mmap.c | 4 ++-- + grub-core/net/http.c | 4 ++-- + grub-core/net/net.c | 8 ++++---- + grub-core/normal/menu.c | 3 +-- + grub-core/osdep/aros/hostdisk.c | 2 +- + grub-core/osdep/devmapper/hostdisk.c | 2 +- + grub-core/script/execute.c | 6 +++--- + grub-core/term/serial.c | 2 +- + grub-core/term/terminfo.c | 2 +- + grub-core/tests/strtoull_test.c | 2 +- + util/grub-fstest.c | 2 +- + include/grub/misc.h | 24 +++++++++++++++++++++--- + 38 files changed, 96 insertions(+), 75 deletions(-) + +diff --git a/grub-core/commands/date.c b/grub-core/commands/date.c +index 8e1f41f141b..5cb4fafd454 100644 +--- a/grub-core/commands/date.c ++++ b/grub-core/commands/date.c +@@ -59,7 +59,8 @@ grub_cmd_date (grub_command_t cmd __attribute__ ((unused)), + + for (; argc; argc--, args++) + { +- char *p, c; ++ const char *p; ++ char c; + int m1, ofs, n, cur_mask; + + p = args[0]; +diff --git a/grub-core/commands/i386/cmostest.c b/grub-core/commands/i386/cmostest.c +index c839b704dc5..9f6b56a2f0c 100644 +--- a/grub-core/commands/i386/cmostest.c ++++ b/grub-core/commands/i386/cmostest.c +@@ -27,7 +27,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + static grub_err_t + parse_args (int argc, char *argv[], int *byte, int *bit) + { +- char *rest; ++ const char *rest; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "address required"); +diff --git a/grub-core/commands/i386/pc/play.c b/grub-core/commands/i386/pc/play.c +index c8181310515..a980e46883c 100644 +--- a/grub-core/commands/i386/pc/play.c ++++ b/grub-core/commands/i386/pc/play.c +@@ -132,7 +132,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)), + } + else + { +- char *end; ++ const char *end; + unsigned tempo; + struct note note; + int i; +diff --git a/grub-core/commands/i386/rdmsr.c b/grub-core/commands/i386/rdmsr.c +index 15b9adfca67..46c4346da1b 100644 +--- a/grub-core/commands/i386/rdmsr.c ++++ b/grub-core/commands/i386/rdmsr.c +@@ -44,7 +44,7 @@ grub_cmd_msr_read (grub_extcmd_context_t ctxt, int argc, char **argv) + { + grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; + grub_uint64_t value; +- char *ptr; ++ const char *ptr; + char buf[sizeof("1122334455667788")]; + + /* +diff --git a/grub-core/commands/i386/wrmsr.c b/grub-core/commands/i386/wrmsr.c +index 9c5e510eb44..fa76f5aed11 100644 +--- a/grub-core/commands/i386/wrmsr.c ++++ b/grub-core/commands/i386/wrmsr.c +@@ -37,7 +37,7 @@ grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char + { + grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr; + grub_uint64_t value; +- char *ptr; ++ const char *ptr; + + /* + * The CPUID instruction should be used to determine whether MSRs +diff --git a/grub-core/commands/password_pbkdf2.c b/grub-core/commands/password_pbkdf2.c +index da636e6217a..ab845d25eb3 100644 +--- a/grub-core/commands/password_pbkdf2.c ++++ b/grub-core/commands/password_pbkdf2.c +@@ -86,7 +86,7 @@ grub_cmd_password (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { + grub_err_t err; +- char *ptr, *ptr2; ++ const char *ptr, *ptr2; + grub_uint8_t *ptro; + struct pbkdf2_password *pass; + +diff --git a/grub-core/commands/pcidump.c b/grub-core/commands/pcidump.c +index f99ad4a216f..f72628fce2d 100644 +--- a/grub-core/commands/pcidump.c ++++ b/grub-core/commands/pcidump.c +@@ -95,7 +95,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (ctxt->state[0].set) + { + ptr = ctxt->state[0].arg; +- ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); ++ ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -108,8 +108,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (*ptr != ':') + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; +- ctx.pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) +- << 16; ++ ctx.pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + if (grub_errno == GRUB_ERR_BAD_NUMBER) + grub_errno = GRUB_ERR_NONE; + else +@@ -121,10 +120,10 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (ctxt->state[1].set) + { + const char *optr; +- ++ + ptr = ctxt->state[1].arg; + optr = ptr; +- ctx.bus = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.bus = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -138,7 +137,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; + optr = ptr; +- ctx.device = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.device = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -149,7 +148,7 @@ grub_cmd_pcidump (grub_extcmd_context_t ctxt, + if (*ptr == '.') + { + ptr++; +- ctx.function = grub_strtoul (ptr, (char **) &ptr, 16); ++ ctx.function = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + ctx.check_function = 1; +diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c +index f00b184c81e..7c5c72fe460 100644 +--- a/grub-core/commands/regexp.c ++++ b/grub-core/commands/regexp.c +@@ -64,7 +64,7 @@ set_matches (char **varnames, char *str, grub_size_t nmatches, + { + int i; + char *p; +- char *q; ++ const char * q; + grub_err_t err; + unsigned long j; + +diff --git a/grub-core/commands/setpci.c b/grub-core/commands/setpci.c +index d5bc97d60b2..e966af080a6 100644 +--- a/grub-core/commands/setpci.c ++++ b/grub-core/commands/setpci.c +@@ -169,7 +169,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (ctxt->state[0].set) + { + ptr = ctxt->state[0].arg; +- pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff); ++ pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -182,8 +182,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr != ':') + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; +- pciid_check_value |= (grub_strtoul (ptr, (char **) &ptr, 16) & 0xffff) +- << 16; ++ pciid_check_value |= (grub_strtoul (ptr, &ptr, 16) & 0xffff) << 16; + if (grub_errno == GRUB_ERR_BAD_NUMBER) + grub_errno = GRUB_ERR_NONE; + else +@@ -197,10 +196,10 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (ctxt->state[1].set) + { + const char *optr; +- ++ + ptr = ctxt->state[1].arg; + optr = ptr; +- bus = grub_strtoul (ptr, (char **) &ptr, 16); ++ bus = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -214,7 +213,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("missing `%c' symbol"), ':'); + ptr++; + optr = ptr; +- device = grub_strtoul (ptr, (char **) &ptr, 16); ++ device = grub_strtoul (ptr, &ptr, 16); + if (grub_errno == GRUB_ERR_BAD_NUMBER) + { + grub_errno = GRUB_ERR_NONE; +@@ -225,7 +224,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '.') + { + ptr++; +- function = grub_strtoul (ptr, (char **) &ptr, 16); ++ function = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + check_function = 1; +@@ -253,7 +252,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (i == ARRAY_SIZE (pci_registers)) + { + regsize = 0; +- regaddr = grub_strtoul (ptr, (char **) &ptr, 16); ++ regaddr = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown register"); + } +@@ -270,7 +269,7 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '+') + { + ptr++; +- regaddr += grub_strtoul (ptr, (char **) &ptr, 16); ++ regaddr += grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + } +@@ -302,14 +301,14 @@ grub_cmd_setpci (grub_extcmd_context_t ctxt, int argc, char **argv) + if (*ptr == '=') + { + ptr++; +- regwrite = grub_strtoul (ptr, (char **) &ptr, 16); ++ regwrite = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + write_mask = 0xffffffff; + if (*ptr == ':') + { + ptr++; +- write_mask = grub_strtoul (ptr, (char **) &ptr, 16); ++ write_mask = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + return grub_errno; + write_mask = 0xffffffff; +diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c +index 4e929e0452e..62d3fb3988f 100644 +--- a/grub-core/commands/test.c ++++ b/grub-core/commands/test.c +@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + + /* A simple implementation for signed numbers. */ + static int +-grub_strtosl (char *arg, char **end, int base) ++grub_strtosl (char *arg, const char ** const end, int base) + { + if (arg[0] == '-') + return -grub_strtoul (arg + 1, end, base); +diff --git a/grub-core/commands/videoinfo.c b/grub-core/commands/videoinfo.c +index 4be8107d553..016a4d81835 100644 +--- a/grub-core/commands/videoinfo.c ++++ b/grub-core/commands/videoinfo.c +@@ -136,7 +136,7 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), + ctx.height = ctx.width = ctx.depth = 0; + if (argc) + { +- char *ptr; ++ const char *ptr; + ptr = args[0]; + ctx.width = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index 1a3eb6b8d77..3f264be77d1 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -971,7 +971,8 @@ grub_diskfilter_vg_register (struct grub_diskfilter_vg *vg) + for (p = vgp->lvs; p; p = p->next) + { + int cur_num; +- char *num, *end; ++ char *num; ++ const char *end; + if (!p->fullname) + continue; + if (grub_strncmp (p->fullname, lv->fullname, len) != 0) +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 7b265c780c3..0cbd0dd1629 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -38,7 +38,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); + at the number. In case STR is not found, *P will be NULL and the + return value will be 0. */ + static grub_uint64_t +-grub_lvm_getvalue (char **p, const char *str) ++grub_lvm_getvalue (const char ** const p, const char *str) + { + *p = grub_strstr (*p, str); + if (! *p) +@@ -63,12 +63,12 @@ grub_lvm_checkvalue (char **p, char *str, char *tmpl) + #endif + + static int +-grub_lvm_check_flag (char *p, const char *str, const char *flag) ++grub_lvm_check_flag (const char *p, const char *str, const char *flag) + { + grub_size_t len_str = grub_strlen (str), len_flag = grub_strlen (flag); + while (1) + { +- char *q; ++ const char *q; + p = grub_strstr (p, str); + if (! p) + return 0; +@@ -105,7 +105,8 @@ grub_lvm_detect (grub_disk_t disk, + char buf[GRUB_LVM_LABEL_SIZE]; + char vg_id[GRUB_LVM_ID_STRLEN+1]; + char pv_id[GRUB_LVM_ID_STRLEN+1]; +- char *metadatabuf, *p, *q, *vgname; ++ char *metadatabuf, *vgname; ++ const char *p, *q; + struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; + struct grub_lvm_pv_header *pvh; + struct grub_lvm_disk_locn *dlocn; +diff --git a/grub-core/efiemu/pnvram.c b/grub-core/efiemu/pnvram.c +index c5c3d4bd3d5..dd42bc69116 100644 +--- a/grub-core/efiemu/pnvram.c ++++ b/grub-core/efiemu/pnvram.c +@@ -39,7 +39,7 @@ static grub_size_t nvramsize; + + /* Parse signed value */ + static int +-grub_strtosl (const char *arg, char **end, int base) ++grub_strtosl (const char *arg, const char ** const end, int base) + { + if (arg[0] == '-') + return -grub_strtoul (arg + 1, end, base); +@@ -120,7 +120,8 @@ nvram_set (void * data __attribute__ ((unused))) + grub_memset (nvram, 0, nvramsize); + FOR_SORTED_ENV (var) + { +- char *guid, *attr, *name, *varname; ++ const char *guid; ++ char *attr, *name, *varname; + struct efi_variable *efivar; + int len = 0; + int i; +diff --git a/grub-core/gfxmenu/gui_circular_progress.c b/grub-core/gfxmenu/gui_circular_progress.c +index 354dd7b73ee..7578bfbec92 100644 +--- a/grub-core/gfxmenu/gui_circular_progress.c ++++ b/grub-core/gfxmenu/gui_circular_progress.c +@@ -230,7 +230,7 @@ circprog_set_state (void *vself, int visible, int start, + static int + parse_angle (const char *value) + { +- char *ptr; ++ const char *ptr; + int angle; + + angle = grub_strtol (value, &ptr, 10); +diff --git a/grub-core/gfxmenu/theme_loader.c b/grub-core/gfxmenu/theme_loader.c +index d6829bb5e90..eae83086bcc 100644 +--- a/grub-core/gfxmenu/theme_loader.c ++++ b/grub-core/gfxmenu/theme_loader.c +@@ -484,7 +484,7 @@ parse_proportional_spec (const char *value, signed *abs, grub_fixed_signed_t *pr + ptr++; + } + +- num = grub_strtoul (ptr, (char **) &ptr, 0); ++ num = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; + if (sig) +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index 2b85f4950bd..88d39360da0 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -134,7 +134,7 @@ struct grub_fs_block + static grub_err_t + grub_fs_blocklist_open (grub_file_t file, const char *name) + { +- char *p = (char *) name; ++ const char *p = name; + unsigned num = 0; + unsigned i; + grub_disk_t disk = file->device->disk; +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 5c3899f0e5b..e21dd44c7cf 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -383,7 +383,8 @@ grub_isspace (int c) + } + + unsigned long +-grub_strtoul (const char *str, char **end, int base) ++grub_strtoul (const char * restrict str, const char ** const restrict end, ++ int base) + { + unsigned long long num; + +@@ -400,7 +401,8 @@ grub_strtoul (const char *str, char **end, int base) + } + + unsigned long long +-grub_strtoull (const char *str, char **end, int base) ++grub_strtoull (const char * restrict str, const char ** const restrict end, ++ int base) + { + unsigned long long num = 0; + int found = 0; +@@ -901,14 +903,14 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, + { + if (fmt[0] == '0') + zerofill = '0'; +- format1 = grub_strtoul (fmt, (char **) &fmt, 10); ++ format1 = grub_strtoul (fmt, &fmt, 10); + } + + if (*fmt == '.') + fmt++; + + if (grub_isdigit (*fmt)) +- format2 = grub_strtoul (fmt, (char **) &fmt, 10); ++ format2 = grub_strtoul (fmt, &fmt, 10); + + if (*fmt == '$') + { +diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c +index e499147cbcb..2c401b866c4 100644 +--- a/grub-core/kern/partition.c ++++ b/grub-core/kern/partition.c +@@ -126,7 +126,7 @@ grub_partition_probe (struct grub_disk *disk, const char *str) + while (*ptr && grub_isalpha (*ptr)) + ptr++; + partname_end = ptr; +- num = grub_strtoul (ptr, (char **) &ptr, 0) - 1; ++ num = grub_strtoul (ptr, &ptr, 0) - 1; + + curpart = 0; + /* Use the first partition map type found. */ +diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c +index fd7744a6ff6..ccc185017ee 100644 +--- a/grub-core/lib/arg.c ++++ b/grub-core/lib/arg.c +@@ -375,7 +375,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv, + + case ARG_TYPE_INT: + { +- char *tail; ++ const char * tail; + + grub_strtoull (option, &tail, 0); + if (tail == 0 || tail == option || *tail != '\0' || grub_errno) +diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c +index ef56150ac77..05719ab2ccb 100644 +--- a/grub-core/lib/legacy_parse.c ++++ b/grub-core/lib/legacy_parse.c +@@ -418,7 +418,7 @@ adjust_file (const char *in, grub_size_t len) + } + if (*comma != ',') + return grub_legacy_escape (in, len); +- part = grub_strtoull (comma + 1, (char **) &rest, 0); ++ part = grub_strtoull (comma + 1, &rest, 0); + if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z') + { + subpart = rest[1] - 'a'; +diff --git a/grub-core/lib/syslinux_parse.c b/grub-core/lib/syslinux_parse.c +index 4afa99279a2..de9fda06f52 100644 +--- a/grub-core/lib/syslinux_parse.c ++++ b/grub-core/lib/syslinux_parse.c +@@ -1062,7 +1062,7 @@ write_entry (struct output_buffer *outbuf, + if (ptr[0] == 'h' && ptr[1] == 'd') + { + is_fd = 0; +- devn = grub_strtoul (ptr + 2, &ptr, 0); ++ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + continue; + } + if (grub_strncasecmp (ptr, "file=", 5) == 0) +@@ -1086,12 +1086,12 @@ write_entry (struct output_buffer *outbuf, + if (ptr[0] == 'f' && ptr[1] == 'd') + { + is_fd = 1; +- devn = grub_strtoul (ptr + 2, &ptr, 0); ++ devn = grub_strtoul (ptr + 2, (const char **)&ptr, 0); + continue; + } + if (grub_isdigit (ptr[0])) + { +- part = grub_strtoul (ptr, &ptr, 0); ++ part = grub_strtoul (ptr, (const char **)&ptr, 0); + continue; + } + /* FIXME: isolinux, ntldr, cmldr, *dos, seg, hide +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 5b9b92d6ba5..50cca304fd0 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -1616,7 +1616,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "unknown disk type name"); + +- unit = grub_strtoul (arg, (char **) &arg, 10); ++ unit = grub_strtoul (arg, &arg, 10); + if (! (arg && *arg >= 'a' && *arg <= 'z')) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "only device specifications of form " +@@ -1634,7 +1634,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + if (ctxt->state[OPENBSD_SERIAL_ARG].set) + { + struct grub_openbsd_bootarg_console serial; +- char *ptr; ++ const char *ptr; + unsigned port = 0; + unsigned speed = 9600; + +@@ -1736,7 +1736,7 @@ grub_cmd_netbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) + if (ctxt->state[NETBSD_SERIAL_ARG].set) + { + struct grub_netbsd_btinfo_serial serial; +- char *ptr; ++ const char *ptr; + + grub_memset (&serial, 0, sizeof (serial)); + grub_strcpy (serial.devname, "com"); +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 376c726928a..201e6597c6d 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -954,7 +954,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + #endif /* GRUB_MACHINE_PCBIOS */ + if (grub_memcmp (argv[i], "mem=", 4) == 0) + { +- char *val = argv[i] + 4; ++ const char *val = argv[i] + 4; + + linux_mem_size = grub_strtoul (val, &val, 0); + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index fe3e1d41d09..0bf0e13d647 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -272,7 +272,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + else if (grub_memcmp (argv[i], "mem=", 4) == 0) + { +- char *val = argv[i] + 4; ++ const char *val = argv[i] + 4; + + linux_mem_size = grub_strtoul (val, &val, 0); + +diff --git a/grub-core/loader/i386/xen_fileXX.c b/grub-core/loader/i386/xen_fileXX.c +index 6329ec01038..27afcaacbce 100644 +--- a/grub-core/loader/i386/xen_fileXX.c ++++ b/grub-core/loader/i386/xen_fileXX.c +@@ -25,7 +25,7 @@ parse_xen_guest (grub_elf_t elf, struct grub_xen_file_info *xi, + grub_off_t off, grub_size_t sz) + { + char *buf; +- char *ptr; ++ const char *ptr; + int has_paddr = 0; + + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c +index 6a31cbae325..b569cb23b5a 100644 +--- a/grub-core/mmap/mmap.c ++++ b/grub-core/mmap/mmap.c +@@ -423,7 +423,7 @@ static grub_err_t + grub_cmd_badram (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { +- char * str; ++ const char *str; + struct badram_entry entry; + + if (argc != 1) +@@ -465,7 +465,7 @@ static grub_uint64_t + parsemem (const char *str) + { + grub_uint64_t ret; +- char *ptr; ++ const char *ptr; + + ret = grub_strtoul (str, &ptr, 0); + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index c9c59690a98..b52b558d631 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -110,7 +110,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + return GRUB_ERR_NONE; + } + ptr += sizeof ("HTTP/1.1 ") - 1; +- code = grub_strtoul (ptr, &ptr, 10); ++ code = grub_strtoul (ptr, (const char **)&ptr, 10); + if (grub_errno) + return grub_errno; + switch (code) +@@ -137,7 +137,7 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len) + == 0 && !data->size_recv) + { + ptr += sizeof ("Content-Length: ") - 1; +- file->size = grub_strtoull (ptr, &ptr, 10); ++ file->size = grub_strtoull (ptr, (const char **)&ptr, 10); + data->size_recv = 1; + return GRUB_ERR_NONE; + } +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 27a0a1d6961..aa56393e1c4 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -411,7 +411,7 @@ parse_ip (const char *val, grub_uint32_t *ip, const char **rest) + for (i = 0; i < 4; i++) + { + unsigned long t; +- t = grub_strtoul (ptr, (char **) &ptr, 0); ++ t = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; +@@ -465,7 +465,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + ptr++; + continue; + } +- t = grub_strtoul (ptr, (char **) &ptr, 16); ++ t = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; +@@ -577,7 +577,7 @@ grub_net_resolve_net_address (const char *name, + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4; + if (*rest == '/') + { +- addr->ipv4.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); ++ addr->ipv4.masksize = grub_strtoul (rest + 1, &rest, 0); + if (!grub_errno && *rest == 0) + return GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; +@@ -593,7 +593,7 @@ grub_net_resolve_net_address (const char *name, + addr->type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6; + if (*rest == '/') + { +- addr->ipv6.masksize = grub_strtoul (rest + 1, (char **) &rest, 0); ++ addr->ipv6.masksize = grub_strtoul (rest + 1, &rest, 0); + if (!grub_errno && *rest == 0) + return GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 046a1fb2c84..37d753d8081 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -194,8 +194,7 @@ menuentry_eq (const char *id, const char *spec) + static int + get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + { +- const char *val; +- char *tail; ++ const char *val, *tail; + int entry; + int sz = 0; + +diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c +index 2be654ca3bd..3b2c9de2496 100644 +--- a/grub-core/osdep/aros/hostdisk.c ++++ b/grub-core/osdep/aros/hostdisk.c +@@ -194,7 +194,7 @@ grub_util_fd_open (const char *dev, int flg) + p1 = dev + strlen (dev); + else + { +- unit = grub_strtoul (p1 + 1, (char **) &p2, 16); ++ unit = grub_strtoul (p1 + 1, &p2, 16); + if (p2 && *p2 == '/') + flags = grub_strtoul (p2 + 1, 0, 16); + } +diff --git a/grub-core/osdep/devmapper/hostdisk.c b/grub-core/osdep/devmapper/hostdisk.c +index a697bcb4d8d..a8afc0c9408 100644 +--- a/grub-core/osdep/devmapper/hostdisk.c ++++ b/grub-core/osdep/devmapper/hostdisk.c +@@ -113,7 +113,7 @@ grub_util_get_dm_node_linear_info (dev_t dev, + void *next = NULL; + uint64_t length, start; + char *target, *params; +- char *ptr; ++ const char *ptr; + int major = 0, minor = 0; + int first = 1; + grub_disk_addr_t partstart = 0; +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index ba38b5e8aef..c6d2c365c9a 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -146,7 +146,7 @@ replace_scope (struct grub_script_scope *new_scope) + grub_err_t + grub_script_break (grub_command_t cmd, int argc, char *argv[]) + { +- char *p = 0; ++ const char *p = NULL; + unsigned long count; + + if (argc == 0) +@@ -178,7 +178,7 @@ grub_err_t + grub_script_shift (grub_command_t cmd __attribute__((unused)), + int argc, char *argv[]) + { +- char *p = 0; ++ const char *p = NULL; + unsigned long n = 0; + + if (! scope) +@@ -239,7 +239,7 @@ grub_err_t + grub_script_return (grub_command_t cmd __attribute__((unused)), + int argc, char *argv[]) + { +- char *p; ++ const char *p = NULL; + unsigned long n; + + if (! scope || argc > 1) +diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c +index db80b3ba0fb..f9271b09239 100644 +--- a/grub-core/term/serial.c ++++ b/grub-core/term/serial.c +@@ -269,7 +269,7 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args) + + if (state[OPTION_BASE_CLOCK].set) + { +- char *ptr; ++ const char *ptr; + config.base_clock = grub_strtoull (state[OPTION_BASE_CLOCK].arg, &ptr, 0); + if (grub_errno) + return grub_errno; +diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c +index 29df35e6d20..537a5c0cb0b 100644 +--- a/grub-core/term/terminfo.c ++++ b/grub-core/term/terminfo.c +@@ -737,7 +737,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args) + + if (state[OPTION_GEOMETRY].set) + { +- char *ptr = state[OPTION_GEOMETRY].arg; ++ const char *ptr = state[OPTION_GEOMETRY].arg; + w = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + return grub_errno; +diff --git a/grub-core/tests/strtoull_test.c b/grub-core/tests/strtoull_test.c +index 7da615ff33e..5488ab26b43 100644 +--- a/grub-core/tests/strtoull_test.c ++++ b/grub-core/tests/strtoull_test.c +@@ -25,7 +25,7 @@ static void + strtoull_testcase (const char *input, int base, unsigned long long expected, + int num_digits, grub_err_t error) + { +- char *output; ++ const char *output; + unsigned long long value; + grub_errno = 0; + value = grub_strtoull(input, &output, base); +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index 88f9c5d4ad8..39bad1f432f 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -538,7 +538,7 @@ void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; + static error_t + argp_parser (int key, char *arg, struct argp_state *state) + { +- char *p; ++ const char *p; + + switch (key) + { +diff --git a/include/grub/misc.h b/include/grub/misc.h +index 960097fbd06..998e47e0ccf 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -288,11 +288,29 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) + - (int) grub_tolower ((grub_uint8_t) *s2); + } + +-unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base); +-unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base); ++/* ++ * Note that these differ from the C standard's definitions of strtol, ++ * strtoul(), and strtoull() by the addition of two const qualifiers on the end ++ * pointer, which make the declaration match the *semantic* requirements of ++ * their behavior. This means that instead of: ++ * ++ * char *s = "1234 abcd"; ++ * char *end; ++ * unsigned long l; ++ * ++ * l = grub_strtoul(s, &end, 10); ++ * ++ * We must one of: ++ * ++ * const char *end; ++ * ... or ... ++ * l = grub_strtoul(s, (const char ** const)&end, 10); ++ */ ++unsigned long EXPORT_FUNC(grub_strtoul) (const char * restrict str, const char ** const restrict end, int base); ++unsigned long long EXPORT_FUNC(grub_strtoull) (const char * restrict str, const char ** const restrict end, int base); + + static inline long +-grub_strtol (const char *str, char **end, int base) ++grub_strtol (const char * restrict str, const char ** const restrict end, int base) + { + int negative = 0; + unsigned long long magnitude; diff --git a/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch b/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch new file mode 100644 index 0000000..84c1370 --- /dev/null +++ b/0161-Fix-menu-entry-selection-based-on-ID-and-title.patch @@ -0,0 +1,233 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 19 Oct 2018 10:57:52 -0400 +Subject: [PATCH] Fix menu entry selection based on ID and title + +Currently if grub_strtoul(saved_entry_value, NULL, 0) does not return an +error, we assume the value it has produced is a correct index into our +menu entry list, and do not try to interpret the value as the "id" or +"title" . In cases where "id" or "title" start with a numeral, this +makes them impossible to use as selection criteria. + +This patch splits the search into three phases - matching id, matching +title, and only once those have been exhausted, trying to interpret the +ID as a numeral. In that case, we also require that the entire string +is numeric, not merely a string with leading numeric characters. + +Resolves: rhbz#1640979 + +Signed-off-by: Peter Jones +[javierm: fix menu entry selection based on title] +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/menu.c | 141 ++++++++++++++++++++++++------------------------ + 1 file changed, 71 insertions(+), 70 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 37d753d8081..ea714d27176 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) + } + + static int +-menuentry_eq (const char *id, const char *spec) ++menuentry_eq (const char *id, const char *spec, int limit) + { + const char *ptr1, *ptr2; + ptr1 = id; + ptr2 = spec; +- while (1) ++ while (limit == -1 || ptr1 - id <= limit) + { + if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) + return ptr2 - spec; +@@ -178,7 +178,11 @@ menuentry_eq (const char *id, const char *spec) + if (*ptr2 == '>') + ptr2++; + if (*ptr1 != *ptr2) +- return 0; ++ { ++ if (limit > -1 && ptr1 - id == limit && !*ptr1 && grub_isspace(*ptr2)) ++ return ptr1 -id -1; ++ return 0; ++ } + if (*ptr1 == 0) + return ptr1 - id; + ptr1++; +@@ -187,6 +191,58 @@ menuentry_eq (const char *id, const char *spec) + return 0; + } + ++static int ++get_entry_number_helper(grub_menu_t menu, ++ const char * const val, const char ** const tail) ++{ ++ /* See if the variable matches the title of a menu entry. */ ++ int entry = -1; ++ grub_menu_entry_t e; ++ int i; ++ ++ for (i = 0, e = menu->entry_list; e; i++) ++ { ++ int l = 0; ++ while (val[l] && !grub_isspace(val[l])) ++ l++; ++ ++ if (menuentry_eq (e->id, val, l)) ++ { ++ if (tail) ++ *tail = val + l; ++ return i; ++ } ++ e = e->next; ++ } ++ ++ for (i = 0, e = menu->entry_list; e; i++) ++ { ++ ++ if (menuentry_eq (e->title, val, -1)) ++ { ++ if (tail) ++ *tail = NULL; ++ return i; ++ } ++ e = e->next; ++ } ++ ++ if (tail) ++ *tail = NULL; ++ ++ entry = (int) grub_strtoul (val, tail, 0); ++ if (grub_errno == GRUB_ERR_BAD_NUMBER || ++ (*tail && **tail && !grub_isspace(**tail))) ++ { ++ entry = -1; ++ if (tail) ++ *tail = NULL; ++ grub_errno = GRUB_ERR_NONE; ++ } ++ ++ return entry; ++} ++ + /* Get the first entry number from the value of the environment variable NAME, + which is a space-separated list of non-negative integers. The entry number + which is returned is stripped from the value of NAME. If no entry number +@@ -196,7 +252,6 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + { + const char *val, *tail; + int entry; +- int sz = 0; + + val = grub_env_get (name); + if (! val) +@@ -204,50 +259,24 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + + grub_error_push (); + +- entry = (int) grub_strtoul (val, &tail, 0); ++ entry = get_entry_number_helper(menu, val, &tail); ++ if (!(*tail == 0 || grub_isspace(*tail))) ++ entry = -1; + +- if (grub_errno == GRUB_ERR_BAD_NUMBER) ++ if (entry >= 0) + { +- /* See if the variable matches the title of a menu entry. */ +- grub_menu_entry_t e = menu->entry_list; +- int i; +- +- for (i = 0; e; i++) +- { +- sz = menuentry_eq (e->title, val); +- if (sz < 1) +- sz = menuentry_eq (e->id, val); +- +- if (sz >= 1) +- { +- entry = i; +- break; +- } +- e = e->next; +- } +- +- if (sz > 0) +- grub_errno = GRUB_ERR_NONE; +- +- if (! e) +- entry = -1; +- } +- +- if (grub_errno == GRUB_ERR_NONE) +- { +- if (sz > 0) +- tail += sz; +- + /* Skip whitespace to find the next entry. */ + while (*tail && grub_isspace (*tail)) + tail++; +- grub_env_set (name, tail); ++ if (*tail) ++ grub_env_set (name, tail); ++ else ++ grub_env_unset (name); + } + else + { + grub_env_unset (name); + grub_errno = GRUB_ERR_NONE; +- entry = -1; + } + + grub_error_pop (); +@@ -524,6 +553,7 @@ static int + get_entry_number (grub_menu_t menu, const char *name) + { + const char *val; ++ const char *tail; + int entry; + + val = grub_env_get (name); +@@ -531,38 +561,9 @@ get_entry_number (grub_menu_t menu, const char *name) + return -1; + + grub_error_push (); +- +- entry = (int) grub_strtoul (val, 0, 0); +- +- if (grub_errno == GRUB_ERR_BAD_NUMBER) +- { +- /* See if the variable matches the title of a menu entry. */ +- grub_menu_entry_t e = menu->entry_list; +- int i; +- +- grub_errno = GRUB_ERR_NONE; +- +- for (i = 0; e; i++) +- { +- if (menuentry_eq (e->title, val) +- || menuentry_eq (e->id, val)) +- { +- entry = i; +- break; +- } +- e = e->next; +- } +- +- if (! e) +- entry = -1; +- } +- +- if (grub_errno != GRUB_ERR_NONE) +- { +- grub_errno = GRUB_ERR_NONE; +- entry = -1; +- } +- ++ entry = get_entry_number_helper(menu, val, &tail); ++ if (tail && *tail != '\0') ++ entry = -1; + grub_error_pop (); + + return entry; diff --git a/0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch b/0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch new file mode 100644 index 0000000..d560ec9 --- /dev/null +++ b/0162-Make-the-menu-entry-users-option-argument-to-be-opti.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 26 Nov 2018 10:06:42 +0100 +Subject: [PATCH] Make the menu entry users option argument to be optional + +The --users option is used to restrict the access to specific menu entries +only to a set of users. But the option requires an argument to either be a +constant or a variable that has been set. So for example the following: + + menuentry "May be run by superusers or users in $users" --users $users { + linux /vmlinuz + } + +Would fail if $users is not defined and grub would discard the menu entry. +Instead, allow the --users option to have an optional argument and ignore +the option if the argument was not set. + +Related: rhbz#1652434 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/menuentry.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index 9faf2be0f64..29736f5cd03 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -29,7 +29,7 @@ static const struct grub_arg_option options[] = + { + {"class", 1, GRUB_ARG_OPTION_REPEATABLE, + N_("Menu entry type."), N_("STRING"), ARG_TYPE_STRING}, +- {"users", 2, 0, ++ {"users", 2, GRUB_ARG_OPTION_OPTIONAL, + N_("List of users allowed to boot this entry."), N_("USERNAME[,USERNAME]"), + ARG_TYPE_STRING}, + {"hotkey", 3, 0, +@@ -281,7 +281,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args) + if (! ctxt->state[3].set && ! ctxt->script) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no menuentry definition"); + +- if (ctxt->state[1].set) ++ if (ctxt->state[1].set && ctxt->state[1].arg) + users = ctxt->state[1].arg; + else if (ctxt->state[5].set) + users = NULL; diff --git a/0163-Add-efi-export-env-and-efi-load-env-commands.patch b/0163-Add-efi-export-env-and-efi-load-env-commands.patch new file mode 100644 index 0000000..9b2ab56 --- /dev/null +++ b/0163-Add-efi-export-env-and-efi-load-env-commands.patch @@ -0,0 +1,360 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 16 Jan 2019 13:21:46 -0500 +Subject: [PATCH] Add efi-export-env and efi-load-env commands + +This adds "efi-export-env VARIABLE" and "efi-load-env", which manipulate the +environment block stored in the EFI variable +GRUB_ENV-91376aff-cba6-42be-949d-06fde81128e8. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 6 ++ + grub-core/commands/efi/env.c | 168 +++++++++++++++++++++++++++++++++++++++++++ + grub-core/kern/efi/efi.c | 3 + + grub-core/kern/efi/init.c | 5 -- + grub-core/lib/envblk.c | 43 +++++++++++ + util/editenv.c | 2 - + util/grub-set-bootflag.c | 1 + + include/grub/efi/efi.h | 5 ++ + include/grub/lib/envblk.h | 3 + + 9 files changed, 229 insertions(+), 7 deletions(-) + create mode 100644 grub-core/commands/efi/env.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 65ca74f9ad9..661994686e6 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -817,6 +817,12 @@ module = { + enable = efi; + }; + ++module = { ++ name = efienv; ++ common = commands/efi/env.c; ++ enable = efi; ++}; ++ + module = { + name = efifwsetup; + efi = commands/efi/efifwsetup.c; +diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c +new file mode 100644 +index 00000000000..a69079786aa +--- /dev/null ++++ b/grub-core/commands/efi/env.c +@@ -0,0 +1,168 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2012 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static const grub_efi_guid_t grub_env_guid = GRUB_EFI_GRUB_VARIABLE_GUID; ++ ++static grub_err_t ++grub_efi_export_env(grub_command_t cmd __attribute__ ((unused)), ++ int argc, char *argv[]) ++{ ++ const char *value; ++ char *old_value; ++ struct grub_envblk envblk_s = { NULL, 0 }; ++ grub_envblk_t envblk = &envblk_s; ++ grub_err_t err; ++ int changed = 1; ++ grub_efi_status_t status; ++ ++ grub_dprintf ("efienv", "argc:%d\n", argc); ++ for (int i = 0; i < argc; i++) ++ grub_dprintf ("efienv", "argv[%d]: %s\n", i, argv[i]); ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name expected")); ++ ++ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, ++ &envblk_s.size); ++ if (!envblk_s.buf || envblk_s.size < 1) ++ { ++ char *buf = grub_malloc (1025); ++ if (!buf) ++ return grub_errno; ++ ++ grub_memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1); ++ grub_memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#', ++ DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1); ++ buf[1024] = '\0'; ++ ++ envblk_s.buf = buf; ++ envblk_s.size = 1024; ++ } ++ else ++ { ++ char *buf = grub_realloc (envblk_s.buf, envblk_s.size + 1); ++ if (!buf) ++ return grub_errno; ++ ++ envblk_s.buf = buf; ++ envblk_s.buf[envblk_s.size] = '\0'; ++ } ++ ++ err = grub_envblk_get(envblk, argv[0], &old_value); ++ if (err != GRUB_ERR_NONE) ++ { ++ grub_dprintf ("efienv", "grub_envblk_get returned %d\n", err); ++ return err; ++ } ++ ++ value = grub_env_get(argv[0]); ++ if ((!value && !old_value) || ++ (value && old_value && !grub_strcmp(old_value, value))) ++ changed = 0; ++ ++ if (old_value) ++ grub_free(old_value); ++ ++ if (changed == 0) ++ { ++ grub_dprintf ("efienv", "No changes necessary\n"); ++ return 0; ++ } ++ ++ if (value) ++ { ++ grub_dprintf ("efienv", "setting \"%s\" to \"%s\"\n", argv[0], value); ++ grub_envblk_set(envblk, argv[0], value); ++ } ++ else ++ { ++ grub_dprintf ("efienv", "deleting \"%s\" from envblk\n", argv[0]); ++ grub_envblk_delete(envblk, argv[0]); ++ } ++ ++ grub_dprintf ("efienv", "envblk is %lu bytes:\n\"%s\"\n", envblk_s.size, envblk_s.buf); ++ ++ grub_dprintf ("efienv", "removing GRUB_ENV\n"); ++ status = grub_efi_set_variable ("GRUB_ENV", &grub_env_guid, NULL, 0); ++ if (status != GRUB_EFI_SUCCESS) ++ grub_dprintf ("efienv", "removal returned %ld\n", status); ++ ++ grub_dprintf ("efienv", "setting GRUB_ENV\n"); ++ status = grub_efi_set_variable ("GRUB_ENV", &grub_env_guid, ++ envblk_s.buf, envblk_s.size); ++ if (status != GRUB_EFI_SUCCESS) ++ grub_dprintf ("efienv", "setting GRUB_ENV returned %ld\n", status); ++ ++ return 0; ++} ++ ++static int ++set_var (const char *name, const char *value, ++ void *whitelist __attribute__((__unused__))) ++{ ++ grub_env_set (name, value); ++ return 0; ++} ++ ++static grub_err_t ++grub_efi_load_env(grub_command_t cmd __attribute__ ((unused)), ++ int argc, char *argv[] __attribute__((__unused__))) ++{ ++ struct grub_envblk envblk_s = { NULL, 0 }; ++ grub_envblk_t envblk = &envblk_s; ++ ++ envblk_s.buf = grub_efi_get_variable ("GRUB_ENV", &grub_env_guid, ++ &envblk_s.size); ++ if (!envblk_s.buf || envblk_s.size < 1) ++ return 0; ++ ++ if (argc > 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unexpected argument")); ++ ++ grub_envblk_iterate (envblk, NULL, set_var); ++ grub_free (envblk_s.buf); ++} ++ ++static grub_command_t export_cmd, loadenv_cmd; ++ ++GRUB_MOD_INIT(lsefi) ++{ ++ export_cmd = grub_register_command ("efi-export-env", grub_efi_export_env, ++ N_("VARIABLE_NAME"), N_("Export environment variable to UEFI.")); ++ loadenv_cmd = grub_register_command ("efi-load-env", grub_efi_load_env, ++ NULL, N_("Load the grub environment from UEFI.")); ++} ++ ++GRUB_MOD_FINI(lsefi) ++{ ++ grub_unregister_command (export_cmd); ++ grub_unregister_command (loadenv_cmd); ++} +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index ada3004cfba..279394d85eb 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -224,6 +224,9 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, + if (status == GRUB_EFI_SUCCESS) + return GRUB_ERR_NONE; + ++ if (status == GRUB_EFI_NOT_FOUND && datasize == 0) ++ return GRUB_ERR_NONE; ++ + return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var); + } + +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index e6183a4c44d..d1afa3af11e 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -29,11 +29,6 @@ + + grub_addr_t grub_modbase; + +-#define GRUB_EFI_GRUB_VARIABLE_GUID \ +- { 0x91376aff, 0xcba6, 0x42be, \ +- { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \ +- } +- + /* Helper for grub_efi_env_init */ + static int + set_var (const char *name, const char *value, +diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c +index 230e0e9d9ab..f89d86d4e8d 100644 +--- a/grub-core/lib/envblk.c ++++ b/grub-core/lib/envblk.c +@@ -223,6 +223,49 @@ grub_envblk_delete (grub_envblk_t envblk, const char *name) + } + } + ++struct get_var_state { ++ const char * const name; ++ char * value; ++ int found; ++}; ++ ++static int ++get_var (const char * const name, const char * const value, void *statep) ++{ ++ struct get_var_state *state = (struct get_var_state *)statep; ++ ++ if (!grub_strcmp(state->name, name)) ++ { ++ state->found = 1; ++ state->value = grub_strdup(value); ++ if (!state->value) ++ grub_errno = grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ ++ return 1; ++ } ++ ++ return 0; ++} ++ ++grub_err_t ++grub_envblk_get (grub_envblk_t envblk, const char * const name, char ** const value) ++{ ++ struct get_var_state state = { ++ .name = name, ++ .value = NULL, ++ .found = 0, ++ }; ++ ++ grub_envblk_iterate(envblk, (void *)&state, get_var); ++ ++ *value = state.value; ++ ++ if (state.found && !state.value) ++ return grub_errno; ++ ++ return GRUB_ERR_NONE; ++} ++ + void + grub_envblk_iterate (grub_envblk_t envblk, + void *hook_data, +diff --git a/util/editenv.c b/util/editenv.c +index 1f7f6f3ae18..66f99f988ff 100644 +--- a/util/editenv.c ++++ b/util/editenv.c +@@ -30,8 +30,6 @@ + #include + #include + +-#define DEFAULT_ENVBLK_SIZE 1024 +- + void + grub_util_create_envblk_file (const char *name) + { +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index bb198f02351..6a79ee67444 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -25,6 +25,7 @@ + + #include /* For *_DIR_NAME defines */ + #include ++#include + #include /* For GRUB_ENVBLK_DEFCFG define */ + #include + #include +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 8ca3981d7a1..d24afbadbf6 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -24,6 +24,11 @@ + #include + #include + ++#define GRUB_EFI_GRUB_VARIABLE_GUID \ ++ { 0x91376aff, 0xcba6, 0x42be, \ ++ { 0x94, 0x9d, 0x06, 0xfd, 0xe8, 0x11, 0x28, 0xe8 } \ ++ } ++ + /* Variables. */ + extern grub_efi_system_table_t *EXPORT_VAR(grub_efi_system_table); + extern grub_efi_handle_t EXPORT_VAR(grub_efi_image_handle); +diff --git a/include/grub/lib/envblk.h b/include/grub/lib/envblk.h +index c3e65592170..ab969af2461 100644 +--- a/include/grub/lib/envblk.h ++++ b/include/grub/lib/envblk.h +@@ -22,6 +22,8 @@ + #define GRUB_ENVBLK_SIGNATURE "# GRUB Environment Block\n" + #define GRUB_ENVBLK_DEFCFG "grubenv" + ++#define DEFAULT_ENVBLK_SIZE 1024 ++ + #ifndef ASM_FILE + + struct grub_envblk +@@ -33,6 +35,7 @@ typedef struct grub_envblk *grub_envblk_t; + + grub_envblk_t grub_envblk_open (char *buf, grub_size_t size); + int grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value); ++grub_err_t grub_envblk_get (grub_envblk_t envblk, const char * const name, char ** const value); + void grub_envblk_delete (grub_envblk_t envblk, const char *name); + void grub_envblk_iterate (grub_envblk_t envblk, + void *hook_data, diff --git a/0164-Make-it-possible-to-subtract-conditions-from-debug.patch b/0164-Make-it-possible-to-subtract-conditions-from-debug.patch new file mode 100644 index 0000000..c281ef6 --- /dev/null +++ b/0164-Make-it-possible-to-subtract-conditions-from-debug.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 17 Jan 2019 13:10:39 -0500 +Subject: [PATCH] Make it possible to subtract conditions from debug= + +This makes it so you can do set debug to "all,-scripting,-lexer" and get the +obvious outcome. Any negation present will take preference over that +conditional, so "all,-scripting,scripting" is the same thing as +"all,-scripting". + +Signed-off-by: Peter Jones +--- + grub-core/kern/misc.c | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index e21dd44c7cf..18a7dbf4cd7 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -163,12 +163,24 @@ int + grub_debug_enabled (const char * condition) + { + const char *debug; ++ char *negcond; ++ int negated = 0; + + debug = grub_env_get ("debug"); + if (!debug) + return 0; + +- if (grub_strword (debug, "all") || grub_strword (debug, condition)) ++ negcond = grub_zalloc (grub_strlen (condition) + 2); ++ if (negcond) ++ { ++ grub_strcpy (negcond, "-"); ++ grub_strcpy (negcond+1, condition); ++ negated = grub_strword (debug, negcond); ++ grub_free (negcond); ++ } ++ ++ if (!negated && ++ (grub_strword (debug, "all") || grub_strword (debug, condition))) + return 1; + + return 0; diff --git a/0165-Export-all-variables-from-the-initial-context-when-c.patch b/0165-Export-all-variables-from-the-initial-context-when-c.patch new file mode 100644 index 0000000..bfe3165 --- /dev/null +++ b/0165-Export-all-variables-from-the-initial-context-when-c.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 22 Jan 2019 15:40:25 +0100 +Subject: [PATCH] Export all variables from the initial context when creating a + submenu + +When a submenu is created, only the exported variables are copied to the +new menu context. But we want the variables to be global, so export lets +export all variables to the new created submenu. + +Also, don't unset the default variable when a new submenu is created. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/context.c | 2 +- + grub-core/normal/menu.c | 2 -- + 2 files changed, 1 insertion(+), 3 deletions(-) + +diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c +index ee53d4a68e5..87edd254c44 100644 +--- a/grub-core/normal/context.c ++++ b/grub-core/normal/context.c +@@ -99,7 +99,7 @@ grub_env_new_context (int export_all) + grub_err_t + grub_env_context_open (void) + { +- return grub_env_new_context (0); ++ return grub_env_new_context (1); + } + + int grub_extractor_level = 0; +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index ea714d27176..d4832f17699 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -375,8 +375,6 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + + if (ptr && ptr[0] && ptr[1]) + grub_env_set ("default", ptr + 1); +- else +- grub_env_unset ("default"); + + grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args); + diff --git a/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch b/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch new file mode 100644 index 0000000..2cef9b9 --- /dev/null +++ b/0166-Fix-the-looking-up-grub.cfg-XXX-while-tftp-booting.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Masayoshi Mizuma +Date: Tue, 18 Dec 2018 21:27:45 -0500 +Subject: [PATCH] Fix the looking up grub.cfg-XXX while tftp booting. + +Currently, grub doesn't look up grub.cfg-UUID, grub.cfg-MAC and grub.cfg-IP +while the boot is from tftp. That is because the uuid size is got by +grub_snprintf(, 0, ,), but the grub_snprintf() always returns 0, +so grub judges there's no available uuid in the client and give up +the looking up grub.cfg-XXX. + +This issue can be fixed by changing grub_snprintf(, 0, ,) behaivior +to like as snprintf() from glibc, however, somewhere may expect +such argument as the error, so it's risky. + +Let's use sizeof() and grub_strlen() to calculate the uuid size +instead of grub_snprintf(). + +Resolves: rhbz#1658500 +--- + grub-core/net/net.c | 8 +++----- + 1 file changed, 3 insertions(+), 5 deletions(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index aa56393e1c4..15073dde1c4 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -1942,11 +1942,9 @@ grub_net_search_configfile (char *config) + char *client_uuid_var; + grub_size_t client_uuid_var_size; + +- client_uuid_var_size = grub_snprintf (NULL, 0, +- "net_%s_clientuuid", inf->name); +- if (client_uuid_var_size <= 0) +- continue; +- client_uuid_var_size += 1; ++ client_uuid_var_size = sizeof ("net_") + grub_strlen (inf->name) + ++ sizeof ("_clientuuid") + 1; ++ + client_uuid_var = grub_malloc(client_uuid_var_size); + if (!client_uuid_var) + continue; diff --git a/0167-Try-to-set-fPIE-and-friends-on-libgnu.a.patch b/0167-Try-to-set-fPIE-and-friends-on-libgnu.a.patch new file mode 100644 index 0000000..837da31 --- /dev/null +++ b/0167-Try-to-set-fPIE-and-friends-on-libgnu.a.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 12 Jul 2019 17:45:51 +0200 +Subject: [PATCH] Try to set -fPIE and friends on libgnu.a + +In order to make sure UTIL_CFLAGS and UTIL_LDFLAGS can correctly get +-Wl,-z,relro,-z,now , we need everything going in them to be built with at +least -fPIC (and preferably -fPIE) wherever we can, or else we get relocations +in some component object that can't be used with the link type that's being +used for the final ELF object. + +So this makes sure libgnu.a gets built with HOST_CFLAGS and HOST_LDFLAGS, +which are what is later used to define UTIL_CFLAGS and UTIL_LDFLAGS, and +includes -fPIE. + +Fixes an rpmdiff check. + +Related: rhbz#1658500 + +Signed-off-by: Peter Jones +[javierm: replace from bootstrap instead patching generated Makefile.am] +Signed-off-by: Javier Martinez Canillas +--- + bootstrap.conf | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 8804d5beb89..29a6a3e90e2 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -82,6 +82,9 @@ bootstrap_post_import_hook () { + patch -d grub-core/lib/gnulib -p2 \ + < "grub-core/lib/gnulib-patches/$patchname.patch" + done ++ for flagvar in CPPFLAGS CFLAGS; do ++ sed -i -e "s/^AM_$flagvar =/AM_$flagvar = \$(HOST_$flagvar)/" grub-core/lib/gnulib/Makefile.am ++ done + FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this + } diff --git a/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch b/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch new file mode 100644 index 0000000..21d242e --- /dev/null +++ b/0168-Don-t-make-grub_strtoull-print-an-error-if-no-conver.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 11 Feb 2019 15:14:10 +0100 +Subject: [PATCH] Don't make grub_strtoull() print an error if no conversion is + performed + +Callers can check if grub_errno was set to GRUB_ERR_BAD_NUMBER, so there's +no need to print an error if a conversion couldn't be performed. This just +pollutes the output with noisy error messages. + +Resolves: rhbz#1674512 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/misc.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 18a7dbf4cd7..87afb43cd55 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -475,8 +475,7 @@ grub_strtoull (const char * restrict str, const char ** const restrict end, + + if (! found) + { +- grub_error (GRUB_ERR_BAD_NUMBER, +- N_("unrecognized number")); ++ grub_errno = GRUB_ERR_BAD_NUMBER; + return 0; + } + diff --git a/0169-Fix-the-type-of-grub_efi_status_t.patch b/0169-Fix-the-type-of-grub_efi_status_t.patch new file mode 100644 index 0000000..fba3f3d --- /dev/null +++ b/0169-Fix-the-type-of-grub_efi_status_t.patch @@ -0,0 +1,79 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Mar 2019 13:06:06 -0400 +Subject: [PATCH] Fix the type of grub_efi_status_t + +Currently, in some builds with some checkers, we see: + +1. grub-core/disk/efi/efidisk.c:601: error[shiftTooManyBitsSigned]: Shifting signed 64-bit value by 63 bits is undefined behaviour + +This is because grub_efi_status_t is defined as grub_efi_intn_t, which is +signed, and shifting into the sign bit is not defined behavior. UEFI fixed +this in the spec in 2.3: + +2.3 | Change the defined type of EFI_STATUS from INTN to UINTN | May 7, 2009 + +And the current EDK2 code has: +MdePkg/Include/Base.h-// +MdePkg/Include/Base.h-// Status codes common to all execution phases +MdePkg/Include/Base.h-// +MdePkg/Include/Base.h:typedef UINTN RETURN_STATUS; +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-/** +MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit set. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code. +MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit set. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-**/ +MdePkg/Include/Base.h-#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCode))) +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-/** +MdePkg/Include/Base.h- Produces a RETURN_STATUS code with the highest bit clear. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @param StatusCode The status code value to convert into a warning code. +MdePkg/Include/Base.h- StatusCode must be in the range 0x00000000..0x7FFFFFFF. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @return The value specified by StatusCode with the highest bit clear. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-**/ +MdePkg/Include/Base.h-#define ENCODE_WARNING(StatusCode) ((RETURN_STATUS)(StatusCode)) +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-/** +MdePkg/Include/Base.h- Returns TRUE if a specified RETURN_STATUS code is an error code. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- This function returns TRUE if StatusCode has the high bit set. Otherwise, FALSE is returned. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @param StatusCode The status code value to evaluate. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h- @retval TRUE The high bit of StatusCode is set. +MdePkg/Include/Base.h- @retval FALSE The high bit of StatusCode is clear. +MdePkg/Include/Base.h- +MdePkg/Include/Base.h-**/ +MdePkg/Include/Base.h-#define RETURN_ERROR(StatusCode) (((INTN)(RETURN_STATUS)(StatusCode)) < 0) +... +Uefi/UefiBaseType.h:typedef RETURN_STATUS EFI_STATUS; + +This patch makes grub's implementation match the Edk2 declaration with regards +to the signedness of the type. + +Signed-off-by: Peter Jones +--- + include/grub/efi/api.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index 2ed9c26a450..dec7b06083e 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -536,7 +536,7 @@ typedef grub_uint64_t grub_efi_uint64_t; + typedef grub_uint8_t grub_efi_char8_t; + typedef grub_uint16_t grub_efi_char16_t; + +-typedef grub_efi_intn_t grub_efi_status_t; ++typedef grub_efi_uintn_t grub_efi_status_t; + /* Make grub_efi_status_t reasonably printable. */ + #if GRUB_CPU_SIZEOF_VOID_P == 8 + #define PRIxGRUB_EFI_STATUS "lx" diff --git a/0170-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch b/0170-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch new file mode 100644 index 0000000..5c6c28e --- /dev/null +++ b/0170-grub.d-Split-out-boot-success-reset-from-menu-auto-h.patch @@ -0,0 +1,165 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Christian Glombek +Date: Tue, 2 Apr 2019 16:22:21 +0200 +Subject: [PATCH] grub.d: Split out boot success reset from menu auto hide + script + +Also rename fallback and menu auto hide script to be executed +before and after boot success reset script. +In menu auto hide script, rename last_boot_ok var to menu_hide_ok +--- + Makefile.util.def | 14 ++++++++---- + ...allback_counting.in => 08_fallback_counting.in} | 14 ++++++------ + util/grub.d/10_reset_boot_success.in | 25 ++++++++++++++++++++++ + .../{01_menu_auto_hide.in => 12_menu_auto_hide.in} | 23 +++++--------------- + 4 files changed, 48 insertions(+), 28 deletions(-) + rename util/grub.d/{01_fallback_counting.in => 08_fallback_counting.in} (65%) + create mode 100644 util/grub.d/10_reset_boot_success.in + rename util/grub.d/{01_menu_auto_hide.in => 12_menu_auto_hide.in} (58%) + +diff --git a/Makefile.util.def b/Makefile.util.def +index 2019ebd0207..1fa92caad4d 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -458,14 +458,14 @@ script = { + }; + + script = { +- name = '01_fallback_counting'; +- common = util/grub.d/01_fallback_counting.in; ++ name = '08_fallback_counting'; ++ common = util/grub.d/08_fallback_counting.in; + installdir = grubconf; + }; + + script = { +- name = '01_menu_auto_hide'; +- common = util/grub.d/01_menu_auto_hide.in; ++ name = '12_menu_auto_hide'; ++ common = util/grub.d/12_menu_auto_hide.in; + installdir = grubconf; + }; + +@@ -524,6 +524,12 @@ script = { + condition = COND_HOST_LINUX; + }; + ++script = { ++ name = '10_reset_boot_success'; ++ common = util/grub.d/10_reset_boot_success.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '10_xnu'; + common = util/grub.d/10_xnu.in; +diff --git a/util/grub.d/01_fallback_counting.in b/util/grub.d/08_fallback_counting.in +similarity index 65% +rename from util/grub.d/01_fallback_counting.in +rename to util/grub.d/08_fallback_counting.in +index be0e770ea82..2e2c3ff7d31 100644 +--- a/util/grub.d/01_fallback_counting.in ++++ b/util/grub.d/08_fallback_counting.in +@@ -1,15 +1,17 @@ + #! /bin/sh -e +- +-# Boot Counting ++# Fallback Countdown ++# ++# This snippet depends on 10_reset_boot_success and needs to be kept in sync. ++# + # The boot_counter env var can be used to count down boot attempts after an +-# OSTree upgrade and choose the rollback deployment when 0 is reached. Both +-# boot_counter and boot_success need to be (re-)set from userspace. ++# OSTree upgrade and choose the rollback deployment when 0 is reached. ++# Both boot_counter=X and boot_success=1 need to be set from userspace. + cat << EOF + insmod increment + # Check if boot_counter exists and boot_success=0 to activate this behaviour. + if [ -n "\${boot_counter}" -a "\${boot_success}" = "0" ]; then +- # if countdown has ended, choose to boot rollback deployment (default=1 on +- # OSTree-based systems) ++ # if countdown has ended, choose to boot rollback deployment, ++ # i.e. default=1 on OSTree-based systems. + if [ "\${boot_counter}" = "0" -o "\${boot_counter}" = "-1" ]; then + set default=1 + set boot_counter=-1 +diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in +new file mode 100644 +index 00000000000..6c88d933dde +--- /dev/null ++++ b/util/grub.d/10_reset_boot_success.in +@@ -0,0 +1,25 @@ ++#! /bin/sh -e ++# Reset Boot Success ++# ++# The 08_fallback_counting and 12_menu_auto_hide snippets rely on this one ++# and need to be kept in sync. ++# ++# The boot_success var needs to be set to 1 from userspace to mark a boot successful. ++cat << EOF ++insmod increment ++# Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry ++if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then ++ set menu_hide_ok=1 ++else ++ set menu_hide_ok=0 ++fi ++# Reset boot_indeterminate after a successful boot, increment otherwise ++if [ "\${boot_success}" = "1" ] ; then ++ set boot_indeterminate=0 ++else ++ increment boot_indeterminate ++fi ++# Reset boot_success for current boot ++set boot_success=0 ++save_env boot_success boot_indeterminate ++EOF +diff --git a/util/grub.d/01_menu_auto_hide.in b/util/grub.d/12_menu_auto_hide.in +similarity index 58% +rename from util/grub.d/01_menu_auto_hide.in +rename to util/grub.d/12_menu_auto_hide.in +index ad175870a54..6a7c0fa0d43 100644 +--- a/util/grub.d/01_menu_auto_hide.in ++++ b/util/grub.d/12_menu_auto_hide.in +@@ -1,5 +1,8 @@ + #! /bin/sh +- ++# Menu Auto Hide ++# ++# This snippet depends on 10_reset_boot_success and needs to be kept in sync. ++# + # Disable / skip generating menu-auto-hide config parts on serial terminals + for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do + case "$x" in +@@ -10,29 +13,13 @@ for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do + done + + cat << EOF +-if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then +- set last_boot_ok=1 +-else +- set last_boot_ok=0 +-fi +- +-# Reset boot_indeterminate after a successful boot +-if [ "\${boot_success}" = "1" ] ; then +- set boot_indeterminate=0 +-# Avoid boot_indeterminate causing the menu to be hidden more then once +-elif [ "\${boot_indeterminate}" = "1" ]; then +- set boot_indeterminate=2 +-fi +-set boot_success=0 +-save_env boot_success boot_indeterminate +- + if [ x\$feature_timeout_style = xy ] ; then + if [ "\${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 +- elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then ++ elif [ "\${menu_auto_hide}" -a "\${menu_hide_ok}" = "1" ]; then + set orig_timeout_style=\${timeout_style} + set orig_timeout=\${timeout} + if [ "\${fastboot}" = "1" ]; then diff --git a/0171-Fix-systemctl-kexec-exit-status-check.patch b/0171-Fix-systemctl-kexec-exit-status-check.patch new file mode 100644 index 0000000..74ecedc --- /dev/null +++ b/0171-Fix-systemctl-kexec-exit-status-check.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 9 Apr 2019 12:30:38 +0200 +Subject: [PATCH] Fix systemctl kexec exit status check + +There's always an error printed even when the systemctl kexec command does +succeed. That's because systemctl executes it asynchronously, but the emu +loader seems to expect it to be synchronous and that should never return. + +Also, it's wrong to test if kexecute == 1 since we already know that's the +case or otherwise the function wouldn't had called grub_fatal() earlier. + +Finally, systemctl kexec failing shouldn't be a fatal error since the emu +loader fallbacks to executing the kexec command in case of a failure. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/loader/emu/linux.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c +index fda9e00d24c..5b85b225eed 100644 +--- a/grub-core/loader/emu/linux.c ++++ b/grub-core/loader/emu/linux.c +@@ -71,8 +71,10 @@ grub_linux_boot (void) + (kexecute==1) ? "do-or-die" : "just-in-case"); + rc = grub_util_exec (systemctl); + +- if (kexecute == 1) +- grub_fatal (N_("Error trying to perform 'systemctl kexec'")); ++ if (rc == GRUB_ERR_NONE) ++ return rc; ++ ++ grub_error (rc, N_("Error trying to perform 'systemctl kexec'")); + + /* need to check read-only root before resetting hard!? */ + grub_printf("Performing 'kexec -e'"); diff --git a/0172-Print-grub-emu-linux-loader-messages-as-debug.patch b/0172-Print-grub-emu-linux-loader-messages-as-debug.patch new file mode 100644 index 0000000..a49ec44 --- /dev/null +++ b/0172-Print-grub-emu-linux-loader-messages-as-debug.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 9 Apr 2019 12:42:37 +0200 +Subject: [PATCH] Print grub-emu linux loader messages as debug + +They just polute the output and should better be debug messages instead. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/loader/emu/linux.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c +index 5b85b225eed..22ab6af1727 100644 +--- a/grub-core/loader/emu/linux.c ++++ b/grub-core/loader/emu/linux.c +@@ -50,7 +50,7 @@ grub_linux_boot (void) + initrd_param = grub_xasprintf("%s", ""); + } + +- grub_printf("%serforming 'kexec -l %s %s %s'\n", ++ grub_dprintf ("linux", "%serforming 'kexec -l %s %s %s'\n", + (kexecute) ? "P" : "Not p", + kernel_path, initrd_param, boot_cmdline); + +@@ -67,7 +67,7 @@ grub_linux_boot (void) + if (kexecute < 1) + grub_fatal (N_("Use '"PACKAGE"-emu --kexec' to force a system restart.")); + +- grub_printf("Performing 'systemctl kexec' (%s) ", ++ grub_dprintf ("linux", "Performing 'systemctl kexec' (%s) ", + (kexecute==1) ? "do-or-die" : "just-in-case"); + rc = grub_util_exec (systemctl); + diff --git a/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch b/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch new file mode 100644 index 0000000..34cff10 --- /dev/null +++ b/0173-Don-t-assume-that-boot-commands-will-only-return-on-.patch @@ -0,0 +1,79 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 9 Apr 2019 13:12:40 +0200 +Subject: [PATCH] Don't assume that boot commands will only return on fail + +While it's true that for most loaders the boot command never returns, it +may be the case that it does. For example the GRUB emulator boot command +calls to systemctl kexec which in turn does an asynchonous call to kexec. + +So in this case GRUB will wrongly assume that the boot command fails and +print a "Failed to boot both default and fallback entries" even when the +kexec call later succeeds. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/menu.c | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index d4832f17699..9ea1f411814 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -285,7 +285,7 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) + } + + /* Run a menu entry. */ +-static void ++static grub_err_t + grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + { + grub_err_t err = GRUB_ERR_NONE; +@@ -385,7 +385,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + + if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) + /* Implicit execution of boot, only if something is loaded. */ +- grub_command_execute ("boot", 0, 0); ++ err = grub_command_execute ("boot", 0, 0); + + if (errs_before != grub_err_printed_errors) + grub_wait_after_message (); +@@ -408,6 +408,8 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + else + grub_env_unset ("default"); + grub_env_unset ("timeout"); ++ ++ return err; + } + + /* Execute ENTRY from the menu MENU, falling back to entries specified +@@ -422,10 +424,13 @@ grub_menu_execute_with_fallback (grub_menu_t menu, + void *callback_data) + { + int fallback_entry; ++ grub_err_t err; + + callback->notify_booting (entry, callback_data); + +- grub_menu_execute_entry (entry, 1); ++ err = grub_menu_execute_entry (entry, 1); ++ if (err == GRUB_ERR_NONE) ++ return; + + /* Deal with fallback entries. */ + while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback")) +@@ -436,11 +441,9 @@ grub_menu_execute_with_fallback (grub_menu_t menu, + + entry = grub_menu_get_entry (menu, fallback_entry); + callback->notify_fallback (entry, callback_data); +- grub_menu_execute_entry (entry, 1); +- /* If the function call to execute the entry returns at all, then this is +- taken to indicate a boot failure. For menu entries that do something +- other than actually boot an operating system, this could assume +- incorrectly that something failed. */ ++ err = grub_menu_execute_entry (entry, 1); ++ if (err == GRUB_ERR_NONE) ++ return; + } + + if (!autobooted) diff --git a/0174-Fix-undefined-references-for-fdt-when-building-with-.patch b/0174-Fix-undefined-references-for-fdt-when-building-with-.patch new file mode 100644 index 0000000..9065da8 --- /dev/null +++ b/0174-Fix-undefined-references-for-fdt-when-building-with-.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 1 May 2019 00:36:19 +0200 +Subject: [PATCH] Fix undefined references for fdt when building with platform + emu + +The fdt module isn't build for this platform, so adding the declarations +with platform emu will lead to the following undefined reference errors: + +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x500): undefined reference to `grub_fdt_add_subnode' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x518): undefined reference to `grub_fdt_check_header' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x530): undefined reference to `grub_fdt_check_header_nosize' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x548): undefined reference to `grub_fdt_create_empty_tree' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x560): undefined reference to `grub_fdt_find_subnode' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x578): undefined reference to `grub_fdt_first_node' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x590): undefined reference to `grub_fdt_get_nodename' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5a8): undefined reference to `grub_fdt_get_prop' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5c0): undefined reference to `grub_fdt_next_node' +BUILDSTDERR: /usr/bin/ld: grub_emu_lite-symlist.o:(.data+0x5d8): undefined reference to `grub_fdt_set_prop' +BUILDSTDERR: collect2: error: ld returned 1 exit status +BUILDSTDERR: make[1]: *** [Makefile:27093: grub-emu-lite] Error 1 +BUILDSTDERR: make[1]: *** Waiting for unfinished jobs.... + +Signed-off-by: Javier Martinez Canillas +--- + include/grub/fdt.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/grub/fdt.h b/include/grub/fdt.h +index 22b7c5463fc..2041341fd68 100644 +--- a/include/grub/fdt.h ++++ b/include/grub/fdt.h +@@ -19,7 +19,7 @@ + #ifndef GRUB_FDT_HEADER + #define GRUB_FDT_HEADER 1 + +-#if defined(__arm__) || defined(__aarch64__) ++#if !defined(GRUB_MACHINE_EMU) && (defined(__arm__) || defined(__aarch64__)) + + #include + #include diff --git a/0175-Do-better-in-bootstrap.conf.patch b/0175-Do-better-in-bootstrap.conf.patch new file mode 100644 index 0000000..3547c78 --- /dev/null +++ b/0175-Do-better-in-bootstrap.conf.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 10:58:52 -0400 +Subject: [PATCH] Do better in bootstrap.conf + +--- + bootstrap.conf | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 29a6a3e90e2..417cfe405f4 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -16,7 +16,13 @@ + # along with this program. If not, see . + + +-GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 ++# GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 ++if [[ -z "${GNULIB_REVISION}" ]] ;then ++ GNULIB_REVISION=fixes ++fi ++if [[ -z "${GNULIB_URL}" ]] ;then ++ GNULIB_URL=https://github.com/rhboot/gnulib.git ++fi + + # gnulib modules used by this package. + # mbswidth is used by gnulib-fix-width.diff's changes to argp rather than diff --git a/0176-Use-git-to-apply-gnulib-patches.patch b/0176-Use-git-to-apply-gnulib-patches.patch new file mode 100644 index 0000000..0813bad --- /dev/null +++ b/0176-Use-git-to-apply-gnulib-patches.patch @@ -0,0 +1,474 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 11:21:27 -0400 +Subject: [PATCH] Use git to apply gnulib patches. + +Signed-off-by: Peter Jones +--- + bootstrap.conf | 4 - + grub-core/lib/gnulib-patches/fix-null-deref.patch | 13 -- + .../gnulib-patches/fix-sign-compare-errors.patch | 161 --------------- + grub-core/lib/gnulib-patches/fix-width.patch | 217 --------------------- + grub-core/lib/gnulib-patches/no-abort.patch | 26 --- + 5 files changed, 421 deletions(-) + delete mode 100644 grub-core/lib/gnulib-patches/fix-null-deref.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch + delete mode 100644 grub-core/lib/gnulib-patches/fix-width.patch + delete mode 100644 grub-core/lib/gnulib-patches/no-abort.patch + +diff --git a/bootstrap.conf b/bootstrap.conf +index 417cfe405f4..24ea40b2fc5 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -84,10 +84,6 @@ cp -a INSTALL INSTALL.grub + + bootstrap_post_import_hook () { + set -e +- for patchname in fix-null-deref fix-width no-abort fix-sign-compare-errors; do +- patch -d grub-core/lib/gnulib -p2 \ +- < "grub-core/lib/gnulib-patches/$patchname.patch" +- done + for flagvar in CPPFLAGS CFLAGS; do + sed -i -e "s/^AM_$flagvar =/AM_$flagvar = \$(HOST_$flagvar)/" grub-core/lib/gnulib/Makefile.am + done +diff --git a/grub-core/lib/gnulib-patches/fix-null-deref.patch b/grub-core/lib/gnulib-patches/fix-null-deref.patch +deleted file mode 100644 +index 8fafa153a47..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-null-deref.patch ++++ /dev/null +@@ -1,13 +0,0 @@ +-diff --git a/lib/argp-parse.c b/lib/argp-parse.c +-index 6dec57310..900adad54 100644 +---- a/lib/argp-parse.c +-+++ b/lib/argp-parse.c +-@@ -940,7 +940,7 @@ weak_alias (__argp_parse, argp_parse) +- void * +- __argp_input (const struct argp *argp, const struct argp_state *state) +- { +-- if (state) +-+ if (state && state->pstate) +- { +- struct group *group; +- struct parser *parser = state->pstate; +diff --git a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch b/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch +deleted file mode 100644 +index 479029c0565..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-sign-compare-errors.patch ++++ /dev/null +@@ -1,161 +0,0 @@ +-diff --git a/lib/regcomp.c b/lib/regcomp.c +-index cc85f35ac58..361079d82d6 100644 +---- a/lib/regcomp.c +-+++ b/lib/regcomp.c +-@@ -322,7 +322,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, +- *p++ = dfa->nodes[node].opr.c; +- memset (&state, '\0', sizeof (state)); +- if (__mbrtowc (&wc, (const char *) buf, p - buf, +-- &state) == p - buf +-+ &state) == (size_t)(p - buf) +- && (__wcrtomb ((char *) buf, __towlower (wc), &state) +- != (size_t) -1)) +- re_set_fastmap (fastmap, false, buf[0]); +-@@ -3778,7 +3778,7 @@ fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) +- num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2) +- ? -2 +- : num == -1 +-- ? c - '0' +-+ ? (Idx)(c - '0') +- : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); +- } +- return num; +-diff --git a/lib/regex_internal.c b/lib/regex_internal.c +-index 9004ce809eb..193a1e3d332 100644 +---- a/lib/regex_internal.c +-+++ b/lib/regex_internal.c +-@@ -233,7 +233,7 @@ build_wcs_buffer (re_string_t *pstr) +- /* Apply the translation if we need. */ +- if (__glibc_unlikely (pstr->trans != NULL)) +- { +-- int i, ch; +-+ unsigned int i, ch; +- +- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) +- { +-@@ -376,7 +376,7 @@ build_wcs_upper_buffer (re_string_t *pstr) +- prev_st = pstr->cur_state; +- if (__glibc_unlikely (pstr->trans != NULL)) +- { +-- int i, ch; +-+ unsigned int i, ch; +- +- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i) +- { +-@@ -754,7 +754,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) +- memset (&cur_state, 0, sizeof (cur_state)); +- mbclen = __mbrtowc (&wc2, (const char *) pp, mlen, +- &cur_state); +-- if (raw + offset - p <= mbclen +-+ if ((size_t)(raw + offset - p) <= mbclen +- && mbclen < (size_t) -2) +- { +- memset (&pstr->cur_state, '\0', +-diff --git a/lib/regex_internal.h b/lib/regex_internal.h +-index 5462419b787..e0f8292395d 100644 +---- a/lib/regex_internal.h +-+++ b/lib/regex_internal.h +-@@ -425,7 +425,7 @@ struct re_string_t +- unsigned char offsets_needed; +- unsigned char newline_anchor; +- unsigned char word_ops_used; +-- int mb_cur_max; +-+ unsigned int mb_cur_max; +- }; +- typedef struct re_string_t re_string_t; +- +-@@ -702,7 +702,7 @@ struct re_dfa_t +- unsigned int is_utf8 : 1; +- unsigned int map_notascii : 1; +- unsigned int word_ops_used : 1; +-- int mb_cur_max; +-+ unsigned int mb_cur_max; +- bitset_t word_char; +- reg_syntax_t syntax; +- Idx *subexp_map; +-diff --git a/lib/regexec.c b/lib/regexec.c +-index 0a7a27b772e..b57d4f9141d 100644 +---- a/lib/regexec.c +-+++ b/lib/regexec.c +-@@ -443,7 +443,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, +- { +- if (ret_len) +- { +-- assert (pmatch[0].rm_so == start); +-+ assert (pmatch[0].rm_so == (long)start); +- rval = pmatch[0].rm_eo - start; +- } +- else +-@@ -877,11 +877,11 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, +- if (__glibc_unlikely (mctx.input.offsets_needed != 0)) +- { +- pmatch[reg_idx].rm_so = +-- (pmatch[reg_idx].rm_so == mctx.input.valid_len +-+ (pmatch[reg_idx].rm_so == (long)mctx.input.valid_len +- ? mctx.input.valid_raw_len +- : mctx.input.offsets[pmatch[reg_idx].rm_so]); +- pmatch[reg_idx].rm_eo = +-- (pmatch[reg_idx].rm_eo == mctx.input.valid_len +-+ (pmatch[reg_idx].rm_eo == (long)mctx.input.valid_len +- ? mctx.input.valid_raw_len +- : mctx.input.offsets[pmatch[reg_idx].rm_eo]); +- } +-@@ -1418,11 +1418,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, +- } +- memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); +- +-- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) +-+ for (idx = pmatch[0].rm_so; idx <= (long)pmatch[0].rm_eo ;) +- { +- update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); +- +-- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) +-+ if (idx == (long)pmatch[0].rm_eo && cur_node == mctx->last_node) +- { +- Idx reg_idx; +- if (fs) +-@@ -1519,7 +1519,7 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, +- if (reg_num < nmatch) +- { +- /* We are at the last node of this sub expression. */ +-- if (pmatch[reg_num].rm_so < cur_idx) +-+ if (pmatch[reg_num].rm_so < (long)cur_idx) +- { +- pmatch[reg_num].rm_eo = cur_idx; +- /* This is a non-empty match or we are not inside an optional +-@@ -2938,7 +2938,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, +- mctx->state_log[str_idx] = cur_state; +- } +- +-- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;) +-+ for (null_cnt = 0; str_idx < last_str && null_cnt <= (long)mctx->max_mb_elem_len;) +- { +- re_node_set_empty (&next_nodes); +- if (mctx->state_log[str_idx + 1]) +-@@ -3718,7 +3718,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, +- const re_string_t *input, Idx str_idx) +- { +- const re_token_t *node = dfa->nodes + node_idx; +-- int char_len, elem_len; +-+ unsigned int char_len, elem_len; +- Idx i; +- +- if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) +-@@ -4066,7 +4066,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) +- /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ +- ret = re_string_realloc_buffers (pstr, +- MAX (min_len, +-- MIN (pstr->len, pstr->bufs_len * 2))); +-+ MIN ((long)pstr->len, pstr->bufs_len * 2))); +- if (__glibc_unlikely (ret != REG_NOERROR)) +- return ret; +- +-@@ -4236,7 +4236,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, +- = (from == to ? -1 : 0); +- +- mctx->bkref_ents[mctx->nbkref_ents++].more = 0; +-- if (mctx->max_mb_elem_len < to - from) +-+ if (mctx->max_mb_elem_len < (long)(to - from)) +- mctx->max_mb_elem_len = to - from; +- return REG_NOERROR; +- } +diff --git a/grub-core/lib/gnulib-patches/fix-width.patch b/grub-core/lib/gnulib-patches/fix-width.patch +deleted file mode 100644 +index 0a208ad08b5..00000000000 +--- a/grub-core/lib/gnulib-patches/fix-width.patch ++++ /dev/null +@@ -1,217 +0,0 @@ +-diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c +-index ba6a407f7..d0685b3d4 100644 +---- a/lib/argp-fmtstream.c +-+++ b/lib/argp-fmtstream.c +-@@ -28,9 +28,11 @@ +- #include +- #include +- #include +-+#include +- +- #include "argp-fmtstream.h" +- #include "argp-namefrob.h" +-+#include "mbswidth.h" +- +- #ifndef ARGP_FMTSTREAM_USE_LINEWRAP +- +-@@ -115,6 +117,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free) +- #endif +- #endif +- +-+ +-+/* Return the pointer to the first character that doesn't fit in l columns. */ +-+static inline const ptrdiff_t +-+add_width (const char *ptr, const char *end, size_t l) +-+{ +-+ mbstate_t ps; +-+ const char *ptr0 = ptr; +-+ +-+ memset (&ps, 0, sizeof (ps)); +-+ +-+ while (ptr < end) +-+ { +-+ wchar_t wc; +-+ size_t s, k; +-+ +-+ s = mbrtowc (&wc, ptr, end - ptr, &ps); +-+ if (s == (size_t) -1) +-+ break; +-+ if (s == (size_t) -2) +-+ { +-+ if (1 >= l) +-+ break; +-+ l--; +-+ ptr++; +-+ continue; +-+ } +-+ +-+ if (wc == '\e' && ptr + 3 < end +-+ && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1') +-+ && ptr[3] == 'm') +-+ { +-+ ptr += 4; +-+ continue; +-+ } +-+ +-+ k = wcwidth (wc); +-+ +-+ if (k >= l) +-+ break; +-+ l -= k; +-+ ptr += s; +-+ } +-+ return ptr - ptr0; +-+} +-+ +- /* Process FS's buffer so that line wrapping is done from POINT_OFFS to the +- end of its buffer. This code is mostly from glibc stdio/linewrap.c. */ +- void +-@@ -168,13 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- if (!nl) +- { +- /* The buffer ends in a partial line. */ +-+ size_t display_width = mbsnwidth (buf, fs->p - buf, +-+ MBSW_STOP_AT_NUL); +- +-- if (fs->point_col + len < fs->rmargin) +-+ if (fs->point_col + display_width < fs->rmargin) +- { +- /* The remaining buffer text is a partial line and fits +- within the maximum line width. Advance point for the +- characters to be written and stop scanning. */ +-- fs->point_col += len; +-+ fs->point_col += display_width; +- break; +- } +- else +-@@ -182,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- the end of the buffer. */ +- nl = fs->p; +- } +-- else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin) +-- { +-- /* The buffer contains a full line that fits within the maximum +-- line width. Reset point and scan the next line. */ +-- fs->point_col = 0; +-- buf = nl + 1; +-- continue; +-- } +-+ else +-+ { +-+ size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL); +-+ if (display_width < (ssize_t) fs->rmargin) +-+ { +-+ /* The buffer contains a full line that fits within the maximum +-+ line width. Reset point and scan the next line. */ +-+ fs->point_col = 0; +-+ buf = nl + 1; +-+ continue; +-+ } +-+ } +- +- /* This line is too long. */ +- r = fs->rmargin - 1; +-@@ -225,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- char *p, *nextline; +- int i; +- +-- p = buf + (r + 1 - fs->point_col); +-+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); +- while (p >= buf && !isblank ((unsigned char) *p)) +- --p; +- nextline = p + 1; /* This will begin the next line. */ +-@@ -243,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- { +- /* A single word that is greater than the maximum line width. +- Oh well. Put it on an overlong line by itself. */ +-- p = buf + (r + 1 - fs->point_col); +-+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col)); +- /* Find the end of the long word. */ +- if (p < nl) +- do +-@@ -277,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs) +- && fs->p > nextline) +- { +- /* The margin needs more blanks than we removed. */ +-- if (fs->end - fs->p > fs->wmargin + 1) +-+ if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL) +-+ > fs->wmargin + 1) +- /* Make some space for them. */ +- { +- size_t mv = fs->p - nextline; +-diff --git a/lib/argp-help.c b/lib/argp-help.c +-index e5375a0f0..5d8f451ec 100644 +---- a/lib/argp-help.c +-+++ b/lib/argp-help.c +-@@ -51,6 +51,7 @@ +- #include "argp.h" +- #include "argp-fmtstream.h" +- #include "argp-namefrob.h" +-+#include "mbswidth.h" +- +- #ifndef SIZE_MAX +- # define SIZE_MAX ((size_t) -1) +-@@ -1432,7 +1433,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state, +- +- /* Manually do line wrapping so that it (probably) won't get wrapped at +- any embedded spaces. */ +-- space (stream, 1 + nl - cp); +-+ space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL)); +- +- __argp_fmtstream_write (stream, cp, nl - cp); +- } +-diff --git a/lib/mbswidth.c b/lib/mbswidth.c +-index 408a15e34..b3fb7f83a 100644 +---- a/lib/mbswidth.c +-+++ b/lib/mbswidth.c +-@@ -38,6 +38,14 @@ +- /* Get INT_MAX. */ +- #include +- +-+#ifndef FALLTHROUGH +-+# if __GNUC__ < 7 +-+# define FALLTHROUGH ((void) 0) +-+# else +-+# define FALLTHROUGH __attribute__ ((__fallthrough__)) +-+# endif +-+#endif +-+ +- /* Returns the number of columns needed to represent the multibyte +- character string pointed to by STRING. If a non-printable character +- occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned. +-@@ -90,6 +98,10 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +- p++; +- width++; +- break; +-+ case '\0': +-+ if (flags & MBSW_STOP_AT_NUL) +-+ return width; +-+ FALLTHROUGH; +- default: +- /* If we have a multibyte sequence, scan it up to its end. */ +- { +-@@ -168,6 +180,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags) +- { +- unsigned char c = (unsigned char) *p++; +- +-+ if (c == 0 && (flags & MBSW_STOP_AT_NUL)) +-+ return width; +-+ +- if (isprint (c)) +- { +- if (width == INT_MAX) +-diff --git a/lib/mbswidth.h b/lib/mbswidth.h +-index 2b5c53c37..45a123e63 100644 +---- a/lib/mbswidth.h +-+++ b/lib/mbswidth.h +-@@ -45,6 +45,10 @@ extern "C" { +- control characters and 1 otherwise. */ +- #define MBSW_REJECT_UNPRINTABLE 2 +- +-+/* If this bit is set \0 is treated as the end of string. +-+ Otherwise it's treated as a normal one column width character. */ +-+#define MBSW_STOP_AT_NUL 4 +-+ +- +- /* Returns the number of screen columns needed for STRING. */ +- #define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ +diff --git a/grub-core/lib/gnulib-patches/no-abort.patch b/grub-core/lib/gnulib-patches/no-abort.patch +deleted file mode 100644 +index e469c4762eb..00000000000 +--- a/grub-core/lib/gnulib-patches/no-abort.patch ++++ /dev/null +@@ -1,26 +0,0 @@ +-diff --git a/lib/regcomp.c b/lib/regcomp.c +-index cc85f35ac..de45ebb5c 100644 +---- a/lib/regcomp.c +-+++ b/lib/regcomp.c +-@@ -528,9 +528,9 @@ regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, +- to this routine. If we are given anything else, or if other regex +- code generates an invalid error code, then the program has a bug. +- Dump core so we can fix it. */ +-- abort (); +-- +-- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); +-+ msg = gettext ("unknown regexp error"); +-+ else +-+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]); +- +- msg_size = strlen (msg) + 1; /* Includes the null. */ +- +-@@ -1136,7 +1136,7 @@ optimize_utf8 (re_dfa_t *dfa) +- } +- break; +- default: +-- abort (); +-+ break; +- } +- +- if (mb_chars || has_period) diff --git a/0177-autogen.sh-use-find-wholename-for-long-path-matches.patch b/0177-autogen.sh-use-find-wholename-for-long-path-matches.patch new file mode 100644 index 0000000..1ac3f16 --- /dev/null +++ b/0177-autogen.sh-use-find-wholename-for-long-path-matches.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 14:01:50 -0400 +Subject: [PATCH] autogen.sh: use find -wholename for long path matches + +Signed-off-by: Peter Jones +--- + autogen.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/autogen.sh b/autogen.sh +index ef43270fca0..a1783d62c26 100755 +--- a/autogen.sh ++++ b/autogen.sh +@@ -13,7 +13,7 @@ fi + export LC_COLLATE=C + unset LC_ALL + +-find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath './gnulib/*' ! -iname './grub-core/lib/gnulib/*' |sort > po/POTFILES.in ++find . -iname '*.[ch]' ! -ipath './grub-core/lib/libgcrypt-grub/*' ! -ipath './build-aux/*' ! -ipath './grub-core/lib/libgcrypt/src/misc.c' ! -ipath './grub-core/lib/libgcrypt/src/global.c' ! -ipath './grub-core/lib/libgcrypt/src/secmem.c' ! -ipath './util/grub-gen-widthspec.c' ! -ipath './util/grub-gen-asciih.c' ! -ipath './gnulib/*' ! -wholename './grub-core/lib/gnulib/*' |sort > po/POTFILES.in + find util -iname '*.in' ! -name Makefile.in |sort > po/POTFILES-shell.in + + echo "Importing unicode..." diff --git a/0178-bootstrap.conf-don-t-clobber-AM_CFLAGS-here.patch b/0178-bootstrap.conf-don-t-clobber-AM_CFLAGS-here.patch new file mode 100644 index 0000000..3a0e5bc --- /dev/null +++ b/0178-bootstrap.conf-don-t-clobber-AM_CFLAGS-here.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 29 Jul 2019 14:02:11 -0400 +Subject: [PATCH] bootstrap.conf: don't clobber AM_CFLAGS here + +--- + bootstrap.conf | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 24ea40b2fc5..274c55a5568 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -84,9 +84,6 @@ cp -a INSTALL INSTALL.grub + + bootstrap_post_import_hook () { + set -e +- for flagvar in CPPFLAGS CFLAGS; do +- sed -i -e "s/^AM_$flagvar =/AM_$flagvar = \$(HOST_$flagvar)/" grub-core/lib/gnulib/Makefile.am +- done + FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this + } diff --git a/0179-Fix-build-error-with-the-fdt-module-on-risc-v.patch b/0179-Fix-build-error-with-the-fdt-module-on-risc-v.patch new file mode 100644 index 0000000..35f2878 --- /dev/null +++ b/0179-Fix-build-error-with-the-fdt-module-on-risc-v.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +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 +--- + 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 + #include +@@ -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 */ diff --git a/0180-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch b/0180-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch new file mode 100644 index 0000000..582cadb --- /dev/null +++ b/0180-RISC-V-Fix-computation-of-pc-relative-relocation-off.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +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 +Tested-by: Chester Lin +Reviewed-by: Daniel Kiper +--- + 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)) + { diff --git a/0181-blscfg-Add-support-for-the-devicetree-field.patch b/0181-blscfg-Add-support-for-the-devicetree-field.patch new file mode 100644 index 0000000..8c971af --- /dev/null +++ b/0181-blscfg-Add-support-for-the-devicetree-field.patch @@ -0,0 +1,132 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +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 +--- + 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); diff --git a/0182-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch b/0182-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch new file mode 100644 index 0000000..2da87d6 --- /dev/null +++ b/0182-Set-a-devicetree-var-in-a-BLS-config-if-GRUB_DEFAULT.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +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 +--- + 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 diff --git a/0183-Don-t-add-a-class-option-to-menu-entries-generated-f.patch b/0183-Don-t-add-a-class-option-to-menu-entries-generated-f.patch new file mode 100644 index 0000000..d136618 --- /dev/null +++ b/0183-Don-t-add-a-class-option-to-menu-entries-generated-f.patch @@ -0,0 +1,78 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 4 Oct 2019 16:43:05 +0200 +Subject: [PATCH] Don't add a class option to menu entries generated for + ppc64le + +For ppc64le a grub config file with menuentry commands is still generated +even when BLS support is enabled. That's because BLS support was added to +Petitboot 1.8.0 and any previous version won't be able to parse BLS files. + +To make the BLS snippets the source of truth, these are used to generate +the menuentry commands in the grub config file. + +And to keep it consistent across all ppc64le machines regardless of the +firmware used, the grub config file is also generated for machines with +OF that use grub2 and would have BLS support. + +The BLS snippets created by the kernel package have fields that are used +to specify the generated menuentry command users and class options. These +fields are not present in BLS snippets created by OSTree though, so the +script generating the menuentry commands will add options with an empty +argument which will lead to grub failing to parse them. + +We could check if the field is defined before attempting to add those, but +since the grub2 blscfg module also supports setting these to variables, it +could lead to an empty argument even if was defined in the BLS snippet if +the variable doesn't exist. + +So to make more robust, just don't add a class to the menuentry commands +generated by the script. It's better to not have a class for the menuentry +than grub2 failing to parse the command and not populating the boot menu. + +Resolves: rhbz#1758225 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux_bls.in | 10 +--------- + 1 file changed, 1 insertion(+), 9 deletions(-) + +diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in +index 1b7536435f1..68fbedf2129 100644 +--- a/util/grub.d/10_linux_bls.in ++++ b/util/grub.d/10_linux_bls.in +@@ -127,9 +127,7 @@ read_config() + initrd="" + options="" + linux="" +- grub_users="" + grub_arg="" +- grub_class="" + + while read -r line + do +@@ -148,15 +146,9 @@ read_config() + "options") + options=${value} + ;; +- "grub_users") +- grub_users=${value} +- ;; + "grub_arg") + grub_arg=${value} + ;; +- "grub_class") +- grub_class=${value} +- ;; + esac + done < ${config_file} + } +@@ -180,7 +172,7 @@ populate_menu() + for bls in "${files[@]}" ; do + read_config "${blsdir}/${bls}.conf" + +- menu="${menu}menuentry '${title}' --class ${grub_class} ${grub_arg} --id=${bls} {\n" ++ menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" + menu="${menu}\t linux ${linux} ${options}\n" + if [ -n "${initrd}" ] ; then + menu="${menu}\t initrd ${boot_prefix}${initrd}\n" diff --git a/0184-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch b/0184-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch new file mode 100644 index 0000000..f4aa008 --- /dev/null +++ b/0184-10_linux.in-Also-use-GRUB_CMDLINE_LINUX_DEFAULT-to-s.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 15 Oct 2019 09:08:25 +0200 +Subject: [PATCH] 10_linux.in: Also use GRUB_CMDLINE_LINUX_DEFAULT to set + kernelopts + +The GRUB documentation mentions that there are two variables to set the +linux kernel cmdline: GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT. + +The former is added to all the menuentry commands and the latter is not +added to the recovery mode menu entries. But the blscfg module doesn't +populate recovery entries from the BLS snippets, so the values set in the +GRUB_CMDLINE_LINUX_DEFAULT variable should also be included in kernelopts. + +This is needed because the GRUB_CMDLINE_LINUX_DEFAULT option is mentioned +in the GRUB documentation so users assume that the kernel cmdline options +can be changed by setting this option and running the grub2-mkconfig tool. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 1520b7e47c1..0471464e68e 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -118,7 +118,7 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + populate_header_warn + + cat << EOF +-set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX}" ++set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + + insmod blscfg + blscfg +@@ -134,7 +134,7 @@ EOF + fi + fi + +- ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX}" ++ ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then + ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" + fi diff --git a/0185-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch b/0185-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch new file mode 100644 index 0000000..669c770 --- /dev/null +++ b/0185-blscfg-Don-t-hardcode-an-env-var-as-fallback-for-the.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 14 Oct 2019 17:37:26 +0200 +Subject: [PATCH] blscfg: Don't hardcode an env var as fallback for the BLS + options field + +If the BLS fragments don't have an options field or if this was set to an +environment variable that was not defined in the grubenv file, the blscfg +module searches for an default_kernelopts variable that is defined in the +grub.cfg file. + +But the blscfg module shouldn't hardcode fallbacks variables and instead +this logic should be handled in the GRUB config file itself. + +Also, add a comment explaining where the kernelopts variable is supposed +to be defined and what is the process for the user to change its value. + +Resolves: rhbz#1710483 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 4 ---- + util/grub.d/10_linux.in | 12 +++++++++++- + 2 files changed, 11 insertions(+), 5 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 1ec89870483..471975fd2e5 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -733,10 +733,6 @@ static void create_entry (struct bls_entry *entry) + + title = bls_get_val (entry, "title", NULL); + options = expand_val (bls_get_val (entry, "options", NULL)); +- +- if (!options) +- options = expand_val (grub_env_get("default_kernelopts")); +- + initrds = bls_make_list (entry, "initrd", NULL); + + devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 0471464e68e..21a6915dca3 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -118,7 +118,17 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + populate_header_warn + + cat << EOF +-set default_kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++# The kernelopts variable should be defined in the grubenv file. But to ensure that menu ++# entries populated from BootLoaderSpec files that use this variable work correctly even ++# without a grubenv file, define a fallback kernelopts variable if this has not been set. ++# ++# The kernelopts variable in the grubenv file can be modified using the grubby tool or by ++# executing the grub2-mkconfig tool. For the latter, the values of the GRUB_CMDLINE_LINUX ++# and GRUB_CMDLINE_LINUX_DEFAULT options from /etc/default/grub file are used to set both ++# the kernelopts variable in the grubenv file and the fallback kernelopts variable. ++if [ -z "\${kernelopts}" ]; then ++ set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++fi + + insmod blscfg + blscfg diff --git a/0186-grub-set-bootflag-Update-comment-about-running-as-ro.patch b/0186-grub-set-bootflag-Update-comment-about-running-as-ro.patch new file mode 100644 index 0000000..cd4ef77 --- /dev/null +++ b/0186-grub-set-bootflag-Update-comment-about-running-as-ro.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 13 Nov 2019 12:15:43 +0100 +Subject: [PATCH] grub-set-bootflag: Update comment about running as root + through pkexec + +We have stopped using pkexec for grub-set-bootflag, instead it is now +installed suid root, update the comment accordingly. + +Signed-off-by: Hans de Goede +--- + util/grub-set-bootflag.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index 6a79ee67444..65d74ce010f 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -18,7 +18,7 @@ + */ + + /* +- * NOTE this gets run by users as root (through pkexec), so this does not ++ * NOTE this gets run by users as root (its suid root), so this does not + * use any grub library / util functions to allow for easy auditing. + * The grub headers are only included to get certain defines. + */ diff --git a/0187-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch b/0187-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch new file mode 100644 index 0000000..122bf68 --- /dev/null +++ b/0187-grub-set-bootflag-Write-new-env-to-tmpfile-and-then-.patch @@ -0,0 +1,152 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 13 Nov 2019 13:02:01 +0100 +Subject: [PATCH] grub-set-bootflag: Write new env to tmpfile and then rename + +Make the grubenv writing code in grub-set-bootflag more robust by +writing the modified grubenv to a tmpfile first and then renaming the +tmpfile over the old grubenv (following symlinks). + +Signed-off-by: Hans de Goede +--- + util/grub-set-bootflag.c | 87 +++++++++++++++++++++++++++++++++++++++++++----- + 1 file changed, 78 insertions(+), 9 deletions(-) + +diff --git a/util/grub-set-bootflag.c b/util/grub-set-bootflag.c +index 65d74ce010f..d1c5e28862b 100644 +--- a/util/grub-set-bootflag.c ++++ b/util/grub-set-bootflag.c +@@ -28,7 +28,9 @@ + #include + #include /* For GRUB_ENVBLK_DEFCFG define */ + #include ++#include + #include ++#include + #include + #include + +@@ -54,8 +56,10 @@ int main(int argc, char *argv[]) + { + /* NOTE buf must be at least the longest bootflag length + 4 bytes */ + char env[GRUBENV_SIZE + 1], buf[64], *s; ++ /* +1 for 0 termination, +6 for "XXXXXX" in tmp filename */ ++ char env_filename[PATH_MAX + 1], tmp_filename[PATH_MAX + 6 + 1]; + const char *bootflag; +- int i, len, ret; ++ int i, fd, len, ret; + FILE *f; + + if (argc != 2) +@@ -77,7 +81,32 @@ int main(int argc, char *argv[]) + bootflag = bootflags[i]; + len = strlen (bootflag); + +- f = fopen (GRUBENV, "r"); ++ /* ++ * Really become root. setuid avoids an user killing us, possibly leaking ++ * the tmpfile. setgid avoids the new grubenv's gid being that of the user. ++ */ ++ ret = setuid(0); ++ if (ret) ++ { ++ perror ("Error setuid(0) failed"); ++ return 1; ++ } ++ ++ ret = setgid(0); ++ if (ret) ++ { ++ perror ("Error setgid(0) failed"); ++ return 1; ++ } ++ ++ /* Canonicalize GRUBENV filename, resolving symlinks, etc. */ ++ if (!realpath(GRUBENV, env_filename)) ++ { ++ perror ("Error canonicalizing " GRUBENV " filename"); ++ return 1; ++ } ++ ++ f = fopen (env_filename, "r"); + if (!f) + { + perror ("Error opening " GRUBENV " for reading"); +@@ -132,30 +161,70 @@ int main(int argc, char *argv[]) + snprintf(buf, sizeof(buf), "%s=1\n", bootflag); + memcpy(s, buf, len + 3); + +- /* "r+", don't truncate so that the diskspace stays reserved */ +- f = fopen (GRUBENV, "r+"); ++ ++ /* ++ * Create a tempfile for writing the new env. Use the canonicalized filename ++ * for the template so that the tmpfile is in the same dir / on same fs. ++ */ ++ snprintf(tmp_filename, sizeof(tmp_filename), "%sXXXXXX", env_filename); ++ fd = mkstemp(tmp_filename); ++ if (fd == -1) ++ { ++ perror ("Creating tmpfile failed"); ++ return 1; ++ } ++ ++ f = fdopen (fd, "w"); + if (!f) + { +- perror ("Error opening " GRUBENV " for writing"); ++ perror ("Error fdopen of tmpfile failed"); ++ unlink(tmp_filename); + return 1; + } + + ret = fwrite (env, 1, GRUBENV_SIZE, f); + if (ret != GRUBENV_SIZE) + { +- perror ("Error writing to " GRUBENV); ++ perror ("Error writing tmpfile"); ++ unlink(tmp_filename); + return 1; + } + + ret = fflush (f); + if (ret) + { +- perror ("Error flushing " GRUBENV); ++ perror ("Error flushing tmpfile"); ++ unlink(tmp_filename); + return 1; + } + +- fsync (fileno (f)); +- fclose (f); ++ ret = fsync (fileno (f)); ++ if (ret) ++ { ++ perror ("Error syncing tmpfile"); ++ unlink(tmp_filename); ++ return 1; ++ } ++ ++ ret = fclose (f); ++ if (ret) ++ { ++ perror ("Error closing tmpfile"); ++ unlink(tmp_filename); ++ return 1; ++ } ++ ++ /* ++ * And finally rename the tmpfile with the new env over the old env, the ++ * linux kernel guarantees that this is atomic (from a syscall pov). ++ */ ++ ret = rename(tmp_filename, env_filename); ++ if (ret) ++ { ++ perror ("Error renaming tmpfile to " GRUBENV " failed"); ++ unlink(tmp_filename); ++ return 1; ++ } + + return 0; + } diff --git a/0188-blscfg-add-a-space-char-when-appending-fields-for-va.patch b/0188-blscfg-add-a-space-char-when-appending-fields-for-va.patch new file mode 100644 index 0000000..9f69238 --- /dev/null +++ b/0188-blscfg-add-a-space-char-when-appending-fields-for-va.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 26 Nov 2019 09:51:41 +0100 +Subject: [PATCH] blscfg: add a space char when appending fields for variable + expansion + +The GRUB variables are expanded and replaced by their values before adding +menu entries, but they didn't include space characters after the values so +the result was not correct. + +For the common case this wasn't a problem but it is if there are variables +that are part of the values of other variables. + +Resolves: rhbz#1669252 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 31 ++++++++++++++++++------------- + 1 file changed, 18 insertions(+), 13 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 471975fd2e5..d78cff79f97 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -593,26 +593,29 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) + + static char *field_append(bool is_var, char *buffer, char *start, char *end) + { +- char *temp = grub_strndup(start, end - start + 1); +- const char *field = temp; ++ char *tmp = grub_strndup(start, end - start + 1); ++ const char *field = tmp; ++ int term = is_var ? 2 : 1; + + if (is_var) { +- field = grub_env_get (temp); ++ field = grub_env_get (tmp); + if (!field) + return buffer; + } + +- if (!buffer) { +- buffer = grub_strdup(field); +- if (!buffer) +- return NULL; +- } else { +- buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field)); +- if (!buffer) +- return NULL; ++ if (!buffer) ++ buffer = grub_zalloc (grub_strlen(field) + term); ++ else ++ buffer = grub_realloc (buffer, grub_strlen(buffer) + grub_strlen(field) + term); + +- grub_stpcpy (buffer + grub_strlen(buffer), field); +- } ++ if (!buffer) ++ return NULL; ++ ++ tmp = buffer + grub_strlen(buffer); ++ tmp = grub_stpcpy (tmp, field); ++ ++ if (is_var) ++ tmp = grub_stpcpy (tmp, " "); + + return buffer; + } +@@ -642,6 +645,8 @@ static char *expand_val(char *value) + buffer = field_append(is_var, buffer, start, end); + is_var = false; + start = value; ++ if (*start == ' ') ++ start++; + } + } + diff --git a/0189-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch b/0189-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch new file mode 100644 index 0000000..54b73e6 --- /dev/null +++ b/0189-grub.d-Fix-boot_indeterminate-getting-set-on-boot_su.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 26 Nov 2019 09:51:41 +0100 +Subject: [PATCH] grub.d: Fix boot_indeterminate getting set on boot_success=0 + boot + +The "grub.d: Split out boot success reset from menu auto hide script" +not only moved the code to clear boot_success and boot_indeterminate +but for some reason also mixed in some broken changes to the +boot_indeterminate handling. + +The boot_indeterminate var is meant to suppress the boot menu after +a reboot from either a selinux-relabel or offline-updates. These +2 special boot scenarios do not set boot_success since there is no +successfull interaction with the user. Instead they increment +boot_indeterminate, and if it is 1 and only when it is 1, so the +first reboot after a "special" boot we suppress the menu. + +To ensure that we do show the menu if we somehow get stuck in a +"special" boot loop where we do special-boots without them +incrementing boot_indeterminate, the code before the +"grub.d: Split out boot success reset from menu auto hide script" +commit would increment boot_indeterminate once when it is 1, so that +even if the "special" boot reboot-loop immediately we would show the +menu on the next boot. + +That commit broke this however, because it not only moves the code, +it also changes it from only "incrementing" boot_indeterminate once to +always incrementing it, except when boot_success == 1 (and we reset it). + +This broken behavior causes the following problem: + +1. Boot a broken kernel, system hangs, power-cycle +2. boot_success now != 1, so we increment boot_indeterminate from 0 + (unset!) to 1. User either simply tries again, or makes some changes + but the end-result still is a system hang, power-cycle +3. Now boot_indeterminate==1 so we do not show the menu even though the + previous boot failed -> BAD + +This commit fixes this by restoring the behavior of setting +boot_indeterminate to 2 when it was 1 before. + +Fixes: "grub.d: Split out boot success reset from menu auto hide script" +Signed-off-by: Hans de Goede +--- + util/grub.d/10_reset_boot_success.in | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in +index 6c88d933dde..737e1ae5b68 100644 +--- a/util/grub.d/10_reset_boot_success.in ++++ b/util/grub.d/10_reset_boot_success.in +@@ -6,18 +6,18 @@ + # + # The boot_success var needs to be set to 1 from userspace to mark a boot successful. + cat << EOF +-insmod increment + # Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry + if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then + set menu_hide_ok=1 + else + set menu_hide_ok=0 + fi +-# Reset boot_indeterminate after a successful boot, increment otherwise ++# Reset boot_indeterminate after a successful boot + if [ "\${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +-else +- increment boot_indeterminate ++# Avoid boot_indeterminate causing the menu to be hidden more then once ++elif [ "\${boot_indeterminate}" = "1" ]; then ++ set boot_indeterminate=2 + fi + # Reset boot_success for current boot + set boot_success=0 diff --git a/0190-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch b/0190-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch new file mode 100644 index 0000000..2df15bf --- /dev/null +++ b/0190-blscfg-Add-support-for-sorting-the-plus-higher-than-.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 4 Nov 2019 17:33:30 +0100 +Subject: [PATCH] blscfg: Add support for sorting the plus ('+') higher than + base version + +Handle plus separator. Concept is the same as tilde, except that if one of +the strings ends (base version), the other is considered as higher version. + +A plus character is used for example by the Linux kernel build system to +denote that is the base version plus some changes on top of it. + +Currently for example rpmvercmp("5.3.0", "5.3.0+") will return 0 even when +the two versions are not the same. + +Resolves: rhbz#1767395 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 19 +++++++++++++++++-- + 1 file changed, 17 insertions(+), 2 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index d78cff79f97..83b33c1cd93 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -163,8 +163,8 @@ static int vercmp(const char * a, const char * b) + + /* loop through each version segment of str1 and str2 and compare them */ + while (*one || *two) { +- while (*one && !grub_isalnum(*one) && *one != '~') one++; +- while (*two && !grub_isalnum(*two) && *two != '~') two++; ++ while (*one && !grub_isalnum(*one) && *one != '~' && *one != '+') one++; ++ while (*two && !grub_isalnum(*two) && *two != '~' && *two != '+') two++; + + /* handle the tilde separator, it sorts before everything else */ + if (*one == '~' || *two == '~') { +@@ -175,6 +175,21 @@ static int vercmp(const char * a, const char * b) + continue; + } + ++ /* ++ * Handle plus separator. Concept is the same as tilde, ++ * except that if one of the strings ends (base version), ++ * the other is considered as higher version. ++ */ ++ if (*one == '+' || *two == '+') { ++ if (!*one) return -1; ++ if (!*two) return 1; ++ if (*one != '+') goto_return (1); ++ if (*two != '+') goto_return (-1); ++ one++; ++ two++; ++ continue; ++ } ++ + /* If we ran to the end of either, we are finished with the loop */ + if (!(*one && *two)) break; + diff --git a/0191-Fix-savedefault-with-blscfg.patch b/0191-Fix-savedefault-with-blscfg.patch new file mode 100644 index 0000000..51d5b82 --- /dev/null +++ b/0191-Fix-savedefault-with-blscfg.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fritz Elfert +Date: Mon, 13 Jan 2020 19:29:58 +0100 +Subject: [PATCH] Fix savedefault with blscfg + +The GRUB_SAVEDEFAULT option was ignored on a BLS configuration. Fix it by +making the menu entries populated from the BLS files to call savedefault +if a save_default environment variable has been set to "true". + +This variable is set by grub2-mkconfig to the value in GRUB_SAVEDEFAULT. +--- + grub-core/commands/blscfg.c | 5 ++++- + util/grub.d/10_linux.in | 4 ++++ + 2 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 83b33c1cd93..069db721bec 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -889,11 +889,14 @@ static void create_entry (struct bls_entry *entry) + + grub_dprintf ("blscfg2", "devicetree %s for id:\"%s\"\n", dt, id); + +- src = grub_xasprintf ("load_video\n" ++ const char *sdval = grub_env_get("save_default"); ++ bool savedefault = ((NULL != sdval) && (grub_strcmp(sdval, "true") == 0)); ++ src = grub_xasprintf ("%sload_video\n" + "set gfxpayload=keep\n" + "insmod gzio\n" + "linux %s%s%s%s\n" + "%s%s", ++ savedefault ? "savedefault\n" : "", + GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", + initrd ? initrd : "", dt ? dt : ""); + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 21a6915dca3..b70dca27567 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -152,6 +152,10 @@ EOF + if [ -n "${GRUB_DEFAULT_DTB}" ]; then + ${grub_editenv} - set devicetree="${GRUB_DEFAULT_DTB}" + fi ++ ++ if [ -n "${GRUB_SAVEDEFAULT}" ]; then ++ ${grub_editenv} - set save_default="${GRUB_SAVEDEFAULT}" ++ fi + fi + + exit 0 diff --git a/0192-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch b/0192-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch new file mode 100644 index 0000000..b694ec9 --- /dev/null +++ b/0192-Also-define-GRUB_EFI_MAX_ALLOCATION_ADDRESS-for-RISC.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: David Abdurachmanov +Date: Thu, 16 Jan 2020 13:10:10 +0100 +Subject: [PATCH] Also define GRUB_EFI_MAX_ALLOCATION_ADDRESS for RISC-V + +The commit "Try to pick better locations for kernel and initrd" missed to +define this macro for the RISC-V (riscv64) architecture, so add it there. + +Signed-off-by: David Abdurachmanov +--- + include/grub/riscv64/efi/memory.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h +index c6cb3241714..acb61dca44b 100644 +--- a/include/grub/riscv64/efi/memory.h ++++ b/include/grub/riscv64/efi/memory.h +@@ -2,5 +2,6 @@ + #include + + #define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL ++#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS + + #endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/0193-chainloader-Define-machine-types-for-RISC-V.patch b/0193-chainloader-Define-machine-types-for-RISC-V.patch new file mode 100644 index 0000000..2ec7100 --- /dev/null +++ b/0193-chainloader-Define-machine-types-for-RISC-V.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: David Abdurachmanov +Date: Sat, 9 Nov 2019 18:06:32 +0000 +Subject: [PATCH] chainloader: Define machine types for RISC-V + +The commit "Add secureboot support on efi chainloader" didn't add machine +types for RISC-V, so this patch adds them. + +Note, that grub-core/loader/riscv/linux.c is skipped because Linux is not +supported yet. This patch might need a new revision once that's the case. + +Signed-off-by: David Abdurachmanov +--- + grub-core/loader/efi/chainloader.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index f4ddbeda687..2c529f71471 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -316,6 +316,10 @@ static const grub_uint16_t machine_type __attribute__((__unused__)) = + GRUB_PE32_MACHINE_I386; + #elif defined(__ia64__) + GRUB_PE32_MACHINE_IA64; ++#elif defined(__riscv) && (__riscv_xlen == 32) ++ GRUB_PE32_MACHINE_RISCV32; ++#elif defined(__riscv) && (__riscv_xlen == 64) ++ GRUB_PE32_MACHINE_RISCV64; + #else + #error this architecture is not supported by grub2 + #endif diff --git a/0194-Add-start-symbol-for-RISC-V.patch b/0194-Add-start-symbol-for-RISC-V.patch new file mode 100644 index 0000000..677efae --- /dev/null +++ b/0194-Add-start-symbol-for-RISC-V.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: David Abdurachmanov +Date: Sat, 9 Nov 2019 19:51:57 +0000 +Subject: [PATCH] Add start symbol for RISC-V + +All other architectures have start symbol. + +Hopefully this resolves: + + BUILDSTDERR: ././grub-mkimage: error: undefined symbol start. + +Signed-off-by: David Abdurachmanov +--- + grub-core/kern/riscv/efi/startup.S | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/grub-core/kern/riscv/efi/startup.S b/grub-core/kern/riscv/efi/startup.S +index f2a7b2b1ede..781773136e8 100644 +--- a/grub-core/kern/riscv/efi/startup.S ++++ b/grub-core/kern/riscv/efi/startup.S +@@ -29,6 +29,7 @@ + + .file "startup.S" + .text ++FUNCTION(start) + FUNCTION(_start) + /* + * EFI_SYSTEM_TABLE and EFI_HANDLE are passed in a1/a0. diff --git a/0195-RISC-V-Add-__clzdi2-symbol.patch b/0195-RISC-V-Add-__clzdi2-symbol.patch new file mode 100644 index 0000000..492aaef --- /dev/null +++ b/0195-RISC-V-Add-__clzdi2-symbol.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Thu, 19 Sep 2019 09:39:04 +0200 +Subject: [PATCH] RISC-V: Add __clzdi2 symbol + +This is needed for the zstd module build for riscv64-emu. + +Signed-off-by: Andreas Schwab +Reviewed-by: Daniel Kiper +--- + configure.ac | 2 +- + include/grub/compiler-rt-emu.h | 5 +++++ + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 5076d635c57..eff160b6931 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1444,7 +1444,7 @@ fi + + # Check for libgcc symbols + if test x"$platform" = xemu; then +-AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) ++AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __clzdi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms) + fi + + if test "x$TARGET_APPLE_LINKER" = x1 ; then +diff --git a/include/grub/compiler-rt-emu.h b/include/grub/compiler-rt-emu.h +index b21425d9eb8..fde620ac186 100644 +--- a/include/grub/compiler-rt-emu.h ++++ b/include/grub/compiler-rt-emu.h +@@ -74,6 +74,11 @@ unsigned + EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); + #endif + ++#ifdef HAVE___CLZDI2 ++int ++EXPORT_FUNC (__clzdi2) (grub_uint64_t x); ++#endif ++ + #ifdef HAVE___AEABI_UIDIV + grub_uint32_t + EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b); diff --git a/0196-grub-install-Define-default-platform-for-RISC-V.patch b/0196-grub-install-Define-default-platform-for-RISC-V.patch new file mode 100644 index 0000000..962c080 --- /dev/null +++ b/0196-grub-install-Define-default-platform-for-RISC-V.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andreas Schwab +Date: Thu, 15 Aug 2019 16:55:13 +0200 +Subject: [PATCH] grub-install: Define default platform for RISC-V + +Signed-off-by: Andreas Schwab +Reviewed-by: Daniel Kiper +Reviewed-by: Alexander Graf +--- + util/grub-install.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/util/grub-install.c b/util/grub-install.c +index 37fcdac12cc..8b6a037903e 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -324,6 +324,14 @@ get_default_platform (void) + return "arm64-efi"; + #elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__) + return grub_install_get_default_x86_platform (); ++#elif defined (__riscv) ++#if __riscv_xlen == 32 ++ return "riscv32-efi"; ++#elif __riscv_xlen == 64 ++ return "riscv64-efi"; ++#else ++ return NULL; ++#endif + #else + return NULL; + #endif diff --git a/0197-blscfg-Always-use-the-root-variable-to-search-for-BL.patch b/0197-blscfg-Always-use-the-root-variable-to-search-for-BL.patch new file mode 100644 index 0000000..55efdaa --- /dev/null +++ b/0197-blscfg-Always-use-the-root-variable-to-search-for-BL.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 14 Jan 2020 17:41:29 +0100 +Subject: [PATCH] blscfg: Always use the root variable to search for BLS + snippets + +The boot and root variables are set by grub2-mkconfig to tell GRUB what +are the devices and partitions used as the EFI System Partition (ESP) +and to store the /boot directory (or used as the /boot mount point). + +But the boot variable is not needed anymore, this was added because the +blscfg module used to search for the BLS snippets in the ESP, but was +later changed to always search for the BLS files in /boot even for EFI. + +When doing that change, the logic was made backwards and so the boot +variable is wrongly used for legacy BIOS. This only works because this +is set to the same value as the root variable. + +So the correct thing to do is to always use the root variable to search +the BLS snippets, since that is set to the partition that stores them. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 069db721bec..24e35a40f24 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -1018,14 +1018,12 @@ bls_load_entries (const char *path) + if (!devid) { + #ifdef GRUB_MACHINE_EMU + devid = "host"; +-#elif defined(GRUB_MACHINE_EFI) ++#else + devid = grub_env_get ("root"); +-#else +- devid = grub_env_get ("boot"); + #endif + if (!devid) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, +- N_("variable `%s' isn't set"), "boot"); ++ N_("variable `%s' isn't set"), "root"); + } + + grub_dprintf ("blscfg", "opening %s\n", devid); diff --git a/0198-bootstrap.conf-Force-autogen.sh-to-use-python3.patch b/0198-bootstrap.conf-Force-autogen.sh-to-use-python3.patch new file mode 100644 index 0000000..d63a24e --- /dev/null +++ b/0198-bootstrap.conf-Force-autogen.sh-to-use-python3.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 15 Jan 2020 12:47:46 +0100 +Subject: [PATCH] bootstrap.conf: Force autogen.sh to use python3 + +The python-unversioned-command package is not installed in the buildroot, +but the bootstrap script expects the python command to be present if one +is not defined. So building the package leads to the following error: + +./autogen.sh: line 20: python: command not found + +This is harmless since gnulib is included as a source anyways, because the +builders can't download. But still the issue should be fixed by forcing to +use python3 that's the default in Fedora now. + +Signed-off-by: Javier Martinez Canillas +--- + bootstrap.conf | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/bootstrap.conf b/bootstrap.conf +index 274c55a5568..5665c83351d 100644 +--- a/bootstrap.conf ++++ b/bootstrap.conf +@@ -84,7 +84,7 @@ cp -a INSTALL INSTALL.grub + + bootstrap_post_import_hook () { + set -e +- FROM_BOOTSTRAP=1 ./autogen.sh ++ PYTHON=python3 FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this + } + diff --git a/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch b/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch new file mode 100644 index 0000000..1f85760 --- /dev/null +++ b/0199-efi-http-Export-fw-http-_path-variables-to-make-them.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 5 Mar 2020 16:21:47 +0100 +Subject: [PATCH] efi/http: Export {fw,http}_path variables to make them global + +The fw_path environment variable is used by http_configure() function to +determine the HTTP path that should be used as prefix when using relative +HTTP paths. And this is stored in the http_path environment variable. + +Later, that variable is looked up by grub_efihttp_open() to generate the +complete path to be used in the HTTP request. + +But these variables are not exported, which means that are not global and +so are only found in the initial context. + +This can cause commands like configfile that create a new context to fail +because the fw_path and http_path variables will not be found. + +Resolves: rhbz#1616395 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/main.c | 1 + + grub-core/net/efi/http.c | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c +index dcf48726d54..9bf6a8b231a 100644 +--- a/grub-core/kern/main.c ++++ b/grub-core/kern/main.c +@@ -142,6 +142,7 @@ grub_set_prefix_and_root (void) + if (fw_path) + { + grub_env_set ("fw_path", fw_path); ++ grub_env_export ("fw_path"); + grub_dprintf ("fw_path", "fw_path:\"%s\"\n", fw_path); + grub_free (fw_path); + } +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index de351b2cd03..755b7a6d054 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -39,6 +39,7 @@ http_configure (struct grub_efi_net_device *dev, int prefer_ip6) + http_path++; + grub_env_unset ("http_path"); + grub_env_set ("http_path", http_path); ++ grub_env_export ("http_path"); + } + } + diff --git a/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch b/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch new file mode 100644 index 0000000..c394549 --- /dev/null +++ b/0200-efi-http-Enclose-literal-IPv6-addresses-in-square-br.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 5 Mar 2020 16:21:58 +0100 +Subject: [PATCH] efi/http: Enclose literal IPv6 addresses in square brackets + +According to RFC 2732 (https://www.ietf.org/rfc/rfc2732.txt), literal IPv6 +addresses must be enclosed in square brackets. But GRUB currently does not +do this and is causing HTTP servers to send Bad Request (400) responses. + +For example, the following is the HTTP stream when fetching a config file: + +HEAD /EFI/BOOT/grub.cfg HTTP/1.1 +Host: 2000:dead:beef:a::1 +Accept: */* +User-Agent: UefiHttpBoot/1.0 + +HTTP/1.1 400 Bad Request +Date: Thu, 05 Mar 2020 14:46:02 GMT +Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d +Connection: close +Content-Type: text/html; charset=iso-8859-1 + +and after enclosing the IPv6 address the HTTP request is successful: + +HEAD /EFI/BOOT/grub.cfg HTTP/1.1 +Host: [2000:dead:beef:a::1] +Accept: */* +User-Agent: UefiHttpBoot/1.0 + +HTTP/1.1 200 OK +Date: Thu, 05 Mar 2020 14:48:04 GMT +Server: Apache/2.4.41 (Fedora) OpenSSL/1.1.1d +Last-Modified: Thu, 27 Feb 2020 17:45:58 GMT +ETag: "206-59f924b24b1da" +Accept-Ranges: bytes +Content-Length: 518 + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/http.c | 37 ++++++++++++++++++++++++++++--------- + 1 file changed, 28 insertions(+), 9 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index 755b7a6d054..fc8cb25ae0a 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -158,13 +158,7 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + grub_efi_status_t status; + grub_efi_boot_services_t *b = grub_efi_system_table->boot_services; + char *url = NULL; +- +- request_headers[0].field_name = (grub_efi_char8_t *)"Host"; +- request_headers[0].field_value = (grub_efi_char8_t *)server; +- request_headers[1].field_name = (grub_efi_char8_t *)"Accept"; +- request_headers[1].field_value = (grub_efi_char8_t *)"*/*"; +- request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent"; +- request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0"; ++ char *hostname = NULL; + + { + grub_efi_ipv6_address_t address; +@@ -174,9 +168,24 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + const char *protocol = (use_https == 1) ? "https" : "http"; + + if (grub_efi_string_to_ip6_address (server, &address, &rest) && *rest == 0) +- url = grub_xasprintf ("%s://[%s]%s", protocol, server, name); ++ { ++ hostname = grub_xasprintf ("[%s]", server); ++ if (!hostname) ++ return GRUB_ERR_OUT_OF_MEMORY; ++ ++ server = hostname; ++ ++ url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ if (!url) ++ { ++ grub_free (hostname); ++ return GRUB_ERR_OUT_OF_MEMORY; ++ } ++ } + else +- url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ { ++ url = grub_xasprintf ("%s://%s%s", protocol, server, name); ++ } + + if (!url) + { +@@ -199,6 +208,13 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + request_data.url = ucs2_url; + } + ++ request_headers[0].field_name = (grub_efi_char8_t *)"Host"; ++ request_headers[0].field_value = (grub_efi_char8_t *)server; ++ request_headers[1].field_name = (grub_efi_char8_t *)"Accept"; ++ request_headers[1].field_value = (grub_efi_char8_t *)"*/*"; ++ request_headers[2].field_name = (grub_efi_char8_t *)"User-Agent"; ++ request_headers[2].field_value = (grub_efi_char8_t *)"UefiHttpBoot/1.0"; ++ + request_data.method = (headeronly > 0) ? GRUB_EFI_HTTPMETHODHEAD : GRUB_EFI_HTTPMETHODGET; + + request_message.data.request = &request_data; +@@ -228,6 +244,9 @@ efihttp_request (grub_efi_http_t *http, char *server, char *name, int use_https, + + status = efi_call_2 (http->request, http, &request_token); + ++ if (hostname) ++ grub_free (hostname); ++ + if (status != GRUB_EFI_SUCCESS) + { + efi_call_1 (b->close_event, request_token.event); diff --git a/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch b/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch new file mode 100644 index 0000000..209aed8 --- /dev/null +++ b/0201-efi-net-Allow-to-specify-a-port-number-in-addresses.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 9 Mar 2020 15:29:45 +0100 +Subject: [PATCH] efi/net: Allow to specify a port number in addresses + +The grub_efi_net_parse_address() function is not covering the case where a +port number is specified in an IPv4 or IPv6 address, so will fail to parse +the network address. + +For most cases the issue is harmless, because the function is only used to +match an address with a network interface and if fails the default is used. + +But still is a bug that has to be fixed and it causes error messages to be +printed like the following: + +error: net/efi/net.c:782:unrecognised network address '192.168.122.1:8080' + +error: net/efi/net.c:781:unrecognised network address '[2000:dead:beef:a::1]:8080' + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/net.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 6603cd83edc..84573937b18 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -742,7 +742,7 @@ grub_efi_net_parse_address (const char *address, + return GRUB_ERR_NONE; + } + } +- else if (*rest == 0) ++ else if (*rest == 0 || *rest == ':') + { + grub_uint32_t subnet_mask = 0xffffffffU; + grub_memcpy (ip4->subnet_mask, &subnet_mask, sizeof (ip4->subnet_mask)); +@@ -768,7 +768,7 @@ grub_efi_net_parse_address (const char *address, + return GRUB_ERR_NONE; + } + } +- else if (*rest == 0) ++ else if (*rest == 0 || *rest == ':') + { + ip6->prefix_length = 128; + ip6->is_anycast = 0; diff --git a/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch b/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch new file mode 100644 index 0000000..f92dee4 --- /dev/null +++ b/0202-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 9 Mar 2020 15:30:05 +0100 +Subject: [PATCH] efi/ip4_config: Improve check to detect literal IPv6 + addresses + +The grub_efi_string_to_ip4_address() function wrongly assumes that an IPv6 +address is an IPv4 address, because it doesn't take into account the case +of a caller passing an IPv6 address as a string. + +This leads to the grub_efi_net_parse_address() function to fail and print +the following error message: + +error: net/efi/net.c:785:unrecognised network address '2000:dead:beef:a::1' + +Resolves: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/ip4_config.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index b711a5d9457..313c818b184 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -56,9 +56,20 @@ int + grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest) + { + grub_uint32_t newip = 0; +- int i; ++ int i, ncolon = 0; + const char *ptr = val; + ++ /* Check that is not an IPv6 address */ ++ for (i = 0; i < grub_strlen(ptr); i++) ++ { ++ if (ptr[i] == '[' && i == 0) ++ return 0; ++ ++ if (ptr[i] == ':') ++ if (i == 0 || ++ncolon == 2) ++ return 0; ++ } ++ + for (i = 0; i < 4; i++) + { + unsigned long t; diff --git a/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch b/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch new file mode 100644 index 0000000..33d8f88 --- /dev/null +++ b/0203-efi-net-Print-a-debug-message-if-parsing-the-address.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 10 Mar 2020 11:23:49 +0100 +Subject: [PATCH] efi/net: Print a debug message if parsing the address fails + +Currently if parsing the address fails an error message is printed. But in +most cases this isn't a fatal error since the grub_efi_net_parse_address() +function is only used to match an address with a network interface to use. + +And if this fails, the default interface is used which is good enough for +most cases. So instead of printing an error that would pollute the console +just print a debug message if the address is not parsed correctly. + +A user can enable debug messages for the efinet driver to have information +about the failure and the fact that the default interface is being used. + +Related: rhbz#1732765 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/efi/net.c | 18 +++++++++++------- + 1 file changed, 11 insertions(+), 7 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index 84573937b18..a3f0535d43c 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -778,9 +778,9 @@ grub_efi_net_parse_address (const char *address, + } + } + +- return grub_error (GRUB_ERR_NET_BAD_ADDRESS, +- N_("unrecognised network address `%s'"), +- address); ++ grub_dprintf ("efinet", "unrecognised network address '%s'\n", address); ++ ++ return GRUB_ERR_NET_BAD_ADDRESS; + } + + static grub_efi_net_interface_t * +@@ -795,10 +795,7 @@ match_route (const char *server) + err = grub_efi_net_parse_address (server, &ip4, &ip6, &is_ip6, 0); + + if (err) +- { +- grub_print_error (); + return NULL; +- } + + if (is_ip6) + { +@@ -1233,8 +1230,15 @@ grub_net_open_real (const char *name __attribute__ ((unused))) + /*FIXME: Use DNS translate name to address */ + net_interface = match_route (server); + ++ if (!net_interface && net_default_interface) ++ { ++ net_interface = net_default_interface; ++ grub_dprintf ("efinet", "interface lookup failed, using default '%s'\n", ++ net_interface->name); ++ } ++ + /*XXX: should we check device with default gateway ? */ +- if (!net_interface && !(net_interface = net_default_interface)) ++ if (!net_interface) + { + grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("disk `%s' no route found"), + name); diff --git a/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch b/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch new file mode 100644 index 0000000..fa35f65 --- /dev/null +++ b/0204-blscfg-return-NULL-instead-of-a-zero-length-array-in.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 16 Mar 2020 13:51:45 +0100 +Subject: [PATCH] blscfg: return NULL instead of a zero-length array in + bls_make_list() + +The bls_make_list() function returns a list of all the values for a given +key and if there is none a NULL pointer should be returned. But currently +is returnin a zero-length array instead. + +This makes the callers to wrongly assume that there are values for a key +and populate wrong menu entries. For example menu entries are populated +with an initrd command even if there is no initrd fiel in the BLS file. + +Resolves: rhbz#1806022 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 24e35a40f24..9263a5c1a02 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -600,6 +600,12 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) + list[nlist] = NULL; + } + ++ if (!nlist) ++ { ++ grub_free (list); ++ return NULL; ++ } ++ + if (num) + *num = nlist; + diff --git a/0205-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch b/0205-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch new file mode 100644 index 0000000..5993a6b --- /dev/null +++ b/0205-grub-switch-to-blscfg-Update-grub2-binary-in-ESP-for.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 26 Mar 2020 15:08:30 +0100 +Subject: [PATCH] grub-switch-to-blscfg: Update grub2 binary in ESP for OSTree + systems + +The grub2 EFI binary in the ESP isn't updated as a part of an OSTree update +transaction. So let's make the script to update this and also create a file +to indicate that the installed version has support for the blscfg module. + +Related: rhbz#1751272 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 49b3985fadb..a05a8d98554 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -266,6 +266,15 @@ copy_bls() { + fi + } + ++# The grub2 EFI binary is not copied to the ESP as a part of an ostree ++# transaction. Make sure a grub2 version with BLS support is installed. ++if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars/; then ++ grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" ++ cp ${grub_binary} ${grubdir} || exit 1 ++ # Create a hidden file to indicate that grub2 now has BLS support. ++ touch /boot/grub2/.grub2-blscfg-supported ++fi ++ + GENERATE=0 + if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ + | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then diff --git a/0206-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch b/0206-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch new file mode 100644 index 0000000..27ef6e0 --- /dev/null +++ b/0206-grub-switch-to-blscfg-Only-mark-GRUB-as-BLS-supporte.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 2 Apr 2020 11:07:24 +0200 +Subject: [PATCH] grub-switch-to-blscfg: Only mark GRUB as BLS supported if + blsdir isn't set + +If the user set the blsdir environemnt variable to a path that is not the +default where ostree writes the BLS snippets, the blscfg module won't be +able to parse them and can lead to not having any menu entries on boot. + +So to minimize the risk of things going wrong when dropping the 15_ostree +script used by ostree to create the menu entries, only mark the bootloader +as BLS supported if the blsdir variable has not been set. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index a05a8d98554..4bbed8e4fe9 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -267,8 +267,11 @@ copy_bls() { + } + + # The grub2 EFI binary is not copied to the ESP as a part of an ostree +-# transaction. Make sure a grub2 version with BLS support is installed. +-if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars/; then ++# transaction. Make sure a grub2 version with BLS support is installed ++# but only do this if the blsdir is not set, to make sure that the BLS ++# parsing module will search for the BLS snippets in the default path. ++if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ ++ ! ${grub_editenv} - list | grep -q blsdir; then + grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" + cp ${grub_binary} ${grubdir} || exit 1 + # Create a hidden file to indicate that grub2 now has BLS support. diff --git a/0207-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch b/0207-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch new file mode 100644 index 0000000..cd4be69 --- /dev/null +++ b/0207-10_linux.in-Merge-logic-from-10_linux_bls-and-drop-t.patch @@ -0,0 +1,662 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 31 Mar 2020 12:35:42 +0200 +Subject: [PATCH] 10_linux.in: Merge logic from 10_linux_bls and drop that + script + +There's a 10_linux_bls snippet that's used in ppc64le machines to generate +a set of menuentry commands by parsing BLS configs in /boot/loader/entries. + +This was made because on PowerNV ppc64le machines that boot using the OPAL +firmware, there could be an old version of the Petitboot bootloader that +doesn't have support to parse BLS snippets. + +But there is no need to have a separate GRUB script for that and the logic +could just be part of the usual 10_linux snippet. + +Also the BLS files could be used directly if the bootloader has support to +parse them, which is the case for GRUB that's used in ppc64le OF or if the +Petitboot used in ppc64le OPAL machines is version 1.8.0 or newer. + +So only generate the menuentry commands from the BLS snippets in the case +of OPAL machines with an old Petitboot version. + +Signed-off-by: Javier Martinez Canillas +--- + Makefile.util.def | 7 - + util/grub.d/10_linux.in | 97 ++++++++- + util/grub.d/10_linux_bls.in | 470 -------------------------------------------- + 3 files changed, 96 insertions(+), 478 deletions(-) + delete mode 100644 util/grub.d/10_linux_bls.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index 1fa92caad4d..f3a699691bf 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -517,13 +517,6 @@ script = { + condition = COND_HOST_LINUX; + }; + +-script = { +- name = '10_linux_bls'; +- common = util/grub.d/10_linux_bls.in; +- installdir = grubconf; +- condition = COND_HOST_LINUX; +-}; +- + script = { + name = '10_reset_boot_success'; + common = util/grub.d/10_reset_boot_success.in; +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index b70dca27567..c72cc3246bb 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -84,18 +84,86 @@ esac + + populate_header_warn() + { ++if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then ++ bls_parser="10_linux script" ++else ++ bls_parser="blscfg command" ++fi + cat <&2 ++ ++ files=($(for bls in ${blsdir}/*.conf ; do ++ if ! [[ -e "${bls}" ]] ; then ++ continue ++ fi ++ bls="${bls%.conf}" ++ bls="${bls##*/}" ++ echo "${bls}" ++ done | ${kernel_sort} | tac)) || : ++ ++ for bls in "${files[@]}" ; do ++ read_config "${blsdir}/${bls}.conf" ++ ++ menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" ++ menu="${menu}\t linux ${linux} ${options}\n" ++ if [ -n "${initrd}" ] ; then ++ menu="${menu}\t initrd ${boot_prefix}${initrd}\n" ++ fi ++ menu="${menu}}\n\n" ++ done ++ # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation ++ printf "$menu" ++} ++ + if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then +@@ -115,6 +183,26 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + prepare_grub_to_access_device_with_variable boot ${boot_device} + fi + ++ arch="$(uname -m)" ++ if [ "x${arch}" = "xppc64le" ] && [ -d /sys/firmware/opal ]; then ++ ++ petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" ++ ++ if test -e ${petitboot_path}; then ++ read -a petitboot_version < ${petitboot_path} ++ petitboot_version="$(echo ${petitboot_version//v})" ++ major_version="$(echo ${petitboot_version} | cut -d . -f1)" ++ minor_version="$(echo ${petitboot_version} | cut -d . -f2)" ++ ++ if test -z ${petitboot_version} || test ${major_version} -lt 1 || \ ++ test ${major_version} -eq 1 -a ${minor_version} -lt 8; then ++ BLS_POPULATE_MENU="true" ++ fi ++ else ++ BLS_POPULATE_MENU="true" ++ fi ++ fi ++ + populate_header_warn + + cat << EOF +@@ -129,10 +217,17 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + if [ -z "\${kernelopts}" ]; then + set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + fi ++EOF ++ ++ if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then ++ populate_menu ++ else ++ cat << EOF + + insmod blscfg + blscfg + EOF ++ fi + + if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then + blsdir="/boot/loader/entries" +diff --git a/util/grub.d/10_linux_bls.in b/util/grub.d/10_linux_bls.in +deleted file mode 100644 +index 68fbedf2129..00000000000 +--- a/util/grub.d/10_linux_bls.in ++++ /dev/null +@@ -1,470 +0,0 @@ +-#! /bin/sh +-set -e +- +-# grub-mkconfig helper script. +-# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. +-# +-# GRUB is free software: you can redistribute it and/or modify +-# it under the terms of the GNU General Public License as published by +-# the Free Software Foundation, either version 3 of the License, or +-# (at your option) any later version. +-# +-# GRUB is distributed in the hope that it will be useful, +-# but WITHOUT ANY WARRANTY; without even the implied warranty of +-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-# GNU General Public License for more details. +-# +-# You should have received a copy of the GNU General Public License +-# along with GRUB. If not, see . +- +-prefix="@prefix@" +-exec_prefix="@exec_prefix@" +-datarootdir="@datarootdir@" +- +-. "$pkgdatadir/grub-mkconfig_lib" +- +-export TEXTDOMAIN=@PACKAGE@ +-export TEXTDOMAINDIR="@localedir@" +- +-CLASS="--class gnu-linux --class gnu --class os --unrestricted" +- +-if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then +- OS="$(eval $(grep PRETTY_NAME /etc/os-release) ; echo ${PRETTY_NAME})" +- CLASS="--class $(eval $(grep '^ID_LIKE=\|^ID=' /etc/os-release) ; [ -n "${ID_LIKE}" ] && echo ${ID_LIKE} || echo ${ID}) ${CLASS}" +-else +- OS="${GRUB_DISTRIBUTOR}" +- CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" +-fi +- +-# loop-AES arranges things so that /dev/loop/X can be our root device, but +-# the initrds that Linux uses don't like that. +-case ${GRUB_DEVICE} in +- /dev/loop/*|/dev/loop[0-9]) +- GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` +- ;; +-esac +- +-# Default to disabling partition uuid support to maintian compatibility with +-# older kernels. +-GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true} +- +-# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter +-# and mounting btrfs requires user space scanning, so force UUID in this case. +-if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ +- || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ +- && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ +- || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ +- && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ +- || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then +- LINUX_ROOT_DEVICE=${GRUB_DEVICE} +-elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ +- || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then +- LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} +-else +- LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} +-fi +- +-case x"$GRUB_FS" in +- xbtrfs) +- if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then +- GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}" +- else +- rootsubvol="`make_system_path_relative_to_its_root /`" +- rootsubvol="${rootsubvol#/}" +- if [ "x${rootsubvol}" != x ]; then +- GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" +- fi +- fi;; +- xzfs) +- rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` +- bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" +- LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" +- ;; +-esac +- +-mktitle () +-{ +- local title_type +- local version +- local OS_NAME +- local OS_VERS +- +- title_type=$1 && shift +- version=$1 && shift +- +- OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" +- OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" +- +- case $title_type in +- recovery) +- title=$(printf '%s (%s) %s (recovery mode)' \ +- "${OS_NAME}" "${version}" "${OS_VERS}") +- ;; +- *) +- title=$(printf '%s (%s) %s' \ +- "${OS_NAME}" "${version}" "${OS_VERS}") +- ;; +- esac +- echo -n ${title} +-} +- +-title_correction_code= +- +-populate_header_warn() +-{ +-cat <&2 +- +- files=($(for bls in ${blsdir}/*.conf ; do +- if ! [[ -e "${bls}" ]] ; then +- continue +- fi +- bls="${bls%.conf}" +- bls="${bls##*/}" +- echo "${bls}" +- done | ${kernel_sort} | tac)) || : +- +- for bls in "${files[@]}" ; do +- read_config "${blsdir}/${bls}.conf" +- +- menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" +- menu="${menu}\t linux ${linux} ${options}\n" +- if [ -n "${initrd}" ] ; then +- menu="${menu}\t initrd ${boot_prefix}${initrd}\n" +- fi +- menu="${menu}}\n\n" +- done +- # The printf command seems to be more reliable across shells for special character (\n, \t) evaluation +- printf "$menu" +-} +- +-linux_entry () +-{ +- os="$1" +- version="$2" +- type="$3" +- isdebug="$4" +- args="$5" +- +- if [ -z "$boot_device_id" ]; then +- boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" +- fi +- +- if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then +- if [ x$dirname = x/ ]; then +- if [ -z "${prepare_root_cache}" ]; then +- prepare_grub_to_access_device ${GRUB_DEVICE} +- fi +- else +- if [ -z "${prepare_boot_cache}" ]; then +- prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} +- fi +- fi +- +- if [ -d /sys/firmware/efi ]; then +- bootefi_device="`${grub_probe} --target=device /boot/efi/`" +- prepare_grub_to_access_device_with_variable boot ${bootefi_device} +- else +- boot_device="`${grub_probe} --target=device /boot/`" +- prepare_grub_to_access_device_with_variable boot ${boot_device} +- fi +- +- populate_header_warn +- populate_menu +- +- if [ "x${GRUB_GRUBENV_UPDATE}" = "xyes" ]; then +- blsdir="/boot/loader/entries" +- [ -d "${blsdir}" ] && GRUB_BLS_FS="$(${grub_probe} --target=fs ${blsdir})" +- if [ "x${GRUB_BLS_FS}" = "xbtrfs" ] || [ "x${GRUB_BLS_FS}" = "xzfs" ]; then +- blsdir=$(make_system_path_relative_to_its_root "${blsdir}") +- if [ "x${blsdir}" != "x/loader/entries" ] && [ "x${blsdir}" != "x/boot/loader/entries" ]; then +- ${grub_editenv} - set blsdir="${blsdir}" +- fi +- fi +- +- ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" +- if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then +- ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" +- fi +- fi +- +- exit 0 +- fi +- +- if [ x$type != xsimple ] ; then +- title=$(mktitle "$type" "$version") +- if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then +- replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" +- quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" +- title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" +- fi +- if [ x$isdebug = xdebug ]; then +- title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}" +- fi +- echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" +- else +- echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" +- fi +- if [ x$type != xrecovery ] ; then +- save_default_entry | grub_add_tab +- fi +- +- # Use ELILO's generic "efifb" when it's known to be available. +- # FIXME: We need an interface to select vesafb in case efifb can't be used. +- if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then +- echo " load_video" | sed "s/^/$submenu_indentation/" +- if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ +- && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then +- echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" +- fi +- else +- if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then +- echo " load_video" | sed "s/^/$submenu_indentation/" +- fi +- echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" +- fi +- +- echo " insmod gzio" | sed "s/^/$submenu_indentation/" +- +- if [ x$dirname = x/ ]; then +- if [ -z "${prepare_root_cache}" ]; then +- prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" +- fi +- printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" +- else +- if [ -z "${prepare_boot_cache}" ]; then +- prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" +- fi +- printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" +- fi +- sed "s/^/$submenu_indentation/" << EOF +- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} +-EOF +- if test -n "${initrd}" ; then +- initrd_path= +- for i in ${initrd}; do +- initrd_path="${initrd_path} ${rel_dirname}/${i}" +- done +- sed "s/^/$submenu_indentation/" << EOF +- initrd $(echo $initrd_path) +-EOF +- fi +- if test -n "${fdt}" ; then +- sed "s/^/$submenu_indentation/" << EOF +- devicetree ${rel_dirname}/${fdt} +-EOF +- fi +- sed "s/^/$submenu_indentation/" << EOF +-} +-EOF +-} +- +-machine=`uname -m` +-case "x$machine" in +- xi?86 | xx86_64) +- list= +- for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do +- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi +- done ;; +- *) +- list= +- for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do +- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi +- done ;; +-esac +- +-if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then +- for i in /boot/ostree/*/vmlinuz-* ; do +- if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi +- done +-fi +- +-case "$machine" in +- i?86) GENKERNEL_ARCH="x86" ;; +- mips|mips64) GENKERNEL_ARCH="mips" ;; +- mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; +- arm*) GENKERNEL_ARCH="arm" ;; +- *) GENKERNEL_ARCH="$machine" ;; +-esac +- +-prepare_boot_cache= +-prepare_root_cache= +-boot_device_id= +-title_correction_code= +- +-# Extra indentation to add to menu entries in a submenu. We're not in a submenu +-# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). +-submenu_indentation="" +- +-is_top_level=true +-while [ "x$list" != "x" ] ; do +- linux=`version_find_latest $list` +- if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then +- gettext_printf "Found linux image: %s\n" "$linux" >&2 +- fi +- +- basename=`basename $linux` +- dirname=`dirname $linux` +- rel_dirname=`make_system_path_relative_to_its_root $dirname` +- version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` +- alt_version=`echo $version | sed -e "s,\.old$,,g"` +- linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" +- +- initrd_early= +- for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ +- ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do +- if test -e "${dirname}/${i}" ; then +- initrd_early="${initrd_early} ${i}" +- fi +- done +- +- initrd_real= +- for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ +- "initrd-${version}" "initramfs-${version}.img" \ +- "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ +- "initrd-${alt_version}" "initramfs-${alt_version}.img" \ +- "initramfs-genkernel-${version}" \ +- "initramfs-genkernel-${alt_version}" \ +- "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ +- "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do +- if test -e "${dirname}/${i}" ; then +- initrd_real="${i}" +- break +- fi +- done +- +- initrd= +- if test -n "${initrd_early}" || test -n "${initrd_real}"; then +- initrd="${initrd_early} ${initrd_real}" +- +- initrd_display= +- for i in ${initrd}; do +- initrd_display="${initrd_display} ${dirname}/${i}" +- done +- if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then +- gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 +- fi +- fi +- +- fdt= +- for i in "dtb-${version}" "dtb-${alt_version}"; do +- if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then +- fdt="${i}/${GRUB_DEFAULT_DTB}" +- break +- fi +- done +- +- config= +- for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do +- if test -e "${i}" ; then +- config="${i}" +- break +- fi +- done +- +- initramfs= +- if test -n "${config}" ; then +- initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` +- fi +- +- if test -z "${initramfs}" && test -z "${initrd_real}" ; then +- # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's +- # no initrd or builtin initramfs, it can't work here. +- if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ +- || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then +- +- linux_root_device_thisversion=${GRUB_DEVICE} +- else +- linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} +- fi +- fi +- +- if [ "x${GRUB_DISABLE_SUBMENU}" = "xyes" ] || [ "x${GRUB_DISABLE_SUBMENU}" = "xy" ]; then +- GRUB_DISABLE_SUBMENU="true" +- fi +- +- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then +- linux_entry "${OS}" "${version}" simple standard \ +- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" +- if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then +- linux_entry "${OS}" "${version}" simple debug \ +- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" +- fi +- +- submenu_indentation="$grub_tab" +- +- if [ -z "$boot_device_id" ]; then +- boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" +- fi +- # TRANSLATORS: %s is replaced with an OS name +- echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" +- is_top_level=false +- fi +- +- linux_entry "${OS}" "${version}" advanced standard \ +- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" +- if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then +- linux_entry "${OS}" "${version}" advanced debug \ +- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}" +- fi +- +- if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then +- linux_entry "${OS}" "${version}" recovery standard \ +- "single ${GRUB_CMDLINE_LINUX}" +- fi +- +- list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` +-done +- +-# If at least one kernel was found, then we need to +-# add a closing '}' for the submenu command. +-if [ x"$is_top_level" != xtrue ]; then +- echo '}' +-fi +- +-echo "$title_correction_code" diff --git a/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch b/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch new file mode 100644 index 0000000..c131a7f --- /dev/null +++ b/0208-grub-switch-to-blscfg-Use-install-to-copy-GRUB-binar.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 16 Apr 2020 18:53:03 +0200 +Subject: [PATCH] grub-switch-to-blscfg: Use install to copy GRUB binary, + modules and config + +By default the cp command truncates the destination before copying from the +source, so if interrupted it can lead to a file that's half written. + +This behavior can be modified using the --remove-destination option, but is +usually a better choice to use the install tool for this. So let's do that. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 4bbed8e4fe9..3333a620c28 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -273,7 +273,7 @@ copy_bls() { + if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ + ! ${grub_editenv} - list | grep -q blsdir; then + grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" +- cp ${grub_binary} ${grubdir} || exit 1 ++ install -m 700 ${grub_binary} ${grubdir} || exit 1 + # Create a hidden file to indicate that grub2 now has BLS support. + touch /boot/grub2/.grub2-blscfg-supported + fi +@@ -307,13 +307,13 @@ if [ "${GENERATE}" -eq 1 ] ; then + + if [ -n "${mod_dir}" ]; then + for mod in blscfg increment; do +- cp ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 ++ install -m 700 ${prefix}/lib/grub/${mod_dir}/${mod}.mod ${grubdir}/$mod_dir/ || exit 1 + done + fi + + cp -af "${GRUB_CONFIG_FILE}" "${GRUB_CONFIG_FILE}${backupsuffix}" + if ! grub2-mkconfig -o "${GRUB_CONFIG_FILE}" ; then +- cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" ++ install -m 700 "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" + sed -i"${backupsuffix}" \ + -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ + "${etcdefaultgrub}" diff --git a/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch b/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch new file mode 100644 index 0000000..99c26dd --- /dev/null +++ b/0209-10_linux.in-Enable-BLS-configuration-if-new-kernel-p.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 16 Apr 2020 18:53:05 +0200 +Subject: [PATCH] 10_linux.in: Enable BLS configuration if new-kernel-pkg isn't + present + +Currently if the the GRUB_ENABLE_BLSCFG option in /etc/default/grub hasn't +been set, the 10_linux script will generate a GRUB configuration that does +not include the blscfg command to populate the menu entries from BLS files. + +But on kernel install the /usr/lib/kernel/install.d/20-grub.install script +will only add menuentry commands to the GRUB config file if the old grubby +tool and new-kernel-pkg script are installed. + +So a configuration with the GRUB_ENABLE_BLSCFG option will lead to a setup +where new kernel entries are not added. Make a BLS config the default if +that option wasn't set and the new-kernel-pkg script is not present. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index c72cc3246bb..847646bd8a8 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -164,6 +164,11 @@ populate_menu() + printf "$menu" + } + ++# Make BLS the default if GRUB_ENABLE_BLSCFG was not set and grubby is not installed. ++if [ -z "${GRUB_ENABLE_BLSCFG}" ] && [ -z "$(which new-kernel-pkg 2> /dev/null)" ]; then ++ GRUB_ENABLE_BLSCFG="true" ++fi ++ + if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then diff --git a/0210-efi-Set-image-base-address-before-jumping-to-the-PE-.patch b/0210-efi-Set-image-base-address-before-jumping-to-the-PE-.patch new file mode 100644 index 0000000..3691587 --- /dev/null +++ b/0210-efi-Set-image-base-address-before-jumping-to-the-PE-.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 23 Apr 2020 15:06:46 +0200 +Subject: [PATCH] efi: Set image base address before jumping to the PE/COFF + entry point + +Upstream GRUB uses the EFI LoadImage() and StartImage() to boot the Linux +kernel. But our custom EFI loader that supports Secure Boot instead uses +the EFI handover protocol (for x86) or jumping directly to the PE/COFF +entry point (for aarch64). + +This is done to allow the bootloader to verify the images using the shim +lock protocol to avoid booting untrusted binaries. + +Since the bootloader loads the kernel from the boot media instead of using +LoadImage(), it is responsible to set the Loaded Image base address before +booting the kernel. + +Otherwise the kernel EFI stub will complain that it was not set correctly +and print the following warning message: + +EFI stub: ERROR: FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value + +Resolves: rhbz#1825411 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/loader/efi/linux.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index b56ea0bc041..e09f824862b 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -72,6 +72,7 @@ grub_err_t + grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, + void *kernel_params) + { ++ grub_efi_loaded_image_t *loaded_image = NULL; + handover_func hf; + int offset = 0; + +@@ -79,6 +80,17 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset, + offset = 512; + #endif + ++ /* ++ * Since the EFI loader is not calling the LoadImage() and StartImage() ++ * services for loading the kernel and booting respectively, it has to ++ * set the Loaded Image base address. ++ */ ++ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ if (loaded_image) ++ loaded_image->image_base = kernel_addr; ++ else ++ grub_dprintf ("linux", "Loaded Image base address could not be set\n"); ++ + grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n", + kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params); + hf = (handover_func)((char *)kernel_addr + handover_offset + offset); diff --git a/0211-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch b/0211-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch new file mode 100644 index 0000000..483efc4 --- /dev/null +++ b/0211-blscfg-Lookup-default_kernelopts-variable-as-fallbac.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 29 Apr 2020 20:08:27 +0200 +Subject: [PATCH] blscfg: Lookup default_kernelopts variable as fallback for + options + +The 10_linux script sets a variable that contains the kernel command line +parameters. This is done so the entries will still have a kernel cmdline +defined even if the grubenv can't be read. + +But older versions of the script used to set a default_kernelopts variable +while newer versions just sets the kernelopts, which is what's defined in +the BLS snippets. + +The blscfg module needs to keep looking for the default_kernelops since it +may be that a user doesn't have a grubenv file and has an older grub.cfg +that sets this variable instead of kernelopts. + +Related: rhbz#1765297 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 9263a5c1a02..4ec6504d9a4 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -759,6 +759,10 @@ static void create_entry (struct bls_entry *entry) + + title = bls_get_val (entry, "title", NULL); + options = expand_val (bls_get_val (entry, "options", NULL)); ++ ++ if (!options) ++ options = expand_val (grub_env_get("default_kernelopts")); ++ + initrds = bls_make_list (entry, "initrd", NULL); + + devicetree = expand_val (bls_get_val (entry, "devicetree", NULL)); diff --git a/0212-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch b/0212-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch new file mode 100644 index 0000000..75eb75a --- /dev/null +++ b/0212-10_linux.in-fix-early-exit-due-error-when-reading-pe.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 30 Apr 2020 15:45:31 +0200 +Subject: [PATCH] 10_linux.in: fix early exit due error when reading petitboot + version + +The script uses bash's read built-in command to get the petitboot version +version, but this command has a non-zero exit status if the EOF is found. + +Since the /sys/firmware/devicetree/base/ibm,firmware-versions/petitboot +string ends with a NUL character, use the empty string as read delimiter +to prevent the command to read to the end-of-file and exit with an error. + +Resolves: rhbz#1827397 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 847646bd8a8..09adfce80fd 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -194,7 +194,7 @@ if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then + petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" + + if test -e ${petitboot_path}; then +- read -a petitboot_version < ${petitboot_path} ++ read -r -d '' petitboot_version < ${petitboot_path} + petitboot_version="$(echo ${petitboot_version//v})" + major_version="$(echo ${petitboot_version} | cut -d . -f1)" + minor_version="$(echo ${petitboot_version} | cut -d . -f2)" diff --git a/0213-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch b/0213-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch new file mode 100644 index 0000000..09d378f --- /dev/null +++ b/0213-envblk-Fix-buffer-overrun-when-attempting-to-shrink-.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 12 May 2020 01:00:51 +0200 +Subject: [PATCH] envblk: Fix buffer overrun when attempting to shrink a + variable value +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +If an existing variable is set with a value whose length is smaller than +the current value, a memory corruption can happen due copying padding '#' +characters outside of the environment block buffer. + +This is caused by a wrong calculation of the previous free space position +after moving backward the characters that followed the old variable value. + +That position is calculated to fill the remaining of the buffer with the +padding '#' characters. But since isn't calculated correctly, it can lead +to copies outside of the buffer. + +The issue can be reproduced by creating a variable with a large value and +then try to set a new value that is much smaller: + +$ grub2-editenv --version +grub2-editenv (GRUB) 2.04 + +$ grub2-editenv env create + +$ grub2-editenv env set a="$(for i in {1..500}; do var="b$var"; done; echo $var)" + +$ wc -c env +1024 grubenv + +$ grub2-editenv env set a="$(for i in {1..50}; do var="b$var"; done; echo $var)" +malloc(): corrupted top size +Aborted (core dumped) + +$ wc -c env +0 grubenv + +Reported-by: Renaud Métrich +Signed-off-by: Javier Martinez Canillas +Patch-cc: Daniel Kiper +--- + grub-core/lib/envblk.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c +index f89d86d4e8d..874506da169 100644 +--- a/grub-core/lib/envblk.c ++++ b/grub-core/lib/envblk.c +@@ -143,7 +143,7 @@ grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value) + /* Move the following characters backward, and fill the new + space with harmless characters. */ + grub_memmove (p + vl, p + len, pend - (p + len)); +- grub_memset (space + len - vl, '#', len - vl); ++ grub_memset (space - (len - vl), '#', len - vl); + } + else + /* Move the following characters forward. */ diff --git a/0214-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch b/0214-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch new file mode 100644 index 0000000..2b9b443 --- /dev/null +++ b/0214-10_linux.in-Store-cmdline-in-BLS-snippets-instead-of.patch @@ -0,0 +1,160 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 13 May 2020 19:40:10 +0200 +Subject: [PATCH] 10_linux.in: Store cmdline in BLS snippets instead of using a + variable + +The kernel cmdline was stored as a kernelopts variable in the grubenv file +and the BLS snippets used that. But this turned out to be fragile since the +grubenv file could be removed or get corrupted easily. + +To prevent the entries to not have a cmdline if the grubenv can't be read, +a fallback variable was set in the GRUB config file. But this still caused +issues since the config needs to be re-generated to change the parameters. + +Instead, let's store the cmdline in the BLS snippets. This will make the +configuration more robust, since it will work even without the grubenv +file and the BLS entries will contain all the information needed to boot. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 30 ++++++++++-------------------- + util/grub.d/10_linux.in | 41 +++++++++++++++++++++++++++++++---------- + 2 files changed, 41 insertions(+), 30 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 3333a620c28..cb229126128 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -190,7 +190,7 @@ fi + mkbls() { + local kernelver=$1 && shift + local datetime=$1 && shift +- local bootprefix=$1 && shift ++ local kernelopts=$1 && shift + + local debugname="" + local debugid="" +@@ -209,10 +209,9 @@ mkbls() { + cat <"${bls_target}" +- fi ++ mkbls "${kernelver}" \ ++ "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ ++ "${bootprefix}" "${cmdline}" >"${bls_target}" + + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then + bls_debug="$(echo ${bls_target} | sed -e "s/${kernelver}/${kernelver}~debug/")" + cp -aT "${bls_target}" "${bls_debug}" + title="$(grep '^title[ \t]' "${bls_debug}" | sed -e 's/^title[ \t]*//')" +- blsid="$(grep '^id[ \t]' "${bls_debug}" | sed -e "s/\.${ARCH}/-debug.${arch}/")" ++ options="$(echo "${cmdline} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')" + sed -i -e "s/^title.*/title ${title}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${bls_debug}" +- sed -i -e "s/^id.*/${blsid}/" "${bls_debug}" +- sed -i -e "s/^options.*/options \$kernelopts ${GRUB_CMDLINE_LINUX_DEBUG}/" "${bls_debug}" ++ sed -i -e "s/^options.*/options ${options}/" "${bls_debug}" + fi + done + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 09adfce80fd..80299ecaf00 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -134,23 +134,43 @@ read_config() + done < ${config_file} + } + +-populate_menu() ++blsdir="/boot/loader/entries" ++ ++get_sorted_bls() + { +- blsdir="/boot/loader/entries" +- local -a files + local IFS=$'\n' +- gettext_printf "Generating boot entries from BLS files...\n" >&2 + +- files=($(for bls in ${blsdir}/*.conf ; do +- if ! [[ -e "${bls}" ]] ; then +- continue +- fi ++ files=($(for bls in ${blsdir}/*.conf; do + bls="${bls%.conf}" + bls="${bls##*/}" + echo "${bls}" + done | ${kernel_sort} | tac)) || : + +- for bls in "${files[@]}" ; do ++ echo "${files[@]}" ++} ++ ++update_bls_cmdline() ++{ ++ local cmdline="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" ++ local -a files=($(get_sorted_bls)) ++ ++ for bls in "${files[@]}"; do ++ local options="${cmdline}" ++ if [ -z "${bls##*debug*}" ]; then ++ options="${options} ${GRUB_CMDLINE_LINUX_DEBUG}" ++ fi ++ options="$(echo "${options}" | sed -e 's/\//\\\//g')" ++ sed -i -e "s/^options.*/options ${options}/" "${blsdir}/${bls}.conf" ++ done ++} ++ ++populate_menu() ++{ ++ local -a files=($(get_sorted_bls)) ++ ++ gettext_printf "Generating boot entries from BLS files...\n" >&2 ++ ++ for bls in "${files[@]}"; do + read_config "${blsdir}/${bls}.conf" + + menu="${menu}menuentry '${title}' ${grub_arg} --id=${bls} {\n" +@@ -224,6 +244,8 @@ if [ -z "\${kernelopts}" ]; then + fi + EOF + ++ update_bls_cmdline ++ + if [ "x${BLS_POPULATE_MENU}" = "xtrue" ]; then + populate_menu + else +@@ -244,7 +266,6 @@ EOF + fi + fi + +- ${grub_editenv} - set kernelopts="root=${LINUX_ROOT_DEVICE} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + if [ -n "${GRUB_EARLY_INITRD_LINUX_CUSTOM}" ]; then + ${grub_editenv} - set early_initrd="${GRUB_EARLY_INITRD_LINUX_CUSTOM}" + fi diff --git a/0215-10_linux.in-restore-existence-check-in-get_sorted_bl.patch b/0215-10_linux.in-restore-existence-check-in-get_sorted_bl.patch new file mode 100644 index 0000000..4517745 --- /dev/null +++ b/0215-10_linux.in-restore-existence-check-in-get_sorted_bl.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Adam Williamson +Date: Thu, 14 May 2020 17:52:53 -0700 +Subject: [PATCH] 10_linux.in: restore existence check in `get_sorted_bls` + +This is necessary to handle `/boot/loader/entries` not existing +at all (or possibly existing but being empty - not sure about +that case). Without this check, this function gets pretty wacky +and winds up returning the contents of the current working +directory, which of course causes whatever called it to break. + +Resolves: rhbz#1836020 + +Signed-off-by: Adam Williamson +--- + util/grub.d/10_linux.in | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 80299ecaf00..519e2d9e616 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -141,6 +141,9 @@ get_sorted_bls() + local IFS=$'\n' + + files=($(for bls in ${blsdir}/*.conf; do ++ if ! [[ -e "${bls}" ]] ; then ++ continue ++ fi + bls="${bls%.conf}" + bls="${bls##*/}" + echo "${bls}" diff --git a/0216-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch b/0216-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch new file mode 100644 index 0000000..ca125c6 --- /dev/null +++ b/0216-tpm-Don-t-propagate-TPM-measurement-errors-to-the-ve.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Sat, 16 May 2020 11:33:18 +0200 +Subject: [PATCH] tpm: Don't propagate TPM measurement errors to the verifiers + layer + +Currently if the EFI firmware fails to do a TPM measurement for a file, +the error will be propagated to the verifiers framework and so opening +the file will not succeed. + +This mean that buggy firmwares will prevent the system to boot since the +loader won't be able to open any file. But failing to do TPM measurements +shouldn't be a fatal error and the system should still be able to boot. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/tpm.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/grub-core/commands/tpm.c b/grub-core/commands/tpm.c +index 1441c494d81..dbaeae46dfa 100644 +--- a/grub-core/commands/tpm.c ++++ b/grub-core/commands/tpm.c +@@ -49,7 +49,8 @@ grub_tpm_verify_init (grub_file_t io, + static grub_err_t + grub_tpm_verify_write (void *context, void *buf, grub_size_t size) + { +- return grub_tpm_measure (buf, size, GRUB_BINARY_PCR, context); ++ grub_tpm_measure (buf, size, GRUB_BINARY_PCR, context); ++ return GRUB_ERR_NONE; + } + + static grub_err_t +@@ -57,7 +58,6 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) + { + const char *prefix = NULL; + char *description; +- grub_err_t status; + + switch (type) + { +@@ -73,15 +73,15 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type) + } + description = grub_malloc (grub_strlen (str) + grub_strlen (prefix) + 1); + if (!description) +- return grub_errno; ++ return GRUB_ERR_NONE; + grub_memcpy (description, prefix, grub_strlen (prefix)); + grub_memcpy (description + grub_strlen (prefix), str, + grub_strlen (str) + 1); +- status = +- grub_tpm_measure ((unsigned char *) str, grub_strlen (str), +- GRUB_STRING_PCR, description); ++ ++ grub_tpm_measure ((unsigned char *) str, grub_strlen (str), GRUB_STRING_PCR, ++ description); + grub_free (description); +- return status; ++ return GRUB_ERR_NONE; + } + + struct grub_file_verifier grub_tpm_verifier = { diff --git a/0217-tpm-Enable-module-for-all-EFI-platforms.patch b/0217-tpm-Enable-module-for-all-EFI-platforms.patch new file mode 100644 index 0000000..f119785 --- /dev/null +++ b/0217-tpm-Enable-module-for-all-EFI-platforms.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 18 May 2020 12:56:27 +0200 +Subject: [PATCH] tpm: Enable module for all EFI platforms + +The tpm module is only enabled for x86_64, but there's nothing specific to +that architecture in the code and could be enabled for all EFI platforms. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/Makefile.core.def | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 661994686e6..b283c502b9c 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2512,7 +2512,7 @@ module = { + name = tpm; + common = commands/tpm.c; + efi = commands/efi/tpm.c; +- enable = x86_64_efi; ++ enable = efi; + }; + + module = { diff --git a/0218-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch b/0218-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch new file mode 100644 index 0000000..945efc2 --- /dev/null +++ b/0218-10_linux.in-Don-t-update-BLS-files-that-aren-t-manag.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 20 May 2020 12:23:27 +0200 +Subject: [PATCH] 10_linux.in: Don't update BLS files that aren't managed by + GRUB scripts + +The script is updating all BLS files present in the /boot/loader/entries +directory, but it should only update the BLS that belong to the machine. + +Otherwise if a user is sharing the same boot partition between different +operating systems, the grub2-mkconfig tool will wrongly update BLS files +that were created by a different OS. + +There are also cases where the BLS snippets are not managed by the GRUB +scripts at all, for example in OSTree based systems. So it's also wrong +to update the BLS snippets created by OSTree. + +Resolves: rhbz#1837783 + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 519e2d9e616..e61b6c94f11 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -138,16 +138,25 @@ blsdir="/boot/loader/entries" + + get_sorted_bls() + { ++ if ! [ -d "${blsdir}" ] || ! [ -e /etc/machine-id ]; then ++ return ++ fi ++ ++ read machine_id < /etc/machine-id ++ if [ -z "${machine_id}" ]; then ++ return ++ fi ++ + local IFS=$'\n' + +- files=($(for bls in ${blsdir}/*.conf; do ++ files=($(for bls in ${blsdir}/${machine_id}-*.conf; do + if ! [[ -e "${bls}" ]] ; then + continue + fi + bls="${bls%.conf}" + bls="${bls##*/}" + echo "${bls}" +- done | ${kernel_sort} | tac)) || : ++ done | ${kernel_sort} 2>/dev/null | tac)) || : + + echo "${files[@]}" + } diff --git a/0219-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch b/0219-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch new file mode 100644 index 0000000..fd68d09 --- /dev/null +++ b/0219-x86-efi-Reduce-maximum-bounce-buffer-size-to-16-MiB.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 26 May 2020 16:59:28 +0200 +Subject: [PATCH] x86-efi: Reduce maximum bounce buffer size to 16 MiB + +The EFI linux loader allocates a bounce buffer to copy the initrd since in +some machines doing DMA on addresses above 4GB is not possible during EFI. + +But the verifiers framework also allocates a buffer to copy the initrd in +its grub_file_open() handler. It does this since the data to verify has to +be passed as a single chunk to modules that use the verifiers framework. + +If the initrd image size is big there may not be enough memory in the heap +to allocate two buffers of that size. This causes an allocation failure in +the verifiers framework and leads to the initrd not being read. + +To prevent these allocation failures, let's reduce the maximum size of the +bounce buffer used in the EFI loader. Since the data read can be copied to +the actual initrd address in multilple chunks. + +Resolves: rhbz#1838633 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/loader/i386/efi/linux.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 50b7798d6e5..e5b2736b0ce 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -144,7 +144,7 @@ grub_linuxefi_unload (void) + return GRUB_ERR_NONE; + } + +-#define BOUNCE_BUFFER_MAX 0x10000000ull ++#define BOUNCE_BUFFER_MAX 0x1000000ull + + static grub_ssize_t + read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len) diff --git a/0220-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch b/0220-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch new file mode 100644 index 0000000..1c5e599 --- /dev/null +++ b/0220-http-Prepend-prefix-when-the-HTTP-path-is-relative-a.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 2 Jun 2020 13:25:01 +0200 +Subject: [PATCH] http: Prepend prefix when the HTTP path is relative as done + in efi/http + +There are two different HTTP drivers that can be used when requesting an +HTTP resource: the efi/http that uses the EFI_HTTP_PROTOCOL and the http +that uses GRUB's HTTP and TCP/IP implementation. + +The efi/http driver appends a prefix that is defined in the variable +http_path, but the http driver doesn't. + +So using this driver and attempting to fetch a resource using a relative +path fails. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/http.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index b52b558d631..598961afbb5 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -501,13 +502,20 @@ http_open (struct grub_file *file, const char *filename) + { + grub_err_t err; + struct http_data *data; ++ const char *http_path; + + data = grub_zalloc (sizeof (*data)); + if (!data) + return grub_errno; + file->size = GRUB_FILE_SIZE_UNKNOWN; + +- data->filename = grub_strdup (filename); ++ /* If path is relative, prepend http_path */ ++ http_path = grub_env_get ("http_path"); ++ if (http_path && filename[0] != '/') ++ data->filename = grub_xasprintf ("%s/%s", http_path, filename); ++ else ++ data->filename = grub_strdup (filename); ++ + if (!data->filename) + { + grub_free (data); diff --git a/0221-fix-build-with-rpm-4.16.patch b/0221-fix-build-with-rpm-4.16.patch new file mode 100644 index 0000000..2a2e389 --- /dev/null +++ b/0221-fix-build-with-rpm-4.16.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Thierry Vignaud +Date: Mon, 8 Jun 2020 06:50:21 +0200 +Subject: [PATCH] fix build with rpm-4.16 + +Signed-off-by: Thierry Vignaud +--- + configure.ac | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/configure.ac b/configure.ac +index eff160b6931..5d3316185da 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1887,6 +1887,15 @@ if test x"$rpm_sort_excuse" = x ; then + [Define to 1 if you have the rpm library.]) + fi + ++if test x"$LIBRPM" = x ; then ++ # Check for rpm library. ++ AC_CHECK_LIB([rpmio], [rpmvercmp], [], ++ [rpm_sort_excuse="rpmio missing rpmvercmp"]) ++ LIBRPM="-lrpmio"; ++ AC_DEFINE([HAVE_RPMIO], [1], ++ [Define to 1 if you have the rpm library.]) ++fi ++ + AC_SUBST([LIBRPM]) + + LIBGEOM= diff --git a/0222-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch b/0222-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch new file mode 100644 index 0000000..dbb24f2 --- /dev/null +++ b/0222-Only-mark-GRUB-as-BLS-supported-in-OSTree-systems-wi.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 18 Jun 2020 11:19:00 +0200 +Subject: [PATCH] Only mark GRUB as BLS supported in OSTree systems with a boot + partition + +The script grub2-switch-to-blscfg updates the grub2 EFI binary in OSTree +systems and marks that has BLS support, to indicate that's not necessary +to add menuentry commands since the BLS snippets can be used to populate +the GRUB boot menu. + +But OSTree doesn't support installations that don't have a boot partition, +the BLS snippets assume that there will be one so this has to be checked +and only mark the bootloader as supporting BLS in OSTree installations +that have /boot as a mountpoint. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index cb229126128..a851424beb2 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -261,7 +261,8 @@ copy_bls() { + # but only do this if the blsdir is not set, to make sure that the BLS + # parsing module will search for the BLS snippets in the default path. + if test -f /run/ostree-booted && test -d /sys/firmware/efi/efivars && \ +- ! ${grub_editenv} - list | grep -q blsdir; then ++ ! ${grub_editenv} - list | grep -q blsdir && \ ++ mountpoint -q /boot; then + grub_binary="$(find /usr/lib/ostree-boot/efi/EFI/${EFIDIR}/ -name grub*.efi)" + install -m 700 ${grub_binary} ${grubdir} || exit 1 + # Create a hidden file to indicate that grub2 now has BLS support. diff --git a/0223-Don-t-assume-that-boot-commands-will-only-return-on-.patch b/0223-Don-t-assume-that-boot-commands-will-only-return-on-.patch new file mode 100644 index 0000000..5dc6377 --- /dev/null +++ b/0223-Don-t-assume-that-boot-commands-will-only-return-on-.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 9 Apr 2019 13:12:40 +0200 +Subject: [PATCH] Don't assume that boot commands will only return on fail + +While it's true that for most loaders the boot command never returns, it +may be the case that it does. For example the GRUB emulator boot command +calls to systemctl kexec which in turn does an asynchonous call to kexec. + +So in this case GRUB will wrongly assume that the boot command fails and +print a "Failed to boot both default and fallback entries" even when the +kexec call later succeeds. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/normal/menu.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c +index 9ea1f411814..14ceb9bb060 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -302,7 +302,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; +- return; ++ return grub_errno; + } + + errs_before = grub_err_printed_errors; +@@ -315,7 +315,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot) + grub_env_context_open (); + menu = grub_zalloc (sizeof (*menu)); + if (! menu) +- return; ++ return grub_errno; + grub_env_set_menu (menu); + if (auto_boot) + grub_env_set ("timeout", "0"); diff --git a/0224-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch b/0224-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch new file mode 100644 index 0000000..02528b5 --- /dev/null +++ b/0224-Fix-a-missing-return-in-efi-export-env-and-efi-load-.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 16 Jan 2019 13:21:46 -0500 +Subject: [PATCH] Fix a missing return in efi-export-env and efi-load-env + commands + +Somewhere along the way this got mis-merged to include a return without +a value. Fix it up. + +Signed-off-by: Peter Jones +--- + grub-core/commands/efi/env.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/commands/efi/env.c b/grub-core/commands/efi/env.c +index a69079786aa..4838dac22e7 100644 +--- a/grub-core/commands/efi/env.c ++++ b/grub-core/commands/efi/env.c +@@ -149,6 +149,8 @@ grub_efi_load_env(grub_command_t cmd __attribute__ ((unused)), + + grub_envblk_iterate (envblk, NULL, set_var); + grub_free (envblk_s.buf); ++ ++ return GRUB_ERR_NONE; + } + + static grub_command_t export_cmd, loadenv_cmd; diff --git a/0225-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch b/0225-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch new file mode 100644 index 0000000..99b66f0 --- /dev/null +++ b/0225-yylex-Make-lexer-fatal-errors-actually-be-fatal.patch @@ -0,0 +1,67 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 15 Apr 2020 15:45:02 -0400 +Subject: [PATCH] yylex: Make lexer fatal errors actually be fatal + +When presented with a command that can't be tokenized to anything +smaller than YYLMAX characters, the parser calls YY_FATAL_ERROR(errmsg), +expecting that will stop further processing, as such: + + #define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + if ( yyleng >= YYLMAX ) \ + YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ + yy_flex_strncpy( yytext, yyg->yytext_ptr, yyleng + 1 , yyscanner); \ + yyg->yy_c_buf_p = yy_cp; + +The code flex generates expects that YY_FATAL_ERROR() will either return +for it or do some form of longjmp(), or handle the error in some way at +least, and so the strncpy() call isn't in an "else" clause, and thus if +YY_FATAL_ERROR() is *not* actually fatal, it does the call with the +questionable limit, and predictable results ensue. + +Unfortunately, our implementation of YY_FATAL_ERROR() is: + + #define YY_FATAL_ERROR(msg) \ + do { \ + grub_printf (_("fatal error: %s\n"), _(msg)); \ + } while (0) + +The same pattern exists in yyless(), and similar problems exist in users +of YY_INPUT(), several places in the main parsing loop, +yy_get_next_buffer(), yy_load_buffer_state(), yyensure_buffer_stack, +yy_scan_buffer(), etc. + +All of these callers expect YY_FATAL_ERROR() to actually be fatal, and +the things they do if it returns after calling it are wildly unsafe. + +Fixes: CVE-2020-10713 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: 926df817dc8 +--- + grub-core/script/yylex.l | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l +index 7b44c37b76f..b7203c82309 100644 +--- a/grub-core/script/yylex.l ++++ b/grub-core/script/yylex.l +@@ -37,11 +37,11 @@ + + /* + * As we don't have access to yyscanner, we cannot do much except to +- * print the fatal error. ++ * print the fatal error and exit. + */ + #define YY_FATAL_ERROR(msg) \ + do { \ +- grub_printf (_("fatal error: %s\n"), _(msg)); \ ++ grub_fatal (_("fatal error: %s\n"), _(msg));\ + } while (0) + + #define COPY(str, hint) \ diff --git a/0226-safemath-Add-some-arithmetic-primitives-that-check-f.patch b/0226-safemath-Add-some-arithmetic-primitives-that-check-f.patch new file mode 100644 index 0000000..2478686 --- /dev/null +++ b/0226-safemath-Add-some-arithmetic-primitives-that-check-f.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 10:58:42 -0400 +Subject: [PATCH] safemath: Add some arithmetic primitives that check for + overflow + +This adds a new header, include/grub/safemath.h, that includes easy to +use wrappers for __builtin_{add,sub,mul}_overflow() declared like: + + bool OP(a, b, res) + +where OP is grub_add, grub_sub or grub_mul. OP() returns true in the +case where the operation would overflow and res is not modified. +Otherwise, false is returned and the operation is executed. + +These arithmetic primitives require newer compiler versions. So, bump +these requirements in the INSTALL file too. + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: de1c315841a +--- + include/grub/compiler.h | 8 ++++++++ + include/grub/safemath.h | 37 +++++++++++++++++++++++++++++++++++++ + INSTALL | 22 ++-------------------- + 3 files changed, 47 insertions(+), 20 deletions(-) + create mode 100644 include/grub/safemath.h + +diff --git a/include/grub/compiler.h b/include/grub/compiler.h +index 9859ff4cc79..ebafec68957 100644 +--- a/include/grub/compiler.h ++++ b/include/grub/compiler.h +@@ -48,6 +48,14 @@ + # define WARN_UNUSED_RESULT + #endif + ++#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) ++# define CLANG_PREREQ(maj,min) \ ++ ((__clang_major__ > (maj)) || \ ++ (__clang_major__ == (maj) && __clang_minor__ >= (min))) ++#else ++# define CLANG_PREREQ(maj,min) 0 ++#endif ++ + #define UNUSED __attribute__((__unused__)) + + #endif /* ! GRUB_COMPILER_HEADER */ +diff --git a/include/grub/safemath.h b/include/grub/safemath.h +new file mode 100644 +index 00000000000..c17b89bba17 +--- /dev/null ++++ b/include/grub/safemath.h +@@ -0,0 +1,37 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2020 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ * ++ * Arithmetic operations that protect against overflow. ++ */ ++ ++#ifndef GRUB_SAFEMATH_H ++#define GRUB_SAFEMATH_H 1 ++ ++#include ++ ++/* These appear in gcc 5.1 and clang 3.8. */ ++#if GNUC_PREREQ(5, 1) || CLANG_PREREQ(3, 8) ++ ++#define grub_add(a, b, res) __builtin_add_overflow(a, b, res) ++#define grub_sub(a, b, res) __builtin_sub_overflow(a, b, res) ++#define grub_mul(a, b, res) __builtin_mul_overflow(a, b, res) ++ ++#else ++#error gcc 5.1 or newer or clang 3.8 or newer is required ++#endif ++ ++#endif /* GRUB_SAFEMATH_H */ +diff --git a/INSTALL b/INSTALL +index 8acb4090235..dcb9b7d7b7a 100644 +--- a/INSTALL ++++ b/INSTALL +@@ -11,27 +11,9 @@ GRUB depends on some software packages installed into your system. If + you don't have any of them, please obtain and install them before + configuring the GRUB. + +-* GCC 4.1.3 or later +- Note: older versions may work but support is limited +- +- Experimental support for clang 3.3 or later (results in much bigger binaries) ++* GCC 5.1.0 or later ++ Experimental support for clang 3.8.0 or later (results in much bigger binaries) + for i386, x86_64, arm (including thumb), arm64, mips(el), powerpc, sparc64 +- Note: clang 3.2 or later works for i386 and x86_64 targets but results in +- much bigger binaries. +- earlier versions not tested +- Note: clang 3.2 or later works for arm +- earlier versions not tested +- Note: clang on arm64 is not supported due to +- https://llvm.org/bugs/show_bug.cgi?id=26030 +- Note: clang 3.3 or later works for mips(el) +- earlier versions fail to generate .reginfo and hence gprel relocations +- fail. +- Note: clang 3.2 or later works for powerpc +- earlier versions not tested +- Note: clang 3.5 or later works for sparc64 +- earlier versions return "error: unable to interface with target machine" +- Note: clang has no support for ia64 and hence you can't compile GRUB +- for ia64 with clang + * GNU Make + * GNU Bison 2.3 or later + * GNU gettext 0.17 or later diff --git a/0227-calloc-Make-sure-we-always-have-an-overflow-checking.patch b/0227-calloc-Make-sure-we-always-have-an-overflow-checking.patch new file mode 100644 index 0000000..b44695b --- /dev/null +++ b/0227-calloc-Make-sure-we-always-have-an-overflow-checking.patch @@ -0,0 +1,240 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:15:29 -0400 +Subject: [PATCH] calloc: Make sure we always have an overflow-checking + calloc() available + +This tries to make sure that everywhere in this source tree, we always have +an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.) +available, and that they all safely check for overflow and return NULL when +it would occur. + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: 79e51ab7a9a +--- + grub-core/kern/emu/misc.c | 12 ++++++++++++ + grub-core/kern/emu/mm.c | 10 ++++++++++ + grub-core/kern/mm.c | 40 ++++++++++++++++++++++++++++++++++++++ + grub-core/lib/libgcrypt_wrap/mem.c | 11 +++++++++-- + grub-core/lib/posix_wrap/stdlib.h | 8 +++++++- + include/grub/emu/misc.h | 1 + + include/grub/mm.h | 6 ++++++ + 7 files changed, 85 insertions(+), 3 deletions(-) + +diff --git a/grub-core/kern/emu/misc.c b/grub-core/kern/emu/misc.c +index 7a8d9e62300..f08a1bb8415 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -86,6 +86,18 @@ grub_util_error (const char *fmt, ...) + grub_exit (1); + } + ++void * ++xcalloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *p; ++ ++ p = calloc (nmemb, size); ++ if (!p) ++ grub_util_error ("%s", _("out of memory")); ++ ++ return p; ++} ++ + void * + xmalloc (grub_size_t size) + { +diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c +index f262e95e388..145b01d3719 100644 +--- a/grub-core/kern/emu/mm.c ++++ b/grub-core/kern/emu/mm.c +@@ -25,6 +25,16 @@ + #include + #include + ++void * ++grub_calloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *ret; ++ ret = calloc (nmemb, size); ++ if (!ret) ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); ++ return ret; ++} ++ + void * + grub_malloc (grub_size_t size) + { +diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c +index 002cbfa4f3d..80d0720d005 100644 +--- a/grub-core/kern/mm.c ++++ b/grub-core/kern/mm.c +@@ -67,8 +67,10 @@ + #include + #include + #include ++#include + + #ifdef MM_DEBUG ++# undef grub_calloc + # undef grub_malloc + # undef grub_zalloc + # undef grub_realloc +@@ -375,6 +377,30 @@ grub_memalign (grub_size_t align, grub_size_t size) + return 0; + } + ++/* ++ * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on ++ * integer overflow. ++ */ ++void * ++grub_calloc (grub_size_t nmemb, grub_size_t size) ++{ ++ void *ret; ++ grub_size_t sz = 0; ++ ++ if (grub_mul (nmemb, size, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ ret = grub_memalign (0, sz); ++ if (!ret) ++ return NULL; ++ ++ grub_memset (ret, 0, sz); ++ return ret; ++} ++ + /* Allocate SIZE bytes and return the pointer. */ + void * + grub_malloc (grub_size_t size) +@@ -561,6 +587,20 @@ grub_mm_dump (unsigned lineno) + grub_printf ("\n"); + } + ++void * ++grub_debug_calloc (const char *file, int line, grub_size_t nmemb, grub_size_t size) ++{ ++ void *ptr; ++ ++ if (grub_mm_debug) ++ grub_printf ("%s:%d: calloc (0x%" PRIxGRUB_SIZE ", 0x%" PRIxGRUB_SIZE ") = ", ++ file, line, size); ++ ptr = grub_calloc (nmemb, size); ++ if (grub_mm_debug) ++ grub_printf ("%p\n", ptr); ++ return ptr; ++} ++ + void * + grub_debug_malloc (const char *file, int line, grub_size_t size) + { +diff --git a/grub-core/lib/libgcrypt_wrap/mem.c b/grub-core/lib/libgcrypt_wrap/mem.c +index beeb661a3c8..74c6eafe525 100644 +--- a/grub-core/lib/libgcrypt_wrap/mem.c ++++ b/grub-core/lib/libgcrypt_wrap/mem.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -36,7 +37,10 @@ void * + gcry_xcalloc (size_t n, size_t m) + { + void *ret; +- ret = grub_zalloc (n * m); ++ size_t sz; ++ if (grub_mul (n, m, &sz)) ++ grub_fatal ("gcry_xcalloc would overflow"); ++ ret = grub_zalloc (sz); + if (!ret) + grub_fatal ("gcry_xcalloc failed"); + return ret; +@@ -56,7 +60,10 @@ void * + gcry_xcalloc_secure (size_t n, size_t m) + { + void *ret; +- ret = grub_zalloc (n * m); ++ size_t sz; ++ if (grub_mul (n, m, &sz)) ++ grub_fatal ("gcry_xcalloc would overflow"); ++ ret = grub_zalloc (sz); + if (!ret) + grub_fatal ("gcry_xcalloc failed"); + return ret; +diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h +index 3b46f47ff50..7a8d385e973 100644 +--- a/grub-core/lib/posix_wrap/stdlib.h ++++ b/grub-core/lib/posix_wrap/stdlib.h +@@ -21,6 +21,7 @@ + + #include + #include ++#include + + static inline void + free (void *ptr) +@@ -37,7 +38,12 @@ malloc (grub_size_t size) + static inline void * + calloc (grub_size_t size, grub_size_t nelem) + { +- return grub_zalloc (size * nelem); ++ grub_size_t sz; ++ ++ if (grub_mul (size, nelem, &sz)) ++ return NULL; ++ ++ return grub_zalloc (sz); + } + + static inline void * +diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h +index 5ef4f79e689..01056954b96 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -47,6 +47,7 @@ grub_util_device_is_mapped (const char *dev); + #define GRUB_HOST_PRIuLONG_LONG "llu" + #define GRUB_HOST_PRIxLONG_LONG "llx" + ++void * EXPORT_FUNC(xcalloc) (grub_size_t nmemb, grub_size_t size) WARN_UNUSED_RESULT; + void * EXPORT_FUNC(xmalloc) (grub_size_t size) WARN_UNUSED_RESULT; + void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) WARN_UNUSED_RESULT; + char * EXPORT_FUNC(xstrdup) (const char *str) WARN_UNUSED_RESULT; +diff --git a/include/grub/mm.h b/include/grub/mm.h +index 28e2e53eb32..9c38dd3ca5d 100644 +--- a/include/grub/mm.h ++++ b/include/grub/mm.h +@@ -29,6 +29,7 @@ + #endif + + void grub_mm_init_region (void *addr, grub_size_t size); ++void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size); + void *EXPORT_FUNC(grub_malloc) (grub_size_t size); + void *EXPORT_FUNC(grub_zalloc) (grub_size_t size); + void EXPORT_FUNC(grub_free) (void *ptr); +@@ -48,6 +49,9 @@ extern int EXPORT_VAR(grub_mm_debug); + void grub_mm_dump_free (void); + void grub_mm_dump (unsigned lineno); + ++#define grub_calloc(nmemb, size) \ ++ grub_debug_calloc (GRUB_FILE, __LINE__, nmemb, size) ++ + #define grub_malloc(size) \ + grub_debug_malloc (GRUB_FILE, __LINE__, size) + +@@ -63,6 +67,8 @@ void grub_mm_dump (unsigned lineno); + #define grub_free(ptr) \ + grub_debug_free (GRUB_FILE, __LINE__, ptr) + ++void *EXPORT_FUNC(grub_debug_calloc) (const char *file, int line, ++ grub_size_t nmemb, grub_size_t size); + void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line, + grub_size_t size); + void *EXPORT_FUNC(grub_debug_zalloc) (const char *file, int line, diff --git a/0228-calloc-Use-calloc-at-most-places.patch b/0228-calloc-Use-calloc-at-most-places.patch new file mode 100644 index 0000000..6d42930 --- /dev/null +++ b/0228-calloc-Use-calloc-at-most-places.patch @@ -0,0 +1,1834 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:26:01 -0400 +Subject: [PATCH] calloc: Use calloc() at most places + +This modifies most of the places we do some form of: + + X = malloc(Y * Z); + +to use calloc(Y, Z) instead. + +Among other issues, this fixes: + - allocation of integer overflow in grub_png_decode_image_header() + reported by Chris Coulson, + - allocation of integer overflow in luks_recover_key() + reported by Chris Coulson, + - allocation of integer overflow in grub_lvm_detect() + reported by Chris Coulson. + +Fixes: CVE-2020-14308 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: 48eeedf1e4b +--- + grub-core/bus/usb/usbhub.c | 8 ++++---- + grub-core/commands/efi/lsefisystab.c | 3 ++- + grub-core/commands/legacycfg.c | 6 +++--- + grub-core/commands/menuentry.c | 2 +- + grub-core/commands/nativedisk.c | 2 +- + grub-core/commands/parttool.c | 12 +++++++++--- + grub-core/commands/regexp.c | 2 +- + grub-core/commands/search_wrap.c | 2 +- + grub-core/disk/diskfilter.c | 4 ++-- + grub-core/disk/ieee1275/ofdisk.c | 2 +- + grub-core/disk/ldm.c | 14 +++++++------- + grub-core/disk/luks.c | 2 +- + grub-core/disk/lvm.c | 8 ++++---- + grub-core/disk/xen/xendisk.c | 2 +- + grub-core/efiemu/loadcore.c | 2 +- + grub-core/efiemu/mm.c | 6 +++--- + grub-core/font/font.c | 3 +-- + grub-core/fs/affs.c | 6 +++--- + grub-core/fs/btrfs.c | 6 +++--- + grub-core/fs/hfs.c | 2 +- + grub-core/fs/hfsplus.c | 6 +++--- + grub-core/fs/iso9660.c | 2 +- + grub-core/fs/ntfs.c | 4 ++-- + grub-core/fs/sfs.c | 2 +- + grub-core/fs/tar.c | 2 +- + grub-core/fs/udf.c | 4 ++-- + grub-core/fs/zfs/zfs.c | 4 ++-- + grub-core/gfxmenu/gui_string_util.c | 2 +- + grub-core/gfxmenu/widget-box.c | 4 ++-- + grub-core/io/gzio.c | 2 +- + grub-core/kern/efi/efi.c | 6 +++--- + grub-core/kern/emu/hostdisk.c | 2 +- + grub-core/kern/fs.c | 2 +- + grub-core/kern/misc.c | 2 +- + grub-core/kern/parser.c | 2 +- + grub-core/kern/uboot/uboot.c | 2 +- + grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- + grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- + grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- + grub-core/lib/priority_queue.c | 2 +- + grub-core/lib/reed_solomon.c | 7 +++---- + grub-core/lib/relocator.c | 10 +++++----- + grub-core/lib/zstd/fse_decompress.c | 2 +- + grub-core/loader/arm/linux.c | 2 +- + grub-core/loader/efi/chainloader.c | 2 +- + grub-core/loader/i386/bsdXX.c | 2 +- + grub-core/loader/i386/xnu.c | 4 ++-- + grub-core/loader/macho.c | 2 +- + grub-core/loader/multiboot_elfxx.c | 2 +- + grub-core/loader/xnu.c | 2 +- + grub-core/mmap/mmap.c | 4 ++-- + grub-core/net/bootp.c | 2 +- + grub-core/net/dns.c | 10 +++++----- + grub-core/net/net.c | 4 ++-- + grub-core/normal/charset.c | 10 +++++----- + grub-core/normal/cmdline.c | 14 +++++++------- + grub-core/normal/menu_entry.c | 14 +++++++------- + grub-core/normal/menu_text.c | 4 ++-- + grub-core/normal/term.c | 4 ++-- + grub-core/osdep/linux/getroot.c | 6 +++--- + grub-core/osdep/unix/config.c | 2 +- + grub-core/osdep/windows/getroot.c | 2 +- + grub-core/osdep/windows/hostdisk.c | 4 ++-- + grub-core/osdep/windows/init.c | 2 +- + grub-core/osdep/windows/platform.c | 4 ++-- + grub-core/osdep/windows/relpath.c | 2 +- + grub-core/partmap/gpt.c | 2 +- + grub-core/partmap/msdos.c | 2 +- + grub-core/script/execute.c | 2 +- + grub-core/tests/fake_input.c | 2 +- + grub-core/tests/video_checksum.c | 6 +++--- + grub-core/video/capture.c | 2 +- + grub-core/video/emu/sdl.c | 2 +- + grub-core/video/i386/pc/vga.c | 2 +- + grub-core/video/readers/png.c | 2 +- + util/getroot.c | 2 +- + util/grub-file.c | 2 +- + util/grub-fstest.c | 4 ++-- + util/grub-install-common.c | 2 +- + util/grub-install.c | 4 ++-- + util/grub-mkimagexx.c | 6 ++---- + util/grub-mkrescue.c | 4 ++-- + util/grub-mkstandalone.c | 2 +- + util/grub-pe2elf.c | 12 +++++------- + util/grub-probe.c | 4 ++-- + include/grub/unicode.h | 4 ++-- + 86 files changed, 176 insertions(+), 175 deletions(-) + +diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c +index 34a7ff1b5f8..a06cce302d2 100644 +--- a/grub-core/bus/usb/usbhub.c ++++ b/grub-core/bus/usb/usbhub.c +@@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) + grub_usb_set_configuration (dev, 1); + + dev->nports = hubdesc.portcnt; +- dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); +- dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); ++ dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); ++ dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); + if (!dev->children || !dev->ports) + { + grub_free (dev->children); +@@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d + + /* Query the number of ports the root Hub has. */ + hub->nports = controller->dev->hubports (controller); +- hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); +- hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); ++ hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); ++ hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); + if (!hub->devices || !hub->ports) + { + grub_free (hub->devices); +diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c +index df103022188..cd81507f5d4 100644 +--- a/grub-core/commands/efi/lsefisystab.c ++++ b/grub-core/commands/efi/lsefisystab.c +@@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), + grub_printf ("Vendor: "); + + for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); +- vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); ++ /* Allocate extra 3 bytes to simplify math. */ ++ vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); + if (!vendor) + return grub_errno; + *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index 891eac5a33f..da5143d4360 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -315,7 +315,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), + if (argc < 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); + +- cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); ++ cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); + if (!cutargs) + return grub_errno; + cutargc = argc - 1; +@@ -437,7 +437,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), + { + char rbuf[3] = "-r"; + bsdargc = cutargc + 2; +- bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); ++ bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); + if (!bsdargs) + { + err = grub_errno; +@@ -560,7 +560,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), + "module"); + +- newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); ++ newargs = grub_calloc (argc + 1, sizeof (newargs[0])); + if (!newargs) + return grub_errno; + grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); +diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c +index 29736f5cd03..84edfc06b7f 100644 +--- a/grub-core/commands/menuentry.c ++++ b/grub-core/commands/menuentry.c +@@ -157,7 +157,7 @@ grub_normal_add_menu_entry (int argc, const char **args, + grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id); + + /* Save argc, args to pass as parameters to block arg later. */ +- menu_args = grub_malloc (sizeof (char*) * (argc + 1)); ++ menu_args = grub_calloc (argc + 1, sizeof (char *)); + if (! menu_args) + goto fail; + +diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c +index 699447d11ec..7c8f97f6ad5 100644 +--- a/grub-core/commands/nativedisk.c ++++ b/grub-core/commands/nativedisk.c +@@ -195,7 +195,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), + else + path_prefix = prefix; + +- mods = grub_malloc (argc * sizeof (mods[0])); ++ mods = grub_calloc (argc, sizeof (mods[0])); + if (!mods) + return grub_errno; + +diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c +index 22b46b18741..051e31320e9 100644 +--- a/grub-core/commands/parttool.c ++++ b/grub-core/commands/parttool.c +@@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name, + for (nargs = 0; args[nargs].name != 0; nargs++); + cur->nargs = nargs; + cur->args = (struct grub_parttool_argdesc *) +- grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); ++ grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); ++ if (!cur->args) ++ { ++ grub_free (cur); ++ curhandle--; ++ return -1; ++ } + grub_memcpy (cur->args, args, + (nargs + 1) * sizeof (struct grub_parttool_argdesc)); + +@@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), + return err; + } + +- parsed = (int *) grub_zalloc (argc * sizeof (int)); ++ parsed = (int *) grub_calloc (argc, sizeof (int)); + + for (i = 1; i < argc; i++) + if (! parsed[i]) +@@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), + } + ptool = cur; + pargs = (struct grub_parttool_args *) +- grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); ++ grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); + for (j = i; j < argc; j++) + if (! parsed[j]) + { +diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c +index 7c5c72fe460..612003f94c8 100644 +--- a/grub-core/commands/regexp.c ++++ b/grub-core/commands/regexp.c +@@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) + if (ret) + goto fail; + +- matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); ++ matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); + if (! matches) + goto fail; + +diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c +index d7fd26b9405..47fc8eb9966 100644 +--- a/grub-core/commands/search_wrap.c ++++ b/grub-core/commands/search_wrap.c +@@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) + for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) + nhints++; + +- hints = grub_malloc (sizeof (hints[0]) * nhints); ++ hints = grub_calloc (nhints, sizeof (hints[0])); + if (!hints) + return grub_errno; + j = 0; +diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c +index 3f264be77d1..88784dc440b 100644 +--- a/grub-core/disk/diskfilter.c ++++ b/grub-core/disk/diskfilter.c +@@ -1137,7 +1137,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, + array->lvs->segments->node_count = nmemb; + array->lvs->segments->raid_member_size = disk_size; + array->lvs->segments->nodes +- = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); ++ = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); + array->lvs->segments->stripe_size = stripe_size; + for (i = 0; i < nmemb; i++) + { +@@ -1230,7 +1230,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, + grub_partition_t p; + for (p = disk->partition; p; p = p->parent) + s++; +- pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); ++ pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); + s = 0; + for (p = disk->partition; p; p = p->parent) + pv->partmaps[s++] = xstrdup (p->partmap->name); +diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c +index f73257e66dc..03674cb477e 100644 +--- a/grub-core/disk/ieee1275/ofdisk.c ++++ b/grub-core/disk/ieee1275/ofdisk.c +@@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) + /* Power machines documentation specify 672 as maximum SAS disks in + one system. Using a slightly larger value to be safe. */ + table_size = 768; +- table = grub_malloc (table_size * sizeof (grub_uint64_t)); ++ table = grub_calloc (table_size, sizeof (grub_uint64_t)); + + if (!table) + { +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index 2a22d2d6c1c..e6323701ab3 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, + lv->segments->type = GRUB_DISKFILTER_MIRROR; + lv->segments->node_count = 0; + lv->segments->node_alloc = 8; +- lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) +- * lv->segments->node_alloc); ++ lv->segments->nodes = grub_calloc (lv->segments->node_alloc, ++ sizeof (*lv->segments->nodes)); + if (!lv->segments->nodes) + goto fail2; + ptr = vblk[i].dynamic; +@@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, + { + comp->segment_alloc = 8; + comp->segment_count = 0; +- comp->segments = grub_malloc (sizeof (*comp->segments) +- * comp->segment_alloc); ++ comp->segments = grub_calloc (comp->segment_alloc, ++ sizeof (*comp->segments)); + if (!comp->segments) + goto fail2; + } +@@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, + } + comp->segments->node_count = read_int (ptr + 1, *ptr); + comp->segments->node_alloc = comp->segments->node_count; +- comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) +- * comp->segments->node_alloc); ++ comp->segments->nodes = grub_calloc (comp->segments->node_alloc, ++ sizeof (*comp->segments->nodes)); + if (!lv->segments->nodes) + goto fail2; + } +@@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, + *nsectors = lv->size; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c +index 86c50c61217..18b3a8bb1d3 100644 +--- a/grub-core/disk/luks.c ++++ b/grub-core/disk/luks.c +@@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, + && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) + max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); + +- split_key = grub_malloc (keysize * max_stripes); ++ split_key = grub_calloc (keysize, max_stripes); + if (!split_key) + return grub_errno; + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 0cbd0dd1629..8e76d1ae121 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -174,7 +174,7 @@ grub_lvm_detect (grub_disk_t disk, + first one. */ + + /* Allocate buffer space for the circular worst-case scenario. */ +- metadatabuf = grub_malloc (2 * mda_size); ++ metadatabuf = grub_calloc (2, mda_size); + if (! metadatabuf) + goto fail; + +@@ -427,7 +427,7 @@ grub_lvm_detect (grub_disk_t disk, + #endif + goto lvs_fail; + } +- lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); ++ lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); + seg = lv->segments; + + for (i = 0; i < lv->segment_count; i++) +@@ -484,8 +484,8 @@ grub_lvm_detect (grub_disk_t disk, + if (seg->node_count != 1) + seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); + +- seg->nodes = grub_zalloc (sizeof (*stripe) +- * seg->node_count); ++ seg->nodes = grub_calloc (seg->node_count, ++ sizeof (*stripe)); + stripe = seg->nodes; + + p = grub_strstr (p, "stripes = ["); +diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c +index 48476cbbf96..d6612eebd75 100644 +--- a/grub-core/disk/xen/xendisk.c ++++ b/grub-core/disk/xen/xendisk.c +@@ -426,7 +426,7 @@ grub_xendisk_init (void) + if (!ctr) + return; + +- virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); ++ virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); + if (!virtdisks) + return; + if (grub_xenstore_dir ("device/vbd", fill, &ctr)) +diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c +index 44085ef818e..2b924623f51 100644 +--- a/grub-core/efiemu/loadcore.c ++++ b/grub-core/efiemu/loadcore.c +@@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) + + grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; + grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) +- grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); ++ grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); + + /* Relocators */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); +diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c +index 52a032f7b2e..9b8e0d0ad1a 100644 +--- a/grub-core/efiemu/mm.c ++++ b/grub-core/efiemu/mm.c +@@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void) + /* Initialize variables*/ + grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); + scanline_events = (struct grub_efiemu_mmap_scan *) +- grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); + + /* Number of chunks can't increase more than by factor of 2 */ + result = (grub_efi_memory_descriptor_t *) +- grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); + if (!result || !scanline_events) + { + grub_free (result); +@@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void) + + /* Preallocate mmap */ + efiemu_mmap = (grub_efi_memory_descriptor_t *) +- grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); ++ grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); + if (!efiemu_mmap) + { + grub_efiemu_unload (); +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 85a292557ac..8e118b315ce 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct + font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; + + /* Allocate the character index array. */ +- font->char_index = grub_malloc (font->num_chars +- * sizeof (struct char_index_entry)); ++ font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); + if (!font->char_index) + return 1; + font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); +diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c +index 6b6a2bc9135..220b3712f2a 100644 +--- a/grub-core/fs/affs.c ++++ b/grub-core/fs/affs.c +@@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) + return 0; + } + latin1[symlink_size] = 0; +- utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); + if (!utf8) + { + grub_free (latin1); +@@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, + return 1; + } + +- hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); ++ hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); + if (!hashtable) + return 1; + +@@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) + len = file.namelen; + if (len > sizeof (file.name)) + len = sizeof (file.name); +- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); + if (*label) + *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; + } +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index 9cd7f4bdf65..ba080fdc580 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -442,7 +442,7 @@ lower_bound (struct grub_btrfs_data *data, + { + desc->allocated = 16; + desc->depth = 0; +- desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); ++ desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); + if (!desc->data) + return grub_errno; + } +@@ -781,7 +781,7 @@ raid56_read_retry (struct grub_btrfs_data *data, + grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; + grub_uint64_t i, failed_devices; + +- buffers = grub_zalloc (sizeof(*buffers) * nstripes); ++ buffers = grub_calloc (nstripes, sizeof (*buffers)); + if (!buffers) + goto cleanup; + +@@ -2477,7 +2477,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), + *nsectors = 64 * 2 - 1; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c +index ac0a40990e0..3fe842b4d8b 100644 +--- a/grub-core/fs/hfs.c ++++ b/grub-core/fs/hfs.c +@@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label) + grub_size_t len = data->sblock.volname[0]; + if (len > sizeof (data->sblock.volname) - 1) + len = sizeof (data->sblock.volname) - 1; +- *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); ++ *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); + if (*label) + macroman_to_utf8 (*label, data->sblock.volname + 1, + len + 1, 0); +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index 54786bb1c6d..dae43becc97 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -720,7 +720,7 @@ list_nodes (void *record, void *hook_arg) + if (! filename) + return 0; + +- keyname = grub_malloc (grub_be_to_cpu16 (catkey->namelen) * sizeof (*keyname)); ++ keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); + if (!keyname) + { + grub_free (filename); +@@ -1007,7 +1007,7 @@ grub_hfsplus_label (grub_device_t device, char **label) + grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); + + label_len = grub_be_to_cpu16 (catkey->namelen); +- label_name = grub_malloc (label_len * sizeof (*label_name)); ++ label_name = grub_calloc (label_len, sizeof (*label_name)); + if (!label_name) + { + grub_free (node); +@@ -1029,7 +1029,7 @@ grub_hfsplus_label (grub_device_t device, char **label) + } + } + +- *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! *label) + { + grub_free (label_name); +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 49c0c632bf3..4f1b52a552a 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) + int i; + grub_uint16_t t[MAX_NAMELEN / 2 + 1]; + +- p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! p) + return NULL; + +diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c +index fc4e1f678d6..2f34f76da88 100644 +--- a/grub-core/fs/ntfs.c ++++ b/grub-core/fs/ntfs.c +@@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) + grub_uint16_t *tmp; + grub_size_t i; + +- buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); +- tmp = grub_malloc (len * sizeof (tmp[0])); ++ buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); ++ tmp = grub_calloc (len, sizeof (tmp[0])); + if (!buf || !tmp) + { + grub_free (buf); +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 50c1fe72f44..90f7fb37918 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + node->next_extent = node->block; + node->cache_size = 0; + +- node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); ++ node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); + if (!node->cache) + { + grub_errno = 0; +diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c +index 7d63e0c99c7..c551ed6b520 100644 +--- a/grub-core/fs/tar.c ++++ b/grub-core/fs/tar.c +@@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, + if (data->linkname_alloc < linksize + 1) + { + char *n; +- n = grub_malloc (2 * (linksize + 1)); ++ n = grub_calloc (2, linksize + 1); + if (!n) + return grub_errno; + grub_free (data->linkname); +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index dc8b6e2d1c9..a83761674ad 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + { + unsigned i; + utf16len = sz - 1; +- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); ++ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) +@@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + { + unsigned i; + utf16len = (sz - 1) / 2; +- utf16 = grub_malloc (utf16len * sizeof (utf16[0])); ++ utf16 = grub_calloc (utf16len, sizeof (utf16[0])); + if (!utf16) + return NULL; + for (i = 0; i < utf16len; i++) +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 2f72e42bf80..381dde556d1 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, + } + subvol->nkeys = 0; + zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); +- subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); ++ subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); + if (!subvol->keyring) + { + grub_free (fsname); +@@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), + *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c +index a9a415e3129..ba1e1eab319 100644 +--- a/grub-core/gfxmenu/gui_string_util.c ++++ b/grub-core/gfxmenu/gui_string_util.c +@@ -55,7 +55,7 @@ canonicalize_path (const char *path) + if (*p == '/') + components++; + +- char **path_array = grub_malloc (components * sizeof (*path_array)); ++ char **path_array = grub_calloc (components, sizeof (*path_array)); + if (! path_array) + return 0; + +diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c +index b6060288914..470597ded2b 100644 +--- a/grub-core/gfxmenu/widget-box.c ++++ b/grub-core/gfxmenu/widget-box.c +@@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, + box->content_height = 0; + box->raw_pixmaps = + (struct grub_video_bitmap **) +- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); ++ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + box->scaled_pixmaps = + (struct grub_video_bitmap **) +- grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); ++ grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); + + /* Initialize all pixmap pointers to NULL so that proper destruction can + be performed if an error is encountered partway through construction. */ +diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c +index 6208a976363..43d98a7bdf4 100644 +--- a/grub-core/io/gzio.c ++++ b/grub-core/io/gzio.c +@@ -554,7 +554,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ + z = 1 << j; /* table entries for j-bit table */ + + /* allocate and link in new table */ +- q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); ++ q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); + if (! q) + { + if (h) +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 279394d85eb..ab133fecce0 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -207,7 +207,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, + + len = grub_strlen (var); + len16 = len * GRUB_MAX_UTF16_PER_UTF8; +- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); ++ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + if (!var16) + return grub_errno; + len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); +@@ -245,7 +245,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, + + len = grub_strlen (var); + len16 = len * GRUB_MAX_UTF16_PER_UTF8; +- var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); ++ var16 = grub_calloc (len16 + 1, sizeof (var16[0])); + if (!var16) + return NULL; + len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); +@@ -401,7 +401,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + while (len > 0 && fp->path_name[len - 1] == 0) + len--; + +- dup_name = grub_malloc (len * sizeof (*dup_name)); ++ dup_name = grub_calloc (len, sizeof (*dup_name)); + if (!dup_name) + { + grub_free (name); +diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c +index e9ec680cdbb..d975265b2e0 100644 +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -615,7 +615,7 @@ static char * + grub_util_path_concat_real (size_t n, int ext, va_list ap) + { + size_t totlen = 0; +- char **l = xmalloc ((n + ext) * sizeof (l[0])); ++ char **l = xcalloc (n + ext, sizeof (l[0])); + char *r, *p, *pi; + size_t i; + int first = 1; +diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c +index 88d39360da0..fb30da9f404 100644 +--- a/grub-core/kern/fs.c ++++ b/grub-core/kern/fs.c +@@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) + while (p); + + /* Allocate a block list. */ +- blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); ++ blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); + if (! blocks) + return 0; + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 87afb43cd55..dc5e10b651a 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -750,7 +750,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, + args->ptr = args->prealloc; + else + { +- args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); ++ args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); + if (!args->ptr) + { + grub_errno = GRUB_ERR_NONE; +diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c +index 78175aac2d3..619db3122a0 100644 +--- a/grub-core/kern/parser.c ++++ b/grub-core/kern/parser.c +@@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, + return grub_errno; + grub_memcpy (args, buffer, bp - buffer); + +- *argv = grub_malloc (sizeof (char *) * (*argc + 1)); ++ *argv = grub_calloc (*argc + 1, sizeof (char *)); + if (!*argv) + { + grub_free (args); +diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c +index be4816fe6f5..aac8f9ae1fd 100644 +--- a/grub-core/kern/uboot/uboot.c ++++ b/grub-core/kern/uboot/uboot.c +@@ -133,7 +133,7 @@ grub_uboot_dev_enum (void) + return num_devices; + + max_devices = 2; +- enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); ++ enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); + if (!enum_devices) + return 0; + +diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c +index f5e946a2d8f..63f6fcd11ef 100644 +--- a/grub-core/lib/libgcrypt/cipher/ac.c ++++ b/grub-core/lib/libgcrypt/cipher/ac.c +@@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, + gcry_mpi_t mpi; + char *label; + +- data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); ++ data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); + if (! data_mpis_new) + { + err = gcry_error_from_errno (errno); +@@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, + } + + /* Add MPI list. */ +- arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); ++ arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +@@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, + /* We build a list of arguments to pass to + gcry_sexp_build_array(). */ + data_length = _gcry_ac_data_length (data); +- arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); ++ arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +@@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, + arg_list_n += 2; + + /* Allocate list. */ +- arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); ++ arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); + if (! arg_list) + { + err = gcry_error_from_errno (errno); +diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c +index 2788e349fa9..b12e79b1922 100644 +--- a/grub-core/lib/libgcrypt/cipher/primegen.c ++++ b/grub-core/lib/libgcrypt/cipher/primegen.c +@@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, + } + + /* Allocate an array to track pool usage. */ +- pool_in_use = gcry_malloc (n * sizeof *pool_in_use); ++ pool_in_use = gcry_calloc (n, sizeof *pool_in_use); + if (!pool_in_use) + { + err = gpg_err_code_from_errno (errno); +@@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, + if (nbits < 16) + log_fatal ("can't generate a prime with less than %d bits\n", 16); + +- mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); ++ mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); + /* Make nbits fit into gcry_mpi_t implementation. */ + val_2 = mpi_alloc_set_ui( 2 ); + val_3 = mpi_alloc_set_ui( 3); +diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c +index 910982141e0..ca087ad75b9 100644 +--- a/grub-core/lib/libgcrypt/cipher/pubkey.c ++++ b/grub-core/lib/libgcrypt/cipher/pubkey.c +@@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) + * array to a format string, so we have to do it this way :-(. */ + /* FIXME: There is now such a format specifier, so we can + change the code to be more clear. */ +- arg_list = malloc (nelem * sizeof *arg_list); ++ arg_list = calloc (nelem, sizeof *arg_list); + if (!arg_list) + { + rc = gpg_err_code_from_syserror (); +@@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) + } + strcpy (p, "))"); + +- arg_list = malloc (nelem * sizeof *arg_list); ++ arg_list = calloc (nelem, sizeof *arg_list); + if (!arg_list) + { + rc = gpg_err_code_from_syserror (); +diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c +index 659be0b7f40..7d5e7c05aab 100644 +--- a/grub-core/lib/priority_queue.c ++++ b/grub-core/lib/priority_queue.c +@@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, + { + struct grub_priority_queue *ret; + void *els; +- els = grub_malloc (elsize * 8); ++ els = grub_calloc (8, elsize); + if (!els) + return 0; + ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); +diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c +index 19c20085279..79037c093f7 100644 +--- a/grub-core/lib/reed_solomon.c ++++ b/grub-core/lib/reed_solomon.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#define xcalloc calloc + #define xmalloc malloc + #define grub_memset memset + #define grub_memcpy memcpy +@@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) + gf_single_t *rs_polynomial; + unsigned int i, j; + gf_single_t *m; +- m = xmalloc ((s + rs) * sizeof (gf_single_t)); ++ m = xcalloc (s + rs, sizeof (gf_single_t)); + grub_memcpy (m, data, s * sizeof (gf_single_t)); +- grub_memset (m + s, 0, rs * sizeof (gf_single_t)); +- rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); +- grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); ++ rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); + rs_polynomial[rs] = 1; + /* Multiply with X - a^r */ + for (j = 0; j < rs; j++) +diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c +index ea3ebc719b1..5847aac3643 100644 +--- a/grub-core/lib/relocator.c ++++ b/grub-core/lib/relocator.c +@@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, + } + #endif + +- eventt = grub_malloc (maxevents * sizeof (events[0])); ++ eventt = grub_calloc (maxevents, sizeof (events[0])); + counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); +- events = grub_malloc (maxevents * sizeof (events[0])); ++ events = grub_calloc (maxevents, sizeof (events[0])); + if (!events || !eventt || !counter) + { + grub_dprintf ("relocator", "events or counter allocation failed %d\n", +@@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel, + #endif + unsigned cural = 0; + int oom = 0; +- res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); ++ res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); + if (!res->subchunks) + oom = 1; + res->nsubchunks = nallocs; +@@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, + count[(chunk->src & 0xff) + 1]++; + } + } +- from = grub_malloc (nchunks * sizeof (sorted[0])); +- to = grub_malloc (nchunks * sizeof (sorted[0])); ++ from = grub_calloc (nchunks, sizeof (sorted[0])); ++ to = grub_calloc (nchunks, sizeof (sorted[0])); + if (!from || !to) + { + grub_free (from); +diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c +index 72bbead5bee..2227b84bc7e 100644 +--- a/grub-core/lib/zstd/fse_decompress.c ++++ b/grub-core/lib/zstd/fse_decompress.c +@@ -82,7 +82,7 @@ + FSE_DTable* FSE_createDTable (unsigned tableLog) + { + if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; +- return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) ); ++ return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); + } + + void FSE_freeDTable (FSE_DTable* dt) +diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c +index 51684914cfc..d70c174868e 100644 +--- a/grub-core/loader/arm/linux.c ++++ b/grub-core/loader/arm/linux.c +@@ -78,7 +78,7 @@ linux_prepare_atag (void *target_atag) + + /* some place for cmdline, initrd and terminator. */ + tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; +- tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); ++ tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); + if (!tmp_atag) + return grub_errno; + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 2c529f71471..736505173cb 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -125,7 +125,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; + fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; + +- path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); ++ path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) + return; + +diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c +index af6741d157c..a8d8bf7daed 100644 +--- a/grub-core/loader/i386/bsdXX.c ++++ b/grub-core/loader/i386/bsdXX.c +@@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) + if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) + return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); + +- *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); ++ *shdr = grub_calloc (e->e_shnum, e->e_shentsize); + if (! *shdr) + return grub_errno; + +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index e64ed08f580..b7d176b5d30 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d + return grub_errno; + + len = grub_strlen (name); +- utf16 = grub_malloc (sizeof (grub_uint16_t) * len); ++ utf16 = grub_calloc (len, sizeof (grub_uint16_t)); + if (!utf16) + { + grub_free (utf8); +@@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * + grub_uint16_t *utf16; + grub_err_t err; + +- utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); ++ utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); + if (!utf16) + return grub_errno; + grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); +diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c +index 085f9c6890a..05710c48e06 100644 +--- a/grub-core/loader/macho.c ++++ b/grub-core/loader/macho.c +@@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) + if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) + == (grub_off_t) -1) + goto fail; +- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); ++ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + if (!archs) + goto fail; + if (grub_file_read (macho->file, archs, +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index 70cd1db513e..cc6853692a8 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + { + grub_uint8_t *shdr, *shdrptr; + +- shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); ++ shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); + if (!shdr) + return grub_errno; + +diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c +index e0f47e72b06..2f0ebd0b8bf 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -801,7 +801,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), + if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) + { + narchs = grub_be_to_cpu32 (head.nfat_arch); +- archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); ++ archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); + if (! archs) + { + grub_file_close (file); +diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c +index b569cb23b5a..64684c23d0d 100644 +--- a/grub-core/mmap/mmap.c ++++ b/grub-core/mmap/mmap.c +@@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) + + /* Initialize variables. */ + ctx.scanline_events = (struct grub_mmap_scan *) +- grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); ++ grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); + +- present = grub_zalloc (sizeof (present[0]) * current_priority); ++ present = grub_calloc (current_priority, sizeof (present[0])); + + if (! ctx.scanline_events || !present) + { +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 2e46842e829..5a5ebbfb1aa 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -1629,7 +1629,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + if (ncards == 0) + return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); + +- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); ++ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); + if (!ifaces) + return grub_errno; + +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index 5d9afe093c0..e332d5eb4a4 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), + ptr++; + ptr += 4; + } +- *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) +- * grub_be_to_cpu16 (head->ancount)); ++ *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), ++ sizeof ((*data->addresses)[0])); + if (!*data->addresses) + { + grub_errno = GRUB_ERR_NONE; +@@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), + dns_cache[h].addresses = 0; + dns_cache[h].name = grub_strdup (data->oname); + dns_cache[h].naddresses = *data->naddresses; +- dns_cache[h].addresses = grub_malloc (*data->naddresses +- * sizeof (dns_cache[h].addresses[0])); ++ dns_cache[h].addresses = grub_calloc (*data->naddresses, ++ sizeof (dns_cache[h].addresses[0])); + dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; + if (!dns_cache[h].addresses || !dns_cache[h].name) + { +@@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, + } + } + +- sockets = grub_malloc (sizeof (sockets[0]) * n_servers); ++ sockets = grub_calloc (n_servers, sizeof (sockets[0])); + if (!sockets) + return grub_errno; + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 15073dde1c4..ad024c9ef7a 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -338,8 +338,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), + ncards++; + } + +- ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); +- slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); ++ ifaces = grub_calloc (ncards, sizeof (ifaces[0])); ++ slaacs = grub_calloc (ncards, sizeof (slaacs[0])); + if (!ifaces || !slaacs) + { + grub_free (ifaces); +diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c +index b0ab47d73fd..d57fb72faa8 100644 +--- a/grub-core/normal/charset.c ++++ b/grub-core/normal/charset.c +@@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, + { + grub_size_t msg_len = grub_strlen (msg); + +- *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + if (!*unicode_msg) + return -1; +@@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + } + else + { +- n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); ++ n = grub_calloc (out->ncomb + 1, sizeof (n[0])); + if (!n) + { + grub_errno = GRUB_ERR_NONE; +@@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, + } \ + } + +- visual = grub_malloc (sizeof (visual[0]) * logical_len); ++ visual = grub_calloc (logical_len, sizeof (visual[0])); + if (!visual) + return -1; + +@@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, + { + const grub_uint32_t *line_start = logical, *ptr; + struct grub_unicode_glyph *visual_ptr; +- *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) +- * (logical_len + 2)); ++ *visual_out = visual_ptr = grub_calloc (logical_len + 2, ++ 3 * sizeof (visual_ptr[0])); + if (!visual_ptr) + return -1; + for (ptr = logical; ptr <= logical + logical_len; ptr++) +diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c +index c037d5050ed..c57242e2ea9 100644 +--- a/grub-core/normal/cmdline.c ++++ b/grub-core/normal/cmdline.c +@@ -41,7 +41,7 @@ grub_err_t + grub_set_history (int newsize) + { + grub_uint32_t **old_hist_lines = hist_lines; +- hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); ++ hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); + + /* Copy the old lines into the new buffer. */ + if (old_hist_lines) +@@ -114,7 +114,7 @@ static void + grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) + { + grub_free (hist_lines[pos]); +- hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); ++ hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); + if (!hist_lines[pos]) + { + grub_print_error (); +@@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) + char *ret; + unsigned nterms; + +- buf = grub_malloc (max_len * sizeof (grub_uint32_t)); ++ buf = grub_calloc (max_len, sizeof (grub_uint32_t)); + if (!buf) + return 0; + +@@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) + FOR_ACTIVE_TERM_OUTPUTS(cur) + nterms++; + +- cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); ++ cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); + if (!cl_terms) + { + grub_free (buf); +@@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated) + } + cl_term_cur = cl_terms; + +- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + if (!unicode_msg) + { + grub_free (buf); +@@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated) + grub_uint32_t *insert; + + insertlen = grub_strlen (insertu8); +- insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); ++ insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); + if (!insert) + { + grub_free (insertu8); +@@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated) + + grub_free (kill_buf); + +- kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); ++ kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); + if (grub_errno) + { + grub_print_error (); +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index 5785f67ee1c..f31487c1f58 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) + { + linep->len = 0; + linep->max_len = 80; +- linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); +- linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); ++ linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); ++ linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); + if (! linep->buf || !linep->pos) + { + grub_free (linep->buf); +@@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, + pos = linep->pos + (term_screen - screen->terms); + + if (!*pos) +- *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); ++ *pos = grub_calloc (linep->len + 1, sizeof (**pos)); + + if (i == region_start || linep == screen->lines + screen->line + || (i > region_start && mode == ALL_LINES)) +@@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update) + + /* Insert the string. */ + current_linep = screen->lines + screen->line; +- unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); + + if (!unicode_msg) + return 0; +@@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update) + if (completion_buffer.buf) + { + buflen = grub_strlen (completion_buffer.buf); +- ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); ++ ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); + + if (!ucs4) + { +@@ -1265,7 +1265,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) + for (i = 0; i < (unsigned) screen->num_lines; i++) + { + grub_free (screen->lines[i].pos); +- screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); ++ screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); + if (! screen->lines[i].pos) + { + grub_print_error (); +@@ -1275,7 +1275,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) + } + } + +- screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); ++ screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); + if (!screen->terms) + { + grub_print_error (); +diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c +index 7681f7d2893..ca135624356 100644 +--- a/grub-core/normal/menu_text.c ++++ b/grub-core/normal/menu_text.c +@@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, + grub_size_t msg_len = grub_strlen (msg) + 2; + int ret = 0; + +- unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + if (!unicode_msg) + return 0; +@@ -167,7 +167,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, + + title = entry ? entry->title : ""; + title_len = grub_strlen (title); +- unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); ++ unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); + if (! unicode_title) + /* XXX How to show this error? */ + return; +diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c +index a1e5c5a0daf..cc8c173b6e8 100644 +--- a/grub-core/normal/term.c ++++ b/grub-core/normal/term.c +@@ -264,7 +264,7 @@ grub_term_save_pos (void) + FOR_ACTIVE_TERM_OUTPUTS(cur) + cnt++; + +- ret = grub_malloc (cnt * sizeof (ret[0])); ++ ret = grub_calloc (cnt, sizeof (ret[0])); + if (!ret) + return NULL; + +@@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) + + grub_error_push (); + +- unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); ++ unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); + + grub_error_pop (); + +diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c +index 36429a7cd25..f0c503f43d3 100644 +--- a/grub-core/osdep/linux/getroot.c ++++ b/grub-core/osdep/linux/getroot.c +@@ -176,7 +176,7 @@ grub_util_raid_getmembers (const char *name, int bootable) + if (ret != 0) + grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); + +- devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); ++ devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); + + for (i = 0, j = 0; j < info.nr_disks; i++) + { +@@ -249,7 +249,7 @@ grub_find_root_devices_from_btrfs (const char *dir) + return NULL; + } + +- ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); ++ ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); + + for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) + { +@@ -508,7 +508,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) + if (relroot) + *relroot = NULL; + +- entries = xmalloc (entry_max * sizeof (*entries)); ++ entries = xcalloc (entry_max, sizeof (*entries)); + + again: + fp = grub_util_fopen ("/proc/self/mountinfo", "r"); +diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c +index b637c58efb7..46a881530c0 100644 +--- a/grub-core/osdep/unix/config.c ++++ b/grub-core/osdep/unix/config.c +@@ -102,7 +102,7 @@ grub_util_load_config (struct grub_util_config *cfg) + argv[0] = "sh"; + argv[1] = "-c"; + +- script = xmalloc (4 * strlen (cfgfile) + 300); ++ script = xcalloc (4, strlen (cfgfile) + 300); + + ptr = script; + memcpy (ptr, ". '", 3); +diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c +index 661d9546192..eada663b261 100644 +--- a/grub-core/osdep/windows/getroot.c ++++ b/grub-core/osdep/windows/getroot.c +@@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) + + for (ptr = path; *ptr; ptr++); + allocsize = (ptr - path + 10) * 2; +- out = xmalloc (allocsize * sizeof (out[0])); ++ out = xcalloc (allocsize, sizeof (out[0])); + + /* When pointing to EFI system partition GetVolumePathName fails + for ESP root and returns abberant information for everything +diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c +index 87a106c9b82..29cf42788fe 100644 +--- a/grub-core/osdep/windows/hostdisk.c ++++ b/grub-core/osdep/windows/hostdisk.c +@@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) + + while (1) + { +- fpa = xmalloc (alloc * sizeof (fpa[0])); ++ fpa = xcalloc (alloc, sizeof (fpa[0])); + + len = GetFullPathName (tpath, alloc, fpa, NULL); + if (len >= alloc) +@@ -405,7 +405,7 @@ grub_util_fd_opendir (const char *name) + for (l = 0; name_windows[l]; l++); + for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); + l++; +- pattern = xmalloc ((l + 3) * sizeof (pattern[0])); ++ pattern = xcalloc (l + 3, sizeof (pattern[0])); + memcpy (pattern, name_windows, l * sizeof (pattern[0])); + pattern[l] = '\\'; + pattern[l + 1] = '*'; +diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c +index e8ffd62c6a0..6297de6326a 100644 +--- a/grub-core/osdep/windows/init.c ++++ b/grub-core/osdep/windows/init.c +@@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), + LPWSTR *targv; + + targv = CommandLineToArgvW (tcmdline, argc); +- *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); ++ *argv = xcalloc (*argc + 1, sizeof (argv[0])); + + for (i = 0; i < *argc; i++) + (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); +diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c +index 7eb53fe01b4..1ef86bf5873 100644 +--- a/grub-core/osdep/windows/platform.c ++++ b/grub-core/osdep/windows/platform.c +@@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, + grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); + + distrib8_len = grub_strlen (efi_distributor); +- distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 +- * sizeof (grub_uint16_t)); ++ distributor16 = xcalloc (distrib8_len + 1, ++ GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); + distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, + (const grub_uint8_t *) efi_distributor, + distrib8_len, 0); +diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c +index cb0861744ae..478e8ef14d5 100644 +--- a/grub-core/osdep/windows/relpath.c ++++ b/grub-core/osdep/windows/relpath.c +@@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) + if (dirwindows[0] && dirwindows[1] == ':') + offset = 2; + } +- ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); ++ ret = xcalloc (flen - offset + 2, sizeof (ret[0])); + if (dirwindows[offset] != '\\' + && dirwindows[offset] != '/' + && dirwindows[offset]) +diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c +index 103f6796f39..72a2e37cd48 100644 +--- a/grub-core/partmap/gpt.c ++++ b/grub-core/partmap/gpt.c +@@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, + *nsectors = ctx.len; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c +index 7b8e4507625..ee3f24982b8 100644 +--- a/grub-core/partmap/msdos.c ++++ b/grub-core/partmap/msdos.c +@@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, + avail_nsectors = *nsectors; + if (*nsectors > max_nsectors) + *nsectors = max_nsectors; +- *sectors = grub_malloc (*nsectors * sizeof (**sectors)); ++ *sectors = grub_calloc (*nsectors, sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index c6d2c365c9a..b55e171c931 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -587,7 +587,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) + for (iptr = orig_str; *iptr; iptr++) + if (*iptr == '$') + dollar_cnt++; +- ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); ++ ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); + + if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) + goto fail; +diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c +index 2d60852989c..b5eb516be2d 100644 +--- a/grub-core/tests/fake_input.c ++++ b/grub-core/tests/fake_input.c +@@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) + saved = grub_term_inputs; + if (seq) + grub_free (seq); +- seq = grub_malloc (nseq_in * sizeof (seq[0])); ++ seq = grub_calloc (nseq_in, sizeof (seq[0])); + if (!seq) + return; + +diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c +index 74d5b65e5c7..44d0810698a 100644 +--- a/grub-core/tests/video_checksum.c ++++ b/grub-core/tests/video_checksum.c +@@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, + { + case 4: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); +@@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, + } + case 3: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); +@@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, + } + case 2: + { +- grub_uint8_t *buffer = xmalloc (mode_info->width * 3); ++ grub_uint8_t *buffer = xcalloc (3, mode_info->width); + grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); + grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); + grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); +diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c +index 4f83c744116..4d3195e017b 100644 +--- a/grub-core/video/capture.c ++++ b/grub-core/video/capture.c +@@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, + framebuffer.mode_info = *mode_info; + framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); + +- framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); ++ framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); + if (!framebuffer.ptr) + return grub_errno; + +diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c +index a2f639f66de..0ebab6f57dd 100644 +--- a/grub-core/video/emu/sdl.c ++++ b/grub-core/video/emu/sdl.c +@@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, + if (start + count > mode_info.number_of_colors) + count = mode_info.number_of_colors - start; + +- tmp = grub_malloc (count * sizeof (tmp[0])); ++ tmp = grub_calloc (count, sizeof (tmp[0])); + for (i = 0; i < count; i++) + { + tmp[i].r = palette_data[i].r; +diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c +index 01f47112d37..b2f776c997b 100644 +--- a/grub-core/video/i386/pc/vga.c ++++ b/grub-core/video/i386/pc/vga.c +@@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, + + vga_height = height ? : 480; + +- framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); ++ framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); + framebuffer.front_page = 0; + framebuffer.back_page = 0; + if (!framebuffer.temporary_buffer) +diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c +index 777e71334cb..61bd645379b 100644 +--- a/grub-core/video/readers/png.c ++++ b/grub-core/video/readers/png.c +@@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data) + if (data->is_16bit || data->is_gray || data->is_palette) + #endif + { +- data->image_data = grub_malloc (data->image_height * data->row_bytes); ++ data->image_data = grub_calloc (data->image_height, data->row_bytes); + if (grub_errno) + return grub_errno; + +diff --git a/util/getroot.c b/util/getroot.c +index fa3460d6cd8..6feb2a4de40 100644 +--- a/util/getroot.c ++++ b/util/getroot.c +@@ -219,7 +219,7 @@ make_device_name (const char *drive) + char *ret, *ptr; + const char *iptr; + +- ret = xmalloc (strlen (drive) * 2); ++ ret = xcalloc (2, strlen (drive)); + ptr = ret; + for (iptr = drive; *iptr; iptr++) + { +diff --git a/util/grub-file.c b/util/grub-file.c +index 50c18b6835a..b2e7dd69f4c 100644 +--- a/util/grub-file.c ++++ b/util/grub-file.c +@@ -54,7 +54,7 @@ main (int argc, char *argv[]) + + grub_util_host_init (&argc, &argv); + +- argv2 = xmalloc (argc * sizeof (argv2[0])); ++ argv2 = xcalloc (argc, sizeof (argv2[0])); + + if (argc == 2 && strcmp (argv[1], "--version") == 0) + { +diff --git a/util/grub-fstest.c b/util/grub-fstest.c +index 39bad1f432f..bfcef852d83 100644 +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state) + if (args_count < num_disks) + { + if (args_count == 0) +- images = xmalloc (num_disks * sizeof (images[0])); ++ images = xcalloc (num_disks, sizeof (images[0])); + images[args_count] = grub_canonicalize_file_name (arg); + args_count++; + return 0; +@@ -734,7 +734,7 @@ main (int argc, char *argv[]) + + grub_util_host_init (&argc, &argv); + +- args = xmalloc (argc * sizeof (args[0])); ++ args = xcalloc (argc, sizeof (args[0])); + + argp_parse (&argp, argc, argv, 0, 0, 0); + +diff --git a/util/grub-install-common.c b/util/grub-install-common.c +index ca0ac612ac5..0295d40f5e4 100644 +--- a/util/grub-install-common.c ++++ b/util/grub-install-common.c +@@ -286,7 +286,7 @@ handle_install_list (struct install_list *il, const char *val, + il->n_entries++; + } + il->n_alloc = il->n_entries + 1; +- il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); ++ il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); + ptr = val; + for (ce = il->entries; ; ce++) + { +diff --git a/util/grub-install.c b/util/grub-install.c +index 8b6a037903e..dddb7576c97 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -634,7 +634,7 @@ device_map_check_duplicates (const char *dev_map) + if (! fp) + return; + +- d = xmalloc (alloced * sizeof (d[0])); ++ d = xcalloc (alloced, sizeof (d[0])); + + while (fgets (buf, sizeof (buf), fp)) + { +@@ -1263,7 +1263,7 @@ main (int argc, char *argv[]) + ndev++; + } + +- grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); ++ grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); + + for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, + curdrive++) +diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c +index d16ec63a16f..52bc9c848d9 100644 +--- a/util/grub-mkimagexx.c ++++ b/util/grub-mkimagexx.c +@@ -2294,10 +2294,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, + + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); + smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); + +- smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections); +- memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections); +- smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections); +- memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections); ++ smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); ++ smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); + + SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); + +diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c +index ce2cbc4f100..51831027f72 100644 +--- a/util/grub-mkrescue.c ++++ b/util/grub-mkrescue.c +@@ -441,8 +441,8 @@ main (int argc, char *argv[]) + xorriso = xstrdup ("xorriso"); + label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); + +- argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); +- xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); ++ argp_argv = xcalloc (argc, sizeof (argp_argv[0])); ++ xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); + + xorriso_tail_argc = 0; + /* Program name */ +diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c +index 4907d44c0bd..edf309717c3 100644 +--- a/util/grub-mkstandalone.c ++++ b/util/grub-mkstandalone.c +@@ -296,7 +296,7 @@ main (int argc, char *argv[]) + grub_util_host_init (&argc, &argv); + grub_util_disable_fd_syncs (); + +- files = xmalloc ((argc + 1) * sizeof (files[0])); ++ files = xcalloc (argc + 1, sizeof (files[0])); + + argp_parse (&argp, argc, argv, 0, 0, 0); + +diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c +index 0d4084a108e..11331294f1b 100644 +--- a/util/grub-pe2elf.c ++++ b/util/grub-pe2elf.c +@@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, + char *pe_strtab = (image + pe_chdr->symtab_offset + + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); + +- section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); ++ section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); + section_map[0] = 0; +- shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); ++ shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); + idx = 1; + idx_reloc = pe_chdr->num_sections + 1; + +@@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, + + pe_sec = pe_shdr + shdr[i].sh_link; + pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); +- rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); ++ rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); + num_rels = 0; + modified = 0; + +@@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image, + pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); + pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); + +- symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * +- sizeof (Elf_Sym)); +- memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); ++ symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); + num_syms = 1; + +- symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); ++ symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); + + for (i = 0; i < (int) pe_chdr->num_symbols; + i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) +diff --git a/util/grub-probe.c b/util/grub-probe.c +index 7481e487211..cf4291c00a4 100644 +--- a/util/grub-probe.c ++++ b/util/grub-probe.c +@@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim) + grub_util_pull_device (*curdev); + ndev++; + } +- +- drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); ++ ++ drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); + + for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, + curdrive++) +diff --git a/include/grub/unicode.h b/include/grub/unicode.h +index a0403e91f9a..4de986a8576 100644 +--- a/include/grub/unicode.h ++++ b/include/grub/unicode.h +@@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) + grub_memcpy (out, in, sizeof (*in)); + if (in->ncomb > ARRAY_SIZE (out->combining_inline)) + { +- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); ++ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + if (!out->combining_ptr) + { + grub_free (out); +@@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, + grub_memcpy (out, in, sizeof (*in)); + if (in->ncomb > ARRAY_SIZE (out->combining_inline)) + { +- out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); ++ out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); + if (!out->combining_ptr) + return; + grub_memcpy (out->combining_ptr, in->combining_ptr, diff --git a/0229-malloc-Use-overflow-checking-primitives-where-we-do-.patch b/0229-malloc-Use-overflow-checking-primitives-where-we-do-.patch new file mode 100644 index 0000000..f840978 --- /dev/null +++ b/0229-malloc-Use-overflow-checking-primitives-where-we-do-.patch @@ -0,0 +1,1320 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 15 Jun 2020 12:28:27 -0400 +Subject: [PATCH] malloc: Use overflow checking primitives where we do complex + allocations + +This attempts to fix the places where we do the following where +arithmetic_expr may include unvalidated data: + + X = grub_malloc(arithmetic_expr); + +It accomplishes this by doing the arithmetic ahead of time using grub_add(), +grub_sub(), grub_mul() and testing for overflow before proceeding. + +Among other issues, this fixes: + - allocation of integer overflow in grub_video_bitmap_create() + reported by Chris Coulson, + - allocation of integer overflow in grub_png_decode_image_header() + reported by Chris Coulson, + - allocation of integer overflow in grub_squash_read_symlink() + reported by Chris Coulson, + - allocation of integer overflow in grub_ext2_read_symlink() + reported by Chris Coulson, + - allocation of integer overflow in read_section_as_string() + reported by Chris Coulson. + +Fixes: CVE-2020-14309, CVE-2020-14310, CVE-2020-14311 + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: 5fb2befbf04 +--- + grub-core/commands/legacycfg.c | 29 +++++++++++++++++++----- + grub-core/commands/wildcard.c | 36 ++++++++++++++++++++++++----- + grub-core/disk/ldm.c | 32 ++++++++++++++++++-------- + grub-core/font/font.c | 7 +++++- + grub-core/fs/btrfs.c | 28 +++++++++++++++-------- + grub-core/fs/ext2.c | 10 ++++++++- + grub-core/fs/iso9660.c | 51 +++++++++++++++++++++++++++++------------- + grub-core/fs/sfs.c | 27 +++++++++++++++++----- + grub-core/fs/squash4.c | 45 ++++++++++++++++++++++++++++--------- + grub-core/fs/udf.c | 41 +++++++++++++++++++++------------ + grub-core/fs/xfs.c | 11 +++++---- + grub-core/fs/zfs/zfs.c | 22 ++++++++++++------ + grub-core/fs/zfs/zfscrypt.c | 7 +++++- + grub-core/lib/arg.c | 20 +++++++++++++++-- + grub-core/loader/i386/bsd.c | 8 ++++++- + grub-core/net/dns.c | 9 +++++++- + grub-core/normal/charset.c | 10 +++++++-- + grub-core/normal/cmdline.c | 14 ++++++++++-- + grub-core/normal/menu_entry.c | 13 +++++++++-- + grub-core/script/argv.c | 16 +++++++++++-- + grub-core/script/lexer.c | 21 ++++++++++++++--- + grub-core/video/bitmap.c | 25 +++++++++++++-------- + grub-core/video/readers/png.c | 13 +++++++++-- + 23 files changed, 382 insertions(+), 113 deletions(-) + +diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c +index da5143d4360..782761c31aa 100644 +--- a/grub-core/commands/legacycfg.c ++++ b/grub-core/commands/legacycfg.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -104,13 +105,22 @@ legacy_file (const char *filename) + if (newsuffix) + { + char *t; +- ++ grub_size_t sz; ++ ++ if (grub_add (grub_strlen (suffix), grub_strlen (newsuffix), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail_0; ++ } ++ + t = suffix; +- suffix = grub_realloc (suffix, grub_strlen (suffix) +- + grub_strlen (newsuffix) + 1); ++ suffix = grub_realloc (suffix, sz); + if (!suffix) + { + grub_free (t); ++ ++ fail_0: + grub_free (entrysrc); + grub_free (parsed); + grub_free (newsuffix); +@@ -154,13 +164,22 @@ legacy_file (const char *filename) + else + { + char *t; ++ grub_size_t sz; ++ ++ if (grub_add (grub_strlen (entrysrc), grub_strlen (parsed), &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail_1; ++ } + + t = entrysrc; +- entrysrc = grub_realloc (entrysrc, grub_strlen (entrysrc) +- + grub_strlen (parsed) + 1); ++ entrysrc = grub_realloc (entrysrc, sz); + if (!entrysrc) + { + grub_free (t); ++ ++ fail_1: + grub_free (parsed); + grub_free (suffix); + return grub_errno; +diff --git a/grub-core/commands/wildcard.c b/grub-core/commands/wildcard.c +index 560d437cdc6..8f67a4be7f0 100644 +--- a/grub-core/commands/wildcard.c ++++ b/grub-core/commands/wildcard.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #include + +@@ -48,6 +49,7 @@ merge (char **dest, char **ps) + int i; + int j; + char **p; ++ grub_size_t sz; + + if (! dest) + return ps; +@@ -60,7 +62,12 @@ merge (char **dest, char **ps) + for (j = 0; ps[j]; j++) + ; + +- p = grub_realloc (dest, sizeof (char*) * (i + j + 1)); ++ if (grub_add (i, j, &sz) || ++ grub_add (sz, 1, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return dest; ++ ++ p = grub_realloc (dest, sz); + if (! p) + { + grub_free (dest); +@@ -115,8 +122,15 @@ make_regex (const char *start, const char *end, regex_t *regexp) + char ch; + int i = 0; + unsigned len = end - start; +- char *buffer = grub_malloc (len * 2 + 2 + 1); /* worst case size. */ ++ char *buffer; ++ grub_size_t sz; + ++ /* Worst case size is (len * 2 + 2 + 1). */ ++ if (grub_mul (len, 2, &sz) || ++ grub_add (sz, 3, &sz)) ++ return 1; ++ ++ buffer = grub_malloc (sz); + if (! buffer) + return 1; + +@@ -226,6 +240,7 @@ match_devices_iter (const char *name, void *data) + struct match_devices_ctx *ctx = data; + char **t; + char *buffer; ++ grub_size_t sz; + + /* skip partitions if asked to. */ + if (ctx->noparts && grub_strchr (name, ',')) +@@ -239,11 +254,16 @@ match_devices_iter (const char *name, void *data) + if (regexec (ctx->regexp, buffer, 0, 0, 0)) + { + grub_dprintf ("expand", "not matched\n"); ++ fail: + grub_free (buffer); + return 0; + } + +- t = grub_realloc (ctx->devs, sizeof (char*) * (ctx->ndev + 2)); ++ if (grub_add (ctx->ndev, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ goto fail; ++ ++ t = grub_realloc (ctx->devs, sz); + if (! t) + { + grub_free (buffer); +@@ -300,6 +320,7 @@ match_files_iter (const char *name, + struct match_files_ctx *ctx = data; + char **t; + char *buffer; ++ grub_size_t sz; + + /* skip . and .. names */ + if (grub_strcmp(".", name) == 0 || grub_strcmp("..", name) == 0) +@@ -315,9 +336,14 @@ match_files_iter (const char *name, + if (! buffer) + return 1; + +- t = grub_realloc (ctx->files, sizeof (char*) * (ctx->nfile + 2)); +- if (! t) ++ if (grub_add (ctx->nfile, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ goto fail; ++ ++ t = grub_realloc (ctx->files, sz); ++ if (!t) + { ++ fail: + grub_free (buffer); + return 1; + } +diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c +index e6323701ab3..58f8a53e1ab 100644 +--- a/grub-core/disk/ldm.c ++++ b/grub-core/disk/ldm.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_UTIL + #include +@@ -289,6 +290,7 @@ make_vg (grub_disk_t disk, + struct grub_ldm_vblk vblk[GRUB_DISK_SECTOR_SIZE + / sizeof (struct grub_ldm_vblk)]; + unsigned i; ++ grub_size_t sz; + err = grub_disk_read (disk, cursec, 0, + sizeof(vblk), &vblk); + if (err) +@@ -350,7 +352,13 @@ make_vg (grub_disk_t disk, + grub_free (lv); + goto fail2; + } +- lv->name = grub_malloc (*ptr + 1); ++ if (grub_add (*ptr, 1, &sz)) ++ { ++ grub_free (lv->internal_id); ++ grub_free (lv); ++ goto fail2; ++ } ++ lv->name = grub_malloc (sz); + if (!lv->name) + { + grub_free (lv->internal_id); +@@ -599,10 +607,13 @@ make_vg (grub_disk_t disk, + if (lv->segments->node_alloc == lv->segments->node_count) + { + void *t; +- lv->segments->node_alloc *= 2; +- t = grub_realloc (lv->segments->nodes, +- sizeof (*lv->segments->nodes) +- * lv->segments->node_alloc); ++ grub_size_t sz; ++ ++ if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) || ++ grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz)) ++ goto fail2; ++ ++ t = grub_realloc (lv->segments->nodes, sz); + if (!t) + goto fail2; + lv->segments->nodes = t; +@@ -723,10 +734,13 @@ make_vg (grub_disk_t disk, + if (comp->segment_alloc == comp->segment_count) + { + void *t; +- comp->segment_alloc *= 2; +- t = grub_realloc (comp->segments, +- comp->segment_alloc +- * sizeof (*comp->segments)); ++ grub_size_t sz; ++ ++ if (grub_mul (comp->segment_alloc, 2, &comp->segment_alloc) || ++ grub_mul (comp->segment_alloc, sizeof (*comp->segments), &sz)) ++ goto fail2; ++ ++ t = grub_realloc (comp->segments, sz); + if (!t) + goto fail2; + comp->segments = t; +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 8e118b315ce..5edb477ac2e 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -360,9 +361,13 @@ static char * + read_section_as_string (struct font_file_section *section) + { + char *str; ++ grub_size_t sz; + grub_ssize_t ret; + +- str = grub_malloc (section->length + 1); ++ if (grub_add (section->length, 1, &sz)) ++ return NULL; ++ ++ str = grub_malloc (sz); + if (!str) + return 0; + +diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c +index ba080fdc580..0d8c666aea1 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -44,6 +44,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -358,9 +359,13 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc, + if (desc->allocated < desc->depth) + { + void *newdata; +- desc->allocated *= 2; +- newdata = grub_realloc (desc->data, sizeof (desc->data[0]) +- * desc->allocated); ++ grub_size_t sz; ++ ++ if (grub_mul (desc->allocated, 2, &desc->allocated) || ++ grub_mul (desc->allocated, sizeof (desc->data[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ newdata = grub_realloc (desc->data, sz); + if (!newdata) + return grub_errno; + desc->data = newdata; +@@ -651,16 +656,21 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id) + if (data->n_devices_attached > data->n_devices_allocated) + { + void *tmp; +- data->n_devices_allocated = 2 * data->n_devices_attached + 1; +- data->devices_attached +- = grub_realloc (tmp = data->devices_attached, +- data->n_devices_allocated +- * sizeof (data->devices_attached[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || ++ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || ++ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) ++ goto fail; ++ ++ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + if (!data->devices_attached) + { ++ data->devices_attached = tmp; ++ ++ fail: + if (ctx.dev_found) + grub_device_close (ctx.dev_found); +- data->devices_attached = tmp; + return NULL; + } + } +diff --git a/grub-core/fs/ext2.c b/grub-core/fs/ext2.c +index 9b389802a35..ac33bcd68c4 100644 +--- a/grub-core/fs/ext2.c ++++ b/grub-core/fs/ext2.c +@@ -46,6 +46,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -703,6 +704,7 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) + { + char *symlink; + struct grub_fshelp_node *diro = node; ++ grub_size_t sz; + + if (! diro->inode_read) + { +@@ -717,7 +719,13 @@ grub_ext2_read_symlink (grub_fshelp_node_t node) + } + } + +- symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); ++ if (grub_add (grub_le_to_cpu32 (diro->inode.size), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ symlink = grub_malloc (sz); + if (! symlink) + return 0; + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 4f1b52a552a..7ba5b300bc1 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -531,8 +532,13 @@ add_part (struct iterate_dir_ctx *ctx, + int len2) + { + int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; ++ grub_size_t sz; + +- ctx->symlink = grub_realloc (ctx->symlink, size + len2 + 1); ++ if (grub_add (size, len2, &sz) || ++ grub_add (sz, 1, &sz)) ++ return; ++ ++ ctx->symlink = grub_realloc (ctx->symlink, sz); + if (! ctx->symlink) + return; + +@@ -560,17 +566,24 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + { + grub_size_t off = 0, csize = 1; + char *old; ++ grub_size_t sz; ++ + csize = entry->len - 5; + old = ctx->filename; + if (ctx->filename_alloc) + { + off = grub_strlen (ctx->filename); +- ctx->filename = grub_realloc (ctx->filename, csize + off + 1); ++ if (grub_add (csize, off, &sz) || ++ grub_add (sz, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ctx->filename = grub_realloc (ctx->filename, sz); + } + else + { + off = 0; +- ctx->filename = grub_zalloc (csize + 1); ++ if (grub_add (csize, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ctx->filename = grub_zalloc (sz); + } + if (!ctx->filename) + { +@@ -776,14 +789,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, + if (node->have_dirents >= node->alloc_dirents) + { + struct grub_fshelp_node *new_node; +- node->alloc_dirents *= 2; +- new_node = grub_realloc (node, +- sizeof (struct grub_fshelp_node) +- + ((node->alloc_dirents +- - ARRAY_SIZE (node->dirents)) +- * sizeof (node->dirents[0]))); ++ grub_size_t sz; ++ ++ if (grub_mul (node->alloc_dirents, 2, &node->alloc_dirents) || ++ grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || ++ grub_mul (sz, sizeof (node->dirents[0]), &sz) || ++ grub_add (sz, sizeof (struct grub_fshelp_node), &sz)) ++ goto fail_0; ++ ++ new_node = grub_realloc (node, sz); + if (!new_node) + { ++ fail_0: + if (ctx.filename_alloc) + grub_free (ctx.filename); + grub_free (node); +@@ -799,14 +816,18 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir, + * sizeof (node->dirents[0]) < grub_strlen (ctx.symlink) + 1) + { + struct grub_fshelp_node *new_node; +- new_node = grub_realloc (node, +- sizeof (struct grub_fshelp_node) +- + ((node->alloc_dirents +- - ARRAY_SIZE (node->dirents)) +- * sizeof (node->dirents[0])) +- + grub_strlen (ctx.symlink) + 1); ++ grub_size_t sz; ++ ++ if (grub_sub (node->alloc_dirents, ARRAY_SIZE (node->dirents), &sz) || ++ grub_mul (sz, sizeof (node->dirents[0]), &sz) || ++ grub_add (sz, sizeof (struct grub_fshelp_node) + 1, &sz) || ++ grub_add (sz, grub_strlen (ctx.symlink), &sz)) ++ goto fail_1; ++ ++ new_node = grub_realloc (node, sz); + if (!new_node) + { ++ fail_1: + if (ctx.filename_alloc) + grub_free (ctx.filename); + grub_free (node); +diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c +index 90f7fb37918..de2b107a4a4 100644 +--- a/grub-core/fs/sfs.c ++++ b/grub-core/fs/sfs.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -307,10 +308,15 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) + if (node->cache && node->cache_size >= node->cache_allocated) + { + struct cache_entry *e = node->cache; +- e = grub_realloc (node->cache,node->cache_allocated * 2 +- * sizeof (e[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (node->cache_allocated, 2 * sizeof (e[0]), &sz)) ++ goto fail; ++ ++ e = grub_realloc (node->cache, sz); + if (!e) + { ++ fail: + grub_errno = 0; + grub_free (node->cache); + node->cache = 0; +@@ -477,10 +483,16 @@ grub_sfs_create_node (struct grub_fshelp_node **node, + grub_size_t len = grub_strlen (name); + grub_uint8_t *name_u8; + int ret; ++ grub_size_t sz; ++ ++ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || ++ grub_add (sz, 1, &sz)) ++ return 1; ++ + *node = grub_malloc (sizeof (**node)); + if (!*node) + return 1; +- name_u8 = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ name_u8 = grub_malloc (sz); + if (!name_u8) + { + grub_free (*node); +@@ -724,8 +736,13 @@ grub_sfs_label (grub_device_t device, char **label) + data = grub_sfs_mount (disk); + if (data) + { +- grub_size_t len = grub_strlen (data->label); +- *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); ++ grub_size_t sz, len = grub_strlen (data->label); ++ ++ if (grub_mul (len, GRUB_MAX_UTF8_PER_LATIN1, &sz) || ++ grub_add (sz, 1, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ *label = grub_malloc (sz); + if (*label) + *grub_latin1_to_utf8 ((grub_uint8_t *) *label, + (const grub_uint8_t *) data->label, +diff --git a/grub-core/fs/squash4.c b/grub-core/fs/squash4.c +index 95d5c1e1ff4..785123894e3 100644 +--- a/grub-core/fs/squash4.c ++++ b/grub-core/fs/squash4.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + #include + + #include "xz.h" +@@ -459,7 +460,17 @@ grub_squash_read_symlink (grub_fshelp_node_t node) + { + char *ret; + grub_err_t err; +- ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); ++ grub_size_t sz; ++ ++ if (grub_add (grub_le_to_cpu32 (node->ino.symlink.namelen), 1, &sz)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return NULL; ++ } ++ ++ ret = grub_malloc (sz); ++ if (!ret) ++ return NULL; + + err = read_chunk (node->data, ret, + grub_le_to_cpu32 (node->ino.symlink.namelen), +@@ -506,11 +517,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + + { + grub_fshelp_node_t node; +- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (!node) + return 0; +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz); + if (hook (".", GRUB_FSHELP_DIR, node, hook_data)) + return 1; + +@@ -518,12 +534,15 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + { + grub_err_t err; + +- node = grub_malloc (sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ if (grub_mul (dir->stsize, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (!node) + return 0; + +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz); + + node->stsize--; + err = read_chunk (dir->data, &node->ino, sizeof (node->ino), +@@ -557,6 +576,7 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; + struct grub_squash_dirent di; + struct grub_squash_inode ino; ++ grub_size_t sz; + + err = read_chunk (dir->data, &di, sizeof (di), + grub_le_to_cpu64 (dir->data->sb.diroffset) +@@ -589,13 +609,16 @@ grub_squash_iterate_dir (grub_fshelp_node_t dir, + if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) + filetype = GRUB_FSHELP_SYMLINK; + +- node = grub_malloc (sizeof (*node) +- + (dir->stsize + 1) * sizeof (dir->stack[0])); ++ if (grub_add (dir->stsize, 1, &sz) || ++ grub_mul (sz, sizeof (dir->stack[0]), &sz) || ++ grub_add (sz, sizeof (*node), &sz)) ++ return 0; ++ ++ node = grub_malloc (sz); + if (! node) + return 0; + +- grub_memcpy (node, dir, +- sizeof (*node) + dir->stsize * sizeof (dir->stack[0])); ++ grub_memcpy (node, dir, sz - sizeof(dir->stack[0])); + + node->ino = ino; + node->stack[node->stsize].ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index a83761674ad..21ac7f4460d 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -890,9 +891,19 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) + utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2]; + } + if (!outbuf) +- outbuf = grub_malloc (utf16len * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ { ++ grub_size_t size; ++ ++ if (grub_mul (utf16len, GRUB_MAX_UTF8_PER_UTF16, &size) || ++ grub_add (size, 1, &size)) ++ goto fail; ++ ++ outbuf = grub_malloc (size); ++ } + if (outbuf) + *grub_utf16_to_utf8 ((grub_uint8_t *) outbuf, utf16, utf16len) = '\0'; ++ ++ fail: + grub_free (utf16); + return outbuf; + } +@@ -1005,7 +1016,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + grub_size_t sz = U64 (node->block.fe.file_size); + grub_uint8_t *raw; + const grub_uint8_t *ptr; +- char *out, *optr; ++ char *out = NULL, *optr; + + if (sz < 4) + return NULL; +@@ -1013,14 +1024,16 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + if (!raw) + return NULL; + if (grub_udf_read_file (node, NULL, NULL, 0, sz, (char *) raw) < 0) +- { +- grub_free (raw); +- return NULL; +- } ++ goto fail_1; + +- out = grub_malloc (sz * 2 + 1); ++ if (grub_mul (sz, 2, &sz) || ++ grub_add (sz, 1, &sz)) ++ goto fail_0; ++ ++ out = grub_malloc (sz); + if (!out) + { ++ fail_0: + grub_free (raw); + return NULL; + } +@@ -1031,17 +1044,17 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + { + grub_size_t s; + if ((grub_size_t) (ptr - raw + 4) > sz) +- goto fail; ++ goto fail_1; + if (!(ptr[2] == 0 && ptr[3] == 0)) +- goto fail; ++ goto fail_1; + s = 4 + ptr[1]; + if ((grub_size_t) (ptr - raw + s) > sz) +- goto fail; ++ goto fail_1; + switch (*ptr) + { + case 1: + if (ptr[1]) +- goto fail; ++ goto fail_1; + /* Fallthrough. */ + case 2: + /* in 4 bytes. out: 1 byte. */ +@@ -1066,11 +1079,11 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + if (optr != out) + *optr++ = '/'; + if (!read_string (ptr + 4, s - 4, optr)) +- goto fail; ++ goto fail_1; + optr += grub_strlen (optr); + break; + default: +- goto fail; ++ goto fail_1; + } + ptr += s; + } +@@ -1078,7 +1091,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) + grub_free (raw); + return out; + +- fail: ++ fail_1: + grub_free (raw); + grub_free (out); + grub_error (GRUB_ERR_BAD_FS, "invalid symlink"); +diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c +index 96ffecbfc92..ea6590290b1 100644 +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -899,6 +900,7 @@ static struct grub_xfs_data * + grub_xfs_mount (grub_disk_t disk) + { + struct grub_xfs_data *data = 0; ++ grub_size_t sz; + + data = grub_zalloc (sizeof (struct grub_xfs_data)); + if (!data) +@@ -913,10 +915,11 @@ grub_xfs_mount (grub_disk_t disk) + if (!grub_xfs_sb_valid(data)) + goto fail; + +- data = grub_realloc (data, +- sizeof (struct grub_xfs_data) +- - sizeof (struct grub_xfs_inode) +- + grub_xfs_inode_size(data) + 1); ++ if (grub_add (grub_xfs_inode_size (data), ++ sizeof (struct grub_xfs_data) - sizeof (struct grub_xfs_inode) + 1, &sz)) ++ goto fail; ++ ++ data = grub_realloc (data, sz); + + if (! data) + goto fail; +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index 381dde556d1..36d0373a6a5 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -55,6 +55,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -773,11 +774,14 @@ fill_vdev_info (struct grub_zfs_data *data, + if (data->n_devices_attached > data->n_devices_allocated) + { + void *tmp; +- data->n_devices_allocated = 2 * data->n_devices_attached + 1; +- data->devices_attached +- = grub_realloc (tmp = data->devices_attached, +- data->n_devices_allocated +- * sizeof (data->devices_attached[0])); ++ grub_size_t sz; ++ ++ if (grub_mul (data->n_devices_attached, 2, &data->n_devices_allocated) || ++ grub_add (data->n_devices_allocated, 1, &data->n_devices_allocated) || ++ grub_mul (data->n_devices_allocated, sizeof (data->devices_attached[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ data->devices_attached = grub_realloc (tmp = data->devices_attached, sz); + if (!data->devices_attached) + { + data->devices_attached = tmp; +@@ -3468,14 +3472,18 @@ grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name) + { + char *nvpair; + char *ret; +- grub_size_t size; ++ grub_size_t size, sz; + int found; + + found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, + &size, 0); + if (!found) + return 0; +- ret = grub_zalloc (size + 3 * sizeof (grub_uint32_t)); ++ ++ if (grub_add (size, 3 * sizeof (grub_uint32_t), &sz)) ++ return 0; ++ ++ ret = grub_zalloc (sz); + if (!ret) + return 0; + grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); +diff --git a/grub-core/fs/zfs/zfscrypt.c b/grub-core/fs/zfs/zfscrypt.c +index 1402e0bc29b..de3b015f582 100644 +--- a/grub-core/fs/zfs/zfscrypt.c ++++ b/grub-core/fs/zfs/zfscrypt.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -82,9 +83,13 @@ grub_zfs_add_key (grub_uint8_t *key_in, + int passphrase) + { + struct grub_zfs_wrap_key *key; ++ grub_size_t sz; ++ + if (!passphrase && keylen > 32) + keylen = 32; +- key = grub_malloc (sizeof (*key) + keylen); ++ if (grub_add (sizeof (*key), keylen, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ key = grub_malloc (sz); + if (!key) + return grub_errno; + key->is_passphrase = passphrase; +diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c +index ccc185017ee..8439a0062ff 100644 +--- a/grub-core/lib/arg.c ++++ b/grub-core/lib/arg.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + /* Built-in parser for default options. */ + static const struct grub_arg_option help_options[] = +@@ -216,7 +217,13 @@ static inline grub_err_t + add_arg (char ***argl, int *num, char *s) + { + char **p = *argl; +- *argl = grub_realloc (*argl, (++(*num) + 1) * sizeof (char *)); ++ grub_size_t sz; ++ ++ if (grub_add (++(*num), 1, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ ++ *argl = grub_realloc (*argl, sz); + if (! *argl) + { + grub_free (p); +@@ -431,6 +438,7 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, + grub_size_t argcnt; + struct grub_arg_list *list; + const struct grub_arg_option *options; ++ grub_size_t sz0, sz1; + + options = extcmd->options; + if (! options) +@@ -443,7 +451,15 @@ grub_arg_list_alloc(grub_extcmd_t extcmd, int argc, + argcnt += ((grub_size_t) argc + 1) / 2 + 1; /* max possible for any option */ + } + +- list = grub_zalloc (sizeof (*list) * i + sizeof (char*) * argcnt); ++ if (grub_mul (sizeof (*list), i, &sz0) || ++ grub_mul (sizeof (char *), argcnt, &sz1) || ++ grub_add (sz0, sz1, &sz0)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ return 0; ++ } ++ ++ list = grub_zalloc (sz0); + if (! list) + return 0; + +diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c +index 50cca304fd0..ff98fb7b62b 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + #include + #ifdef GRUB_MACHINE_PCBIOS + #include +@@ -1013,11 +1014,16 @@ grub_netbsd_add_modules (void) + struct grub_netbsd_btinfo_modules *mods; + unsigned i; + grub_err_t err; ++ grub_size_t sz; + + for (mod = netbsd_mods; mod; mod = mod->next) + modcnt++; + +- mods = grub_malloc (sizeof (*mods) + sizeof (mods->mods[0]) * modcnt); ++ if (grub_mul (modcnt, sizeof (mods->mods[0]), &sz) || ++ grub_add (sz, sizeof (*mods), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ mods = grub_malloc (sz); + if (!mods) + return grub_errno; + +diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c +index e332d5eb4a4..906ec7d6782 100644 +--- a/grub-core/net/dns.c ++++ b/grub-core/net/dns.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + + struct dns_cache_element + { +@@ -51,9 +52,15 @@ grub_net_add_dns_server (const struct grub_net_network_level_address *s) + { + int na = dns_servers_alloc * 2; + struct grub_net_network_level_address *ns; ++ grub_size_t sz; ++ + if (na < 8) + na = 8; +- ns = grub_realloc (dns_servers, na * sizeof (ns[0])); ++ ++ if (grub_mul (na, sizeof (ns[0]), &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ ns = grub_realloc (dns_servers, sz); + if (!ns) + return grub_errno; + dns_servers_alloc = na; +diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c +index d57fb72faa8..4dfcc31078d 100644 +--- a/grub-core/normal/charset.c ++++ b/grub-core/normal/charset.c +@@ -48,6 +48,7 @@ + #include + #include + #include ++#include + + #if HAVE_FONT_SOURCE + #include "widthspec.h" +@@ -464,6 +465,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + { + struct grub_unicode_combining *n; + unsigned j; ++ grub_size_t sz; + + if (!haveout) + continue; +@@ -477,10 +479,14 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, + n = out->combining_inline; + else if (out->ncomb > (int) ARRAY_SIZE (out->combining_inline)) + { +- n = grub_realloc (out->combining_ptr, +- sizeof (n[0]) * (out->ncomb + 1)); ++ if (grub_add (out->ncomb, 1, &sz) || ++ grub_mul (sz, sizeof (n[0]), &sz)) ++ goto fail; ++ ++ n = grub_realloc (out->combining_ptr, sz); + if (!n) + { ++ fail: + grub_errno = GRUB_ERR_NONE; + continue; + } +diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c +index c57242e2ea9..de03fe63b3d 100644 +--- a/grub-core/normal/cmdline.c ++++ b/grub-core/normal/cmdline.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + static grub_uint32_t *kill_buf; + +@@ -307,12 +308,21 @@ cl_insert (struct cmdline_term *cl_terms, unsigned nterms, + if (len + (*llen) >= (*max_len)) + { + grub_uint32_t *nbuf; +- (*max_len) *= 2; +- nbuf = grub_realloc ((*buf), sizeof (grub_uint32_t) * (*max_len)); ++ grub_size_t sz; ++ ++ if (grub_mul (*max_len, 2, max_len) || ++ grub_mul (*max_len, sizeof (grub_uint32_t), &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ goto fail; ++ } ++ ++ nbuf = grub_realloc ((*buf), sz); + if (nbuf) + (*buf) = nbuf; + else + { ++ fail: + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + (*max_len) /= 2; +diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c +index f31487c1f58..de64a367c4e 100644 +--- a/grub-core/normal/menu_entry.c ++++ b/grub-core/normal/menu_entry.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + + enum update_mode + { +@@ -113,10 +114,18 @@ ensure_space (struct line *linep, int extra) + { + if (linep->max_len < linep->len + extra) + { +- linep->max_len = 2 * (linep->len + extra); +- linep->buf = grub_realloc (linep->buf, (linep->max_len + 1) * sizeof (linep->buf[0])); ++ grub_size_t sz0, sz1; ++ ++ if (grub_add (linep->len, extra, &sz0) || ++ grub_mul (sz0, 2, &sz0) || ++ grub_add (sz0, 1, &sz1) || ++ grub_mul (sz1, sizeof (linep->buf[0]), &sz1)) ++ return 0; ++ ++ linep->buf = grub_realloc (linep->buf, sz1); + if (! linep->buf) + return 0; ++ linep->max_len = sz0; + } + + return 1; +diff --git a/grub-core/script/argv.c b/grub-core/script/argv.c +index 217ec5d1e1b..5751fdd5708 100644 +--- a/grub-core/script/argv.c ++++ b/grub-core/script/argv.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + + /* Return nearest power of two that is >= v. */ + static unsigned +@@ -81,11 +82,16 @@ int + grub_script_argv_next (struct grub_script_argv *argv) + { + char **p = argv->args; ++ grub_size_t sz; + + if (argv->args && argv->argc && argv->args[argv->argc - 1] == 0) + return 0; + +- p = grub_realloc (p, round_up_exp ((argv->argc + 2) * sizeof (char *))); ++ if (grub_add (argv->argc, 2, &sz) || ++ grub_mul (sz, sizeof (char *), &sz)) ++ return 1; ++ ++ p = grub_realloc (p, round_up_exp (sz)); + if (! p) + return 1; + +@@ -105,13 +111,19 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s, + { + grub_size_t a; + char *p = argv->args[argv->argc - 1]; ++ grub_size_t sz; + + if (! s) + return 0; + + a = p ? grub_strlen (p) : 0; + +- p = grub_realloc (p, round_up_exp ((a + slen + 1) * sizeof (char))); ++ if (grub_add (a, slen, &sz) || ++ grub_add (sz, 1, &sz) || ++ grub_mul (sz, sizeof (char), &sz)) ++ return 1; ++ ++ p = grub_realloc (p, round_up_exp (sz)); + if (! p) + return 1; + +diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c +index c6bd3172fab..5fb0cbd0bc9 100644 +--- a/grub-core/script/lexer.c ++++ b/grub-core/script/lexer.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + #define yytext_ptr char * + #include "grub_script.tab.h" +@@ -110,10 +111,14 @@ grub_script_lexer_record (struct grub_parser_param *parser, char *str) + old = lexer->recording; + if (lexer->recordlen < len) + lexer->recordlen = len; +- lexer->recordlen *= 2; ++ ++ if (grub_mul (lexer->recordlen, 2, &lexer->recordlen)) ++ goto fail; ++ + lexer->recording = grub_realloc (lexer->recording, lexer->recordlen); + if (!lexer->recording) + { ++ fail: + grub_free (old); + lexer->recordpos = 0; + lexer->recordlen = 0; +@@ -130,7 +135,7 @@ int + grub_script_lexer_yywrap (struct grub_parser_param *parserstate, + const char *input) + { +- grub_size_t len = 0; ++ grub_size_t len = 0, sz; + char *p = 0; + char *line = 0; + YY_BUFFER_STATE buffer; +@@ -168,12 +173,22 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate, + } + else if (len && line[len - 1] != '\n') + { +- p = grub_realloc (line, len + 2); ++ if (grub_add (len, 2, &sz)) ++ { ++ grub_free (line); ++ grub_script_yyerror (parserstate, N_("overflow is detected")); ++ return 1; ++ } ++ ++ p = grub_realloc (line, sz); + if (p) + { + p[len++] = '\n'; + p[len] = '\0'; + } ++ else ++ grub_free (line); ++ + line = p; + } + +diff --git a/grub-core/video/bitmap.c b/grub-core/video/bitmap.c +index b2e0315665b..6256e209a6b 100644 +--- a/grub-core/video/bitmap.c ++++ b/grub-core/video/bitmap.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -58,7 +59,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, + enum grub_video_blit_format blit_format) + { + struct grub_video_mode_info *mode_info; +- unsigned int size; ++ grub_size_t size; + + if (!bitmap) + return grub_error (GRUB_ERR_BUG, "invalid argument"); +@@ -137,19 +138,25 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap, + + mode_info->pitch = width * mode_info->bytes_per_pixel; + +- /* Calculate size needed for the data. */ +- size = (width * mode_info->bytes_per_pixel) * height; ++ /* Calculate size needed for the data. */ ++ if (grub_mul (width, mode_info->bytes_per_pixel, &size) || ++ grub_mul (size, height, &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + + (*bitmap)->data = grub_zalloc (size); + if (! (*bitmap)->data) +- { +- grub_free (*bitmap); +- *bitmap = 0; +- +- return grub_errno; +- } ++ goto fail; + + return GRUB_ERR_NONE; ++ ++ fail: ++ grub_free (*bitmap); ++ *bitmap = NULL; ++ ++ return grub_errno; + } + + /* Frees all resources allocated by bitmap. */ +diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c +index 61bd645379b..0157ff7420b 100644 +--- a/grub-core/video/readers/png.c ++++ b/grub-core/video/readers/png.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -301,9 +302,17 @@ grub_png_decode_image_header (struct grub_png_data *data) + data->bpp <<= 1; + + data->color_bits = color_bits; +- data->row_bytes = data->image_width * data->bpp; ++ ++ if (grub_mul (data->image_width, data->bpp, &data->row_bytes)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ + if (data->color_bits <= 4) +- data->row_bytes = (data->image_width * data->color_bits + 7) / 8; ++ { ++ if (grub_mul (data->image_width, data->color_bits + 7, &data->row_bytes)) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ ++ data->row_bytes >>= 3; ++ } + + #ifndef GRUB_CPU_WORDS_BIGENDIAN + if (data->is_16bit || data->is_gray || data->is_palette) diff --git a/0230-iso9660-Don-t-leak-memory-on-realloc-failures.patch b/0230-iso9660-Don-t-leak-memory-on-realloc-failures.patch new file mode 100644 index 0000000..8ec24bd --- /dev/null +++ b/0230-iso9660-Don-t-leak-memory-on-realloc-failures.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sat, 4 Jul 2020 12:25:09 -0400 +Subject: [PATCH] iso9660: Don't leak memory on realloc() failures + +Signed-off-by: Peter Jones +Reviewed-by: Daniel Kiper +Upstream-commit-id: f2bd30b2fe7 +--- + grub-core/fs/iso9660.c | 24 ++++++++++++++++++++---- + 1 file changed, 20 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c +index 7ba5b300bc1..5ec4433b8f8 100644 +--- a/grub-core/fs/iso9660.c ++++ b/grub-core/fs/iso9660.c +@@ -533,14 +533,20 @@ add_part (struct iterate_dir_ctx *ctx, + { + int size = ctx->symlink ? grub_strlen (ctx->symlink) : 0; + grub_size_t sz; ++ char *new; + + if (grub_add (size, len2, &sz) || + grub_add (sz, 1, &sz)) + return; + +- ctx->symlink = grub_realloc (ctx->symlink, sz); +- if (! ctx->symlink) +- return; ++ new = grub_realloc (ctx->symlink, sz); ++ if (!new) ++ { ++ grub_free (ctx->symlink); ++ ctx->symlink = NULL; ++ return; ++ } ++ ctx->symlink = new; + + grub_memcpy (ctx->symlink + size, part, len2); + ctx->symlink[size + len2] = 0; +@@ -634,7 +640,12 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + is the length. Both are part of the `Component + Record'. */ + if (ctx->symlink && !ctx->was_continue) +- add_part (ctx, "/", 1); ++ { ++ add_part (ctx, "/", 1); ++ if (grub_errno) ++ return grub_errno; ++ } ++ + add_part (ctx, (char *) &entry->data[pos + 2], + entry->data[pos + 1]); + ctx->was_continue = (entry->data[pos] & 1); +@@ -653,6 +664,11 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry, + add_part (ctx, "/", 1); + break; + } ++ ++ /* Check if grub_realloc() failed in add_part(). */ ++ if (grub_errno) ++ return grub_errno; ++ + /* In pos + 1 the length of the `Component Record' is + stored. */ + pos += entry->data[pos + 1] + 2; diff --git a/0231-font-Do-not-load-more-than-one-NAME-section.patch b/0231-font-Do-not-load-more-than-one-NAME-section.patch new file mode 100644 index 0000000..a1da629 --- /dev/null +++ b/0231-font-Do-not-load-more-than-one-NAME-section.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Kiper +Date: Tue, 7 Jul 2020 15:36:26 +0200 +Subject: [PATCH] font: Do not load more than one NAME section + +The GRUB font file can have one NAME section only. Though if somebody +crafts a broken font file with many NAME sections and loads it then the +GRUB leaks memory. So, prevent against that by loading first NAME +section and failing in controlled way on following one. + +Reported-by: Chris Coulson +Signed-off-by: Daniel Kiper +Reviewed-by: Jan Setje-Eilers +Upstream-commit-id: 482814113dc +--- + grub-core/font/font.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/font/font.c b/grub-core/font/font.c +index 5edb477ac2e..d09bb38d896 100644 +--- a/grub-core/font/font.c ++++ b/grub-core/font/font.c +@@ -532,6 +532,12 @@ grub_font_load (const char *filename) + if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME, + sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0) + { ++ if (font->name != NULL) ++ { ++ grub_error (GRUB_ERR_BAD_FONT, "invalid font file: too many NAME sections"); ++ goto fail; ++ } ++ + font->name = read_section_as_string (§ion); + if (!font->name) + goto fail; diff --git a/0232-gfxmenu-Fix-double-free-in-load_image.patch b/0232-gfxmenu-Fix-double-free-in-load_image.patch new file mode 100644 index 0000000..97416b9 --- /dev/null +++ b/0232-gfxmenu-Fix-double-free-in-load_image.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 20:41:56 +0000 +Subject: [PATCH] gfxmenu: Fix double free in load_image() + +self->bitmap should be zeroed after free. Otherwise, there is a chance +to double free (USE_AFTER_FREE) it later in rescale_image(). + +Fixes: CID 292472 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: 5d3e84b15a4 +--- + grub-core/gfxmenu/gui_image.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/grub-core/gfxmenu/gui_image.c b/grub-core/gfxmenu/gui_image.c +index 29784ed2d9a..6b2e976f16e 100644 +--- a/grub-core/gfxmenu/gui_image.c ++++ b/grub-core/gfxmenu/gui_image.c +@@ -195,7 +195,10 @@ load_image (grub_gui_image_t self, const char *path) + return grub_errno; + + if (self->bitmap && (self->bitmap != self->raw_bitmap)) +- grub_video_bitmap_destroy (self->bitmap); ++ { ++ grub_video_bitmap_destroy (self->bitmap); ++ self->bitmap = 0; ++ } + if (self->raw_bitmap) + grub_video_bitmap_destroy (self->raw_bitmap); + diff --git a/0233-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch b/0233-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch new file mode 100644 index 0000000..235376b --- /dev/null +++ b/0233-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 21:30:43 +0000 +Subject: [PATCH] xnu: Fix double free in grub_xnu_devprop_add_property() + +grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get +allocated and freed in the caller. + +Minor improvement: do prop fields initialization after memory allocations. + +Fixes: CID 292442, CID 292457, CID 292460, CID 292466 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: 4d5e2d13519 +--- + grub-core/loader/i386/xnu.c | 19 +++++++++---------- + 1 file changed, 9 insertions(+), 10 deletions(-) + +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index b7d176b5d30..e9e11925972 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -262,20 +262,19 @@ grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev, + if (!prop) + return grub_errno; + ++ prop->data = grub_malloc (datalen); ++ if (!prop->data) ++ { ++ grub_free (prop); ++ return grub_errno; ++ } ++ grub_memcpy (prop->data, data, datalen); ++ + prop->name = utf8; + prop->name16 = utf16; + prop->name16len = utf16len; +- + prop->length = datalen; +- prop->data = grub_malloc (prop->length); +- if (!prop->data) +- { +- grub_free (prop->name); +- grub_free (prop->name16); +- grub_free (prop); +- return grub_errno; +- } +- grub_memcpy (prop->data, data, prop->length); ++ + grub_list_push (GRUB_AS_LIST_P (&dev->properties), + GRUB_AS_LIST (prop)); + return GRUB_ERR_NONE; diff --git a/0234-lzma-Make-sure-we-don-t-dereference-past-array.patch b/0234-lzma-Make-sure-we-don-t-dereference-past-array.patch new file mode 100644 index 0000000..d5a31f5 --- /dev/null +++ b/0234-lzma-Make-sure-we-don-t-dereference-past-array.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Thu, 9 Jul 2020 03:05:23 +0000 +Subject: [PATCH] lzma: Make sure we don't dereference past array + +The two dimensional array p->posSlotEncoder[4][64] is being dereferenced +using the GetLenToPosState() macro which checks if len is less than 5, +and if so subtracts 2 from it. If len = 0, that is 0 - 2 = 4294967294. +Obviously we don't want to dereference that far out so we check if the +position found is greater or equal kNumLenToPosStates (4) and bail out. + +N.B.: Upstream LZMA 18.05 and later has this function completely rewritten +without any history. + +Fixes: CID 51526 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Upstream-commit-id: f91e043bda4 +--- + grub-core/lib/LzmaEnc.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/grub-core/lib/LzmaEnc.c b/grub-core/lib/LzmaEnc.c +index f2ec04a8c28..753e56a95e3 100644 +--- a/grub-core/lib/LzmaEnc.c ++++ b/grub-core/lib/LzmaEnc.c +@@ -1877,13 +1877,19 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize + } + else + { +- UInt32 posSlot; ++ UInt32 posSlot, lenToPosState; + RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); + p->state = kMatchNextStates[p->state]; + LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); + pos -= LZMA_NUM_REPS; + GetPosSlot(pos, posSlot); +- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); ++ lenToPosState = GetLenToPosState(len); ++ if (lenToPosState >= kNumLenToPosStates) ++ { ++ p->result = SZ_ERROR_DATA; ++ return CheckErrors(p); ++ } ++ RcTree_Encode(&p->rc, p->posSlotEncoder[lenToPosState], kNumPosSlotBits, posSlot); + + if (posSlot >= kStartPosModelIndex) + { diff --git a/0235-term-Fix-overflow-on-user-inputs.patch b/0235-term-Fix-overflow-on-user-inputs.patch new file mode 100644 index 0000000..b381e45 --- /dev/null +++ b/0235-term-Fix-overflow-on-user-inputs.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Tue, 7 Jul 2020 15:12:25 -0400 +Subject: [PATCH] term: Fix overflow on user inputs + +This requires a very weird input from the serial interface but can cause +an overflow in input_buf (keys) overwriting the next variable (npending) +with the user choice: + +(pahole output) + +struct grub_terminfo_input_state { + int input_buf[6]; /* 0 24 */ + int npending; /* 24 4 */ <- CORRUPT + ...snip... + +The magic string requires causing this is "ESC,O,],0,1,2,q" and we overflow +npending with "q" (aka increase npending to 161). The simplest fix is to +just to disallow overwrites input_buf, which exactly what this patch does. + +Fixes: CID 292449 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Upstream-commit-id: 98dfa546777 +--- + grub-core/term/terminfo.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c +index 537a5c0cb0b..44d0b3b19fb 100644 +--- a/grub-core/term/terminfo.c ++++ b/grub-core/term/terminfo.c +@@ -398,7 +398,7 @@ grub_terminfo_getwh (struct grub_term_output *term) + } + + static void +-grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, ++grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, int max_len, + int (*readkey) (struct grub_term_input *term)) + { + int c; +@@ -414,6 +414,9 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len, + if (c == -1) \ + return; \ + \ ++ if (*len >= max_len) \ ++ return; \ ++ \ + keys[*len] = c; \ + (*len)++; \ + } +@@ -602,8 +605,8 @@ grub_terminfo_getkey (struct grub_term_input *termi) + return ret; + } + +- grub_terminfo_readkey (termi, data->input_buf, +- &data->npending, data->readkey); ++ grub_terminfo_readkey (termi, data->input_buf, &data->npending, ++ GRUB_TERMINFO_READKEY_MAX_LEN, data->readkey); + + #if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) + if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC diff --git a/0236-udf-Fix-memory-leak.patch b/0236-udf-Fix-memory-leak.patch new file mode 100644 index 0000000..6b8f092 --- /dev/null +++ b/0236-udf-Fix-memory-leak.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Tue, 7 Jul 2020 22:02:31 -0400 +Subject: [PATCH] udf: Fix memory leak + +Fixes: CID 73796 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Reviewed-by: Jan Setje-Eilers +Upstream-commit-id: 8da62d8183c +--- + grub-core/fs/udf.c | 17 +++++++++++++---- + 1 file changed, 13 insertions(+), 4 deletions(-) + +diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c +index 21ac7f4460d..2ac5c1d0048 100644 +--- a/grub-core/fs/udf.c ++++ b/grub-core/fs/udf.c +@@ -965,8 +965,10 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, + return 0; + + if (grub_udf_read_icb (dir->data, &dirent.icb, child)) +- return 0; +- ++ { ++ grub_free (child); ++ return 0; ++ } + if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT) + { + /* This is the parent directory. */ +@@ -988,11 +990,18 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir, + dirent.file_ident_length, + (char *) raw)) + != dirent.file_ident_length) +- return 0; ++ { ++ grub_free (child); ++ return 0; ++ } + + filename = read_string (raw, dirent.file_ident_length, 0); + if (!filename) +- grub_print_error (); ++ { ++ /* As the hook won't get called. */ ++ grub_free (child); ++ grub_print_error (); ++ } + + if (filename && hook (filename, type, child, hook_data)) + { diff --git a/0237-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch b/0237-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch new file mode 100644 index 0000000..18c0a49 --- /dev/null +++ b/0237-multiboot2-Fix-memory-leak-if-grub_create_loader_cmd.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Konrad Rzeszutek Wilk +Date: Fri, 26 Jun 2020 10:51:43 -0400 +Subject: [PATCH] multiboot2: Fix memory leak if grub_create_loader_cmdline() + fails + +Fixes: CID 292468 + +Signed-off-by: Konrad Rzeszutek Wilk +Reviewed-by: Daniel Kiper +Upstream-commit-id: cd6760b6289 +--- + grub-core/loader/multiboot_mbi2.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 53da7861516..0efc660620e 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -1070,7 +1070,11 @@ grub_multiboot2_add_module (grub_addr_t start, grub_size_t size, + err = grub_create_loader_cmdline (argc, argv, newmod->cmdline, + newmod->cmdline_size, GRUB_VERIFY_MODULE_CMDLINE); + if (err) +- return err; ++ { ++ grub_free (newmod->cmdline); ++ grub_free (newmod); ++ return err; ++ } + + if (modules_last) + modules_last->next = newmod; diff --git a/0238-tftp-Do-not-use-priority-queue.patch b/0238-tftp-Do-not-use-priority-queue.patch new file mode 100644 index 0000000..9a1750e --- /dev/null +++ b/0238-tftp-Do-not-use-priority-queue.patch @@ -0,0 +1,278 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Thu, 9 Jul 2020 08:10:40 +0000 +Subject: [PATCH] tftp: Do not use priority queue + +There is not need to reassemble the order of blocks. Per RFC 1350, +server must wait for the ACK, before sending next block. Data packets +can be served immediately without putting them to priority queue. + +Logic to handle incoming packet is this: + - if packet block id equal to expected block id, then + process the packet, + - if packet block id is less than expected - this is retransmit + of old packet, then ACK it and drop the packet, + - if packet block id is more than expected - that shouldn't + happen, just drop the packet. + +It makes the tftp receive path code simpler, smaller and faster. +As a benefit, this change fixes CID# 73624 and CID# 96690, caused +by following while loop: + + while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) + +where tftph pointer is not moving from one iteration to another, causing +to serve same packet again. Luckily, double serving didn't happen due to +data->block++ during the first iteration. + +Fixes: CID 73624, CID 96690 + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: 8316694c4f7 +--- + grub-core/net/tftp.c | 162 ++++++++++++++++----------------------------------- + 1 file changed, 50 insertions(+), 112 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 4920c3a9783..22badd74316 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -25,7 +25,6 @@ + #include + #include + #include +-#include + #include + + GRUB_MOD_LICENSE ("GPLv3+"); +@@ -106,31 +105,8 @@ typedef struct tftp_data + int have_oack; + struct grub_error_saved save_err; + grub_net_udp_socket_t sock; +- grub_priority_queue_t pq; + } *tftp_data_t; + +-static int +-cmp_block (grub_uint16_t a, grub_uint16_t b) +-{ +- grub_int16_t i = (grub_int16_t) (a - b); +- if (i > 0) +- return +1; +- if (i < 0) +- return -1; +- return 0; +-} +- +-static int +-cmp (const void *a__, const void *b__) +-{ +- struct grub_net_buff *a_ = *(struct grub_net_buff **) a__; +- struct grub_net_buff *b_ = *(struct grub_net_buff **) b__; +- struct tftphdr *a = (struct tftphdr *) a_->data; +- struct tftphdr *b = (struct tftphdr *) b_->data; +- /* We want the first elements to be on top. */ +- return -cmp_block (grub_be_to_cpu16 (a->u.data.block), grub_be_to_cpu16 (b->u.data.block)); +-} +- + static grub_err_t + ack (tftp_data_t data, grub_uint64_t block) + { +@@ -207,73 +183,60 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + return GRUB_ERR_NONE; + } + +- err = grub_priority_queue_push (data->pq, &nb); +- if (err) +- return err; ++ /* Ack old/retransmitted block. */ ++ if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1) ++ ack (data, grub_be_to_cpu16 (tftph->u.data.block)); ++ /* Ignore unexpected block. */ ++ else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1) ++ grub_dprintf ("tftp", "TFTP unexpected block # %d\n", tftph->u.data.block); ++ else ++ { ++ unsigned size; + +- { +- struct grub_net_buff **nb_top_p, *nb_top; +- while (1) +- { +- nb_top_p = grub_priority_queue_top (data->pq); +- if (!nb_top_p) +- return GRUB_ERR_NONE; +- nb_top = *nb_top_p; +- tftph = (struct tftphdr *) nb_top->data; +- if (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) >= 0) +- break; +- ack (data, grub_be_to_cpu16 (tftph->u.data.block)); +- grub_netbuff_free (nb_top); +- grub_priority_queue_pop (data->pq); +- } +- while (cmp_block (grub_be_to_cpu16 (tftph->u.data.block), data->block + 1) == 0) +- { +- unsigned size; +- +- grub_priority_queue_pop (data->pq); +- +- if (file->device->net->packs.count < 50) ++ if (file->device->net->packs.count < 50) ++ { + err = ack (data, data->block + 1); +- else +- { +- file->device->net->stall = 1; +- err = 0; +- } +- if (err) +- return err; ++ if (err) ++ return err; ++ } ++ else ++ file->device->net->stall = 1; + +- err = grub_netbuff_pull (nb_top, sizeof (tftph->opcode) + +- sizeof (tftph->u.data.block)); +- if (err) +- return err; +- size = nb_top->tail - nb_top->data; ++ err = grub_netbuff_pull (nb, sizeof (tftph->opcode) + ++ sizeof (tftph->u.data.block)); ++ if (err) ++ return err; ++ size = nb->tail - nb->data; + +- data->block++; +- if (size < data->block_size) +- { +- if (data->ack_sent < data->block) +- ack (data, data->block); +- file->device->net->eof = 1; +- file->device->net->stall = 1; +- grub_net_udp_close (data->sock); +- data->sock = NULL; +- } +- /* Prevent garbage in broken cards. Is it still necessary +- given that IP implementation has been fixed? +- */ +- if (size > data->block_size) +- { +- err = grub_netbuff_unput (nb_top, size - data->block_size); +- if (err) +- return err; +- } +- /* If there is data, puts packet in socket list. */ +- if ((nb_top->tail - nb_top->data) > 0) +- grub_net_put_packet (&file->device->net->packs, nb_top); +- else +- grub_netbuff_free (nb_top); +- } +- } ++ data->block++; ++ if (size < data->block_size) ++ { ++ if (data->ack_sent < data->block) ++ ack (data, data->block); ++ file->device->net->eof = 1; ++ file->device->net->stall = 1; ++ grub_net_udp_close (data->sock); ++ data->sock = NULL; ++ } ++ /* ++ * Prevent garbage in broken cards. Is it still necessary ++ * given that IP implementation has been fixed? ++ */ ++ if (size > data->block_size) ++ { ++ err = grub_netbuff_unput (nb, size - data->block_size); ++ if (err) ++ return err; ++ } ++ /* If there is data, puts packet in socket list. */ ++ if ((nb->tail - nb->data) > 0) ++ { ++ grub_net_put_packet (&file->device->net->packs, nb); ++ /* Do not free nb. */ ++ return GRUB_ERR_NONE; ++ } ++ } ++ grub_netbuff_free (nb); + return GRUB_ERR_NONE; + case TFTP_ERROR: + data->have_oack = 1; +@@ -287,19 +250,6 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + } + } + +-static void +-destroy_pq (tftp_data_t data) +-{ +- struct grub_net_buff **nb_p; +- while ((nb_p = grub_priority_queue_top (data->pq))) +- { +- grub_netbuff_free (*nb_p); +- grub_priority_queue_pop (data->pq); +- } +- +- grub_priority_queue_destroy (data->pq); +-} +- + /* Create a normalized copy of the filename. + Compress any string of consecutive forward slashes to a single forward + slash. */ +@@ -395,13 +345,6 @@ tftp_open (struct grub_file *file, const char *filename) + file->not_easily_seekable = 1; + file->data = data; + +- data->pq = grub_priority_queue_new (sizeof (struct grub_net_buff *), cmp); +- if (!data->pq) +- { +- grub_free (data); +- return grub_errno; +- } +- + grub_dprintf ("tftp", "resolving address for %s\n", file->device->net->server); + err = grub_net_resolve_address (file->device->net->server, &addr); + if (err) +@@ -410,7 +353,6 @@ tftp_open (struct grub_file *file, const char *filename) + grub_dprintf ("tftp", "file_size is %llu, block_size is %llu\n", + (unsigned long long)data->file_size, + (unsigned long long)data->block_size); +- destroy_pq (data); + grub_free (data); + return err; + } +@@ -422,7 +364,6 @@ tftp_open (struct grub_file *file, const char *filename) + if (!data->sock) + { + grub_dprintf ("tftp", "connection failed\n"); +- destroy_pq (data); + grub_free (data); + return grub_errno; + } +@@ -436,7 +377,6 @@ tftp_open (struct grub_file *file, const char *filename) + if (err) + { + grub_net_udp_close (data->sock); +- destroy_pq (data); + grub_free (data); + return err; + } +@@ -453,7 +393,6 @@ tftp_open (struct grub_file *file, const char *filename) + if (grub_errno) + { + grub_net_udp_close (data->sock); +- destroy_pq (data); + grub_free (data); + return grub_errno; + } +@@ -496,7 +435,6 @@ tftp_close (struct grub_file *file) + grub_print_error (); + grub_net_udp_close (data->sock); + } +- destroy_pq (data); + grub_free (data); + return GRUB_ERR_NONE; + } diff --git a/0239-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch b/0239-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch new file mode 100644 index 0000000..b68f3a1 --- /dev/null +++ b/0239-multiboot2-Set-min-address-for-mbi-allocation-to-0x1.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lukasz Hawrylko +Date: Mon, 16 Dec 2019 11:15:55 +0100 +Subject: [PATCH] multiboot2: Set min address for mbi allocation to 0x1000 + +In some cases GRUB2 allocates multiboot2 structure at 0 address, that is +a confusing behavior. Consumers of that structure can have internal NULL-checks +that will throw an error when get a pointer to data allocated at address 0. +To prevent that, define min address for mbi allocation on x86 and x86_64 +platforms. + +Signed-off-by: Lukasz Hawrylko +Reviewed-by: Daniel Kiper +Upstream-commit-id: 0f3f5b7c13f +--- + grub-core/loader/multiboot_mbi2.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 0efc660620e..e88c9f4884f 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -48,6 +48,12 @@ + #define HAS_VGA_TEXT 0 + #endif + ++#if defined (__i386__) || defined (__x86_64__) ++#define MBI_MIN_ADDR 0x1000 ++#else ++#define MBI_MIN_ADDR 0 ++#endif ++ + struct module + { + struct module *next; +@@ -708,7 +714,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) + COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); + + err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, +- 0, 0xffffffff - bufsize, ++ MBI_MIN_ADDR, 0xffffffff - bufsize, + bufsize, MULTIBOOT_TAG_ALIGN, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) diff --git a/0240-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch b/0240-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch new file mode 100644 index 0000000..3c054cc --- /dev/null +++ b/0240-relocator-Protect-grub_relocator_alloc_chunk_addr-in.patch @@ -0,0 +1,147 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 15 Jul 2020 06:42:37 +0000 +Subject: [PATCH] relocator: Protect grub_relocator_alloc_chunk_addr() input + args against integer underflow/overflow + +Use arithmetic macros from safemath.h to accomplish it. In this commit, +I didn't want to be too paranoid to check every possible math equation +for overflow/underflow. Only obvious places (with non zero chance of +overflow/underflow) were refactored. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: ebb15735f10 +--- + grub-core/loader/i386/linux.c | 9 +++++++-- + grub-core/loader/i386/pc/linux.c | 9 +++++++-- + grub-core/loader/i386/xen.c | 12 ++++++++++-- + grub-core/loader/xnu.c | 11 +++++++---- + 4 files changed, 31 insertions(+), 10 deletions(-) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 201e6597c6d..90f2315f847 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -548,9 +549,13 @@ grub_linux_boot (void) + + { + grub_relocator_chunk_t ch; ++ grub_size_t sz; ++ ++ if (grub_add (ctx.real_size, efi_mmap_size, &sz)) ++ return GRUB_ERR_OUT_OF_RANGE; ++ + err = grub_relocator_alloc_chunk_addr (relocator, &ch, +- ctx.real_mode_target, +- (ctx.real_size + efi_mmap_size)); ++ ctx.real_mode_target, sz); + if (err) + return err; + real_mode_mem = get_virtual_current_address (ch); +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 0bf0e13d647..33d1196b1e2 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -231,8 +232,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + setup_sects = GRUB_LINUX_DEFAULT_SETUP_SECTS; + + real_size = setup_sects << GRUB_DISK_SECTOR_BITS; +- grub_linux16_prot_size = grub_file_size (file) +- - real_size - GRUB_DISK_SECTOR_SIZE; ++ if (grub_sub (grub_file_size (file), real_size, &grub_linux16_prot_size) || ++ grub_sub (grub_linux16_prot_size, GRUB_DISK_SECTOR_SIZE, &grub_linux16_prot_size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + + if (! grub_linux_is_bzimage + && GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size +diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c +index 8f662c8ac89..cd24874ca32 100644 +--- a/grub-core/loader/i386/xen.c ++++ b/grub-core/loader/i386/xen.c +@@ -41,6 +41,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -636,6 +637,7 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), + grub_relocator_chunk_t ch; + grub_addr_t kern_start; + grub_addr_t kern_end; ++ grub_size_t sz; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); +@@ -703,8 +705,14 @@ grub_cmd_xen (grub_command_t cmd __attribute__ ((unused)), + + xen_state.max_addr = ALIGN_UP (kern_end, PAGE_SIZE); + +- err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, +- kern_end - kern_start); ++ ++ if (grub_sub (kern_end, kern_start, &sz)) ++ { ++ err = GRUB_ERR_OUT_OF_RANGE; ++ goto fail; ++ } ++ ++ err = grub_relocator_alloc_chunk_addr (xen_state.relocator, &ch, kern_start, sz); + if (err) + goto fail; + kern_chunk_src = get_virtual_current_address (ch); +diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c +index 2f0ebd0b8bf..3fd653993f7 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -60,15 +61,17 @@ grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target) + { + grub_err_t err; + grub_relocator_chunk_t ch; ++ grub_addr_t tgt; ++ ++ if (grub_add (grub_xnu_heap_target_start, grub_xnu_heap_size, &tgt)) ++ return GRUB_ERR_OUT_OF_RANGE; + +- err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, +- grub_xnu_heap_target_start +- + grub_xnu_heap_size, size); ++ err = grub_relocator_alloc_chunk_addr (grub_xnu_relocator, &ch, tgt, size); + if (err) + return err; + + *src = get_virtual_current_address (ch); +- *target = grub_xnu_heap_target_start + grub_xnu_heap_size; ++ *target = tgt; + grub_xnu_heap_size += size; + grub_dprintf ("xnu", "val=%p\n", *src); + return GRUB_ERR_NONE; diff --git a/0241-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch b/0241-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch new file mode 100644 index 0000000..2ac5395 --- /dev/null +++ b/0241-relocator-Protect-grub_relocator_alloc_chunk_align-m.patch @@ -0,0 +1,335 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Wed, 8 Jul 2020 01:44:38 +0000 +Subject: [PATCH] relocator: Protect grub_relocator_alloc_chunk_align() + max_addr against integer underflow + +This commit introduces integer underflow mitigation in max_addr calculation +in grub_relocator_alloc_chunk_align() invocation. + +It consists of 2 fixes: + 1. Introduced grub_relocator_alloc_chunk_align_safe() wrapper function to perform + sanity check for min/max and size values, and to make safe invocation of + grub_relocator_alloc_chunk_align() with validated max_addr value. Replace all + invocations such as grub_relocator_alloc_chunk_align(..., min_addr, max_addr - size, size, ...) + by grub_relocator_alloc_chunk_align_safe(..., min_addr, max_addr, size, ...). + 2. Introduced UP_TO_TOP32(s) macro for the cases where max_addr is 32-bit top + address (0xffffffff - size + 1) or similar. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: 10498c8ba17 +--- + grub-core/lib/i386/relocator.c | 28 +++++++++++----------------- + grub-core/lib/mips/relocator.c | 6 ++---- + grub-core/lib/powerpc/relocator.c | 6 ++---- + grub-core/lib/x86_64/efi/relocator.c | 7 +++---- + grub-core/loader/i386/linux.c | 5 ++--- + grub-core/loader/i386/multiboot_mbi.c | 7 +++---- + grub-core/loader/i386/pc/linux.c | 6 ++---- + grub-core/loader/mips/linux.c | 9 +++------ + grub-core/loader/multiboot.c | 2 +- + grub-core/loader/multiboot_elfxx.c | 10 +++++----- + grub-core/loader/multiboot_mbi2.c | 10 +++++----- + grub-core/loader/xnu_resume.c | 2 +- + include/grub/relocator.h | 29 +++++++++++++++++++++++++++++ + 13 files changed, 69 insertions(+), 58 deletions(-) + +diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c +index 71dd4f0ab0c..34cbe834fa3 100644 +--- a/grub-core/lib/i386/relocator.c ++++ b/grub-core/lib/i386/relocator.c +@@ -83,11 +83,10 @@ grub_relocator32_boot (struct grub_relocator *rel, + /* Specific memory range due to Global Descriptor Table for use by payload + that we will store in returned chunk. The address range and preference + are based on "THE LINUX/x86 BOOT PROTOCOL" specification. */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x1000, +- 0x9a000 - RELOCATOR_SIZEOF (32), +- RELOCATOR_SIZEOF (32), 16, +- GRUB_RELOCATOR_PREFERENCE_LOW, +- avoid_efi_bootservices); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x1000, 0x9a000, ++ RELOCATOR_SIZEOF (32), 16, ++ GRUB_RELOCATOR_PREFERENCE_LOW, ++ avoid_efi_bootservices); + if (err) + return err; + +@@ -125,13 +124,10 @@ grub_relocator16_boot (struct grub_relocator *rel, + grub_relocator_chunk_t ch; + + /* Put it higher than the byte it checks for A20 check. */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0x8010, +- 0xa0000 - RELOCATOR_SIZEOF (16) +- - GRUB_RELOCATOR16_STACK_SIZE, +- RELOCATOR_SIZEOF (16) +- + GRUB_RELOCATOR16_STACK_SIZE, 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, +- 0); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0x8010, 0xa0000, ++ RELOCATOR_SIZEOF (16) + ++ GRUB_RELOCATOR16_STACK_SIZE, 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + +@@ -183,11 +179,9 @@ grub_relocator64_boot (struct grub_relocator *rel, + void *relst; + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, min_addr, +- max_addr - RELOCATOR_SIZEOF (64), +- RELOCATOR_SIZEOF (64), 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, +- 0); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, min_addr, max_addr, ++ RELOCATOR_SIZEOF (64), 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + +diff --git a/grub-core/lib/mips/relocator.c b/grub-core/lib/mips/relocator.c +index 9d5f49cb93a..743b213e695 100644 +--- a/grub-core/lib/mips/relocator.c ++++ b/grub-core/lib/mips/relocator.c +@@ -120,10 +120,8 @@ grub_relocator32_boot (struct grub_relocator *rel, + unsigned i; + grub_addr_t vtarget; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- (0xffffffff - stateset_size) +- + 1, stateset_size, +- sizeof (grub_uint32_t), ++ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), ++ stateset_size, sizeof (grub_uint32_t), + GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; +diff --git a/grub-core/lib/powerpc/relocator.c b/grub-core/lib/powerpc/relocator.c +index bdf2b111be7..8ffb8b68683 100644 +--- a/grub-core/lib/powerpc/relocator.c ++++ b/grub-core/lib/powerpc/relocator.c +@@ -115,10 +115,8 @@ grub_relocator32_boot (struct grub_relocator *rel, + unsigned i; + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- (0xffffffff - stateset_size) +- + 1, stateset_size, +- sizeof (grub_uint32_t), ++ err = grub_relocator_alloc_chunk_align (rel, &ch, 0, UP_TO_TOP32 (stateset_size), ++ stateset_size, sizeof (grub_uint32_t), + GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; +diff --git a/grub-core/lib/x86_64/efi/relocator.c b/grub-core/lib/x86_64/efi/relocator.c +index 3caef7a4021..7d200a125ee 100644 +--- a/grub-core/lib/x86_64/efi/relocator.c ++++ b/grub-core/lib/x86_64/efi/relocator.c +@@ -50,10 +50,9 @@ grub_relocator64_efi_boot (struct grub_relocator *rel, + * 64-bit relocator code may live above 4 GiB quite well. + * However, I do not want ask for problems. Just in case. + */ +- err = grub_relocator_alloc_chunk_align (rel, &ch, 0, +- 0x100000000 - RELOCATOR_SIZEOF (64_efi), +- RELOCATOR_SIZEOF (64_efi), 16, +- GRUB_RELOCATOR_PREFERENCE_NONE, 1); ++ err = grub_relocator_alloc_chunk_align_safe (rel, &ch, 0, 0x100000000, ++ RELOCATOR_SIZEOF (64_efi), 16, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) + return err; + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 90f2315f847..7d0c987cd91 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -182,9 +182,8 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, + for (; err && *align + 1 > min_align; (*align)--) + { + grub_errno = GRUB_ERR_NONE; +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- 0x1000000, +- 0xffffffff & ~prot_size, ++ err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, ++ UP_TO_TOP32 (prot_size), + prot_size, 1 << *align, + GRUB_RELOCATOR_PREFERENCE_LOW, + 1); +diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c +index ad3cc292fd1..a67d9d0a808 100644 +--- a/grub-core/loader/i386/multiboot_mbi.c ++++ b/grub-core/loader/i386/multiboot_mbi.c +@@ -466,10 +466,9 @@ grub_multiboot_make_mbi (grub_uint32_t *target) + + bufsize = grub_multiboot_get_mbi_size (); + +- err = grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, +- 0x10000, 0xa0000 - bufsize, +- bufsize, 4, +- GRUB_RELOCATOR_PREFERENCE_NONE, 0); ++ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot_relocator, &ch, ++ 0x10000, 0xa0000, bufsize, 4, ++ GRUB_RELOCATOR_PREFERENCE_NONE, 0); + if (err) + return err; + ptrorig = get_virtual_current_address (ch); +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 33d1196b1e2..f1ad185ddc2 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -463,10 +463,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + + { + grub_relocator_chunk_t ch; +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- addr_min, addr_max - size, +- size, 0x1000, +- GRUB_RELOCATOR_PREFERENCE_HIGH, 0); ++ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, addr_min, addr_max, size, ++ 0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 0); + if (err) + return err; + initrd_chunk = get_virtual_current_address (ch); +diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c +index 7b723bf189d..e4ed95921df 100644 +--- a/grub-core/loader/mips/linux.c ++++ b/grub-core/loader/mips/linux.c +@@ -442,12 +442,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + { + grub_relocator_chunk_t ch; + +- err = grub_relocator_alloc_chunk_align (relocator, &ch, +- (target_addr & 0x1fffffff) +- + linux_size + 0x10000, +- (0x10000000 - size), +- size, 0x10000, +- GRUB_RELOCATOR_PREFERENCE_NONE, 0); ++ err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, (target_addr & 0x1fffffff) + ++ linux_size + 0x10000, 0x10000000, size, ++ 0x10000, GRUB_RELOCATOR_PREFERENCE_NONE, 0); + + if (err) + goto fail; +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 3e6ad166dc9..3e286908dda 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -404,7 +404,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, +- lowest_addr, (0xffffffff - size) + 1, ++ lowest_addr, UP_TO_TOP32 (size), + size, MULTIBOOT_MOD_ALIGN, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c +index cc6853692a8..f2318e0d165 100644 +--- a/grub-core/loader/multiboot_elfxx.c ++++ b/grub-core/loader/multiboot_elfxx.c +@@ -109,10 +109,10 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + if (load_size > mld->max_addr || mld->min_addr > mld->max_addr - load_size) + return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); + +- err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, +- mld->min_addr, mld->max_addr - load_size, +- load_size, mld->align ? mld->align : 1, +- mld->preference, mld->avoid_efi_boot_services); ++ err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch, ++ mld->min_addr, mld->max_addr, ++ load_size, mld->align ? mld->align : 1, ++ mld->preference, mld->avoid_efi_boot_services); + + if (err) + { +@@ -256,7 +256,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) + continue; + + err = grub_relocator_alloc_chunk_align (GRUB_MULTIBOOT (relocator), &ch, 0, +- (0xffffffff - sh->sh_size) + 1, ++ UP_TO_TOP32 (sh->sh_size), + sh->sh_size, sh->sh_addralign, + GRUB_RELOCATOR_PREFERENCE_NONE, + mld->avoid_efi_boot_services); +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index e88c9f4884f..9a943d7bdd7 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -301,10 +301,10 @@ grub_multiboot2_load (grub_file_t file, const char *filename) + return grub_error (GRUB_ERR_BAD_OS, "invalid min/max address and/or load size"); + } + +- err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, +- mld.min_addr, mld.max_addr - code_size, +- code_size, mld.align ? mld.align : 1, +- mld.preference, keep_bs); ++ err = grub_relocator_alloc_chunk_align_safe (grub_multiboot2_relocator, &ch, ++ mld.min_addr, mld.max_addr, ++ code_size, mld.align ? mld.align : 1, ++ mld.preference, keep_bs); + } + else + err = grub_relocator_alloc_chunk_addr (grub_multiboot2_relocator, +@@ -714,7 +714,7 @@ grub_multiboot2_make_mbi (grub_uint32_t *target) + COMPILE_TIME_ASSERT (MULTIBOOT_TAG_ALIGN % sizeof (grub_properly_aligned_t) == 0); + + err = grub_relocator_alloc_chunk_align (grub_multiboot2_relocator, &ch, +- MBI_MIN_ADDR, 0xffffffff - bufsize, ++ MBI_MIN_ADDR, UP_TO_TOP32 (bufsize), + bufsize, MULTIBOOT_TAG_ALIGN, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +diff --git a/grub-core/loader/xnu_resume.c b/grub-core/loader/xnu_resume.c +index 8089804d482..d648ef0cd3a 100644 +--- a/grub-core/loader/xnu_resume.c ++++ b/grub-core/loader/xnu_resume.c +@@ -129,7 +129,7 @@ grub_xnu_resume (char *imagename) + { + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_align (grub_xnu_relocator, &ch, 0, +- (0xffffffff - hibhead.image_size) + 1, ++ UP_TO_TOP32 (hibhead.image_size), + hibhead.image_size, + GRUB_XNU_PAGESIZE, + GRUB_RELOCATOR_PREFERENCE_NONE, 0); +diff --git a/include/grub/relocator.h b/include/grub/relocator.h +index 24d8672d22c..1b3bdd92ac6 100644 +--- a/include/grub/relocator.h ++++ b/include/grub/relocator.h +@@ -49,6 +49,35 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, + int preference, + int avoid_efi_boot_services); + ++/* ++ * Wrapper for grub_relocator_alloc_chunk_align() with purpose of ++ * protecting against integer underflow. ++ * ++ * Compare to its callee, max_addr has different meaning here. ++ * It covers entire chunk and not just start address of the chunk. ++ */ ++static inline grub_err_t ++grub_relocator_alloc_chunk_align_safe (struct grub_relocator *rel, ++ grub_relocator_chunk_t *out, ++ grub_phys_addr_t min_addr, ++ grub_phys_addr_t max_addr, ++ grub_size_t size, grub_size_t align, ++ int preference, ++ int avoid_efi_boot_services) ++{ ++ /* Sanity check and ensure following equation (max_addr - size) is safe. */ ++ if (max_addr < size || (max_addr - size) < min_addr) ++ return GRUB_ERR_OUT_OF_RANGE; ++ ++ return grub_relocator_alloc_chunk_align (rel, out, min_addr, ++ max_addr - size, ++ size, align, preference, ++ avoid_efi_boot_services); ++} ++ ++/* Top 32-bit address minus s bytes and plus 1 byte. */ ++#define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1) ++ + #define GRUB_RELOCATOR_PREFERENCE_NONE 0 + #define GRUB_RELOCATOR_PREFERENCE_LOW 1 + #define GRUB_RELOCATOR_PREFERENCE_HIGH 2 diff --git a/0242-script-Remove-unused-fields-from-grub_script_functio.patch b/0242-script-Remove-unused-fields-from-grub_script_functio.patch new file mode 100644 index 0000000..93beaac --- /dev/null +++ b/0242-script-Remove-unused-fields-from-grub_script_functio.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 10 Jul 2020 11:21:14 +0100 +Subject: [PATCH] script: Remove unused fields from grub_script_function struct + +Signed-off-by: Chris Coulson +Reviewed-by: Daniel Kiper +Upstream-commit-id: d04089c8e52 +--- + include/grub/script_sh.h | 5 ----- + 1 file changed, 5 deletions(-) + +diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h +index 360c2be1f05..b382bcf09bc 100644 +--- a/include/grub/script_sh.h ++++ b/include/grub/script_sh.h +@@ -359,13 +359,8 @@ struct grub_script_function + /* The script function. */ + struct grub_script *func; + +- /* The flags. */ +- unsigned flags; +- + /* The next element. */ + struct grub_script_function *next; +- +- int references; + }; + typedef struct grub_script_function *grub_script_function_t; + diff --git a/0243-script-Avoid-a-use-after-free-when-redefining-a-func.patch b/0243-script-Avoid-a-use-after-free-when-redefining-a-func.patch new file mode 100644 index 0000000..4435a7d --- /dev/null +++ b/0243-script-Avoid-a-use-after-free-when-redefining-a-func.patch @@ -0,0 +1,105 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Fri, 10 Jul 2020 14:41:45 +0100 +Subject: [PATCH] script: Avoid a use-after-free when redefining a function + during execution + +Defining a new function with the same name as a previously defined +function causes the grub_script and associated resources for the +previous function to be freed. If the previous function is currently +executing when a function with the same name is defined, this results +in use-after-frees when processing subsequent commands in the original +function. + +Instead, reject a new function definition if it has the same name as +a previously defined function, and that function is currently being +executed. Although a behavioural change, this should be backwards +compatible with existing configurations because they can't be +dependent on the current behaviour without being broken. + +Signed-off-by: Chris Coulson +Reviewed-by: Daniel Kiper +Upstream-commit-id: f6253a1f540 +--- + grub-core/script/execute.c | 2 ++ + grub-core/script/function.c | 16 +++++++++++++--- + include/grub/script_sh.h | 2 ++ + grub-core/script/parser.y | 3 ++- + 4 files changed, 19 insertions(+), 4 deletions(-) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index b55e171c931..d2f02cc5b38 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -872,7 +872,9 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args) + old_scope = scope; + scope = &new_scope; + ++ func->executing++; + ret = grub_script_execute (func->func); ++ func->executing--; + + function_return = 0; + active_loops = loops; +diff --git a/grub-core/script/function.c b/grub-core/script/function.c +index d36655e510f..3aad04bf9dd 100644 +--- a/grub-core/script/function.c ++++ b/grub-core/script/function.c +@@ -34,6 +34,7 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, + func = (grub_script_function_t) grub_malloc (sizeof (*func)); + if (! func) + return 0; ++ func->executing = 0; + + func->name = grub_strdup (functionname_arg->str); + if (! func->name) +@@ -60,10 +61,19 @@ grub_script_function_create (struct grub_script_arg *functionname_arg, + grub_script_function_t q; + + q = *p; +- grub_script_free (q->func); +- q->func = cmd; + grub_free (func); +- func = q; ++ if (q->executing > 0) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, ++ N_("attempt to redefine a function being executed")); ++ func = NULL; ++ } ++ else ++ { ++ grub_script_free (q->func); ++ q->func = cmd; ++ func = q; ++ } + } + else + { +diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h +index b382bcf09bc..6c48e075122 100644 +--- a/include/grub/script_sh.h ++++ b/include/grub/script_sh.h +@@ -361,6 +361,8 @@ struct grub_script_function + + /* The next element. */ + struct grub_script_function *next; ++ ++ unsigned executing; + }; + typedef struct grub_script_function *grub_script_function_t; + +diff --git a/grub-core/script/parser.y b/grub-core/script/parser.y +index 4f0ab8319e3..f80b86b6f15 100644 +--- a/grub-core/script/parser.y ++++ b/grub-core/script/parser.y +@@ -289,7 +289,8 @@ function: "function" "name" + grub_script_mem_free (state->func_mem); + else { + script->children = state->scripts; +- grub_script_function_create ($2, script); ++ if (!grub_script_function_create ($2, script)) ++ grub_script_free (script); + } + + state->scripts = $3; diff --git a/0244-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch b/0244-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch new file mode 100644 index 0000000..850fef7 --- /dev/null +++ b/0244-relocator-Fix-grub_relocator_alloc_chunk_align-top-m.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Fri, 17 Jul 2020 05:17:26 +0000 +Subject: [PATCH] relocator: Fix grub_relocator_alloc_chunk_align() top memory + allocation + +Current implementation of grub_relocator_alloc_chunk_align() +does not allow allocation of the top byte. + +Assuming input args are: + max_addr = 0xfffff000; + size = 0x1000; + +And this is valid. But following overflow protection will +unnecessarily move max_addr one byte down (to 0xffffefff): + if (max_addr > ~size) + max_addr = ~size; + +~size + 1 will fix the situation. In addition, check size +for non zero to do not zero max_addr. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Daniel Kiper +Upstream-commit-id: ab80a97eb1f +--- + grub-core/lib/relocator.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c +index 5847aac3643..f2c1944c28d 100644 +--- a/grub-core/lib/relocator.c ++++ b/grub-core/lib/relocator.c +@@ -1386,8 +1386,8 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel, + }; + grub_addr_t min_addr2 = 0, max_addr2; + +- if (max_addr > ~size) +- max_addr = ~size; ++ if (size && (max_addr > ~size)) ++ max_addr = ~size + 1; + + #ifdef GRUB_MACHINE_PCBIOS + if (min_addr < 0x1000) diff --git a/0245-hfsplus-fix-two-more-overflows.patch b/0245-hfsplus-fix-two-more-overflows.patch new file mode 100644 index 0000000..937918f --- /dev/null +++ b/0245-hfsplus-fix-two-more-overflows.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 14:43:31 -0400 +Subject: [PATCH] hfsplus: fix two more overflows + +Both node->size and node->namelen come from the supplied filesystem, +which may be user-supplied. We can't trust them for the math unless we +know they don't overflow; making sure they go through calloc() first +will give us that. + +Signed-off-by: Peter Jones +Reviewed-by: Darren Kenny +Upstream-commit-id: b4915078903 +--- + grub-core/fs/hfsplus.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c +index dae43becc97..9c4e4c88c99 100644 +--- a/grub-core/fs/hfsplus.c ++++ b/grub-core/fs/hfsplus.c +@@ -31,6 +31,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -475,8 +476,12 @@ grub_hfsplus_read_symlink (grub_fshelp_node_t node) + { + char *symlink; + grub_ssize_t numread; ++ grub_size_t sz = node->size; + +- symlink = grub_malloc (node->size + 1); ++ if (grub_add (sz, 1, &sz)) ++ return NULL; ++ ++ symlink = grub_malloc (sz); + if (!symlink) + return 0; + +@@ -715,8 +720,8 @@ list_nodes (void *record, void *hook_arg) + if (type == GRUB_FSHELP_UNKNOWN) + return 0; + +- filename = grub_malloc (grub_be_to_cpu16 (catkey->namelen) +- * GRUB_MAX_UTF8_PER_UTF16 + 1); ++ filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen), ++ GRUB_MAX_UTF8_PER_UTF16 + 1); + if (! filename) + return 0; + diff --git a/0246-lvm-fix-two-more-potential-data-dependent-alloc-over.patch b/0246-lvm-fix-two-more-potential-data-dependent-alloc-over.patch new file mode 100644 index 0000000..31e7f07 --- /dev/null +++ b/0246-lvm-fix-two-more-potential-data-dependent-alloc-over.patch @@ -0,0 +1,108 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 15:48:20 -0400 +Subject: [PATCH] lvm: fix two more potential data-dependent alloc overflows + +It appears to be possible to make a (possibly invalid) lvm PV with a +metadata size field that overflows our type when adding it to the +address we've allocated. Even if it doesn't, it may be possible to do +so with the math using the outcome of that as an operand. Check them +both. + +Signed-off-by: Peter Jones +Signed-off-by: Darren Kenny +Upstream-commit-id: 45ec6046ea0 +--- + grub-core/disk/lvm.c | 47 +++++++++++++++++++++++++++++++++++++++-------- + 1 file changed, 39 insertions(+), 8 deletions(-) + +diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c +index 8e76d1ae121..cca8ec668ba 100644 +--- a/grub-core/disk/lvm.c ++++ b/grub-core/disk/lvm.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_UTIL + #include +@@ -102,10 +103,11 @@ grub_lvm_detect (grub_disk_t disk, + { + grub_err_t err; + grub_uint64_t mda_offset, mda_size; ++ grub_size_t ptr; + char buf[GRUB_LVM_LABEL_SIZE]; + char vg_id[GRUB_LVM_ID_STRLEN+1]; + char pv_id[GRUB_LVM_ID_STRLEN+1]; +- char *metadatabuf, *vgname; ++ char *metadatabuf, *mda_end, *vgname; + const char *p, *q; + struct grub_lvm_label_header *lh = (struct grub_lvm_label_header *) buf; + struct grub_lvm_pv_header *pvh; +@@ -206,19 +208,31 @@ grub_lvm_detect (grub_disk_t disk, + grub_le_to_cpu64 (rlocn->size) - + grub_le_to_cpu64 (mdah->size)); + } +- p = q = metadatabuf + grub_le_to_cpu64 (rlocn->offset); + +- while (*q != ' ' && q < metadatabuf + mda_size) +- q++; +- +- if (q == metadatabuf + mda_size) ++ if (grub_add ((grub_size_t)metadatabuf, ++ (grub_size_t)grub_le_to_cpu64 (rlocn->offset), ++ &ptr)) + { ++error_parsing_metadata: + #ifdef GRUB_UTIL + grub_util_info ("error parsing metadata"); + #endif + goto fail2; + } + ++ p = q = (char *)ptr; ++ ++ if (grub_add ((grub_size_t)metadatabuf, (grub_size_t)mda_size, &ptr)) ++ goto error_parsing_metadata; ++ ++ mda_end = (char *)ptr; ++ ++ while (*q != ' ' && q < mda_end) ++ q++; ++ ++ if (q == mda_end) ++ goto error_parsing_metadata; ++ + vgname_len = q - p; + vgname = grub_malloc (vgname_len + 1); + if (!vgname) +@@ -368,8 +382,25 @@ grub_lvm_detect (grub_disk_t disk, + { + const char *iptr; + char *optr; +- lv->fullname = grub_malloc (sizeof ("lvm/") - 1 + 2 * vgname_len +- + 1 + 2 * s + 1); ++ ++ /* this is kind of hard to read with our safe (but rather ++ * baroque) math primatives, but it boils down to: ++ * ++ * sz0 = vgname_len * 2 + 1 ++ * + s * 2 + 1 ++ * + sizeof ("lvm/") - 1; ++ */ ++ grub_size_t sz0 = vgname_len, sz1 = s; ++ ++ if (grub_mul (sz0, 2, &sz0) || ++ grub_add (sz0, 1, &sz0) || ++ grub_mul (sz1, 2, &sz1) || ++ grub_add (sz1, 1, &sz1) || ++ grub_add (sz0, sz1, &sz0) || ++ grub_add (sz0, sizeof ("lvm/") - 1, &sz0)) ++ goto lvs_fail; ++ ++ lv->fullname = grub_malloc (sz0); + if (!lv->fullname) + goto lvs_fail; + diff --git a/0247-emu-make-grub_free-NULL-safe.patch b/0247-emu-make-grub_free-NULL-safe.patch new file mode 100644 index 0000000..64ecc34 --- /dev/null +++ b/0247-emu-make-grub_free-NULL-safe.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 16:08:08 -0400 +Subject: [PATCH] emu: make grub_free(NULL) safe + +The grub_free() implementation in kern/mm.c safely handles NULL +pointers, and code at many places depends on this. We don't know that +the same is true on all host OSes, so we need to handle the same +behavior in grub-emu's implementation. + +Signed-off-by: Peter Jones +Reviewed-by: Darren Kenny +Upstream-commit-id: 96bb109e658 +--- + grub-core/kern/emu/mm.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/grub-core/kern/emu/mm.c b/grub-core/kern/emu/mm.c +index 145b01d3719..4d1046a219e 100644 +--- a/grub-core/kern/emu/mm.c ++++ b/grub-core/kern/emu/mm.c +@@ -60,7 +60,8 @@ grub_zalloc (grub_size_t size) + void + grub_free (void *ptr) + { +- free (ptr); ++ if (ptr) ++ free (ptr); + } + + void * diff --git a/0248-efi-fix-some-malformed-device-path-arithmetic-errors.patch b/0248-efi-fix-some-malformed-device-path-arithmetic-errors.patch new file mode 100644 index 0000000..a18412f --- /dev/null +++ b/0248-efi-fix-some-malformed-device-path-arithmetic-errors.patch @@ -0,0 +1,248 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 16:53:27 -0400 +Subject: [PATCH] efi: fix some malformed device path arithmetic errors. + +Several places we take the length of a device path and subtract 4 from +it, without ever checking that it's >= 4. There are also cases where +this kind of malformation will result in unpredictable iteration, +including treating the length from one dp node as the type in the next +node. These are all errors, no matter where the data comes from. + +This patch adds a checking macro, GRUB_EFI_DEVICE_PATH_VALID(), which +can be used in several places, and makes GRUB_EFI_NEXT_DEVICE_PATH() +return NULL and GRUB_EFI_END_ENTIRE_DEVICE_PATH() evaluate as true when +the length is too small. Additionally, it makes several places in the +code check for and return errors in these cases. + +Signed-off-by: Peter Jones +Upstream-commit-id: 23e68a83990 +--- + grub-core/kern/efi/efi.c | 67 ++++++++++++++++++++++++++++++++------ + grub-core/loader/efi/chainloader.c | 19 +++++++++-- + grub-core/loader/i386/xnu.c | 9 ++--- + include/grub/efi/api.h | 14 +++++--- + 4 files changed, 88 insertions(+), 21 deletions(-) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index ab133fecce0..8c09e60987d 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -350,7 +350,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + + dp = dp0; + +- while (1) ++ while (dp) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -360,9 +360,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + if (type == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE + && subtype == GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE) + { +- grub_efi_uint16_t len; +- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) +- / sizeof (grub_efi_char16_t)); ++ grub_efi_uint16_t len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ len = (len - 4) / sizeof (grub_efi_char16_t); + filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2; + } + +@@ -378,7 +384,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + if (!name) + return NULL; + +- while (1) ++ while (dp) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -394,8 +400,15 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + + *p++ = '/'; + +- len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) +- / sizeof (grub_efi_char16_t)); ++ len = GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ len = (len - 4) / sizeof (grub_efi_char16_t); + fp = (grub_efi_file_path_device_path_t *) dp; + /* According to EFI spec Path Name is NULL terminated */ + while (len > 0 && fp->path_name[len - 1] == 0) +@@ -470,7 +483,26 @@ grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp) + ; + p = GRUB_EFI_NEXT_DEVICE_PATH (p)) + { +- total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p); ++ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (p); ++ ++ /* ++ * In the event that we find a node that's completely garbage, for ++ * example if we get to 0x7f 0x01 0x02 0x00 ... (EndInstance with a size ++ * of 2), GRUB_EFI_END_ENTIRE_DEVICE_PATH() will be true and ++ * GRUB_EFI_NEXT_DEVICE_PATH() will return NULL, so we won't continue, ++ * and neither should our consumers, but there won't be any error raised ++ * even though the device path is junk. ++ * ++ * This keeps us from passing junk down back to our caller. ++ */ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ total_size += len; + if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p)) + break; + } +@@ -515,7 +547,7 @@ dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor) + void + grub_efi_print_device_path (grub_efi_device_path_t *dp) + { +- while (1) ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp)) + { + grub_efi_uint8_t type = GRUB_EFI_DEVICE_PATH_TYPE (dp); + grub_efi_uint8_t subtype = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp); +@@ -987,7 +1019,11 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, + /* Return non-zero. */ + return 1; + +- while (1) ++ if (dp1 == dp2) ++ return 0; ++ ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp1) ++ && GRUB_EFI_DEVICE_PATH_VALID (dp2)) + { + grub_efi_uint8_t type1, type2; + grub_efi_uint8_t subtype1, subtype2; +@@ -1023,5 +1059,16 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1, + dp2 = (grub_efi_device_path_t *) ((char *) dp2 + len2); + } + ++ /* ++ * There's no "right" answer here, but we probably don't want to call a valid ++ * dp and an invalid dp equal, so pick one way or the other. ++ */ ++ if (GRUB_EFI_DEVICE_PATH_VALID (dp1) && ++ !GRUB_EFI_DEVICE_PATH_VALID (dp2)) ++ return 1; ++ else if (!GRUB_EFI_DEVICE_PATH_VALID (dp1) && ++ GRUB_EFI_DEVICE_PATH_VALID (dp2)) ++ return -1; ++ + return 0; + } +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 736505173cb..5f7c6cfe105 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -125,6 +125,12 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; + fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; + ++ if (!GRUB_EFI_DEVICE_PATH_VALID ((grub_efi_device_path_t *)fp)) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "EFI Device Path is invalid"); ++ return; ++ } ++ + path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) + return; +@@ -165,9 +171,18 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + + size = 0; + d = dp; +- while (1) ++ while (d) + { +- size += GRUB_EFI_DEVICE_PATH_LENGTH (d); ++ grub_size_t len = GRUB_EFI_DEVICE_PATH_LENGTH (d); ++ ++ if (len < 4) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "malformed EFI Device Path node has length=%d", len); ++ return NULL; ++ } ++ ++ size += len; + if ((GRUB_EFI_END_ENTIRE_DEVICE_PATH (d))) + break; + d = GRUB_EFI_NEXT_DEVICE_PATH (d); +diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c +index e9e11925972..a7009360732 100644 +--- a/grub-core/loader/i386/xnu.c ++++ b/grub-core/loader/i386/xnu.c +@@ -515,14 +515,15 @@ grub_cmd_devprop_load (grub_command_t cmd __attribute__ ((unused)), + + devhead = buf; + buf = devhead + 1; +- dpstart = buf; ++ dp = dpstart = buf; + +- do ++ while (GRUB_EFI_DEVICE_PATH_VALID (dp) && buf < bufend) + { +- dp = buf; + buf = (char *) buf + GRUB_EFI_DEVICE_PATH_LENGTH (dp); ++ if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp)) ++ break; ++ dp = buf; + } +- while (!GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp) && buf < bufend); + + dev = grub_xnu_devprop_add_device (dpstart, (char *) buf + - (char *) dpstart); +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index dec7b06083e..fc8a564e94d 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -666,6 +666,7 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; + #define GRUB_EFI_DEVICE_PATH_TYPE(dp) ((dp)->type & 0x7f) + #define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) ((dp)->subtype) + #define GRUB_EFI_DEVICE_PATH_LENGTH(dp) ((dp)->length) ++#define GRUB_EFI_DEVICE_PATH_VALID(dp) ((dp) != NULL && GRUB_EFI_DEVICE_PATH_LENGTH (dp) >= 4) + + /* The End of Device Path nodes. */ + #define GRUB_EFI_END_DEVICE_PATH_TYPE (0xff & 0x7f) +@@ -674,13 +675,16 @@ typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; + #define GRUB_EFI_END_THIS_DEVICE_PATH_SUBTYPE 0x01 + + #define GRUB_EFI_END_ENTIRE_DEVICE_PATH(dp) \ +- (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ +- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ +- == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)) ++ (!GRUB_EFI_DEVICE_PATH_VALID (dp) || \ ++ (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_END_DEVICE_PATH_TYPE \ ++ && (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp) \ ++ == GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE))) + + #define GRUB_EFI_NEXT_DEVICE_PATH(dp) \ +- ((grub_efi_device_path_t *) ((char *) (dp) \ +- + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) ++ (GRUB_EFI_DEVICE_PATH_VALID (dp) \ ++ ? ((grub_efi_device_path_t *) \ ++ ((char *) (dp) + GRUB_EFI_DEVICE_PATH_LENGTH (dp))) \ ++ : NULL) + + /* Hardware Device Path. */ + #define GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE 1 diff --git a/0249-Fix-a-regression-caused-by-efi-fix-some-malformed-de.patch b/0249-Fix-a-regression-caused-by-efi-fix-some-malformed-de.patch new file mode 100644 index 0000000..1bccfd6 --- /dev/null +++ b/0249-Fix-a-regression-caused-by-efi-fix-some-malformed-de.patch @@ -0,0 +1,84 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Coulson +Date: Wed, 22 Jul 2020 17:06:04 +0100 +Subject: [PATCH] Fix a regression caused by "efi: fix some malformed device + path arithmetic errors" + +This commit introduced a bogus check inside copy_file_path to +determine whether the destination grub_efi_file_path_device_path_t +was valid before anything was copied to it. Depending on the +contents of the heap buffer, this check could fail which would +result in copy_file_path returning early. + +Without any error propagated to the caller, make_file_path would +then try to advance the invalid device path node with +GRUB_EFI_NEXT_DEVICE_PATH, which would also fail, returning a NULL +pointer that would subsequently be dereferenced. + +Remove the bogus check, and also propagate errors from copy_file_path. +--- + grub-core/loader/efi/chainloader.c | 25 +++++++++++++------------ + 1 file changed, 13 insertions(+), 12 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 5f7c6cfe105..3dfa41bb49d 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -115,7 +115,7 @@ grub_chainloader_boot (void) + return grub_errno; + } + +-static void ++static grub_err_t + copy_file_path (grub_efi_file_path_device_path_t *fp, + const char *str, grub_efi_uint16_t len) + { +@@ -125,15 +125,9 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; + fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; + +- if (!GRUB_EFI_DEVICE_PATH_VALID ((grub_efi_device_path_t *)fp)) +- { +- grub_error (GRUB_ERR_BAD_ARGUMENT, "EFI Device Path is invalid"); +- return; +- } +- + path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) +- return; ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, "failed to allocate path buffer"); + + size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8, + (const grub_uint8_t *) str, len, 0); +@@ -146,6 +140,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, + fp->path_name[size++] = '\0'; + fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); + grub_free (path_name); ++ return GRUB_ERR_NONE; + } + + static grub_efi_device_path_t * +@@ -203,13 +198,19 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) + /* Fill the file path for the directory. */ + d = (grub_efi_device_path_t *) ((char *) file_path + + ((char *) d - (char *) dp)); +- copy_file_path ((grub_efi_file_path_device_path_t *) d, +- dir_start, dir_end - dir_start); ++ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, ++ dir_start, dir_end - dir_start) != GRUB_ERR_NONE) ++ { ++ fail: ++ grub_free (file_path); ++ return 0; ++ } + + /* Fill the file path for the file. */ + d = GRUB_EFI_NEXT_DEVICE_PATH (d); +- copy_file_path ((grub_efi_file_path_device_path_t *) d, +- dir_end + 1, grub_strlen (dir_end + 1)); ++ if (copy_file_path ((grub_efi_file_path_device_path_t *) d, ++ dir_end + 1, grub_strlen (dir_end + 1)) != GRUB_ERR_NONE) ++ goto fail; + + /* Fill the end of device path nodes. */ + d = GRUB_EFI_NEXT_DEVICE_PATH (d); diff --git a/0250-efi-Fix-use-after-free-in-halt-reboot-path.patch b/0250-efi-Fix-use-after-free-in-halt-reboot-path.patch new file mode 100644 index 0000000..b0d5289 --- /dev/null +++ b/0250-efi-Fix-use-after-free-in-halt-reboot-path.patch @@ -0,0 +1,162 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Mon, 20 Jul 2020 23:03:05 +0000 +Subject: [PATCH] efi: Fix use-after-free in halt/reboot path + +commit 92bfc33db984 ("efi: Free malloc regions on exit") +introduced memory freeing in grub_efi_fini(), which is +used not only by exit path but by halt/reboot one as well. +As result of memory freeing, code and data regions used by +modules, such as halt, reboot, acpi (used by halt) also got +freed. After return to module code, CPU executes, filled +by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as +a code. Which leads to #UD exception later. + +grub> halt +!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!! +RIP - 0000000003F4EC28, CS - 0000000000000038, RFLAGS - 0000000000200246 +RAX - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41 +RBX - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000 +RSI - 00000000064DB768, RDI - 000000000832C5C3 +R8 - 0000000000000002, R9 - 0000000000000000, R10 - 00000000061E2E52 +R11 - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4 +R14 - 0000000003E10D80, R15 - 00000000061E2F60 +DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030 +GS - 0000000000000030, SS - 0000000000000030 +CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000 +CR4 - 0000000000000668, CR8 - 0000000000000000 +DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 +DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 +GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000 +IDTR - 0000000007598018 0000000000000FFF, TR - 0000000000000000 +FXSAVE_STATE - 0000000007F0F4C0 + +Proposal here is to continue to free allocated memory for +exit boot services path but keep it for halt/reboot path +as it won't be much security concern here. +Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY +loader flag to be used by efi halt/reboot path. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Darren Kenny +--- + grub-core/kern/arm/efi/init.c | 3 +++ + grub-core/kern/arm64/efi/init.c | 3 +++ + grub-core/kern/efi/efi.c | 3 ++- + grub-core/kern/efi/init.c | 1 - + grub-core/kern/i386/efi/init.c | 9 +++++++-- + grub-core/kern/ia64/efi/init.c | 9 +++++++-- + grub-core/lib/efi/halt.c | 3 ++- + include/grub/loader.h | 1 + + 8 files changed, 25 insertions(+), 7 deletions(-) + +diff --git a/grub-core/kern/arm/efi/init.c b/grub-core/kern/arm/efi/init.c +index 06df60e2f0e..40c3b467fc6 100644 +--- a/grub-core/kern/arm/efi/init.c ++++ b/grub-core/kern/arm/efi/init.c +@@ -71,4 +71,7 @@ grub_machine_fini (int flags) + efi_call_1 (b->close_event, tmr_evt); + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/arm64/efi/init.c b/grub-core/kern/arm64/efi/init.c +index 6224999ec9c..5010caefd66 100644 +--- a/grub-core/kern/arm64/efi/init.c ++++ b/grub-core/kern/arm64/efi/init.c +@@ -57,4 +57,7 @@ grub_machine_fini (int flags) + return; + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index 8c09e60987d..5ee739d51ae 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -157,7 +157,8 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle) + void + grub_reboot (void) + { +- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); ++ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); + for (;;) ; +diff --git a/grub-core/kern/efi/init.c b/grub-core/kern/efi/init.c +index d1afa3af11e..2ffb5205dda 100644 +--- a/grub-core/kern/efi/init.c ++++ b/grub-core/kern/efi/init.c +@@ -131,5 +131,4 @@ grub_efi_fini (void) + { + grub_efidisk_fini (); + grub_console_fini (); +- grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/i386/efi/init.c b/grub-core/kern/i386/efi/init.c +index da499aba04e..deb2eacd8d8 100644 +--- a/grub-core/kern/i386/efi/init.c ++++ b/grub-core/kern/i386/efi/init.c +@@ -39,6 +39,11 @@ grub_machine_init (void) + void + grub_machine_fini (int flags) + { +- if (flags & GRUB_LOADER_FLAG_NORETURN) +- grub_efi_fini (); ++ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) ++ return; ++ ++ grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/kern/ia64/efi/init.c b/grub-core/kern/ia64/efi/init.c +index b5ecbd09121..f1965571b1d 100644 +--- a/grub-core/kern/ia64/efi/init.c ++++ b/grub-core/kern/ia64/efi/init.c +@@ -70,6 +70,11 @@ grub_machine_init (void) + void + grub_machine_fini (int flags) + { +- if (flags & GRUB_LOADER_FLAG_NORETURN) +- grub_efi_fini (); ++ if (!(flags & GRUB_LOADER_FLAG_NORETURN)) ++ return; ++ ++ grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } +diff --git a/grub-core/lib/efi/halt.c b/grub-core/lib/efi/halt.c +index 5859f0498a8..29d41364168 100644 +--- a/grub-core/lib/efi/halt.c ++++ b/grub-core/lib/efi/halt.c +@@ -28,7 +28,8 @@ + void + grub_halt (void) + { +- grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); ++ grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); + #if !defined(__ia64__) && !defined(__arm__) && !defined(__aarch64__) && \ + !defined(__riscv) + grub_acpi_halt (); +diff --git a/include/grub/loader.h b/include/grub/loader.h +index 7f82a499fd9..b208642821b 100644 +--- a/include/grub/loader.h ++++ b/include/grub/loader.h +@@ -33,6 +33,7 @@ enum + { + GRUB_LOADER_FLAG_NORETURN = 1, + GRUB_LOADER_FLAG_PXE_NOT_UNLOAD = 2, ++ GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY = 4, + }; + + void EXPORT_FUNC (grub_loader_set) (grub_err_t (*boot) (void), diff --git a/0251-efi-dhcp-fix-some-allocation-error-checking.patch b/0251-efi-dhcp-fix-some-allocation-error-checking.patch new file mode 100644 index 0000000..7549733 --- /dev/null +++ b/0251-efi-dhcp-fix-some-allocation-error-checking.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:11:06 -0400 +Subject: [PATCH] efi+dhcp: fix some allocation error checking. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/dhcp.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/grub-core/net/efi/dhcp.c b/grub-core/net/efi/dhcp.c +index dbef63d8c08..e5c79b748b0 100644 +--- a/grub-core/net/efi/dhcp.c ++++ b/grub-core/net/efi/dhcp.c +@@ -80,7 +80,7 @@ grub_efi_dhcp4_parse_dns (grub_efi_dhcp4_protocol_t *dhcp4, grub_efi_dhcp4_packe + if (status != GRUB_EFI_BUFFER_TOO_SMALL) + return NULL; + +- option_list = grub_malloc (option_count * sizeof(*option_list)); ++ option_list = grub_calloc (option_count, sizeof(*option_list)); + if (!option_list) + return NULL; + +@@ -360,8 +360,11 @@ grub_cmd_efi_bootp6 (struct grub_command *cmd __attribute__ ((unused)), + + if (status == GRUB_EFI_BUFFER_TOO_SMALL && count) + { +- options = grub_malloc (count * sizeof(*options)); +- status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ options = grub_calloc (count, sizeof(*options)); ++ if (options) ++ status = efi_call_4 (dev->dhcp6->parse, dev->dhcp6, mode.ia->reply_packet, &count, options); ++ else ++ status = GRUB_EFI_OUT_OF_RESOURCES; + } + + if (status != GRUB_EFI_SUCCESS) diff --git a/0252-efi-http-fix-some-allocation-error-checking.patch b/0252-efi-http-fix-some-allocation-error-checking.patch new file mode 100644 index 0000000..4dffab9 --- /dev/null +++ b/0252-efi-http-fix-some-allocation-error-checking.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:14:15 -0400 +Subject: [PATCH] efi+http: fix some allocation error checking. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/http.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/grub-core/net/efi/http.c b/grub-core/net/efi/http.c +index fc8cb25ae0a..26647a50fa4 100644 +--- a/grub-core/net/efi/http.c ++++ b/grub-core/net/efi/http.c +@@ -412,8 +412,8 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + int type) + { + grub_err_t err; +- grub_off_t size; +- char *buf; ++ grub_off_t size = 0; ++ char *buf = NULL; + char *file_name = NULL; + const char *http_path; + +@@ -441,8 +441,11 @@ grub_efihttp_open (struct grub_efi_net_device *dev, + return err; + } + +- buf = grub_malloc (size); +- efihttp_read (dev, buf, size); ++ if (size) ++ { ++ buf = grub_malloc (size); ++ efihttp_read (dev, buf, size); ++ } + + file->size = size; + file->data = buf; diff --git a/0253-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch b/0253-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch new file mode 100644 index 0000000..30c21a5 --- /dev/null +++ b/0253-efi-ip-46-_config.c-fix-some-potential-allocation-ov.patch @@ -0,0 +1,127 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sun, 19 Jul 2020 17:27:00 -0400 +Subject: [PATCH] efi/ip[46]_config.c: fix some potential allocation overflows + +In theory all of this data comes from the firmware stack and it should +be safe, but it's better to be paranoid. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip4_config.c | 25 ++++++++++++++++++------- + grub-core/net/efi/ip6_config.c | 13 ++++++++++--- + 2 files changed, 28 insertions(+), 10 deletions(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index 313c818b184..9725e928f7e 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -4,15 +4,20 @@ + #include + #include + #include ++#include + + char * + grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_address_t hw_address) + { + char *hw_addr, *p; +- int sz, s; +- int i; ++ grub_size_t sz, s, i; + +- sz = (int)hw_address_size * (sizeof ("XX:") - 1) + 1; ++ if (grub_mul (hw_address_size, sizeof ("XX:") - 1, &sz) || ++ grub_add (sz, 1, &sz)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + + hw_addr = grub_malloc (sz); + if (!hw_addr) +@@ -20,7 +25,7 @@ grub_efi_hw_address_to_string (grub_efi_uint32_t hw_address_size, grub_efi_mac_a + + p = hw_addr; + s = sz; +- for (i = 0; i < (int)hw_address_size; i++) ++ for (i = 0; i < hw_address_size; i++) + { + grub_snprintf (p, sz, "%02x:", hw_address[i]); + p += sizeof ("XX:") - 1; +@@ -238,14 +243,20 @@ grub_efi_ip4_interface_route_table (struct grub_efi_net_device *dev) + { + grub_efi_ip4_config2_interface_info_t *interface_info; + char **ret; +- int i, id; ++ int id; ++ grub_size_t i, nmemb; + + interface_info = efi_ip4_config_interface_info (dev->ip4_config); + if (!interface_info) + return NULL; + +- ret = grub_malloc (sizeof (*ret) * (interface_info->route_table_size + 1)); ++ if (grub_add (interface_info->route_table_size, 1, &nmemb)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + ++ ret = grub_calloc (nmemb, sizeof (*ret)); + if (!ret) + { + grub_free (interface_info); +@@ -253,7 +264,7 @@ grub_efi_ip4_interface_route_table (struct grub_efi_net_device *dev) + } + + id = 0; +- for (i = 0; i < (int)interface_info->route_table_size; i++) ++ for (i = 0; i < interface_info->route_table_size; i++) + { + char *subnet, *gateway, *mask; + grub_uint32_t u32_subnet, u32_gateway; +diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c +index 017c4d05bc7..a46f6f9b685 100644 +--- a/grub-core/net/efi/ip6_config.c ++++ b/grub-core/net/efi/ip6_config.c +@@ -3,6 +3,7 @@ + #include + #include + #include ++#include + + char * + grub_efi_ip6_address_to_string (grub_efi_pxe_ipv6_address_t *address) +@@ -228,14 +229,20 @@ grub_efi_ip6_interface_route_table (struct grub_efi_net_device *dev) + { + grub_efi_ip6_config_interface_info_t *interface_info; + char **ret; +- int i, id; ++ int id; ++ grub_size_t i, nmemb; + + interface_info = efi_ip6_config_interface_info (dev->ip6_config); + if (!interface_info) + return NULL; + +- ret = grub_malloc (sizeof (*ret) * (interface_info->route_count + 1)); ++ if (grub_add (interface_info->route_count, 1, &nmemb)) ++ { ++ grub_errno = GRUB_ERR_OUT_OF_RANGE; ++ return NULL; ++ } + ++ ret = grub_calloc (nmemb, sizeof (*ret)); + if (!ret) + { + grub_free (interface_info); +@@ -243,7 +250,7 @@ grub_efi_ip6_interface_route_table (struct grub_efi_net_device *dev) + } + + id = 0; +- for (i = 0; i < (int)interface_info->route_count ; i++) ++ for (i = 0; i < interface_info->route_count ; i++) + { + char *gateway, *destination; + grub_uint64_t u64_gateway[2]; diff --git a/0254-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch b/0254-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch new file mode 100644 index 0000000..3f0b01d --- /dev/null +++ b/0254-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Fri, 24 Jul 2020 17:18:09 +0100 +Subject: [PATCH] efilinux: Fix integer overflows in grub_cmd_initrd + +These could be triggered by an extremely large number of arguments to +the initrd command on 32-bit architectures, or a crafted filesystem with +very large files on any architecture. + +Signed-off-by: Colin Watson +--- + grub-core/loader/i386/efi/linux.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index e5b2736b0ce..c0a98d152ff 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -28,6 +28,8 @@ + #include + #include + #include ++#include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -206,7 +208,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- files = grub_zalloc (argc * sizeof (files[0])); ++ files = grub_calloc (argc, sizeof (files[0])); + if (!files) + goto fail; + +@@ -216,7 +218,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + if (! files[i]) + goto fail; + nfiles++; +- size += ALIGN_UP (grub_file_size (files[i]), 4); ++ if (grub_add (size, ALIGN_UP (grub_file_size (files[i]), 4), &size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ goto fail; ++ } + } + + initrd_mem = kernel_alloc(size, N_("can't allocate initrd")); diff --git a/0255-efi-Fix-use-after-free-in-halt-reboot-path.patch b/0255-efi-Fix-use-after-free-in-halt-reboot-path.patch new file mode 100644 index 0000000..93efaf6 --- /dev/null +++ b/0255-efi-Fix-use-after-free-in-halt-reboot-path.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alexey Makhalov +Date: Mon, 20 Jul 2020 23:03:05 +0000 +Subject: [PATCH] efi: Fix use-after-free in halt/reboot path + +commit 92bfc33db984 ("efi: Free malloc regions on exit") +introduced memory freeing in grub_efi_fini(), which is +used not only by exit path but by halt/reboot one as well. +As result of memory freeing, code and data regions used by +modules, such as halt, reboot, acpi (used by halt) also got +freed. After return to module code, CPU executes, filled +by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as +a code. Which leads to #UD exception later. + +grub> halt +!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!! +RIP - 0000000003F4EC28, CS - 0000000000000038, RFLAGS - 0000000000200246 +RAX - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41 +RBX - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000 +RSI - 00000000064DB768, RDI - 000000000832C5C3 +R8 - 0000000000000002, R9 - 0000000000000000, R10 - 00000000061E2E52 +R11 - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4 +R14 - 0000000003E10D80, R15 - 00000000061E2F60 +DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030 +GS - 0000000000000030, SS - 0000000000000030 +CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000 +CR4 - 0000000000000668, CR8 - 0000000000000000 +DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 +DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 +GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000 +IDTR - 0000000007598018 0000000000000FFF, TR - 0000000000000000 +FXSAVE_STATE - 0000000007F0F4C0 + +Proposal here is to continue to free allocated memory for +exit boot services path but keep it for halt/reboot path +as it won't be much security concern here. +Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY +loader flag to be used by efi halt/reboot path. + +Signed-off-by: Alexey Makhalov +Reviewed-by: Darren Kenny +--- + grub-core/kern/riscv/efi/init.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c +index 7eb1969d0b0..38795fe6741 100644 +--- a/grub-core/kern/riscv/efi/init.c ++++ b/grub-core/kern/riscv/efi/init.c +@@ -73,4 +73,7 @@ grub_machine_fini (int flags) + return; + + grub_efi_fini (); ++ ++ if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) ++ grub_efi_memory_fini (); + } diff --git a/0256-linux-loader-avoid-overflow-on-initrd-size-calculati.patch b/0256-linux-loader-avoid-overflow-on-initrd-size-calculati.patch new file mode 100644 index 0000000..51f39e5 --- /dev/null +++ b/0256-linux-loader-avoid-overflow-on-initrd-size-calculati.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 24 Jul 2020 13:57:27 -0400 +Subject: [PATCH] linux loader: avoid overflow on initrd size calculation + +Signed-off-by: Peter Jones +--- + grub-core/loader/linux.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 471b214d6c3..25624ebc114 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -151,8 +151,8 @@ grub_initrd_init (int argc, char *argv[], + initrd_ctx->nfiles = 0; + initrd_ctx->components = 0; + +- initrd_ctx->components = grub_zalloc (argc +- * sizeof (initrd_ctx->components[0])); ++ initrd_ctx->components = grub_calloc (argc, ++ sizeof (initrd_ctx->components[0])); + if (!initrd_ctx->components) + return grub_errno; + diff --git a/0257-linuxefi-fail-kernel-validation-without-shim-protoco.patch b/0257-linuxefi-fail-kernel-validation-without-shim-protoco.patch new file mode 100644 index 0000000..3d04672 --- /dev/null +++ b/0257-linuxefi-fail-kernel-validation-without-shim-protoco.patch @@ -0,0 +1,130 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dimitri John Ledkov +Date: Wed, 22 Jul 2020 11:31:43 +0100 +Subject: [PATCH] linuxefi: fail kernel validation without shim protocol. + +If certificates that signed grub are installed into db, grub can be +booted directly. It will then boot any kernel without signature +validation. The booted kernel will think it was booted in secureboot +mode and will implement lockdown, yet it could have been tampered. + +This version of the patch skips calling verification, when booted +without secureboot. And is indented with gnu ident. + +CVE-2020-15705 + +Reported-by: Mathieu Trudel-Lapierre +Signed-off-by: Dimitri John Ledkov +--- + grub-core/loader/arm64/linux.c | 13 +++++++++---- + grub-core/loader/efi/chainloader.c | 1 + + grub-core/loader/efi/linux.c | 1 + + grub-core/loader/i386/efi/linux.c | 17 +++++++++++------ + 4 files changed, 22 insertions(+), 10 deletions(-) + +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index 8791b35b6fe..720eec075cd 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -383,11 +384,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); + +- rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); +- if (rc < 0) ++ if (grub_efi_secure_boot ()) + { +- grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); +- goto fail; ++ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); ++ if (rc <= 0) ++ { ++ grub_error (GRUB_ERR_INVALID_COMMAND, ++ N_("%s has invalid signature"), argv[0]); ++ goto fail; ++ } + } + + pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 3dfa41bb49d..26f4fa9dc6a 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -1083,6 +1083,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + + return 0; + } ++ // -1 fall-through to fail + + fail: + if (dev) +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index e09f824862b..927d89a90d7 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -33,6 +33,7 @@ struct grub_efi_shim_lock + }; + typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; + ++// Returns 1 on success, -1 on error, 0 when not available + int + grub_linuxefi_secure_validate (void *data, grub_uint32_t size) + { +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index c0a98d152ff..60ef7d12f07 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -101,7 +102,7 @@ kernel_alloc(grub_efi_uintn_t size, const char * const errmsg) + + pages = BYTES_TO_PAGES(size); + grub_dprintf ("linux", "Trying to allocate %lu pages from %p\n", +- pages, (void *)max); ++ (unsigned long)pages, (void *)(unsigned long)max); + + prev_max = max; + addr = grub_efi_allocate_pages_real (max, pages, +@@ -307,12 +308,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- rc = grub_linuxefi_secure_validate (kernel, filelen); +- if (rc < 0) ++ if (grub_efi_secure_boot ()) + { +- grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), +- argv[0]); +- goto fail; ++ rc = grub_linuxefi_secure_validate (kernel, filelen); ++ if (rc <= 0) ++ { ++ grub_error (GRUB_ERR_INVALID_COMMAND, ++ N_("%s has invalid signature"), argv[0]); ++ goto fail; ++ } + } + + lh = (struct linux_i386_kernel_header *)kernel; +@@ -386,6 +390,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); + grub_dprintf ("linux", "copying %lu bytes from %p to %p\n", ++ (unsigned long) + MIN((grub_size_t)0x202+setup_header_end_offset, + sizeof (*params)) - 0x1f1, + (grub_uint8_t *)kernel + 0x1f1, diff --git a/0258-linux-Fix-integer-overflows-in-initrd-size-handling.patch b/0258-linux-Fix-integer-overflows-in-initrd-size-handling.patch new file mode 100644 index 0000000..b784faa --- /dev/null +++ b/0258-linux-Fix-integer-overflows-in-initrd-size-handling.patch @@ -0,0 +1,166 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Sat, 25 Jul 2020 12:15:37 +0100 +Subject: [PATCH] linux: Fix integer overflows in initrd size handling + +These could be triggered by a crafted filesystem with very large files. + +Fixes: CVE-2020-15707 + +Signed-off-by: Colin Watson +Reviewed-by: Jan Setje-Eilers +--- + grub-core/loader/linux.c | 75 +++++++++++++++++++++++++++++++++++------------- + 1 file changed, 55 insertions(+), 20 deletions(-) + +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 25624ebc114..1af142f5760 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -4,6 +4,8 @@ + #include + #include + #include ++#include ++#include + + struct newc_head + { +@@ -98,13 +100,13 @@ free_dir (struct dir *root) + grub_free (root); + } + +-static grub_size_t ++static grub_err_t + insert_dir (const char *name, struct dir **root, +- grub_uint8_t *ptr) ++ grub_uint8_t *ptr, grub_size_t *size) + { + struct dir *cur, **head = root; + const char *cb, *ce = name; +- grub_size_t size = 0; ++ *size = 0; + while (1) + { + for (cb = ce; *cb == '/'; cb++); +@@ -130,14 +132,22 @@ insert_dir (const char *name, struct dir **root, + ptr = make_header (ptr, name, ce - name, + 040777, 0); + } +- size += ALIGN_UP ((ce - (char *) name) +- + sizeof (struct newc_head), 4); ++ if (grub_add (*size, ++ ALIGN_UP ((ce - (char *) name) ++ + sizeof (struct newc_head), 4), ++ size)) ++ { ++ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); ++ grub_free (n->name); ++ grub_free (n); ++ return grub_errno; ++ } + *head = n; + cur = n; + } + root = &cur->next; + } +- return size; ++ return GRUB_ERR_NONE; + } + + grub_err_t +@@ -173,26 +183,33 @@ grub_initrd_init (int argc, char *argv[], + eptr = grub_strchr (ptr, ':'); + if (eptr) + { ++ grub_size_t dir_size, name_len; ++ + initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr); +- if (!initrd_ctx->components[i].newc_name) ++ if (!initrd_ctx->components[i].newc_name || ++ insert_dir (initrd_ctx->components[i].newc_name, &root, 0, ++ &dir_size)) + { + grub_initrd_close (initrd_ctx); + return grub_errno; + } +- initrd_ctx->size +- += ALIGN_UP (sizeof (struct newc_head) +- + grub_strlen (initrd_ctx->components[i].newc_name), +- 4); +- initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name, +- &root, 0); ++ name_len = grub_strlen (initrd_ctx->components[i].newc_name); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) + name_len, 4), ++ &initrd_ctx->size) || ++ grub_add (initrd_ctx->size, dir_size, &initrd_ctx->size)) ++ goto overflow; + newc = 1; + fname = eptr + 1; + } + } + else if (newc) + { +- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) +- + sizeof ("TRAILER!!!") - 1, 4); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) ++ + sizeof ("TRAILER!!!") - 1, 4), ++ &initrd_ctx->size)) ++ goto overflow; + free_dir (root); + root = 0; + newc = 0; +@@ -208,19 +225,29 @@ grub_initrd_init (int argc, char *argv[], + initrd_ctx->nfiles++; + initrd_ctx->components[i].size + = grub_file_size (initrd_ctx->components[i].file); +- initrd_ctx->size += initrd_ctx->components[i].size; ++ if (grub_add (initrd_ctx->size, initrd_ctx->components[i].size, ++ &initrd_ctx->size)) ++ goto overflow; + } + + if (newc) + { + initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); +- initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) +- + sizeof ("TRAILER!!!") - 1, 4); ++ if (grub_add (initrd_ctx->size, ++ ALIGN_UP (sizeof (struct newc_head) ++ + sizeof ("TRAILER!!!") - 1, 4), ++ &initrd_ctx->size)) ++ goto overflow; + free_dir (root); + root = 0; + } + + return GRUB_ERR_NONE; ++ ++overflow: ++ free_dir (root); ++ grub_initrd_close (initrd_ctx); ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected")); + } + + grub_size_t +@@ -261,8 +288,16 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, + + if (initrd_ctx->components[i].newc_name) + { +- ptr += insert_dir (initrd_ctx->components[i].newc_name, +- &root, ptr); ++ grub_size_t dir_size; ++ ++ if (insert_dir (initrd_ctx->components[i].newc_name, &root, ptr, ++ &dir_size)) ++ { ++ free_dir (root); ++ grub_initrd_close (initrd_ctx); ++ return grub_errno; ++ } ++ ptr += dir_size; + ptr = make_header (ptr, initrd_ctx->components[i].newc_name, + grub_strlen (initrd_ctx->components[i].newc_name), + 0100777, diff --git a/0259-Fix-const-char-pointers-in-grub-core-commands-blscfg.patch b/0259-Fix-const-char-pointers-in-grub-core-commands-blscfg.patch new file mode 100644 index 0000000..62658d2 --- /dev/null +++ b/0259-Fix-const-char-pointers-in-grub-core-commands-blscfg.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/commands/blscfg.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/commands/blscfg.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 4ec6504d9a4..e907a6a5d28 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -612,7 +612,7 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) + return list; + } + +-static char *field_append(bool is_var, char *buffer, char *start, char *end) ++static char *field_append(bool is_var, char *buffer, const char *start, const char *end) + { + char *tmp = grub_strndup(start, end - start + 1); + const char *field = tmp; +@@ -641,11 +641,11 @@ static char *field_append(bool is_var, char *buffer, char *start, char *end) + return buffer; + } + +-static char *expand_val(char *value) ++static char *expand_val(const char *value) + { + char *buffer = NULL; +- char *start = value; +- char *end = value; ++ const char *start = value; ++ const char *end = value; + bool is_var = false; + + if (!value) diff --git a/0260-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch b/0260-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch new file mode 100644 index 0000000..b7e55d3 --- /dev/null +++ b/0260-Fix-const-char-pointers-in-grub-core-net-bootp.c.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/bootp.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/bootp.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 5a5ebbfb1aa..2658a0cda4e 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -365,7 +365,7 @@ grub_net_configure_by_dhcp_ack (const char *name, + struct grub_net_network_level_interface *inter; + int mask = -1; + char server_ip[sizeof ("xxx.xxx.xxx.xxx")]; +- const grub_uint8_t *opt; ++ const char *opt; + grub_uint8_t opt_len, overload = 0; + const char *boot_file = 0, *server_name = 0; + grub_size_t boot_file_len, server_name_len; +@@ -572,7 +572,7 @@ grub_net_configure_by_dhcp_ack (const char *name, + if (opt && opt_len) + { + grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len); +- if (opt && grub_strcmp (opt, "HTTPClient") == 0) ++ if (opt && grub_strcmp ((char *)opt, "HTTPClient") == 0) + { + char *proto, *ip, *pa; + diff --git a/0261-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch b/0261-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch new file mode 100644 index 0000000..6c16e9e --- /dev/null +++ b/0261-Fix-const-char-pointers-in-grub-core-net-efi-ip4_con.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/ip4_config.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip4_config.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c +index 9725e928f7e..cb880fc3e8f 100644 +--- a/grub-core/net/efi/ip4_config.c ++++ b/grub-core/net/efi/ip4_config.c +@@ -61,7 +61,8 @@ int + grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest) + { + grub_uint32_t newip = 0; +- int i, ncolon = 0; ++ grub_size_t i; ++ int ncolon = 0; + const char *ptr = val; + + /* Check that is not an IPv6 address */ +@@ -78,7 +79,7 @@ grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *addres + for (i = 0; i < 4; i++) + { + unsigned long t; +- t = grub_strtoul (ptr, (char **) &ptr, 0); ++ t = grub_strtoul (ptr, &ptr, 0); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; diff --git a/0262-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch b/0262-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch new file mode 100644 index 0000000..7c29683 --- /dev/null +++ b/0262-Fix-const-char-pointers-in-grub-core-net-efi-ip6_con.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/ip6_config.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/ip6_config.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/net/efi/ip6_config.c b/grub-core/net/efi/ip6_config.c +index a46f6f9b685..1c5415d7185 100644 +--- a/grub-core/net/efi/ip6_config.c ++++ b/grub-core/net/efi/ip6_config.c +@@ -85,7 +85,7 @@ grub_efi_string_to_ip6_address (const char *val, grub_efi_ipv6_address_t *addres + ptr++; + continue; + } +- t = grub_strtoul (ptr, (char **) &ptr, 16); ++ t = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; diff --git a/0263-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch b/0263-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch new file mode 100644 index 0000000..0fe90c8 --- /dev/null +++ b/0263-Fix-const-char-pointers-in-grub-core-net-efi-net.c.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/net.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/net.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c +index a3f0535d43c..78e5442fc52 100644 +--- a/grub-core/net/efi/net.c ++++ b/grub-core/net/efi/net.c +@@ -729,7 +729,7 @@ grub_efi_net_parse_address (const char *address, + { + grub_uint32_t subnet_mask_size; + +- subnet_mask_size = grub_strtoul (rest + 1, (char **) &rest, 0); ++ subnet_mask_size = grub_strtoul (rest + 1, &rest, 0); + + if (!grub_errno && subnet_mask_size <= 32 && *rest == 0) + { +@@ -758,7 +758,7 @@ grub_efi_net_parse_address (const char *address, + { + grub_efi_uint8_t prefix_length; + +- prefix_length = grub_strtoul (rest + 1, (char **) &rest, 0); ++ prefix_length = grub_strtoul (rest + 1, &rest, 0); + if (!grub_errno && prefix_length <= 128 && *rest == 0) + { + ip6->prefix_length = prefix_length; diff --git a/0264-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch b/0264-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch new file mode 100644 index 0000000..59f29e4 --- /dev/null +++ b/0264-Fix-const-char-pointers-in-grub-core-net-efi-pxe.c.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/efi/pxe.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/efi/pxe.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/net/efi/pxe.c b/grub-core/net/efi/pxe.c +index 531949cba5c..73e2bb01c1b 100644 +--- a/grub-core/net/efi/pxe.c ++++ b/grub-core/net/efi/pxe.c +@@ -187,7 +187,7 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + ptr++; + continue; + } +- t = grub_strtoul (ptr, (char **) &ptr, 16); ++ t = grub_strtoul (ptr, &ptr, 16); + if (grub_errno) + { + grub_errno = GRUB_ERR_NONE; +@@ -225,7 +225,7 @@ pxe_open (struct grub_efi_net_device *dev, + int type __attribute__((unused))) + { + int i; +- char *p; ++ const char *p; + grub_efi_status_t status; + grub_efi_pxe_ip_address_t server_ip; + grub_efi_uint64_t file_size = 0; +@@ -313,7 +313,7 @@ pxe_read (struct grub_efi_net_device *dev, + grub_size_t len) + { + int i; +- char *p; ++ const char *p; + grub_efi_status_t status; + grub_efi_pxe_t *pxe = (prefer_ip6) ? dev->ip6_pxe : dev->ip4_pxe; + grub_efi_uint64_t bufsz = len; diff --git a/0265-Fix-const-char-pointers-in-grub-core-net-url.c.patch b/0265-Fix-const-char-pointers-in-grub-core-net-url.c.patch new file mode 100644 index 0000000..e3d1be4 --- /dev/null +++ b/0265-Fix-const-char-pointers-in-grub-core-net-url.c.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 20 Jul 2020 12:24:02 -0400 +Subject: [PATCH] Fix const char ** pointers in grub-core/net/url.c + +This will need to get folded back in the right place on the next rebase, +but it's before "Make grub_strtol() "end" pointers have safer const +qualifiers" currently, so for now I'm leaving it here instead of merging +it back with the original patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/url.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/net/url.c b/grub-core/net/url.c +index 146858284cd..d9d2fc9a9dc 100644 +--- a/grub-core/net/url.c ++++ b/grub-core/net/url.c +@@ -235,7 +235,7 @@ extract_http_url_info (char *url, int ssl, + c = *port_end; + *port_end = '\0'; + +- portul = grub_strtoul (port_off, &separator, 10); ++ portul = grub_strtoul (port_off, (const char **)&separator, 10); + *port_end = c; + #ifdef URL_TEST + if (portul == ULONG_MAX && errno == ERANGE) diff --git a/0266-Add-systemd-integration-scripts-to-make-systemctl-re.patch b/0266-Add-systemd-integration-scripts-to-make-systemctl-re.patch new file mode 100644 index 0000000..faf5139 --- /dev/null +++ b/0266-Add-systemd-integration-scripts-to-make-systemctl-re.patch @@ -0,0 +1,190 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 22 Jul 2020 14:03:42 +0200 +Subject: [PATCH] Add systemd integration scripts to make "systemctl reboot + --boot-loader-menu=xxx" work with grub + +This commit adds a number of scripts / config files to make +"systemctl reboot --boot-loader-menu=xxx" work with grub: + +1. /lib/systemd/system/systemd-logind.service.d/10-grub.conf +This sets SYSTEMD_REBOOT_TO_BOOT_LOADER_MENU in the env. for logind, +indicating that the boot-loader which is used supports this feature, see: +https://github.com/systemd/systemd/blob/master/docs/ENVIRONMENT.md + +2. /lib/systemd/system/grub-systemd-integration.service + /lib/systemd/system/reboot.target.wants/grub-systemd-integration.service -> + ../grub-systemd-integration.service + /usr/libexec/grub/grub-systemd-integration.sh + +The symlink in the .wants dir causes the added service file to be started +by systemd just before rebooting the system. +If /run/systemd/reboot-to-boot-loader-menu exist then the service will run +the grub-systemd-integration.sh script. +This script sets the new menu_show_once_timeout grubenv variable to the +requested timeout in seconds. + +3. /etc/grub.d/14_menu_show_once + +This new grub-mkconfig snippet adds the necessary code to the generated +grub.conf to honor the new menu_show_once_timeout variable, and to +automatically clear it after consuming it. + +Note the service and libexec script use grub-systemd-integration as name +because in the future they may be used to add further integration with +systemctl reboot --foo options, e.g. support for --boot-loader-entry=NAME. + +A few notes about upstreaming this patch from the rhboot grub2 fork: +1. I have deliberately put the grub.conf bits for this in a new / separate + grub-mkconfig snippet generator for easy upstreaming +2. Even though the commit message mentions the .wants symlink for the .service + I have been unable to come up with a clean way to do this at "make install" + time, this should be fixed before upstreaming. + +Downstream notes: +1. Since make install does not add the .wants symlink, this needs to be done + in grub2.spec %install +2. This is keeping support for the "old" Fedora specific menu_show_once env + variable, which has a hardcoded timeout of 60 sec in 12_menu_auto_hide in + place for now. This can be dropped (eventually) in a follow-up patch once + GNOME has been converted to use the systemd dbus API equivalent of + "systemctl reboot --boot-loader-menu=xxx". + +Signed-off-by: Hans de Goede +--- + Makefile.util.def | 27 ++++++++++++++++++++++++ + conf/Makefile.common | 6 ++++++ + util/grub.d/14_menu_show_once.in | 13 ++++++++++++ + util/systemd/10-grub-logind-service.conf.in | 2 ++ + util/systemd/grub-systemd-integration.service.in | 8 +++++++ + util/systemd/systemd-integration.sh.in | 6 ++++++ + 6 files changed, 62 insertions(+) + create mode 100755 util/grub.d/14_menu_show_once.in + create mode 100644 util/systemd/10-grub-logind-service.conf.in + create mode 100644 util/systemd/grub-systemd-integration.service.in + create mode 100644 util/systemd/systemd-integration.sh.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index f3a699691bf..dc8d1790ea5 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -469,6 +469,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '14_menu_show_once'; ++ common = util/grub.d/14_menu_show_once.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '01_users'; + common = util/grub.d/01_users.in; +@@ -568,6 +574,27 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = 'grub-systemd-integration.service'; ++ common = util/systemd/grub-systemd-integration.service.in; ++ installdir = systemdunit; ++ condition = COND_HOST_LINUX; ++}; ++ ++script = { ++ name = 'systemd-integration.sh'; ++ common = util/systemd/systemd-integration.sh.in; ++ installdir = grublibexec; ++ condition = COND_HOST_LINUX; ++}; ++ ++script = { ++ name = '10-grub-logind-service.conf'; ++ common = util/systemd/10-grub-logind-service.conf.in; ++ installdir = systemd_logind_service_d; ++ condition = COND_HOST_LINUX; ++}; ++ + program = { + mansection = 1; + name = grub-mkrescue; +diff --git a/conf/Makefile.common b/conf/Makefile.common +index 87c1f0e809b..6b85eb394ce 100644 +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -63,8 +63,11 @@ CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS) + # Other variables + + grubconfdir = $(sysconfdir)/grub.d ++grublibexecdir = $(libexecdir)/$(grubdirname) + platformdir = $(pkglibdir)/$(target_cpu)-$(platform) + starfielddir = $(pkgdatadir)/themes/starfield ++systemdunitdir = ${prefix}/lib/systemd/system ++systemd_logind_service_ddir = $(systemdunitdir)/systemd-logind.service.d + + CFLAGS_GNULIB = -Wno-undef -Wno-unused -Wno-unused-parameter -Wno-redundant-decls -Wno-unreachable-code -Werror=trampolines -fno-trampolines + CPPFLAGS_GNULIB = -I$(top_builddir)/grub-core/lib/gnulib -I$(top_srcdir)/grub-core/lib/gnulib +@@ -119,6 +122,9 @@ noinst_LIBRARIES = + dist_noinst_DATA = + platform_SCRIPTS = + platform_PROGRAMS = ++grublibexec_SCRIPTS = ++systemdunit_SCRIPTS = ++systemd_logind_service_d_SCRIPTS = + + TESTS = + EXTRA_DIST = +diff --git a/util/grub.d/14_menu_show_once.in b/util/grub.d/14_menu_show_once.in +new file mode 100755 +index 00000000000..1cd7f36142b +--- /dev/null ++++ b/util/grub.d/14_menu_show_once.in +@@ -0,0 +1,13 @@ ++#! /bin/sh ++# Force the menu to be shown once, with a timeout of ${menu_show_once_timeout} ++# if requested by ${menu_show_once_timeout} being set in the env. ++cat << EOF ++if [ x\$feature_timeout_style = xy ]; then ++ if [ "\${menu_show_once_timeout}" ]; then ++ set timeout_style=menu ++ set timeout="\${menu_show_once_timeout}" ++ unset menu_show_once_timeout ++ save_env menu_show_once_timeout ++ fi ++fi ++EOF +diff --git a/util/systemd/10-grub-logind-service.conf.in b/util/systemd/10-grub-logind-service.conf.in +new file mode 100644 +index 00000000000..f2d4ac00732 +--- /dev/null ++++ b/util/systemd/10-grub-logind-service.conf.in +@@ -0,0 +1,2 @@ ++[Service] ++Environment=SYSTEMD_REBOOT_TO_BOOT_LOADER_MENU=true +diff --git a/util/systemd/grub-systemd-integration.service.in b/util/systemd/grub-systemd-integration.service.in +new file mode 100644 +index 00000000000..c81fb594ce1 +--- /dev/null ++++ b/util/systemd/grub-systemd-integration.service.in +@@ -0,0 +1,8 @@ ++[Unit] ++Description=Grub2 systemctl reboot --boot-loader-menu=... support ++Before=umount.target systemd-reboot.service ++DefaultDependencies=no ++ConditionPathExists=/run/systemd/reboot-to-boot-loader-menu ++ ++[Service] ++ExecStart=@libexecdir@/@grubdirname@/systemd-integration.sh +diff --git a/util/systemd/systemd-integration.sh.in b/util/systemd/systemd-integration.sh.in +new file mode 100644 +index 00000000000..dc1218597bc +--- /dev/null ++++ b/util/systemd/systemd-integration.sh.in +@@ -0,0 +1,6 @@ ++#!/bin/sh ++ ++TIMEOUT_USEC=$(cat /run/systemd/reboot-to-boot-loader-menu) ++TIMEOUT=$(((TIMEOUT_USEC + 500000) / 1000000)) ++ ++@grub_editenv@ - set menu_show_once_timeout=$TIMEOUT diff --git a/0267-systemd-integration.sh-Also-set-old-menu_show_once-g.patch b/0267-systemd-integration.sh-Also-set-old-menu_show_once-g.patch new file mode 100644 index 0000000..9021de5 --- /dev/null +++ b/0267-systemd-integration.sh-Also-set-old-menu_show_once-g.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Thu, 23 Jul 2020 09:27:36 +0200 +Subject: [PATCH] systemd-integration.sh: Also set old menu_show_once grubenv + var + +Downstream RH / Fedora patch for compatibility with old, not (yet) +regenerated grub.cfg files which miss the menu_show_once_timeout check. +This older grubenv variable leads to a fixed timeout of 60 seconds. + +Note that the new menu_show_once_timeout will overrule these 60 seconds +if both are set and the grub.cfg does have the menu_show_once_timeout +check. + +Signed-off-by: Hans de Goede +--- + util/systemd/systemd-integration.sh.in | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/util/systemd/systemd-integration.sh.in b/util/systemd/systemd-integration.sh.in +index dc1218597bc..a4c071c5b0c 100644 +--- a/util/systemd/systemd-integration.sh.in ++++ b/util/systemd/systemd-integration.sh.in +@@ -4,3 +4,8 @@ TIMEOUT_USEC=$(cat /run/systemd/reboot-to-boot-loader-menu) + TIMEOUT=$(((TIMEOUT_USEC + 500000) / 1000000)) + + @grub_editenv@ - set menu_show_once_timeout=$TIMEOUT ++ ++# Downstream RH / Fedora patch for compatibility with old, not (yet) ++# regenerated grub.cfg files which miss the menu_show_once_timeout check ++# this older grubenv variable leads to a fixed timeout of 60 seconds ++@grub_editenv@ - set menu_show_once=1 diff --git a/0268-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch b/0268-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch new file mode 100644 index 0000000..e7b5c6e --- /dev/null +++ b/0268-tftp-roll-over-block-counter-to-prevent-timeouts-wit.patch @@ -0,0 +1,51 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 24 Aug 2020 14:46:27 +0200 +Subject: [PATCH] tftp: roll over block counter to prevent timeouts with data + packets + +The block number is a 16-bit counter which only allows to fetch +files no bigger than 65535 * blksize. To avoid this limit, the +counter is rolled over. This behavior isn't defined in RFC 1350 +but is handled by many TFTP servers and it's what GRUB was doing +before implicitly due an overflow. + +Fixing that bug led to TFTP timeouts, since GRUB wasn't acking +data packets anymore for files with size bigger than the maximum +mentioned above. Restore the old behavior to prevent this issue. + +Resolves: rhbz#1869335 + +Suggested-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +--- + grub-core/net/tftp.c | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 22badd74316..acbb01c10e7 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -183,8 +183,20 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)), + return GRUB_ERR_NONE; + } + +- /* Ack old/retransmitted block. */ +- if (grub_be_to_cpu16 (tftph->u.data.block) < data->block + 1) ++ /* ++ * Ack old/retransmitted block. ++ * ++ * The block number is a 16-bit counter which only allows to fetch ++ * files no bigger than 65535 * blksize. To avoid this limit, the ++ * counter is rolled over. This behavior isn't defined in RFC 1350 ++ * but is handled by many TFTP servers and it's what GRUB was doing ++ * before implicitly due an overflow. ++ * ++ * Fixing that bug led to TFTP timeouts, since GRUB wasn't acking ++ * data packets anymore for files with size bigger than the maximum ++ * mentioned above. Restore the old behavior to prevent this issue. ++ */ ++ if (grub_be_to_cpu16 (tftph->u.data.block) < ((data->block + 1) & 0xffffu)) + ack (data, grub_be_to_cpu16 (tftph->u.data.block)); + /* Ignore unexpected block. */ + else if (grub_be_to_cpu16 (tftph->u.data.block) > data->block + 1) diff --git a/20-grub.install b/20-grub.install new file mode 100755 index 0000000..8ae3885 --- /dev/null +++ b/20-grub.install @@ -0,0 +1,176 @@ +#!/bin/bash + +if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then + exit 0 +fi + +[[ -f /etc/default/grub ]] && . /etc/default/grub +[[ -f /etc/os-release ]] && . /etc/os-release + +COMMAND="$1" +KERNEL_VERSION="$2" +BOOT_DIR_ABS="$3" +KERNEL_IMAGE="$4" + +KERNEL_DIR="${KERNEL_IMAGE%/*}" + +MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID + +# If ${BOOT_DIR_ABS} exists, some other boot loader is active. +[[ -d "${BOOT_DIR_ABS}" ]] && exit 0 + +BLS_DIR="/boot/loader/entries" + +mkbls() { + local kernelver=$1 && shift + local datetime=$1 && shift + local kernelopts=$1 && shift + + local debugname="" + local debugid="" + local flavor="" + + if [[ "$kernelver" == *\+* ]] ; then + local flavor=-"${kernelver##*+}" + if [[ "${flavor}" == "-debug" ]]; then + local debugname=" with debugging" + local debugid="-debug" + fi + fi + + cat </dev/null && \ + restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}" + done + # hmac is .vmlinuz-.hmac so needs a special treatment + i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac" + if [[ -e "$i" ]]; then + rm -f "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" + cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" + command -v restorecon &>/dev/null && \ + restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac" + fi + fi + + if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then + if [[ -f /etc/kernel/cmdline ]]; then + read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline + elif [[ -f /usr/lib/kernel/cmdline ]]; then + read -r -d '' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline + else + declare -a BOOT_OPTIONS + + read -r -d '' -a line < /proc/cmdline + for i in "${line[@]}"; do + [[ "${i#initrd=*}" != "$i" ]] && continue + [[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue + BOOT_OPTIONS+=("$i") + done + fi + + eval "$(grub2-get-kernel-settings)" || true + [[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR" + BLS_ID="${MACHINE_ID}-${KERNEL_VERSION}" + BLS_TARGET="${BLS_DIR}/${BLS_ID}.conf" + mkbls "${KERNEL_VERSION}" \ + "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${KERNEL_DIR}")")" \ + "${BOOT_OPTIONS[*]}" >"${BLS_TARGET}" + command -v restorecon &>/dev/null && restorecon -R "${BLS_TARGET}" + + LINUX="$(grep '^linux[ \t]' "${BLS_TARGET}" | sed -e 's,^linux[ \t]*,,')" + INITRD="$(grep '^initrd[ \t]' "${BLS_TARGET}" | sed -e 's,^initrd[ \t]*,,')" + LINUX_RELPATH="$(grub2-mkrelpath /boot${LINUX})" + BOOTPREFIX="$(dirname ${LINUX_RELPATH})" + ROOTPREFIX="$(dirname "/boot${LINUX}")" + + if [[ $LINUX != $LINUX_RELPATH ]]; then + sed -i -e "s,^linux.*,linux ${BOOTPREFIX}${LINUX},g" "${BLS_TARGET}" + sed -i -e "s,^initrd.*,initrd ${BOOTPREFIX}${INITRD},g" "${BLS_TARGET}" + fi + + if [[ "$KERNEL_VERSION" == *\+* ]] && [ "x$GRUB_DEFAULT_TO_DEBUG" != "xtrue" ]; then + GRUB_UPDATE_DEFAULT_KERNEL=false + fi + + if [ "x$GRUB_UPDATE_DEFAULT_KERNEL" = "xtrue" ]; then + NEWDEFAULT="${BLS_ID}" + fi + + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then + BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")" + cp -aT "${BLS_TARGET}" "${BLS_DEBUG}" + TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')" + OPTIONS="$(echo "${BOOT_OPTIONS[*]} ${GRUB_CMDLINE_LINUX_DEBUG}" | sed -e 's/\//\\\//g')" + sed -i -e "s/^title.*/title ${TITLE}${GRUB_LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}" + sed -i -e "s/^options.*/options ${OPTIONS}/" "${BLS_DEBUG}" + if [ -n "$NEWDEFAULT" -a "x$GRUB_DEFAULT_TO_DEBUG" = "xtrue" ]; then + NEWDEFAULT="${BLS_DEBUG_ID}" + fi + fi + if [ -n "$NEWDEFAULT" ]; then + grub2-editenv - set "saved_entry=${NEWDEFAULT}" + fi + + # this probably isn't the best place to do this, but it will do for now. + if [ -e "${ROOTPREFIX}${INITRD}" -a -e "${ROOTPREFIX}${LINUX}" -a \ + "${ROOTPREFIX}${INITRD}" -ot "${ROOTPREFIX}${LINUX}" -a \ + -x /usr/lib/kernel/install.d/50-dracut.install ]; then + rm -f "${ROOTPREFIX}${INITRD}" + fi + exit 0 + fi + + /sbin/new-kernel-pkg --package "kernel${flavor}" --install "$KERNEL_VERSION" || exit $? + /sbin/new-kernel-pkg --package "kernel${flavor}" --mkinitrd --dracut --depmod --update "$KERNEL_VERSION" || exit $? + /sbin/new-kernel-pkg --package "kernel${flavor}" --rpmposttrans "$KERNEL_VERSION" || exit $? + # If grubby is used there's no need to run other installation plugins + exit 77 + ;; + remove) + + if [[ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]] || [[ ! -f /sbin/new-kernel-pkg ]]; then + BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf" + BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")" + rm -f "${BLS_TARGET}" "${BLS_DEBUG}" + + for i in vmlinuz System.map config zImage.stub dtb; do + rm -rf "/boot/${i}-${KERNEL_VERSION}" + done + # hmac is .vmlinuz-.hmac so needs a special treatment + rm -f "/boot/.vmlinuz-${KERNEL_VERSION}.hmac" + + exit 0 + fi + + /sbin/new-kernel-pkg --package "kernel${flavor+-$flavor}" --rminitrd --rmmoddep --remove "$KERNEL_VERSION" || exit $? + # If grubby is used there's no need to run other installation plugins + exit 77 + ;; + *) + ;; +esac diff --git a/99-grub-mkconfig.install b/99-grub-mkconfig.install new file mode 100755 index 0000000..d9686b5 --- /dev/null +++ b/99-grub-mkconfig.install @@ -0,0 +1,59 @@ +#!/bin/bash + +if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then + exit 0 +fi + +# PV and PVH Xen DomU guests boot with pygrub that doesn't have BLS support, +# also Xen Dom0 use the menuentries from 20_linux_xen and not the ones from +# 10_linux. So BLS support needs to be disabled for both Xen Dom0 and DomU. +if [[ -e /sys/hypervisor/type ]] && grep -q "^xen$" /sys/hypervisor/type; then + RUN_MKCONFIG=true + DISABLE_BLS=true +fi + +ARCH=$(uname -m) +# Older ppc64le OPAL firmware (petitboot version < 1.8.0) don't have BLS support +# so grub2-mkconfig has to be run to generate a config with menuentry commands. +if [[ $ARCH = "ppc64le" ]] && [ -d /sys/firmware/opal ]; then + + petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot" + + if test -e ${petitboot_path}; then + read -r -d '' petitboot_version < ${petitboot_path} + petitboot_version="$(echo ${petitboot_version//v})" + major_version="$(echo ${petitboot_version} | cut -d . -f1)" + minor_version="$(echo ${petitboot_version} | cut -d . -f2)" + + if test -z ${petitboot_version} || test ${major_version} -lt 1 || \ + test ${major_version} -eq 1 -a ${minor_version} -lt 8; then + RUN_MKCONFIG=true + fi + else + RUN_MKCONFIG=true + fi +fi + +if [[ $DISABLE_BLS = "true" ]]; then + if grep -q '^GRUB_ENABLE_BLSCFG="*true"*\s*$' /etc/default/grub; then + sed -i 's/^GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/' /etc/default/grub + fi +fi + +# A traditional grub configuration file needs to be generated only in the case when +# the bootloaders are not capable of populating a menu entry from the BLS fragments. +if [[ $RUN_MKCONFIG != "true" ]]; then + exit 0 +fi + +[[ -f /etc/default/grub ]] && . /etc/default/grub + +COMMAND="$1" + +case "$COMMAND" in + add|remove) + grub2-mkconfig --no-grubenv-update -o /boot/grub2/grub.cfg >& /dev/null + ;; + *) + ;; +esac diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d78a498 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +# +# Makefile +# Peter Jones, 2018-07-11 02:39 +# + +define get-config +$(shell git config --local --get "grub2.$(1)") +endef + +FEDVER ?= $(call get-config, rebase.fedora-version) +ifeq ($(FEDVER),) +override FEDVER = 29 +endif + +ARCH ?= +ifneq ($(ARCH),) +override ARCH := $(foreach x,$(ARCH), --arch-override=$(x)) +endif + +# this is wacky because just using wildcard gets the list from before clean +# happens. +SOURCES ?= $(shell ls *.src.rpm) + +all: + +push : + git push + +clean : + @rm -vf *.src.rpm + +srpm : clean + fedpkg srpm + +scratch: srpm + koji build --scratch ${ARCH} f${FEDVER} $(SOURCES) + +release: + fedpkg build --target f${FEDVER} ${ARCH} + +rebase: + ./do-rebase --nocommit --nobumpspec f${FEDVER} ${REPO} + +rpmspec: + rpmspec -D "_sourcedir $(shell pwd)" -P grub2.spec + +rebuild: srpm + rpmbuild --rebuild $(SOURCES) + +local prep mockbuild compile : + fedpkg $@ + +.PHONY: all push srpm scratch release rebase rpmspec local prep mockbuild compile clean + +# vim:ft=make diff --git a/README.Fedora b/README.Fedora new file mode 100644 index 0000000..efa29ad --- /dev/null +++ b/README.Fedora @@ -0,0 +1,70 @@ +Using GNU GRUB 2 in Fedora +========================== + +GRUB 2 provides various feature enhancements over the previous GRUB version +(referred to as "GRUB", or "GRUB Legacy") which has been unmaintained upstream +for years. GRUB has thus been deprecated in Fedora and replaced by GRUB 2 for +BIOS systems. (EFI systems still uses GRUB Legacy from the new grub-efi package.) + +Utilities +--------- + +The GRUB 2 utilities are prefixed with 'grub2': + +grub2-bin2h +grub2-editenv +grub2-fstest +grub2-install +grub2-kbdcomp +grub2-menulst2cfg +grub2-mkconfig +grub2-mkdevicemap +grub2-mkfont +grub2-mkimage +grub2-mklayout +grub2-mknetdir +grub2-mkpasswd-pbkdf2 +grub2-mkrelpath +grub2-mkrescue +grub2-probe +grub2-reboot +grub2-script-check +grub2-set-default +grub2-setup + +The default location for boot loader installation is /boot/grub2/ . + +GRUB 2 in Fedora +---------------- + +The Fedora installer (anaconda) will make sure grub2 is installed for new and +updated systems. It will run grub2-install to install the boot loader in the +MBR and in /boot/grub2/, and it will write /etc/default/grub and run +grub2-mkconfig to create /boot/grub2/grub.cfg. + +The active boot loader will not be changed when the GRUB 2 package is updated. +A new boot loader can be installed with something like: + + grub2-install /dev/sda + +grubby will patch grub.cfg (through /etc/grub2.cfg) when new kernels are +installed. The GRUB 2 configuration system in /etc/default/grub and /etc/grub.d/ +is thus only used initially by anaconda, but it is possible to generate a new +grub.cfg with: + + grub2-mkconfig -o /boot/grub2/grub.cfg + +Documentation +------------- + +The GRUB 2 manual can be found in grub.html or on +http://www.gnu.org/software/grub/manual/ . + +Support channels +---------------- + +If you find a bug in this package, report them to the Red Hat Bugzilla [2]. +For talk about using grub2, use IRC channel #grub on freenode Network [3]. + +[2] http://bugzilla.redhat.com/ +[3] http://freenode.net/ diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..5b08e7e --- /dev/null +++ b/bootstrap @@ -0,0 +1,1073 @@ +#! /bin/sh +# Print a version string. +scriptversion=2019-01-04.17; # UTC + +# Bootstrap this package from checked-out sources. + +# Copyright (C) 2003-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Originally written by Paul Eggert. The canonical version of this +# script is maintained as build-aux/bootstrap in gnulib, however, to +# be useful to your project, you should place a copy of it under +# version control in the top-level directory of your project. The +# intent is that all customization can be done with a bootstrap.conf +# file also maintained in your version control; gnulib comes with a +# template build-aux/bootstrap.conf to get you started. + +# Please report bugs or propose patches to bug-gnulib@gnu.org. + +nl=' +' + +# Ensure file names are sorted consistently across platforms. +LC_ALL=C +export LC_ALL + +# Ensure that CDPATH is not set. Otherwise, the output from cd +# would cause trouble in at least one use below. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +local_gl_dir=gl + +# Honor $PERL, but work even if there is none. +PERL="${PERL-perl}" + +me=$0 + +default_gnulib_url=git://git.sv.gnu.org/gnulib + +usage() { + cat <&2 +} + +# warn_ WORD1... +warn_ () +{ + # If IFS does not start with ' ', set it and emit the warning in a subshell. + case $IFS in + ' '*) warnf_ '%s\n' "$*";; + *) (IFS=' '; warn_ "$@");; + esac +} + +# die WORD1... +die() { warn_ "$@"; exit 1; } + +# Configuration. + +# Name of the Makefile.am +gnulib_mk=gnulib.mk + +# List of gnulib modules needed. +gnulib_modules= + +# Any gnulib files needed that are not in modules. +gnulib_files= + +: ${AUTOPOINT=autopoint} +: ${AUTORECONF=autoreconf} + +# A function to be called right after gnulib-tool is run. +# Override it via your own definition in bootstrap.conf. +bootstrap_post_import_hook() { :; } + +# A function to be called after everything else in this script. +# Override it via your own definition in bootstrap.conf. +bootstrap_epilogue() { :; } + +# The command to download all .po files for a specified domain into a +# specified directory. Fill in the first %s with the destination +# directory and the second with the domain name. +po_download_command_format=\ +"wget --mirror --level=1 -nd -q -A.po -P '%s' \ + https://translationproject.org/latest/%s/" + +# Prefer a non-empty tarname (4th argument of AC_INIT if given), else +# fall back to the package name (1st argument with munging) +extract_package_name=' + /^AC_INIT(\[*/{ + s/// + /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{ + s//\1/ + s/[],)].*// + p + q + } + s/[],)].*// + s/^GNU // + y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ + s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g + p + } +' +package=$(sed -n "$extract_package_name" configure.ac) \ + || die 'cannot find package name in configure.ac' +gnulib_name=lib$package + +build_aux=build-aux +source_base=lib +m4_base=m4 +doc_base=doc +tests_base=tests +gnulib_extra_files=" + build-aux/install-sh + build-aux/mdate-sh + build-aux/texinfo.tex + build-aux/depcomp + build-aux/config.guess + build-aux/config.sub + doc/INSTALL +" + +# Additional gnulib-tool options to use. Use "\newline" to break lines. +gnulib_tool_option_extras= + +# Other locale categories that need message catalogs. +EXTRA_LOCALE_CATEGORIES= + +# Additional xgettext options to use. Use "\\\newline" to break lines. +XGETTEXT_OPTIONS='\\\ + --flag=_:1:pass-c-format\\\ + --flag=N_:1:pass-c-format\\\ + --flag=error:3:c-format --flag=error_at_line:5:c-format\\\ +' + +# Package bug report address and copyright holder for gettext files +COPYRIGHT_HOLDER='Free Software Foundation, Inc.' +MSGID_BUGS_ADDRESS=bug-$package@gnu.org + +# Files we don't want to import. +excluded_files= + +# File that should exist in the top directory of a checked out hierarchy, +# but not in a distribution tarball. +checkout_only_file=README-hacking + +# Whether to use copies instead of symlinks. +copy=false + +# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want +# those files to be generated in directories like lib/, m4/, and po/. +# Or set it to 'auto' to make this script select which to use based +# on which version control system (if any) is used in the source directory. +vc_ignore=auto + +# Set this to true in bootstrap.conf to enable --bootstrap-sync by +# default. +bootstrap_sync=false + +# Use git to update gnulib sources +use_git=true + +check_exists() { + if test "$1" = "--verbose"; then + ($2 --version /dev/null 2>&1 + if test $? -ge 126; then + # If not found, run with diagnostics as one may be + # presented with env variables to set to find the right version + ($2 --version /dev/null 2>&1 + fi + + test $? -lt 126 +} + +# find_tool ENVVAR NAMES... +# ------------------------- +# Search for a required program. Use the value of ENVVAR, if set, +# otherwise find the first of the NAMES that can be run. +# If found, set ENVVAR to the program name, die otherwise. +# +# FIXME: code duplication, see also gnu-web-doc-update. +find_tool () +{ + find_tool_envvar=$1 + shift + find_tool_names=$@ + eval "find_tool_res=\$$find_tool_envvar" + if test x"$find_tool_res" = x; then + for i; do + if check_exists $i; then + find_tool_res=$i + break + fi + done + fi + if test x"$find_tool_res" = x; then + warn_ "one of these is required: $find_tool_names;" + die "alternatively set $find_tool_envvar to a compatible tool" + fi + eval "$find_tool_envvar=\$find_tool_res" + eval "export $find_tool_envvar" +} + +# Override the default configuration, if necessary. +# Make sure that bootstrap.conf is sourced from the current directory +# if we were invoked as "sh bootstrap". +case "$0" in + */*) test -r "$0.conf" && . "$0.conf" ;; + *) test -r "$0.conf" && . ./"$0.conf" ;; +esac + +if test "$vc_ignore" = auto; then + vc_ignore= + test -d .git && vc_ignore=.gitignore + test -d CVS && vc_ignore="$vc_ignore .cvsignore" +fi + +if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then + use_gnulib=false +else + use_gnulib=true +fi + +# Translate configuration into internal form. + +# Parse options. + +for option +do + case $option in + --help) + usage + exit;; + --gnulib-srcdir=*) + GNULIB_SRCDIR=${option#--gnulib-srcdir=};; + --skip-po) + SKIP_PO=t;; + --force) + checkout_only_file=;; + --copy) + copy=true;; + --bootstrap-sync) + bootstrap_sync=true;; + --no-bootstrap-sync) + bootstrap_sync=false;; + --no-git) + use_git=false;; + *) + die "$option: unknown option";; + esac +done + +$use_git || test -d "$GNULIB_SRCDIR" \ + || die "Error: --no-git requires --gnulib-srcdir" + +if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then + die "Bootstrapping from a non-checked-out distribution is risky." +fi + +# Strip blank and comment lines to leave significant entries. +gitignore_entries() { + sed '/^#/d; /^$/d' "$@" +} + +# If $STR is not already on a line by itself in $FILE, insert it at the start. +# Entries are inserted at the start of the ignore list to ensure existing +# entries starting with ! are not overridden. Such entries support +# whitelisting exceptions after a more generic blacklist pattern. +insert_if_absent() { + file=$1 + str=$2 + test -f $file || touch $file + test -r $file || die "Error: failed to read ignore file: $file" + duplicate_entries=$(gitignore_entries $file | sort | uniq -d) + if [ "$duplicate_entries" ] ; then + die "Error: Duplicate entries in $file: " $duplicate_entries + fi + linesold=$(gitignore_entries $file | wc -l) + linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l) + if [ $linesold != $linesnew ] ; then + { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \ + || die "insert_if_absent $file $str: failed" + fi +} + +# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with +# insert_if_absent. +insert_vc_ignore() { + vc_ignore_file="$1" + pattern="$2" + case $vc_ignore_file in + *.gitignore) + # A .gitignore entry that does not start with '/' applies + # recursively to subdirectories, so prepend '/' to every + # .gitignore entry. + pattern=$(echo "$pattern" | sed s,^,/,);; + esac + insert_if_absent "$vc_ignore_file" "$pattern" +} + +# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac. +found_aux_dir=no +grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \ + >/dev/null && found_aux_dir=yes +grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \ + >/dev/null && found_aux_dir=yes +test $found_aux_dir = yes \ + || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it" + +# If $build_aux doesn't exist, create it now, otherwise some bits +# below will malfunction. If creating it, also mark it as ignored. +if test ! -d $build_aux; then + mkdir $build_aux + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + insert_vc_ignore $dot_ig $build_aux + done +fi + +# Note this deviates from the version comparison in automake +# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a +# but this should suffice as we won't be specifying old +# version formats or redundant trailing .0 in bootstrap.conf. +# If we did want full compatibility then we should probably +# use m4_version_compare from autoconf. +sort_ver() { # sort -V is not generally available + ver1="$1" + ver2="$2" + + # split on '.' and compare each component + i=1 + while : ; do + p1=$(echo "$ver1" | cut -d. -f$i) + p2=$(echo "$ver2" | cut -d. -f$i) + if [ ! "$p1" ]; then + echo "$1 $2" + break + elif [ ! "$p2" ]; then + echo "$2 $1" + break + elif [ ! "$p1" = "$p2" ]; then + if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison + echo "$2 $1" + elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison + echo "$1 $2" + else # numeric, then lexicographic comparison + lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1) + if [ "$lp" = "$p2" ]; then + echo "$1 $2" + else + echo "$2 $1" + fi + fi + break + fi + i=$(($i+1)) + done +} + +get_version_sed=' +# Move version to start of line. +s/.*[v ]\([0-9]\)/\1/ + +# Skip lines that do not start with version. +/^[0-9]/!d + +# Remove characters after the version. +s/[^.a-z0-9-].*// + +# The first component must be digits only. +s/^\([0-9]*\)[a-z-].*/\1/ + +#the following essentially does s/5.005/5.5/ +s/\.0*\([1-9]\)/.\1/g +p +q' + +get_version() { + app=$1 + + $app --version >/dev/null 2>&1 || { $app --version; return 1; } + + $app --version 2>&1 | sed -n "$get_version_sed" +} + +check_versions() { + ret=0 + + while read app req_ver; do + # We only need libtoolize from the libtool package. + if test "$app" = libtool; then + app=libtoolize + fi + # Exempt git if --no-git is in effect. + if test "$app" = git; then + $use_git || continue + fi + # Honor $APP variables ($TAR, $AUTOCONF, etc.) + appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_') + test "$appvar" = TAR && appvar=AMTAR + case $appvar in + GZIP) ;; # Do not use $GZIP: it contains gzip options. + PERL::*) ;; # Keep perl modules as-is + *) eval "app=\${$appvar-$app}" ;; + esac + + # Handle the still-experimental Automake-NG programs specially. + # They remain named as the mainstream Automake programs ("automake", + # and "aclocal") to avoid gratuitous incompatibilities with + # pre-existing usages (by, say, autoreconf, or custom autogen.sh + # scripts), but correctly identify themselves (as being part of + # "GNU automake-ng") when asked their version. + case $app in + automake-ng|aclocal-ng) + app=${app%-ng} + ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || { + warn_ "Error: '$app' not found or not from Automake-NG" + ret=1 + continue + } ;; + # Another check is for perl modules. These can be written as + # e.g. perl::XML::XPath in case of XML::XPath module, etc. + perl::*) + # Extract module name + app="${app#perl::}" + if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then + warn_ "Error: perl module '$app' not found" + ret=1 + fi + continue + ;; + esac + if [ "$req_ver" = "-" ]; then + # Merely require app to exist; not all prereq apps are well-behaved + # so we have to rely on $? rather than get_version. + if ! check_exists --verbose $app; then + warn_ "Error: '$app' not found" + ret=1 + fi + else + # Require app to produce a new enough version string. + inst_ver=$(get_version $app) + if [ ! "$inst_ver" ]; then + warn_ "Error: '$app' not found" + ret=1 + else + latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2) + if [ ! "$latest_ver" = "$inst_ver" ]; then + warnf_ '%s\n' \ + "Error: '$app' version == $inst_ver is too old" \ + " '$app' version >= $req_ver is required" + ret=1 + fi + fi + fi + done + + return $ret +} + +print_versions() { + echo "Program Min_version" + echo "----------------------" + printf %s "$buildreq" + echo "----------------------" + # can't depend on column -t +} + +# Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6. +# Also find the compatible sha1 utility on the BSDs +if test x"$SKIP_PO" = x; then + find_tool SHA1SUM sha1sum gsha1sum shasum sha1 +fi + +use_libtool=0 +# We'd like to use grep -E, to see if any of LT_INIT, +# AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac, +# but that's not portable enough (e.g., for Solaris). +grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \ + && use_libtool=1 +grep '^[ ]*LT_INIT' configure.ac >/dev/null \ + && use_libtool=1 +if test $use_libtool = 1; then + find_tool LIBTOOLIZE glibtoolize libtoolize +fi + +# gnulib-tool requires at least automake and autoconf. +# If either is not listed, add it (with minimum version) as a prerequisite. +case $buildreq in + *automake*) ;; + *) buildreq="automake 1.9 +$buildreq" ;; +esac +case $buildreq in + *autoconf*) ;; + *) buildreq="autoconf 2.59 +$buildreq" ;; +esac + +# When we can deduce that gnulib-tool will require patch, +# and when patch is not already listed as a prerequisite, add it, too. +if test -d "$local_gl_dir" \ + && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then + case $buildreq in + *patch*) ;; + *) buildreq="patch - +$buildreq" ;; + esac +fi + +if ! printf "$buildreq" | check_versions; then + echo >&2 + if test -f README-prereq; then + die "See README-prereq for how to get the prerequisite programs" + else + die "Please install the prerequisite programs" + fi +fi + +# Warn the user if autom4te appears to be broken; this causes known +# issues with at least gettext 0.18.3. +probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -) +if test "x$probe" != xhi; then + warn_ "WARNING: your autom4te wrapper eats stdin;" + warn_ "if bootstrap fails, consider upgrading your autotools" +fi + +echo "$0: Bootstrapping from checked-out $package sources..." + +# See if we can use gnulib's git-merge-changelog merge driver. +if $use_git && test -d .git && check_exists git; then + if git config merge.merge-changelog.driver >/dev/null ; then + : + elif check_exists git-merge-changelog; then + echo "$0: initializing git-merge-changelog driver" + git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver' + git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B' + else + echo "$0: consider installing git-merge-changelog from gnulib" + fi +fi + + +cleanup_gnulib() { + status=$? + rm -fr "$gnulib_path" + exit $status +} + +git_modules_config () { + test -f .gitmodules && git config --file .gitmodules "$@" +} + +if $use_gnulib; then + if $use_git; then + gnulib_path=$(git_modules_config submodule.gnulib.path) + test -z "$gnulib_path" && gnulib_path=gnulib + fi + + # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a + # submodule, for use in the rest of the script. + + case ${GNULIB_SRCDIR--} in + -) + # Note that $use_git is necessarily true in this case. + if git_modules_config submodule.gnulib.url >/dev/null; then + echo "$0: getting gnulib files..." + git submodule init -- "$gnulib_path" || exit $? + git submodule update -- "$gnulib_path" || exit $? + + elif [ ! -d "$gnulib_path" ]; then + echo "$0: getting gnulib files..." + + trap cleanup_gnulib 1 2 13 15 + + shallow= + if test -z "$GNULIB_REVISION"; then + git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2' + fi + git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \ + || cleanup_gnulib + + trap - 1 2 13 15 + fi + GNULIB_SRCDIR=$gnulib_path + ;; + *) + # Use GNULIB_SRCDIR directly or as a reference. + if $use_git && test -d "$GNULIB_SRCDIR"/.git && \ + git_modules_config submodule.gnulib.url >/dev/null; then + echo "$0: getting gnulib files..." + if git submodule -h|grep -- --reference > /dev/null; then + # Prefer the one-liner available in git 1.6.4 or newer. + git submodule update --init --reference "$GNULIB_SRCDIR" \ + "$gnulib_path" || exit $? + else + # This fallback allows at least git 1.5.5. + if test -f "$gnulib_path"/gnulib-tool; then + # Since file already exists, assume submodule init already complete. + git submodule update -- "$gnulib_path" || exit $? + else + # Older git can't clone into an empty directory. + rmdir "$gnulib_path" 2>/dev/null + git clone --reference "$GNULIB_SRCDIR" \ + "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \ + && git submodule init -- "$gnulib_path" \ + && git submodule update -- "$gnulib_path" \ + || exit $? + fi + fi + GNULIB_SRCDIR=$gnulib_path + fi + ;; + esac + + if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \ + && ! git_modules_config submodule.gnulib.url >/dev/null; then + (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib + fi + + # $GNULIB_SRCDIR now points to the version of gnulib to use, and + # we no longer need to use git or $gnulib_path below here. + + if $bootstrap_sync; then + cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || { + echo "$0: updating bootstrap and restarting..." + case $(sh -c 'echo "$1"' -- a) in + a) ignored=--;; + *) ignored=ignored;; + esac + exec sh -c \ + 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \ + $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \ + "$0" "$@" --no-bootstrap-sync + } + fi + + gnulib_tool=$GNULIB_SRCDIR/gnulib-tool + <$gnulib_tool || exit $? +fi + +# Get translations. + +download_po_files() { + subdir=$1 + domain=$2 + echo "$me: getting translations into $subdir for $domain..." + cmd=$(printf "$po_download_command_format" "$subdir" "$domain") + eval "$cmd" +} + +# Mirror .po files to $po_dir/.reference and copy only the new +# or modified ones into $po_dir. Also update $po_dir/LINGUAS. +# Note po files that exist locally only are left in $po_dir but will +# not be included in LINGUAS and hence will not be distributed. +update_po_files() { + # Directory containing primary .po files. + # Overwrite them only when we're sure a .po file is new. + po_dir=$1 + domain=$2 + + # Mirror *.po files into this dir. + # Usually contains *.s1 checksum files. + ref_po_dir="$po_dir/.reference" + + test -d $ref_po_dir || mkdir $ref_po_dir || return + download_po_files $ref_po_dir $domain \ + && ls "$ref_po_dir"/*.po 2>/dev/null | + sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return + + langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g') + test "$langs" = '*' && langs=x + for po in $langs; do + case $po in x) continue;; esac + new_po="$ref_po_dir/$po.po" + cksum_file="$ref_po_dir/$po.s1" + if ! test -f "$cksum_file" || + ! test -f "$po_dir/$po.po" || + ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then + echo "$me: updated $po_dir/$po.po..." + cp "$new_po" "$po_dir/$po.po" \ + && $SHA1SUM < "$new_po" > "$cksum_file" || return + fi + done +} + +case $SKIP_PO in +'') + if test -d po; then + update_po_files po $package || exit + fi + + if test -d runtime-po; then + update_po_files runtime-po $package-runtime || exit + fi;; +esac + +symlink_to_dir() +{ + src=$1/$2 + dst=${3-$2} + + test -f "$src" && { + + # If the destination directory doesn't exist, create it. + # This is required at least for "lib/uniwidth/cjk.h". + dst_dir=$(dirname "$dst") + if ! test -d "$dst_dir"; then + mkdir -p "$dst_dir" + + # If we've just created a directory like lib/uniwidth, + # tell version control system(s) it's ignorable. + # FIXME: for now, this does only one level + parent=$(dirname "$dst_dir") + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + ig=$parent/$dot_ig + insert_vc_ignore $ig "${dst_dir##*/}" + done + fi + + if $copy; then + { + test ! -h "$dst" || { + echo "$me: rm -f $dst" && + rm -f "$dst" + } + } && + test -f "$dst" && + cmp -s "$src" "$dst" || { + echo "$me: cp -fp $src $dst" && + cp -fp "$src" "$dst" + } + else + # Leave any existing symlink alone, if it already points to the source, + # so that broken build tools that care about symlink times + # aren't confused into doing unnecessary builds. Conversely, if the + # existing symlink's timestamp is older than the source, make it afresh, + # so that broken tools aren't confused into skipping needed builds. See + # . + test -h "$dst" && + src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 && + dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 && + test "$src_i" = "$dst_i" && + both_ls=$(ls -dt "$src" "$dst") && + test "X$both_ls" = "X$dst$nl$src" || { + dot_dots= + case $src in + /*) ;; + *) + case /$dst/ in + *//* | */../* | */./* | /*/*/*/*/*/) + die "invalid symlink calculation: $src -> $dst";; + /*/*/*/*/) dot_dots=../../../;; + /*/*/*/) dot_dots=../../;; + /*/*/) dot_dots=../;; + esac;; + esac + + echo "$me: ln -fs $dot_dots$src $dst" && + ln -fs "$dot_dots$src" "$dst" + } + fi + } +} + +version_controlled_file() { + parent=$1 + file=$2 + if test -d .git; then + git rm -n "$file" > /dev/null 2>&1 + elif test -d .svn; then + svn log -r HEAD "$file" > /dev/null 2>&1 + elif test -d CVS; then + grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null | + grep '^/[^/]*/[0-9]' > /dev/null + else + warn_ "no version control for $file?" + false + fi +} + +# NOTE: we have to be careful to run both autopoint and libtoolize +# before gnulib-tool, since gnulib-tool is likely to provide newer +# versions of files "installed" by these two programs. +# Then, *after* gnulib-tool (see below), we have to be careful to +# run autoreconf in such a way that it does not run either of these +# two just-pre-run programs. + +# Import from gettext. +with_gettext=yes +grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \ + with_gettext=no + +if test $with_gettext = yes || test $use_libtool = 1; then + + tempbase=.bootstrap$$ + trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15 + + > $tempbase.0 > $tempbase.1 && + find . ! -type d -print | sort > $tempbase.0 || exit + + if test $with_gettext = yes; then + # Released autopoint has the tendency to install macros that have been + # obsoleted in current gnulib, so run this before gnulib-tool. + echo "$0: $AUTOPOINT --force" + $AUTOPOINT --force || exit + fi + + # Autoreconf runs aclocal before libtoolize, which causes spurious + # warnings if the initial aclocal is confused by the libtoolized + # (or worse out-of-date) macro directory. + # libtoolize 1.9b added the --install option; but we support back + # to libtoolize 1.5.22, where the install action was default. + if test $use_libtool = 1; then + install= + case $($LIBTOOLIZE --help) in + *--install*) install=--install ;; + esac + echo "running: $LIBTOOLIZE $install --copy" + $LIBTOOLIZE $install --copy + fi + + find . ! -type d -print | sort >$tempbase.1 + old_IFS=$IFS + IFS=$nl + for file in $(comm -13 $tempbase.0 $tempbase.1); do + IFS=$old_IFS + parent=${file%/*} + version_controlled_file "$parent" "$file" || { + for dot_ig in x $vc_ignore; do + test $dot_ig = x && continue + ig=$parent/$dot_ig + insert_vc_ignore "$ig" "${file##*/}" + done + } + done + IFS=$old_IFS + + rm -f $tempbase.0 $tempbase.1 + trap - 1 2 13 15 +fi + +# Import from gnulib. + +if $use_gnulib; then + gnulib_tool_options="\ + --no-changelog\ + --aux-dir=$build_aux\ + --doc-base=$doc_base\ + --lib=$gnulib_name\ + --m4-base=$m4_base/\ + --source-base=$source_base/\ + --tests-base=$tests_base\ + --local-dir=$local_gl_dir\ + $gnulib_tool_option_extras\ + " + if test $use_libtool = 1; then + case "$gnulib_tool_options " in + *' --libtool '*) ;; + *) gnulib_tool_options="$gnulib_tool_options --libtool" ;; + esac + fi + echo "$0: $gnulib_tool $gnulib_tool_options --import ..." + $gnulib_tool $gnulib_tool_options --import $gnulib_modules \ + || die "gnulib-tool failed" + + for file in $gnulib_files; do + symlink_to_dir "$GNULIB_SRCDIR" $file \ + || die "failed to symlink $file" + done +fi + +bootstrap_post_import_hook \ + || die "bootstrap_post_import_hook failed" + +# Don't proceed if there are uninitialized submodules. In particular, +# the next step will remove dangling links, which might be links into +# uninitialized submodules. +# +# Uninitialized submodules are listed with an initial dash. +if $use_git && git submodule | grep '^-' >/dev/null; then + die "some git submodules are not initialized. " \ + "Run 'git submodule init' and bootstrap again." +fi + +# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some +# gnulib-populated directories. Such .m4 files would cause aclocal to fail. +# The following requires GNU find 4.2.3 or newer. Considering the usual +# portability constraints of this script, that may seem a very demanding +# requirement, but it should be ok. Ignore any failure, which is fine, +# since this is only a convenience to help developers avoid the relatively +# unusual case in which a symlinked-to .m4 file is git-removed from gnulib +# between successive runs of this script. +find "$m4_base" "$source_base" \ + -depth \( -name '*.m4' -o -name '*.[ch]' \) \ + -type l -xtype l -delete > /dev/null 2>&1 + +# Invoke autoreconf with --force --install to ensure upgrades of tools +# such as ylwrap. +AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS" + +# Some systems (RHEL 5) are using ancient autotools, for which the +# --no-recursive option had not been invented. Detect that lack and +# omit the option when it's not supported. FIXME in 2017: remove this +# hack when RHEL 5 autotools are updated, or when they become irrelevant. +case $($AUTORECONF --help) in + *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";; +esac + +# Tell autoreconf not to invoke autopoint or libtoolize; they were run above. +echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS" +AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \ + || die "autoreconf failed" + +# Get some extra files from gnulib, overriding existing files. +for file in $gnulib_extra_files; do + case $file in + */INSTALL) dst=INSTALL;; + build-aux/*) dst=$build_aux/${file#build-aux/};; + *) dst=$file;; + esac + symlink_to_dir "$GNULIB_SRCDIR" $file $dst \ + || die "failed to symlink $file" +done + +if test $with_gettext = yes; then + # Create gettext configuration. + echo "$0: Creating po/Makevars from po/Makevars.template ..." + rm -f po/Makevars + sed ' + /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/ + /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/ + /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'| + /^XGETTEXT_OPTIONS *=/{ + s/$/ \\/ + a\ + '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+} + } + ' po/Makevars.template >po/Makevars \ + || die 'cannot generate po/Makevars' + + # If the 'gettext' module is in use, grab the latest Makefile.in.in. + # If only the 'gettext-h' module is in use, assume autopoint already + # put the correct version of this file into place. + case $gnulib_modules in + *gettext-h*) ;; + *gettext*) + cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \ + || die "cannot create po/Makefile.in.in" + ;; + esac + + if test -d runtime-po; then + # Similarly for runtime-po/Makevars, but not quite the same. + rm -f runtime-po/Makevars + sed ' + /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/ + /^subdir *=.*/s/=.*/= runtime-po/ + /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/ + /^XGETTEXT_OPTIONS *=/{ + s/$/ \\/ + a\ + '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+} + } + ' po/Makevars.template >runtime-po/Makevars \ + || die 'cannot generate runtime-po/Makevars' + + # Copy identical files from po to runtime-po. + (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po) + fi +fi + +bootstrap_epilogue + +echo "$0: done. Now you can run './configure'." + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/bootstrap.conf b/bootstrap.conf new file mode 100644 index 0000000..988dda0 --- /dev/null +++ b/bootstrap.conf @@ -0,0 +1,91 @@ +# Bootstrap configuration. + +# Copyright (C) 2006-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263 + +# gnulib modules used by this package. +# mbswidth is used by gnulib-fix-width.diff's changes to argp rather than +# directly. +gnulib_modules=" + argp + error + fnmatch + getdelim + getline + gettext-h + gitlog-to-changelog + mbswidth + progname + realloc-gnu + regex + save-cwd +" + +gnulib_tool_option_extras="\ + --no-conditional-dependencies \ + --no-vc-files \ +" + +gnulib_name=libgnu +source_base=grub-core/lib/gnulib +gnulib_extra_files=" + build-aux/install-sh + build-aux/mdate-sh + build-aux/texinfo.tex + build-aux/depcomp + build-aux/config.guess + build-aux/config.sub +" + +# Additional xgettext options to use. Use "\\\newline" to break lines. +XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ + --from-code=UTF-8\\\ +' + +checkout_only_file= +copy=true +vc_ignore= + +SKIP_PO=t + +# Build prerequisites +buildreq="\ +autoconf 2.63 +automake 1.11 +gettext 0.18.3 +git 1.5.5 +tar - +" + +# bootstrap doesn't give us a reasonable way to stop Automake from +# overwriting this, so we just copy our version aside and put it back later. +cp -a INSTALL INSTALL.grub + +bootstrap_post_import_hook () { + set -e + for patchname in fix-null-deref fix-width no-abort; do + patch -d grub-core/lib/gnulib -p2 \ + < "grub-core/lib/gnulib-patches/$patchname.patch" + done + FROM_BOOTSTRAP=1 ./autogen.sh + set +e # bootstrap expects this +} + +bootstrap_epilogue () { + mv INSTALL.grub INSTALL +} diff --git a/do-rebase b/do-rebase new file mode 100755 index 0000000..1f9b21c --- /dev/null +++ b/do-rebase @@ -0,0 +1,189 @@ +#!/bin/bash +set -e +set -u +shopt -qu globstar +shopt -qs expand_aliases +export LC_COLLATE=C +export LC_ALL=C + +diff_ops="-O.git.diff.order --patience -l0" +format_patch_ops="--zero-commit --no-signature --no-numbered --stat=80 --summary $diff_ops" +alias othergit="GIT_DIR=$PWD/.rhboot.git GIT_WORK_TREE=$PWD git" +alias formatpatch="othergit format-patch $format_patch_ops" + +usage() +{ + retcode=0 + if [ -n "${1:-}" ]; then + exec 1>&2 + retcode=$1 + fi + echo usage: "do-rebase [OPTIONS] [--dist RELEASEVER | RELEASEVER ] [GITREPO]" + echo OPTIONS: --dist=RELEASEVER --repo=REPO --amend --nocommit --nobumpspec + exit $retcode +} + +if ! git status | grep -q 'nothing to commit, working .* clean' ; then + echo "Working directory is not clean, cannot rebase." 1>&2 + exit 1 +fi + +gitrepo="git@github.com:rhboot/grub2.git" +releasever="" +amend="" +commit=1 +bumpspec=1 + +declare -a savedargs +savedargs=() +while [ $# -gt 0 ]; do + case $1 in + --help|-h|--usage|-?|-u) + usage + ;; + --dist=*) + releasever=${1##--dist=} + ;; + --dist) + shift + releasever=$1 + ;; + --repo=*) + gitrepo=${1##--repo=} + ;; + --repo) + shift + gitrepo=$1 + ;; + --amend) + amend="--amend" + ;; + --commit) + commit=1 + ;; + --nocommit|--no-commit|--nc) + # --nocommit implies nobumpspec, but --bumpspec after it will + # force bumpspec to get run. + commit=0 + bumpspec=0 + ;; + --bumpspec) + bumpspec=2 + ;; + --nobumpspec|--no-bumpspec|--nb) + bumpspec=0 + ;; + *) + savedargs[${#savedargs[@]}]="$1" + ;; + esac + shift +done +set -- "${savedargs[@]}" + +if [ -z "${releasever}" -a $# -gt 0 ]; then + releasever=$1 + shift +else + dist=$(git status | grep "On branch" | cut -d\ -f3-) + if [ -z "$dist" ]; then + echo "Could not figure out distro release version" 1>&2 + usage 1 + fi + case "$(eval echo \${dist})" in + .fc*) + releasever=$(echo ${dist} | \ + sed 's/^\.fc\([[:digit:]]\+\)$/fedora-\1/') + ;; + .*) + releasever=$(echo $dist | \ + sed 's/^\.\([[:alpha:]]\+\)\([[:digit:]]\+\)$/\1-\2/') + ;; + rhel*) + releasever=${dist} + dist=.el${releasever##rhel-} + ;; + esac + if [ -z "${releasever}" -o "${releasever}" = "${dist}" ]; then + echo "Could not figure out distro release version" 1>&2 + usage 1 + fi +fi + +if [ -z "$releasever" ]; then + echo "Could not figure out distro release version" 1>&2 + usage 1 +fi + +if [ -n "${1:-}" ]; then + gitrepo=$1 + shift +fi + +if [ $# -ge 1 ]; then + echo "Unknown argument \"$1\"" 1>&2 + usage 1 +fi + +if [ ! -d $PWD/.rhboot.git ]; then + othergit init + othergit config core.abbrev 11 + if ! othergit remote add \ + rhboot $gitrepo \ + >/dev/null 2>&1 ; then + echo "Could not add remote: rhboot" 1>&2 + exit 1 + fi +elif othergit remote show -n rhboot | grep -q "URL: github$" ; then + if ! othergit remote add \ + rhboot $gitrepo \ + >/dev/null 2>&1 ; then + echo "Could not add remote: rhboot" 1>&2 + exit 1 + fi +else + othergit remote set-url rhboot ${gitrepo} +fi + +othergit fetch rhboot +remote=$(othergit branch --list -r "rhboot/${releasever}" 2>/dev/null) +if [ "${remote}" != " rhboot/${releasever}" ]; then + echo branch \"${releasever}\" does not appear to exist 1>&2 + exit 1 +fi + +unset LC_ALL +git rm -q 0*.patch + +# No need for this patch anymore, the package is rebased on latest release now. +#> release-to-master.patch +#othergit diff --full-index --binary $diff_ops grub-2.04..refs/remotes/rhboot/master > release-to-master.patch +#git add release-to-master.patch + +fedpkg sources +curl -L https://github.com/rhboot/gnulib/archive/fixes.tar.gz > gnulib-fixes.tar.gz.new +if cmp -s gnulib-fixes.tar.gz gnulib-fixes.tar.gz.new; then + rm gnulib-fixes.tar.gz.new +else + mv gnulib-fixes.tar.gz.new gnulib-fixes.tar.gz + sed -i -e '/gnulib-/d' sources + fedpkg upload gnulib-fixes.tar.gz + git add sources +fi + +> grub.patches +patches=$(formatpatch refs/remotes/rhboot/master..refs/remotes/rhboot/${releasever}) +for x in $patches ; do + echo Patch$(echo ${x} | cut -d- -f1): ${x} >> grub.patches +done +if [[ -z "$amend" && ${bumpspec} -gt 0 ]] || [[ ${bumpspec} -ge 2 ]] ; then + rpmdev-bumpspec -c "- Rebased to newer upstream for ${releasever}" grub2.spec +fi +git add 0*.patch grub2.spec grub.patches +if [[ ${commit} -eq 1 ]] ; then + if [ -z "$amend" ]; then + fedpkg commit -s -c + else + git commit --amend + fi +fi diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..819cd18 --- /dev/null +++ b/gitignore @@ -0,0 +1,237 @@ +*~ +00_header +10_* +20_linux_xen +30_os-prober +40_custom +41_custom +*.1 +*.8 +ABOUT-NLS +aclocal.m4 +ahci_test +ascii.bitmaps +ascii.h +autom4te.cache +build-aux +build-grub-gen-asciih +build-grub-gen-widthspec +build-grub-mkfont +cdboot_test +cmp_test +config.cache +config.guess +config.h +config-util.h +config-util.h.in +config.log +config.status +config.sub +configure +core_compress_test +DISTLIST +docs/*.info +docs/stamp-vti +docs/version.texi +ehci_test +example_grub_script_test +example_scripted_test +example_unit_test +*.exec +*.exec.exe +fddboot_test +genkernsyms.sh +gensymlist.sh +gentrigtables +gentrigtables.exe +gettext_strings_test +/gnulib +grub-bin2h +/grub-bios-setup +/grub-bios-setup.exe +grub_cmd_date +grub_cmd_echo +grub_cmd_regexp +grub_cmd_set_date +grub_cmd_sleep +/grub-editenv +/grub-editenv.exe +grub-emu +grub-emu-lite +grub-emu.exe +grub-emu-lite.exe +grub_emu_init.c +grub_emu_init.h +/grub-file +/grub-file.exe +grub-fstest +grub-fstest.exe +grub_fstest_init.c +grub_fstest_init.h +grub_func_test +grub-install +grub-install.exe +grub-kbdcomp +/grub-macbless +/grub-macbless.exe +grub-macho2img +/grub-menulst2cfg +/grub-menulst2cfg.exe +/grub-mk* +grub-mount +/grub-ofpathname +/grub-ofpathname.exe +grub-core/build-grub-pe2elf.exe +/grub-probe +/grub-probe.exe +grub_probe_init.c +grub_probe_init.h +/grub-reboot +grub_script_blanklines +grub_script_blockarg +grub_script_break +grub-script-check +grub-script-check.exe +grub_script_check_init.c +grub_script_check_init.h +grub_script_comments +grub_script_continue +grub_script_dollar +grub_script_echo1 +grub_script_echo_keywords +grub_script_escape_comma +grub_script_eval +grub_script_expansion +grub_script_final_semicolon +grub_script_for1 +grub_script_functions +grub_script_gettext +grub_script_if +grub_script_leading_whitespace +grub_script_no_commands +grub_script_not +grub_script_return +grub_script_setparams +grub_script_shift +grub_script_strcmp +grub_script_test +grub_script_vars1 +grub_script_while1 +grub_script.tab.c +grub_script.tab.h +grub_script.yy.c +grub_script.yy.h +grub-set-default +grub_setup_init.c +grub_setup_init.h +grub-shell +grub-shell-tester +grub-sparc64-setup +grub-sparc64-setup.exe +/grub-syslinux2cfg +/grub-syslinux2cfg.exe +gzcompress_test +hddboot_test +help_test +*.img +*.image +*.image.exe +include/grub/cpu +include/grub/machine +INSTALL.grub +install-sh +lib/libgcrypt-grub +libgrub_a_init.c +*.log +*.lst +lzocompress_test +*.marker +Makefile +/m4 +*.mod +mod-*.c +missing +netboot_test +*.o +*.a +ohci_test +partmap_test +pata_test +*.pf2 +*.pp +po/*.mo +po/grub.pot +po/Makefile.in.in +po/Makevars +po/Makevars.template +po/POTFILES +po/Rules-quot +po/stamp-po +printf_test +priority_queue_unit_test +pseries_test +stamp-h +stamp-h1 +stamp-h.in +symlist.c +symlist.h +trigtables.c +*.trs +uhci_test +update-grub_lib +unidata.c +xzcompress_test +Makefile.in +GPATH +GRTAGS +GSYMS +GTAGS +compile +depcomp +mdate-sh +texinfo.tex +grub-core/lib/libgcrypt-grub +.deps +.deps-util +.deps-core +.dirstamp +Makefile.util.am +contrib +grub-core/bootinfo.txt +grub-core/Makefile.core.am +grub-core/Makefile.gcry.def +grub-core/contrib +grub-core/gdb_grub +grub-core/genmod.sh +grub-core/gensyminfo.sh +grub-core/gmodule.pl +grub-core/grub.chrp +grub-core/modinfo.sh +grub-core/*.module +grub-core/*.module.exe +grub-core/*.pp +grub-core/kernel.img.bin +util/bash-completion.d/grub +grub-core/lib/gnulib +grub-core/rs_decoder.h +widthspec.bin +widthspec.h +docs/stamp-1 +docs/version-dev.texi +Makefile.utilgcry.def +po/*.po +po/*.gmo +po/LINGUAS +po/remove-potcdate.sed +include/grub/gcrypt/gcrypt.h +include/grub/gcrypt/g10lib.h +po/POTFILES.in +po/POTFILES-shell.in +/grub-glue-efi +/grub-render-label +/grub-glue-efi.exe +/grub-render-label.exe +/garbage-gen +/garbage-gen.exe +/grub-fs-tester +grub-core/build-grub-module-verifier diff --git a/grub.macros b/grub.macros new file mode 100644 index 0000000..c451aad --- /dev/null +++ b/grub.macros @@ -0,0 +1,626 @@ +# vim:filetype=spec +# Modules always contain just 32-bit code +%global _libdir %{_exec_prefix}/lib +%global _binaries_in_noarch_packages_terminate_build 0 +#%%undefine _missing_build_ids_terminate_build +%{expand:%%{!?buildsubdir:%%global buildsubdir grub-%{tarversion}}} +%{expand:%%{!?_licensedir:%%global license %%%%doc}} + +%global _configure ../configure + +%if %{?_with_ccache: 1}%{?!_with_ccache: 0} +%global cc_equals CC=/usr/%{_lib}/ccache/gcc +%else +%global cc_equals %{nil} +%endif + +%global cflags_sed \\\ + sed \\\ + -e 's/-O. //g' \\\ + -e 's/-fplugin=annobin //g' \\\ + -e 's,-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 ,,g' \\\ + -e 's/-fstack-protector[[:alpha:]-]\\+//g' \\\ + -e 's/-Wp,-D_FORTIFY_SOURCE=[[:digit:]]\\+//g' \\\ + -e 's/--param=ssp-buffer-size=4//g' \\\ + -e 's/-mregparm=3/-mregparm=4/g' \\\ + -e 's/-fexceptions//g' \\\ + -e 's/-fasynchronous-unwind-tables//g' \\\ + -e 's/^/ -fno-strict-aliasing /' \\\ + %{nil} + +%global host_cflags %{expand:%%(echo %{build_cflags} %{?_hardening_cflags} | %{cflags_sed})} +%global legacy_host_cflags \\\ + %{expand:%%(echo %{host_cflags} | \\\ + %{cflags_sed} \\\ + -e 's/-m64//g' \\\ + -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ + )} +%global efi_host_cflags %{expand:%%(echo %{host_cflags})} + +%global target_cflags %{expand:%%(echo %{build_cflags} | %{cflags_sed})} +%global legacy_target_cflags \\\ + %{expand:%%(echo %{target_cflags} | \\\ + %{cflags_sed} \\\ + -e 's/-m64//g' \\\ + -e 's/-mcpu=power[[:alnum:]]\\+/-mcpu=power6/g' \\\ + )} +%global efi_target_cflags %{expand:%%(echo %{target_cflags})} + +%global ldflags_sed \\\ + sed \\\ + -e 's/^$//' \\\ + %{nil} + +%global host_ldflags %{expand:%%(echo %{build_ldflags} %{?_hardening_ldflags} | %{ldflags_sed})} +%global legacy_host_ldflags \\\ + %{expand:%%(echo %{host_ldflags} | \\\ + %{ldflags_sed} \\\ + )} +%global efi_host_ldflags %{expand:%%(echo %{host_ldflags})} + +%global target_ldflags %{expand:%%(echo %{build_ldflags} -static | %{ldflags_sed})} +%global legacy_target_ldflags \\\ + %{expand:%%(echo %{target_ldflags} | \\\ + %{ldflags_sed} \\\ + )} +%global efi_target_ldflags %{expand:%%(echo %{target_ldflags})} + +%global with_efi_arch 0 +%global with_alt_efi_arch 0 +%global with_legacy_arch 0 +%global with_emu_arch 1 +%global emuarch %{_arch} +%global grubefiarch %{nil} +%global grublegacyarch %{nil} + +# sparc is always compiled 64 bit +%ifarch %{sparc} +%global target_cpu_name sparc64 +%global _target_platform %{target_cpu_name}-%{_vendor}-%{_target_os}%{?_gnu} +%global legacy_target_cpu_name %{_arch} +%global legacy_package_arch ieee1275 +%global platform ieee1275 +%endif +# ppc is always compiled 64 bit +%ifarch ppc ppc64 ppc64le +# GRUB emu fails to build on ppc64le +%global with_emu_arch 0 +%global target_cpu_name %{_arch} +%global legacy_target_cpu_name powerpc +%global legacy_package_arch %{_arch} +%global legacy_grub_dir powerpc-ieee1275 +%global _target_platform %{target_cpu_name}-%{_vendor}-%{_target_os}%{?_gnu} +%global platform ieee1275 +%endif + + +%global efi_only aarch64 %{arm} riscv64 +%global efi_arch x86_64 ia64 %{efi_only} +%ifarch %{efi_arch} +%global with_efi_arch 1 +%else +%global with_efi_arch 0 +%endif +%ifarch %{efi_only} +%global with_efi_only 1 +%else +%global with_efi_only 0 +%endif +%{!?with_efi_arch:%global without_efi_arch 0} +%{?with_efi_arch:%global without_efi_arch 1} +%{!?with_efi_only:%global without_efi_only 0} +%{?with_efi_only:%global without_efi_only 1} + +### fixme +%ifarch aarch64 %{arm} riscv64 +%global efi_modules " " +%else +%global efi_modules " backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug " +%endif + +%ifarch aarch64 %{arm} riscv64 +%global legacy_provides -l +%endif + +%ifarch %{ix86} +%global efiarch ia32 +%global target_cpu_name i386 +%global grub_target_name i386-efi +%global package_arch efi-ia32 + +%global legacy_target_cpu_name i386 +%global legacy_package_arch pc +%global platform pc +%endif + +%ifarch x86_64 +%global efiarch x64 +%global target_cpu_name %{_arch} +%global grub_target_name %{_arch}-efi +%global package_arch efi-x64 + +%global legacy_target_cpu_name i386 +%global legacy_package_arch pc +%global platform pc + +%global alt_efi_arch ia32 +%global alt_target_cpu_name i386 +%global alt_grub_target_name i386-efi +%global alt_platform efi +%global alt_package_arch efi-ia32 + +%global alt_efi_host_cflags %{expand:%%(echo %{efi_host_cflags})} +%global alt_efi_target_cflags \\\ + %{expand:%%(echo %{target_cflags} | \\\ + %{cflags_sed} \\\ + -e 's/-m64//g' \\\ + )} +%endif + +%ifarch aarch64 +%global emuarch arm64 +%global efiarch aa64 +%global target_cpu_name aarch64 +%global grub_target_name arm64-efi +%global package_arch efi-aa64 +%endif + +%ifarch riscv64 +%global emuarch riscv64 +%global efiarch riscv64 +%global target_cpu_name riscv64 +%global grub_target_name riscv64-efi +%global package_arch efi-riscv64 +%endif + +%ifarch %{arm} +%global efiarch arm +%global target_cpu_name arm +%global grub_target_name arm-efi +%global package_arch efi-arm +%global efi_target_cflags \\\ + %{expand:%%(echo %{optflags} | \\\ + %{cflags_sed} \\\ + -e 's/-march=armv7-a[[:alnum:]+-]*/&+nofp/g' \\\ + -e 's/-mfpu=[[:alnum:]-]\\+//g' \\\ + -e 's/-mfloat-abi=[[:alpha:]]\\+/-mfloat-abi=soft/g' \\\ + )} +%endif + +%global _target_platform %{target_cpu_name}-%{_vendor}-%{_target_os}%{?_gnu} +%global _alt_target_platform %{alt_target_cpu_name}-%{_vendor}-%{_target_os}%{?_gnu} + +%ifarch %{efi_arch} +%global with_efi_arch 1 +%global grubefiname grub%{efiarch}.efi +%global grubeficdname gcd%{efiarch}.efi +%global grubefiarch %{target_cpu_name}-efi +%ifarch %{ix86} +%global with_efi_modules 0 +%global without_efi_modules 1 +%else +%global with_efi_modules 1 +%global without_efi_modules 0 +%endif +%endif + +%if 0%{?alt_efi_arch:1} +%global with_alt_efi_arch 1 +%global grubaltefiname grub%{alt_efi_arch}.efi +%global grubalteficdname gcd%{alt_efi_arch}.efi +%global grubaltefiarch %{alt_target_cpu_name}-efi +%endif + +%ifnarch %{efi_only} +%global with_legacy_arch 1 +%global grublegacyarch %{legacy_target_cpu_name}-%{platform} +%global moduledir %{legacy_target_cpu_name}-%{platform} +%endif + +%global evr %{epoch}:%{version}-%{release} + +%ifarch x86_64 +%global with_efi_common 1 +%global with_legacy_modules 0 +%global with_legacy_common 0 +%else +%global with_efi_common 0 +%global with_legacy_common 1 +%global with_legacy_modules 1 +%endif + +%define define_legacy_variant() \ +%{expand:%%package %%{1}} \ +Summary: Bootloader with support for Linux, Multiboot, and more \ +Provides: %{name} = %{evr} \ +Obsoletes: %{name} < %{evr} \ +Requires: %{name}-common = %{evr} \ +Requires: %{name}-tools-minimal = %{evr} \ +Requires: %{name}-%{1}-modules = %{evr} \ +Requires: gettext which file \ +Requires: %{name}-tools = %{evr} \ +Requires(pre): dracut \ +Requires(post): dracut \ +%{expand:%%description %%{1}} \ +%{desc} \ +This subpackage provides support for %{1} systems. \ + \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%%{1}-%{tarversion}}}\ +%{expand:%%if 0%%{with_legacy_modules} \ +%%package %%{1}-modules \ +Summary: Modules used to build custom grub images \ +BuildArch: noarch \ +Requires: %%{name}-common = %%{evr} \ +%%description %%{1}-modules \ +%%{desc} \ +This subpackage provides support for rebuilding your own grub.efi. \ +%%endif \ +} \ + \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%%{1}-%{tarversion}}}\ +%{expand:%%package %%{1}-tools} \ +Summary: Support tools for GRUB. \ +Requires: gettext os-prober which file system-logos \ +Requires: %{name}-common = %{evr} \ +Requires: %{name}-tools-minimal = %{evr} \ +Requires: os-prober >= 1.58-11 \ +Requires: gettext which file \ + \ +%{expand:%%description %%{1}-tools} \ +%{desc} \ +This subpackage provides tools for support of %%{1} platforms. \ +%{nil} + +%define define_efi_variant(o) \ +%{expand:%%package %{1}} \ +Summary: GRUB for EFI systems. \ +Requires: efi-filesystem \ +Requires: %{name}-common = %{evr} \ +Requires: %{name}-tools-minimal >= %{evr} \ +Requires: %{name}-tools = %{evr} \ +Provides: %{name}-efi = %{evr} \ +%{?legacy_provides:Provides: %{name} = %{evr}} \ +%{-o:Obsoletes: %{name}-efi < %{evr}} \ + \ +%{expand:%%description %{1}} \ +%{desc} \ +This subpackage provides support for %{1} systems. \ + \ +%{expand:%%{?!buildsubdir:%%define buildsubdir grub-%{1}-%{tarversion}}}\ +%{expand:%if 0%{?with_efi_modules} \ +%{expand:%%package %{1}-modules} \ +Summary: Modules used to build custom grub.efi images \ +BuildArch: noarch \ +Requires: %{name}-common = %{evr} \ +Provides: %{name}-efi-modules = %{evr} \ +Obsoletes: %{name}-efi-modules < %{evr} \ +%{expand:%%description %{1}-modules} \ +%{desc} \ +This subpackage provides support for rebuilding your own grub.efi. \ +%endif} \ + \ +%{expand:%%package %{1}-cdboot} \ +Summary: Files used to boot removeable media with EFI \ +Requires: %{name}-common = %{evr} \ +Provides: %{name}-efi-cdboot = %{evr} \ +%{expand:%%description %{1}-cdboot} \ +%{desc} \ +This subpackage provides optional components of grub used with removeable media on %{1} systems.\ +%{nil} + +%global do_common_setup() \ +%setup -q -n grub-%{tarversion} \ +rm -fv docs/*.info \ +cp %{SOURCE6} .gitignore \ +cp %{SOURCE7} bootstrap \ +cp %{SOURCE8} bootstrap.conf \ +cp %{SOURCE9} ./grub-core/tests/strtoull_test.c \ +cp %{SOURCE2} gnulib-%{gnulibversion}.tar.gz \ +tar -zxf gnulib-%{gnulibversion}.tar.gz \ +mv gnulib-%{gnulibversion} gnulib \ +git init \ +echo '![[:digit:]][[:digit:]]_*.in' > util/grub.d/.gitignore \ +echo '!*.[[:digit:]]' > util/.gitignore \ +echo '!config.h' > include/grub/emu/.gitignore \ +git config user.email "%{name}-owner@fedoraproject.org" \ +git config user.name "Fedora Ninjas" \ +git config gc.auto 0 \ +rm -f configure \ +git add . \ +git commit -a -q -m "%{tarversion} baseline." \ +#git apply --index --whitespace=nowarn %{SOURCE3} \ +#git commit -a -q -m "%{tarversion} master." \ +git am --whitespace=nowarn %%{patches} = 0.99-8 +%endif +%if %{?_with_ccache: 1}%{?!_with_ccache: 0} +BuildRequires: ccache +%endif + +ExcludeArch: s390 s390x +Obsoletes: %{name} <= %{evr} + +%if 0%{with_legacy_arch} +Requires: %{name}-%{legacy_package_arch} = %{evr} +%else +Requires: %{name}-%{package_arch} = %{evr} +%endif + +%global desc \ +The GRand Unified Bootloader (GRUB) is a highly configurable and \ +customizable bootloader with modular architecture. It supports a rich \ +variety of kernel formats, file systems, computer architectures and \ +hardware devices.\ +%{nil} + +# generate with do-rebase +%include %{SOURCE11} + +%description +%{desc} + +%package common +Summary: grub2 common layout +BuildArch: noarch +Conflicts: grubby < 8.40-18 + +%description common +This package provides some directories which are required by various grub2 +subpackages. + +%package tools +Summary: Support tools for GRUB. +Obsoletes: %{name}-tools < %{evr} +Requires: %{name}-common = %{epoch}:%{version}-%{release} +Requires: gettext os-prober which file +Requires(pre): dracut +Requires(post): dracut + +%description tools +%{desc} +This subpackage provides tools for support of all platforms. + +%ifarch x86_64 +%package tools-efi +Summary: Support tools for GRUB. +Requires: gettext os-prober which file +Requires: %{name}-common = %{epoch}:%{version}-%{release} +Obsoletes: %{name}-tools < %{evr} + +%description tools-efi +%{desc} +This subpackage provides tools for support of EFI platforms. +%endif + +%package tools-minimal +Summary: Support tools for GRUB. +Requires: gettext +Requires: %{name}-common = %{epoch}:%{version}-%{release} +Obsoletes: %{name}-tools < %{evr} + +%description tools-minimal +%{desc} +This subpackage provides tools for support of all platforms. + +%package tools-extra +Summary: Support tools for GRUB. +Requires: gettext os-prober which file +Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} +Requires: %{name}-common = %{epoch}:%{version}-%{release} +Obsoletes: %{name}-tools < %{evr} + +%description tools-extra +%{desc} +This subpackage provides tools for support of all platforms. + +%if 0%{with_efi_arch} +%{expand:%define_efi_variant %%{package_arch} -o} +%endif +%if 0%{with_alt_efi_arch} +%{expand:%define_efi_variant %%{alt_package_arch}} +%endif +%if 0%{with_legacy_arch} +%{expand:%define_legacy_variant %%{legacy_package_arch}} +%endif + +%if 0%{with_emu_arch} +%package emu +Summary: GRUB user-space emulation. +Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} + +%description emu +%{desc} +This subpackage provides the GRUB user-space emulation support of all platforms. + +%package emu-modules +Summary: GRUB user-space emulation modules. +Requires: %{name}-tools-minimal = %{epoch}:%{version}-%{release} + +%description emu-modules +%{desc} +This subpackage provides the GRUB user-space emulation modules. +%endif + +%prep +%do_common_setup +%if 0%{with_efi_arch} +mkdir grub-%{grubefiarch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubefiarch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubefiarch}-%{tarversion}/unifont.pcf.gz +git add grub-%{grubefiarch}-%{tarversion} +%endif +%if 0%{with_alt_efi_arch} +mkdir grub-%{grubaltefiarch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grubaltefiarch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grubaltefiarch}-%{tarversion}/unifont.pcf.gz +git add grub-%{grubaltefiarch}-%{tarversion} +%endif +%if 0%{with_legacy_arch} +mkdir grub-%{grublegacyarch}-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-%{grublegacyarch}-%{tarversion}/.gitignore +cp %{SOURCE4} grub-%{grublegacyarch}-%{tarversion}/unifont.pcf.gz +git add grub-%{grublegacyarch}-%{tarversion} +%endif +%if 0%{with_emu_arch} +mkdir grub-emu-%{tarversion} +grep -A100000 '# stuff "make" creates' .gitignore > grub-emu-%{tarversion}/.gitignore +cp %{SOURCE4} grub-emu-%{tarversion}/unifont.pcf.gz +git add grub-emu-%{tarversion} +%endif +git commit -m "After making subdirs" + +%build +%if 0%{with_efi_arch} +%{expand:%do_primary_efi_build %%{grubefiarch} %%{grubefiname} %%{grubeficdname} %%{_target_platform} %%{efi_target_cflags} %%{efi_host_cflags}} +%endif +%if 0%{with_alt_efi_arch} +%{expand:%do_alt_efi_build %%{grubaltefiarch} %%{grubaltefiname} %%{grubalteficdname} %%{_alt_target_platform} %%{alt_efi_target_cflags} %%{alt_efi_host_cflags}} +%endif +%if 0%{with_legacy_arch} +%{expand:%do_legacy_build %%{grublegacyarch}} +%endif +%if 0%{with_emu_arch} +%{expand:%do_emu_build} +%endif +makeinfo --info --no-split -I docs -o docs/grub-dev.info \ + docs/grub-dev.texi +makeinfo --info --no-split -I docs -o docs/grub.info \ + docs/grub.texi +makeinfo --html --no-split -I docs -o docs/grub-dev.html \ + docs/grub-dev.texi +makeinfo --html --no-split -I docs -o docs/grub.html \ + docs/grub.texi + +%install +set -e +rm -fr $RPM_BUILD_ROOT + +%do_common_install +%if 0%{with_efi_arch} +%{expand:%do_efi_install %%{grubefiarch} %%{grubefiname} %%{grubeficdname}} +%endif +%if 0%{with_alt_efi_arch} +%{expand:%do_alt_efi_install %%{grubaltefiarch} %%{grubaltefiname} %%{grubalteficdname}} +%endif +%if 0%{with_legacy_arch} +%{expand:%do_legacy_install %%{grublegacyarch} %%{alt_grub_target_name} 0%{with_efi_arch}} +%endif +%if 0%{with_emu_arch} +%{expand:%do_emu_install %%{package_arch}} +%endif +rm -f $RPM_BUILD_ROOT%{_infodir}/dir +ln -s %{name}-set-password ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-setpassword +echo '.so man8/%{name}-set-password.8' > ${RPM_BUILD_ROOT}/%{_datadir}/man/man8/%{name}-setpassword.8 +%ifnarch x86_64 +rm -vf ${RPM_BUILD_ROOT}/%{_bindir}/%{name}-render-label +rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-bios-setup +rm -vf ${RPM_BUILD_ROOT}/%{_sbindir}/%{name}-macbless +%endif + +%find_lang grub + +# Make selinux happy with exec stack binaries. +mkdir ${RPM_BUILD_ROOT}%{_sysconfdir}/prelink.conf.d/ +cat << EOF > ${RPM_BUILD_ROOT}%{_sysconfdir}/prelink.conf.d/grub2.conf +# these have execstack, and break under selinux +-b /usr/bin/grub2-script-check +-b /usr/bin/grub2-mkrelpath +-b /usr/bin/grub2-mount +-b /usr/bin/grub2-fstest +-b /usr/sbin/grub2-bios-setup +-b /usr/sbin/grub2-probe +-b /usr/sbin/grub2-sparc64-setup +EOF + +# Install kernel-install scripts +install -d -m 0755 %{buildroot}%{_prefix}/lib/kernel/install.d/ +install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE10} +install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE3} +install -d -m 0755 %{buildroot}%{_sysconfdir}/kernel/install.d/ +# Install systemd user service to set the boot_success flag +install -D -m 0755 -t %{buildroot}%{_userunitdir} \ + docs/grub-boot-success.{timer,service} +install -d -m 0755 %{buildroot}%{_userunitdir}/timers.target.wants +ln -s ../grub-boot-success.timer \ + %{buildroot}%{_userunitdir}/timers.target.wants +# Install systemd system-update unit to set boot_indeterminate for offline-upd +install -D -m 0755 -t %{buildroot}%{_unitdir} docs/grub-boot-indeterminate.service +install -d -m 0755 %{buildroot}%{_unitdir}/system-update.target.wants +install -d -m 0755 %{buildroot}%{_unitdir}/reboot.target.wants +ln -s ../grub-boot-indeterminate.service \ + %{buildroot}%{_unitdir}/system-update.target.wants +ln -s ../grub2-systemd-integration.service \ + %{buildroot}%{_unitdir}/reboot.target.wants + +# Don't run debuginfo on all the grub modules and whatnot; it just +# rejects them, complains, and slows down extraction. +%global finddebugroot "%{_builddir}/%{?buildsubdir}/debug" + +%global dip RPM_BUILD_ROOT=%{finddebugroot} %{__debug_install_post} +%define __debug_install_post ( \ + mkdir -p %{finddebugroot}/usr \ + mv ${RPM_BUILD_ROOT}/usr/bin %{finddebugroot}/usr/bin \ + mv ${RPM_BUILD_ROOT}/usr/sbin %{finddebugroot}/usr/sbin \ + %{dip} \ + install -m 0755 -d %{buildroot}/usr/lib/ %{buildroot}/usr/src/ \ + cp -al %{finddebugroot}/usr/lib/debug/ \\\ + %{buildroot}/usr/lib/debug/ \ + cp -al %{finddebugroot}/usr/src/debug/ \\\ + %{buildroot}/usr/src/debug/ ) \ + mv %{finddebugroot}/usr/bin %{buildroot}/usr/bin \ + mv %{finddebugroot}/usr/sbin %{buildroot}/usr/sbin \ + %{nil} + +%undefine buildsubdir + +%pre tools +if [ -f /boot/grub2/user.cfg ]; then + if grep -q '^GRUB_PASSWORD=' /boot/grub2/user.cfg ; then + sed -i 's/^GRUB_PASSWORD=/GRUB2_PASSWORD=/' /boot/grub2/user.cfg + fi +elif [ -f %{efi_esp_dir}/user.cfg ]; then + if grep -q '^GRUB_PASSWORD=' %{efi_esp_dir}/user.cfg ; then + sed -i 's/^GRUB_PASSWORD=/GRUB2_PASSWORD=/' \ + %{efi_esp_dir}/user.cfg + fi +elif [ -f /etc/grub.d/01_users ] && \ + grep -q '^password_pbkdf2 root' /etc/grub.d/01_users ; then + if [ -f %{efi_esp_dir}/grub.cfg ]; then + # on EFI we don't get permissions on the file, but + # the directory is protected. + grep '^password_pbkdf2 root' /etc/grub.d/01_users | \ + sed 's/^password_pbkdf2 root \(.*\)$/GRUB2_PASSWORD=\1/' \ + > %{efi_esp_dir}/user.cfg + fi + if [ -f /boot/grub2/grub.cfg ]; then + install -m 0600 /dev/null /boot/grub2/user.cfg + chmod 0600 /boot/grub2/user.cfg + grep '^password_pbkdf2 root' /etc/grub.d/01_users | \ + sed 's/^password_pbkdf2 root \(.*\)$/GRUB2_PASSWORD=\1/' \ + > /boot/grub2/user.cfg + fi +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 +# later restore them in triggerpostun. +# https://bugzilla.redhat.com/show_bug.cgi?id=735259 + +# Back up the files before uninstalling old grub2 +mkdir -p /boot/grub2.tmp && +mv -f /boot/grub2/*.mod \ + /boot/grub2/*.img \ + /boot/grub2/*.lst \ + /boot/grub2/device.map \ + /boot/grub2.tmp/ || : + +%triggerpostun -- grub2 < 1:1.99-4 +# ... and restore the files. +test ! -f /boot/grub2/device.map && +test -d /boot/grub2.tmp && +mv -f /boot/grub2.tmp/*.mod \ + /boot/grub2.tmp/*.img \ + /boot/grub2.tmp/*.lst \ + /boot/grub2.tmp/device.map \ + /boot/grub2/ && +rm -r /boot/grub2.tmp/ || : + +%files common -f grub.lang +%dir %{_libdir}/grub/ +%dir %{_datarootdir}/grub/ +%attr(0700,root,root) %dir %{_sysconfdir}/grub.d +%{_prefix}/lib/kernel/install.d/20-grub.install +%{_prefix}/lib/kernel/install.d/99-grub-mkconfig.install +%dir %{_datarootdir}/grub +%exclude %{_datarootdir}/grub/* +%dir /boot/%{name} +%dir /boot/%{name}/themes/ +%dir /boot/%{name}/themes/system +%attr(0700,root,root) %dir /boot/grub2 +%exclude /boot/grub2/* +%dir %attr(0700,root,root) %{efi_esp_dir} +%exclude %{efi_esp_dir}/* +%ghost %config(noreplace) /boot/grub2/grubenv +%license COPYING +%doc THANKS +%doc docs/grub.html +%doc docs/grub-dev.html +%doc docs/font_char_metrics.png + +%files tools-minimal +%{_sysconfdir}/prelink.conf.d/grub2.conf +%{_sbindir}/%{name}-get-kernel-settings +%{_sbindir}/%{name}-probe +%attr(4755, root, root) %{_sbindir}/%{name}-set-bootflag +%{_sbindir}/%{name}-set-default +%{_sbindir}/%{name}-set*password +%{_bindir}/%{name}-editenv +%{_bindir}/%{name}-mkpasswd-pbkdf2 +%{_bindir}/%{name}-mount + +%{_datadir}/man/man3/%{name}-get-kernel-settings* +%{_datadir}/man/man8/%{name}-set-default* +%{_datadir}/man/man8/%{name}-set*password* +%{_datadir}/man/man1/%{name}-editenv* +%{_datadir}/man/man1/%{name}-mkpasswd-* + +%ifarch x86_64 +%files tools-efi +%{_bindir}/%{name}-glue-efi +%{_bindir}/%{name}-render-label +%{_sbindir}/%{name}-macbless +%{_datadir}/man/man1/%{name}-glue-efi* +%{_datadir}/man/man1/%{name}-render-label* +%{_datadir}/man/man8/%{name}-macbless* +%endif + +%files tools +%attr(0644,root,root) %ghost %config(noreplace) %{_sysconfdir}/default/grub +%config %{_sysconfdir}/grub.d/??_* +%{_sysconfdir}/grub.d/README +%{_userunitdir}/grub-boot-success.timer +%{_userunitdir}/grub-boot-success.service +%{_userunitdir}/timers.target.wants +%{_unitdir}/grub-boot-indeterminate.service +%{_unitdir}/system-update.target.wants +%{_unitdir}/%{name}-systemd-integration.service +%{_unitdir}/reboot.target.wants +%{_unitdir}/systemd-logind.service.d +%{_infodir}/%{name}* +%{_datarootdir}/grub/* +%{_sbindir}/%{name}-install +%exclude %{_datarootdir}/grub/themes +%exclude %{_datarootdir}/grub/*.h +%{_datarootdir}/bash-completion/completions/grub +%{_sbindir}/%{name}-mkconfig +%{_sbindir}/%{name}-switch-to-blscfg +%{_sbindir}/%{name}-rpm-sort +%{_sbindir}/%{name}-reboot +%{_bindir}/%{name}-file +%{_bindir}/%{name}-menulst2cfg +%{_bindir}/%{name}-mkimage +%{_bindir}/%{name}-mkrelpath +%{_bindir}/%{name}-script-check +%{_libexecdir}/%{name} +%{_datadir}/man/man?/* + +# exclude man pages from tools-extra +%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* +%exclude %{_datadir}/man/man1/%{name}-fstest* +%exclude %{_datadir}/man/man1/%{name}-glue-efi* +%exclude %{_datadir}/man/man1/%{name}-kbdcomp* +%exclude %{_datadir}/man/man1/%{name}-mkfont* +%exclude %{_datadir}/man/man1/%{name}-mklayout* +%exclude %{_datadir}/man/man1/%{name}-mknetdir* +%exclude %{_datadir}/man/man1/%{name}-mkrescue* +%exclude %{_datadir}/man/man1/%{name}-mkstandalone* +%exclude %{_datadir}/man/man1/%{name}-syslinux2cfg* + +# exclude man pages from tools-minimal +%exclude %{_datadir}/man/man3/%{name}-get-kernel-settings* +%exclude %{_datadir}/man/man8/%{name}-set-default* +%exclude %{_datadir}/man/man8/%{name}-set*password* +%exclude %{_datadir}/man/man1/%{name}-editenv* +%exclude %{_datadir}/man/man1/%{name}-mkpasswd-* +%exclude %{_datadir}/man/man8/%{name}-macbless* +%exclude %{_datadir}/man/man1/%{name}-render-label* + +%if %{with_legacy_arch} +%{_sbindir}/%{name}-install +%ifarch x86_64 +%{_sbindir}/%{name}-bios-setup +%else +%exclude %{_sbindir}/%{name}-bios-setup +%exclude %{_datadir}/man/man8/%{name}-bios-setup* +%endif +%ifarch %{sparc} +%{_sbindir}/%{name}-sparc64-setup +%else +%exclude %{_sbindir}/%{name}-sparc64-setup +%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* +%endif +%ifarch %{sparc} ppc ppc64 ppc64le +%{_sbindir}/%{name}-ofpathname +%else +%exclude %{_sbindir}/%{name}-ofpathname +%exclude %{_datadir}/man/man8/%{name}-ofpathname* +%endif +%endif + +%files tools-extra +%{_bindir}/%{name}-fstest +%{_bindir}/%{name}-kbdcomp +%{_bindir}/%{name}-mkfont +%{_bindir}/%{name}-mklayout +%{_bindir}/%{name}-mknetdir +%ifnarch %{sparc} +%{_bindir}/%{name}-mkrescue +%{_datadir}/man/man1/%{name}-mkrescue* +%else +%exclude %{_datadir}/man/man1/%{name}-mkrescue* +%endif +%{_bindir}/%{name}-mkstandalone +%{_bindir}/%{name}-syslinux2cfg +%{_sysconfdir}/sysconfig/grub +%{_datadir}/man/man1/%{name}-fstest* +%{_datadir}/man/man1/%{name}-kbdcomp* +%{_datadir}/man/man1/%{name}-mkfont* +%{_datadir}/man/man1/%{name}-mklayout* +%{_datadir}/man/man1/%{name}-mknetdir* +%{_datadir}/man/man1/%{name}-mkstandalone* +%{_datadir}/man/man1/%{name}-syslinux2cfg* +%exclude %{_bindir}/%{name}-glue-efi +%exclude %{_sbindir}/%{name}-sparc64-setup +%exclude %{_sbindir}/%{name}-ofpathname +%exclude %{_datadir}/man/man1/%{name}-glue-efi* +%exclude %{_datadir}/man/man8/%{name}-ofpathname* +%exclude %{_datadir}/man/man8/%{name}-sparc64-setup* +%exclude %{_datarootdir}/grub/themes/starfield + +%if 0%{with_efi_arch} +%{expand:%define_efi_variant_files %%{package_arch} %%{grubefiname} %%{grubeficdname} %%{grubefiarch} %%{target_cpu_name} %%{grub_target_name}} +%endif +%if 0%{with_alt_efi_arch} +%{expand:%define_efi_variant_files %%{alt_package_arch} %%{grubaltefiname} %%{grubalteficdname} %%{grubaltefiarch} %%{alt_target_cpu_name} %%{alt_grub_target_name}} +%endif +%if 0%{with_legacy_arch} +%{expand:%define_legacy_variant_files %%{legacy_package_arch} %%{grublegacyarch}} +%endif + +%if 0%{with_emu_arch} +%files emu +%{_bindir}/%{name}-emu* +%{_datadir}/man/man1/%{name}-emu* + +%files emu-modules +%{_libdir}/grub/%{emuarch}-emu/* +%exclude %{_libdir}/grub/%{emuarch}-emu/*.module +%endif + +%changelog +* Mon Aug 31 2020 Javier Martinez Canillas - 2.04-31 +- Roll over TFTP block counter to prevent timeouts with data packets + Resolves: rhbz#1869335 + +* Fri Aug 21 2020 Javier Martinez Canillas - 2.04-30 +- Set TFTP blocksize to 1428 instead of 2048 to avoid IP fragmentation + Resolves: rhbz#1869335 + +* Fri Aug 21 2020 Javier Martinez Canillas - 2.04-29 +- Fix TFTP timeouts when trying to fetch files larger than 65535 KiB + Resolves: rhbz#1869335 + +* Wed Aug 12 2020 Javier Martinez Canillas - 2.04-28 +- Add support for "systemctl reboot --boot-loader-menu=xx" (hdegoede) + Related: rhbz#1857389 + +* Mon Aug 10 2020 Peter Jones - 2.04-27 +- Attempt to enable dual-signing in f33 +- "Minor" bug fixes. For f33: + Resolves: CVE-2020-10713 + Resolves: CVE-2020-14308 + Resolves: CVE-2020-14309 + Resolves: CVE-2020-14310 + Resolves: CVE-2020-14311 + Resolves: CVE-2020-15705 + Resolves: CVE-2020-15706 + Resolves: CVE-2020-15707 + +* Tue Jun 30 2020 Jeff Law - 2.04-26 +- Disable LTO + +* Thu Jun 18 2020 Javier Martinez Canillas - 2.04-25 +- Only mark GRUB as BLS supported in OSTree systems with a boot partition + +* Mon Jun 08 2020 Javier Martinez Canillas - 2.04-24 +- http: Prepend prefix when the HTTP path is relative as done in efi/http +- Fix build with rpm-4.16 (thierry.vignaud) + +* Fri Jun 05 2020 Javier Martinez Canillas - 2.04-23 +- Install GRUB as \EFI\BOOT\BOOTARM.EFI in armv7hl + +* Tue May 26 2020 Javier Martinez Canillas - 2.04-22 +- Fix an out of memory error when loading large initrd images + Resolves: rhbz#1838633 + +* Wed May 20 2020 Javier Martinez Canillas - 2.04-21 +- Don't update BLS files that aren't managed by GRUB scripts + Resolves: rhbz#1837783 + +* Mon May 18 2020 Javier Martinez Canillas - 2.04-20 +- Only enable the tpm module for EFI platforms + +* Sat May 16 2020 Javier Martinez Canillas - 2.04-19 +- Enable tpm module and make system to boot even if TPM measurements fail + Resolves: rhbz#1836433 + +* Thu May 14 2020 Adam Williamson - 2.04-18 +- 10_linux.in: restore existence check in `get_sorted_bls` + Resolves: rhbz#1836020 + +* Wed May 13 2020 Javier Martinez Canillas - 2.04-17 +- Store cmdline in BLS snippets instead of using a grubenv variable + +* Tue May 12 2020 Javier Martinez Canillas - 2.04-16 +- Fix a segfault in grub2-editenv when attempting to shrink a variable + +* Thu Apr 30 2020 Javier Martinez Canillas - 2.04-15 +- blscfg: Lookup default_kernelopts variable as fallback for options + Related: rhbz#1765297 +- 10_linux.in: fix early exit due error when reading petitboot version + Resolves: rhbz#1827397 + +* Thu Apr 23 2020 Javier Martinez Canillas - 2.04-14 +- efi: Set image base address before jumping to the PE/COFF entry point + Resolves: rhbz#1825411 + +* Thu Apr 16 2020 Javier Martinez Canillas - 2.04-13 +- Make the grub-switch-to-blscfg and 10_linux scripts more robust + +* Thu Apr 02 2020 Javier Martinez Canillas - 2.04-12 +- Merge 10_linux_bls logic into 10_linux and avoid issues if blsdir is set + +* Thu Mar 26 2020 Javier Martinez Canillas - 2.04-11 +- grub-switch-to-blscfg: Update grub2 binary in ESP for OSTree systems + Related: rhbz#1751272 + +* Tue Mar 17 2020 Javier Martinez Canillas - 2.04-10 +- Fix for entries having an empty initrd command and HTTP boot issues + Resolves: rhbz#1806022 + +* Thu Jan 16 2020 Javier Martinez Canillas - 2.04-9 +- Add riscv64 support to grub.macros and RISC-V build fixes (davidlt) +- blscfg: Always use the root variable to search for BLS snippets +- bootstrap.conf: Force autogen.sh to use python3 + +* Mon Jan 13 2020 Javier Martinez Canillas - 2.04-8 +- Make the blscfg module honour the GRUB_SAVEDEFAULT option (fritz) + Resolves: rhbz#1704926 + +* Mon Jan 06 2020 Peter Jones - 2.04-7 +- Add zstd to the EFI module list. + Related: rhbz#1418336 + +* Thu Dec 05 2019 Javier Martinez Canillas - 2.04-6 +- Various grub2 cleanups (pbrobinson) +- Another fix for blscfg variable expansion support +- blscfg: Add support for sorting the plus ('+') higher than base version + Resolves: rhbz#1767395 + +* Wed Nov 27 2019 Javier Martinez Canillas - 2.04-5 +- blscfg: add a space char when appending fields for variable expansion +- grub.d: Fix boot_indeterminate getting set on boot_success=0 boot + +* Tue Nov 26 2019 Javier Martinez Canillas - 2.04-4 +- grub-set-bootflag: Write new env to tmpfile and then rename (hdegoede) + Resolves: CVE-2019-14865 + Resolves: rhbz#1776580 + +* Thu Oct 17 2019 Javier Martinez Canillas - 2.04-3 +- 20-grub-install: Don't add an id field to generated BLS snippets +- 99-grub-mkconfig: Disable BLS usage for Xen machines + Resolves: rhbz#1703700 +- Don't add a class option to menu entries generated for ppc64le + Resolves: rhbz#1758225 +- 10_linux.in: Also use GRUB_CMDLINE_LINUX_DEFAULT to set kernelopts +- blscfg: Don't hardcode an env var as fallback for the BLS options field + Resolves: rhbz#1710483 + +* Wed Sep 18 2019 Javier Martinez Canillas - 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 - 2.04-1 +- Update to 2.04 + Resolves: rhbz#1727279 + +* Wed Aug 07 2019 Javier Martinez Canillas - 2.02-97 +- Include regexp module in EFI builds + +* Thu Aug 01 2019 Javier Martinez Canillas - 2.02-96 +- Manual build for the Fedora 31 mass rebuild to succeed + +* Thu Jul 25 2019 Fedora Release Engineering +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + +* Thu Jul 18 2019 Javier Martinez Canillas - 2.02-94 +- 20-grub-install: Restore default SELinux security contexts for BLS files + Resolves: rhbz#1726020 + +* Wed Jul 17 2019 Javier Martinez Canillas - 2.02-93 +- Add btrfs snapshot submenu when BLS configuration is used +- Move grub2-probe to the grub2-tools-minimal subpackage + Resolves: rhbz#1715994 + +* Tue Jul 16 2019 Javier Martinez Canillas - 2.02-92 +- Cleanup our patchset to reduce the number of patches + +* Sat Jul 13 2019 Javier Martinez Canillas - 2.02-91 +- Includes security modules in Grub2 EFI builds (benjamin.doron) + Resolves: rhbz#1722938 +- Enable again multiboot and multiboot2 modules on EFI builds + Resolves: rhbz#1703872 + +* Fri Jul 05 2019 Javier Martinez Canillas - 2.02-90 +- Fix failure to request grub.cfg over HTTP +- Some ARM fixes (pbrobinson) +- Preserve multi-device workflows (Yclept Nemo) + +* Thu Jun 27 2019 Javier Martinez Canillas - 2.02-89 +- Fix --bls-directory option comment in grub2-switch-to-blscfg man page + Resolves: rhbz#1714835 +- 10_linux_bls: use '=' to separate --id argument due a Petitboot bug +- grub-set-bootflag: Print an error if failing to read from grubenv + Resolves: rhbz#1702354 +- 10_linux: generate BLS section even if no kernels are found in /boot +- 10_linux: don't search for OSTree kernels + +* Tue Jun 18 2019 Sergio Durigan Junior - 2.02-88 +- Use '-g' instead of '-g3' when compiling grub2. + Resolves: rhbz#1708780 + +* Tue Jun 11 2019 Javier Martinez Canillas - 2.02-87 +- Rebuild for RPM 4.15 + +* Mon Jun 10 22:13:19 CET 2019 Igor Gnatenko +- Rebuild for RPM 4.15 + +* Mon Jun 10 15:42:01 CET 2019 Igor Gnatenko +- Rebuild for RPM 4.15 + +* Mon May 20 2019 Javier Martinez Canillas - 2.02-84 +- Don't try to switch to a BLS config if GRUB_ENABLE_BLSCFG is already set + +* Wed May 15 2019 Javier Martinez Canillas - 2.02-83 +- Fix error messages wrongly being printed when executing blscfg command + Resolves: rhbz#1699761 +- Remove bogus load_env after blscfg command in 10_linux + +* Tue May 07 2019 Javier Martinez Canillas - 2.02-82 +- Make blscfg module compatible at least up to the Fedora 19 GRUB core + Related: rhbz#1652806 + +* Fri May 03 2019 Neal Gompa - 2.02-81 +- Add grub2-mount to grub2-tools-minimal subpackage + Resolves: rhbz#1471267 + +* Fri May 03 2019 Javier Martinez Canillas - 2.02-80 +- Add grub2-emu subpackage + +* Fri May 03 2019 Tim Landscheidt - 2.02-79 +- Fix description of grub2-pc + Resolves: rhbz#1484298 + +* Thu Apr 18 2019 Javier Martinez Canillas - 2.02-78 +- Add 10_reset_boot_success to Makefile + Related: rhbz#17010 + +* Thu Apr 18 2019 Javier Martinez Canillas - 2.02-77 +- Never remove boot loader configuration for other boot loaders from the ESP. + This would render machines with sd-boot unbootable (zbyszek) +- Execute grub2-switch-to-blscfg script in %%posttrans instead of %%post +- grub.d: Split out boot success reset from menu auto hide script (lorbus) +- HTTP boot: strncmp returns 0 on equal (stephen) +- Some grub2-emu fixes and make it to not print unnecessary messages +- Don't assume that boot commands will only return on fail + +* Thu Mar 28 2019 Javier Martinez Canillas - 2.02-76 +- 10_linux_bls: don't add --users option to generated menu entries + Resolves: rhbz#1693515 + +* Tue Mar 26 2019 Javier Martinez Canillas - 2.02-75 +- A set of EFI fixes to support arm64 QCom UEFI firmwares (pbrobinson) + +* Fri Mar 22 2019 Javier Martinez Canillas - 2.02-74 +- Fix some BLS snippets not being displayed in the GRUB menu + Resolves: rhbz#1691232 +- Fix possible undefined behaviour due wrong grub_efi_status_t type (pjones) + +* Wed Mar 20 2019 Javier Martinez Canillas - 2.02-73 +- Only set blsdir if /boot/loader/entries is in a btrfs or zfs partition + Related: rhbz#1688453 + +* Mon Mar 11 2019 Javier Martinez Canillas - 2.02-72 +- Avoid grub2-efi package to overwrite existing /boot/grub2/grubenv file + Resolves: rhbz#1687323 +- Switch to BLS in tools package %%post scriptlet + Resolves: rhbz#1652806 + +* Wed Feb 27 2019 Javier Martinez Canillas - 2.02-71 +- 20-grub-install: Replace, rather than overwrite, the existing kernel (pjones) + Resolves: rhbz#1642402 +- 99-grub-mkconfig: Don't update grubenv generating entries on ppc64le + Related: rhbz#1637875 +- blscfg: fallback to default_kernelopts if BLS option field isn't set + Related: rhbz#1625124 +- grub-switch-to-blscfg: copy increment.mod for legacy BIOS and ppc64 + Resolves: rhbz#1652806 + +* Fri Feb 15 2019 Javier Martinez Canillas - 2.02-70 +- Check if blsdir exists before attempting to get it's real path + Resolves: rhbz#1677415 + +* Wed Feb 13 2019 Javier Martinez Canillas - 2.02-69 +- Don't make grub_strtoull() print an error if no conversion is performed + Resolves: rhbz#1674512 +- Set blsdir if the BLS directory path isn't one of the looked up by default + Resolves: rhbz#1657240 + +* Mon Feb 04 2019 Javier Martinez Canillas - 2.02-68 +- Don't build the grub2-efi-ia32-* packages on i686 (pjones) +- Add efi-export-env and efi-load-env commands (pjones) +- Make it possible to subtract conditions from debug= (pjones) +- Try to set -fPIE and friends on libgnu.a (pjones) +- Add more options to blscfg command to make it more flexible +- Add support for prepend early initrds to the BLS entries +- Fix grub.cfg-XXX look up when booting over TFTP + +* Fri Feb 01 2019 Fedora Release Engineering +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + +* Mon Dec 17 2018 Javier Martinez Canillas - 2.02-66 +- Don't exclude /etc/grub.d/01_fallback_counting anymore + +* Tue Dec 11 2018 Javier Martinez Canillas - 2.02-65 +- BLS files should only be copied by grub-switch-to-blscfg if BLS isn't set + Related: rhbz#1638117 +- Fix get_entry_number() wrongly dereferencing the tail pointer + Resolves: rhbz#1654936 +- Make grub2-mkconfig to honour GRUB_CMDLINE_LINUX in /etc/default/grub + Resolves: rhbz#1637875 + +* Fri Nov 30 2018 Javier Martinez Canillas - 2.02-64 +- Add comments and revert logic changes in 01_fallback_counting +- Remove quotes when reading ID value from /etc/os-release + Related: rhbz#1650706 +- blscfg: expand grub_users before passing to grub_normal_add_menu_entry() + Resolves: rhbz#1650706 +- Drop buggy downstream patch "efinet: retransmit if our device is busy" + Resolves: rhbz#1649048 +- Make the menu entry users option argument to be optional + Related: rhbz#1652434 +- 10_linux_bls: add missing menu entries options + Resolves: rhbz#1652434 +- Drop "Be more aggro about actually using the *configured* network device." + Resolves: rhbz#1654388 +- Fix menu entry selection based on title + Resolves: rhbz#1654936 + +* Wed Nov 21 2018 Javier Martinez Canillas - 2.02-63 +- add 10_linux_bls grub.d snippet to generate menu entries from BLS files + Resolves: rhbz#1636013 +- Only set kernelopts in grubenv if it wasn't set before + Resolves: rhbz#1636466 +- kernel-install: Remove existing initramfs if it's older than the kernel (pjones) + Resolves: rhbz#1638405 +- Update the saved entry correctly after a kernel install (pjones) + Resolves: rhbz#1638117 +- blscfg: sort everything with rpm *package* comparison (pjones) + Related: rhbz#1638103 +- blscfg: Make 10_linux_bls sort the same way as well + Related: rhbz#1638103 +- don't set saved_entry on grub2-mkconfig + Resolves: rhbz#1636466 +- Fix menu entry selection based on ID and title (pjones) + Resolves: rhbz#1640979 +- Don't unconditionally set default entry when installing debug kernels + Resolves: rhbz#1636346 +- Remove installkernel-bls script + Related: rhbz#1647721 + +* Thu Oct 04 2018 Peter Jones - 2.02-62 +- Exclude /etc/grub.d/01_fallback_counting until we work through some design + questions. + Resolves: rhbz#1614637 + +* Wed Oct 03 2018 Peter Jones - 2.02-61 +- Fix the fallback counting script even harder. Apparently, this wasn't + tested well enough. + Resolves: rhbz#1614637 + +* Tue Oct 02 2018 Peter Jones - 2.02-60 +- Fix grub.cfg boot counting snippet generation (lorbus) + Resolves: rhbz#1614637 +- Fix spurrious allocation error reporting on EFI boot + Resolves: rhbz#1635319 +- Stop doing TPM on BIOS *again*. It just doesn't work. + Related: rhbz#1579835 +- Make blscfg module loadable on older grub2 i386-pc and powerpc-ieee1275 + builds +- Fix execstack cropping up in grub2-tools +- Ban stack trampolines with compiler flags. + +* Tue Sep 25 2018 Hans de Goede - 2.02-59 +- Stop using pkexec for grub2-set-bootflag, it does not work under gdm + instead make it suid root (it was written with this in mind) + +* Tue Sep 25 2018 Peter Jones +- Use bounce buffers for addresses above 4GB +- Allow initramfs, cmdline, and params >4GB, but not kernel + +* Wed Sep 12 2018 Peter Jones - 2.02-58 +- Add 2 conditions to boot-success timer and service: + - Don't run it for system users + Resolves: rhbz#1592201 + - Don't run it when pkexec isn't available + Resolves: rhbz#1619445 +- Use -Wsign-compare -Wconversion -Wextra in the build. + +* Tue Sep 11 2018 Peter Jones - 2.02-57 +- Limit grub_malloc() on x86_64 to < 31bit addresses, as some devices seem to + have a colossally broken storage controller (or UEFI driver) that can't do + DMA to higher memory addresses, but fails silently. + Resolves: rhbz#1626844 (possibly really resolving it this time.) +- Also integrate Hans's attempt to fix the related error from -54, but do it + the other way around: try the low addresses first and *then* the high one if + the allocation fails. This way we'll get low regions by default, and if + kernel/initramfs don't fit anywhere, it'll try the higher addresses. + Related: rhbz#1624532 +- Coalesce all the intermediate debugging junk from -54/-55/-56. + +* Tue Sep 11 2018 Peter Jones - 2.02-56 +- Don't mangle fw_path even harder. + Resolves: rhbz#1626844 +- Fix reboot being missing on some platforms, and make it alias to + "reset" as well. +- More dprintf(). + +* Mon Sep 10 2018 Peter Jones - 2.02-55 +- Fix UEFI memory problem in a different way. + Related: rhbz#1624532 +- Don't mangle fw_path with a / unless we're on http + Resolves: rhbz#1626844 + +* Fri Sep 07 2018 Kevin Fenzi - 2.02-54 +- Add patch from https://github.com/rhboot/grub2/pull/30 to fix uefi booting + Resolves: rhbz#1624532 + +* Thu Aug 30 2018 Peter Jones - 2.02-53 +- Fix AArch64 machines with no RAM latched lower than 1GB + Resolves: rhbz#1615969 +- Set http_path and http_url when HTTP booting +- Hopefully slightly better error reporting in some cases +- Better allocation of kernel+initramfs on x86_64 and aarch64 + Resolves: rhbz#1572126 + +* Mon Aug 20 2018 Peter Jones - 2.02-52 +- Update conflicts on grubby not to care about %%{?dist} + +* Sun Aug 19 2018 Peter Jones - 2.02-51 +- Make it quieter. + +* Thu Aug 16 2018 Peter Jones - 2.02-50 +- Fix arm32 off-by-one error on reading the PE header. + +* Tue Aug 14 2018 Peter Jones - 2.02-50 +- Fix typo in /etc/grub.d/01_fallback_counting + Resolves: rhbz#1614637 + +* Fri Aug 10 2018 Javier Martinez Canillas - 2.02-50 +- Add an installkernel script for BLS configurations + +* Tue Aug 07 2018 Peter Jones - 2.02-49 +- Temporarily make -cdboot perms 0700 again. + +* Fri Aug 03 2018 Peter Jones - 2.02-48 +- Kill .note.gnu.property with fire. + Resolves: rhbz#1612339 + +* Thu Aug 02 2018 Peter Jones - 2.02-47 +- Enable armv7 EFI builds. This was way harder than I expected. + +* Tue Jul 17 2018 Peter Jones - 2.02-46 +- Fix some minor BLS issues +- Rework the FDT module linking to make aarch64 build and boot right + +* Mon Jul 16 2018 pjones - 2.02-45 +- Rework SB patches and 10_linux.in changes even harder. + Resolves: rhbz#1601578 + +* Mon Jul 16 2018 Hans de Goede - 2.02-44 +- Make the user session automatically set the boot_success grubenv flag +- Make offline-updates increment the boot_indeterminate grubenv variable + +* Mon Jul 16 2018 pjones - 2.02-43 +- Rework SB patches and 10_linux.in changes + +* Fri Jul 13 2018 Peter Jones - 2.02-42 +- Revert broken moduledir fix *again*. + +* Thu Jul 12 2018 Peter Jones - 2.02-41 +- Fix our linuxefi/linux command reunion. + +* Wed Jul 11 2018 Peter Jones - 2.02-40 +- Port several fixes from the F28 tree and a WIP tree. + +* Mon Jul 09 2018 pjones - 2.02-39 +- Fix my fix of grub2-switch-to-blscfg (javierm and pjones) + +* Mon Jul 02 2018 Javier Martinez Canillas - 2.02-38 +- Use BLS fragment filename as menu entry id and for sort criterion + +* Tue Jun 26 2018 Javier Martinez Canillas +- Cleanups and fixes for grub2-switch-to-blscfg (pjones) +- Use /boot/loader/entries as BLS dir also on EFI (javierm) + +* Tue Jun 19 2018 Peter Jones - 2.02-37 +- Fix some TPM errors on 32-bit (hdegoede) +- More fixups to avoid compiler changes (pjones) +- Put lsmmap into the EFI builds (pjones) + Related: rhbz#1572126 +- Make 20-grub.install to exit if there is no machine ID set (javierm) + Resolves: rhbz#1576573 +- More fixes for BLS (javierm) + Resolves: rhbz#1588184 + +* Wed May 16 2018 Peter Jones - 2.02-37.fc29 +- Fixups to work with gcc 8 +- Experimental https boot support on UEFI +- XFS fixes for sparse inode support + Resolves: rhbz#1575797 + +* Thu May 10 2018 Javier Martinez Canillas - 2.02-36 +- Use version field to sort BLS entries if id field isn't defined +- Add version field to BLS fragments generated by 20-grub.install + +* Tue Apr 24 2018 Peter Jones - 2.02-35 +- A couple of fixes needed by Fedora Atomic - javierm + +* Mon Apr 23 2018 Peter Jones - 2.02-34 +- Put the os-prober dep back in - we need to change test plans and criteria + before it can go. + Resolves: rhbz#1569411 + +* Wed Apr 11 2018 Peter Jones - 2.02-33 +- Work around some issues with older automake found in CentOS. +- Make multiple initramfs images work in BLS. + +* Wed Apr 11 2018 Javier Martinez Canillas - 2.02-32 +- Make 20-grub.install to generate debug BLS when MAKEDEBUG is set. + +* Fri Apr 06 2018 Peter Jones - 2.02-31 +- Pull in some TPM fixes I missed. + +* Fri Apr 06 2018 Peter Jones - 2.02-30 +- Enable TPM measurements +- Set the default boot entry to the first entry when we're using BLS. + +* Tue Apr 03 2018 Peter Jones - 2.02-29 +- Fix for BLS paths on BIOS / non-UEFI (javierm) + +* Fri Mar 16 2018 Peter Jones - 2.02-28 +- Install kernel-install scripts. (javierm) +- Add grub2-switch-to-blscfg + +* Tue Mar 06 2018 Peter Jones - 2.02-27 +- Build the blscfg module in on EFI builds. + +* Wed Feb 28 2018 Peter Jones - 2.02-26 +- Try to fix things for new compiler madness. + I really don't know why gcc decided __attribute__((packed)) on a "typedef + struct" should imply __attribute__((align (1))) and that it should have a + warning that it does so. The obvious behavior would be to keep the alignment + of the first element unless it's used in another object or type that /also/ + hask the packed attribute. Why should it change the default alignment at + all? +- Merge in the BLS patches Javier and I wrote. +- Attempt to fix pmtimer initialization failures to not be super duper slow. + +* Fri Feb 09 2018 Igor Gnatenko +- Escape macros in %%changelog + +* Tue Jan 23 2018 Peter Jones - 2.02-24 +- Fix a merge error from 2.02-21 that affected kernel loading on Aarch64. + Related: rhbz#1519311 + Related: rhbz#1506704 + Related: rhbz#1502312 + +* Fri Jan 19 2018 Peter Jones - 2.02-23 +- Only nerf annobin, not -fstack-crash-protection. +- Fix a conflict on /boot/efi directory permissions between -cdboot and the + normal bootloader. + +* Thu Jan 18 2018 Peter Jones - 2.02-22 +- Nerf some gcc 7.2.1-6 'features' that cause grub to crash on start. + +* Thu Jan 18 2018 Peter Jones - 2.02-21 +- Fix grub2-efi-modules provides/obsoletes generation + Resolves: rhbz#1506704 +- *Also* build grub-efi-ia32{,-*,!-modules} packages for i686 builds + Resolves: rhbz#1502312 +- Make everything under /boot/efi be mode 0700, since that's what FAT will + show anyway. + +* Wed Jan 17 2018 Peter Jones - 2.02-20 +- Update to newer upstream for F28 +- Pull in patches for Apollo Lake hardware + Resolves: rhbz#1519311 + +* Tue Oct 24 2017 Peter Jones - 2.02-19 +- Handle xen module loading (somewhat) better + Resolves: rhbz#1486002 + +* Wed Sep 20 2017 Peter Jones - 2.02-18 +- Make grub2-efi-aa64 provide grub2 + Resolves: rhbz#1491045 + +* Mon Sep 11 2017 Dennis Gilmore - 2.02-17 +- bump for Obsoletes again + +* Wed Sep 06 2017 Peter Jones - 2.02-16 +- Fix Obsoletes on grub2-pc + +* Wed Aug 30 2017 Petr Šabata - 2.02-15 +- Limit the pattern matching in do_alt_efi_install to files to + unbreak module builds + +* Fri Aug 25 2017 Peter Jones - 2.02-14 +- Revert the /usr/lib/.build-id/ change: + https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo + says (without any particularly convincing reasoning): + The main build-id file should not be in the debuginfo file, but in the + main package (this was always a problem since the package and debuginfo + package installed might not match). If we want to make usr/lib/debug/ a + network resource then we will need to move the symlink to another + location (maybe /usr/lib/.build-id). + So do it that way. Of course it doesn't matter, because exclude gets + ignored due to implementation details. + +* Fri Aug 25 2017 Peter Jones - 2.02-13 +- Add some unconditional Provides: + grub2-efi on grub2-efi-${arch} + grub2-efi-cdboot on grub2-efi-${arch}-cdboot + grub2 on all grub2-${arch} pacakges +- Something is somehow adding /usr/lib/.build-id/... to all the -tools + subpackages, so exclude all that. + +* Thu Aug 24 2017 Peter Jones - 2.02-12 +- Fix arm kernel command line allocation + Resolves: rhbz#1484609 +- Get rid of the temporary extra efi packages hack. + +* Wed Aug 23 2017 Peter Jones - 2.02-11 +- Put grub2-mkimage in -tools, not -tools-extra. +- Fix i686 building +- Fix ppc HFS+ usage due to /boot/efi's presence. + +* Fri Aug 18 2017 Peter Jones - 2.02-10 +- Add the .img files into grub2-pc-modules (and all legacy variants) + +* Wed Aug 16 2017 Peter Jones - 2.02-9 +- Re-work for ia32-efi. + +* Wed Aug 16 2017 pjones - 2.02-8 +- Rebased to newer upstream for fedora-27 + +* Tue Aug 15 2017 Peter Jones - 2.02-7 +- Rebuild again with new fixed rpm. (bug #1480407) + +* Fri Aug 11 2017 Kevin Fenzi - 2.02-6 +- Rebuild again with new fixed rpm. (bug #1480407) + +* Thu Aug 10 2017 Kevin Fenzi - 2.02-5 +- Rebuild for rpm soname bump again. + +* Thu Aug 10 2017 Igor Gnatenko - 2.02-4 +- Rebuilt for RPM soname bump + +* Thu Aug 03 2017 Peter Jones - 2.02-3 +- Rebuild so it gets SB signed correctly. + Related: rhbz#1335533 +- Enable lsefi + +* Mon Jul 24 2017 Michael Cronenworth - 2.02-2 +- Fix symlink to work on both EFI and BIOS machines + Resolves: rhbz#1335533 + +* Mon Jul 10 2017 Peter Jones - 2.02-1 +- Rebased to newer upstream for fedora-27 + +* Wed Feb 01 2017 Stephen Gallagher - 2.02-0.39 +- Add missing %%license macro +- Fix deps that should have moved to -tools but didn't. + +* Thu Dec 08 2016 Peter Jones - 2.02-0.38 +- Fix regexp in power compile flags, and synchronize release number with + other branches. + +* Fri Dec 02 2016 pjones - 1:2.02-0.37 +- Rebased to newer upstream for fedora-26 + +* Thu Dec 01 2016 Peter Jones - 2.02-0.36 +- Update version to .36 because I already built an f25 one named 0.35 + +* Thu Dec 01 2016 pjones - 1:2.02-0.35 +- Rebased to newer upstream for fedora-26 + +* Thu Dec 01 2016 Peter Jones - 2.02-0.34 +- Fix power6 makefile bits for newer autoconf defaults. +- efi/chainloader: fix wrong sanity check in relocate_coff() (Laszlo Ersek) + Resolves: rhbz#1347291 + +* Thu Aug 25 2016 Peter Jones - 2.02-0.34 +- Update to be newer than f24's branch. +- Add grub2-get-kernel-settings + Related: rhbz#1226325 + +* Thu Apr 07 2016 pjones - 1:2.02-0.30 +- Revert 27e66193, which was replaced by upstream's 49426e9fd + Resolves: rhbz#1251600 + +* Thu Apr 07 2016 Peter Jones - 2.02-0.29 +- Fix ppc64 build failure and rebase to newer f24 code. + +* Tue Apr 05 2016 pjones - 1:2.02-0.27 +- Pull TPM updates from mjg59. + Resolves: rhbz#1318067 + +* Tue Mar 08 2016 pjones - 1:2.02-0.27 +- Fix aarch64 build problem. + +* Fri Mar 04 2016 Peter Jones - 2.02-0.26 +- Rebased to newer upstream (grub-2.02-beta3) for fedora-24 + +* Thu Dec 10 2015 Peter Jones - 2.02-0.25 +- Fix security issue when reading username and password + Related: CVE-2015-8370 +- Do a better job of handling GRUB2_PASSWORD + Related: rhbz#1284370 + +* Fri Nov 20 2015 Peter Jones - 2.02-0.24 +- Rebuild without multiboot* modules in the EFI image. + Related: rhbz#1264103 + +* Sat Sep 05 2015 Kalev Lember - 2.02-0.23 +- Rebuilt for librpm soname bump + +* Wed Aug 05 2015 Peter Jones - 2.02-0.21 +- Back out one of the debuginfo generation patches; it doesn't work right on + aarch64 yet. + Resolves: rhbz#1250197 + +* Mon Aug 03 2015 Peter Jones - 2.02-0.20 +- The previous fix was completely not right, so fix it a different way. + Resolves: rhbz#1249668 + +* Fri Jul 31 2015 Peter Jones - 2.02-0.19 +- Fix grub2-mkconfig's sort to put kernels in the right order. + Related: rhbz#1124074 + +* Thu Jul 30 2015 Peter Jones - 2.02-0.18 +- Fix a build failure on aarch64 + +* Wed Jul 22 2015 Peter Jones - 2.02-0.17 +- Don't build hardened (fixes FTBFS) (pbrobinson) +- Reconcile with the current upstream +- Fixes for gcc 5 + +* Tue Apr 28 2015 Peter Jones - 2.02-0.16 +- Make grub2-mkconfig produce the kernel titles we actually want. + Resolves: rhbz#1215839 + +* Sat Feb 21 2015 Till Maas +- Rebuilt for Fedora 23 Change + https://fedoraproject.org/wiki/Changes/Harden_all_packages_with_position-independent_code + +* Mon Jan 05 2015 Peter Jones - 2.02-0.15 +- Bump release to rebuild with Ralf Corsépius's fixes. + +* Sun Jan 04 2015 Ralf Corsépius - 2.02-0.14 +- Move grub2.info/grub2-dev.info install-info scriptlets into *-tools package. +- Use sub-shell in %%__debug_install_post (RHBZ#1168732). +- Cleanup grub2-starfield-theme packaging. + +* Thu Dec 04 2014 Peter Jones - 2.02-0.13 +- Update minilzo to 2.08 for CVE-2014-4607 + Resolves: rhbz#1131793 + +* Thu Nov 13 2014 Peter Jones - 2.02-0.12 +- Make backtrace and usb conditional on !arm +- Make sure gcdaa64.efi is packaged. + Resolves: rhbz#1163481 + +* Fri Nov 07 2014 Peter Jones - 2.02-0.11 +- fix a copy-paste error in patch 0154. + Resolves: rhbz#964828 + +* Mon Oct 27 2014 Peter Jones - 2.02-0.10 +- Try to emit linux16/initrd16 and linuxefi/initrdefi when appropriate + in 30_os-prober. + Resolves: rhbz#1108296 +- If $fw_path doesn't work to find the config file, try $prefix as well + Resolves: rhbz#1148652 + +* Mon Sep 29 2014 Peter Jones - 2.02-0.9 +- Clean up the build a bit to make it faster +- Make grubenv work right on UEFI machines + Related: rhbz#1119943 +- Sort debug and rescue kernels later than normal ones + Related: rhbz#1065360 +- Allow "fallback" to include entries by title as well as number. + Related: rhbz#1026084 +- Fix a segfault on aarch64. +- Load arm with SB enabled if available. +- Add some serial port options to GRUB_MODULES. + +* Tue Aug 19 2014 Peter Jones - 2.02-0.8 +- Add ppc64le support. + Resolves: rhbz#1125540 + +* Thu Jul 24 2014 Peter Jones - 2.02-0.7 +- Enabled syslinuxcfg module. + +* Wed Jul 02 2014 Peter Jones - 2.02-0.6 +- Re-merge RHEL 7 changes and ARM works in progress. + +* Mon Jun 30 2014 Peter Jones - 2.02-0.5 +- Avoid munging raw spaces when we're escaping command line arguments. + Resolves: rhbz#923374 + +* Tue Jun 24 2014 Peter Jones - 2.02-0.4 +- Update to latest upstream. + +* Thu Mar 13 2014 Peter Jones - 2.02-0.3 +- Merge in RHEL 7 changes and ARM works in progress. + +* Mon Jan 06 2014 Peter Jones - 2.02-0.2 +- Update to grub-2.02~beta2 + +* Sat Aug 10 2013 Peter Jones - 2.00-25 +- Last build failed because of a hardware error on the builder. + +* Mon Aug 05 2013 Peter Jones - 2.00-24 +- Fix compiler flags to deal with -fstack-protector-strong + +* Sat Aug 03 2013 Fedora Release Engineering - 1:2.00-24 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild + +* Tue Jul 02 2013 Dennis Gilmore - 2.00-23 +- add epoch to obsoletes + +* Fri Jun 21 2013 Peter Jones - 2.00-22 +- Fix linewrapping in edit menu. + Resolves: rhbz #976643 + +* Thu Jun 20 2013 Peter Jones - 2.00-21 +- Fix obsoletes to pull in -starfield-theme subpackage when it should. + +* Fri Jun 14 2013 Peter Jones - 2.00-20 +- Put the theme entirely ento the subpackage where it belongs (#974667) + +* Wed Jun 12 2013 Peter Jones - 2.00-19 +- Rebase to upstream snapshot. +- Fix PPC build error (#967862) +- Fix crash on net_bootp command (#960624) +- Reset colors on ppc when appropriate (#908519) +- Left align "Loading..." messages (#908492) +- Fix probing of SAS disks on PPC (#953954) +- Add support for UEFI OSes returned by os-prober +- Disable "video" mode on PPC for now (#973205) +- Make grub fit better into the boot sequence, visually (#966719) + +* Fri May 10 2013 Matthias Clasen - 2.00-18 +- Move the starfield theme to a subpackage (#962004) +- Don't allow SSE or MMX on UEFI builds (#949761) + +* Wed Apr 24 2013 Peter Jones - 2.00-17.pj0 +- Rebase to upstream snapshot. + +* Thu Apr 04 2013 Peter Jones - 2.00-17 +- Fix booting from drives with 4k sectors on UEFI. +- Move bash completion to new location (#922997) +- Include lvm support for /boot (#906203) + +* Thu Feb 14 2013 Peter Jones - 2.00-16 +- Allow the user to disable submenu generation +- (partially) support BLS-style configuration stanzas. + +* Tue Feb 12 2013 Peter Jones - 2.00-15.pj0 +- Add various config file related changes. + +* Thu Dec 20 2012 Dennis Gilmore - 2.00-15 +- bump nvr + +* Mon Dec 17 2012 Karsten Hopp 2.00-14 +- add bootpath device to the device list (pfsmorigo, #886685) + +* Tue Nov 27 2012 Peter Jones - 2.00-13 +- Add vlan tag support (pfsmorigo, #871563) +- Follow symlinks during PReP installation in grub2-install (pfsmorigo, #874234) +- Improve search paths for config files on network boot (pfsmorigo, #873406) + +* Tue Oct 23 2012 Peter Jones - 2.00-12 +- Don't load modules when grub transitions to "normal" mode on UEFI. + +* Mon Oct 22 2012 Peter Jones - 2.00-11 +- Rebuild with newer pesign so we'll get signed with the final signing keys. + +* Thu Oct 18 2012 Peter Jones - 2.00-10 +- Various PPC fixes. +- Fix crash fetching from http (gustavold, #860834) +- Issue separate dns queries for ipv4 and ipv6 (gustavold, #860829) +- Support IBM CAS reboot (pfsmorigo, #859223) +- Include all modules in the core image on ppc (pfsmorigo, #866559) + +* Mon Oct 01 2012 Peter Jones - 1:2.00-9 +- Work around bug with using "\x20" in linux command line. + Related: rhbz#855849 + +* Thu Sep 20 2012 Peter Jones - 2.00-8 +- Don't error on insmod on UEFI/SB, but also don't do any insmodding. +- Increase device path size for ieee1275 + Resolves: rhbz#857936 +- Make network booting work on ieee1275 machines. + Resolves: rhbz#857936 + +* Wed Sep 05 2012 Matthew Garrett - 2.00-7 +- Add Apple partition map support for EFI + +* Thu Aug 23 2012 David Cantrell - 2.00-6 +- Only require pesign on EFI architectures (#851215) + +* Tue Aug 14 2012 Peter Jones - 2.00-5 +- Work around AHCI firmware bug in efidisk driver. +- Move to newer pesign macros +- Don't allow insmod if we're in secure-boot mode. + +* Wed Aug 08 2012 Peter Jones +- Split module lists for UEFI boot vs UEFI cd images. +- Add raid modules for UEFI image (related: #750794) +- Include a prelink whitelist for binaries that need execstack (#839813) +- Include fix efi memory map fix from upstream (#839363) + +* Wed Aug 08 2012 Peter Jones - 2.00-4 +- Correct grub-mkimage invocation to use efidir RPM macro (jwb) +- Sign with test keys on UEFI systems. +- PPC - Handle device paths with commas correctly. + Related: rhbz#828740 + +* Wed Jul 25 2012 Peter Jones - 2.00-3 +- Add some more code to support Secure Boot, and temporarily disable + some other bits that don't work well enough yet. + Resolves: rhbz#836695 + +* Wed Jul 11 2012 Matthew Garrett - 2.00-2 +- Set a prefix for the image - needed for installer work +- Provide the font in the EFI directory for the same reason + +* Thu Jun 28 2012 Peter Jones - 2.00-1 +- Rebase to grub-2.00 release. + +* Mon Jun 18 2012 Peter Jones - 2.0-0.37.beta6 +- Fix double-free in grub-probe. + +* Wed Jun 06 2012 Peter Jones - 2.0-0.36.beta6 +- Build with patch19 applied. + +* Wed Jun 06 2012 Peter Jones - 2.0-0.35.beta6 +- More ppc fixes. + +* Wed Jun 06 2012 Peter Jones - 2.0-0.34.beta6 +- Add IBM PPC fixes. + +* Mon Jun 04 2012 Peter Jones - 2.0-0.33.beta6 +- Update to beta6. +- Various fixes from mads. + +* Fri May 25 2012 Peter Jones - 2.0-0.32.beta5 +- Revert builddep change for crt1.o; it breaks ppc build. + +* Fri May 25 2012 Peter Jones - 2.0-0.31.beta5 +- Add fwsetup command (pjones) +- More ppc fixes (IBM) + +* Tue May 22 2012 Peter Jones - 2.0-0.30.beta5 +- Fix the /other/ grub2-tools require to include epoch. + +* Mon May 21 2012 Peter Jones - 2.0-0.29.beta5 +- Get rid of efi_uga and efi_gop, favoring all_video instead. + +* Mon May 21 2012 Peter Jones - 2.0-0.28.beta5 +- Name grub.efi something that's arch-appropriate (kiilerix, pjones) +- use EFI/$SOMETHING_DISTRO_BASED/ not always EFI/redhat/grub2-efi/ . +- move common stuff to -tools (kiilerix) +- spec file cleanups (kiilerix) + +* Mon May 14 2012 Peter Jones - 2.0-0.27.beta5 +- Fix module trampolining on ppc (benh) + +* Thu May 10 2012 Peter Jones - 2.0-0.27.beta5 +- Fix license of theme (mizmo) + Resolves: rhbz#820713 +- Fix some PPC bootloader detection IBM problem + Resolves: rhbz#820722 + +* Thu May 10 2012 Peter Jones - 2.0-0.26.beta5 +- Update to beta5. +- Update how efi building works (kiilerix) +- Fix theme support to bring in fonts correctly (kiilerix, pjones) + +* Wed May 09 2012 Peter Jones - 2.0-0.25.beta4 +- Include theme support (mizmo) +- Include locale support (kiilerix) +- Include html docs (kiilerix) + +* Thu Apr 26 2012 Peter Jones - 2.0-0.24 +- Various fixes from Mads Kiilerich + +* Thu Apr 19 2012 Peter Jones - 2.0-0.23 +- Update to 2.00~beta4 +- Make fonts work so we can do graphics reasonably + +* Thu Mar 29 2012 David Aquilina - 2.0-0.22 +- Fix ieee1275 platform define for ppc + +* Thu Mar 29 2012 Peter Jones - 2.0-0.21 +- Remove ppc excludearch lines (dwa) +- Update ppc terminfo patch (hamzy) + +* Wed Mar 28 2012 Peter Jones - 2.0-0.20 +- Fix ppc64 vs ppc exclude according to what dwa tells me they need +- Fix version number to better match policy. + +* Tue Mar 27 2012 Dan Horák - 1.99-19.2 +- Add support for serial terminal consoles on PPC by Mark Hamzy + +* Sun Mar 25 2012 Dan Horák - 1.99-19.1 +- Use Fix-tests-of-zeroed-partition patch by Mark Hamzy + +* Thu Mar 15 2012 Peter Jones - 1.99-19 +- Use --with-grubdir= on configure to make it behave like -17 did. + +* Wed Mar 14 2012 Peter Jones - 1.99-18 +- Rebase from 1.99 to 2.00~beta2 + +* Wed Mar 07 2012 Peter Jones - 1.99-17 +- Update for newer autotools and gcc 4.7.0 + Related: rhbz#782144 +- Add /etc/sysconfig/grub link to /etc/default/grub + Resolves: rhbz#800152 +- ExcludeArch s390*, which is not supported by this package. + Resolves: rhbz#758333 + +* Fri Feb 17 2012 Orion Poplawski - 1:1.99-16 +- Build with -Os (bug 782144) + +* Fri Jan 13 2012 Fedora Release Engineering - 1:1.99-15 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Wed Dec 14 2011 Matthew Garrett - 1.99-14 +- fix up various grub2-efi issues + +* Thu Dec 08 2011 Adam Williamson - 1.99-13 +- fix hardwired call to grub-probe in 30_os-prober (rhbz#737203) + +* Mon Nov 07 2011 Peter Jones - 1.99-12 +- Lots of .spec fixes from Mads Kiilerich: + Remove comment about update-grub - it isn't run in any scriptlets + patch info pages so they can be installed and removed correctly when renamed + fix references to grub/grub2 renames in info pages (#743964) + update README.Fedora (#734090) + fix comments for the hack for upgrading from grub2 < 1.99-4 + fix sed syntax error preventing use of $RPM_OPT_FLAGS (#704820) + make /etc/grub2*.cfg %%config(noreplace) + make grub.cfg %%ghost - an empty file is of no use anyway + create /etc/default/grub more like anaconda would create it (#678453) + don't create rescue entries by default - grubby will not maintain them anyway + set GRUB_SAVEDEFAULT=true so saved defaults works (rbhz#732058) + grub2-efi should have its own bash completion + don't set gfxpayload in efi mode - backport upstream r3402 +- Handle dmraid better. Resolves: rhbz#742226 + +* Wed Oct 26 2011 Fedora Release Engineering - 1:1.99-11 +- Rebuilt for glibc bug#747377 + +* Wed Oct 19 2011 Adam Williamson - 1.99-10 +- /etc/default/grub is explicitly intended for user customization, so + mark it as config(noreplace) + +* Tue Oct 11 2011 Peter Jones - 1.99-9 +- grub has an epoch, so we need that expressed in the obsolete as well. + Today isn't my day. + +* Tue Oct 11 2011 Peter Jones - 1.99-8 +- Fix my bad obsoletes syntax. + +* Thu Oct 06 2011 Peter Jones - 1.99-7 +- Obsolete grub + Resolves: rhbz#743381 + +* Wed Sep 14 2011 Peter Jones - 1.99-6 +- Use mv not cp to try to avoid moving disk blocks around for -5 fix + Related: rhbz#735259 +- handle initramfs on xen better (patch from Marko Ristola) + Resolves: rhbz#728775 + +* Sat Sep 03 2011 Kalev Lember - 1.99-5 +- Fix upgrades from grub2 < 1.99-4 (#735259) + +* Fri Sep 02 2011 Peter Jones - 1.99-4 +- Don't do sysadminny things in %%preun or %%post ever. (#735259) +- Actually include the changelog in this build (sorry about -3) + +* Thu Sep 01 2011 Peter Jones - 1.99-2 +- Require os-prober (#678456) (patch from Elad Alfassa) +- Require which (#734959) (patch from Elad Alfassa) + +* Thu Sep 01 2011 Peter Jones - 1.99-1 +- Update to grub-1.99 final. +- Fix crt1.o require on x86-64 (fix from Mads Kiilerich) +- Various CFLAGS fixes (from Mads Kiilerich) + - -fexceptions and -m64 +- Temporarily ignore translations (from Mads Kiilerich) + +* Thu Jul 21 2011 Peter Jones - 1.99-0.3 +- Use /sbin not /usr/sbin . + +* Thu Jun 23 2011 Peter Lemenkov - 1:1.99-0.2 +- Fixes for ppc and ppc64 + +* Wed Feb 09 2011 Fedora Release Engineering - 1:1.98-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild diff --git a/noautobuild b/noautobuild new file mode 100644 index 0000000..e69de29 diff --git a/sources b/sources new file mode 100644 index 0000000..9bd1834 --- /dev/null +++ b/sources @@ -0,0 +1,4 @@ +SHA512 (unifont-5.1.20080820.pcf.gz) = 8939e2bc82ca97b60e6678f3ff079a2be7ba9b702f2e8ee289e853af5823695f7baafbf14b674fc5e41071f2a6de4f2dadd56bf8b4653849dd756d59622f1649 +SHA512 (theme.tar.bz2) = 0f6f914d5f801509403094b28b8cfe5169cb56ae9bdd808ae21a6780a8236b434161a068351508dd78729c25ee2fed066c124c1eef9e15102750b409b4576a5c +SHA512 (grub-2.04.tar.xz) = 9c15c42d0cf5d61446b752194e3b628bb04be0fe6ea0240ab62b3d753784712744846e1f7c3651d8e0968d22012e6d713c38c44936d4004ded3ca4d4007babbb +SHA512 (gnulib-fixes.tar.gz) = c45de2126598485bcf2fee81a66e64afa0e253aa04fc796c9201dd50229a93cc086d635a21d4644cb454ad6f71fa342494573aa86478fca19059cf71836b0619 diff --git a/strtoull_test.c b/strtoull_test.c new file mode 100644 index 0000000..7da615f --- /dev/null +++ b/strtoull_test.c @@ -0,0 +1,63 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2016 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static void +strtoull_testcase (const char *input, int base, unsigned long long expected, + int num_digits, grub_err_t error) +{ + char *output; + unsigned long long value; + grub_errno = 0; + value = grub_strtoull(input, &output, base); + grub_test_assert (grub_errno == error, + "unexpected error. Expected %d, got %d. Input \"%s\"", + error, grub_errno, input); + if (grub_errno) + { + grub_errno = 0; + return; + } + grub_test_assert (input + num_digits == output, + "unexpected number of digits. Expected %d, got %d, input \"%s\"", + num_digits, (int) (output - input), input); + grub_test_assert (value == expected, + "unexpected return value. Expected %llu, got %llu, input \"\%s\"", + expected, value, input); +} + +static void +strtoull_test (void) +{ + strtoull_testcase ("9", 0, 9, 1, GRUB_ERR_NONE); + strtoull_testcase ("0xaa", 0, 0xaa, 4, GRUB_ERR_NONE); + strtoull_testcase ("0xff", 0, 0xff, 4, GRUB_ERR_NONE); + strtoull_testcase ("0", 10, 0, 1, GRUB_ERR_NONE); + strtoull_testcase ("8", 8, 0, 0, GRUB_ERR_BAD_NUMBER); + strtoull_testcase ("38", 8, 3, 1, GRUB_ERR_NONE); + strtoull_testcase ("7", 8, 7, 1, GRUB_ERR_NONE); + strtoull_testcase ("1]", 16, 1, 1, GRUB_ERR_NONE); + strtoull_testcase ("18446744073709551616", 10, 0, 0, GRUB_ERR_OUT_OF_RANGE); +} + + +GRUB_FUNCTIONAL_TEST (strtoull_test, strtoull_test);