From ce0f4932682bb82a854630e0fe7b6fcb1bc14459 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Jul 16 2018 19:54:21 +0000 Subject: Rebased to newer upstream for fedora-29 Signed-off-by: Peter Jones --- diff --git a/0153-grub-setup-Debug-message-cleanup.patch b/0153-grub-setup-Debug-message-cleanup.patch new file mode 100644 index 0000000..7a58522 --- /dev/null +++ b/0153-grub-setup-Debug-message-cleanup.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Cao jin +Date: Tue, 3 Jul 2018 18:51:13 +0800 +Subject: [PATCH] grub-setup: Debug message cleanup + +Variable "root" is initialized after root device probing and is null in +current place, so, drop it. + +Signed-off-by: Cao jin +Reviewed-by: Daniel Kiper +--- + util/setup.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/util/setup.c b/util/setup.c +index 80363075d34..9c1e1b7da6a 100644 +--- a/util/setup.c ++++ b/util/setup.c +@@ -305,9 +305,8 @@ SETUP (const char *dir, + bl.first_block = (struct grub_boot_blocklist *) (core_img + + GRUB_DISK_SECTOR_SIZE + - sizeof (*bl.block)); +- grub_util_info ("root is `%s', dest is `%s'", root, dest); + +- grub_util_info ("Opening dest"); ++ grub_util_info ("Opening dest `%s'", dest); + dest_dev = grub_device_open (dest); + if (! dest_dev) + grub_util_error ("%s", grub_errmsg); diff --git a/0153-re-write-.gitignore.patch b/0153-re-write-.gitignore.patch deleted file mode 100644 index 4635360..0000000 --- a/0153-re-write-.gitignore.patch +++ /dev/null @@ -1,497 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 8 Aug 2017 12:48:04 -0400 -Subject: [PATCH] re-write .gitignore - ---- - .gitignore | 352 ++++++++++++-------------------------- - build-aux/.gitignore | 9 + - docs/.gitignore | 4 + - grub-core/.gitignore | 15 ++ - grub-core/gnulib/.gitignore | 22 +++ - grub-core/lib/.gitignore | 1 + - include/grub/gcrypt/.gitignore | 2 + - po/.gitignore | 4 + - util/bash-completion.d/.gitignore | 1 + - 9 files changed, 170 insertions(+), 240 deletions(-) - create mode 100644 build-aux/.gitignore - create mode 100644 docs/.gitignore - create mode 100644 grub-core/.gitignore - create mode 100644 grub-core/gnulib/.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 eca17bec9b8..d95fac5789c 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -1,249 +1,121 @@ --00_header --10_* --20_linux_xen --30_os-prober --40_custom --41_custom --*.1 --*.8 --aclocal.m4 --ahci_test --ascii.bitmaps --ascii.h --autom4te.cache --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 -+# things ./autogen.sh will create -+/Makefile.utilgcry.def -+/aclocal.m4 -+/autom4te.cache -+/configure -+Makefile -+# we want to enable building in a subdirectory, but we don't want to exclude -+# /build-aux so explicitly don't ignore it. -+/build*/ -+!/build-aux/ -+ -+# things very common editors create that we never want -+*~ -+.*.sw? -+ -+# built objects across the whole tree -+Makefile.in -+*.a -+*.am - *.exec --*.exec.exe --fddboot_test --genkernsyms.sh --gensymlist.sh --gentrigtables --gentrigtables.exe --gettext_strings_test --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-sh --lib/libgcrypt-grub --libgrub_a_init.c --*.log -+*.img -+*.info - *.lst --lzocompress_test - *.marker --Makefile - *.mod --mod-*.c --missing --netboot_test -+*.module - *.o --*.a --ohci_test --partmap_test --pata_test - *.pf2 --*.pp --po/*.mo --po/grub.pot --po/POTFILES --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/gnulib/alloca.h --grub-core/gnulib/arg-nonnull.h --grub-core/gnulib/c++defs.h --grub-core/gnulib/charset.alias --grub-core/gnulib/configmake.h --grub-core/gnulib/float.h --grub-core/gnulib/getopt.h --grub-core/gnulib/langinfo.h --grub-core/gnulib/ref-add.sed --grub-core/gnulib/ref-del.sed --grub-core/gnulib/stdio.h --grub-core/gnulib/stdlib.h --grub-core/gnulib/string.h --grub-core/gnulib/strings.h --grub-core/gnulib/sys --grub-core/gnulib/unistd.h --grub-core/gnulib/warn-on-use.h --grub-core/gnulib/wchar.h --grub-core/gnulib/wctype.h --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 --grub-core/gnulib/locale.h --grub-core/gnulib/unitypes.h --grub-core/gnulib/uniwidth.h --build-aux/test-driver -+ -+# 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 -+/po/POTFILES -+/stamp-h -+/stamp-h1 -+config.log -+config.status -+ -+# stuff "make dist" creates -+ChangeLog -+grub-*.tar -+grub-*.tar.* -+ -+# stuff "make" creates -+/[[:digit:]][[:digit:]]_?* -+/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*-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*-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*-script-check -+/grub*-script-check.1 -+/grub*-set-default -+/grub*-set-default.8 -+/grub*-shell -+/grub*-shell-tester -+/grub*-sparc64-setup -+/grub*-sparc64-setup.8 -+/grub*-syslinux2cfg -+/grub*-syslinux2cfg.1 -+/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 -diff --git a/build-aux/.gitignore b/build-aux/.gitignore -new file mode 100644 -index 00000000000..f2f17aab9ff ---- /dev/null -+++ b/build-aux/.gitignore -@@ -0,0 +1,9 @@ -+/compile -+/config.guess -+/config.sub -+/depcomp -+/install-sh -+/mdate-sh -+/missing -+/test-driver -+/texinfo.tex -diff --git a/docs/.gitignore b/docs/.gitignore -new file mode 100644 -index 00000000000..91aee84d3e9 ---- /dev/null -+++ b/docs/.gitignore -@@ -0,0 +1,4 @@ -+/*.in -+/stamp-1 -+/stamp-vti -+/version*.texi -diff --git a/grub-core/.gitignore b/grub-core/.gitignore -new file mode 100644 -index 00000000000..c738ac6c649 ---- /dev/null -+++ b/grub-core/.gitignore -@@ -0,0 +1,15 @@ -+/*.lst -+/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/gnulib/.gitignore b/grub-core/gnulib/.gitignore -new file mode 100644 -index 00000000000..29e199c2db4 ---- /dev/null -+++ b/grub-core/gnulib/.gitignore -@@ -0,0 +1,22 @@ -+/alloca.h -+/arg-nonnull.h -+/c++defs.h -+/charset.alias -+/configmake.h -+/getopt.h -+/langinfo.h -+/libgnu.a -+/locale.h -+/ref-add.sed -+/ref-del.sed -+/stdio.h -+/stdlib.h -+/string.h -+/strings.h -+/sys/ -+/unistd.h -+/unitypes.h -+/uniwidth.h -+/warn-on-use.h -+/wchar.h -+/wctype.h -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..97b679c3138 ---- /dev/null -+++ b/po/.gitignore -@@ -0,0 +1,4 @@ -+/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..b7e1eb12428 ---- /dev/null -+++ b/util/bash-completion.d/.gitignore -@@ -0,0 +1 @@ -+grub diff --git a/0154-IBM-client-architecture-CAS-reboot-support.patch b/0154-IBM-client-architecture-CAS-reboot-support.patch deleted file mode 100644 index 0dcaa0a..0000000 --- a/0154-IBM-client-architecture-CAS-reboot-support.patch +++ /dev/null @@ -1,172 +0,0 @@ -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 62929d983bf..2d53c0e8608 100644 ---- a/grub-core/kern/ieee1275/openfw.c -+++ b/grub-core/kern/ieee1275/openfw.c -@@ -588,3 +588,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 78a70a8bf47..249e19bc788 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 a8502d90711..ab78ca87f90 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -27,6 +27,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. */ -@@ -877,6 +880,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 8868f3a756f..2310f33dbc2 100644 ---- a/include/grub/ieee1275/ieee1275.h -+++ b/include/grub/ieee1275/ieee1275.h -@@ -252,6 +252,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/0154-efi-console-Fix-the-enter-key-not-working-on-x86-tab.patch b/0154-efi-console-Fix-the-enter-key-not-working-on-x86-tab.patch new file mode 100644 index 0000000..222f403 --- /dev/null +++ b/0154-efi-console-Fix-the-enter-key-not-working-on-x86-tab.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 26 Jun 2018 20:15:01 +0200 +Subject: [PATCH] efi/console: Fix the "enter" key not working on x86 tablets + +Most 8" or 7" x86 Windows 10 tablets come with volume up/down buttons and +a power-button. In their UEFI these are almost always mapped to arrow +up/down and enter. + +Pressing the volume buttons (sometimes by accident) will stop the +menu countdown, but the power-button / "enter" key was not being recognized +as enter, so the user would be stuck at the grub menu. + +The problem is that these tablets send scan_code 13 or 0x0d for the +power-button, which officialy maps to the F3 key. They also set +unicode_char to 0x0d. + +This commit recognizes the special case of both scan_code and unicode_char +being set to 0x0d and treats this as an enter key press. + +This fixes things getting stuck at the grub-menu and allows the user +to choice a grub-menu entry using the buttons on the tablet. + +Signed-off-by: Hans de Goede +Reviewed-by: Daniel Kiper +--- + grub-core/term/efi/console.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c +index 02f64ea7441..4840cc59d3f 100644 +--- a/grub-core/term/efi/console.c ++++ b/grub-core/term/efi/console.c +@@ -122,6 +122,9 @@ grub_efi_translate_key (grub_efi_input_key_t key) + else + return key.unicode_char; + } ++ /* Some devices send enter with scan_code 0x0d (F3) and unicode_char 0x0d. */ ++ else if (key.scan_code == '\r' && key.unicode_char == '\r') ++ return key.unicode_char; + else if (key.scan_code < ARRAY_SIZE (efi_codes)) + return efi_codes[key.scan_code]; + diff --git a/0155-commands-file-Use-definitions-from-arm-linux.h.patch b/0155-commands-file-Use-definitions-from-arm-linux.h.patch new file mode 100644 index 0000000..8350f24 --- /dev/null +++ b/0155-commands-file-Use-definitions-from-arm-linux.h.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leif Lindholm +Date: Mon, 25 Jun 2018 18:01:28 +0100 +Subject: [PATCH] commands/file: Use definitions from arm/linux.h + +Clean up code for matching IS_ARM slightly by making use of struct +linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE. + +Signed-off-by: Leif Lindholm +Reviewed-by: Daniel Kiper +--- + grub-core/commands/file.c | 17 ++++++++--------- + 1 file changed, 8 insertions(+), 9 deletions(-) + +diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c +index 63c84499bab..ab0c9fb9694 100644 +--- a/grub-core/commands/file.c ++++ b/grub-core/commands/file.c +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -383,21 +384,19 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) + } + case IS_ARM_LINUX: + { +- grub_uint32_t sig, sig_pi; +- if (grub_file_read (file, &sig_pi, 4) != 4) ++ struct linux_arm_kernel_header lh; ++ ++ if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) + break; +- /* Raspberry pi. */ +- if (sig_pi == grub_cpu_to_le32_compile_time (0xea000006)) ++ /* Short forward branch in A32 state (for Raspberry pi kernels). */ ++ if (lh.code0 == grub_cpu_to_le32_compile_time (0xea000006)) + { + ret = 1; + break; + } + +- if (grub_file_seek (file, 0x24) == (grub_size_t) -1) +- break; +- if (grub_file_read (file, &sig, 4) != 4) +- break; +- if (sig == grub_cpu_to_le32_compile_time (0x016f2818)) ++ if (lh.magic == ++ grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM_MAGIC_SIGNATURE)) + { + ret = 1; + break; diff --git a/0155-for-ppc-reset-console-display-attr-when-clear-screen.patch b/0155-for-ppc-reset-console-display-attr-when-clear-screen.patch deleted file mode 100644 index ac67453..0000000 --- a/0155-for-ppc-reset-console-display-attr-when-clear-screen.patch +++ /dev/null @@ -1,29 +0,0 @@ -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/0156-Disable-GRUB-video-support-for-IBM-power-machines.patch b/0156-Disable-GRUB-video-support-for-IBM-power-machines.patch deleted file mode 100644 index ab411af..0000000 --- a/0156-Disable-GRUB-video-support-for-IBM-power-machines.patch +++ /dev/null @@ -1,62 +0,0 @@ -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 3e12e6b24e1..3e14f539368 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 2310f33dbc2..ca08bd96681 100644 ---- a/include/grub/ieee1275/ieee1275.h -+++ b/include/grub/ieee1275/ieee1275.h -@@ -146,6 +146,8 @@ enum grub_ieee1275_flag - GRUB_IEEE1275_FLAG_BROKEN_REPEAT, - - GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN, -+ -+ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT - }; - - extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); diff --git a/0156-commands-file-Use-definitions-from-arm64-linux.h.patch b/0156-commands-file-Use-definitions-from-arm64-linux.h.patch new file mode 100644 index 0000000..5ee71bc --- /dev/null +++ b/0156-commands-file-Use-definitions-from-arm64-linux.h.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Leif Lindholm +Date: Mon, 25 Jun 2018 18:01:29 +0100 +Subject: [PATCH] commands/file: Use definitions from arm64/linux.h + +Clean up code for matching IS_ARM64 slightly by making use of struct +linux_arm64_kernel_header and GRUB_LINUX_ARM64_MAGIC_SIGNATURE. + +Signed-off-by: Leif Lindholm +Reviewed-by: Daniel Kiper +--- + grub-core/commands/file.c | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c +index ab0c9fb9694..3ff6d5522d2 100644 +--- a/grub-core/commands/file.c ++++ b/grub-core/commands/file.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -405,13 +406,13 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args) + } + case IS_ARM64_LINUX: + { +- grub_uint32_t sig; ++ struct linux_arm64_kernel_header lh; + +- if (grub_file_seek (file, 0x38) == (grub_size_t) -1) ++ if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) + break; +- if (grub_file_read (file, &sig, 4) != 4) +- break; +- if (sig == grub_cpu_to_le32_compile_time (0x644d5241)) ++ ++ if (lh.magic == ++ grub_cpu_to_le32_compile_time (GRUB_LINUX_ARM64_MAGIC_SIGNATURE)) + { + ret = 1; + break; diff --git a/0157-Honor-a-symlink-when-generating-configuration-by-gru.patch b/0157-Honor-a-symlink-when-generating-configuration-by-gru.patch deleted file mode 100644 index 1ea476c..0000000 --- a/0157-Honor-a-symlink-when-generating-configuration-by-gru.patch +++ /dev/null @@ -1,26 +0,0 @@ -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 33332360eec..bc5a3f17541 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/0157-re-write-.gitignore.patch b/0157-re-write-.gitignore.patch new file mode 100644 index 0000000..4635360 --- /dev/null +++ b/0157-re-write-.gitignore.patch @@ -0,0 +1,497 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 8 Aug 2017 12:48:04 -0400 +Subject: [PATCH] re-write .gitignore + +--- + .gitignore | 352 ++++++++++++-------------------------- + build-aux/.gitignore | 9 + + docs/.gitignore | 4 + + grub-core/.gitignore | 15 ++ + grub-core/gnulib/.gitignore | 22 +++ + grub-core/lib/.gitignore | 1 + + include/grub/gcrypt/.gitignore | 2 + + po/.gitignore | 4 + + util/bash-completion.d/.gitignore | 1 + + 9 files changed, 170 insertions(+), 240 deletions(-) + create mode 100644 build-aux/.gitignore + create mode 100644 docs/.gitignore + create mode 100644 grub-core/.gitignore + create mode 100644 grub-core/gnulib/.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 eca17bec9b8..d95fac5789c 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -1,249 +1,121 @@ +-00_header +-10_* +-20_linux_xen +-30_os-prober +-40_custom +-41_custom +-*.1 +-*.8 +-aclocal.m4 +-ahci_test +-ascii.bitmaps +-ascii.h +-autom4te.cache +-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 ++# things ./autogen.sh will create ++/Makefile.utilgcry.def ++/aclocal.m4 ++/autom4te.cache ++/configure ++Makefile ++# we want to enable building in a subdirectory, but we don't want to exclude ++# /build-aux so explicitly don't ignore it. ++/build*/ ++!/build-aux/ ++ ++# things very common editors create that we never want ++*~ ++.*.sw? ++ ++# built objects across the whole tree ++Makefile.in ++*.a ++*.am + *.exec +-*.exec.exe +-fddboot_test +-genkernsyms.sh +-gensymlist.sh +-gentrigtables +-gentrigtables.exe +-gettext_strings_test +-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-sh +-lib/libgcrypt-grub +-libgrub_a_init.c +-*.log ++*.img ++*.info + *.lst +-lzocompress_test + *.marker +-Makefile + *.mod +-mod-*.c +-missing +-netboot_test ++*.module + *.o +-*.a +-ohci_test +-partmap_test +-pata_test + *.pf2 +-*.pp +-po/*.mo +-po/grub.pot +-po/POTFILES +-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/gnulib/alloca.h +-grub-core/gnulib/arg-nonnull.h +-grub-core/gnulib/c++defs.h +-grub-core/gnulib/charset.alias +-grub-core/gnulib/configmake.h +-grub-core/gnulib/float.h +-grub-core/gnulib/getopt.h +-grub-core/gnulib/langinfo.h +-grub-core/gnulib/ref-add.sed +-grub-core/gnulib/ref-del.sed +-grub-core/gnulib/stdio.h +-grub-core/gnulib/stdlib.h +-grub-core/gnulib/string.h +-grub-core/gnulib/strings.h +-grub-core/gnulib/sys +-grub-core/gnulib/unistd.h +-grub-core/gnulib/warn-on-use.h +-grub-core/gnulib/wchar.h +-grub-core/gnulib/wctype.h +-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 +-grub-core/gnulib/locale.h +-grub-core/gnulib/unitypes.h +-grub-core/gnulib/uniwidth.h +-build-aux/test-driver ++ ++# 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 ++/po/POTFILES ++/stamp-h ++/stamp-h1 ++config.log ++config.status ++ ++# stuff "make dist" creates ++ChangeLog ++grub-*.tar ++grub-*.tar.* ++ ++# stuff "make" creates ++/[[:digit:]][[:digit:]]_?* ++/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*-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*-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*-script-check ++/grub*-script-check.1 ++/grub*-set-default ++/grub*-set-default.8 ++/grub*-shell ++/grub*-shell-tester ++/grub*-sparc64-setup ++/grub*-sparc64-setup.8 ++/grub*-syslinux2cfg ++/grub*-syslinux2cfg.1 ++/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 +diff --git a/build-aux/.gitignore b/build-aux/.gitignore +new file mode 100644 +index 00000000000..f2f17aab9ff +--- /dev/null ++++ b/build-aux/.gitignore +@@ -0,0 +1,9 @@ ++/compile ++/config.guess ++/config.sub ++/depcomp ++/install-sh ++/mdate-sh ++/missing ++/test-driver ++/texinfo.tex +diff --git a/docs/.gitignore b/docs/.gitignore +new file mode 100644 +index 00000000000..91aee84d3e9 +--- /dev/null ++++ b/docs/.gitignore +@@ -0,0 +1,4 @@ ++/*.in ++/stamp-1 ++/stamp-vti ++/version*.texi +diff --git a/grub-core/.gitignore b/grub-core/.gitignore +new file mode 100644 +index 00000000000..c738ac6c649 +--- /dev/null ++++ b/grub-core/.gitignore +@@ -0,0 +1,15 @@ ++/*.lst ++/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/gnulib/.gitignore b/grub-core/gnulib/.gitignore +new file mode 100644 +index 00000000000..29e199c2db4 +--- /dev/null ++++ b/grub-core/gnulib/.gitignore +@@ -0,0 +1,22 @@ ++/alloca.h ++/arg-nonnull.h ++/c++defs.h ++/charset.alias ++/configmake.h ++/getopt.h ++/langinfo.h ++/libgnu.a ++/locale.h ++/ref-add.sed ++/ref-del.sed ++/stdio.h ++/stdlib.h ++/string.h ++/strings.h ++/sys/ ++/unistd.h ++/unitypes.h ++/uniwidth.h ++/warn-on-use.h ++/wchar.h ++/wctype.h +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..97b679c3138 +--- /dev/null ++++ b/po/.gitignore +@@ -0,0 +1,4 @@ ++/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..b7e1eb12428 +--- /dev/null ++++ b/util/bash-completion.d/.gitignore +@@ -0,0 +1 @@ ++grub diff --git a/0158-IBM-client-architecture-CAS-reboot-support.patch b/0158-IBM-client-architecture-CAS-reboot-support.patch new file mode 100644 index 0000000..0dcaa0a --- /dev/null +++ b/0158-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 62929d983bf..2d53c0e8608 100644 +--- a/grub-core/kern/ieee1275/openfw.c ++++ b/grub-core/kern/ieee1275/openfw.c +@@ -588,3 +588,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 78a70a8bf47..249e19bc788 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 a8502d90711..ab78ca87f90 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -27,6 +27,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. */ +@@ -877,6 +880,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 8868f3a756f..2310f33dbc2 100644 +--- a/include/grub/ieee1275/ieee1275.h ++++ b/include/grub/ieee1275/ieee1275.h +@@ -252,6 +252,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/0158-Move-bash-completion-script-922997.patch b/0158-Move-bash-completion-script-922997.patch deleted file mode 100644 index 6c3c773..0000000 --- a/0158-Move-bash-completion-script-922997.patch +++ /dev/null @@ -1,52 +0,0 @@ -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 c7888e40f66..783118ccdcd 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -289,6 +289,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. - # -@@ -498,6 +506,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/0159-Update-to-minilzo-2.08.patch b/0159-Update-to-minilzo-2.08.patch deleted file mode 100644 index a71c501..0000000 --- a/0159-Update-to-minilzo-2.08.patch +++ /dev/null @@ -1,8509 +0,0 @@ -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/0159-for-ppc-reset-console-display-attr-when-clear-screen.patch b/0159-for-ppc-reset-console-display-attr-when-clear-screen.patch new file mode 100644 index 0000000..ac67453 --- /dev/null +++ b/0159-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/0160-Allow-fallback-to-include-entries-by-title-not-just-.patch b/0160-Allow-fallback-to-include-entries-by-title-not-just-.patch deleted file mode 100644 index bee65ed..0000000 --- a/0160-Allow-fallback-to-include-entries-by-title-not-just-.patch +++ /dev/null @@ -1,141 +0,0 @@ -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 e7a83c2d6e2..d2f64b05e0a 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/0160-Disable-GRUB-video-support-for-IBM-power-machines.patch b/0160-Disable-GRUB-video-support-for-IBM-power-machines.patch new file mode 100644 index 0000000..ab411af --- /dev/null +++ b/0160-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 3e12e6b24e1..3e14f539368 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 2310f33dbc2..ca08bd96681 100644 +--- a/include/grub/ieee1275/ieee1275.h ++++ b/include/grub/ieee1275/ieee1275.h +@@ -146,6 +146,8 @@ enum grub_ieee1275_flag + GRUB_IEEE1275_FLAG_BROKEN_REPEAT, + + GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN, ++ ++ GRUB_IEEE1275_FLAG_DISABLE_VIDEO_SUPPORT + }; + + extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag); diff --git a/0161-Add-GRUB_DISABLE_UUID.patch b/0161-Add-GRUB_DISABLE_UUID.patch deleted file mode 100644 index a6856d2..0000000 --- a/0161-Add-GRUB_DISABLE_UUID.patch +++ /dev/null @@ -1,106 +0,0 @@ -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 2adfa97bee8..2fd32608c01 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 bc5a3f17541..b0a8626dd1c 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/0161-Honor-a-symlink-when-generating-configuration-by-gru.patch b/0161-Honor-a-symlink-when-generating-configuration-by-gru.patch new file mode 100644 index 0000000..1ea476c --- /dev/null +++ b/0161-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 33332360eec..bc5a3f17541 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/0162-Make-exit-take-a-return-code.patch b/0162-Make-exit-take-a-return-code.patch deleted file mode 100644 index 937c774..0000000 --- a/0162-Make-exit-take-a-return-code.patch +++ /dev/null @@ -1,256 +0,0 @@ -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 | 2 +- - grub-core/kern/uboot/init.c | 6 +++--- - grub-core/kern/xen/init.c | 2 +- - include/grub/misc.h | 2 +- - 14 files changed, 39 insertions(+), 21 deletions(-) - -diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c -index a3a11824172..b25ca4b9f17 100644 ---- a/grub-core/commands/minicmd.c -+++ b/grub-core/commands/minicmd.c -@@ -176,12 +176,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 708581fcbde..e339f264b3a 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 76661337f10..82012a72fcb 100644 ---- a/grub-core/kern/emu/misc.c -+++ b/grub-core/kern/emu/misc.c -@@ -137,9 +137,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 0d8ebf58b95..f5423ce27d9 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -68,7 +68,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..952411d5dc6 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -1095,7 +1095,7 @@ grub_abort (void) - grub_getkey (); - } - -- grub_exit (); -+ grub_exit (1); - } - - void -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 0559c033c3d..fce526d417b 100644 ---- a/grub-core/kern/xen/init.c -+++ b/grub-core/kern/xen/init.c -@@ -549,7 +549,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 372f009e84f..83fd69f4ada 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/0162-Move-bash-completion-script-922997.patch b/0162-Move-bash-completion-script-922997.patch new file mode 100644 index 0000000..6c3c773 --- /dev/null +++ b/0162-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 c7888e40f66..783118ccdcd 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -289,6 +289,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. + # +@@ -498,6 +506,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/0163-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch b/0163-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch deleted file mode 100644 index 942116a..0000000 --- a/0163-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch +++ /dev/null @@ -1,19 +0,0 @@ -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/0163-Update-to-minilzo-2.08.patch b/0163-Update-to-minilzo-2.08.patch new file mode 100644 index 0000000..a71c501 --- /dev/null +++ b/0163-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/0164-Allow-fallback-to-include-entries-by-title-not-just-.patch b/0164-Allow-fallback-to-include-entries-by-title-not-just-.patch new file mode 100644 index 0000000..bee65ed --- /dev/null +++ b/0164-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 e7a83c2d6e2..d2f64b05e0a 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/0164-Make-efi-machines-load-an-env-block-from-a-variable.patch b/0164-Make-efi-machines-load-an-env-block-from-a-variable.patch deleted file mode 100644 index 7e23166..0000000 --- a/0164-Make-efi-machines-load-an-env-block-from-a-variable.patch +++ /dev/null @@ -1,81 +0,0 @@ -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 fc4767f1985..a6e257f946a 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -191,6 +191,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/0165-Add-GRUB_DISABLE_UUID.patch b/0165-Add-GRUB_DISABLE_UUID.patch new file mode 100644 index 0000000..a6856d2 --- /dev/null +++ b/0165-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 2adfa97bee8..2fd32608c01 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 bc5a3f17541..b0a8626dd1c 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/0165-DHCP-client-ID-and-UUID-options-added.patch b/0165-DHCP-client-ID-and-UUID-options-added.patch deleted file mode 100644 index ddc17fe..0000000 --- a/0165-DHCP-client-ID-and-UUID-options-added.patch +++ /dev/null @@ -1,142 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Tue, 27 Nov 2012 17:18:53 -0200 -Subject: [PATCH] DHCP client ID and UUID options added. - ---- - grub-core/net/bootp.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++----- - include/grub/net.h | 2 ++ - 2 files changed, 81 insertions(+), 8 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 9e2fdb795f5..f03eeab2fb4 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -25,6 +25,49 @@ - #include - #include - -+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 void - parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) - { -@@ -55,6 +98,9 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) - - taglength = *ptr++; - -+ grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n", -+ tagtype, tagtype, taglength); -+ - switch (tagtype) - { - case GRUB_NET_BOOTP_NETMASK: -@@ -120,6 +166,39 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) - taglength); - break; - -+ case GRUB_NET_BOOTP_CLIENT_ID: -+ set_env_limn_ro (name, "clientid", (char *) ptr, taglength); -+ break; -+ -+ case GRUB_NET_BOOTP_CLIENT_UUID: -+ { -+ if (taglength != 17) -+ break; -+ -+ /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */ -+ -+ ptr += 1; -+ taglength -= 1; -+ -+ char *val = grub_malloc (2 * taglength + 4 + 1); -+ int i = 0; -+ int j = 0; -+ for (i = 0; i < taglength; i++) -+ { -+ val[2 * i + j] = hexdigit (ptr[i] >> 4); -+ val[2 * i + 1 + j] = hexdigit (ptr[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 * taglength + 4); -+ } -+ break; -+ - /* If you need any other options please contact GRUB - development team. */ - } -@@ -302,14 +381,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 1096b24322e..e266bae23f4 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -457,6 +457,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_BOOTP_END = 0xff - }; - diff --git a/0166-Make-exit-take-a-return-code.patch b/0166-Make-exit-take-a-return-code.patch new file mode 100644 index 0000000..937c774 --- /dev/null +++ b/0166-Make-exit-take-a-return-code.patch @@ -0,0 +1,256 @@ +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 | 2 +- + grub-core/kern/uboot/init.c | 6 +++--- + grub-core/kern/xen/init.c | 2 +- + include/grub/misc.h | 2 +- + 14 files changed, 39 insertions(+), 21 deletions(-) + +diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c +index a3a11824172..b25ca4b9f17 100644 +--- a/grub-core/commands/minicmd.c ++++ b/grub-core/commands/minicmd.c +@@ -176,12 +176,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 708581fcbde..e339f264b3a 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 76661337f10..82012a72fcb 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -137,9 +137,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 0d8ebf58b95..f5423ce27d9 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -68,7 +68,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..952411d5dc6 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1095,7 +1095,7 @@ grub_abort (void) + grub_getkey (); + } + +- grub_exit (); ++ grub_exit (1); + } + + void +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 0559c033c3d..fce526d417b 100644 +--- a/grub-core/kern/xen/init.c ++++ b/grub-core/kern/xen/init.c +@@ -549,7 +549,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 372f009e84f..83fd69f4ada 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/0166-trim-arp-packets-with-abnormal-size.patch b/0166-trim-arp-packets-with-abnormal-size.patch deleted file mode 100644 index 1a6990a..0000000 --- a/0166-trim-arp-packets-with-abnormal-size.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Paulo Flabiano Smorigo -Date: Wed, 5 Feb 2014 09:42:42 -0200 -Subject: [PATCH] trim arp packets with abnormal size - -GRUB uses arp request to create the arp response. If the incoming packet -is foobared, GRUB needs to trim the arp response packet before sending it. ---- - grub-core/net/arp.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c -index 54306e3b16d..d1c69ed2b55 100644 ---- a/grub-core/net/arp.c -+++ b/grub-core/net/arp.c -@@ -150,6 +150,12 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, - if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 - && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) - { -+ if ((nb->tail - nb->data) > 50) -+ { -+ grub_dprintf ("net", "arp packet with abnormal size (%ld bytes).\n", -+ nb->tail - nb->data); -+ nb->tail = nb->data + 50; -+ } - grub_net_link_level_address_t target; - struct grub_net_buff nb_reply; - struct arppkt *arp_reply; diff --git a/0167-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch b/0167-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch deleted file mode 100644 index e219fa5..0000000 --- a/0167-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch +++ /dev/null @@ -1,38 +0,0 @@ -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 61ebd7dc714..87a7da34982 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/0167-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch b/0167-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch new file mode 100644 index 0000000..942116a --- /dev/null +++ b/0167-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/0168-Add-support-for-UEFI-operating-systems-returned-by-o.patch b/0168-Add-support-for-UEFI-operating-systems-returned-by-o.patch deleted file mode 100644 index 6ddda34..0000000 --- a/0168-Add-support-for-UEFI-operating-systems-returned-by-o.patch +++ /dev/null @@ -1,46 +0,0 @@ -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/0168-Make-efi-machines-load-an-env-block-from-a-variable.patch b/0168-Make-efi-machines-load-an-env-block-from-a-variable.patch new file mode 100644 index 0000000..7e23166 --- /dev/null +++ b/0168-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 fc4767f1985..a6e257f946a 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -191,6 +191,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/0169-DHCP-client-ID-and-UUID-options-added.patch b/0169-DHCP-client-ID-and-UUID-options-added.patch new file mode 100644 index 0000000..ddc17fe --- /dev/null +++ b/0169-DHCP-client-ID-and-UUID-options-added.patch @@ -0,0 +1,142 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Tue, 27 Nov 2012 17:18:53 -0200 +Subject: [PATCH] DHCP client ID and UUID options added. + +--- + grub-core/net/bootp.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++----- + include/grub/net.h | 2 ++ + 2 files changed, 81 insertions(+), 8 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 9e2fdb795f5..f03eeab2fb4 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -25,6 +25,49 @@ + #include + #include + ++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 void + parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) + { +@@ -55,6 +98,9 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) + + taglength = *ptr++; + ++ grub_dprintf("net", "DHCP option %u (0x%02x) found with length %u.\n", ++ tagtype, tagtype, taglength); ++ + switch (tagtype) + { + case GRUB_NET_BOOTP_NETMASK: +@@ -120,6 +166,39 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) + taglength); + break; + ++ case GRUB_NET_BOOTP_CLIENT_ID: ++ set_env_limn_ro (name, "clientid", (char *) ptr, taglength); ++ break; ++ ++ case GRUB_NET_BOOTP_CLIENT_UUID: ++ { ++ if (taglength != 17) ++ break; ++ ++ /* The format is 9cfe245e-d0c8-bd45-a79f-54ea5fbd3d97 */ ++ ++ ptr += 1; ++ taglength -= 1; ++ ++ char *val = grub_malloc (2 * taglength + 4 + 1); ++ int i = 0; ++ int j = 0; ++ for (i = 0; i < taglength; i++) ++ { ++ val[2 * i + j] = hexdigit (ptr[i] >> 4); ++ val[2 * i + 1 + j] = hexdigit (ptr[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 * taglength + 4); ++ } ++ break; ++ + /* If you need any other options please contact GRUB + development team. */ + } +@@ -302,14 +381,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 1096b24322e..e266bae23f4 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -457,6 +457,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_BOOTP_END = 0xff + }; + diff --git a/0169-Migrate-PPC-from-Yaboot-to-Grub2.patch b/0169-Migrate-PPC-from-Yaboot-to-Grub2.patch deleted file mode 100644 index 7008926..0000000 --- a/0169-Migrate-PPC-from-Yaboot-to-Grub2.patch +++ /dev/null @@ -1,151 +0,0 @@ -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 3180ac880a9..c7b775bce73 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -487,6 +487,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/0170-Add-fw_path-variable-revised.patch b/0170-Add-fw_path-variable-revised.patch deleted file mode 100644 index 3126d2e..0000000 --- a/0170-Add-fw_path-variable-revised.patch +++ /dev/null @@ -1,78 +0,0 @@ -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 249e19bc788..759c475c4d9 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); -+ 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/0170-trim-arp-packets-with-abnormal-size.patch b/0170-trim-arp-packets-with-abnormal-size.patch new file mode 100644 index 0000000..1a6990a --- /dev/null +++ b/0170-trim-arp-packets-with-abnormal-size.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Paulo Flabiano Smorigo +Date: Wed, 5 Feb 2014 09:42:42 -0200 +Subject: [PATCH] trim arp packets with abnormal size + +GRUB uses arp request to create the arp response. If the incoming packet +is foobared, GRUB needs to trim the arp response packet before sending it. +--- + grub-core/net/arp.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c +index 54306e3b16d..d1c69ed2b55 100644 +--- a/grub-core/net/arp.c ++++ b/grub-core/net/arp.c +@@ -150,6 +150,12 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 + && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) + { ++ if ((nb->tail - nb->data) > 50) ++ { ++ grub_dprintf ("net", "arp packet with abnormal size (%ld bytes).\n", ++ nb->tail - nb->data); ++ nb->tail = nb->data + 50; ++ } + grub_net_link_level_address_t target; + struct grub_net_buff nb_reply; + struct arppkt *arp_reply; diff --git a/0171-Add-support-for-linuxefi.patch b/0171-Add-support-for-linuxefi.patch deleted file mode 100644 index a91df66..0000000 --- a/0171-Add-support-for-linuxefi.patch +++ /dev/null @@ -1,479 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Tue, 10 Jul 2012 11:58:52 -0400 -Subject: [PATCH] Add support for linuxefi - ---- - grub-core/Makefile.core.def | 8 + - grub-core/kern/efi/mm.c | 32 ++++ - grub-core/loader/i386/efi/linux.c | 371 ++++++++++++++++++++++++++++++++++++++ - include/grub/efi/efi.h | 3 + - include/grub/i386/linux.h | 1 + - 5 files changed, 415 insertions(+) - create mode 100644 grub-core/loader/i386/efi/linux.c - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index a6e257f946a..aacad137b36 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1759,6 +1759,14 @@ module = { - enable = x86_64_efi; - }; - -+module = { -+ name = linuxefi; -+ efi = loader/i386/efi/linux.c; -+ efi = lib/cmdline.c; -+ enable = i386_efi; -+ enable = x86_64_efi; -+}; -+ - module = { - name = chain; - efi = loader/efi/chainloader.c; -diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c -index c48e9b5c7c3..775daed16e6 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/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -new file mode 100644 -index 00000000000..b79e6320ba9 ---- /dev/null -+++ b/grub-core/loader/i386/efi/linux.c -@@ -0,0 +1,371 @@ -+/* -+ * 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 -+ -+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) -+ -+#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; -+ -+static 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; -+} -+ -+typedef void(*handover_func)(void *, grub_efi_system_table_t *, struct linux_kernel_params *); -+ -+static grub_err_t -+grub_linuxefi_boot (void) -+{ -+ handover_func hf; -+ int offset = 0; -+ -+#ifdef __x86_64__ -+ offset = 512; -+#endif -+ -+ hf = (handover_func)((char *)kernel_mem + handover_offset + offset); -+ -+ asm volatile ("cli"); -+ -+ hf (grub_efi_image_handle, grub_efi_system_table, params); -+ -+ /* Not reached */ -+ return GRUB_ERR_NONE; -+} -+ -+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)initrd_mem, BYTES_TO_PAGES(params->ramdisk_size)); -+ if (linux_cmdline) -+ grub_efi_free_pages((grub_efi_physical_address_t)linux_cmdline, BYTES_TO_PAGES(params->cmdline_size + 1)); -+ if (kernel_mem) -+ grub_efi_free_pages((grub_efi_physical_address_t)kernel_mem, BYTES_TO_PAGES(kernel_size)); -+ if (params) -+ grub_efi_free_pages((grub_efi_physical_address_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++) -+ { -+ grub_file_filter_disable_compression (); -+ files[i] = grub_file_open (argv[i]); -+ 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_uint64_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)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_kernel_header lh; -+ grub_ssize_t len, start, filelen; -+ void *kernel; -+ -+ 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]); -+ 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]); -+ grub_free (kernel); -+ goto fail; -+ } -+ -+ grub_file_seek (file, 0); -+ -+ grub_free(kernel); -+ -+ 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; -+ } -+ -+ memset (params, 0, 16384); -+ -+ if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) -+ { -+ if (!grub_errno) -+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -+ argv[0]); -+ goto fail; -+ } -+ -+ 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; -+ } -+ -+ 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)); -+ -+ lh.cmd_line_ptr = (grub_uint32_t)(grub_uint64_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(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; -+ } -+ -+ if (grub_file_seek (file, start) == (grub_off_t) -1) -+ { -+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -+ argv[0]); -+ goto fail; -+ } -+ -+ if (grub_file_read (file, kernel_mem, len) != len && !grub_errno) -+ { -+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -+ argv[0]); -+ } -+ -+ if (grub_errno == GRUB_ERR_NONE) -+ { -+ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); -+ loaded = 1; -+ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; -+ } -+ -+ memcpy(params, &lh, 2 * 512); -+ -+ params->type_of_loader = 0x21; -+ -+ fail: -+ -+ if (file) -+ grub_file_close (file); -+ -+ 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)linux_cmdline, BYTES_TO_PAGES(lh.cmdline_size + 1)); -+ -+ if (kernel_mem && !loaded) -+ grub_efi_free_pages((grub_efi_physical_address_t)kernel_mem, BYTES_TO_PAGES(kernel_size)); -+ -+ if (params && !loaded) -+ grub_efi_free_pages((grub_efi_physical_address_t)params, BYTES_TO_PAGES(16384)); -+ -+ return grub_errno; -+} -+ -+static grub_command_t cmd_linux, cmd_initrd; -+ -+GRUB_MOD_INIT(linuxefi) -+{ -+ cmd_linux = -+ grub_register_command ("linuxefi", grub_cmd_linux, -+ 0, N_("Load Linux.")); -+ cmd_initrd = -+ grub_register_command ("initrdefi", grub_cmd_initrd, -+ 0, N_("Load initrd.")); -+ my_mod = mod; -+} -+ -+GRUB_MOD_FINI(linuxefi) -+{ -+ grub_unregister_command (cmd_linux); -+ grub_unregister_command (cmd_initrd); -+} -diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index c996913e5bc..3efbafbb418 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); - int -diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h -index 0bd75881708..5d8282a7db6 100644 ---- a/include/grub/i386/linux.h -+++ b/include/grub/i386/linux.h -@@ -139,6 +139,7 @@ struct linux_i386_kernel_header - grub_uint64_t setup_data; - grub_uint64_t pref_address; - grub_uint32_t init_size; -+ grub_uint32_t handover_offset; - } GRUB_PACKED; - - /* Boot parameters for Linux based on 2.6.12. This is used by the setup diff --git a/0171-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch b/0171-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch new file mode 100644 index 0000000..e219fa5 --- /dev/null +++ b/0171-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 61ebd7dc714..87a7da34982 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/0172-Add-support-for-UEFI-operating-systems-returned-by-o.patch b/0172-Add-support-for-UEFI-operating-systems-returned-by-o.patch new file mode 100644 index 0000000..6ddda34 --- /dev/null +++ b/0172-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/0172-Use-linuxefi-and-initrdefi-where-appropriate.patch b/0172-Use-linuxefi-and-initrdefi-where-appropriate.patch deleted file mode 100644 index 2196911..0000000 --- a/0172-Use-linuxefi-and-initrdefi-where-appropriate.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 16 Jul 2012 18:57:11 -0400 -Subject: [PATCH] Use "linuxefi" and "initrdefi" where appropriate. - ---- - util/grub.d/10_linux.in | 11 +++++++++-- - 1 file changed, 9 insertions(+), 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 87a7da34982..37d539fcf93 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -139,9 +139,16 @@ linux_entry () - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi - message="$(gettext_printf "Loading Linux %s ..." ${version})" -+ if [ -d /sys/firmware/efi ]; then -+ linuxcmd=linuxefi -+ initrdcmd=initrdefi -+ else -+ linuxcmd=linux -+ initrdcmd=initrd -+ fi - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' -- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} -+ ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} - EOF - if test -n "${initrd}" ; then - # TRANSLATORS: ramdisk isn't identifier. Should be translated. -@@ -152,7 +159,7 @@ EOF - done - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' -- initrd $(echo $initrd_path) -+ ${initrdcmd} $(echo $initrd_path) - EOF - fi - sed "s/^/$submenu_indentation/" << EOF diff --git a/0173-Don-t-allow-insmod-when-secure-boot-is-enabled.patch b/0173-Don-t-allow-insmod-when-secure-boot-is-enabled.patch deleted file mode 100644 index 5bd9974..0000000 --- a/0173-Don-t-allow-insmod-when-secure-boot-is-enabled.patch +++ /dev/null @@ -1,121 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Colin Watson -Date: Tue, 23 Oct 2012 10:40:49 -0400 -Subject: [PATCH] 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/kern/dl.c | 22 ++++++++++++++++++++++ - grub-core/kern/efi/efi.c | 28 ++++++++++++++++++++++++++++ - include/grub/efi/efi.h | 1 + - 3 files changed, 51 insertions(+) - -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index e394cd96f8c..621070918d4 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -32,12 +32,21 @@ - #include - #include - #include -+#include - - /* Platforms where modules are in a readonly area of memory. */ - #if defined(GRUB_MACHINE_QEMU) - #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 +695,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); -diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c -index e339f264b3a..92e1583b37d 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -278,6 +278,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/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 3efbafbb418..f68a19de442 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -84,6 +84,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); diff --git a/0173-Migrate-PPC-from-Yaboot-to-Grub2.patch b/0173-Migrate-PPC-from-Yaboot-to-Grub2.patch new file mode 100644 index 0000000..7008926 --- /dev/null +++ b/0173-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 3180ac880a9..c7b775bce73 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -487,6 +487,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/0174-Add-fw_path-variable-revised.patch b/0174-Add-fw_path-variable-revised.patch new file mode 100644 index 0000000..3126d2e --- /dev/null +++ b/0174-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 249e19bc788..759c475c4d9 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); ++ 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/0174-Pass-x-hex-hex-straight-through-unmolested.patch b/0174-Pass-x-hex-hex-straight-through-unmolested.patch deleted file mode 100644 index 5f4884d..0000000 --- a/0174-Pass-x-hex-hex-straight-through-unmolested.patch +++ /dev/null @@ -1,179 +0,0 @@ -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 9b4e72766ff..02c46f9fdfa 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 d5e10ee8798..0a5b2afb94b 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; -@@ -85,7 +97,25 @@ int 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 ab78ca87f90..cf6cd6601d6 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -55,6 +55,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) - { -@@ -71,7 +77,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; - } -@@ -95,7 +109,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; -@@ -397,10 +418,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/0175-Add-X-option-to-printf-functions.patch b/0175-Add-X-option-to-printf-functions.patch deleted file mode 100644 index 4fd28fc..0000000 --- a/0175-Add-X-option-to-printf-functions.patch +++ /dev/null @@ -1,55 +0,0 @@ -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 952411d5dc6..8344526be7f 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/0175-Add-support-for-linuxefi.patch b/0175-Add-support-for-linuxefi.patch new file mode 100644 index 0000000..a91df66 --- /dev/null +++ b/0175-Add-support-for-linuxefi.patch @@ -0,0 +1,479 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Tue, 10 Jul 2012 11:58:52 -0400 +Subject: [PATCH] Add support for linuxefi + +--- + grub-core/Makefile.core.def | 8 + + grub-core/kern/efi/mm.c | 32 ++++ + grub-core/loader/i386/efi/linux.c | 371 ++++++++++++++++++++++++++++++++++++++ + include/grub/efi/efi.h | 3 + + include/grub/i386/linux.h | 1 + + 5 files changed, 415 insertions(+) + create mode 100644 grub-core/loader/i386/efi/linux.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index a6e257f946a..aacad137b36 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1759,6 +1759,14 @@ module = { + enable = x86_64_efi; + }; + ++module = { ++ name = linuxefi; ++ efi = loader/i386/efi/linux.c; ++ efi = lib/cmdline.c; ++ enable = i386_efi; ++ enable = x86_64_efi; ++}; ++ + module = { + name = chain; + efi = loader/efi/chainloader.c; +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index c48e9b5c7c3..775daed16e6 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/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +new file mode 100644 +index 00000000000..b79e6320ba9 +--- /dev/null ++++ b/grub-core/loader/i386/efi/linux.c +@@ -0,0 +1,371 @@ ++/* ++ * 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 ++ ++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) ++ ++#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; ++ ++static 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; ++} ++ ++typedef void(*handover_func)(void *, grub_efi_system_table_t *, struct linux_kernel_params *); ++ ++static grub_err_t ++grub_linuxefi_boot (void) ++{ ++ handover_func hf; ++ int offset = 0; ++ ++#ifdef __x86_64__ ++ offset = 512; ++#endif ++ ++ hf = (handover_func)((char *)kernel_mem + handover_offset + offset); ++ ++ asm volatile ("cli"); ++ ++ hf (grub_efi_image_handle, grub_efi_system_table, params); ++ ++ /* Not reached */ ++ return GRUB_ERR_NONE; ++} ++ ++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)initrd_mem, BYTES_TO_PAGES(params->ramdisk_size)); ++ if (linux_cmdline) ++ grub_efi_free_pages((grub_efi_physical_address_t)linux_cmdline, BYTES_TO_PAGES(params->cmdline_size + 1)); ++ if (kernel_mem) ++ grub_efi_free_pages((grub_efi_physical_address_t)kernel_mem, BYTES_TO_PAGES(kernel_size)); ++ if (params) ++ grub_efi_free_pages((grub_efi_physical_address_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++) ++ { ++ grub_file_filter_disable_compression (); ++ files[i] = grub_file_open (argv[i]); ++ 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_uint64_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)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_kernel_header lh; ++ grub_ssize_t len, start, filelen; ++ void *kernel; ++ ++ 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]); ++ 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]); ++ grub_free (kernel); ++ goto fail; ++ } ++ ++ grub_file_seek (file, 0); ++ ++ grub_free(kernel); ++ ++ 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; ++ } ++ ++ memset (params, 0, 16384); ++ ++ if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) ++ { ++ if (!grub_errno) ++ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), ++ argv[0]); ++ goto fail; ++ } ++ ++ 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; ++ } ++ ++ 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)); ++ ++ lh.cmd_line_ptr = (grub_uint32_t)(grub_uint64_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(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; ++ } ++ ++ if (grub_file_seek (file, start) == (grub_off_t) -1) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), ++ argv[0]); ++ goto fail; ++ } ++ ++ if (grub_file_read (file, kernel_mem, len) != len && !grub_errno) ++ { ++ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), ++ argv[0]); ++ } ++ ++ if (grub_errno == GRUB_ERR_NONE) ++ { ++ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); ++ loaded = 1; ++ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; ++ } ++ ++ memcpy(params, &lh, 2 * 512); ++ ++ params->type_of_loader = 0x21; ++ ++ fail: ++ ++ if (file) ++ grub_file_close (file); ++ ++ 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)linux_cmdline, BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ ++ if (kernel_mem && !loaded) ++ grub_efi_free_pages((grub_efi_physical_address_t)kernel_mem, BYTES_TO_PAGES(kernel_size)); ++ ++ if (params && !loaded) ++ grub_efi_free_pages((grub_efi_physical_address_t)params, BYTES_TO_PAGES(16384)); ++ ++ return grub_errno; ++} ++ ++static grub_command_t cmd_linux, cmd_initrd; ++ ++GRUB_MOD_INIT(linuxefi) ++{ ++ cmd_linux = ++ grub_register_command ("linuxefi", grub_cmd_linux, ++ 0, N_("Load Linux.")); ++ cmd_initrd = ++ grub_register_command ("initrdefi", grub_cmd_initrd, ++ 0, N_("Load initrd.")); ++ my_mod = mod; ++} ++ ++GRUB_MOD_FINI(linuxefi) ++{ ++ grub_unregister_command (cmd_linux); ++ grub_unregister_command (cmd_initrd); ++} +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index c996913e5bc..3efbafbb418 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); + int +diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h +index 0bd75881708..5d8282a7db6 100644 +--- a/include/grub/i386/linux.h ++++ b/include/grub/i386/linux.h +@@ -139,6 +139,7 @@ struct linux_i386_kernel_header + grub_uint64_t setup_data; + grub_uint64_t pref_address; + grub_uint32_t init_size; ++ grub_uint32_t handover_offset; + } GRUB_PACKED; + + /* Boot parameters for Linux based on 2.6.12. This is used by the setup diff --git a/0176-Search-for-specific-config-file-for-netboot.patch b/0176-Search-for-specific-config-file-for-netboot.patch deleted file mode 100644 index 7436e03..0000000 --- a/0176-Search-for-specific-config-file-for-netboot.patch +++ /dev/null @@ -1,200 +0,0 @@ -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 10773fc3435..0769bf850d3 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); -+ -+ 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 759c475c4d9..b2654ef62e8 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 e266bae23f4..50d62ab0c8c 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -566,4 +566,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/0176-Use-linuxefi-and-initrdefi-where-appropriate.patch b/0176-Use-linuxefi-and-initrdefi-where-appropriate.patch new file mode 100644 index 0000000..2196911 --- /dev/null +++ b/0176-Use-linuxefi-and-initrdefi-where-appropriate.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 16 Jul 2012 18:57:11 -0400 +Subject: [PATCH] Use "linuxefi" and "initrdefi" where appropriate. + +--- + util/grub.d/10_linux.in | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 87a7da34982..37d539fcf93 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -139,9 +139,16 @@ linux_entry () + printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" + fi + message="$(gettext_printf "Loading Linux %s ..." ${version})" ++ if [ -d /sys/firmware/efi ]; then ++ linuxcmd=linuxefi ++ initrdcmd=initrdefi ++ else ++ linuxcmd=linux ++ initrdcmd=initrd ++ fi + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' +- linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} ++ ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} + EOF + if test -n "${initrd}" ; then + # TRANSLATORS: ramdisk isn't identifier. Should be translated. +@@ -152,7 +159,7 @@ EOF + done + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' +- initrd $(echo $initrd_path) ++ ${initrdcmd} $(echo $initrd_path) + EOF + fi + sed "s/^/$submenu_indentation/" << EOF diff --git a/0177-Don-t-allow-insmod-when-secure-boot-is-enabled.patch b/0177-Don-t-allow-insmod-when-secure-boot-is-enabled.patch new file mode 100644 index 0000000..5bd9974 --- /dev/null +++ b/0177-Don-t-allow-insmod-when-secure-boot-is-enabled.patch @@ -0,0 +1,121 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Tue, 23 Oct 2012 10:40:49 -0400 +Subject: [PATCH] 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/kern/dl.c | 22 ++++++++++++++++++++++ + grub-core/kern/efi/efi.c | 28 ++++++++++++++++++++++++++++ + include/grub/efi/efi.h | 1 + + 3 files changed, 51 insertions(+) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index e394cd96f8c..621070918d4 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -32,12 +32,21 @@ + #include + #include + #include ++#include + + /* Platforms where modules are in a readonly area of memory. */ + #if defined(GRUB_MACHINE_QEMU) + #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 +695,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); +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index e339f264b3a..92e1583b37d 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -278,6 +278,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/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 3efbafbb418..f68a19de442 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -84,6 +84,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); diff --git a/0177-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch b/0177-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch deleted file mode 100644 index 2e57d44..0000000 --- a/0177-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch +++ /dev/null @@ -1,248 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Tue, 22 Jan 2013 06:31:38 +0100 -Subject: [PATCH] blscfg: add blscfg module to parse Boot Loader Specification - snippets - -http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec - -Works like this: - - insmod blscfg - bls_import - -Done! You should now have menu items for your snippets in place. - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 8 ++ - grub-core/commands/blscfg.c | 201 ++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 209 insertions(+) - create mode 100644 grub-core/commands/blscfg.c - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index aacad137b36..3f42ce16fad 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -768,6 +768,14 @@ module = { - common = commands/blocklist.c; - }; - -+module = { -+ name = blscfg; -+ common = commands/blscfg.c; -+ enable = i386_efi; -+ enable = x86_64_efi; -+ enable = i386_pc; -+}; -+ - module = { - name = boot; - common = commands/boot.c; -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -new file mode 100644 -index 00000000000..4274aca5a9d ---- /dev/null -+++ b/grub-core/commands/blscfg.c -@@ -0,0 +1,201 @@ -+/*-*- 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 -+ -+GRUB_MOD_LICENSE ("GPLv3+"); -+ -+#ifdef GRUB_MACHINE_EFI -+#define GRUB_LINUX_CMD "linuxefi" -+#define GRUB_INITRD_CMD "initrdefi" -+#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/" -+#define GRUB_BOOT_DEVICE "($boot)" -+#else -+#define GRUB_LINUX_CMD "linux" -+#define GRUB_INITRD_CMD "initrd" -+#define GRUB_BLS_CONFIG_PATH "/loader/entries/" -+#define GRUB_BOOT_DEVICE "($root)" -+#endif -+ -+static int parse_entry ( -+ const char *filename, -+ const struct grub_dirhook_info *info __attribute__ ((unused)), -+ void *data __attribute__ ((unused))) -+{ -+ grub_size_t n; -+ char *p; -+ grub_file_t f = NULL; -+ grub_off_t sz; -+ char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL; -+ const char *args[2] = { NULL, NULL }; -+ -+ if (filename[0] == '.') -+ return 0; -+ -+ n = grub_strlen (filename); -+ if (n <= 5) -+ return 0; -+ -+ if (grub_strcmp (filename + n - 5, ".conf") != 0) -+ return 0; -+ -+ p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename); -+ -+ f = grub_file_open (p); -+ if (!f) -+ goto finish; -+ -+ sz = grub_file_size (f); -+ if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) -+ goto finish; -+ -+ for (;;) -+ { -+ char *buf; -+ -+ buf = grub_file_getline (f); -+ if (!buf) -+ break; -+ -+ if (grub_strncmp (buf, "title ", 6) == 0) -+ { -+ grub_free (title); -+ title = grub_strdup (buf + 6); -+ if (!title) -+ goto finish; -+ } -+ else if (grub_strncmp (buf, "options ", 8) == 0) -+ { -+ grub_free (options); -+ options = grub_strdup (buf + 8); -+ if (!options) -+ goto finish; -+ } -+ else if (grub_strncmp (buf, "linux ", 6) == 0) -+ { -+ grub_free (clinux); -+ clinux = grub_strdup (buf + 6); -+ if (!clinux) -+ goto finish; -+ } -+ else if (grub_strncmp (buf, "initrd ", 7) == 0) -+ { -+ grub_free (initrd); -+ initrd = grub_strdup (buf + 7); -+ if (!initrd) -+ goto finish; -+ } -+ -+ grub_free(buf); -+ } -+ -+ if (!linux) -+ { -+ grub_printf ("Skipping file %s with no 'linux' key.", p); -+ goto finish; -+ } -+ -+ args[0] = title ? title : filename; -+ -+ src = grub_xasprintf ("load_video\n" -+ "set gfx_payload=keep\n" -+ "insmod gzio\n" -+ GRUB_LINUX_CMD " %s%s%s%s\n" -+ "%s%s%s%s", -+ GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", -+ initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); -+ -+ grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0); -+ -+finish: -+ grub_free (p); -+ grub_free (title); -+ grub_free (options); -+ grub_free (clinux); -+ grub_free (initrd); -+ grub_free (src); -+ -+ if (f) -+ grub_file_close (f); -+ -+ return 0; -+} -+ -+static grub_err_t -+grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), -+ int argc __attribute__ ((unused)), -+ char **args __attribute__ ((unused))) -+{ -+ grub_fs_t fs; -+ grub_device_t dev; -+ static grub_err_t r; -+ const char *devid; -+ -+ devid = grub_env_get ("root"); -+ if (!devid) -+ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root"); -+ -+ dev = grub_device_open (devid); -+ if (!dev) -+ return grub_errno; -+ -+ fs = grub_fs_probe (dev); -+ if (!fs) -+ { -+ r = grub_errno; -+ goto finish; -+ } -+ -+ r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL); -+ -+finish: -+ if (dev) -+ grub_device_close (dev); -+ -+ return r; -+} -+ -+static grub_extcmd_t cmd; -+ -+GRUB_MOD_INIT(bls) -+{ -+ cmd = grub_register_extcmd ("bls_import", -+ grub_cmd_bls_import, -+ 0, -+ NULL, -+ N_("Import Boot Loader Specification snippets."), -+ NULL); -+} -+ -+GRUB_MOD_FINI(bls) -+{ -+ grub_unregister_extcmd (cmd); -+} diff --git a/0178-Don-t-write-messages-to-the-screen.patch b/0178-Don-t-write-messages-to-the-screen.patch deleted file mode 100644 index 64a5c8d..0000000 --- a/0178-Don-t-write-messages-to-the-screen.patch +++ /dev/null @@ -1,172 +0,0 @@ -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 | 3 --- - 5 files changed, 5 insertions(+), 36 deletions(-) - -diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c -index 4880cefe3f8..b22e1bcc94b 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 37d539fcf93..3c290f65403 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -138,7 +138,6 @@ linux_entry () - fi - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi -- message="$(gettext_printf "Loading Linux %s ..." ${version})" - if [ -d /sys/firmware/efi ]; then - linuxcmd=linuxefi - initrdcmd=initrdefi -@@ -147,7 +146,6 @@ linux_entry () - initrdcmd=initrd - fi - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} - EOF - if test -n "${initrd}" ; then -@@ -158,7 +156,6 @@ EOF - initrd_path="${initrd_path} ${rel_dirname}/${i}" - done - sed "s/^/$submenu_indentation/" << EOF -- echo '$(echo "$message" | grub_quote)' - ${initrdcmd} $(echo $initrd_path) - EOF - fi diff --git a/0178-Pass-x-hex-hex-straight-through-unmolested.patch b/0178-Pass-x-hex-hex-straight-through-unmolested.patch new file mode 100644 index 0000000..5f4884d --- /dev/null +++ b/0178-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 9b4e72766ff..02c46f9fdfa 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 d5e10ee8798..0a5b2afb94b 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; +@@ -85,7 +97,25 @@ int 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 ab78ca87f90..cf6cd6601d6 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -55,6 +55,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) + { +@@ -71,7 +77,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; + } +@@ -95,7 +109,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; +@@ -397,10 +418,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/0179-Add-X-option-to-printf-functions.patch b/0179-Add-X-option-to-printf-functions.patch new file mode 100644 index 0000000..4fd28fc --- /dev/null +++ b/0179-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 952411d5dc6..8344526be7f 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/0179-Don-t-print-GNU-GRUB-header.patch b/0179-Don-t-print-GNU-GRUB-header.patch deleted file mode 100644 index cdcdb13..0000000 --- a/0179-Don-t-print-GNU-GRUB-header.patch +++ /dev/null @@ -1,42 +0,0 @@ -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 b2654ef62e8..f57b7508a76 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -202,15 +202,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) -@@ -235,6 +236,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/0180-Don-t-add-to-highlighted-row.patch b/0180-Don-t-add-to-highlighted-row.patch deleted file mode 100644 index b2d5575..0000000 --- a/0180-Don-t-add-to-highlighted-row.patch +++ /dev/null @@ -1,23 +0,0 @@ -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/0180-Search-for-specific-config-file-for-netboot.patch b/0180-Search-for-specific-config-file-for-netboot.patch new file mode 100644 index 0000000..7436e03 --- /dev/null +++ b/0180-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 10773fc3435..0769bf850d3 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); ++ ++ 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 759c475c4d9..b2654ef62e8 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 e266bae23f4..50d62ab0c8c 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -566,4 +566,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/0181-Message-string-cleanups.patch b/0181-Message-string-cleanups.patch deleted file mode 100644 index 9b6208e..0000000 --- a/0181-Message-string-cleanups.patch +++ /dev/null @@ -1,68 +0,0 @@ -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/0181-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch b/0181-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch new file mode 100644 index 0000000..2e57d44 --- /dev/null +++ b/0181-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch @@ -0,0 +1,248 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Tue, 22 Jan 2013 06:31:38 +0100 +Subject: [PATCH] blscfg: add blscfg module to parse Boot Loader Specification + snippets + +http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec + +Works like this: + + insmod blscfg + bls_import + +Done! You should now have menu items for your snippets in place. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 8 ++ + grub-core/commands/blscfg.c | 201 ++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 209 insertions(+) + create mode 100644 grub-core/commands/blscfg.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index aacad137b36..3f42ce16fad 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -768,6 +768,14 @@ module = { + common = commands/blocklist.c; + }; + ++module = { ++ name = blscfg; ++ common = commands/blscfg.c; ++ enable = i386_efi; ++ enable = x86_64_efi; ++ enable = i386_pc; ++}; ++ + module = { + name = boot; + common = commands/boot.c; +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +new file mode 100644 +index 00000000000..4274aca5a9d +--- /dev/null ++++ b/grub-core/commands/blscfg.c +@@ -0,0 +1,201 @@ ++/*-*- 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 ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++#ifdef GRUB_MACHINE_EFI ++#define GRUB_LINUX_CMD "linuxefi" ++#define GRUB_INITRD_CMD "initrdefi" ++#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/" ++#define GRUB_BOOT_DEVICE "($boot)" ++#else ++#define GRUB_LINUX_CMD "linux" ++#define GRUB_INITRD_CMD "initrd" ++#define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++#define GRUB_BOOT_DEVICE "($root)" ++#endif ++ ++static int parse_entry ( ++ const char *filename, ++ const struct grub_dirhook_info *info __attribute__ ((unused)), ++ void *data __attribute__ ((unused))) ++{ ++ grub_size_t n; ++ char *p; ++ grub_file_t f = NULL; ++ grub_off_t sz; ++ char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL; ++ const char *args[2] = { NULL, NULL }; ++ ++ if (filename[0] == '.') ++ return 0; ++ ++ n = grub_strlen (filename); ++ if (n <= 5) ++ return 0; ++ ++ if (grub_strcmp (filename + n - 5, ".conf") != 0) ++ return 0; ++ ++ p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename); ++ ++ f = grub_file_open (p); ++ if (!f) ++ goto finish; ++ ++ sz = grub_file_size (f); ++ if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) ++ goto finish; ++ ++ for (;;) ++ { ++ char *buf; ++ ++ buf = grub_file_getline (f); ++ if (!buf) ++ break; ++ ++ if (grub_strncmp (buf, "title ", 6) == 0) ++ { ++ grub_free (title); ++ title = grub_strdup (buf + 6); ++ if (!title) ++ goto finish; ++ } ++ else if (grub_strncmp (buf, "options ", 8) == 0) ++ { ++ grub_free (options); ++ options = grub_strdup (buf + 8); ++ if (!options) ++ goto finish; ++ } ++ else if (grub_strncmp (buf, "linux ", 6) == 0) ++ { ++ grub_free (clinux); ++ clinux = grub_strdup (buf + 6); ++ if (!clinux) ++ goto finish; ++ } ++ else if (grub_strncmp (buf, "initrd ", 7) == 0) ++ { ++ grub_free (initrd); ++ initrd = grub_strdup (buf + 7); ++ if (!initrd) ++ goto finish; ++ } ++ ++ grub_free(buf); ++ } ++ ++ if (!linux) ++ { ++ grub_printf ("Skipping file %s with no 'linux' key.", p); ++ goto finish; ++ } ++ ++ args[0] = title ? title : filename; ++ ++ src = grub_xasprintf ("load_video\n" ++ "set gfx_payload=keep\n" ++ "insmod gzio\n" ++ GRUB_LINUX_CMD " %s%s%s%s\n" ++ "%s%s%s%s", ++ GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", ++ initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); ++ ++ grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0); ++ ++finish: ++ grub_free (p); ++ grub_free (title); ++ grub_free (options); ++ grub_free (clinux); ++ grub_free (initrd); ++ grub_free (src); ++ ++ if (f) ++ grub_file_close (f); ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), ++ int argc __attribute__ ((unused)), ++ char **args __attribute__ ((unused))) ++{ ++ grub_fs_t fs; ++ grub_device_t dev; ++ static grub_err_t r; ++ const char *devid; ++ ++ devid = grub_env_get ("root"); ++ if (!devid) ++ return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root"); ++ ++ dev = grub_device_open (devid); ++ if (!dev) ++ return grub_errno; ++ ++ fs = grub_fs_probe (dev); ++ if (!fs) ++ { ++ r = grub_errno; ++ goto finish; ++ } ++ ++ r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL); ++ ++finish: ++ if (dev) ++ grub_device_close (dev); ++ ++ return r; ++} ++ ++static grub_extcmd_t cmd; ++ ++GRUB_MOD_INIT(bls) ++{ ++ cmd = grub_register_extcmd ("bls_import", ++ grub_cmd_bls_import, ++ 0, ++ NULL, ++ N_("Import Boot Loader Specification snippets."), ++ NULL); ++} ++ ++GRUB_MOD_FINI(bls) ++{ ++ grub_unregister_extcmd (cmd); ++} diff --git a/0182-Don-t-write-messages-to-the-screen.patch b/0182-Don-t-write-messages-to-the-screen.patch new file mode 100644 index 0000000..64a5c8d --- /dev/null +++ b/0182-Don-t-write-messages-to-the-screen.patch @@ -0,0 +1,172 @@ +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 | 3 --- + 5 files changed, 5 insertions(+), 36 deletions(-) + +diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c +index 4880cefe3f8..b22e1bcc94b 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 37d539fcf93..3c290f65403 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -138,7 +138,6 @@ linux_entry () + fi + printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" + fi +- message="$(gettext_printf "Loading Linux %s ..." ${version})" + if [ -d /sys/firmware/efi ]; then + linuxcmd=linuxefi + initrdcmd=initrdefi +@@ -147,7 +146,6 @@ linux_entry () + initrdcmd=initrd + fi + sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' + ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} + EOF + if test -n "${initrd}" ; then +@@ -158,7 +156,6 @@ EOF + initrd_path="${initrd_path} ${rel_dirname}/${i}" + done + sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' + ${initrdcmd} $(echo $initrd_path) + EOF + fi diff --git a/0182-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch b/0182-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch deleted file mode 100644 index 504f273..0000000 --- a/0182-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch +++ /dev/null @@ -1,29 +0,0 @@ -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/0183-Don-t-print-GNU-GRUB-header.patch b/0183-Don-t-print-GNU-GRUB-header.patch new file mode 100644 index 0000000..cdcdb13 --- /dev/null +++ b/0183-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 b2654ef62e8..f57b7508a76 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -202,15 +202,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) +@@ -235,6 +236,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/0183-Use-the-correct-indentation-for-the-term-help-text.patch b/0183-Use-the-correct-indentation-for-the-term-help-text.patch deleted file mode 100644 index d2bf366..0000000 --- a/0183-Use-the-correct-indentation-for-the-term-help-text.patch +++ /dev/null @@ -1,25 +0,0 @@ -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 f57b7508a76..0ce59fdc3f0 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -426,8 +426,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/0184-Don-t-add-to-highlighted-row.patch b/0184-Don-t-add-to-highlighted-row.patch new file mode 100644 index 0000000..b2d5575 --- /dev/null +++ b/0184-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/0184-Indent-menu-entries.patch b/0184-Indent-menu-entries.patch deleted file mode 100644 index 7a843ec..0000000 --- a/0184-Indent-menu-entries.patch +++ /dev/null @@ -1,23 +0,0 @@ -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/0185-Fix-margins.patch b/0185-Fix-margins.patch deleted file mode 100644 index 9be1731..0000000 --- a/0185-Fix-margins.patch +++ /dev/null @@ -1,34 +0,0 @@ -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/0185-Message-string-cleanups.patch b/0185-Message-string-cleanups.patch new file mode 100644 index 0000000..9b6208e --- /dev/null +++ b/0185-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/0186-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch b/0186-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch new file mode 100644 index 0000000..504f273 --- /dev/null +++ b/0186-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/0186-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch b/0186-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch deleted file mode 100644 index 3a37839..0000000 --- a/0186-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch +++ /dev/null @@ -1,24 +0,0 @@ -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/0187-Use-linux16-when-appropriate-880840.patch b/0187-Use-linux16-when-appropriate-880840.patch deleted file mode 100644 index 9e810d7..0000000 --- a/0187-Use-linux16-when-appropriate-880840.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 28 Oct 2013 10:05:07 -0400 -Subject: [PATCH] Use linux16 when appropriate (#880840) - -The kernel group really would prefer that we use the 16 bit entry point -on x86 bios machines. - -Resolves: rhbz#880840 - -Signed-off-by: Peter Jones ---- - util/grub.d/10_linux.in | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 3c290f65403..c8376a5189c 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -86,6 +86,11 @@ linux_entry () - type="$3" - args="$4" - -+ sixteenbit="" -+ case "$machine" in -+ i?86|x86_64) sixteenbit="16" ;; -+ esac -+ - if [ -z "$boot_device_id" ]; then - boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" - fi -@@ -142,8 +147,8 @@ linux_entry () - linuxcmd=linuxefi - initrdcmd=initrdefi - else -- linuxcmd=linux -- initrdcmd=initrd -+ linuxcmd=linux${sixteenbit} -+ initrdcmd=initrd${sixteenbit} - fi - sed "s/^/$submenu_indentation/" << EOF - ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} diff --git a/0187-Use-the-correct-indentation-for-the-term-help-text.patch b/0187-Use-the-correct-indentation-for-the-term-help-text.patch new file mode 100644 index 0000000..d2bf366 --- /dev/null +++ b/0187-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 f57b7508a76..0ce59fdc3f0 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -426,8 +426,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/0188-Enable-pager-by-default.-985860.patch b/0188-Enable-pager-by-default.-985860.patch deleted file mode 100644 index d92fbcc..0000000 --- a/0188-Enable-pager-by-default.-985860.patch +++ /dev/null @@ -1,23 +0,0 @@ -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/0188-Indent-menu-entries.patch b/0188-Indent-menu-entries.patch new file mode 100644 index 0000000..7a843ec --- /dev/null +++ b/0188-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/0189-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch b/0189-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch deleted file mode 100644 index 93233bc..0000000 --- a/0189-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch +++ /dev/null @@ -1,24 +0,0 @@ -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/0189-Fix-margins.patch b/0189-Fix-margins.patch new file mode 100644 index 0000000..9be1731 --- /dev/null +++ b/0189-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/0190-Don-t-say-GNU-Linux-in-generated-menus.patch b/0190-Don-t-say-GNU-Linux-in-generated-menus.patch deleted file mode 100644 index d64a0b4..0000000 --- a/0190-Don-t-say-GNU-Linux-in-generated-menus.patch +++ /dev/null @@ -1,42 +0,0 @@ -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 c8376a5189c..11f50d5730b 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 e8143b079dc..972a4b5a03d 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/0190-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch b/0190-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch new file mode 100644 index 0000000..3a37839 --- /dev/null +++ b/0190-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/0191-Don-t-draw-a-border-around-the-menu.patch b/0191-Don-t-draw-a-border-around-the-menu.patch deleted file mode 100644 index e5d11ac..0000000 --- a/0191-Don-t-draw-a-border-around-the-menu.patch +++ /dev/null @@ -1,71 +0,0 @@ -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/0191-Use-linux16-when-appropriate-880840.patch b/0191-Use-linux16-when-appropriate-880840.patch new file mode 100644 index 0000000..9e810d7 --- /dev/null +++ b/0191-Use-linux16-when-appropriate-880840.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 28 Oct 2013 10:05:07 -0400 +Subject: [PATCH] Use linux16 when appropriate (#880840) + +The kernel group really would prefer that we use the 16 bit entry point +on x86 bios machines. + +Resolves: rhbz#880840 + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 3c290f65403..c8376a5189c 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -86,6 +86,11 @@ linux_entry () + type="$3" + args="$4" + ++ sixteenbit="" ++ case "$machine" in ++ i?86|x86_64) sixteenbit="16" ;; ++ esac ++ + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi +@@ -142,8 +147,8 @@ linux_entry () + linuxcmd=linuxefi + initrdcmd=initrdefi + else +- linuxcmd=linux +- initrdcmd=initrd ++ linuxcmd=linux${sixteenbit} ++ initrdcmd=initrd${sixteenbit} + fi + sed "s/^/$submenu_indentation/" << EOF + ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} diff --git a/0192-Enable-pager-by-default.-985860.patch b/0192-Enable-pager-by-default.-985860.patch new file mode 100644 index 0000000..d92fbcc --- /dev/null +++ b/0192-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/0192-Use-the-standard-margin-for-the-timeout-string.patch b/0192-Use-the-standard-margin-for-the-timeout-string.patch deleted file mode 100644 index c6c770c..0000000 --- a/0192-Use-the-standard-margin-for-the-timeout-string.patch +++ /dev/null @@ -1,40 +0,0 @@ -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/0193-Add-.eh_frame-to-list-of-relocations-stripped.patch b/0193-Add-.eh_frame-to-list-of-relocations-stripped.patch deleted file mode 100644 index d837061..0000000 --- a/0193-Add-.eh_frame-to-list-of-relocations-stripped.patch +++ /dev/null @@ -1,22 +0,0 @@ -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 311da61c6c5..044ab3abe88 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/0193-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch b/0193-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch new file mode 100644 index 0000000..93233bc --- /dev/null +++ b/0193-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/0194-Don-t-say-GNU-Linux-in-generated-menus.patch b/0194-Don-t-say-GNU-Linux-in-generated-menus.patch new file mode 100644 index 0000000..d64a0b4 --- /dev/null +++ b/0194-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 c8376a5189c..11f50d5730b 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 e8143b079dc..972a4b5a03d 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/0194-Make-10_linux-work-with-our-changes-for-linux16-and-.patch b/0194-Make-10_linux-work-with-our-changes-for-linux16-and-.patch deleted file mode 100644 index 0d53ead..0000000 --- a/0194-Make-10_linux-work-with-our-changes-for-linux16-and-.patch +++ /dev/null @@ -1,79 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Jan 2014 13:12:23 -0500 -Subject: [PATCH] Make 10_linux work with our changes for linux16 and linuxefi - on aarch64 - -Signed-off-by: Peter Jones ---- - util/grub.d/10_linux.in | 35 ++++++++++++++++++++++++++--------- - 1 file changed, 26 insertions(+), 9 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 11f50d5730b..c889b47db59 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -86,9 +86,18 @@ linux_entry () - type="$3" - args="$4" - -- sixteenbit="" -+ linuxcmd=linux -+ initrdcmd=initrd - case "$machine" in -- i?86|x86_64) sixteenbit="16" ;; -+ i?86|x86_64) -+ if [ -d /sys/firmware/efi ]; then -+ linuxcmd=linuxefi -+ initrdcmd=initrdefi -+ else -+ linuxcmd=linux16 -+ initrdcmd=linux16 -+ fi -+ ;; - esac - - if [ -z "$boot_device_id" ]; then -@@ -143,13 +152,6 @@ linux_entry () - fi - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi -- if [ -d /sys/firmware/efi ]; then -- linuxcmd=linuxefi -- initrdcmd=initrdefi -- else -- linuxcmd=linux${sixteenbit} -- initrdcmd=initrd${sixteenbit} -- fi - sed "s/^/$submenu_indentation/" << EOF - ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} - EOF -@@ -162,6 +164,13 @@ EOF - done - sed "s/^/$submenu_indentation/" << EOF - ${initrdcmd} $(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 -@@ -245,6 +254,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 -e "${dirname}/${i}/foundation-v8.dtb" ; then -+ fdt="${i}/foundation-v8.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/0195-Don-t-draw-a-border-around-the-menu.patch b/0195-Don-t-draw-a-border-around-the-menu.patch new file mode 100644 index 0000000..e5d11ac --- /dev/null +++ b/0195-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/0195-Don-t-print-during-fdt-loading-method.patch b/0195-Don-t-print-during-fdt-loading-method.patch deleted file mode 100644 index cc6572f..0000000 --- a/0195-Don-t-print-during-fdt-loading-method.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Jan 2014 16:15:46 -0500 -Subject: [PATCH] Don't print during fdt loading method. - -Signed-off-by: Peter Jones ---- - util/grub.d/10_linux.in | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index c889b47db59..c0c822c7147 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -167,9 +167,7 @@ EOF - 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/0196-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch b/0196-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch deleted file mode 100644 index 33bdad2..0000000 --- a/0196-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch +++ /dev/null @@ -1,33 +0,0 @@ -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 0a5b2afb94b..970ea868c14 100644 ---- a/grub-core/lib/cmdline.c -+++ b/grub-core/lib/cmdline.c -@@ -97,16 +97,7 @@ int 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/0196-Use-the-standard-margin-for-the-timeout-string.patch b/0196-Use-the-standard-margin-for-the-timeout-string.patch new file mode 100644 index 0000000..c6c770c --- /dev/null +++ b/0196-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/0197-Add-.eh_frame-to-list-of-relocations-stripped.patch b/0197-Add-.eh_frame-to-list-of-relocations-stripped.patch new file mode 100644 index 0000000..d837061 --- /dev/null +++ b/0197-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 311da61c6c5..044ab3abe88 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/0197-Don-t-require-a-password-to-boot-entries-generated-b.patch b/0197-Don-t-require-a-password-to-boot-entries-generated-b.patch deleted file mode 100644 index 194e20c..0000000 --- a/0197-Don-t-require-a-password-to-boot-entries-generated-b.patch +++ /dev/null @@ -1,28 +0,0 @@ -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 c0c822c7147..2e533ffd8aa 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/0198-Don-t-emit-Booting-.-message.patch b/0198-Don-t-emit-Booting-.-message.patch deleted file mode 100644 index 725ae09..0000000 --- a/0198-Don-t-emit-Booting-.-message.patch +++ /dev/null @@ -1,49 +0,0 @@ -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 d2f64b05e0a..5e2f5283d3d 100644 ---- a/grub-core/normal/menu.c -+++ b/grub-core/normal/menu.c -@@ -838,12 +838,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/0198-Make-10_linux-work-with-our-changes-for-linux16-and-.patch b/0198-Make-10_linux-work-with-our-changes-for-linux16-and-.patch new file mode 100644 index 0000000..0d53ead --- /dev/null +++ b/0198-Make-10_linux-work-with-our-changes-for-linux16-and-.patch @@ -0,0 +1,79 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Jan 2014 13:12:23 -0500 +Subject: [PATCH] Make 10_linux work with our changes for linux16 and linuxefi + on aarch64 + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 35 ++++++++++++++++++++++++++--------- + 1 file changed, 26 insertions(+), 9 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 11f50d5730b..c889b47db59 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -86,9 +86,18 @@ linux_entry () + type="$3" + args="$4" + +- sixteenbit="" ++ linuxcmd=linux ++ initrdcmd=initrd + case "$machine" in +- i?86|x86_64) sixteenbit="16" ;; ++ i?86|x86_64) ++ if [ -d /sys/firmware/efi ]; then ++ linuxcmd=linuxefi ++ initrdcmd=initrdefi ++ else ++ linuxcmd=linux16 ++ initrdcmd=linux16 ++ fi ++ ;; + esac + + if [ -z "$boot_device_id" ]; then +@@ -143,13 +152,6 @@ linux_entry () + fi + printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" + fi +- if [ -d /sys/firmware/efi ]; then +- linuxcmd=linuxefi +- initrdcmd=initrdefi +- else +- linuxcmd=linux${sixteenbit} +- initrdcmd=initrd${sixteenbit} +- fi + sed "s/^/$submenu_indentation/" << EOF + ${linuxcmd} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} + EOF +@@ -162,6 +164,13 @@ EOF + done + sed "s/^/$submenu_indentation/" << EOF + ${initrdcmd} $(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 +@@ -245,6 +254,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 -e "${dirname}/${i}/foundation-v8.dtb" ; then ++ fdt="${i}/foundation-v8.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/0199-Don-t-print-during-fdt-loading-method.patch b/0199-Don-t-print-during-fdt-loading-method.patch new file mode 100644 index 0000000..cc6572f --- /dev/null +++ b/0199-Don-t-print-during-fdt-loading-method.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Jan 2014 16:15:46 -0500 +Subject: [PATCH] Don't print during fdt loading method. + +Signed-off-by: Peter Jones +--- + util/grub.d/10_linux.in | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index c889b47db59..c0c822c7147 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -167,9 +167,7 @@ EOF + 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/0199-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch b/0199-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch deleted file mode 100644 index d6169aa..0000000 --- a/0199-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch +++ /dev/null @@ -1,1960 +0,0 @@ -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 783118ccdcd..d5db2803ec4 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -70,6 +70,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 b16bd925320..39eb94bded6 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 da67965a41a..bf8439fa743 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -802,10 +802,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/0200-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch b/0200-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch new file mode 100644 index 0000000..33bdad2 --- /dev/null +++ b/0200-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 0a5b2afb94b..970ea868c14 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -97,16 +97,7 @@ int 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/0200-use-fw_path-prefix-when-fallback-searching-for-grub-.patch b/0200-use-fw_path-prefix-when-fallback-searching-for-grub-.patch deleted file mode 100644 index 0035e62..0000000 --- a/0200-use-fw_path-prefix-when-fallback-searching-for-grub-.patch +++ /dev/null @@ -1,41 +0,0 @@ -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 0ce59fdc3f0..a3713efcd90 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -343,7 +343,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); -@@ -366,7 +366,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/0201-Don-t-require-a-password-to-boot-entries-generated-b.patch b/0201-Don-t-require-a-password-to-boot-entries-generated-b.patch new file mode 100644 index 0000000..194e20c --- /dev/null +++ b/0201-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 c0c822c7147..2e533ffd8aa 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/0201-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch b/0201-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch deleted file mode 100644 index 84b8d7a..0000000 --- a/0201-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch +++ /dev/null @@ -1,111 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 6 Mar 2014 11:51:33 -0500 -Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files. - -Signed-off-by: Peter Jones ---- - grub-core/normal/main.c | 80 ++++++++++++++++++++++++++----------------------- - 1 file changed, 43 insertions(+), 37 deletions(-) - -diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c -index a3713efcd90..7d9c4f09b9b 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -341,53 +341,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); -- 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 (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; -+ if (! config) -+ goto quit; - -- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); -+ 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_net_search_configfile (config); - -- grub_enter_normal_mode (config); -- grub_free (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); -+ 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/0202-Don-t-emit-Booting-.-message.patch b/0202-Don-t-emit-Booting-.-message.patch new file mode 100644 index 0000000..725ae09 --- /dev/null +++ b/0202-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 d2f64b05e0a..5e2f5283d3d 100644 +--- a/grub-core/normal/menu.c ++++ b/grub-core/normal/menu.c +@@ -838,12 +838,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/0202-Fix-convert-function-to-support-NVMe-devices.patch b/0202-Fix-convert-function-to-support-NVMe-devices.patch deleted file mode 100644 index 0fb6616..0000000 --- a/0202-Fix-convert-function-to-support-NVMe-devices.patch +++ /dev/null @@ -1,56 +0,0 @@ -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/0203-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch b/0203-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch new file mode 100644 index 0000000..d6169aa --- /dev/null +++ b/0203-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 783118ccdcd..d5db2803ec4 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -70,6 +70,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 b16bd925320..39eb94bded6 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 da67965a41a..bf8439fa743 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -802,10 +802,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/0203-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch b/0203-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch deleted file mode 100644 index 5063449..0000000 --- a/0203-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Mon, 10 Feb 2014 16:13:10 -0500 -Subject: [PATCH] Switch to use APM Mustang device tree, for hardware testing. - -Signed-off-by: David A. Marlin ---- - 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 2e533ffd8aa..4e9a6308b3c 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -254,8 +254,8 @@ while [ "x$list" != "x" ] ; do - - fdt= - for i in "dtb-${version}" "dtb-${alt_version}"; do -- if test -e "${dirname}/${i}/foundation-v8.dtb" ; then -- fdt="${i}/foundation-v8.dtb" -+ if test -e "${dirname}/${i}/apm-mustang.dtb" ; then -+ fdt="${i}/apm-mustang.dtb" - break - fi - done diff --git a/0204-Use-the-default-device-tree-from-the-grub-default-fi.patch b/0204-Use-the-default-device-tree-from-the-grub-default-fi.patch deleted file mode 100644 index 9b14a54..0000000 --- a/0204-Use-the-default-device-tree-from-the-grub-default-fi.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Wed, 12 Feb 2014 14:54:04 -0500 -Subject: [PATCH] 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 | 4 ++-- - 2 files changed, 4 insertions(+), 3 deletions(-) - -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index b0a8626dd1c..f68d4925ee6 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 4e9a6308b3c..c548d989b2e 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -254,8 +254,8 @@ while [ "x$list" != "x" ] ; do - - fdt= - for i in "dtb-${version}" "dtb-${alt_version}"; do -- if test -e "${dirname}/${i}/apm-mustang.dtb" ; then -- fdt="${i}/apm-mustang.dtb" -+ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then -+ fdt="${i}/${GRUB_DEFAULT_DTB}" - break - fi - done diff --git a/0204-use-fw_path-prefix-when-fallback-searching-for-grub-.patch b/0204-use-fw_path-prefix-when-fallback-searching-for-grub-.patch new file mode 100644 index 0000000..0035e62 --- /dev/null +++ b/0204-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 0ce59fdc3f0..a3713efcd90 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -343,7 +343,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); +@@ -366,7 +366,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/0205-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch b/0205-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch new file mode 100644 index 0000000..84b8d7a --- /dev/null +++ b/0205-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch @@ -0,0 +1,111 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 6 Mar 2014 11:51:33 -0500 +Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files. + +Signed-off-by: Peter Jones +--- + grub-core/normal/main.c | 80 ++++++++++++++++++++++++++----------------------- + 1 file changed, 43 insertions(+), 37 deletions(-) + +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c +index a3713efcd90..7d9c4f09b9b 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -341,53 +341,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); +- 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 (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; ++ if (! config) ++ goto quit; + +- grub_snprintf (config, config_len, "%s/grub.cfg", prefix); ++ 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_net_search_configfile (config); + +- grub_enter_normal_mode (config); +- grub_free (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); ++ 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/0205-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0205-reopen-SNP-protocol-for-exclusive-use-by-grub.patch deleted file mode 100644 index fb2875b..0000000 --- a/0205-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Fedora Ninjas -Date: Sat, 15 Feb 2014 15:10:22 -0500 -Subject: [PATCH] reopen SNP protocol for exclusive use by grub - ---- - grub-core/net/drivers/efi/efinet.c | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 5388f952ba9..ea0e0ca360e 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -330,6 +330,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - { - struct grub_net_card *card; - grub_efi_device_path_t *dp; -+ grub_efi_simple_network_t *net; - - dp = grub_efi_get_device_path (hnd); - if (! dp) -@@ -383,6 +384,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - &pxe_mode->dhcp_ack, - sizeof (pxe_mode->dhcp_ack), - 1, device, path); -+ net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, -+ GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); -+ if (net) { -+ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED -+ && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) -+ continue; -+ -+ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) -+ continue; -+ -+ if (net->mode->state == GRUB_EFI_NETWORK_STARTED -+ && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) -+ continue; -+ card->efi_net = net; -+ } - return; - } - } diff --git a/0206-Fix-convert-function-to-support-NVMe-devices.patch b/0206-Fix-convert-function-to-support-NVMe-devices.patch new file mode 100644 index 0000000..0fb6616 --- /dev/null +++ b/0206-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/0206-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0206-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch deleted file mode 100644 index 4238b7d..0000000 --- a/0206-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 4 Mar 2016 15:13:59 -0500 -Subject: [PATCH] Revert "reopen SNP protocol for exclusive use by grub" - -This reverts commit a3f2c756ce34c9666bddef35e3b3b85ccecdcffc , which is -obsoleted by these: - -49426e9 efinet: open Simple Network Protocol exclusively -f348aee efinet: enable hardware filters when opening interface -c52ae40 efinet: skip virtual IPv4 and IPv6 devices when enumerating cards - -Signed-off-by: Peter Jones ---- - grub-core/net/drivers/efi/efinet.c | 16 ---------------- - 1 file changed, 16 deletions(-) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index ea0e0ca360e..5388f952ba9 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -330,7 +330,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - { - struct grub_net_card *card; - grub_efi_device_path_t *dp; -- grub_efi_simple_network_t *net; - - dp = grub_efi_get_device_path (hnd); - if (! dp) -@@ -384,21 +383,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - &pxe_mode->dhcp_ack, - sizeof (pxe_mode->dhcp_ack), - 1, device, path); -- net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, -- GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); -- if (net) { -- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED -- && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) -- continue; -- -- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) -- continue; -- -- if (net->mode->state == GRUB_EFI_NETWORK_STARTED -- && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) -- continue; -- card->efi_net = net; -- } - return; - } - } diff --git a/0207-Add-grub_util_readlink.patch b/0207-Add-grub_util_readlink.patch deleted file mode 100644 index 6ea7df1..0000000 --- a/0207-Add-grub_util_readlink.patch +++ /dev/null @@ -1,3731 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 3 Sep 2014 10:01:03 -0400 -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/gnulib/gettimeofday.c | 154 +++++++ - grub-core/gnulib/readlink.c | 74 ++++ - grub-core/gnulib/stat.c | 138 +++++++ - grub-core/osdep/windows/hostdisk.c | 6 + - grub-core/gnulib/pathmax.h | 83 ++++ - grub-core/gnulib/sys_stat.in.h | 732 ++++++++++++++++++++++++++++++++++ - grub-core/gnulib/sys_time.in.h | 213 ++++++++++ - grub-core/gnulib/sys_types.in.h | 2 + - grub-core/gnulib/time.h | 586 +++++++++++++++++++++++++++ - grub-core/gnulib/time.in.h | 274 +++++++++++++ - include/grub/osdep/hostfile_aros.h | 6 + - include/grub/osdep/hostfile_unix.h | 6 + - include/grub/osdep/hostfile_windows.h | 2 + - grub-core/gnulib/Makefile.am | 177 +++++++- - m4/gettimeofday.m4 | 138 +++++++ - m4/gnulib-cache.m4 | 3 +- - m4/gnulib-comp.m4 | 49 +++ - m4/largefile.m4 | 146 +++++++ - m4/pathmax.m4 | 42 ++ - m4/readlink.m4 | 71 ++++ - m4/stat.m4 | 71 ++++ - m4/sys_stat_h.m4 | 96 +++++ - m4/sys_time_h.m4 | 110 +++++ - m4/time_h.m4 | 118 ++++++ - 24 files changed, 3295 insertions(+), 2 deletions(-) - create mode 100644 grub-core/gnulib/gettimeofday.c - create mode 100644 grub-core/gnulib/readlink.c - create mode 100644 grub-core/gnulib/stat.c - create mode 100644 grub-core/gnulib/pathmax.h - create mode 100644 grub-core/gnulib/sys_stat.in.h - create mode 100644 grub-core/gnulib/sys_time.in.h - create mode 100644 grub-core/gnulib/time.h - create mode 100644 grub-core/gnulib/time.in.h - create mode 100644 m4/gettimeofday.m4 - create mode 100644 m4/largefile.m4 - create mode 100644 m4/pathmax.m4 - create mode 100644 m4/readlink.m4 - create mode 100644 m4/stat.m4 - create mode 100644 m4/sys_stat_h.m4 - create mode 100644 m4/sys_time_h.m4 - create mode 100644 m4/time_h.m4 - -diff --git a/grub-core/gnulib/gettimeofday.c b/grub-core/gnulib/gettimeofday.c -new file mode 100644 -index 00000000000..8b2058e8c87 ---- /dev/null -+++ b/grub-core/gnulib/gettimeofday.c -@@ -0,0 +1,154 @@ -+/* Provide gettimeofday for systems that don't have it or for which it's broken. -+ -+ Copyright (C) 2001-2003, 2005-2007, 2009-2014 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, 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 . */ -+ -+/* written by Jim Meyering */ -+ -+#include -+ -+/* Specification. */ -+#include -+ -+#include -+ -+#if HAVE_SYS_TIMEB_H -+# include -+#endif -+ -+#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME -+ -+/* Work around the bug in some systems whereby gettimeofday clobbers -+ the static buffer that localtime uses for its return value. The -+ gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has -+ this problem. The tzset replacement is necessary for at least -+ Solaris 2.5, 2.5.1, and 2.6. */ -+ -+static struct tm tm_zero_buffer; -+static struct tm *localtime_buffer_addr = &tm_zero_buffer; -+ -+# undef localtime -+extern struct tm *localtime (time_t const *); -+ -+# undef gmtime -+extern struct tm *gmtime (time_t const *); -+ -+/* This is a wrapper for localtime. It is used only on systems for which -+ gettimeofday clobbers the static buffer used for localtime's result. -+ -+ On the first call, record the address of the static buffer that -+ localtime uses for its result. */ -+ -+struct tm * -+rpl_localtime (time_t const *timep) -+{ -+ struct tm *tm = localtime (timep); -+ -+ if (localtime_buffer_addr == &tm_zero_buffer) -+ localtime_buffer_addr = tm; -+ -+ return tm; -+} -+ -+/* Same as above, since gmtime and localtime use the same buffer. */ -+struct tm * -+rpl_gmtime (time_t const *timep) -+{ -+ struct tm *tm = gmtime (timep); -+ -+ if (localtime_buffer_addr == &tm_zero_buffer) -+ localtime_buffer_addr = tm; -+ -+ return tm; -+} -+ -+#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */ -+ -+#if TZSET_CLOBBERS_LOCALTIME -+ -+# undef tzset -+extern void tzset (void); -+ -+/* This is a wrapper for tzset, for systems on which tzset may clobber -+ the static buffer used for localtime's result. */ -+void -+rpl_tzset (void) -+{ -+ /* Save and restore the contents of the buffer used for localtime's -+ result around the call to tzset. */ -+ struct tm save = *localtime_buffer_addr; -+ tzset (); -+ *localtime_buffer_addr = save; -+} -+#endif -+ -+/* This is a wrapper for gettimeofday. It is used only on systems -+ that lack this function, or whose implementation of this function -+ causes problems. */ -+ -+int -+gettimeofday (struct timeval *restrict tv, void *restrict tz) -+{ -+#undef gettimeofday -+#if HAVE_GETTIMEOFDAY -+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME -+ /* Save and restore the contents of the buffer used for localtime's -+ result around the call to gettimeofday. */ -+ struct tm save = *localtime_buffer_addr; -+# endif -+ -+# if defined timeval /* 'struct timeval' overridden by gnulib? */ -+# undef timeval -+ struct timeval otv; -+ int result = gettimeofday (&otv, (struct timezone *) tz); -+ if (result == 0) -+ { -+ tv->tv_sec = otv.tv_sec; -+ tv->tv_usec = otv.tv_usec; -+ } -+# else -+ int result = gettimeofday (tv, (struct timezone *) tz); -+# endif -+ -+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME -+ *localtime_buffer_addr = save; -+# endif -+ -+ return result; -+ -+#else -+ -+# if HAVE__FTIME -+ -+ struct _timeb timebuf; -+ _ftime (&timebuf); -+ tv->tv_sec = timebuf.time; -+ tv->tv_usec = timebuf.millitm * 1000; -+ -+# else -+ -+# if !defined OK_TO_USE_1S_CLOCK -+# error "Only 1-second nominal clock resolution found. Is that intended?" \ -+ "If so, compile with the -DOK_TO_USE_1S_CLOCK option." -+# endif -+ tv->tv_sec = time (NULL); -+ tv->tv_usec = 0; -+ -+# endif -+ -+ return 0; -+ -+#endif -+} -diff --git a/grub-core/gnulib/readlink.c b/grub-core/gnulib/readlink.c -new file mode 100644 -index 00000000000..4c496395176 ---- /dev/null -+++ b/grub-core/gnulib/readlink.c -@@ -0,0 +1,74 @@ -+/* Stub for readlink(). -+ Copyright (C) 2003-2007, 2009-2014 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 . */ -+ -+#include -+ -+/* Specification. */ -+#include -+ -+#include -+#include -+#include -+ -+#if !HAVE_READLINK -+ -+/* readlink() substitute for systems that don't have a readlink() function, -+ such as DJGPP 2.03 and mingw32. */ -+ -+ssize_t -+readlink (const char *name, char *buf _GL_UNUSED, -+ size_t bufsize _GL_UNUSED) -+{ -+ struct stat statbuf; -+ -+ /* In general we should use lstat() here, not stat(). But on platforms -+ without symbolic links, lstat() - if it exists - would be equivalent to -+ stat(), therefore we can use stat(). This saves us a configure check. */ -+ if (stat (name, &statbuf) >= 0) -+ errno = EINVAL; -+ return -1; -+} -+ -+#else /* HAVE_READLINK */ -+ -+# undef readlink -+ -+/* readlink() wrapper that uses correct types, for systems like cygwin -+ 1.5.x where readlink returns int, and which rejects trailing slash, -+ for Solaris 9. */ -+ -+ssize_t -+rpl_readlink (const char *name, char *buf, size_t bufsize) -+{ -+# if READLINK_TRAILING_SLASH_BUG -+ size_t len = strlen (name); -+ if (len && name[len - 1] == '/') -+ { -+ /* Even if name without the slash is a symlink to a directory, -+ both lstat() and stat() must resolve the trailing slash to -+ the directory rather than the symlink. We can therefore -+ safely use stat() to distinguish between EINVAL and -+ ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ -+ struct stat st; -+ if (stat (name, &st) == 0) -+ errno = EINVAL; -+ return -1; -+ } -+# endif /* READLINK_TRAILING_SLASH_BUG */ -+ return readlink (name, buf, bufsize); -+} -+ -+#endif /* HAVE_READLINK */ -diff --git a/grub-core/gnulib/stat.c b/grub-core/gnulib/stat.c -new file mode 100644 -index 00000000000..35f4b0b1a51 ---- /dev/null -+++ b/grub-core/gnulib/stat.c -@@ -0,0 +1,138 @@ -+/* Work around platform bugs in stat. -+ Copyright (C) 2009-2014 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 . */ -+ -+/* written by Eric Blake */ -+ -+/* If the user's config.h happens to include , let it include only -+ the system's here, so that orig_stat doesn't recurse to -+ rpl_stat. */ -+#define __need_system_sys_stat_h -+#include -+ -+/* Get the original definition of stat. It might be defined as a macro. */ -+#include -+#include -+#undef __need_system_sys_stat_h -+ -+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -+# if _GL_WINDOWS_64_BIT_ST_SIZE -+# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ -+# define stat _stati64 -+# define REPLACE_FUNC_STAT_DIR 1 -+# undef REPLACE_FUNC_STAT_FILE -+# elif REPLACE_FUNC_STAT_FILE -+/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a. -+ Bypass it. */ -+# define stat _stat -+# define REPLACE_FUNC_STAT_DIR 1 -+# undef REPLACE_FUNC_STAT_FILE -+# endif -+#endif -+ -+static int -+orig_stat (const char *filename, struct stat *buf) -+{ -+ return stat (filename, buf); -+} -+ -+/* Specification. */ -+/* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc -+ eliminates this include because of the preliminary #include -+ above. */ -+#include "sys/stat.h" -+ -+#include -+#include -+#include -+#include -+#include "dosname.h" -+#include "verify.h" -+ -+#if REPLACE_FUNC_STAT_DIR -+# include "pathmax.h" -+ /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also -+ have a constant PATH_MAX. */ -+# ifndef PATH_MAX -+# error "Please port this replacement to your platform" -+# endif -+#endif -+ -+/* Store information about NAME into ST. Work around bugs with -+ trailing slashes. Mingw has other bugs (such as st_ino always -+ being 0 on success) which this wrapper does not work around. But -+ at least this implementation provides the ability to emulate fchdir -+ correctly. */ -+ -+int -+rpl_stat (char const *name, struct stat *st) -+{ -+ int result = orig_stat (name, st); -+#if REPLACE_FUNC_STAT_FILE -+ /* Solaris 9 mistakenly succeeds when given a non-directory with a -+ trailing slash. */ -+ if (result == 0 && !S_ISDIR (st->st_mode)) -+ { -+ size_t len = strlen (name); -+ if (ISSLASH (name[len - 1])) -+ { -+ errno = ENOTDIR; -+ return -1; -+ } -+ } -+#endif /* REPLACE_FUNC_STAT_FILE */ -+#if REPLACE_FUNC_STAT_DIR -+ -+ if (result == -1 && errno == ENOENT) -+ { -+ /* Due to mingw's oddities, there are some directories (like -+ c:\) where stat() only succeeds with a trailing slash, and -+ other directories (like c:\windows) where stat() only -+ succeeds without a trailing slash. But we want the two to be -+ synonymous, since chdir() manages either style. Likewise, Mingw also -+ reports ENOENT for names longer than PATH_MAX, when we want -+ ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR. -+ Fortunately, mingw PATH_MAX is small enough for stack -+ allocation. */ -+ char fixed_name[PATH_MAX + 1] = {0}; -+ size_t len = strlen (name); -+ bool check_dir = false; -+ verify (PATH_MAX <= 4096); -+ if (PATH_MAX <= len) -+ errno = ENAMETOOLONG; -+ else if (len) -+ { -+ strcpy (fixed_name, name); -+ if (ISSLASH (fixed_name[len - 1])) -+ { -+ check_dir = true; -+ while (len && ISSLASH (fixed_name[len - 1])) -+ fixed_name[--len] = '\0'; -+ if (!len) -+ fixed_name[0] = '/'; -+ } -+ else -+ fixed_name[len++] = '/'; -+ result = orig_stat (fixed_name, st); -+ if (result == 0 && check_dir && !S_ISDIR (st->st_mode)) -+ { -+ result = -1; -+ errno = ENOTDIR; -+ } -+ } -+ } -+#endif /* REPLACE_FUNC_STAT_DIR */ -+ return result; -+} -diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c -index 85507af88e3..6f49df465d7 100644 ---- a/grub-core/osdep/windows/hostdisk.c -+++ b/grub-core/osdep/windows/hostdisk.c -@@ -353,6 +353,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/grub-core/gnulib/pathmax.h b/grub-core/gnulib/pathmax.h -new file mode 100644 -index 00000000000..33fc3553d75 ---- /dev/null -+++ b/grub-core/gnulib/pathmax.h -@@ -0,0 +1,83 @@ -+/* Define PATH_MAX somehow. Requires sys/types.h. -+ Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 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, 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 . */ -+ -+#ifndef _PATHMAX_H -+# define _PATHMAX_H -+ -+/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename, -+ including the terminating NUL byte. -+ -+ PATH_MAX is not defined on systems which have no limit on filename length, -+ such as GNU/Hurd. -+ -+ This file does *not* define PATH_MAX always. Programs that use this file -+ can handle the GNU/Hurd case in several ways: -+ - Either with a package-wide handling, or with a per-file handling, -+ - Either through a -+ #ifdef PATH_MAX -+ or through a fallback like -+ #ifndef PATH_MAX -+ # define PATH_MAX 8192 -+ #endif -+ or through a fallback like -+ #ifndef PATH_MAX -+ # define PATH_MAX pathconf ("/", _PC_PATH_MAX) -+ #endif -+ */ -+ -+# include -+ -+# include -+ -+# ifndef _POSIX_PATH_MAX -+# define _POSIX_PATH_MAX 256 -+# endif -+ -+/* Don't include sys/param.h if it already has been. */ -+# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN -+# include -+# endif -+ -+# if !defined PATH_MAX && defined MAXPATHLEN -+# define PATH_MAX MAXPATHLEN -+# endif -+ -+# ifdef __hpux -+/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename, -+ *not* including the terminating NUL byte, and is set to 1023. -+ Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is -+ not defined at all any more. */ -+# undef PATH_MAX -+# define PATH_MAX 1024 -+# endif -+ -+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -+/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com, -+ section "Maximum Path Length Limitation", -+ -+ explains that the maximum size of a filename, including the terminating -+ NUL byte, is 260 = 3 + 256 + 1. -+ This is the same value as -+ - FILENAME_MAX in , -+ - _MAX_PATH in , -+ - MAX_PATH in . -+ Undefine the original value, because mingw's gets it wrong. */ -+# undef PATH_MAX -+# define PATH_MAX 260 -+# endif -+ -+#endif /* _PATHMAX_H */ -diff --git a/grub-core/gnulib/sys_stat.in.h b/grub-core/gnulib/sys_stat.in.h -new file mode 100644 -index 00000000000..b47a7ff0ae7 ---- /dev/null -+++ b/grub-core/gnulib/sys_stat.in.h -@@ -0,0 +1,732 @@ -+/* Provide a more complete sys/stat header file. -+ Copyright (C) 2005-2014 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, 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 . */ -+ -+/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */ -+ -+/* This file is supposed to be used on platforms where is -+ incomplete. It is intended to provide definitions and prototypes -+ needed by an application. Start with what the system provides. */ -+ -+#if __GNUC__ >= 3 -+@PRAGMA_SYSTEM_HEADER@ -+#endif -+@PRAGMA_COLUMNS@ -+ -+#if defined __need_system_sys_stat_h -+/* Special invocation convention. */ -+ -+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@ -+ -+#else -+/* Normal invocation convention. */ -+ -+#ifndef _@GUARD_PREFIX@_SYS_STAT_H -+ -+/* Get nlink_t. -+ May also define off_t to a 64-bit type on native Windows. */ -+#include -+ -+/* Get struct timespec. */ -+#include -+ -+/* The include_next requires a split double-inclusion guard. */ -+#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@ -+ -+#ifndef _@GUARD_PREFIX@_SYS_STAT_H -+#define _@GUARD_PREFIX@_SYS_STAT_H -+ -+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ -+ -+/* The definition of _GL_ARG_NONNULL is copied here. */ -+ -+/* The definition of _GL_WARN_ON_USE is copied here. */ -+ -+/* Before doing "#define mkdir rpl_mkdir" below, we need to include all -+ headers that may declare mkdir(). Native Windows platforms declare mkdir -+ in and/or , not in . */ -+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -+# include /* mingw32, mingw64 */ -+# include /* mingw64, MSVC 9 */ -+#endif -+ -+/* Native Windows platforms declare umask() in . */ -+#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) -+# include -+#endif -+ -+/* Large File Support on native Windows. */ -+#if @WINDOWS_64_BIT_ST_SIZE@ -+# define stat _stati64 -+#endif -+ -+#ifndef S_IFIFO -+# ifdef _S_IFIFO -+# define S_IFIFO _S_IFIFO -+# endif -+#endif -+ -+#ifndef S_IFMT -+# define S_IFMT 0170000 -+#endif -+ -+#if STAT_MACROS_BROKEN -+# undef S_ISBLK -+# undef S_ISCHR -+# undef S_ISDIR -+# undef S_ISFIFO -+# undef S_ISLNK -+# undef S_ISNAM -+# undef S_ISMPB -+# undef S_ISMPC -+# undef S_ISNWK -+# undef S_ISREG -+# undef S_ISSOCK -+#endif -+ -+#ifndef S_ISBLK -+# ifdef S_IFBLK -+# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -+# else -+# define S_ISBLK(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISCHR -+# ifdef S_IFCHR -+# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -+# else -+# define S_ISCHR(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISDIR -+# ifdef S_IFDIR -+# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -+# else -+# define S_ISDIR(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISDOOR /* Solaris 2.5 and up */ -+# define S_ISDOOR(m) 0 -+#endif -+ -+#ifndef S_ISFIFO -+# ifdef S_IFIFO -+# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -+# else -+# define S_ISFIFO(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISLNK -+# ifdef S_IFLNK -+# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -+# else -+# define S_ISLNK(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISMPB /* V7 */ -+# ifdef S_IFMPB -+# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) -+# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) -+# else -+# define S_ISMPB(m) 0 -+# define S_ISMPC(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISMPX /* AIX */ -+# define S_ISMPX(m) 0 -+#endif -+ -+#ifndef S_ISNAM /* Xenix */ -+# ifdef S_IFNAM -+# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM) -+# else -+# define S_ISNAM(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISNWK /* HP/UX */ -+# ifdef S_IFNWK -+# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) -+# else -+# define S_ISNWK(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISPORT /* Solaris 10 and up */ -+# define S_ISPORT(m) 0 -+#endif -+ -+#ifndef S_ISREG -+# ifdef S_IFREG -+# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -+# else -+# define S_ISREG(m) 0 -+# endif -+#endif -+ -+#ifndef S_ISSOCK -+# ifdef S_IFSOCK -+# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -+# else -+# define S_ISSOCK(m) 0 -+# endif -+#endif -+ -+ -+#ifndef S_TYPEISMQ -+# define S_TYPEISMQ(p) 0 -+#endif -+ -+#ifndef S_TYPEISTMO -+# define S_TYPEISTMO(p) 0 -+#endif -+ -+ -+#ifndef S_TYPEISSEM -+# ifdef S_INSEM -+# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM) -+# else -+# define S_TYPEISSEM(p) 0 -+# endif -+#endif -+ -+#ifndef S_TYPEISSHM -+# ifdef S_INSHD -+# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD) -+# else -+# define S_TYPEISSHM(p) 0 -+# endif -+#endif -+ -+/* high performance ("contiguous data") */ -+#ifndef S_ISCTG -+# define S_ISCTG(p) 0 -+#endif -+ -+/* Cray DMF (data migration facility): off line, with data */ -+#ifndef S_ISOFD -+# define S_ISOFD(p) 0 -+#endif -+ -+/* Cray DMF (data migration facility): off line, with no data */ -+#ifndef S_ISOFL -+# define S_ISOFL(p) 0 -+#endif -+ -+/* 4.4BSD whiteout */ -+#ifndef S_ISWHT -+# define S_ISWHT(m) 0 -+#endif -+ -+/* If any of the following are undefined, -+ define them to their de facto standard values. */ -+#if !S_ISUID -+# define S_ISUID 04000 -+#endif -+#if !S_ISGID -+# define S_ISGID 02000 -+#endif -+ -+/* S_ISVTX is a common extension to POSIX. */ -+#ifndef S_ISVTX -+# define S_ISVTX 01000 -+#endif -+ -+#if !S_IRUSR && S_IREAD -+# define S_IRUSR S_IREAD -+#endif -+#if !S_IRUSR -+# define S_IRUSR 00400 -+#endif -+#if !S_IRGRP -+# define S_IRGRP (S_IRUSR >> 3) -+#endif -+#if !S_IROTH -+# define S_IROTH (S_IRUSR >> 6) -+#endif -+ -+#if !S_IWUSR && S_IWRITE -+# define S_IWUSR S_IWRITE -+#endif -+#if !S_IWUSR -+# define S_IWUSR 00200 -+#endif -+#if !S_IWGRP -+# define S_IWGRP (S_IWUSR >> 3) -+#endif -+#if !S_IWOTH -+# define S_IWOTH (S_IWUSR >> 6) -+#endif -+ -+#if !S_IXUSR && S_IEXEC -+# define S_IXUSR S_IEXEC -+#endif -+#if !S_IXUSR -+# define S_IXUSR 00100 -+#endif -+#if !S_IXGRP -+# define S_IXGRP (S_IXUSR >> 3) -+#endif -+#if !S_IXOTH -+# define S_IXOTH (S_IXUSR >> 6) -+#endif -+ -+#if !S_IRWXU -+# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) -+#endif -+#if !S_IRWXG -+# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) -+#endif -+#if !S_IRWXO -+# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) -+#endif -+ -+/* S_IXUGO is a common extension to POSIX. */ -+#if !S_IXUGO -+# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) -+#endif -+ -+#ifndef S_IRWXUGO -+# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) -+#endif -+ -+/* Macros for futimens and utimensat. */ -+#ifndef UTIME_NOW -+# define UTIME_NOW (-1) -+# define UTIME_OMIT (-2) -+#endif -+ -+ -+#if @GNULIB_FCHMODAT@ -+# if !@HAVE_FCHMODAT@ -+_GL_FUNCDECL_SYS (fchmodat, int, -+ (int fd, char const *file, mode_t mode, int flag) -+ _GL_ARG_NONNULL ((2))); -+# endif -+_GL_CXXALIAS_SYS (fchmodat, int, -+ (int fd, char const *file, mode_t mode, int flag)); -+_GL_CXXALIASWARN (fchmodat); -+#elif defined GNULIB_POSIXCHECK -+# undef fchmodat -+# if HAVE_RAW_DECL_FCHMODAT -+_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - " -+ "use gnulib module openat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_FSTAT@ -+# if @REPLACE_FSTAT@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef fstat -+# define fstat rpl_fstat -+# endif -+_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2))); -+_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf)); -+# else -+_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf)); -+# endif -+_GL_CXXALIASWARN (fstat); -+#elif @WINDOWS_64_BIT_ST_SIZE@ -+/* Above, we define stat to _stati64. */ -+# define fstat _fstati64 -+#elif defined GNULIB_POSIXCHECK -+# undef fstat -+# if HAVE_RAW_DECL_FSTAT -+_GL_WARN_ON_USE (fstat, "fstat has portability problems - " -+ "use gnulib module fstat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_FSTATAT@ -+# if @REPLACE_FSTATAT@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef fstatat -+# define fstatat rpl_fstatat -+# endif -+_GL_FUNCDECL_RPL (fstatat, int, -+ (int fd, char const *name, struct stat *st, int flags) -+ _GL_ARG_NONNULL ((2, 3))); -+_GL_CXXALIAS_RPL (fstatat, int, -+ (int fd, char const *name, struct stat *st, int flags)); -+# else -+# if !@HAVE_FSTATAT@ -+_GL_FUNCDECL_SYS (fstatat, int, -+ (int fd, char const *name, struct stat *st, int flags) -+ _GL_ARG_NONNULL ((2, 3))); -+# endif -+_GL_CXXALIAS_SYS (fstatat, int, -+ (int fd, char const *name, struct stat *st, int flags)); -+# endif -+_GL_CXXALIASWARN (fstatat); -+#elif defined GNULIB_POSIXCHECK -+# undef fstatat -+# if HAVE_RAW_DECL_FSTATAT -+_GL_WARN_ON_USE (fstatat, "fstatat is not portable - " -+ "use gnulib module openat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_FUTIMENS@ -+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens -+ implementation relies on futimesat, which on Solaris 10 makes an invocation -+ to futimens that is meant to invoke the libc's futimens(), not gnulib's -+ futimens(). */ -+# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun) -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef futimens -+# define futimens rpl_futimens -+# endif -+_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2])); -+_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2])); -+# else -+# if !@HAVE_FUTIMENS@ -+_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2])); -+# endif -+_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2])); -+# endif -+# if @HAVE_FUTIMENS@ -+_GL_CXXALIASWARN (futimens); -+# endif -+#elif defined GNULIB_POSIXCHECK -+# undef futimens -+# if HAVE_RAW_DECL_FUTIMENS -+_GL_WARN_ON_USE (futimens, "futimens is not portable - " -+ "use gnulib module futimens for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_LCHMOD@ -+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME -+ denotes a symbolic link. */ -+# if !@HAVE_LCHMOD@ -+/* The lchmod replacement follows symbolic links. Callers should take -+ this into account; lchmod should be applied only to arguments that -+ are known to not be symbolic links. On hosts that lack lchmod, -+ this can lead to race conditions between the check and the -+ invocation of lchmod, but we know of no workarounds that are -+ reliable in general. You might try requesting support for lchmod -+ from your operating system supplier. */ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define lchmod chmod -+# endif -+/* Need to cast, because on mingw, the second parameter of chmod is -+ int mode. */ -+_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int, -+ (const char *filename, mode_t mode)); -+# else -+# if 0 /* assume already declared */ -+_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode) -+ _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode)); -+# endif -+# if @HAVE_LCHMOD@ -+_GL_CXXALIASWARN (lchmod); -+# endif -+#elif defined GNULIB_POSIXCHECK -+# undef lchmod -+# if HAVE_RAW_DECL_LCHMOD -+_GL_WARN_ON_USE (lchmod, "lchmod is unportable - " -+ "use gnulib module lchmod for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_LSTAT@ -+# if ! @HAVE_LSTAT@ -+/* mingw does not support symlinks, therefore it does not have lstat. But -+ without links, stat does just fine. */ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define lstat stat -+# endif -+_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf)); -+# elif @REPLACE_LSTAT@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef lstat -+# define lstat rpl_lstat -+# endif -+_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf) -+ _GL_ARG_NONNULL ((1, 2))); -+_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf)); -+# else -+_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf)); -+# endif -+# if @HAVE_LSTAT@ -+_GL_CXXALIASWARN (lstat); -+# endif -+#elif defined GNULIB_POSIXCHECK -+# undef lstat -+# if HAVE_RAW_DECL_LSTAT -+_GL_WARN_ON_USE (lstat, "lstat is unportable - " -+ "use gnulib module lstat for portability"); -+# endif -+#endif -+ -+ -+#if @REPLACE_MKDIR@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef mkdir -+# define mkdir rpl_mkdir -+# endif -+_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode)); -+#else -+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. -+ Additionally, it declares _mkdir (and depending on compile flags, an -+ alias mkdir), only in the nonstandard includes and , -+ which are included above. */ -+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -+ -+# if !GNULIB_defined_rpl_mkdir -+static int -+rpl_mkdir (char const *name, mode_t mode) -+{ -+ return _mkdir (name); -+} -+# define GNULIB_defined_rpl_mkdir 1 -+# endif -+ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define mkdir rpl_mkdir -+# endif -+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode)); -+# else -+_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode)); -+# endif -+#endif -+_GL_CXXALIASWARN (mkdir); -+ -+ -+#if @GNULIB_MKDIRAT@ -+# if !@HAVE_MKDIRAT@ -+_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode) -+ _GL_ARG_NONNULL ((2))); -+# endif -+_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)); -+_GL_CXXALIASWARN (mkdirat); -+#elif defined GNULIB_POSIXCHECK -+# undef mkdirat -+# if HAVE_RAW_DECL_MKDIRAT -+_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - " -+ "use gnulib module openat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_MKFIFO@ -+# if @REPLACE_MKFIFO@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef mkfifo -+# define mkfifo rpl_mkfifo -+# endif -+_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode)); -+# else -+# if !@HAVE_MKFIFO@ -+_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode) -+ _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode)); -+# endif -+_GL_CXXALIASWARN (mkfifo); -+#elif defined GNULIB_POSIXCHECK -+# undef mkfifo -+# if HAVE_RAW_DECL_MKFIFO -+_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - " -+ "use gnulib module mkfifo for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_MKFIFOAT@ -+# if !@HAVE_MKFIFOAT@ -+_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode) -+ _GL_ARG_NONNULL ((2))); -+# endif -+_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)); -+_GL_CXXALIASWARN (mkfifoat); -+#elif defined GNULIB_POSIXCHECK -+# undef mkfifoat -+# if HAVE_RAW_DECL_MKFIFOAT -+_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - " -+ "use gnulib module mkfifoat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_MKNOD@ -+# if @REPLACE_MKNOD@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef mknod -+# define mknod rpl_mknod -+# endif -+_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)); -+# else -+# if !@HAVE_MKNOD@ -+_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev) -+ _GL_ARG_NONNULL ((1))); -+# endif -+/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */ -+_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev)); -+# endif -+_GL_CXXALIASWARN (mknod); -+#elif defined GNULIB_POSIXCHECK -+# undef mknod -+# if HAVE_RAW_DECL_MKNOD -+_GL_WARN_ON_USE (mknod, "mknod is not portable - " -+ "use gnulib module mknod for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_MKNODAT@ -+# if !@HAVE_MKNODAT@ -+_GL_FUNCDECL_SYS (mknodat, int, -+ (int fd, char const *file, mode_t mode, dev_t dev) -+ _GL_ARG_NONNULL ((2))); -+# endif -+_GL_CXXALIAS_SYS (mknodat, int, -+ (int fd, char const *file, mode_t mode, dev_t dev)); -+_GL_CXXALIASWARN (mknodat); -+#elif defined GNULIB_POSIXCHECK -+# undef mknodat -+# if HAVE_RAW_DECL_MKNODAT -+_GL_WARN_ON_USE (mknodat, "mknodat is not portable - " -+ "use gnulib module mkfifoat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_STAT@ -+# if @REPLACE_STAT@ -+/* We can't use the object-like #define stat rpl_stat, because of -+ struct stat. This means that rpl_stat will not be used if the user -+ does (stat)(a,b). Oh well. */ -+# if defined _AIX && defined stat && defined _LARGE_FILES -+ /* With _LARGE_FILES defined, AIX (only) defines stat to stat64, -+ so we have to replace stat64() instead of stat(). */ -+# undef stat64 -+# define stat64(name, st) rpl_stat (name, st) -+# elif @WINDOWS_64_BIT_ST_SIZE@ -+ /* Above, we define stat to _stati64. */ -+# if defined __MINGW32__ && defined _stati64 -+# ifndef _USE_32BIT_TIME_T -+ /* The system headers define _stati64 to _stat64. */ -+# undef _stat64 -+# define _stat64(name, st) rpl_stat (name, st) -+# endif -+# elif defined _MSC_VER && defined _stati64 -+# ifdef _USE_32BIT_TIME_T -+ /* The system headers define _stati64 to _stat32i64. */ -+# undef _stat32i64 -+# define _stat32i64(name, st) rpl_stat (name, st) -+# else -+ /* The system headers define _stati64 to _stat64. */ -+# undef _stat64 -+# define _stat64(name, st) rpl_stat (name, st) -+# endif -+# else -+# undef _stati64 -+# define _stati64(name, st) rpl_stat (name, st) -+# endif -+# elif defined __MINGW32__ && defined stat -+# ifdef _USE_32BIT_TIME_T -+ /* The system headers define stat to _stat32i64. */ -+# undef _stat32i64 -+# define _stat32i64(name, st) rpl_stat (name, st) -+# else -+ /* The system headers define stat to _stat64. */ -+# undef _stat64 -+# define _stat64(name, st) rpl_stat (name, st) -+# endif -+# elif defined _MSC_VER && defined stat -+# ifdef _USE_32BIT_TIME_T -+ /* The system headers define stat to _stat32. */ -+# undef _stat32 -+# define _stat32(name, st) rpl_stat (name, st) -+# else -+ /* The system headers define stat to _stat64i32. */ -+# undef _stat64i32 -+# define _stat64i32(name, st) rpl_stat (name, st) -+# endif -+# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */ -+# undef stat -+# define stat(name, st) rpl_stat (name, st) -+# endif /* !_LARGE_FILES */ -+_GL_EXTERN_C int stat (const char *name, struct stat *buf) -+ _GL_ARG_NONNULL ((1, 2)); -+# endif -+#elif defined GNULIB_POSIXCHECK -+# undef stat -+# if HAVE_RAW_DECL_STAT -+_GL_WARN_ON_USE (stat, "stat is unportable - " -+ "use gnulib module stat for portability"); -+# endif -+#endif -+ -+ -+#if @GNULIB_UTIMENSAT@ -+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat -+ implementation relies on futimesat, which on Solaris 10 makes an invocation -+ to utimensat that is meant to invoke the libc's utimensat(), not gnulib's -+ utimensat(). */ -+# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun) -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef utimensat -+# define utimensat rpl_utimensat -+# endif -+_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name, -+ struct timespec const times[2], int flag) -+ _GL_ARG_NONNULL ((2))); -+_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name, -+ struct timespec const times[2], int flag)); -+# else -+# if !@HAVE_UTIMENSAT@ -+_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name, -+ struct timespec const times[2], int flag) -+ _GL_ARG_NONNULL ((2))); -+# endif -+_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name, -+ struct timespec const times[2], int flag)); -+# endif -+# if @HAVE_UTIMENSAT@ -+_GL_CXXALIASWARN (utimensat); -+# endif -+#elif defined GNULIB_POSIXCHECK -+# undef utimensat -+# if HAVE_RAW_DECL_UTIMENSAT -+_GL_WARN_ON_USE (utimensat, "utimensat is not portable - " -+ "use gnulib module utimensat for portability"); -+# endif -+#endif -+ -+ -+#endif /* _@GUARD_PREFIX@_SYS_STAT_H */ -+#endif /* _@GUARD_PREFIX@_SYS_STAT_H */ -+#endif -diff --git a/grub-core/gnulib/sys_time.in.h b/grub-core/gnulib/sys_time.in.h -new file mode 100644 -index 00000000000..30057ad49fd ---- /dev/null -+++ b/grub-core/gnulib/sys_time.in.h -@@ -0,0 +1,213 @@ -+/* Provide a more complete sys/time.h. -+ -+ Copyright (C) 2007-2014 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, 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 . */ -+ -+/* Written by Paul Eggert. */ -+ -+#ifndef _@GUARD_PREFIX@_SYS_TIME_H -+ -+#if __GNUC__ >= 3 -+@PRAGMA_SYSTEM_HEADER@ -+#endif -+@PRAGMA_COLUMNS@ -+ -+/* On Cygwin and on many BSDish systems, includes itself -+ recursively via . -+ Simply delegate to the system's header in this case; it is a no-op. -+ Without this extra ifdef, the C++ gettimeofday declaration below -+ would be a forward declaration in gnulib's nested . */ -+#if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_ -+# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ -+#else -+ -+/* The include_next requires a split double-inclusion guard. */ -+#if @HAVE_SYS_TIME_H@ -+# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ -+#endif -+ -+#ifndef _@GUARD_PREFIX@_SYS_TIME_H -+#define _@GUARD_PREFIX@_SYS_TIME_H -+ -+#if ! @HAVE_SYS_TIME_H@ -+# include -+#endif -+ -+/* On native Windows with MSVC, get the 'struct timeval' type. -+ Also, on native Windows with a 64-bit time_t, where we are overriding the -+ 'struct timeval' type, get all declarations of system functions whose -+ signature contains 'struct timeval'. */ -+#if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H -+# define _GL_INCLUDING_WINSOCK2_H -+# include -+# undef _GL_INCLUDING_WINSOCK2_H -+#endif -+ -+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ -+ -+/* The definition of _GL_ARG_NONNULL is copied here. */ -+ -+/* The definition of _GL_WARN_ON_USE is copied here. */ -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+#if !@HAVE_STRUCT_TIMEVAL@ || @REPLACE_STRUCT_TIMEVAL@ -+ -+# if @REPLACE_STRUCT_TIMEVAL@ -+# define timeval rpl_timeval -+# endif -+ -+# if !GNULIB_defined_struct_timeval -+struct timeval -+{ -+ time_t tv_sec; -+ long int tv_usec; -+}; -+# define GNULIB_defined_struct_timeval 1 -+# endif -+ -+#endif -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#if @GNULIB_GETTIMEOFDAY@ -+# if @REPLACE_GETTIMEOFDAY@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gettimeofday -+# define gettimeofday rpl_gettimeofday -+# endif -+_GL_FUNCDECL_RPL (gettimeofday, int, -+ (struct timeval *restrict, void *restrict) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (gettimeofday, int, -+ (struct timeval *restrict, void *restrict)); -+# else -+# if !@HAVE_GETTIMEOFDAY@ -+_GL_FUNCDECL_SYS (gettimeofday, int, -+ (struct timeval *restrict, void *restrict) -+ _GL_ARG_NONNULL ((1))); -+# endif -+/* Need to cast, because on glibc systems, by default, the second argument is -+ struct timezone *. */ -+_GL_CXXALIAS_SYS_CAST (gettimeofday, int, -+ (struct timeval *restrict, void *restrict)); -+# endif -+_GL_CXXALIASWARN (gettimeofday); -+#elif defined GNULIB_POSIXCHECK -+# undef gettimeofday -+# if HAVE_RAW_DECL_GETTIMEOFDAY -+_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " -+ "use gnulib module gettimeofday for portability"); -+# endif -+#endif -+ -+/* Hide some function declarations from . */ -+ -+#if defined _MSC_VER && @HAVE_WINSOCK2_H@ -+# if !defined _@GUARD_PREFIX@_UNISTD_H -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef close -+# define close close_used_without_including_unistd_h -+# else -+ _GL_WARN_ON_USE (close, -+ "close() used without including "); -+# endif -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gethostname -+# define gethostname gethostname_used_without_including_unistd_h -+# else -+ _GL_WARN_ON_USE (gethostname, -+ "gethostname() used without including "); -+# endif -+# endif -+# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef socket -+# define socket socket_used_without_including_sys_socket_h -+# undef connect -+# define connect connect_used_without_including_sys_socket_h -+# undef accept -+# define accept accept_used_without_including_sys_socket_h -+# undef bind -+# define bind bind_used_without_including_sys_socket_h -+# undef getpeername -+# define getpeername getpeername_used_without_including_sys_socket_h -+# undef getsockname -+# define getsockname getsockname_used_without_including_sys_socket_h -+# undef getsockopt -+# define getsockopt getsockopt_used_without_including_sys_socket_h -+# undef listen -+# define listen listen_used_without_including_sys_socket_h -+# undef recv -+# define recv recv_used_without_including_sys_socket_h -+# undef send -+# define send send_used_without_including_sys_socket_h -+# undef recvfrom -+# define recvfrom recvfrom_used_without_including_sys_socket_h -+# undef sendto -+# define sendto sendto_used_without_including_sys_socket_h -+# undef setsockopt -+# define setsockopt setsockopt_used_without_including_sys_socket_h -+# undef shutdown -+# define shutdown shutdown_used_without_including_sys_socket_h -+# else -+ _GL_WARN_ON_USE (socket, -+ "socket() used without including "); -+ _GL_WARN_ON_USE (connect, -+ "connect() used without including "); -+ _GL_WARN_ON_USE (accept, -+ "accept() used without including "); -+ _GL_WARN_ON_USE (bind, -+ "bind() used without including "); -+ _GL_WARN_ON_USE (getpeername, -+ "getpeername() used without including "); -+ _GL_WARN_ON_USE (getsockname, -+ "getsockname() used without including "); -+ _GL_WARN_ON_USE (getsockopt, -+ "getsockopt() used without including "); -+ _GL_WARN_ON_USE (listen, -+ "listen() used without including "); -+ _GL_WARN_ON_USE (recv, -+ "recv() used without including "); -+ _GL_WARN_ON_USE (send, -+ "send() used without including "); -+ _GL_WARN_ON_USE (recvfrom, -+ "recvfrom() used without including "); -+ _GL_WARN_ON_USE (sendto, -+ "sendto() used without including "); -+ _GL_WARN_ON_USE (setsockopt, -+ "setsockopt() used without including "); -+ _GL_WARN_ON_USE (shutdown, -+ "shutdown() used without including "); -+# endif -+# endif -+# if !defined _@GUARD_PREFIX@_SYS_SELECT_H -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef select -+# define select select_used_without_including_sys_select_h -+# else -+ _GL_WARN_ON_USE (select, -+ "select() used without including "); -+# endif -+# endif -+#endif -+ -+#endif /* _@GUARD_PREFIX@_SYS_TIME_H */ -+#endif /* _CYGWIN_SYS_TIME_H */ -+#endif /* _@GUARD_PREFIX@_SYS_TIME_H */ -diff --git a/grub-core/gnulib/sys_types.in.h b/grub-core/gnulib/sys_types.in.h -index d7da35623b1..9520c09030c 100644 ---- a/grub-core/gnulib/sys_types.in.h -+++ b/grub-core/gnulib/sys_types.in.h -@@ -23,7 +23,9 @@ - #ifndef _@GUARD_PREFIX@_SYS_TYPES_H - - /* The include_next requires a split double-inclusion guard. */ -+# define _GL_INCLUDING_SYS_TYPES_H - #@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@ -+# undef _GL_INCLUDING_SYS_TYPES_H - - #ifndef _@GUARD_PREFIX@_SYS_TYPES_H - #define _@GUARD_PREFIX@_SYS_TYPES_H -diff --git a/grub-core/gnulib/time.h b/grub-core/gnulib/time.h -new file mode 100644 -index 00000000000..b9203d5569a ---- /dev/null -+++ b/grub-core/gnulib/time.h -@@ -0,0 +1,586 @@ -+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ -+/* A more-standard . -+ -+ Copyright (C) 2007-2014 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, 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 . */ -+ -+#if __GNUC__ >= 3 -+#pragma GCC system_header -+#endif -+ -+ -+/* Don't get in the way of glibc when it includes time.h merely to -+ declare a few standard symbols, rather than to declare all the -+ symbols. Also, Solaris 8 eventually includes itself -+ recursively; if that is happening, just include the system -+ without adding our own declarations. */ -+#if (defined __need_time_t || defined __need_clock_t \ -+ || defined __need_timespec \ -+ || defined _GL_TIME_H) -+ -+# include_next -+ -+#else -+ -+# define _GL_TIME_H -+ -+# include_next -+ -+/* NetBSD 5.0 mis-defines NULL. */ -+# include -+ -+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ -+#ifndef _GL_CXXDEFS_H -+#define _GL_CXXDEFS_H -+ -+/* The three most frequent use cases of these macros are: -+ -+ * For providing a substitute for a function that is missing on some -+ platforms, but is declared and works fine on the platforms on which -+ it exists: -+ -+ #if @GNULIB_FOO@ -+ # if !@HAVE_FOO@ -+ _GL_FUNCDECL_SYS (foo, ...); -+ # endif -+ _GL_CXXALIAS_SYS (foo, ...); -+ _GL_CXXALIASWARN (foo); -+ #elif defined GNULIB_POSIXCHECK -+ ... -+ #endif -+ -+ * For providing a replacement for a function that exists on all platforms, -+ but is broken/insufficient and needs to be replaced on some platforms: -+ -+ #if @GNULIB_FOO@ -+ # if @REPLACE_FOO@ -+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+ # undef foo -+ # define foo rpl_foo -+ # endif -+ _GL_FUNCDECL_RPL (foo, ...); -+ _GL_CXXALIAS_RPL (foo, ...); -+ # else -+ _GL_CXXALIAS_SYS (foo, ...); -+ # endif -+ _GL_CXXALIASWARN (foo); -+ #elif defined GNULIB_POSIXCHECK -+ ... -+ #endif -+ -+ * For providing a replacement for a function that exists on some platforms -+ but is broken/insufficient and needs to be replaced on some of them and -+ is additionally either missing or undeclared on some other platforms: -+ -+ #if @GNULIB_FOO@ -+ # if @REPLACE_FOO@ -+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+ # undef foo -+ # define foo rpl_foo -+ # endif -+ _GL_FUNCDECL_RPL (foo, ...); -+ _GL_CXXALIAS_RPL (foo, ...); -+ # else -+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@ -+ _GL_FUNCDECL_SYS (foo, ...); -+ # endif -+ _GL_CXXALIAS_SYS (foo, ...); -+ # endif -+ _GL_CXXALIASWARN (foo); -+ #elif defined GNULIB_POSIXCHECK -+ ... -+ #endif -+*/ -+ -+/* _GL_EXTERN_C declaration; -+ performs the declaration with C linkage. */ -+#if defined __cplusplus -+# define _GL_EXTERN_C extern "C" -+#else -+# define _GL_EXTERN_C extern -+#endif -+ -+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); -+ declares a replacement function, named rpl_func, with the given prototype, -+ consisting of return type, parameters, and attributes. -+ Example: -+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) -+ _GL_ARG_NONNULL ((1))); -+ */ -+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ -+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) -+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ -+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes -+ -+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); -+ declares the system function, named func, with the given prototype, -+ consisting of return type, parameters, and attributes. -+ Example: -+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) -+ _GL_ARG_NONNULL ((1))); -+ */ -+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ -+ _GL_EXTERN_C rettype func parameters_and_attributes -+ -+/* _GL_CXXALIAS_RPL (func, rettype, parameters); -+ declares a C++ alias called GNULIB_NAMESPACE::func -+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined. -+ Example: -+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); -+ */ -+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \ -+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ -+ namespace GNULIB_NAMESPACE \ -+ { \ -+ rettype (*const func) parameters = ::rpl_func; \ -+ } \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#else -+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters); -+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters); -+ except that the C function rpl_func may have a slightly different -+ declaration. A cast is used to silence the "invalid conversion" error -+ that would otherwise occur. */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ -+ namespace GNULIB_NAMESPACE \ -+ { \ -+ rettype (*const func) parameters = \ -+ reinterpret_cast(::rpl_func); \ -+ } \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#else -+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIAS_SYS (func, rettype, parameters); -+ declares a C++ alias called GNULIB_NAMESPACE::func -+ that redirects to the system provided function func, if GNULIB_NAMESPACE -+ is defined. -+ Example: -+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); -+ */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+ /* If we were to write -+ rettype (*const func) parameters = ::func; -+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls -+ better (remove an indirection through a 'static' pointer variable), -+ but then the _GL_CXXALIASWARN macro below would cause a warning not only -+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */ -+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ -+ namespace GNULIB_NAMESPACE \ -+ { \ -+ static rettype (*func) parameters = ::func; \ -+ } \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#else -+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters); -+ is like _GL_CXXALIAS_SYS (func, rettype, parameters); -+ except that the C function func may have a slightly different declaration. -+ A cast is used to silence the "invalid conversion" error that would -+ otherwise occur. */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ -+ namespace GNULIB_NAMESPACE \ -+ { \ -+ static rettype (*func) parameters = \ -+ reinterpret_cast(::func); \ -+ } \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#else -+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2); -+ is like _GL_CXXALIAS_SYS (func, rettype, parameters); -+ except that the C function is picked among a set of overloaded functions, -+ namely the one with rettype2 and parameters2. Two consecutive casts -+ are used to silence the "cannot find a match" and "invalid conversion" -+ errors that would otherwise occur. */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+ /* The outer cast must be a reinterpret_cast. -+ The inner cast: When the function is defined as a set of overloaded -+ functions, it works as a static_cast<>, choosing the designated variant. -+ When the function is defined as a single variant, it works as a -+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */ -+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ -+ namespace GNULIB_NAMESPACE \ -+ { \ -+ static rettype (*func) parameters = \ -+ reinterpret_cast( \ -+ (rettype2(*)parameters2)(::func)); \ -+ } \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#else -+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIASWARN (func); -+ causes a warning to be emitted when ::func is used but not when -+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded -+ variants. */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+# define _GL_CXXALIASWARN(func) \ -+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) -+# define _GL_CXXALIASWARN_1(func,namespace) \ -+ _GL_CXXALIASWARN_2 (func, namespace) -+/* To work around GCC bug , -+ we enable the warning only when not optimizing. */ -+# if !__OPTIMIZE__ -+# define _GL_CXXALIASWARN_2(func,namespace) \ -+ _GL_WARN_ON_USE (func, \ -+ "The symbol ::" #func " refers to the system function. " \ -+ "Use " #namespace "::" #func " instead.") -+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING -+# define _GL_CXXALIASWARN_2(func,namespace) \ -+ extern __typeof__ (func) func -+# else -+# define _GL_CXXALIASWARN_2(func,namespace) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+# endif -+#else -+# define _GL_CXXALIASWARN(func) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes); -+ causes a warning to be emitted when the given overloaded variant of ::func -+ is used but not when GNULIB_NAMESPACE::func is used. */ -+#if defined __cplusplus && defined GNULIB_NAMESPACE -+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ -+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \ -+ GNULIB_NAMESPACE) -+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ -+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) -+/* To work around GCC bug , -+ we enable the warning only when not optimizing. */ -+# if !__OPTIMIZE__ -+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ -+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ -+ "The symbol ::" #func " refers to the system function. " \ -+ "Use " #namespace "::" #func " instead.") -+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING -+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ -+ extern __typeof__ (func) func -+# else -+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+# endif -+#else -+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ -+ _GL_EXTERN_C int _gl_cxxalias_dummy -+#endif -+ -+#endif /* _GL_CXXDEFS_H */ -+ -+/* The definition of _GL_ARG_NONNULL is copied here. */ -+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools -+ that the values passed as arguments n, ..., m must be non-NULL pointers. -+ n = 1 stands for the first argument, n = 2 for the second argument etc. */ -+#ifndef _GL_ARG_NONNULL -+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 -+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) -+# else -+# define _GL_ARG_NONNULL(params) -+# endif -+#endif -+ -+/* The definition of _GL_WARN_ON_USE is copied here. */ -+#ifndef _GL_WARN_ON_USE -+ -+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) -+/* A compiler attribute is available in gcc versions 4.3.0 and later. */ -+# define _GL_WARN_ON_USE(function, message) \ -+extern __typeof__ (function) function __attribute__ ((__warning__ (message))) -+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING -+/* Verify the existence of the function. */ -+# define _GL_WARN_ON_USE(function, message) \ -+extern __typeof__ (function) function -+# else /* Unsupported. */ -+# define _GL_WARN_ON_USE(function, message) \ -+_GL_WARN_EXTERN_C int _gl_warn_on_use -+# endif -+#endif -+ -+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string") -+ is like _GL_WARN_ON_USE (function, "string"), except that the function is -+ declared with the given prototype, consisting of return type, parameters, -+ and attributes. -+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does -+ not work in this case. */ -+#ifndef _GL_WARN_ON_USE_CXX -+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) -+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ -+extern rettype function parameters_and_attributes \ -+ __attribute__ ((__warning__ (msg))) -+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING -+/* Verify the existence of the function. */ -+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ -+extern rettype function parameters_and_attributes -+# else /* Unsupported. */ -+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ -+_GL_WARN_EXTERN_C int _gl_warn_on_use -+# endif -+#endif -+ -+/* _GL_WARN_EXTERN_C declaration; -+ performs the declaration with C linkage. */ -+#ifndef _GL_WARN_EXTERN_C -+# if defined __cplusplus -+# define _GL_WARN_EXTERN_C extern "C" -+# else -+# define _GL_WARN_EXTERN_C extern -+# endif -+#endif -+ -+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). -+ Or they define it with the wrong member names or define it in -+ (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, -+ but the pthreads-win32 library defines it in . */ -+# if ! 1 -+# if 0 -+# include -+# elif 0 -+# include -+# else -+ -+# ifdef __cplusplus -+extern "C" { -+# endif -+ -+# if !GNULIB_defined_struct_timespec -+# undef timespec -+# define timespec rpl_timespec -+struct timespec -+{ -+ time_t tv_sec; -+ long int tv_nsec; -+}; -+# define GNULIB_defined_struct_timespec 1 -+# endif -+ -+# ifdef __cplusplus -+} -+# endif -+ -+# endif -+# endif -+ -+# if !GNULIB_defined_struct_time_t_must_be_integral -+/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires -+ time_t to be an integer type, even though C99 permits floating -+ point. We don't know of any implementation that uses floating -+ point, and it is much easier to write code that doesn't have to -+ worry about that corner case, so we force the issue. */ -+struct __time_t_must_be_integral { -+ unsigned int __floating_time_t_unsupported : (time_t) 1; -+}; -+# define GNULIB_defined_struct_time_t_must_be_integral 1 -+# endif -+ -+/* Sleep for at least RQTP seconds unless interrupted, If interrupted, -+ return -1 and store the remaining time into RMTP. See -+ . */ -+# if 0 -+# if GNULIB_PORTCHECK -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define nanosleep rpl_nanosleep -+# endif -+_GL_FUNCDECL_RPL (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp)); -+# else -+# if ! 1 -+_GL_FUNCDECL_SYS (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp) -+ _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp)); -+# endif -+_GL_CXXALIASWARN (nanosleep); -+# endif -+ -+/* Return the 'time_t' representation of TP and normalize TP. */ -+# if 0 -+# if GNULIB_PORTCHECK -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define mktime rpl_mktime -+# endif -+_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); -+# else -+_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); -+# endif -+_GL_CXXALIASWARN (mktime); -+# endif -+ -+/* Convert TIMER to RESULT, assuming local time and UTC respectively. See -+ and -+ . */ -+# if 0 -+# if GNULIB_PORTCHECK -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef localtime_r -+# define localtime_r rpl_localtime_r -+# endif -+_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# else -+# if ! 1 -+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+# endif -+_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# endif -+# if 1 -+_GL_CXXALIASWARN (localtime_r); -+# endif -+# if GNULIB_PORTCHECK -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gmtime_r -+# define gmtime_r rpl_gmtime_r -+# endif -+_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# else -+# if ! 1 -+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+# endif -+_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# endif -+# if 1 -+_GL_CXXALIASWARN (gmtime_r); -+# endif -+# endif -+ -+/* Convert TIMER to RESULT, assuming local time and UTC respectively. See -+ and -+ . */ -+# if 1 -+# if 0 -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef localtime -+# define localtime rpl_localtime -+# endif -+_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); -+# else -+_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); -+# endif -+_GL_CXXALIASWARN (localtime); -+# endif -+ -+# if 1 -+# if 0 -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gmtime -+# define gmtime rpl_gmtime -+# endif -+_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); -+# else -+_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); -+# endif -+_GL_CXXALIASWARN (gmtime); -+# endif -+ -+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store -+ the resulting broken-down time into TM. See -+ . */ -+# if 0 -+# if ! 1 -+_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, -+ char const *restrict __format, -+ struct tm *restrict __tm) -+ _GL_ARG_NONNULL ((1, 2, 3))); -+# endif -+_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, -+ char const *restrict __format, -+ struct tm *restrict __tm)); -+_GL_CXXALIASWARN (strptime); -+# endif -+ -+/* Convert TM to a time_t value, assuming UTC. */ -+# if 0 -+# if GNULIB_PORTCHECK -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef timegm -+# define timegm rpl_timegm -+# endif -+_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); -+# else -+# if ! 1 -+_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); -+# endif -+_GL_CXXALIASWARN (timegm); -+# endif -+ -+/* Encourage applications to avoid unsafe functions that can overrun -+ buffers when given outlandish struct tm values. Portable -+ applications should use strftime (or even sprintf) instead. */ -+# if defined GNULIB_POSIXCHECK -+# undef asctime -+_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef asctime_r -+_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef ctime -+_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef ctime_r -+_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+ -+#endif -diff --git a/grub-core/gnulib/time.in.h b/grub-core/gnulib/time.in.h -new file mode 100644 -index 00000000000..81abdf46e0b ---- /dev/null -+++ b/grub-core/gnulib/time.in.h -@@ -0,0 +1,274 @@ -+/* A more-standard . -+ -+ Copyright (C) 2007-2014 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, 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 . */ -+ -+#if __GNUC__ >= 3 -+@PRAGMA_SYSTEM_HEADER@ -+#endif -+@PRAGMA_COLUMNS@ -+ -+/* Don't get in the way of glibc when it includes time.h merely to -+ declare a few standard symbols, rather than to declare all the -+ symbols. Also, Solaris 8 eventually includes itself -+ recursively; if that is happening, just include the system -+ without adding our own declarations. */ -+#if (defined __need_time_t || defined __need_clock_t \ -+ || defined __need_timespec \ -+ || defined _@GUARD_PREFIX@_TIME_H) -+ -+# @INCLUDE_NEXT@ @NEXT_TIME_H@ -+ -+#else -+ -+# define _@GUARD_PREFIX@_TIME_H -+ -+# @INCLUDE_NEXT@ @NEXT_TIME_H@ -+ -+/* NetBSD 5.0 mis-defines NULL. */ -+# include -+ -+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ -+ -+/* The definition of _GL_ARG_NONNULL is copied here. */ -+ -+/* The definition of _GL_WARN_ON_USE is copied here. */ -+ -+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). -+ Or they define it with the wrong member names or define it in -+ (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, -+ but the pthreads-win32 library defines it in . */ -+# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ -+# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ -+# include -+# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ -+# include -+# else -+ -+# ifdef __cplusplus -+extern "C" { -+# endif -+ -+# if !GNULIB_defined_struct_timespec -+# undef timespec -+# define timespec rpl_timespec -+struct timespec -+{ -+ time_t tv_sec; -+ long int tv_nsec; -+}; -+# define GNULIB_defined_struct_timespec 1 -+# endif -+ -+# ifdef __cplusplus -+} -+# endif -+ -+# endif -+# endif -+ -+# if !GNULIB_defined_struct_time_t_must_be_integral -+/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires -+ time_t to be an integer type, even though C99 permits floating -+ point. We don't know of any implementation that uses floating -+ point, and it is much easier to write code that doesn't have to -+ worry about that corner case, so we force the issue. */ -+struct __time_t_must_be_integral { -+ unsigned int __floating_time_t_unsupported : (time_t) 1; -+}; -+# define GNULIB_defined_struct_time_t_must_be_integral 1 -+# endif -+ -+/* Sleep for at least RQTP seconds unless interrupted, If interrupted, -+ return -1 and store the remaining time into RMTP. See -+ . */ -+# if @GNULIB_NANOSLEEP@ -+# if @REPLACE_NANOSLEEP@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define nanosleep rpl_nanosleep -+# endif -+_GL_FUNCDECL_RPL (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp)); -+# else -+# if ! @HAVE_NANOSLEEP@ -+_GL_FUNCDECL_SYS (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp) -+ _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (nanosleep, int, -+ (struct timespec const *__rqtp, struct timespec *__rmtp)); -+# endif -+_GL_CXXALIASWARN (nanosleep); -+# endif -+ -+/* Return the 'time_t' representation of TP and normalize TP. */ -+# if @GNULIB_MKTIME@ -+# if @REPLACE_MKTIME@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# define mktime rpl_mktime -+# endif -+_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); -+# else -+_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); -+# endif -+_GL_CXXALIASWARN (mktime); -+# endif -+ -+/* Convert TIMER to RESULT, assuming local time and UTC respectively. See -+ and -+ . */ -+# if @GNULIB_TIME_R@ -+# if @REPLACE_LOCALTIME_R@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef localtime_r -+# define localtime_r rpl_localtime_r -+# endif -+_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# else -+# if ! @HAVE_DECL_LOCALTIME_R@ -+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+# endif -+_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# endif -+# if @HAVE_DECL_LOCALTIME_R@ -+_GL_CXXALIASWARN (localtime_r); -+# endif -+# if @REPLACE_LOCALTIME_R@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gmtime_r -+# define gmtime_r rpl_gmtime_r -+# endif -+_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# else -+# if ! @HAVE_DECL_LOCALTIME_R@ -+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result) -+ _GL_ARG_NONNULL ((1, 2))); -+# endif -+_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, -+ struct tm *restrict __result)); -+# endif -+# if @HAVE_DECL_LOCALTIME_R@ -+_GL_CXXALIASWARN (gmtime_r); -+# endif -+# endif -+ -+/* Convert TIMER to RESULT, assuming local time and UTC respectively. See -+ and -+ . */ -+# if @GNULIB_GETTIMEOFDAY@ -+# if @REPLACE_LOCALTIME@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef localtime -+# define localtime rpl_localtime -+# endif -+_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); -+# else -+_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); -+# endif -+_GL_CXXALIASWARN (localtime); -+# endif -+ -+# if @GNULIB_GETTIMEOFDAY@ -+# if @REPLACE_GMTIME@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef gmtime -+# define gmtime rpl_gmtime -+# endif -+_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) -+ _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); -+# else -+_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); -+# endif -+_GL_CXXALIASWARN (gmtime); -+# endif -+ -+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store -+ the resulting broken-down time into TM. See -+ . */ -+# if @GNULIB_STRPTIME@ -+# if ! @HAVE_STRPTIME@ -+_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, -+ char const *restrict __format, -+ struct tm *restrict __tm) -+ _GL_ARG_NONNULL ((1, 2, 3))); -+# endif -+_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, -+ char const *restrict __format, -+ struct tm *restrict __tm)); -+_GL_CXXALIASWARN (strptime); -+# endif -+ -+/* Convert TM to a time_t value, assuming UTC. */ -+# if @GNULIB_TIMEGM@ -+# if @REPLACE_TIMEGM@ -+# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -+# undef timegm -+# define timegm rpl_timegm -+# endif -+_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); -+_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); -+# else -+# if ! @HAVE_TIMEGM@ -+_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); -+# endif -+_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); -+# endif -+_GL_CXXALIASWARN (timegm); -+# endif -+ -+/* Encourage applications to avoid unsafe functions that can overrun -+ buffers when given outlandish struct tm values. Portable -+ applications should use strftime (or even sprintf) instead. */ -+# if defined GNULIB_POSIXCHECK -+# undef asctime -+_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef asctime_r -+_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef ctime -+_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+# if defined GNULIB_POSIXCHECK -+# undef ctime_r -+_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " -+ "better use strftime (or even sprintf) instead"); -+# endif -+ -+#endif -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/grub-core/gnulib/Makefile.am b/grub-core/gnulib/Makefile.am -index 3444397fe37..b7c5e60e1c3 100644 ---- a/grub-core/gnulib/Makefile.am -+++ b/grub-core/gnulib/Makefile.am -@@ -21,7 +21,7 @@ - # the same distribution terms as the rest of that program. - # - # Generated by gnulib-tool. --# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex -+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex - - AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects - -@@ -326,6 +326,15 @@ libgnu_a_SOURCES += gettext.h - - ## end gnulib module gettext-h - -+## begin gnulib module gettimeofday -+ -+ -+EXTRA_DIST += gettimeofday.c -+ -+EXTRA_libgnu_a_SOURCES += gettimeofday.c -+ -+## end gnulib module gettimeofday -+ - ## begin gnulib module havelib - - -@@ -596,6 +605,13 @@ EXTRA_libgnu_a_SOURCES += nl_langinfo.c - - ## end gnulib module nl_langinfo - -+## begin gnulib module pathmax -+ -+ -+EXTRA_DIST += pathmax.h -+ -+## end gnulib module pathmax -+ - ## begin gnulib module progname - - libgnu_a_SOURCES += progname.h progname.c -@@ -611,6 +627,15 @@ EXTRA_libgnu_a_SOURCES += rawmemchr.c - - ## end gnulib module rawmemchr - -+## begin gnulib module readlink -+ -+ -+EXTRA_DIST += readlink.c -+ -+EXTRA_libgnu_a_SOURCES += readlink.c -+ -+## end gnulib module readlink -+ - ## begin gnulib module realloc-posix - - -@@ -725,6 +750,15 @@ EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h - - ## end gnulib module snippet/warn-on-use - -+## begin gnulib module stat -+ -+ -+EXTRA_DIST += stat.c -+ -+EXTRA_libgnu_a_SOURCES += stat.c -+ -+## end gnulib module stat -+ - ## begin gnulib module stdalign - - BUILT_SOURCES += $(STDALIGN_H) -@@ -1280,6 +1314,102 @@ libgnu_a_SOURCES += strnlen1.h strnlen1.c - - ## end gnulib module strnlen1 - -+## begin gnulib module sys_stat -+ -+BUILT_SOURCES += sys/stat.h -+ -+# We need the following in order to create when the system -+# has one that is incomplete. -+sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -+ $(AM_V_at)$(MKDIR_P) sys -+ $(AM_V_GEN)rm -f $@-t $@ && \ -+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ -+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ -+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -+ -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \ -+ -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \ -+ -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \ -+ -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \ -+ -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \ -+ -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \ -+ -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \ -+ -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \ -+ -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \ -+ -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \ -+ -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \ -+ -e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \ -+ -e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \ -+ -e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \ -+ -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \ -+ -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \ -+ -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \ -+ -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \ -+ -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \ -+ -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \ -+ -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \ -+ -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \ -+ -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \ -+ -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \ -+ -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \ -+ -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \ -+ -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \ -+ -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \ -+ -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \ -+ -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \ -+ -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ -+ -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \ -+ -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \ -+ -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \ -+ -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \ -+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -+ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ -+ < $(srcdir)/sys_stat.in.h; \ -+ } > $@-t && \ -+ mv $@-t $@ -+MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t -+MOSTLYCLEANDIRS += sys -+ -+EXTRA_DIST += sys_stat.in.h -+ -+## end gnulib module sys_stat -+ -+## begin gnulib module sys_time -+ -+BUILT_SOURCES += sys/time.h -+ -+# We need the following in order to create when the system -+# doesn't have one that works with the given compiler. -+sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -+ $(AM_V_at)$(MKDIR_P) sys -+ $(AM_V_GEN)rm -f $@-t $@ && \ -+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ -+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ -+ -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \ -+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -+ -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ -+ -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ -+ -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ -+ -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \ -+ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ -+ -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ -+ -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \ -+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -+ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ -+ < $(srcdir)/sys_time.in.h; \ -+ } > $@-t && \ -+ mv $@-t $@ -+MOSTLYCLEANFILES += sys/time.h sys/time.h-t -+ -+EXTRA_DIST += sys_time.in.h -+ -+## end gnulib module sys_time -+ - ## begin gnulib module sys_types - - BUILT_SOURCES += sys/types.h -@@ -1334,6 +1464,51 @@ EXTRA_DIST += sysexits.in.h - - ## end gnulib module sysexits - -+## begin gnulib module time -+ -+BUILT_SOURCES += time.h -+ -+# We need the following in order to create when the system -+# doesn't have one that works with the given compiler. -+time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -+ $(AM_V_GEN)rm -f $@-t $@ && \ -+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ -+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ -+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -+ -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ -+ -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ -+ -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ -+ -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ -+ -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ -+ -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ -+ -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ -+ -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ -+ -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ -+ -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ -+ -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ -+ -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ -+ -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \ -+ -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ -+ -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ -+ -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ -+ -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ -+ -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ -+ -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ -+ -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ -+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -+ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ -+ < $(srcdir)/time.in.h; \ -+ } > $@-t && \ -+ mv $@-t $@ -+MOSTLYCLEANFILES += time.h time.h-t -+ -+EXTRA_DIST += time.in.h -+ -+## end gnulib module time -+ - ## begin gnulib module unistd - - BUILT_SOURCES += unistd.h -diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4 -new file mode 100644 -index 00000000000..1c2d66ee261 ---- /dev/null -+++ b/m4/gettimeofday.m4 -@@ -0,0 +1,138 @@ -+# serial 21 -+ -+# Copyright (C) 2001-2003, 2005, 2007, 2009-2014 Free Software Foundation, Inc. -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+dnl From Jim Meyering. -+ -+AC_DEFUN([gl_FUNC_GETTIMEOFDAY], -+[ -+ AC_REQUIRE([AC_C_RESTRICT]) -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H]) -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) -+ AC_CHECK_FUNCS_ONCE([gettimeofday]) -+ -+ gl_gettimeofday_timezone=void -+ if test $ac_cv_func_gettimeofday != yes; then -+ HAVE_GETTIMEOFDAY=0 -+ else -+ gl_FUNC_GETTIMEOFDAY_CLOBBER -+ AC_CACHE_CHECK([for gettimeofday with POSIX signature], -+ [gl_cv_func_gettimeofday_posix_signature], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ struct timeval c; -+ int gettimeofday (struct timeval *restrict, void *restrict); -+ ]], -+ [[/* glibc uses struct timezone * rather than the POSIX void * -+ if _GNU_SOURCE is defined. However, since the only portable -+ use of gettimeofday uses NULL as the second parameter, and -+ since the glibc definition is actually more typesafe, it is -+ not worth wrapping this to get a compliant signature. */ -+ int (*f) (struct timeval *restrict, void *restrict) -+ = gettimeofday; -+ int x = f (&c, 0); -+ return !(x | c.tv_sec | c.tv_usec); -+ ]])], -+ [gl_cv_func_gettimeofday_posix_signature=yes], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+int gettimeofday (struct timeval *restrict, struct timezone *restrict); -+ ]])], -+ [gl_cv_func_gettimeofday_posix_signature=almost], -+ [gl_cv_func_gettimeofday_posix_signature=no])])]) -+ if test $gl_cv_func_gettimeofday_posix_signature = almost; then -+ gl_gettimeofday_timezone='struct timezone' -+ elif test $gl_cv_func_gettimeofday_posix_signature != yes; then -+ REPLACE_GETTIMEOFDAY=1 -+ fi -+ dnl If we override 'struct timeval', we also have to override gettimeofday. -+ if test $REPLACE_STRUCT_TIMEVAL = 1; then -+ REPLACE_GETTIMEOFDAY=1 -+ fi -+ m4_ifdef([gl_FUNC_TZSET_CLOBBER], [ -+ gl_FUNC_TZSET_CLOBBER -+ case "$gl_cv_func_tzset_clobber" in -+ *yes) -+ REPLACE_GETTIMEOFDAY=1 -+ gl_GETTIMEOFDAY_REPLACE_LOCALTIME -+ AC_DEFINE([tzset], [rpl_tzset], -+ [Define to rpl_tzset if the wrapper function should be used.]) -+ AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1], -+ [Define if tzset clobbers localtime's static buffer.]) -+ ;; -+ esac -+ ]) -+ fi -+ AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone], -+ [Define this to 'void' or 'struct timezone' to match the system's -+ declaration of the second argument to gettimeofday.]) -+]) -+ -+ -+dnl See if gettimeofday clobbers the static buffer that localtime uses -+dnl for its return value. The gettimeofday function from Mac OS X 10.0.4 -+dnl (i.e., Darwin 1.3.7) has this problem. -+dnl -+dnl If it does, then arrange to use gettimeofday and localtime only via -+dnl the wrapper functions that work around the problem. -+ -+AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], -+[ -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H]) -+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles -+ -+ AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer], -+ [gl_cv_func_gettimeofday_clobber], -+ [AC_RUN_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ #include -+ #include -+ #include -+ ]], -+ [[ -+ time_t t = 0; -+ struct tm *lt; -+ struct tm saved_lt; -+ struct timeval tv; -+ lt = localtime (&t); -+ saved_lt = *lt; -+ gettimeofday (&tv, NULL); -+ return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0; -+ ]])], -+ [gl_cv_func_gettimeofday_clobber=no], -+ [gl_cv_func_gettimeofday_clobber=yes], -+ [# When cross-compiling: -+ case "$host_os" in -+ # Guess all is fine on glibc systems. -+ *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;; -+ # If we don't know, assume the worst. -+ *) gl_cv_func_gettimeofday_clobber="guessing yes" ;; -+ esac -+ ])]) -+ -+ case "$gl_cv_func_gettimeofday_clobber" in -+ *yes) -+ REPLACE_GETTIMEOFDAY=1 -+ gl_GETTIMEOFDAY_REPLACE_LOCALTIME -+ AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1], -+ [Define if gettimeofday clobbers the localtime buffer.]) -+ ;; -+ esac -+]) -+ -+AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [ -+ REPLACE_GMTIME=1 -+ REPLACE_LOCALTIME=1 -+]) -+ -+# Prerequisites of lib/gettimeofday.c. -+AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [ -+ AC_CHECK_HEADERS([sys/timeb.h]) -+ AC_CHECK_FUNCS([_ftime]) -+]) -diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 -index 408918440b6..ef2ec5bcce0 100644 ---- a/m4/gnulib-cache.m4 -+++ b/m4/gnulib-cache.m4 -@@ -27,7 +27,7 @@ - - - # Specification in the form of a command-line invocation: --# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex -+# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex - - # Specification in the form of a few gnulib-tool.m4 macro invocations: - gl_LOCAL_DIR([]) -@@ -39,6 +39,7 @@ gl_MODULES([ - getline - gettext - progname -+ readlink - regex - ]) - gl_AVOID([]) -diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 -index 7a19f60d85e..66fd0eda901 100644 ---- a/m4/gnulib-comp.m4 -+++ b/m4/gnulib-comp.m4 -@@ -60,10 +60,13 @@ AC_DEFUN([gl_EARLY], - # Code from module getopt-posix: - # Code from module gettext: - # Code from module gettext-h: -+ # Code from module gettimeofday: - # Code from module havelib: - # Code from module include_next: - # Code from module intprops: - # Code from module langinfo: -+ # Code from module largefile: -+ AC_REQUIRE([AC_SYS_LARGEFILE]) - # Code from module localcharset: - # Code from module locale: - # Code from module localeconv: -@@ -81,8 +84,10 @@ AC_DEFUN([gl_EARLY], - # Code from module multiarch: - # Code from module nl_langinfo: - # Code from module nocrash: -+ # Code from module pathmax: - # Code from module progname: - # Code from module rawmemchr: -+ # Code from module readlink: - # Code from module realloc-posix: - # Code from module regex: - # Code from module size_max: -@@ -92,6 +97,7 @@ AC_DEFUN([gl_EARLY], - # Code from module snippet/c++defs: - # Code from module snippet/warn-on-use: - # Code from module ssize_t: -+ # Code from module stat: - # Code from module stdalign: - # Code from module stdbool: - # Code from module stddef: -@@ -108,8 +114,11 @@ AC_DEFUN([gl_EARLY], - # Code from module strndup: - # Code from module strnlen: - # Code from module strnlen1: -+ # Code from module sys_stat: -+ # Code from module sys_time: - # Code from module sys_types: - # Code from module sysexits: -+ # Code from module time: - # Code from module unistd: - # Code from module unitypes: - # Code from module uniwidth/base: -@@ -211,7 +220,14 @@ AC_DEFUN([gl_INIT], - AM_GNU_GETTEXT_VERSION([0.18.1]) - AC_SUBST([LIBINTL]) - AC_SUBST([LTLIBINTL]) -+ gl_FUNC_GETTIMEOFDAY -+ if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then -+ AC_LIBOBJ([gettimeofday]) -+ gl_PREREQ_GETTIMEOFDAY -+ fi -+ gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) - gl_LANGINFO_H -+ AC_REQUIRE([gl_LARGEFILE]) - gl_LOCALCHARSET - LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\"" - AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) -@@ -284,6 +300,7 @@ AC_DEFUN([gl_INIT], - AC_LIBOBJ([nl_langinfo]) - fi - gl_LANGINFO_MODULE_INDICATOR([nl_langinfo]) -+ gl_PATHMAX - AC_CHECK_DECLS([program_invocation_name], [], [], [#include ]) - AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include ]) - gl_FUNC_RAWMEMCHR -@@ -292,6 +309,12 @@ AC_DEFUN([gl_INIT], - gl_PREREQ_RAWMEMCHR - fi - gl_STRING_MODULE_INDICATOR([rawmemchr]) -+ gl_FUNC_READLINK -+ if test $HAVE_READLINK = 0 || test $REPLACE_READLINK = 1; then -+ AC_LIBOBJ([readlink]) -+ gl_PREREQ_READLINK -+ fi -+ gl_UNISTD_MODULE_INDICATOR([readlink]) - gl_FUNC_REALLOC_POSIX - if test $REPLACE_REALLOC = 1; then - AC_LIBOBJ([realloc]) -@@ -309,6 +332,12 @@ AC_DEFUN([gl_INIT], - fi - gl_UNISTD_MODULE_INDICATOR([sleep]) - gt_TYPE_SSIZE_T -+ gl_FUNC_STAT -+ if test $REPLACE_STAT = 1; then -+ AC_LIBOBJ([stat]) -+ gl_PREREQ_STAT -+ fi -+ gl_SYS_STAT_MODULE_INDICATOR([stat]) - gl_STDALIGN_H - AM_STDBOOL_H - gl_STDDEF_H -@@ -355,9 +384,14 @@ AC_DEFUN([gl_INIT], - gl_PREREQ_STRNLEN - fi - gl_STRING_MODULE_INDICATOR([strnlen]) -+ gl_HEADER_SYS_STAT_H -+ AC_PROG_MKDIR_P -+ gl_HEADER_SYS_TIME_H -+ AC_PROG_MKDIR_P - gl_SYS_TYPES_H - AC_PROG_MKDIR_P - gl_SYSEXITS -+ gl_HEADER_TIME_H - gl_UNISTD_H - gl_LIBUNISTRING_LIBHEADER([0.9], [unitypes.h]) - gl_LIBUNISTRING_LIBHEADER([0.9], [uniwidth.h]) -@@ -562,6 +596,7 @@ AC_DEFUN([gl_FILE_LIST], [ - lib/getopt1.c - lib/getopt_int.h - lib/gettext.h -+ lib/gettimeofday.c - lib/intprops.h - lib/itold.c - lib/langinfo.in.h -@@ -587,6 +622,7 @@ AC_DEFUN([gl_FILE_LIST], [ - lib/msvc-nothrow.c - lib/msvc-nothrow.h - lib/nl_langinfo.c -+ lib/pathmax.h - lib/printf-args.c - lib/printf-args.h - lib/printf-parse.c -@@ -595,6 +631,7 @@ AC_DEFUN([gl_FILE_LIST], [ - lib/progname.h - lib/rawmemchr.c - lib/rawmemchr.valgrind -+ lib/readlink.c - lib/realloc.c - lib/ref-add.sin - lib/ref-del.sin -@@ -606,6 +643,7 @@ AC_DEFUN([gl_FILE_LIST], [ - lib/regexec.c - lib/size_max.h - lib/sleep.c -+ lib/stat.c - lib/stdalign.in.h - lib/stdbool.in.h - lib/stddef.in.h -@@ -627,8 +665,11 @@ AC_DEFUN([gl_FILE_LIST], [ - lib/strnlen.c - lib/strnlen1.c - lib/strnlen1.h -+ lib/sys_stat.in.h -+ lib/sys_time.in.h - lib/sys_types.in.h - lib/sysexits.in.h -+ lib/time.in.h - lib/unistd.c - lib/unistd.in.h - lib/unitypes.in.h -@@ -667,6 +708,7 @@ AC_DEFUN([gl_FILE_LIST], [ - m4/getline.m4 - m4/getopt.m4 - m4/gettext.m4 -+ m4/gettimeofday.m4 - m4/glibc2.m4 - m4/glibc21.m4 - m4/gnulib-common.m4 -@@ -681,6 +723,7 @@ AC_DEFUN([gl_FILE_LIST], [ - m4/inttypes-pri.m4 - m4/inttypes_h.m4 - m4/langinfo_h.m4 -+ m4/largefile.m4 - m4/lcmessage.m4 - m4/lib-ld.m4 - m4/lib-link.m4 -@@ -712,16 +755,19 @@ AC_DEFUN([gl_FILE_LIST], [ - m4/nls.m4 - m4/nocrash.m4 - m4/off_t.m4 -+ m4/pathmax.m4 - m4/po.m4 - m4/printf-posix.m4 - m4/printf.m4 - m4/progtest.m4 - m4/rawmemchr.m4 -+ m4/readlink.m4 - m4/realloc.m4 - m4/regex.m4 - m4/size_max.m4 - m4/sleep.m4 - m4/ssize_t.m4 -+ m4/stat.m4 - m4/stdalign.m4 - m4/stdbool.m4 - m4/stddef_h.m4 -@@ -737,9 +783,12 @@ AC_DEFUN([gl_FILE_LIST], [ - m4/strndup.m4 - m4/strnlen.m4 - m4/sys_socket_h.m4 -+ m4/sys_stat_h.m4 -+ m4/sys_time_h.m4 - m4/sys_types_h.m4 - m4/sysexits.m4 - m4/threadlib.m4 -+ m4/time_h.m4 - m4/uintmax_t.m4 - m4/unistd_h.m4 - m4/vasnprintf.m4 -diff --git a/m4/largefile.m4 b/m4/largefile.m4 -new file mode 100644 -index 00000000000..a1b564ad9af ---- /dev/null -+++ b/m4/largefile.m4 -@@ -0,0 +1,146 @@ -+# Enable large files on systems where this is not the default. -+ -+# Copyright 1992-1996, 1998-2014 Free Software Foundation, Inc. -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# The following implementation works around a problem in autoconf <= 2.69; -+# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, -+# or configures them incorrectly in some cases. -+m4_version_prereq([2.70], [] ,[ -+ -+# _AC_SYS_LARGEFILE_TEST_INCLUDES -+# ------------------------------- -+m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], -+[@%:@include -+ /* Check that off_t can represent 2**63 - 1 correctly. -+ We can't simply define LARGE_OFF_T to be 9223372036854775807, -+ since some C++ compilers masquerading as C compilers -+ incorrectly reject 9223372036854775807. */ -+@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) -+ int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721 -+ && LARGE_OFF_T % 2147483647 == 1) -+ ? 1 : -1]];[]dnl -+]) -+ -+ -+# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, -+# CACHE-VAR, -+# DESCRIPTION, -+# PROLOGUE, [FUNCTION-BODY]) -+# -------------------------------------------------------- -+m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE], -+[AC_CACHE_CHECK([for $1 value needed for large files], [$3], -+[while :; do -+ m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])( -+ [AC_LANG_PROGRAM([$5], [$6])], -+ [$3=no; break]) -+ m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])( -+ [AC_LANG_PROGRAM([@%:@define $1 $2 -+$5], [$6])], -+ [$3=$2; break]) -+ $3=unknown -+ break -+done]) -+case $$3 in #( -+ no | unknown) ;; -+ *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);; -+esac -+rm -rf conftest*[]dnl -+])# _AC_SYS_LARGEFILE_MACRO_VALUE -+ -+ -+# AC_SYS_LARGEFILE -+# ---------------- -+# By default, many hosts won't let programs access large files; -+# one must use special compiler options to get large-file access to work. -+# For more details about this brain damage please see: -+# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html -+AC_DEFUN([AC_SYS_LARGEFILE], -+[AC_ARG_ENABLE(largefile, -+ [ --disable-largefile omit support for large files]) -+if test "$enable_largefile" != no; then -+ -+ AC_CACHE_CHECK([for special C compiler options needed for large files], -+ ac_cv_sys_largefile_CC, -+ [ac_cv_sys_largefile_CC=no -+ if test "$GCC" != yes; then -+ ac_save_CC=$CC -+ while :; do -+ # IRIX 6.2 and later do not support large files by default, -+ # so use the C compiler's -n32 option if that helps. -+ AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])]) -+ AC_COMPILE_IFELSE([], [break]) -+ CC="$CC -n32" -+ AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break]) -+ break -+ done -+ CC=$ac_save_CC -+ rm -f conftest.$ac_ext -+ fi]) -+ if test "$ac_cv_sys_largefile_CC" != no; then -+ CC=$CC$ac_cv_sys_largefile_CC -+ fi -+ -+ _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, -+ ac_cv_sys_file_offset_bits, -+ [Number of bits in a file offset, on hosts where this is settable.], -+ [_AC_SYS_LARGEFILE_TEST_INCLUDES]) -+ if test $ac_cv_sys_file_offset_bits = unknown; then -+ _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, -+ ac_cv_sys_large_files, -+ [Define for large files, on AIX-style hosts.], -+ [_AC_SYS_LARGEFILE_TEST_INCLUDES]) -+ fi -+ -+ AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1], -+ [Enable large inode numbers on Mac OS X 10.5.]) -+fi -+])# AC_SYS_LARGEFILE -+])# m4_version_prereq 2.70 -+ -+# Enable large files on systems where this is implemented by Gnulib, not by the -+# system headers. -+# Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib -+# overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively. -+AC_DEFUN([gl_LARGEFILE], -+[ -+ AC_REQUIRE([AC_CANONICAL_HOST]) -+ case "$host_os" in -+ mingw*) -+ dnl Native Windows. -+ dnl mingw64 defines off_t to a 64-bit type already, if -+ dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE. -+ AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1]; -+ ]], -+ [[]])], -+ [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no]) -+ ]) -+ if test $gl_cv_type_off_t_64 = no; then -+ WINDOWS_64_BIT_OFF_T=1 -+ else -+ WINDOWS_64_BIT_OFF_T=0 -+ fi -+ dnl But all native Windows platforms (including mingw64) have a 32-bit -+ dnl st_size member in 'struct stat'. -+ WINDOWS_64_BIT_ST_SIZE=1 -+ ;; -+ *) -+ dnl Nothing to do on gnulib's side. -+ dnl A 64-bit off_t is -+ dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX, -+ dnl OSF/1, Cygwin, -+ dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on -+ dnl glibc, HP-UX, Solaris, -+ dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX, -+ dnl - impossible to achieve on Minix 3.1.8. -+ WINDOWS_64_BIT_OFF_T=0 -+ WINDOWS_64_BIT_ST_SIZE=0 -+ ;; -+ esac -+]) -diff --git a/m4/pathmax.m4 b/m4/pathmax.m4 -new file mode 100644 -index 00000000000..114f91f04b5 ---- /dev/null -+++ b/m4/pathmax.m4 -@@ -0,0 +1,42 @@ -+# pathmax.m4 serial 10 -+dnl Copyright (C) 2002-2003, 2005-2006, 2009-2014 Free Software Foundation, -+dnl Inc. -+dnl This file is free software; the Free Software Foundation -+dnl gives unlimited permission to copy and/or distribute it, -+dnl with or without modifications, as long as this notice is preserved. -+ -+AC_DEFUN([gl_PATHMAX], -+[ -+ dnl Prerequisites of lib/pathmax.h. -+ AC_CHECK_HEADERS_ONCE([sys/param.h]) -+]) -+ -+# Expands to a piece of C program that defines PATH_MAX in the same way as -+# "pathmax.h" will do. -+AC_DEFUN([gl_PATHMAX_SNIPPET], [[ -+/* Arrange to define PATH_MAX, like "pathmax.h" does. */ -+#if HAVE_UNISTD_H -+# include -+#endif -+#include -+#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN -+# include -+#endif -+#if !defined PATH_MAX && defined MAXPATHLEN -+# define PATH_MAX MAXPATHLEN -+#endif -+#ifdef __hpux -+# undef PATH_MAX -+# define PATH_MAX 1024 -+#endif -+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -+# undef PATH_MAX -+# define PATH_MAX 260 -+#endif -+]]) -+ -+# Prerequisites of gl_PATHMAX_SNIPPET. -+AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ], -+[ -+ AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h]) -+]) -diff --git a/m4/readlink.m4 b/m4/readlink.m4 -new file mode 100644 -index 00000000000..f9ce868c2e4 ---- /dev/null -+++ b/m4/readlink.m4 -@@ -0,0 +1,71 @@ -+# readlink.m4 serial 12 -+dnl Copyright (C) 2003, 2007, 2009-2014 Free Software Foundation, Inc. -+dnl This file is free software; the Free Software Foundation -+dnl gives unlimited permission to copy and/or distribute it, -+dnl with or without modifications, as long as this notice is preserved. -+ -+AC_DEFUN([gl_FUNC_READLINK], -+[ -+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) -+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles -+ AC_CHECK_FUNCS_ONCE([readlink]) -+ if test $ac_cv_func_readlink = no; then -+ HAVE_READLINK=0 -+ else -+ AC_CACHE_CHECK([whether readlink signature is correct], -+ [gl_cv_decl_readlink_works], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ /* Cause compilation failure if original declaration has wrong type. */ -+ ssize_t readlink (const char *, char *, size_t);]])], -+ [gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])]) -+ dnl Solaris 9 ignores trailing slash. -+ dnl FreeBSD 7.2 dereferences only one level of links with trailing slash. -+ AC_CACHE_CHECK([whether readlink handles trailing slash correctly], -+ [gl_cv_func_readlink_works], -+ [# We have readlink, so assume ln -s works. -+ ln -s conftest.no-such conftest.link -+ ln -s conftest.link conftest.lnk2 -+ AC_RUN_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+]], [[char buf[20]; -+ return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])], -+ [gl_cv_func_readlink_works=yes], [gl_cv_func_readlink_works=no], -+ [case "$host_os" in -+ # Guess yes on glibc systems. -+ *-gnu*) gl_cv_func_readlink_works="guessing yes" ;; -+ # If we don't know, assume the worst. -+ *) gl_cv_func_readlink_works="guessing no" ;; -+ esac -+ ]) -+ rm -f conftest.link conftest.lnk2]) -+ case "$gl_cv_func_readlink_works" in -+ *yes) -+ if test "$gl_cv_decl_readlink_works" != yes; then -+ REPLACE_READLINK=1 -+ fi -+ ;; -+ *) -+ AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink -+ fails to recognize a trailing slash.]) -+ REPLACE_READLINK=1 -+ ;; -+ esac -+ fi -+]) -+ -+# Like gl_FUNC_READLINK, except prepare for separate compilation -+# (no REPLACE_READLINK, no AC_LIBOBJ). -+AC_DEFUN([gl_FUNC_READLINK_SEPARATE], -+[ -+ AC_CHECK_FUNCS_ONCE([readlink]) -+ gl_PREREQ_READLINK -+]) -+ -+# Prerequisites of lib/readlink.c. -+AC_DEFUN([gl_PREREQ_READLINK], -+[ -+ : -+]) -diff --git a/m4/stat.m4 b/m4/stat.m4 -new file mode 100644 -index 00000000000..1ae327b3684 ---- /dev/null -+++ b/m4/stat.m4 -@@ -0,0 +1,71 @@ -+# serial 11 -+ -+# Copyright (C) 2009-2014 Free Software Foundation, Inc. -+# -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+AC_DEFUN([gl_FUNC_STAT], -+[ -+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles -+ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) -+ AC_CHECK_FUNCS_ONCE([lstat]) -+ dnl mingw is the only known platform where stat(".") and stat("./") differ -+ AC_CACHE_CHECK([whether stat handles trailing slashes on directories], -+ [gl_cv_func_stat_dir_slash], -+ [AC_RUN_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])], -+ [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no], -+ [case $host_os in -+ mingw*) gl_cv_func_stat_dir_slash="guessing no";; -+ *) gl_cv_func_stat_dir_slash="guessing yes";; -+ esac])]) -+ dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/"). -+ dnl (For mingw, this is due to a broken stat() override in libmingwex.a.) -+ dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/"). -+ AC_CACHE_CHECK([whether stat handles trailing slashes on files], -+ [gl_cv_func_stat_file_slash], -+ [touch conftest.tmp -+ # Assume that if we have lstat, we can also check symlinks. -+ if test $ac_cv_func_lstat = yes; then -+ ln -s conftest.tmp conftest.lnk -+ fi -+ AC_RUN_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+]], [[int result = 0; -+ struct stat st; -+ if (!stat ("conftest.tmp/", &st)) -+ result |= 1; -+#if HAVE_LSTAT -+ if (!stat ("conftest.lnk/", &st)) -+ result |= 2; -+#endif -+ return result; -+ ]])], -+ [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no], -+ [case "$host_os" in -+ # Guess yes on glibc systems. -+ *-gnu*) gl_cv_func_stat_file_slash="guessing yes" ;; -+ # If we don't know, assume the worst. -+ *) gl_cv_func_stat_file_slash="guessing no" ;; -+ esac -+ ]) -+ rm -f conftest.tmp conftest.lnk]) -+ case $gl_cv_func_stat_dir_slash in -+ *no) REPLACE_STAT=1 -+ AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs -+ help when passed a directory name with a trailing slash]);; -+ esac -+ case $gl_cv_func_stat_file_slash in -+ *no) REPLACE_STAT=1 -+ AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs -+ help when passed a file name with a trailing slash]);; -+ esac -+]) -+ -+# Prerequisites of lib/stat.c. -+AC_DEFUN([gl_PREREQ_STAT], [:]) -diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 -new file mode 100644 -index 00000000000..eaa7642ba31 ---- /dev/null -+++ b/m4/sys_stat_h.m4 -@@ -0,0 +1,96 @@ -+# sys_stat_h.m4 serial 28 -*- Autoconf -*- -+dnl Copyright (C) 2006-2014 Free Software Foundation, Inc. -+dnl This file is free software; the Free Software Foundation -+dnl gives unlimited permission to copy and/or distribute it, -+dnl with or without modifications, as long as this notice is preserved. -+ -+dnl From Eric Blake. -+dnl Provide a GNU-like . -+ -+AC_DEFUN([gl_HEADER_SYS_STAT_H], -+[ -+ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) -+ -+ dnl Check for broken stat macros. -+ AC_REQUIRE([AC_HEADER_STAT]) -+ -+ gl_CHECK_NEXT_HEADERS([sys/stat.h]) -+ -+ dnl Ensure the type mode_t gets defined. -+ AC_REQUIRE([AC_TYPE_MODE_T]) -+ -+ dnl Whether to override 'struct stat'. -+ m4_ifdef([gl_LARGEFILE], [ -+ AC_REQUIRE([gl_LARGEFILE]) -+ ], [ -+ WINDOWS_64_BIT_ST_SIZE=0 -+ ]) -+ AC_SUBST([WINDOWS_64_BIT_ST_SIZE]) -+ if test $WINDOWS_64_BIT_ST_SIZE = 1; then -+ AC_DEFINE([_GL_WINDOWS_64_BIT_ST_SIZE], [1], -+ [Define to 1 if Gnulib overrides 'struct stat' on Windows so that -+ struct stat.st_size becomes 64-bit.]) -+ fi -+ -+ dnl Define types that are supposed to be defined in or -+ dnl . -+ AC_CHECK_TYPE([nlink_t], [], -+ [AC_DEFINE([nlink_t], [int], -+ [Define to the type of st_nlink in struct stat, or a supertype.])], -+ [#include -+ #include ]) -+ -+ dnl Check for declarations of anything we want to poison if the -+ dnl corresponding gnulib module is not in use. -+ gl_WARN_ON_USE_PREPARE([[#include -+ ]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat -+ mknod mknodat stat utimensat]) -+]) # gl_HEADER_SYS_STAT_H -+ -+AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR], -+[ -+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. -+ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) -+ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) -+ dnl Define it also as a C macro, for the benefit of the unit tests. -+ gl_MODULE_INDICATOR_FOR_TESTS([$1]) -+]) -+ -+AC_DEFUN([gl_SYS_STAT_H_DEFAULTS], -+[ -+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR -+ GNULIB_FCHMODAT=0; AC_SUBST([GNULIB_FCHMODAT]) -+ GNULIB_FSTAT=0; AC_SUBST([GNULIB_FSTAT]) -+ GNULIB_FSTATAT=0; AC_SUBST([GNULIB_FSTATAT]) -+ GNULIB_FUTIMENS=0; AC_SUBST([GNULIB_FUTIMENS]) -+ GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD]) -+ GNULIB_LSTAT=0; AC_SUBST([GNULIB_LSTAT]) -+ GNULIB_MKDIRAT=0; AC_SUBST([GNULIB_MKDIRAT]) -+ GNULIB_MKFIFO=0; AC_SUBST([GNULIB_MKFIFO]) -+ GNULIB_MKFIFOAT=0; AC_SUBST([GNULIB_MKFIFOAT]) -+ GNULIB_MKNOD=0; AC_SUBST([GNULIB_MKNOD]) -+ GNULIB_MKNODAT=0; AC_SUBST([GNULIB_MKNODAT]) -+ GNULIB_STAT=0; AC_SUBST([GNULIB_STAT]) -+ GNULIB_UTIMENSAT=0; AC_SUBST([GNULIB_UTIMENSAT]) -+ dnl Assume proper GNU behavior unless another module says otherwise. -+ HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT]) -+ HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT]) -+ HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS]) -+ HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD]) -+ HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT]) -+ HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT]) -+ HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO]) -+ HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT]) -+ HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD]) -+ HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT]) -+ HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT]) -+ REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT]) -+ REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT]) -+ REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS]) -+ REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT]) -+ REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR]) -+ REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO]) -+ REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD]) -+ REPLACE_STAT=0; AC_SUBST([REPLACE_STAT]) -+ REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT]) -+]) -diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4 -new file mode 100644 -index 00000000000..5c79300f8ec ---- /dev/null -+++ b/m4/sys_time_h.m4 -@@ -0,0 +1,110 @@ -+# Configure a replacement for . -+# serial 8 -+ -+# Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc. -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# Written by Paul Eggert and Martin Lambers. -+ -+AC_DEFUN([gl_HEADER_SYS_TIME_H], -+[ -+ dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement -+ dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1 -+ dnl statements that occur in other macros. -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY]) -+]) -+ -+AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], -+[ -+ AC_REQUIRE([AC_C_RESTRICT]) -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) -+ AC_CHECK_HEADERS_ONCE([sys/time.h]) -+ gl_CHECK_NEXT_HEADERS([sys/time.h]) -+ -+ if test $ac_cv_header_sys_time_h != yes; then -+ HAVE_SYS_TIME_H=0 -+ fi -+ -+ dnl On native Windows with MSVC, 'struct timeval' is defined in -+ dnl only. So include that header in the list. -+ gl_PREREQ_SYS_H_WINSOCK2 -+ AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#if HAVE_SYS_TIME_H -+ #include -+ #endif -+ #include -+ #if HAVE_WINSOCK2_H -+ # include -+ #endif -+ ]], -+ [[static struct timeval x; x.tv_sec = x.tv_usec;]])], -+ [gl_cv_sys_struct_timeval=yes], -+ [gl_cv_sys_struct_timeval=no]) -+ ]) -+ if test $gl_cv_sys_struct_timeval != yes; then -+ HAVE_STRUCT_TIMEVAL=0 -+ else -+ dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined -+ dnl (in and for mingw64, in only -+ dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is -+ dnl smaller than the 'time_t' type mandated by POSIX. -+ dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but -+ dnl that is good enough. -+ AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member], -+ [gl_cv_sys_struct_timeval_tv_sec], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#if HAVE_SYS_TIME_H -+ #include -+ #endif -+ #include -+ #if HAVE_WINSOCK2_H -+ # include -+ #endif -+ ]], -+ [[static struct timeval x; -+ typedef int verify_tv_sec_type[ -+ sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1 -+ ]; -+ ]])], -+ [gl_cv_sys_struct_timeval_tv_sec=yes], -+ [gl_cv_sys_struct_timeval_tv_sec=no]) -+ ]) -+ if test $gl_cv_sys_struct_timeval_tv_sec != yes; then -+ REPLACE_STRUCT_TIMEVAL=1 -+ fi -+ fi -+ -+ dnl Check for declarations of anything we want to poison if the -+ dnl corresponding gnulib module is not in use. -+ gl_WARN_ON_USE_PREPARE([[ -+#if HAVE_SYS_TIME_H -+# include -+#endif -+#include -+ ]], [gettimeofday]) -+]) -+ -+AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR], -+[ -+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. -+ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) -+ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) -+ dnl Define it also as a C macro, for the benefit of the unit tests. -+ gl_MODULE_INDICATOR_FOR_TESTS([$1]) -+]) -+ -+AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS], -+[ -+ GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY]) -+ dnl Assume POSIX behavior unless another module says otherwise. -+ HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY]) -+ HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL]) -+ HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H]) -+ REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY]) -+ REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL]) -+]) -diff --git a/m4/time_h.m4 b/m4/time_h.m4 -new file mode 100644 -index 00000000000..9852778f9a5 ---- /dev/null -+++ b/m4/time_h.m4 -@@ -0,0 +1,118 @@ -+# Configure a more-standard replacement for . -+ -+# Copyright (C) 2000-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc. -+ -+# serial 8 -+ -+# This file is free software; the Free Software Foundation -+# gives unlimited permission to copy and/or distribute it, -+# with or without modifications, as long as this notice is preserved. -+ -+# Written by Paul Eggert and Jim Meyering. -+ -+AC_DEFUN([gl_HEADER_TIME_H], -+[ -+ dnl Use AC_REQUIRE here, so that the default behavior below is expanded -+ dnl once only, before all statements that occur in other macros. -+ AC_REQUIRE([gl_HEADER_TIME_H_BODY]) -+]) -+ -+AC_DEFUN([gl_HEADER_TIME_H_BODY], -+[ -+ AC_REQUIRE([AC_C_RESTRICT]) -+ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) -+ gl_NEXT_HEADERS([time.h]) -+ AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) -+]) -+ -+dnl Check whether 'struct timespec' is declared -+dnl in time.h, sys/time.h, or pthread.h. -+ -+AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], -+[ -+ AC_CHECK_HEADERS_ONCE([sys/time.h]) -+ AC_CACHE_CHECK([for struct timespec in ], -+ [gl_cv_sys_struct_timespec_in_time_h], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ ]], -+ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], -+ [gl_cv_sys_struct_timespec_in_time_h=yes], -+ [gl_cv_sys_struct_timespec_in_time_h=no])]) -+ -+ TIME_H_DEFINES_STRUCT_TIMESPEC=0 -+ SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 -+ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 -+ if test $gl_cv_sys_struct_timespec_in_time_h = yes; then -+ TIME_H_DEFINES_STRUCT_TIMESPEC=1 -+ else -+ AC_CACHE_CHECK([for struct timespec in ], -+ [gl_cv_sys_struct_timespec_in_sys_time_h], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ ]], -+ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], -+ [gl_cv_sys_struct_timespec_in_sys_time_h=yes], -+ [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) -+ if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then -+ SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 -+ else -+ AC_CACHE_CHECK([for struct timespec in ], -+ [gl_cv_sys_struct_timespec_in_pthread_h], -+ [AC_COMPILE_IFELSE( -+ [AC_LANG_PROGRAM( -+ [[#include -+ ]], -+ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], -+ [gl_cv_sys_struct_timespec_in_pthread_h=yes], -+ [gl_cv_sys_struct_timespec_in_pthread_h=no])]) -+ if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then -+ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 -+ fi -+ fi -+ fi -+ AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) -+ AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) -+ AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) -+]) -+ -+AC_DEFUN([gl_TIME_MODULE_INDICATOR], -+[ -+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. -+ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) -+ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) -+ dnl Define it also as a C macro, for the benefit of the unit tests. -+ gl_MODULE_INDICATOR_FOR_TESTS([$1]) -+]) -+ -+AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], -+[ -+ GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) -+ GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) -+ GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) -+ GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) -+ GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) -+ dnl Assume proper GNU behavior unless another module says otherwise. -+ HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) -+ HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) -+ HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) -+ HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) -+ dnl If another module says to replace or to not replace, do that. -+ dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; -+ dnl this lets maintainers check for portability. -+ REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) -+ REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) -+ REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) -+ REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) -+ -+ dnl Hack so that the time module doesn't depend on the sys_time module. -+ dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent. -+ : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY]) -+ dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME -+ dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier -+ dnl is no longer a big deal. -+ REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME]) -+ REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME]) -+]) diff --git a/0207-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch b/0207-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch new file mode 100644 index 0000000..5063449 --- /dev/null +++ b/0207-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Mon, 10 Feb 2014 16:13:10 -0500 +Subject: [PATCH] Switch to use APM Mustang device tree, for hardware testing. + +Signed-off-by: David A. Marlin +--- + 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 2e533ffd8aa..4e9a6308b3c 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -254,8 +254,8 @@ while [ "x$list" != "x" ] ; do + + fdt= + for i in "dtb-${version}" "dtb-${alt_version}"; do +- if test -e "${dirname}/${i}/foundation-v8.dtb" ; then +- fdt="${i}/foundation-v8.dtb" ++ if test -e "${dirname}/${i}/apm-mustang.dtb" ; then ++ fdt="${i}/apm-mustang.dtb" + break + fi + done diff --git a/0208-Make-editenv-chase-symlinks-including-those-across-d.patch b/0208-Make-editenv-chase-symlinks-including-those-across-d.patch deleted file mode 100644 index 73e316e..0000000 --- a/0208-Make-editenv-chase-symlinks-including-those-across-d.patch +++ /dev/null @@ -1,102 +0,0 @@ -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 | 9 +++++++++ - util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- - 2 files changed, 53 insertions(+), 2 deletions(-) - -diff --git a/Makefile.util.def b/Makefile.util.def -index c7b775bce73..d08713b5500 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -231,8 +231,17 @@ 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 = 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 c6f8d2298c3..d8d1dad6ab9 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); - -@@ -59,7 +60,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/0208-Use-the-default-device-tree-from-the-grub-default-fi.patch b/0208-Use-the-default-device-tree-from-the-grub-default-fi.patch new file mode 100644 index 0000000..9b14a54 --- /dev/null +++ b/0208-Use-the-default-device-tree-from-the-grub-default-fi.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Wed, 12 Feb 2014 14:54:04 -0500 +Subject: [PATCH] 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 | 4 ++-- + 2 files changed, 4 insertions(+), 3 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index b0a8626dd1c..f68d4925ee6 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 4e9a6308b3c..c548d989b2e 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -254,8 +254,8 @@ while [ "x$list" != "x" ] ; do + + fdt= + for i in "dtb-${version}" "dtb-${alt_version}"; do +- if test -e "${dirname}/${i}/apm-mustang.dtb" ; then +- fdt="${i}/apm-mustang.dtb" ++ if test -f "${dirname}/${i}/${GRUB_DEFAULT_DTB}" ; then ++ fdt="${i}/${GRUB_DEFAULT_DTB}" + break + fi + done diff --git a/0209-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch b/0209-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch deleted file mode 100644 index bbe37b8..0000000 --- a/0209-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch +++ /dev/null @@ -1,29 +0,0 @@ -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 c548d989b2e..03ea8460bfd 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/0209-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0209-reopen-SNP-protocol-for-exclusive-use-by-grub.patch new file mode 100644 index 0000000..fb2875b --- /dev/null +++ b/0209-reopen-SNP-protocol-for-exclusive-use-by-grub.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Sat, 15 Feb 2014 15:10:22 -0500 +Subject: [PATCH] reopen SNP protocol for exclusive use by grub + +--- + grub-core/net/drivers/efi/efinet.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 5388f952ba9..ea0e0ca360e 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -330,6 +330,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + { + struct grub_net_card *card; + grub_efi_device_path_t *dp; ++ grub_efi_simple_network_t *net; + + dp = grub_efi_get_device_path (hnd); + if (! dp) +@@ -383,6 +384,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + &pxe_mode->dhcp_ack, + sizeof (pxe_mode->dhcp_ack), + 1, device, path); ++ net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, ++ GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); ++ if (net) { ++ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED ++ && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) ++ continue; ++ ++ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) ++ continue; ++ ++ if (net->mode->state == GRUB_EFI_NETWORK_STARTED ++ && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) ++ continue; ++ card->efi_net = net; ++ } + return; + } + } diff --git a/0210-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch b/0210-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch deleted file mode 100644 index fc29633..0000000 --- a/0210-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch +++ /dev/null @@ -1,30 +0,0 @@ -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/0210-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0210-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch new file mode 100644 index 0000000..4238b7d --- /dev/null +++ b/0210-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch @@ -0,0 +1,51 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 4 Mar 2016 15:13:59 -0500 +Subject: [PATCH] Revert "reopen SNP protocol for exclusive use by grub" + +This reverts commit a3f2c756ce34c9666bddef35e3b3b85ccecdcffc , which is +obsoleted by these: + +49426e9 efinet: open Simple Network Protocol exclusively +f348aee efinet: enable hardware filters when opening interface +c52ae40 efinet: skip virtual IPv4 and IPv6 devices when enumerating cards + +Signed-off-by: Peter Jones +--- + grub-core/net/drivers/efi/efinet.c | 16 ---------------- + 1 file changed, 16 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index ea0e0ca360e..5388f952ba9 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -330,7 +330,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + { + struct grub_net_card *card; + grub_efi_device_path_t *dp; +- grub_efi_simple_network_t *net; + + dp = grub_efi_get_device_path (hnd); + if (! dp) +@@ -384,21 +383,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + &pxe_mode->dhcp_ack, + sizeof (pxe_mode->dhcp_ack), + 1, device, path); +- net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, +- GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); +- if (net) { +- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED +- && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) +- continue; +- +- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) +- continue; +- +- if (net->mode->state == GRUB_EFI_NETWORK_STARTED +- && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) +- continue; +- card->efi_net = net; +- } + return; + } + } diff --git a/0211-Add-grub_util_readlink.patch b/0211-Add-grub_util_readlink.patch new file mode 100644 index 0000000..6ea7df1 --- /dev/null +++ b/0211-Add-grub_util_readlink.patch @@ -0,0 +1,3731 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 3 Sep 2014 10:01:03 -0400 +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/gnulib/gettimeofday.c | 154 +++++++ + grub-core/gnulib/readlink.c | 74 ++++ + grub-core/gnulib/stat.c | 138 +++++++ + grub-core/osdep/windows/hostdisk.c | 6 + + grub-core/gnulib/pathmax.h | 83 ++++ + grub-core/gnulib/sys_stat.in.h | 732 ++++++++++++++++++++++++++++++++++ + grub-core/gnulib/sys_time.in.h | 213 ++++++++++ + grub-core/gnulib/sys_types.in.h | 2 + + grub-core/gnulib/time.h | 586 +++++++++++++++++++++++++++ + grub-core/gnulib/time.in.h | 274 +++++++++++++ + include/grub/osdep/hostfile_aros.h | 6 + + include/grub/osdep/hostfile_unix.h | 6 + + include/grub/osdep/hostfile_windows.h | 2 + + grub-core/gnulib/Makefile.am | 177 +++++++- + m4/gettimeofday.m4 | 138 +++++++ + m4/gnulib-cache.m4 | 3 +- + m4/gnulib-comp.m4 | 49 +++ + m4/largefile.m4 | 146 +++++++ + m4/pathmax.m4 | 42 ++ + m4/readlink.m4 | 71 ++++ + m4/stat.m4 | 71 ++++ + m4/sys_stat_h.m4 | 96 +++++ + m4/sys_time_h.m4 | 110 +++++ + m4/time_h.m4 | 118 ++++++ + 24 files changed, 3295 insertions(+), 2 deletions(-) + create mode 100644 grub-core/gnulib/gettimeofday.c + create mode 100644 grub-core/gnulib/readlink.c + create mode 100644 grub-core/gnulib/stat.c + create mode 100644 grub-core/gnulib/pathmax.h + create mode 100644 grub-core/gnulib/sys_stat.in.h + create mode 100644 grub-core/gnulib/sys_time.in.h + create mode 100644 grub-core/gnulib/time.h + create mode 100644 grub-core/gnulib/time.in.h + create mode 100644 m4/gettimeofday.m4 + create mode 100644 m4/largefile.m4 + create mode 100644 m4/pathmax.m4 + create mode 100644 m4/readlink.m4 + create mode 100644 m4/stat.m4 + create mode 100644 m4/sys_stat_h.m4 + create mode 100644 m4/sys_time_h.m4 + create mode 100644 m4/time_h.m4 + +diff --git a/grub-core/gnulib/gettimeofday.c b/grub-core/gnulib/gettimeofday.c +new file mode 100644 +index 00000000000..8b2058e8c87 +--- /dev/null ++++ b/grub-core/gnulib/gettimeofday.c +@@ -0,0 +1,154 @@ ++/* Provide gettimeofday for systems that don't have it or for which it's broken. ++ ++ Copyright (C) 2001-2003, 2005-2007, 2009-2014 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, 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 . */ ++ ++/* written by Jim Meyering */ ++ ++#include ++ ++/* Specification. */ ++#include ++ ++#include ++ ++#if HAVE_SYS_TIMEB_H ++# include ++#endif ++ ++#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME ++ ++/* Work around the bug in some systems whereby gettimeofday clobbers ++ the static buffer that localtime uses for its return value. The ++ gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has ++ this problem. The tzset replacement is necessary for at least ++ Solaris 2.5, 2.5.1, and 2.6. */ ++ ++static struct tm tm_zero_buffer; ++static struct tm *localtime_buffer_addr = &tm_zero_buffer; ++ ++# undef localtime ++extern struct tm *localtime (time_t const *); ++ ++# undef gmtime ++extern struct tm *gmtime (time_t const *); ++ ++/* This is a wrapper for localtime. It is used only on systems for which ++ gettimeofday clobbers the static buffer used for localtime's result. ++ ++ On the first call, record the address of the static buffer that ++ localtime uses for its result. */ ++ ++struct tm * ++rpl_localtime (time_t const *timep) ++{ ++ struct tm *tm = localtime (timep); ++ ++ if (localtime_buffer_addr == &tm_zero_buffer) ++ localtime_buffer_addr = tm; ++ ++ return tm; ++} ++ ++/* Same as above, since gmtime and localtime use the same buffer. */ ++struct tm * ++rpl_gmtime (time_t const *timep) ++{ ++ struct tm *tm = gmtime (timep); ++ ++ if (localtime_buffer_addr == &tm_zero_buffer) ++ localtime_buffer_addr = tm; ++ ++ return tm; ++} ++ ++#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */ ++ ++#if TZSET_CLOBBERS_LOCALTIME ++ ++# undef tzset ++extern void tzset (void); ++ ++/* This is a wrapper for tzset, for systems on which tzset may clobber ++ the static buffer used for localtime's result. */ ++void ++rpl_tzset (void) ++{ ++ /* Save and restore the contents of the buffer used for localtime's ++ result around the call to tzset. */ ++ struct tm save = *localtime_buffer_addr; ++ tzset (); ++ *localtime_buffer_addr = save; ++} ++#endif ++ ++/* This is a wrapper for gettimeofday. It is used only on systems ++ that lack this function, or whose implementation of this function ++ causes problems. */ ++ ++int ++gettimeofday (struct timeval *restrict tv, void *restrict tz) ++{ ++#undef gettimeofday ++#if HAVE_GETTIMEOFDAY ++# if GETTIMEOFDAY_CLOBBERS_LOCALTIME ++ /* Save and restore the contents of the buffer used for localtime's ++ result around the call to gettimeofday. */ ++ struct tm save = *localtime_buffer_addr; ++# endif ++ ++# if defined timeval /* 'struct timeval' overridden by gnulib? */ ++# undef timeval ++ struct timeval otv; ++ int result = gettimeofday (&otv, (struct timezone *) tz); ++ if (result == 0) ++ { ++ tv->tv_sec = otv.tv_sec; ++ tv->tv_usec = otv.tv_usec; ++ } ++# else ++ int result = gettimeofday (tv, (struct timezone *) tz); ++# endif ++ ++# if GETTIMEOFDAY_CLOBBERS_LOCALTIME ++ *localtime_buffer_addr = save; ++# endif ++ ++ return result; ++ ++#else ++ ++# if HAVE__FTIME ++ ++ struct _timeb timebuf; ++ _ftime (&timebuf); ++ tv->tv_sec = timebuf.time; ++ tv->tv_usec = timebuf.millitm * 1000; ++ ++# else ++ ++# if !defined OK_TO_USE_1S_CLOCK ++# error "Only 1-second nominal clock resolution found. Is that intended?" \ ++ "If so, compile with the -DOK_TO_USE_1S_CLOCK option." ++# endif ++ tv->tv_sec = time (NULL); ++ tv->tv_usec = 0; ++ ++# endif ++ ++ return 0; ++ ++#endif ++} +diff --git a/grub-core/gnulib/readlink.c b/grub-core/gnulib/readlink.c +new file mode 100644 +index 00000000000..4c496395176 +--- /dev/null ++++ b/grub-core/gnulib/readlink.c +@@ -0,0 +1,74 @@ ++/* Stub for readlink(). ++ Copyright (C) 2003-2007, 2009-2014 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 . */ ++ ++#include ++ ++/* Specification. */ ++#include ++ ++#include ++#include ++#include ++ ++#if !HAVE_READLINK ++ ++/* readlink() substitute for systems that don't have a readlink() function, ++ such as DJGPP 2.03 and mingw32. */ ++ ++ssize_t ++readlink (const char *name, char *buf _GL_UNUSED, ++ size_t bufsize _GL_UNUSED) ++{ ++ struct stat statbuf; ++ ++ /* In general we should use lstat() here, not stat(). But on platforms ++ without symbolic links, lstat() - if it exists - would be equivalent to ++ stat(), therefore we can use stat(). This saves us a configure check. */ ++ if (stat (name, &statbuf) >= 0) ++ errno = EINVAL; ++ return -1; ++} ++ ++#else /* HAVE_READLINK */ ++ ++# undef readlink ++ ++/* readlink() wrapper that uses correct types, for systems like cygwin ++ 1.5.x where readlink returns int, and which rejects trailing slash, ++ for Solaris 9. */ ++ ++ssize_t ++rpl_readlink (const char *name, char *buf, size_t bufsize) ++{ ++# if READLINK_TRAILING_SLASH_BUG ++ size_t len = strlen (name); ++ if (len && name[len - 1] == '/') ++ { ++ /* Even if name without the slash is a symlink to a directory, ++ both lstat() and stat() must resolve the trailing slash to ++ the directory rather than the symlink. We can therefore ++ safely use stat() to distinguish between EINVAL and ++ ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */ ++ struct stat st; ++ if (stat (name, &st) == 0) ++ errno = EINVAL; ++ return -1; ++ } ++# endif /* READLINK_TRAILING_SLASH_BUG */ ++ return readlink (name, buf, bufsize); ++} ++ ++#endif /* HAVE_READLINK */ +diff --git a/grub-core/gnulib/stat.c b/grub-core/gnulib/stat.c +new file mode 100644 +index 00000000000..35f4b0b1a51 +--- /dev/null ++++ b/grub-core/gnulib/stat.c +@@ -0,0 +1,138 @@ ++/* Work around platform bugs in stat. ++ Copyright (C) 2009-2014 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 . */ ++ ++/* written by Eric Blake */ ++ ++/* If the user's config.h happens to include , let it include only ++ the system's here, so that orig_stat doesn't recurse to ++ rpl_stat. */ ++#define __need_system_sys_stat_h ++#include ++ ++/* Get the original definition of stat. It might be defined as a macro. */ ++#include ++#include ++#undef __need_system_sys_stat_h ++ ++#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ++# if _GL_WINDOWS_64_BIT_ST_SIZE ++# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ ++# define stat _stati64 ++# define REPLACE_FUNC_STAT_DIR 1 ++# undef REPLACE_FUNC_STAT_FILE ++# elif REPLACE_FUNC_STAT_FILE ++/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a. ++ Bypass it. */ ++# define stat _stat ++# define REPLACE_FUNC_STAT_DIR 1 ++# undef REPLACE_FUNC_STAT_FILE ++# endif ++#endif ++ ++static int ++orig_stat (const char *filename, struct stat *buf) ++{ ++ return stat (filename, buf); ++} ++ ++/* Specification. */ ++/* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc ++ eliminates this include because of the preliminary #include ++ above. */ ++#include "sys/stat.h" ++ ++#include ++#include ++#include ++#include ++#include "dosname.h" ++#include "verify.h" ++ ++#if REPLACE_FUNC_STAT_DIR ++# include "pathmax.h" ++ /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also ++ have a constant PATH_MAX. */ ++# ifndef PATH_MAX ++# error "Please port this replacement to your platform" ++# endif ++#endif ++ ++/* Store information about NAME into ST. Work around bugs with ++ trailing slashes. Mingw has other bugs (such as st_ino always ++ being 0 on success) which this wrapper does not work around. But ++ at least this implementation provides the ability to emulate fchdir ++ correctly. */ ++ ++int ++rpl_stat (char const *name, struct stat *st) ++{ ++ int result = orig_stat (name, st); ++#if REPLACE_FUNC_STAT_FILE ++ /* Solaris 9 mistakenly succeeds when given a non-directory with a ++ trailing slash. */ ++ if (result == 0 && !S_ISDIR (st->st_mode)) ++ { ++ size_t len = strlen (name); ++ if (ISSLASH (name[len - 1])) ++ { ++ errno = ENOTDIR; ++ return -1; ++ } ++ } ++#endif /* REPLACE_FUNC_STAT_FILE */ ++#if REPLACE_FUNC_STAT_DIR ++ ++ if (result == -1 && errno == ENOENT) ++ { ++ /* Due to mingw's oddities, there are some directories (like ++ c:\) where stat() only succeeds with a trailing slash, and ++ other directories (like c:\windows) where stat() only ++ succeeds without a trailing slash. But we want the two to be ++ synonymous, since chdir() manages either style. Likewise, Mingw also ++ reports ENOENT for names longer than PATH_MAX, when we want ++ ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR. ++ Fortunately, mingw PATH_MAX is small enough for stack ++ allocation. */ ++ char fixed_name[PATH_MAX + 1] = {0}; ++ size_t len = strlen (name); ++ bool check_dir = false; ++ verify (PATH_MAX <= 4096); ++ if (PATH_MAX <= len) ++ errno = ENAMETOOLONG; ++ else if (len) ++ { ++ strcpy (fixed_name, name); ++ if (ISSLASH (fixed_name[len - 1])) ++ { ++ check_dir = true; ++ while (len && ISSLASH (fixed_name[len - 1])) ++ fixed_name[--len] = '\0'; ++ if (!len) ++ fixed_name[0] = '/'; ++ } ++ else ++ fixed_name[len++] = '/'; ++ result = orig_stat (fixed_name, st); ++ if (result == 0 && check_dir && !S_ISDIR (st->st_mode)) ++ { ++ result = -1; ++ errno = ENOTDIR; ++ } ++ } ++ } ++#endif /* REPLACE_FUNC_STAT_DIR */ ++ return result; ++} +diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c +index 85507af88e3..6f49df465d7 100644 +--- a/grub-core/osdep/windows/hostdisk.c ++++ b/grub-core/osdep/windows/hostdisk.c +@@ -353,6 +353,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/grub-core/gnulib/pathmax.h b/grub-core/gnulib/pathmax.h +new file mode 100644 +index 00000000000..33fc3553d75 +--- /dev/null ++++ b/grub-core/gnulib/pathmax.h +@@ -0,0 +1,83 @@ ++/* Define PATH_MAX somehow. Requires sys/types.h. ++ Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2014 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, 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 . */ ++ ++#ifndef _PATHMAX_H ++# define _PATHMAX_H ++ ++/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename, ++ including the terminating NUL byte. ++ ++ PATH_MAX is not defined on systems which have no limit on filename length, ++ such as GNU/Hurd. ++ ++ This file does *not* define PATH_MAX always. Programs that use this file ++ can handle the GNU/Hurd case in several ways: ++ - Either with a package-wide handling, or with a per-file handling, ++ - Either through a ++ #ifdef PATH_MAX ++ or through a fallback like ++ #ifndef PATH_MAX ++ # define PATH_MAX 8192 ++ #endif ++ or through a fallback like ++ #ifndef PATH_MAX ++ # define PATH_MAX pathconf ("/", _PC_PATH_MAX) ++ #endif ++ */ ++ ++# include ++ ++# include ++ ++# ifndef _POSIX_PATH_MAX ++# define _POSIX_PATH_MAX 256 ++# endif ++ ++/* Don't include sys/param.h if it already has been. */ ++# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN ++# include ++# endif ++ ++# if !defined PATH_MAX && defined MAXPATHLEN ++# define PATH_MAX MAXPATHLEN ++# endif ++ ++# ifdef __hpux ++/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename, ++ *not* including the terminating NUL byte, and is set to 1023. ++ Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is ++ not defined at all any more. */ ++# undef PATH_MAX ++# define PATH_MAX 1024 ++# endif ++ ++# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ++/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com, ++ section "Maximum Path Length Limitation", ++ ++ explains that the maximum size of a filename, including the terminating ++ NUL byte, is 260 = 3 + 256 + 1. ++ This is the same value as ++ - FILENAME_MAX in , ++ - _MAX_PATH in , ++ - MAX_PATH in . ++ Undefine the original value, because mingw's gets it wrong. */ ++# undef PATH_MAX ++# define PATH_MAX 260 ++# endif ++ ++#endif /* _PATHMAX_H */ +diff --git a/grub-core/gnulib/sys_stat.in.h b/grub-core/gnulib/sys_stat.in.h +new file mode 100644 +index 00000000000..b47a7ff0ae7 +--- /dev/null ++++ b/grub-core/gnulib/sys_stat.in.h +@@ -0,0 +1,732 @@ ++/* Provide a more complete sys/stat header file. ++ Copyright (C) 2005-2014 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, 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 . */ ++ ++/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */ ++ ++/* This file is supposed to be used on platforms where is ++ incomplete. It is intended to provide definitions and prototypes ++ needed by an application. Start with what the system provides. */ ++ ++#if __GNUC__ >= 3 ++@PRAGMA_SYSTEM_HEADER@ ++#endif ++@PRAGMA_COLUMNS@ ++ ++#if defined __need_system_sys_stat_h ++/* Special invocation convention. */ ++ ++#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@ ++ ++#else ++/* Normal invocation convention. */ ++ ++#ifndef _@GUARD_PREFIX@_SYS_STAT_H ++ ++/* Get nlink_t. ++ May also define off_t to a 64-bit type on native Windows. */ ++#include ++ ++/* Get struct timespec. */ ++#include ++ ++/* The include_next requires a split double-inclusion guard. */ ++#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@ ++ ++#ifndef _@GUARD_PREFIX@_SYS_STAT_H ++#define _@GUARD_PREFIX@_SYS_STAT_H ++ ++/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ ++ ++/* The definition of _GL_ARG_NONNULL is copied here. */ ++ ++/* The definition of _GL_WARN_ON_USE is copied here. */ ++ ++/* Before doing "#define mkdir rpl_mkdir" below, we need to include all ++ headers that may declare mkdir(). Native Windows platforms declare mkdir ++ in and/or , not in . */ ++#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ++# include /* mingw32, mingw64 */ ++# include /* mingw64, MSVC 9 */ ++#endif ++ ++/* Native Windows platforms declare umask() in . */ ++#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) ++# include ++#endif ++ ++/* Large File Support on native Windows. */ ++#if @WINDOWS_64_BIT_ST_SIZE@ ++# define stat _stati64 ++#endif ++ ++#ifndef S_IFIFO ++# ifdef _S_IFIFO ++# define S_IFIFO _S_IFIFO ++# endif ++#endif ++ ++#ifndef S_IFMT ++# define S_IFMT 0170000 ++#endif ++ ++#if STAT_MACROS_BROKEN ++# undef S_ISBLK ++# undef S_ISCHR ++# undef S_ISDIR ++# undef S_ISFIFO ++# undef S_ISLNK ++# undef S_ISNAM ++# undef S_ISMPB ++# undef S_ISMPC ++# undef S_ISNWK ++# undef S_ISREG ++# undef S_ISSOCK ++#endif ++ ++#ifndef S_ISBLK ++# ifdef S_IFBLK ++# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) ++# else ++# define S_ISBLK(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISCHR ++# ifdef S_IFCHR ++# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) ++# else ++# define S_ISCHR(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISDIR ++# ifdef S_IFDIR ++# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) ++# else ++# define S_ISDIR(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISDOOR /* Solaris 2.5 and up */ ++# define S_ISDOOR(m) 0 ++#endif ++ ++#ifndef S_ISFIFO ++# ifdef S_IFIFO ++# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) ++# else ++# define S_ISFIFO(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISLNK ++# ifdef S_IFLNK ++# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) ++# else ++# define S_ISLNK(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISMPB /* V7 */ ++# ifdef S_IFMPB ++# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) ++# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) ++# else ++# define S_ISMPB(m) 0 ++# define S_ISMPC(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISMPX /* AIX */ ++# define S_ISMPX(m) 0 ++#endif ++ ++#ifndef S_ISNAM /* Xenix */ ++# ifdef S_IFNAM ++# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM) ++# else ++# define S_ISNAM(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISNWK /* HP/UX */ ++# ifdef S_IFNWK ++# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) ++# else ++# define S_ISNWK(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISPORT /* Solaris 10 and up */ ++# define S_ISPORT(m) 0 ++#endif ++ ++#ifndef S_ISREG ++# ifdef S_IFREG ++# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) ++# else ++# define S_ISREG(m) 0 ++# endif ++#endif ++ ++#ifndef S_ISSOCK ++# ifdef S_IFSOCK ++# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) ++# else ++# define S_ISSOCK(m) 0 ++# endif ++#endif ++ ++ ++#ifndef S_TYPEISMQ ++# define S_TYPEISMQ(p) 0 ++#endif ++ ++#ifndef S_TYPEISTMO ++# define S_TYPEISTMO(p) 0 ++#endif ++ ++ ++#ifndef S_TYPEISSEM ++# ifdef S_INSEM ++# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM) ++# else ++# define S_TYPEISSEM(p) 0 ++# endif ++#endif ++ ++#ifndef S_TYPEISSHM ++# ifdef S_INSHD ++# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD) ++# else ++# define S_TYPEISSHM(p) 0 ++# endif ++#endif ++ ++/* high performance ("contiguous data") */ ++#ifndef S_ISCTG ++# define S_ISCTG(p) 0 ++#endif ++ ++/* Cray DMF (data migration facility): off line, with data */ ++#ifndef S_ISOFD ++# define S_ISOFD(p) 0 ++#endif ++ ++/* Cray DMF (data migration facility): off line, with no data */ ++#ifndef S_ISOFL ++# define S_ISOFL(p) 0 ++#endif ++ ++/* 4.4BSD whiteout */ ++#ifndef S_ISWHT ++# define S_ISWHT(m) 0 ++#endif ++ ++/* If any of the following are undefined, ++ define them to their de facto standard values. */ ++#if !S_ISUID ++# define S_ISUID 04000 ++#endif ++#if !S_ISGID ++# define S_ISGID 02000 ++#endif ++ ++/* S_ISVTX is a common extension to POSIX. */ ++#ifndef S_ISVTX ++# define S_ISVTX 01000 ++#endif ++ ++#if !S_IRUSR && S_IREAD ++# define S_IRUSR S_IREAD ++#endif ++#if !S_IRUSR ++# define S_IRUSR 00400 ++#endif ++#if !S_IRGRP ++# define S_IRGRP (S_IRUSR >> 3) ++#endif ++#if !S_IROTH ++# define S_IROTH (S_IRUSR >> 6) ++#endif ++ ++#if !S_IWUSR && S_IWRITE ++# define S_IWUSR S_IWRITE ++#endif ++#if !S_IWUSR ++# define S_IWUSR 00200 ++#endif ++#if !S_IWGRP ++# define S_IWGRP (S_IWUSR >> 3) ++#endif ++#if !S_IWOTH ++# define S_IWOTH (S_IWUSR >> 6) ++#endif ++ ++#if !S_IXUSR && S_IEXEC ++# define S_IXUSR S_IEXEC ++#endif ++#if !S_IXUSR ++# define S_IXUSR 00100 ++#endif ++#if !S_IXGRP ++# define S_IXGRP (S_IXUSR >> 3) ++#endif ++#if !S_IXOTH ++# define S_IXOTH (S_IXUSR >> 6) ++#endif ++ ++#if !S_IRWXU ++# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) ++#endif ++#if !S_IRWXG ++# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) ++#endif ++#if !S_IRWXO ++# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) ++#endif ++ ++/* S_IXUGO is a common extension to POSIX. */ ++#if !S_IXUGO ++# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) ++#endif ++ ++#ifndef S_IRWXUGO ++# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) ++#endif ++ ++/* Macros for futimens and utimensat. */ ++#ifndef UTIME_NOW ++# define UTIME_NOW (-1) ++# define UTIME_OMIT (-2) ++#endif ++ ++ ++#if @GNULIB_FCHMODAT@ ++# if !@HAVE_FCHMODAT@ ++_GL_FUNCDECL_SYS (fchmodat, int, ++ (int fd, char const *file, mode_t mode, int flag) ++ _GL_ARG_NONNULL ((2))); ++# endif ++_GL_CXXALIAS_SYS (fchmodat, int, ++ (int fd, char const *file, mode_t mode, int flag)); ++_GL_CXXALIASWARN (fchmodat); ++#elif defined GNULIB_POSIXCHECK ++# undef fchmodat ++# if HAVE_RAW_DECL_FCHMODAT ++_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - " ++ "use gnulib module openat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_FSTAT@ ++# if @REPLACE_FSTAT@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef fstat ++# define fstat rpl_fstat ++# endif ++_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2))); ++_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf)); ++# else ++_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf)); ++# endif ++_GL_CXXALIASWARN (fstat); ++#elif @WINDOWS_64_BIT_ST_SIZE@ ++/* Above, we define stat to _stati64. */ ++# define fstat _fstati64 ++#elif defined GNULIB_POSIXCHECK ++# undef fstat ++# if HAVE_RAW_DECL_FSTAT ++_GL_WARN_ON_USE (fstat, "fstat has portability problems - " ++ "use gnulib module fstat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_FSTATAT@ ++# if @REPLACE_FSTATAT@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef fstatat ++# define fstatat rpl_fstatat ++# endif ++_GL_FUNCDECL_RPL (fstatat, int, ++ (int fd, char const *name, struct stat *st, int flags) ++ _GL_ARG_NONNULL ((2, 3))); ++_GL_CXXALIAS_RPL (fstatat, int, ++ (int fd, char const *name, struct stat *st, int flags)); ++# else ++# if !@HAVE_FSTATAT@ ++_GL_FUNCDECL_SYS (fstatat, int, ++ (int fd, char const *name, struct stat *st, int flags) ++ _GL_ARG_NONNULL ((2, 3))); ++# endif ++_GL_CXXALIAS_SYS (fstatat, int, ++ (int fd, char const *name, struct stat *st, int flags)); ++# endif ++_GL_CXXALIASWARN (fstatat); ++#elif defined GNULIB_POSIXCHECK ++# undef fstatat ++# if HAVE_RAW_DECL_FSTATAT ++_GL_WARN_ON_USE (fstatat, "fstatat is not portable - " ++ "use gnulib module openat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_FUTIMENS@ ++/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens ++ implementation relies on futimesat, which on Solaris 10 makes an invocation ++ to futimens that is meant to invoke the libc's futimens(), not gnulib's ++ futimens(). */ ++# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun) ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef futimens ++# define futimens rpl_futimens ++# endif ++_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2])); ++_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2])); ++# else ++# if !@HAVE_FUTIMENS@ ++_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2])); ++# endif ++_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2])); ++# endif ++# if @HAVE_FUTIMENS@ ++_GL_CXXALIASWARN (futimens); ++# endif ++#elif defined GNULIB_POSIXCHECK ++# undef futimens ++# if HAVE_RAW_DECL_FUTIMENS ++_GL_WARN_ON_USE (futimens, "futimens is not portable - " ++ "use gnulib module futimens for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_LCHMOD@ ++/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME ++ denotes a symbolic link. */ ++# if !@HAVE_LCHMOD@ ++/* The lchmod replacement follows symbolic links. Callers should take ++ this into account; lchmod should be applied only to arguments that ++ are known to not be symbolic links. On hosts that lack lchmod, ++ this can lead to race conditions between the check and the ++ invocation of lchmod, but we know of no workarounds that are ++ reliable in general. You might try requesting support for lchmod ++ from your operating system supplier. */ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define lchmod chmod ++# endif ++/* Need to cast, because on mingw, the second parameter of chmod is ++ int mode. */ ++_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int, ++ (const char *filename, mode_t mode)); ++# else ++# if 0 /* assume already declared */ ++_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode) ++ _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode)); ++# endif ++# if @HAVE_LCHMOD@ ++_GL_CXXALIASWARN (lchmod); ++# endif ++#elif defined GNULIB_POSIXCHECK ++# undef lchmod ++# if HAVE_RAW_DECL_LCHMOD ++_GL_WARN_ON_USE (lchmod, "lchmod is unportable - " ++ "use gnulib module lchmod for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_LSTAT@ ++# if ! @HAVE_LSTAT@ ++/* mingw does not support symlinks, therefore it does not have lstat. But ++ without links, stat does just fine. */ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define lstat stat ++# endif ++_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf)); ++# elif @REPLACE_LSTAT@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef lstat ++# define lstat rpl_lstat ++# endif ++_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf) ++ _GL_ARG_NONNULL ((1, 2))); ++_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf)); ++# else ++_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf)); ++# endif ++# if @HAVE_LSTAT@ ++_GL_CXXALIASWARN (lstat); ++# endif ++#elif defined GNULIB_POSIXCHECK ++# undef lstat ++# if HAVE_RAW_DECL_LSTAT ++_GL_WARN_ON_USE (lstat, "lstat is unportable - " ++ "use gnulib module lstat for portability"); ++# endif ++#endif ++ ++ ++#if @REPLACE_MKDIR@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef mkdir ++# define mkdir rpl_mkdir ++# endif ++_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode)); ++#else ++/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. ++ Additionally, it declares _mkdir (and depending on compile flags, an ++ alias mkdir), only in the nonstandard includes and , ++ which are included above. */ ++# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ++ ++# if !GNULIB_defined_rpl_mkdir ++static int ++rpl_mkdir (char const *name, mode_t mode) ++{ ++ return _mkdir (name); ++} ++# define GNULIB_defined_rpl_mkdir 1 ++# endif ++ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define mkdir rpl_mkdir ++# endif ++_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode)); ++# else ++_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode)); ++# endif ++#endif ++_GL_CXXALIASWARN (mkdir); ++ ++ ++#if @GNULIB_MKDIRAT@ ++# if !@HAVE_MKDIRAT@ ++_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode) ++ _GL_ARG_NONNULL ((2))); ++# endif ++_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)); ++_GL_CXXALIASWARN (mkdirat); ++#elif defined GNULIB_POSIXCHECK ++# undef mkdirat ++# if HAVE_RAW_DECL_MKDIRAT ++_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - " ++ "use gnulib module openat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_MKFIFO@ ++# if @REPLACE_MKFIFO@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef mkfifo ++# define mkfifo rpl_mkfifo ++# endif ++_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode)); ++# else ++# if !@HAVE_MKFIFO@ ++_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode) ++ _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode)); ++# endif ++_GL_CXXALIASWARN (mkfifo); ++#elif defined GNULIB_POSIXCHECK ++# undef mkfifo ++# if HAVE_RAW_DECL_MKFIFO ++_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - " ++ "use gnulib module mkfifo for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_MKFIFOAT@ ++# if !@HAVE_MKFIFOAT@ ++_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode) ++ _GL_ARG_NONNULL ((2))); ++# endif ++_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)); ++_GL_CXXALIASWARN (mkfifoat); ++#elif defined GNULIB_POSIXCHECK ++# undef mkfifoat ++# if HAVE_RAW_DECL_MKFIFOAT ++_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - " ++ "use gnulib module mkfifoat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_MKNOD@ ++# if @REPLACE_MKNOD@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef mknod ++# define mknod rpl_mknod ++# endif ++_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)); ++# else ++# if !@HAVE_MKNOD@ ++_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev) ++ _GL_ARG_NONNULL ((1))); ++# endif ++/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */ ++_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev)); ++# endif ++_GL_CXXALIASWARN (mknod); ++#elif defined GNULIB_POSIXCHECK ++# undef mknod ++# if HAVE_RAW_DECL_MKNOD ++_GL_WARN_ON_USE (mknod, "mknod is not portable - " ++ "use gnulib module mknod for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_MKNODAT@ ++# if !@HAVE_MKNODAT@ ++_GL_FUNCDECL_SYS (mknodat, int, ++ (int fd, char const *file, mode_t mode, dev_t dev) ++ _GL_ARG_NONNULL ((2))); ++# endif ++_GL_CXXALIAS_SYS (mknodat, int, ++ (int fd, char const *file, mode_t mode, dev_t dev)); ++_GL_CXXALIASWARN (mknodat); ++#elif defined GNULIB_POSIXCHECK ++# undef mknodat ++# if HAVE_RAW_DECL_MKNODAT ++_GL_WARN_ON_USE (mknodat, "mknodat is not portable - " ++ "use gnulib module mkfifoat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_STAT@ ++# if @REPLACE_STAT@ ++/* We can't use the object-like #define stat rpl_stat, because of ++ struct stat. This means that rpl_stat will not be used if the user ++ does (stat)(a,b). Oh well. */ ++# if defined _AIX && defined stat && defined _LARGE_FILES ++ /* With _LARGE_FILES defined, AIX (only) defines stat to stat64, ++ so we have to replace stat64() instead of stat(). */ ++# undef stat64 ++# define stat64(name, st) rpl_stat (name, st) ++# elif @WINDOWS_64_BIT_ST_SIZE@ ++ /* Above, we define stat to _stati64. */ ++# if defined __MINGW32__ && defined _stati64 ++# ifndef _USE_32BIT_TIME_T ++ /* The system headers define _stati64 to _stat64. */ ++# undef _stat64 ++# define _stat64(name, st) rpl_stat (name, st) ++# endif ++# elif defined _MSC_VER && defined _stati64 ++# ifdef _USE_32BIT_TIME_T ++ /* The system headers define _stati64 to _stat32i64. */ ++# undef _stat32i64 ++# define _stat32i64(name, st) rpl_stat (name, st) ++# else ++ /* The system headers define _stati64 to _stat64. */ ++# undef _stat64 ++# define _stat64(name, st) rpl_stat (name, st) ++# endif ++# else ++# undef _stati64 ++# define _stati64(name, st) rpl_stat (name, st) ++# endif ++# elif defined __MINGW32__ && defined stat ++# ifdef _USE_32BIT_TIME_T ++ /* The system headers define stat to _stat32i64. */ ++# undef _stat32i64 ++# define _stat32i64(name, st) rpl_stat (name, st) ++# else ++ /* The system headers define stat to _stat64. */ ++# undef _stat64 ++# define _stat64(name, st) rpl_stat (name, st) ++# endif ++# elif defined _MSC_VER && defined stat ++# ifdef _USE_32BIT_TIME_T ++ /* The system headers define stat to _stat32. */ ++# undef _stat32 ++# define _stat32(name, st) rpl_stat (name, st) ++# else ++ /* The system headers define stat to _stat64i32. */ ++# undef _stat64i32 ++# define _stat64i32(name, st) rpl_stat (name, st) ++# endif ++# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */ ++# undef stat ++# define stat(name, st) rpl_stat (name, st) ++# endif /* !_LARGE_FILES */ ++_GL_EXTERN_C int stat (const char *name, struct stat *buf) ++ _GL_ARG_NONNULL ((1, 2)); ++# endif ++#elif defined GNULIB_POSIXCHECK ++# undef stat ++# if HAVE_RAW_DECL_STAT ++_GL_WARN_ON_USE (stat, "stat is unportable - " ++ "use gnulib module stat for portability"); ++# endif ++#endif ++ ++ ++#if @GNULIB_UTIMENSAT@ ++/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat ++ implementation relies on futimesat, which on Solaris 10 makes an invocation ++ to utimensat that is meant to invoke the libc's utimensat(), not gnulib's ++ utimensat(). */ ++# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun) ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef utimensat ++# define utimensat rpl_utimensat ++# endif ++_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name, ++ struct timespec const times[2], int flag) ++ _GL_ARG_NONNULL ((2))); ++_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name, ++ struct timespec const times[2], int flag)); ++# else ++# if !@HAVE_UTIMENSAT@ ++_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name, ++ struct timespec const times[2], int flag) ++ _GL_ARG_NONNULL ((2))); ++# endif ++_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name, ++ struct timespec const times[2], int flag)); ++# endif ++# if @HAVE_UTIMENSAT@ ++_GL_CXXALIASWARN (utimensat); ++# endif ++#elif defined GNULIB_POSIXCHECK ++# undef utimensat ++# if HAVE_RAW_DECL_UTIMENSAT ++_GL_WARN_ON_USE (utimensat, "utimensat is not portable - " ++ "use gnulib module utimensat for portability"); ++# endif ++#endif ++ ++ ++#endif /* _@GUARD_PREFIX@_SYS_STAT_H */ ++#endif /* _@GUARD_PREFIX@_SYS_STAT_H */ ++#endif +diff --git a/grub-core/gnulib/sys_time.in.h b/grub-core/gnulib/sys_time.in.h +new file mode 100644 +index 00000000000..30057ad49fd +--- /dev/null ++++ b/grub-core/gnulib/sys_time.in.h +@@ -0,0 +1,213 @@ ++/* Provide a more complete sys/time.h. ++ ++ Copyright (C) 2007-2014 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, 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 . */ ++ ++/* Written by Paul Eggert. */ ++ ++#ifndef _@GUARD_PREFIX@_SYS_TIME_H ++ ++#if __GNUC__ >= 3 ++@PRAGMA_SYSTEM_HEADER@ ++#endif ++@PRAGMA_COLUMNS@ ++ ++/* On Cygwin and on many BSDish systems, includes itself ++ recursively via . ++ Simply delegate to the system's header in this case; it is a no-op. ++ Without this extra ifdef, the C++ gettimeofday declaration below ++ would be a forward declaration in gnulib's nested . */ ++#if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_ ++# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ ++#else ++ ++/* The include_next requires a split double-inclusion guard. */ ++#if @HAVE_SYS_TIME_H@ ++# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@ ++#endif ++ ++#ifndef _@GUARD_PREFIX@_SYS_TIME_H ++#define _@GUARD_PREFIX@_SYS_TIME_H ++ ++#if ! @HAVE_SYS_TIME_H@ ++# include ++#endif ++ ++/* On native Windows with MSVC, get the 'struct timeval' type. ++ Also, on native Windows with a 64-bit time_t, where we are overriding the ++ 'struct timeval' type, get all declarations of system functions whose ++ signature contains 'struct timeval'. */ ++#if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H ++# define _GL_INCLUDING_WINSOCK2_H ++# include ++# undef _GL_INCLUDING_WINSOCK2_H ++#endif ++ ++/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ ++ ++/* The definition of _GL_ARG_NONNULL is copied here. */ ++ ++/* The definition of _GL_WARN_ON_USE is copied here. */ ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++#if !@HAVE_STRUCT_TIMEVAL@ || @REPLACE_STRUCT_TIMEVAL@ ++ ++# if @REPLACE_STRUCT_TIMEVAL@ ++# define timeval rpl_timeval ++# endif ++ ++# if !GNULIB_defined_struct_timeval ++struct timeval ++{ ++ time_t tv_sec; ++ long int tv_usec; ++}; ++# define GNULIB_defined_struct_timeval 1 ++# endif ++ ++#endif ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#if @GNULIB_GETTIMEOFDAY@ ++# if @REPLACE_GETTIMEOFDAY@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gettimeofday ++# define gettimeofday rpl_gettimeofday ++# endif ++_GL_FUNCDECL_RPL (gettimeofday, int, ++ (struct timeval *restrict, void *restrict) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (gettimeofday, int, ++ (struct timeval *restrict, void *restrict)); ++# else ++# if !@HAVE_GETTIMEOFDAY@ ++_GL_FUNCDECL_SYS (gettimeofday, int, ++ (struct timeval *restrict, void *restrict) ++ _GL_ARG_NONNULL ((1))); ++# endif ++/* Need to cast, because on glibc systems, by default, the second argument is ++ struct timezone *. */ ++_GL_CXXALIAS_SYS_CAST (gettimeofday, int, ++ (struct timeval *restrict, void *restrict)); ++# endif ++_GL_CXXALIASWARN (gettimeofday); ++#elif defined GNULIB_POSIXCHECK ++# undef gettimeofday ++# if HAVE_RAW_DECL_GETTIMEOFDAY ++_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " ++ "use gnulib module gettimeofday for portability"); ++# endif ++#endif ++ ++/* Hide some function declarations from . */ ++ ++#if defined _MSC_VER && @HAVE_WINSOCK2_H@ ++# if !defined _@GUARD_PREFIX@_UNISTD_H ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef close ++# define close close_used_without_including_unistd_h ++# else ++ _GL_WARN_ON_USE (close, ++ "close() used without including "); ++# endif ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gethostname ++# define gethostname gethostname_used_without_including_unistd_h ++# else ++ _GL_WARN_ON_USE (gethostname, ++ "gethostname() used without including "); ++# endif ++# endif ++# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef socket ++# define socket socket_used_without_including_sys_socket_h ++# undef connect ++# define connect connect_used_without_including_sys_socket_h ++# undef accept ++# define accept accept_used_without_including_sys_socket_h ++# undef bind ++# define bind bind_used_without_including_sys_socket_h ++# undef getpeername ++# define getpeername getpeername_used_without_including_sys_socket_h ++# undef getsockname ++# define getsockname getsockname_used_without_including_sys_socket_h ++# undef getsockopt ++# define getsockopt getsockopt_used_without_including_sys_socket_h ++# undef listen ++# define listen listen_used_without_including_sys_socket_h ++# undef recv ++# define recv recv_used_without_including_sys_socket_h ++# undef send ++# define send send_used_without_including_sys_socket_h ++# undef recvfrom ++# define recvfrom recvfrom_used_without_including_sys_socket_h ++# undef sendto ++# define sendto sendto_used_without_including_sys_socket_h ++# undef setsockopt ++# define setsockopt setsockopt_used_without_including_sys_socket_h ++# undef shutdown ++# define shutdown shutdown_used_without_including_sys_socket_h ++# else ++ _GL_WARN_ON_USE (socket, ++ "socket() used without including "); ++ _GL_WARN_ON_USE (connect, ++ "connect() used without including "); ++ _GL_WARN_ON_USE (accept, ++ "accept() used without including "); ++ _GL_WARN_ON_USE (bind, ++ "bind() used without including "); ++ _GL_WARN_ON_USE (getpeername, ++ "getpeername() used without including "); ++ _GL_WARN_ON_USE (getsockname, ++ "getsockname() used without including "); ++ _GL_WARN_ON_USE (getsockopt, ++ "getsockopt() used without including "); ++ _GL_WARN_ON_USE (listen, ++ "listen() used without including "); ++ _GL_WARN_ON_USE (recv, ++ "recv() used without including "); ++ _GL_WARN_ON_USE (send, ++ "send() used without including "); ++ _GL_WARN_ON_USE (recvfrom, ++ "recvfrom() used without including "); ++ _GL_WARN_ON_USE (sendto, ++ "sendto() used without including "); ++ _GL_WARN_ON_USE (setsockopt, ++ "setsockopt() used without including "); ++ _GL_WARN_ON_USE (shutdown, ++ "shutdown() used without including "); ++# endif ++# endif ++# if !defined _@GUARD_PREFIX@_SYS_SELECT_H ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef select ++# define select select_used_without_including_sys_select_h ++# else ++ _GL_WARN_ON_USE (select, ++ "select() used without including "); ++# endif ++# endif ++#endif ++ ++#endif /* _@GUARD_PREFIX@_SYS_TIME_H */ ++#endif /* _CYGWIN_SYS_TIME_H */ ++#endif /* _@GUARD_PREFIX@_SYS_TIME_H */ +diff --git a/grub-core/gnulib/sys_types.in.h b/grub-core/gnulib/sys_types.in.h +index d7da35623b1..9520c09030c 100644 +--- a/grub-core/gnulib/sys_types.in.h ++++ b/grub-core/gnulib/sys_types.in.h +@@ -23,7 +23,9 @@ + #ifndef _@GUARD_PREFIX@_SYS_TYPES_H + + /* The include_next requires a split double-inclusion guard. */ ++# define _GL_INCLUDING_SYS_TYPES_H + #@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@ ++# undef _GL_INCLUDING_SYS_TYPES_H + + #ifndef _@GUARD_PREFIX@_SYS_TYPES_H + #define _@GUARD_PREFIX@_SYS_TYPES_H +diff --git a/grub-core/gnulib/time.h b/grub-core/gnulib/time.h +new file mode 100644 +index 00000000000..b9203d5569a +--- /dev/null ++++ b/grub-core/gnulib/time.h +@@ -0,0 +1,586 @@ ++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ ++/* A more-standard . ++ ++ Copyright (C) 2007-2014 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, 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 . */ ++ ++#if __GNUC__ >= 3 ++#pragma GCC system_header ++#endif ++ ++ ++/* Don't get in the way of glibc when it includes time.h merely to ++ declare a few standard symbols, rather than to declare all the ++ symbols. Also, Solaris 8 eventually includes itself ++ recursively; if that is happening, just include the system ++ without adding our own declarations. */ ++#if (defined __need_time_t || defined __need_clock_t \ ++ || defined __need_timespec \ ++ || defined _GL_TIME_H) ++ ++# include_next ++ ++#else ++ ++# define _GL_TIME_H ++ ++# include_next ++ ++/* NetBSD 5.0 mis-defines NULL. */ ++# include ++ ++/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ ++#ifndef _GL_CXXDEFS_H ++#define _GL_CXXDEFS_H ++ ++/* The three most frequent use cases of these macros are: ++ ++ * For providing a substitute for a function that is missing on some ++ platforms, but is declared and works fine on the platforms on which ++ it exists: ++ ++ #if @GNULIB_FOO@ ++ # if !@HAVE_FOO@ ++ _GL_FUNCDECL_SYS (foo, ...); ++ # endif ++ _GL_CXXALIAS_SYS (foo, ...); ++ _GL_CXXALIASWARN (foo); ++ #elif defined GNULIB_POSIXCHECK ++ ... ++ #endif ++ ++ * For providing a replacement for a function that exists on all platforms, ++ but is broken/insufficient and needs to be replaced on some platforms: ++ ++ #if @GNULIB_FOO@ ++ # if @REPLACE_FOO@ ++ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++ # undef foo ++ # define foo rpl_foo ++ # endif ++ _GL_FUNCDECL_RPL (foo, ...); ++ _GL_CXXALIAS_RPL (foo, ...); ++ # else ++ _GL_CXXALIAS_SYS (foo, ...); ++ # endif ++ _GL_CXXALIASWARN (foo); ++ #elif defined GNULIB_POSIXCHECK ++ ... ++ #endif ++ ++ * For providing a replacement for a function that exists on some platforms ++ but is broken/insufficient and needs to be replaced on some of them and ++ is additionally either missing or undeclared on some other platforms: ++ ++ #if @GNULIB_FOO@ ++ # if @REPLACE_FOO@ ++ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++ # undef foo ++ # define foo rpl_foo ++ # endif ++ _GL_FUNCDECL_RPL (foo, ...); ++ _GL_CXXALIAS_RPL (foo, ...); ++ # else ++ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@ ++ _GL_FUNCDECL_SYS (foo, ...); ++ # endif ++ _GL_CXXALIAS_SYS (foo, ...); ++ # endif ++ _GL_CXXALIASWARN (foo); ++ #elif defined GNULIB_POSIXCHECK ++ ... ++ #endif ++*/ ++ ++/* _GL_EXTERN_C declaration; ++ performs the declaration with C linkage. */ ++#if defined __cplusplus ++# define _GL_EXTERN_C extern "C" ++#else ++# define _GL_EXTERN_C extern ++#endif ++ ++/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes); ++ declares a replacement function, named rpl_func, with the given prototype, ++ consisting of return type, parameters, and attributes. ++ Example: ++ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) ++ _GL_ARG_NONNULL ((1))); ++ */ ++#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ ++ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) ++#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \ ++ _GL_EXTERN_C rettype rpl_func parameters_and_attributes ++ ++/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes); ++ declares the system function, named func, with the given prototype, ++ consisting of return type, parameters, and attributes. ++ Example: ++ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...) ++ _GL_ARG_NONNULL ((1))); ++ */ ++#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \ ++ _GL_EXTERN_C rettype func parameters_and_attributes ++ ++/* _GL_CXXALIAS_RPL (func, rettype, parameters); ++ declares a C++ alias called GNULIB_NAMESPACE::func ++ that redirects to rpl_func, if GNULIB_NAMESPACE is defined. ++ Example: ++ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...)); ++ */ ++#define _GL_CXXALIAS_RPL(func,rettype,parameters) \ ++ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters) ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ ++ namespace GNULIB_NAMESPACE \ ++ { \ ++ rettype (*const func) parameters = ::rpl_func; \ ++ } \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#else ++# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters); ++ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters); ++ except that the C function rpl_func may have a slightly different ++ declaration. A cast is used to silence the "invalid conversion" error ++ that would otherwise occur. */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ ++ namespace GNULIB_NAMESPACE \ ++ { \ ++ rettype (*const func) parameters = \ ++ reinterpret_cast(::rpl_func); \ ++ } \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#else ++# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIAS_SYS (func, rettype, parameters); ++ declares a C++ alias called GNULIB_NAMESPACE::func ++ that redirects to the system provided function func, if GNULIB_NAMESPACE ++ is defined. ++ Example: ++ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...)); ++ */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++ /* If we were to write ++ rettype (*const func) parameters = ::func; ++ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls ++ better (remove an indirection through a 'static' pointer variable), ++ but then the _GL_CXXALIASWARN macro below would cause a warning not only ++ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */ ++# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ ++ namespace GNULIB_NAMESPACE \ ++ { \ ++ static rettype (*func) parameters = ::func; \ ++ } \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#else ++# define _GL_CXXALIAS_SYS(func,rettype,parameters) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters); ++ is like _GL_CXXALIAS_SYS (func, rettype, parameters); ++ except that the C function func may have a slightly different declaration. ++ A cast is used to silence the "invalid conversion" error that would ++ otherwise occur. */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ ++ namespace GNULIB_NAMESPACE \ ++ { \ ++ static rettype (*func) parameters = \ ++ reinterpret_cast(::func); \ ++ } \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#else ++# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2); ++ is like _GL_CXXALIAS_SYS (func, rettype, parameters); ++ except that the C function is picked among a set of overloaded functions, ++ namely the one with rettype2 and parameters2. Two consecutive casts ++ are used to silence the "cannot find a match" and "invalid conversion" ++ errors that would otherwise occur. */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++ /* The outer cast must be a reinterpret_cast. ++ The inner cast: When the function is defined as a set of overloaded ++ functions, it works as a static_cast<>, choosing the designated variant. ++ When the function is defined as a single variant, it works as a ++ reinterpret_cast<>. The parenthesized cast syntax works both ways. */ ++# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ ++ namespace GNULIB_NAMESPACE \ ++ { \ ++ static rettype (*func) parameters = \ ++ reinterpret_cast( \ ++ (rettype2(*)parameters2)(::func)); \ ++ } \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#else ++# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIASWARN (func); ++ causes a warning to be emitted when ::func is used but not when ++ GNULIB_NAMESPACE::func is used. func must be defined without overloaded ++ variants. */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++# define _GL_CXXALIASWARN(func) \ ++ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) ++# define _GL_CXXALIASWARN_1(func,namespace) \ ++ _GL_CXXALIASWARN_2 (func, namespace) ++/* To work around GCC bug , ++ we enable the warning only when not optimizing. */ ++# if !__OPTIMIZE__ ++# define _GL_CXXALIASWARN_2(func,namespace) \ ++ _GL_WARN_ON_USE (func, \ ++ "The symbol ::" #func " refers to the system function. " \ ++ "Use " #namespace "::" #func " instead.") ++# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING ++# define _GL_CXXALIASWARN_2(func,namespace) \ ++ extern __typeof__ (func) func ++# else ++# define _GL_CXXALIASWARN_2(func,namespace) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++# endif ++#else ++# define _GL_CXXALIASWARN(func) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes); ++ causes a warning to be emitted when the given overloaded variant of ::func ++ is used but not when GNULIB_NAMESPACE::func is used. */ ++#if defined __cplusplus && defined GNULIB_NAMESPACE ++# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ ++ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \ ++ GNULIB_NAMESPACE) ++# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ ++ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) ++/* To work around GCC bug , ++ we enable the warning only when not optimizing. */ ++# if !__OPTIMIZE__ ++# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ ++ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ ++ "The symbol ::" #func " refers to the system function. " \ ++ "Use " #namespace "::" #func " instead.") ++# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING ++# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ ++ extern __typeof__ (func) func ++# else ++# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++# endif ++#else ++# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ ++ _GL_EXTERN_C int _gl_cxxalias_dummy ++#endif ++ ++#endif /* _GL_CXXDEFS_H */ ++ ++/* The definition of _GL_ARG_NONNULL is copied here. */ ++/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools ++ that the values passed as arguments n, ..., m must be non-NULL pointers. ++ n = 1 stands for the first argument, n = 2 for the second argument etc. */ ++#ifndef _GL_ARG_NONNULL ++# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 ++# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) ++# else ++# define _GL_ARG_NONNULL(params) ++# endif ++#endif ++ ++/* The definition of _GL_WARN_ON_USE is copied here. */ ++#ifndef _GL_WARN_ON_USE ++ ++# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) ++/* A compiler attribute is available in gcc versions 4.3.0 and later. */ ++# define _GL_WARN_ON_USE(function, message) \ ++extern __typeof__ (function) function __attribute__ ((__warning__ (message))) ++# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING ++/* Verify the existence of the function. */ ++# define _GL_WARN_ON_USE(function, message) \ ++extern __typeof__ (function) function ++# else /* Unsupported. */ ++# define _GL_WARN_ON_USE(function, message) \ ++_GL_WARN_EXTERN_C int _gl_warn_on_use ++# endif ++#endif ++ ++/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string") ++ is like _GL_WARN_ON_USE (function, "string"), except that the function is ++ declared with the given prototype, consisting of return type, parameters, ++ and attributes. ++ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does ++ not work in this case. */ ++#ifndef _GL_WARN_ON_USE_CXX ++# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) ++# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ ++extern rettype function parameters_and_attributes \ ++ __attribute__ ((__warning__ (msg))) ++# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING ++/* Verify the existence of the function. */ ++# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ ++extern rettype function parameters_and_attributes ++# else /* Unsupported. */ ++# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ ++_GL_WARN_EXTERN_C int _gl_warn_on_use ++# endif ++#endif ++ ++/* _GL_WARN_EXTERN_C declaration; ++ performs the declaration with C linkage. */ ++#ifndef _GL_WARN_EXTERN_C ++# if defined __cplusplus ++# define _GL_WARN_EXTERN_C extern "C" ++# else ++# define _GL_WARN_EXTERN_C extern ++# endif ++#endif ++ ++/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). ++ Or they define it with the wrong member names or define it in ++ (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, ++ but the pthreads-win32 library defines it in . */ ++# if ! 1 ++# if 0 ++# include ++# elif 0 ++# include ++# else ++ ++# ifdef __cplusplus ++extern "C" { ++# endif ++ ++# if !GNULIB_defined_struct_timespec ++# undef timespec ++# define timespec rpl_timespec ++struct timespec ++{ ++ time_t tv_sec; ++ long int tv_nsec; ++}; ++# define GNULIB_defined_struct_timespec 1 ++# endif ++ ++# ifdef __cplusplus ++} ++# endif ++ ++# endif ++# endif ++ ++# if !GNULIB_defined_struct_time_t_must_be_integral ++/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires ++ time_t to be an integer type, even though C99 permits floating ++ point. We don't know of any implementation that uses floating ++ point, and it is much easier to write code that doesn't have to ++ worry about that corner case, so we force the issue. */ ++struct __time_t_must_be_integral { ++ unsigned int __floating_time_t_unsupported : (time_t) 1; ++}; ++# define GNULIB_defined_struct_time_t_must_be_integral 1 ++# endif ++ ++/* Sleep for at least RQTP seconds unless interrupted, If interrupted, ++ return -1 and store the remaining time into RMTP. See ++ . */ ++# if 0 ++# if GNULIB_PORTCHECK ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define nanosleep rpl_nanosleep ++# endif ++_GL_FUNCDECL_RPL (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp)); ++# else ++# if ! 1 ++_GL_FUNCDECL_SYS (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp) ++ _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp)); ++# endif ++_GL_CXXALIASWARN (nanosleep); ++# endif ++ ++/* Return the 'time_t' representation of TP and normalize TP. */ ++# if 0 ++# if GNULIB_PORTCHECK ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define mktime rpl_mktime ++# endif ++_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); ++# else ++_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); ++# endif ++_GL_CXXALIASWARN (mktime); ++# endif ++ ++/* Convert TIMER to RESULT, assuming local time and UTC respectively. See ++ and ++ . */ ++# if 0 ++# if GNULIB_PORTCHECK ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef localtime_r ++# define localtime_r rpl_localtime_r ++# endif ++_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# else ++# if ! 1 ++_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++# endif ++_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# endif ++# if 1 ++_GL_CXXALIASWARN (localtime_r); ++# endif ++# if GNULIB_PORTCHECK ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gmtime_r ++# define gmtime_r rpl_gmtime_r ++# endif ++_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# else ++# if ! 1 ++_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++# endif ++_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# endif ++# if 1 ++_GL_CXXALIASWARN (gmtime_r); ++# endif ++# endif ++ ++/* Convert TIMER to RESULT, assuming local time and UTC respectively. See ++ and ++ . */ ++# if 1 ++# if 0 ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef localtime ++# define localtime rpl_localtime ++# endif ++_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); ++# else ++_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); ++# endif ++_GL_CXXALIASWARN (localtime); ++# endif ++ ++# if 1 ++# if 0 ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gmtime ++# define gmtime rpl_gmtime ++# endif ++_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); ++# else ++_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); ++# endif ++_GL_CXXALIASWARN (gmtime); ++# endif ++ ++/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store ++ the resulting broken-down time into TM. See ++ . */ ++# if 0 ++# if ! 1 ++_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, ++ char const *restrict __format, ++ struct tm *restrict __tm) ++ _GL_ARG_NONNULL ((1, 2, 3))); ++# endif ++_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, ++ char const *restrict __format, ++ struct tm *restrict __tm)); ++_GL_CXXALIASWARN (strptime); ++# endif ++ ++/* Convert TM to a time_t value, assuming UTC. */ ++# if 0 ++# if GNULIB_PORTCHECK ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef timegm ++# define timegm rpl_timegm ++# endif ++_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); ++# else ++# if ! 1 ++_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); ++# endif ++_GL_CXXALIASWARN (timegm); ++# endif ++ ++/* Encourage applications to avoid unsafe functions that can overrun ++ buffers when given outlandish struct tm values. Portable ++ applications should use strftime (or even sprintf) instead. */ ++# if defined GNULIB_POSIXCHECK ++# undef asctime ++_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef asctime_r ++_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef ctime ++_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef ctime_r ++_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++ ++#endif +diff --git a/grub-core/gnulib/time.in.h b/grub-core/gnulib/time.in.h +new file mode 100644 +index 00000000000..81abdf46e0b +--- /dev/null ++++ b/grub-core/gnulib/time.in.h +@@ -0,0 +1,274 @@ ++/* A more-standard . ++ ++ Copyright (C) 2007-2014 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, 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 . */ ++ ++#if __GNUC__ >= 3 ++@PRAGMA_SYSTEM_HEADER@ ++#endif ++@PRAGMA_COLUMNS@ ++ ++/* Don't get in the way of glibc when it includes time.h merely to ++ declare a few standard symbols, rather than to declare all the ++ symbols. Also, Solaris 8 eventually includes itself ++ recursively; if that is happening, just include the system ++ without adding our own declarations. */ ++#if (defined __need_time_t || defined __need_clock_t \ ++ || defined __need_timespec \ ++ || defined _@GUARD_PREFIX@_TIME_H) ++ ++# @INCLUDE_NEXT@ @NEXT_TIME_H@ ++ ++#else ++ ++# define _@GUARD_PREFIX@_TIME_H ++ ++# @INCLUDE_NEXT@ @NEXT_TIME_H@ ++ ++/* NetBSD 5.0 mis-defines NULL. */ ++# include ++ ++/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ ++ ++/* The definition of _GL_ARG_NONNULL is copied here. */ ++ ++/* The definition of _GL_WARN_ON_USE is copied here. */ ++ ++/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). ++ Or they define it with the wrong member names or define it in ++ (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it, ++ but the pthreads-win32 library defines it in . */ ++# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ ++# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ ++# include ++# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ ++# include ++# else ++ ++# ifdef __cplusplus ++extern "C" { ++# endif ++ ++# if !GNULIB_defined_struct_timespec ++# undef timespec ++# define timespec rpl_timespec ++struct timespec ++{ ++ time_t tv_sec; ++ long int tv_nsec; ++}; ++# define GNULIB_defined_struct_timespec 1 ++# endif ++ ++# ifdef __cplusplus ++} ++# endif ++ ++# endif ++# endif ++ ++# if !GNULIB_defined_struct_time_t_must_be_integral ++/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires ++ time_t to be an integer type, even though C99 permits floating ++ point. We don't know of any implementation that uses floating ++ point, and it is much easier to write code that doesn't have to ++ worry about that corner case, so we force the issue. */ ++struct __time_t_must_be_integral { ++ unsigned int __floating_time_t_unsupported : (time_t) 1; ++}; ++# define GNULIB_defined_struct_time_t_must_be_integral 1 ++# endif ++ ++/* Sleep for at least RQTP seconds unless interrupted, If interrupted, ++ return -1 and store the remaining time into RMTP. See ++ . */ ++# if @GNULIB_NANOSLEEP@ ++# if @REPLACE_NANOSLEEP@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define nanosleep rpl_nanosleep ++# endif ++_GL_FUNCDECL_RPL (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp)); ++# else ++# if ! @HAVE_NANOSLEEP@ ++_GL_FUNCDECL_SYS (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp) ++ _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (nanosleep, int, ++ (struct timespec const *__rqtp, struct timespec *__rmtp)); ++# endif ++_GL_CXXALIASWARN (nanosleep); ++# endif ++ ++/* Return the 'time_t' representation of TP and normalize TP. */ ++# if @GNULIB_MKTIME@ ++# if @REPLACE_MKTIME@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# define mktime rpl_mktime ++# endif ++_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp)); ++# else ++_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); ++# endif ++_GL_CXXALIASWARN (mktime); ++# endif ++ ++/* Convert TIMER to RESULT, assuming local time and UTC respectively. See ++ and ++ . */ ++# if @GNULIB_TIME_R@ ++# if @REPLACE_LOCALTIME_R@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef localtime_r ++# define localtime_r rpl_localtime_r ++# endif ++_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# else ++# if ! @HAVE_DECL_LOCALTIME_R@ ++_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++# endif ++_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# endif ++# if @HAVE_DECL_LOCALTIME_R@ ++_GL_CXXALIASWARN (localtime_r); ++# endif ++# if @REPLACE_LOCALTIME_R@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gmtime_r ++# define gmtime_r rpl_gmtime_r ++# endif ++_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# else ++# if ! @HAVE_DECL_LOCALTIME_R@ ++_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result) ++ _GL_ARG_NONNULL ((1, 2))); ++# endif ++_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, ++ struct tm *restrict __result)); ++# endif ++# if @HAVE_DECL_LOCALTIME_R@ ++_GL_CXXALIASWARN (gmtime_r); ++# endif ++# endif ++ ++/* Convert TIMER to RESULT, assuming local time and UTC respectively. See ++ and ++ . */ ++# if @GNULIB_GETTIMEOFDAY@ ++# if @REPLACE_LOCALTIME@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef localtime ++# define localtime rpl_localtime ++# endif ++_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer)); ++# else ++_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); ++# endif ++_GL_CXXALIASWARN (localtime); ++# endif ++ ++# if @GNULIB_GETTIMEOFDAY@ ++# if @REPLACE_GMTIME@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef gmtime ++# define gmtime rpl_gmtime ++# endif ++_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer) ++ _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer)); ++# else ++_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer)); ++# endif ++_GL_CXXALIASWARN (gmtime); ++# endif ++ ++/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store ++ the resulting broken-down time into TM. See ++ . */ ++# if @GNULIB_STRPTIME@ ++# if ! @HAVE_STRPTIME@ ++_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, ++ char const *restrict __format, ++ struct tm *restrict __tm) ++ _GL_ARG_NONNULL ((1, 2, 3))); ++# endif ++_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, ++ char const *restrict __format, ++ struct tm *restrict __tm)); ++_GL_CXXALIASWARN (strptime); ++# endif ++ ++/* Convert TM to a time_t value, assuming UTC. */ ++# if @GNULIB_TIMEGM@ ++# if @REPLACE_TIMEGM@ ++# if !(defined __cplusplus && defined GNULIB_NAMESPACE) ++# undef timegm ++# define timegm rpl_timegm ++# endif ++_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); ++_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm)); ++# else ++# if ! @HAVE_TIMEGM@ ++_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); ++# endif ++_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); ++# endif ++_GL_CXXALIASWARN (timegm); ++# endif ++ ++/* Encourage applications to avoid unsafe functions that can overrun ++ buffers when given outlandish struct tm values. Portable ++ applications should use strftime (or even sprintf) instead. */ ++# if defined GNULIB_POSIXCHECK ++# undef asctime ++_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef asctime_r ++_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef ctime ++_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++# if defined GNULIB_POSIXCHECK ++# undef ctime_r ++_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " ++ "better use strftime (or even sprintf) instead"); ++# endif ++ ++#endif +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/grub-core/gnulib/Makefile.am b/grub-core/gnulib/Makefile.am +index 3444397fe37..b7c5e60e1c3 100644 +--- a/grub-core/gnulib/Makefile.am ++++ b/grub-core/gnulib/Makefile.am +@@ -21,7 +21,7 @@ + # the same distribution terms as the rest of that program. + # + # Generated by gnulib-tool. +-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex ++# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex + + AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects + +@@ -326,6 +326,15 @@ libgnu_a_SOURCES += gettext.h + + ## end gnulib module gettext-h + ++## begin gnulib module gettimeofday ++ ++ ++EXTRA_DIST += gettimeofday.c ++ ++EXTRA_libgnu_a_SOURCES += gettimeofday.c ++ ++## end gnulib module gettimeofday ++ + ## begin gnulib module havelib + + +@@ -596,6 +605,13 @@ EXTRA_libgnu_a_SOURCES += nl_langinfo.c + + ## end gnulib module nl_langinfo + ++## begin gnulib module pathmax ++ ++ ++EXTRA_DIST += pathmax.h ++ ++## end gnulib module pathmax ++ + ## begin gnulib module progname + + libgnu_a_SOURCES += progname.h progname.c +@@ -611,6 +627,15 @@ EXTRA_libgnu_a_SOURCES += rawmemchr.c + + ## end gnulib module rawmemchr + ++## begin gnulib module readlink ++ ++ ++EXTRA_DIST += readlink.c ++ ++EXTRA_libgnu_a_SOURCES += readlink.c ++ ++## end gnulib module readlink ++ + ## begin gnulib module realloc-posix + + +@@ -725,6 +750,15 @@ EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h + + ## end gnulib module snippet/warn-on-use + ++## begin gnulib module stat ++ ++ ++EXTRA_DIST += stat.c ++ ++EXTRA_libgnu_a_SOURCES += stat.c ++ ++## end gnulib module stat ++ + ## begin gnulib module stdalign + + BUILT_SOURCES += $(STDALIGN_H) +@@ -1280,6 +1314,102 @@ libgnu_a_SOURCES += strnlen1.h strnlen1.c + + ## end gnulib module strnlen1 + ++## begin gnulib module sys_stat ++ ++BUILT_SOURCES += sys/stat.h ++ ++# We need the following in order to create when the system ++# has one that is incomplete. ++sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) ++ $(AM_V_at)$(MKDIR_P) sys ++ $(AM_V_GEN)rm -f $@-t $@ && \ ++ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ ++ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ ++ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ ++ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ ++ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ ++ -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \ ++ -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \ ++ -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \ ++ -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \ ++ -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \ ++ -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \ ++ -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \ ++ -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \ ++ -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \ ++ -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \ ++ -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \ ++ -e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \ ++ -e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \ ++ -e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \ ++ -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \ ++ -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \ ++ -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \ ++ -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \ ++ -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \ ++ -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \ ++ -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \ ++ -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \ ++ -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \ ++ -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \ ++ -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \ ++ -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \ ++ -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \ ++ -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \ ++ -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \ ++ -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \ ++ -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ ++ -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \ ++ -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \ ++ -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \ ++ -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \ ++ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ ++ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ ++ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ ++ < $(srcdir)/sys_stat.in.h; \ ++ } > $@-t && \ ++ mv $@-t $@ ++MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t ++MOSTLYCLEANDIRS += sys ++ ++EXTRA_DIST += sys_stat.in.h ++ ++## end gnulib module sys_stat ++ ++## begin gnulib module sys_time ++ ++BUILT_SOURCES += sys/time.h ++ ++# We need the following in order to create when the system ++# doesn't have one that works with the given compiler. ++sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) ++ $(AM_V_at)$(MKDIR_P) sys ++ $(AM_V_GEN)rm -f $@-t $@ && \ ++ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ ++ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ ++ -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \ ++ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ ++ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ ++ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ ++ -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ ++ -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ ++ -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ ++ -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \ ++ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ ++ -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ ++ -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \ ++ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ ++ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ ++ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ ++ < $(srcdir)/sys_time.in.h; \ ++ } > $@-t && \ ++ mv $@-t $@ ++MOSTLYCLEANFILES += sys/time.h sys/time.h-t ++ ++EXTRA_DIST += sys_time.in.h ++ ++## end gnulib module sys_time ++ + ## begin gnulib module sys_types + + BUILT_SOURCES += sys/types.h +@@ -1334,6 +1464,51 @@ EXTRA_DIST += sysexits.in.h + + ## end gnulib module sysexits + ++## begin gnulib module time ++ ++BUILT_SOURCES += time.h ++ ++# We need the following in order to create when the system ++# doesn't have one that works with the given compiler. ++time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) ++ $(AM_V_GEN)rm -f $@-t $@ && \ ++ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ ++ sed -e 's|@''GUARD_PREFIX''@|GL|g' \ ++ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ ++ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ ++ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ ++ -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ ++ -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ ++ -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ ++ -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ ++ -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ ++ -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ ++ -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ ++ -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ ++ -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ ++ -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ ++ -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ ++ -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ ++ -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \ ++ -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ ++ -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ ++ -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ ++ -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ ++ -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ ++ -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ ++ -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ ++ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ ++ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ ++ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ ++ < $(srcdir)/time.in.h; \ ++ } > $@-t && \ ++ mv $@-t $@ ++MOSTLYCLEANFILES += time.h time.h-t ++ ++EXTRA_DIST += time.in.h ++ ++## end gnulib module time ++ + ## begin gnulib module unistd + + BUILT_SOURCES += unistd.h +diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4 +new file mode 100644 +index 00000000000..1c2d66ee261 +--- /dev/null ++++ b/m4/gettimeofday.m4 +@@ -0,0 +1,138 @@ ++# serial 21 ++ ++# Copyright (C) 2001-2003, 2005, 2007, 2009-2014 Free Software Foundation, Inc. ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++dnl From Jim Meyering. ++ ++AC_DEFUN([gl_FUNC_GETTIMEOFDAY], ++[ ++ AC_REQUIRE([AC_C_RESTRICT]) ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H]) ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) ++ AC_CHECK_FUNCS_ONCE([gettimeofday]) ++ ++ gl_gettimeofday_timezone=void ++ if test $ac_cv_func_gettimeofday != yes; then ++ HAVE_GETTIMEOFDAY=0 ++ else ++ gl_FUNC_GETTIMEOFDAY_CLOBBER ++ AC_CACHE_CHECK([for gettimeofday with POSIX signature], ++ [gl_cv_func_gettimeofday_posix_signature], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ struct timeval c; ++ int gettimeofday (struct timeval *restrict, void *restrict); ++ ]], ++ [[/* glibc uses struct timezone * rather than the POSIX void * ++ if _GNU_SOURCE is defined. However, since the only portable ++ use of gettimeofday uses NULL as the second parameter, and ++ since the glibc definition is actually more typesafe, it is ++ not worth wrapping this to get a compliant signature. */ ++ int (*f) (struct timeval *restrict, void *restrict) ++ = gettimeofday; ++ int x = f (&c, 0); ++ return !(x | c.tv_sec | c.tv_usec); ++ ]])], ++ [gl_cv_func_gettimeofday_posix_signature=yes], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++int gettimeofday (struct timeval *restrict, struct timezone *restrict); ++ ]])], ++ [gl_cv_func_gettimeofday_posix_signature=almost], ++ [gl_cv_func_gettimeofday_posix_signature=no])])]) ++ if test $gl_cv_func_gettimeofday_posix_signature = almost; then ++ gl_gettimeofday_timezone='struct timezone' ++ elif test $gl_cv_func_gettimeofday_posix_signature != yes; then ++ REPLACE_GETTIMEOFDAY=1 ++ fi ++ dnl If we override 'struct timeval', we also have to override gettimeofday. ++ if test $REPLACE_STRUCT_TIMEVAL = 1; then ++ REPLACE_GETTIMEOFDAY=1 ++ fi ++ m4_ifdef([gl_FUNC_TZSET_CLOBBER], [ ++ gl_FUNC_TZSET_CLOBBER ++ case "$gl_cv_func_tzset_clobber" in ++ *yes) ++ REPLACE_GETTIMEOFDAY=1 ++ gl_GETTIMEOFDAY_REPLACE_LOCALTIME ++ AC_DEFINE([tzset], [rpl_tzset], ++ [Define to rpl_tzset if the wrapper function should be used.]) ++ AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1], ++ [Define if tzset clobbers localtime's static buffer.]) ++ ;; ++ esac ++ ]) ++ fi ++ AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone], ++ [Define this to 'void' or 'struct timezone' to match the system's ++ declaration of the second argument to gettimeofday.]) ++]) ++ ++ ++dnl See if gettimeofday clobbers the static buffer that localtime uses ++dnl for its return value. The gettimeofday function from Mac OS X 10.0.4 ++dnl (i.e., Darwin 1.3.7) has this problem. ++dnl ++dnl If it does, then arrange to use gettimeofday and localtime only via ++dnl the wrapper functions that work around the problem. ++ ++AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], ++[ ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H]) ++ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles ++ ++ AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer], ++ [gl_cv_func_gettimeofday_clobber], ++ [AC_RUN_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ #include ++ #include ++ #include ++ ]], ++ [[ ++ time_t t = 0; ++ struct tm *lt; ++ struct tm saved_lt; ++ struct timeval tv; ++ lt = localtime (&t); ++ saved_lt = *lt; ++ gettimeofday (&tv, NULL); ++ return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0; ++ ]])], ++ [gl_cv_func_gettimeofday_clobber=no], ++ [gl_cv_func_gettimeofday_clobber=yes], ++ [# When cross-compiling: ++ case "$host_os" in ++ # Guess all is fine on glibc systems. ++ *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;; ++ # If we don't know, assume the worst. ++ *) gl_cv_func_gettimeofday_clobber="guessing yes" ;; ++ esac ++ ])]) ++ ++ case "$gl_cv_func_gettimeofday_clobber" in ++ *yes) ++ REPLACE_GETTIMEOFDAY=1 ++ gl_GETTIMEOFDAY_REPLACE_LOCALTIME ++ AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1], ++ [Define if gettimeofday clobbers the localtime buffer.]) ++ ;; ++ esac ++]) ++ ++AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [ ++ REPLACE_GMTIME=1 ++ REPLACE_LOCALTIME=1 ++]) ++ ++# Prerequisites of lib/gettimeofday.c. ++AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [ ++ AC_CHECK_HEADERS([sys/timeb.h]) ++ AC_CHECK_FUNCS([_ftime]) ++]) +diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 +index 408918440b6..ef2ec5bcce0 100644 +--- a/m4/gnulib-cache.m4 ++++ b/m4/gnulib-cache.m4 +@@ -27,7 +27,7 @@ + + + # Specification in the form of a command-line invocation: +-# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex ++# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex + + # Specification in the form of a few gnulib-tool.m4 macro invocations: + gl_LOCAL_DIR([]) +@@ -39,6 +39,7 @@ gl_MODULES([ + getline + gettext + progname ++ readlink + regex + ]) + gl_AVOID([]) +diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 +index 7a19f60d85e..66fd0eda901 100644 +--- a/m4/gnulib-comp.m4 ++++ b/m4/gnulib-comp.m4 +@@ -60,10 +60,13 @@ AC_DEFUN([gl_EARLY], + # Code from module getopt-posix: + # Code from module gettext: + # Code from module gettext-h: ++ # Code from module gettimeofday: + # Code from module havelib: + # Code from module include_next: + # Code from module intprops: + # Code from module langinfo: ++ # Code from module largefile: ++ AC_REQUIRE([AC_SYS_LARGEFILE]) + # Code from module localcharset: + # Code from module locale: + # Code from module localeconv: +@@ -81,8 +84,10 @@ AC_DEFUN([gl_EARLY], + # Code from module multiarch: + # Code from module nl_langinfo: + # Code from module nocrash: ++ # Code from module pathmax: + # Code from module progname: + # Code from module rawmemchr: ++ # Code from module readlink: + # Code from module realloc-posix: + # Code from module regex: + # Code from module size_max: +@@ -92,6 +97,7 @@ AC_DEFUN([gl_EARLY], + # Code from module snippet/c++defs: + # Code from module snippet/warn-on-use: + # Code from module ssize_t: ++ # Code from module stat: + # Code from module stdalign: + # Code from module stdbool: + # Code from module stddef: +@@ -108,8 +114,11 @@ AC_DEFUN([gl_EARLY], + # Code from module strndup: + # Code from module strnlen: + # Code from module strnlen1: ++ # Code from module sys_stat: ++ # Code from module sys_time: + # Code from module sys_types: + # Code from module sysexits: ++ # Code from module time: + # Code from module unistd: + # Code from module unitypes: + # Code from module uniwidth/base: +@@ -211,7 +220,14 @@ AC_DEFUN([gl_INIT], + AM_GNU_GETTEXT_VERSION([0.18.1]) + AC_SUBST([LIBINTL]) + AC_SUBST([LTLIBINTL]) ++ gl_FUNC_GETTIMEOFDAY ++ if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then ++ AC_LIBOBJ([gettimeofday]) ++ gl_PREREQ_GETTIMEOFDAY ++ fi ++ gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) + gl_LANGINFO_H ++ AC_REQUIRE([gl_LARGEFILE]) + gl_LOCALCHARSET + LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\"" + AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) +@@ -284,6 +300,7 @@ AC_DEFUN([gl_INIT], + AC_LIBOBJ([nl_langinfo]) + fi + gl_LANGINFO_MODULE_INDICATOR([nl_langinfo]) ++ gl_PATHMAX + AC_CHECK_DECLS([program_invocation_name], [], [], [#include ]) + AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include ]) + gl_FUNC_RAWMEMCHR +@@ -292,6 +309,12 @@ AC_DEFUN([gl_INIT], + gl_PREREQ_RAWMEMCHR + fi + gl_STRING_MODULE_INDICATOR([rawmemchr]) ++ gl_FUNC_READLINK ++ if test $HAVE_READLINK = 0 || test $REPLACE_READLINK = 1; then ++ AC_LIBOBJ([readlink]) ++ gl_PREREQ_READLINK ++ fi ++ gl_UNISTD_MODULE_INDICATOR([readlink]) + gl_FUNC_REALLOC_POSIX + if test $REPLACE_REALLOC = 1; then + AC_LIBOBJ([realloc]) +@@ -309,6 +332,12 @@ AC_DEFUN([gl_INIT], + fi + gl_UNISTD_MODULE_INDICATOR([sleep]) + gt_TYPE_SSIZE_T ++ gl_FUNC_STAT ++ if test $REPLACE_STAT = 1; then ++ AC_LIBOBJ([stat]) ++ gl_PREREQ_STAT ++ fi ++ gl_SYS_STAT_MODULE_INDICATOR([stat]) + gl_STDALIGN_H + AM_STDBOOL_H + gl_STDDEF_H +@@ -355,9 +384,14 @@ AC_DEFUN([gl_INIT], + gl_PREREQ_STRNLEN + fi + gl_STRING_MODULE_INDICATOR([strnlen]) ++ gl_HEADER_SYS_STAT_H ++ AC_PROG_MKDIR_P ++ gl_HEADER_SYS_TIME_H ++ AC_PROG_MKDIR_P + gl_SYS_TYPES_H + AC_PROG_MKDIR_P + gl_SYSEXITS ++ gl_HEADER_TIME_H + gl_UNISTD_H + gl_LIBUNISTRING_LIBHEADER([0.9], [unitypes.h]) + gl_LIBUNISTRING_LIBHEADER([0.9], [uniwidth.h]) +@@ -562,6 +596,7 @@ AC_DEFUN([gl_FILE_LIST], [ + lib/getopt1.c + lib/getopt_int.h + lib/gettext.h ++ lib/gettimeofday.c + lib/intprops.h + lib/itold.c + lib/langinfo.in.h +@@ -587,6 +622,7 @@ AC_DEFUN([gl_FILE_LIST], [ + lib/msvc-nothrow.c + lib/msvc-nothrow.h + lib/nl_langinfo.c ++ lib/pathmax.h + lib/printf-args.c + lib/printf-args.h + lib/printf-parse.c +@@ -595,6 +631,7 @@ AC_DEFUN([gl_FILE_LIST], [ + lib/progname.h + lib/rawmemchr.c + lib/rawmemchr.valgrind ++ lib/readlink.c + lib/realloc.c + lib/ref-add.sin + lib/ref-del.sin +@@ -606,6 +643,7 @@ AC_DEFUN([gl_FILE_LIST], [ + lib/regexec.c + lib/size_max.h + lib/sleep.c ++ lib/stat.c + lib/stdalign.in.h + lib/stdbool.in.h + lib/stddef.in.h +@@ -627,8 +665,11 @@ AC_DEFUN([gl_FILE_LIST], [ + lib/strnlen.c + lib/strnlen1.c + lib/strnlen1.h ++ lib/sys_stat.in.h ++ lib/sys_time.in.h + lib/sys_types.in.h + lib/sysexits.in.h ++ lib/time.in.h + lib/unistd.c + lib/unistd.in.h + lib/unitypes.in.h +@@ -667,6 +708,7 @@ AC_DEFUN([gl_FILE_LIST], [ + m4/getline.m4 + m4/getopt.m4 + m4/gettext.m4 ++ m4/gettimeofday.m4 + m4/glibc2.m4 + m4/glibc21.m4 + m4/gnulib-common.m4 +@@ -681,6 +723,7 @@ AC_DEFUN([gl_FILE_LIST], [ + m4/inttypes-pri.m4 + m4/inttypes_h.m4 + m4/langinfo_h.m4 ++ m4/largefile.m4 + m4/lcmessage.m4 + m4/lib-ld.m4 + m4/lib-link.m4 +@@ -712,16 +755,19 @@ AC_DEFUN([gl_FILE_LIST], [ + m4/nls.m4 + m4/nocrash.m4 + m4/off_t.m4 ++ m4/pathmax.m4 + m4/po.m4 + m4/printf-posix.m4 + m4/printf.m4 + m4/progtest.m4 + m4/rawmemchr.m4 ++ m4/readlink.m4 + m4/realloc.m4 + m4/regex.m4 + m4/size_max.m4 + m4/sleep.m4 + m4/ssize_t.m4 ++ m4/stat.m4 + m4/stdalign.m4 + m4/stdbool.m4 + m4/stddef_h.m4 +@@ -737,9 +783,12 @@ AC_DEFUN([gl_FILE_LIST], [ + m4/strndup.m4 + m4/strnlen.m4 + m4/sys_socket_h.m4 ++ m4/sys_stat_h.m4 ++ m4/sys_time_h.m4 + m4/sys_types_h.m4 + m4/sysexits.m4 + m4/threadlib.m4 ++ m4/time_h.m4 + m4/uintmax_t.m4 + m4/unistd_h.m4 + m4/vasnprintf.m4 +diff --git a/m4/largefile.m4 b/m4/largefile.m4 +new file mode 100644 +index 00000000000..a1b564ad9af +--- /dev/null ++++ b/m4/largefile.m4 +@@ -0,0 +1,146 @@ ++# Enable large files on systems where this is not the default. ++ ++# Copyright 1992-1996, 1998-2014 Free Software Foundation, Inc. ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# The following implementation works around a problem in autoconf <= 2.69; ++# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, ++# or configures them incorrectly in some cases. ++m4_version_prereq([2.70], [] ,[ ++ ++# _AC_SYS_LARGEFILE_TEST_INCLUDES ++# ------------------------------- ++m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], ++[@%:@include ++ /* Check that off_t can represent 2**63 - 1 correctly. ++ We can't simply define LARGE_OFF_T to be 9223372036854775807, ++ since some C++ compilers masquerading as C compilers ++ incorrectly reject 9223372036854775807. */ ++@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) ++ int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721 ++ && LARGE_OFF_T % 2147483647 == 1) ++ ? 1 : -1]];[]dnl ++]) ++ ++ ++# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, ++# CACHE-VAR, ++# DESCRIPTION, ++# PROLOGUE, [FUNCTION-BODY]) ++# -------------------------------------------------------- ++m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE], ++[AC_CACHE_CHECK([for $1 value needed for large files], [$3], ++[while :; do ++ m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])( ++ [AC_LANG_PROGRAM([$5], [$6])], ++ [$3=no; break]) ++ m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])( ++ [AC_LANG_PROGRAM([@%:@define $1 $2 ++$5], [$6])], ++ [$3=$2; break]) ++ $3=unknown ++ break ++done]) ++case $$3 in #( ++ no | unknown) ;; ++ *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);; ++esac ++rm -rf conftest*[]dnl ++])# _AC_SYS_LARGEFILE_MACRO_VALUE ++ ++ ++# AC_SYS_LARGEFILE ++# ---------------- ++# By default, many hosts won't let programs access large files; ++# one must use special compiler options to get large-file access to work. ++# For more details about this brain damage please see: ++# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html ++AC_DEFUN([AC_SYS_LARGEFILE], ++[AC_ARG_ENABLE(largefile, ++ [ --disable-largefile omit support for large files]) ++if test "$enable_largefile" != no; then ++ ++ AC_CACHE_CHECK([for special C compiler options needed for large files], ++ ac_cv_sys_largefile_CC, ++ [ac_cv_sys_largefile_CC=no ++ if test "$GCC" != yes; then ++ ac_save_CC=$CC ++ while :; do ++ # IRIX 6.2 and later do not support large files by default, ++ # so use the C compiler's -n32 option if that helps. ++ AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])]) ++ AC_COMPILE_IFELSE([], [break]) ++ CC="$CC -n32" ++ AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break]) ++ break ++ done ++ CC=$ac_save_CC ++ rm -f conftest.$ac_ext ++ fi]) ++ if test "$ac_cv_sys_largefile_CC" != no; then ++ CC=$CC$ac_cv_sys_largefile_CC ++ fi ++ ++ _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ++ ac_cv_sys_file_offset_bits, ++ [Number of bits in a file offset, on hosts where this is settable.], ++ [_AC_SYS_LARGEFILE_TEST_INCLUDES]) ++ if test $ac_cv_sys_file_offset_bits = unknown; then ++ _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ++ ac_cv_sys_large_files, ++ [Define for large files, on AIX-style hosts.], ++ [_AC_SYS_LARGEFILE_TEST_INCLUDES]) ++ fi ++ ++ AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1], ++ [Enable large inode numbers on Mac OS X 10.5.]) ++fi ++])# AC_SYS_LARGEFILE ++])# m4_version_prereq 2.70 ++ ++# Enable large files on systems where this is implemented by Gnulib, not by the ++# system headers. ++# Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib ++# overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively. ++AC_DEFUN([gl_LARGEFILE], ++[ ++ AC_REQUIRE([AC_CANONICAL_HOST]) ++ case "$host_os" in ++ mingw*) ++ dnl Native Windows. ++ dnl mingw64 defines off_t to a 64-bit type already, if ++ dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE. ++ AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1]; ++ ]], ++ [[]])], ++ [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no]) ++ ]) ++ if test $gl_cv_type_off_t_64 = no; then ++ WINDOWS_64_BIT_OFF_T=1 ++ else ++ WINDOWS_64_BIT_OFF_T=0 ++ fi ++ dnl But all native Windows platforms (including mingw64) have a 32-bit ++ dnl st_size member in 'struct stat'. ++ WINDOWS_64_BIT_ST_SIZE=1 ++ ;; ++ *) ++ dnl Nothing to do on gnulib's side. ++ dnl A 64-bit off_t is ++ dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX, ++ dnl OSF/1, Cygwin, ++ dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on ++ dnl glibc, HP-UX, Solaris, ++ dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX, ++ dnl - impossible to achieve on Minix 3.1.8. ++ WINDOWS_64_BIT_OFF_T=0 ++ WINDOWS_64_BIT_ST_SIZE=0 ++ ;; ++ esac ++]) +diff --git a/m4/pathmax.m4 b/m4/pathmax.m4 +new file mode 100644 +index 00000000000..114f91f04b5 +--- /dev/null ++++ b/m4/pathmax.m4 +@@ -0,0 +1,42 @@ ++# pathmax.m4 serial 10 ++dnl Copyright (C) 2002-2003, 2005-2006, 2009-2014 Free Software Foundation, ++dnl Inc. ++dnl This file is free software; the Free Software Foundation ++dnl gives unlimited permission to copy and/or distribute it, ++dnl with or without modifications, as long as this notice is preserved. ++ ++AC_DEFUN([gl_PATHMAX], ++[ ++ dnl Prerequisites of lib/pathmax.h. ++ AC_CHECK_HEADERS_ONCE([sys/param.h]) ++]) ++ ++# Expands to a piece of C program that defines PATH_MAX in the same way as ++# "pathmax.h" will do. ++AC_DEFUN([gl_PATHMAX_SNIPPET], [[ ++/* Arrange to define PATH_MAX, like "pathmax.h" does. */ ++#if HAVE_UNISTD_H ++# include ++#endif ++#include ++#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN ++# include ++#endif ++#if !defined PATH_MAX && defined MAXPATHLEN ++# define PATH_MAX MAXPATHLEN ++#endif ++#ifdef __hpux ++# undef PATH_MAX ++# define PATH_MAX 1024 ++#endif ++#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ ++# undef PATH_MAX ++# define PATH_MAX 260 ++#endif ++]]) ++ ++# Prerequisites of gl_PATHMAX_SNIPPET. ++AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ], ++[ ++ AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h]) ++]) +diff --git a/m4/readlink.m4 b/m4/readlink.m4 +new file mode 100644 +index 00000000000..f9ce868c2e4 +--- /dev/null ++++ b/m4/readlink.m4 +@@ -0,0 +1,71 @@ ++# readlink.m4 serial 12 ++dnl Copyright (C) 2003, 2007, 2009-2014 Free Software Foundation, Inc. ++dnl This file is free software; the Free Software Foundation ++dnl gives unlimited permission to copy and/or distribute it, ++dnl with or without modifications, as long as this notice is preserved. ++ ++AC_DEFUN([gl_FUNC_READLINK], ++[ ++ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) ++ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles ++ AC_CHECK_FUNCS_ONCE([readlink]) ++ if test $ac_cv_func_readlink = no; then ++ HAVE_READLINK=0 ++ else ++ AC_CACHE_CHECK([whether readlink signature is correct], ++ [gl_cv_decl_readlink_works], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ /* Cause compilation failure if original declaration has wrong type. */ ++ ssize_t readlink (const char *, char *, size_t);]])], ++ [gl_cv_decl_readlink_works=yes], [gl_cv_decl_readlink_works=no])]) ++ dnl Solaris 9 ignores trailing slash. ++ dnl FreeBSD 7.2 dereferences only one level of links with trailing slash. ++ AC_CACHE_CHECK([whether readlink handles trailing slash correctly], ++ [gl_cv_func_readlink_works], ++ [# We have readlink, so assume ln -s works. ++ ln -s conftest.no-such conftest.link ++ ln -s conftest.link conftest.lnk2 ++ AC_RUN_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++]], [[char buf[20]; ++ return readlink ("conftest.lnk2/", buf, sizeof buf) != -1;]])], ++ [gl_cv_func_readlink_works=yes], [gl_cv_func_readlink_works=no], ++ [case "$host_os" in ++ # Guess yes on glibc systems. ++ *-gnu*) gl_cv_func_readlink_works="guessing yes" ;; ++ # If we don't know, assume the worst. ++ *) gl_cv_func_readlink_works="guessing no" ;; ++ esac ++ ]) ++ rm -f conftest.link conftest.lnk2]) ++ case "$gl_cv_func_readlink_works" in ++ *yes) ++ if test "$gl_cv_decl_readlink_works" != yes; then ++ REPLACE_READLINK=1 ++ fi ++ ;; ++ *) ++ AC_DEFINE([READLINK_TRAILING_SLASH_BUG], [1], [Define to 1 if readlink ++ fails to recognize a trailing slash.]) ++ REPLACE_READLINK=1 ++ ;; ++ esac ++ fi ++]) ++ ++# Like gl_FUNC_READLINK, except prepare for separate compilation ++# (no REPLACE_READLINK, no AC_LIBOBJ). ++AC_DEFUN([gl_FUNC_READLINK_SEPARATE], ++[ ++ AC_CHECK_FUNCS_ONCE([readlink]) ++ gl_PREREQ_READLINK ++]) ++ ++# Prerequisites of lib/readlink.c. ++AC_DEFUN([gl_PREREQ_READLINK], ++[ ++ : ++]) +diff --git a/m4/stat.m4 b/m4/stat.m4 +new file mode 100644 +index 00000000000..1ae327b3684 +--- /dev/null ++++ b/m4/stat.m4 +@@ -0,0 +1,71 @@ ++# serial 11 ++ ++# Copyright (C) 2009-2014 Free Software Foundation, Inc. ++# ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++AC_DEFUN([gl_FUNC_STAT], ++[ ++ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles ++ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) ++ AC_CHECK_FUNCS_ONCE([lstat]) ++ dnl mingw is the only known platform where stat(".") and stat("./") differ ++ AC_CACHE_CHECK([whether stat handles trailing slashes on directories], ++ [gl_cv_func_stat_dir_slash], ++ [AC_RUN_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++]], [[struct stat st; return stat (".", &st) != stat ("./", &st);]])], ++ [gl_cv_func_stat_dir_slash=yes], [gl_cv_func_stat_dir_slash=no], ++ [case $host_os in ++ mingw*) gl_cv_func_stat_dir_slash="guessing no";; ++ *) gl_cv_func_stat_dir_slash="guessing yes";; ++ esac])]) ++ dnl AIX 7.1, Solaris 9, mingw64 mistakenly succeed on stat("file/"). ++ dnl (For mingw, this is due to a broken stat() override in libmingwex.a.) ++ dnl FreeBSD 7.2 mistakenly succeeds on stat("link-to-file/"). ++ AC_CACHE_CHECK([whether stat handles trailing slashes on files], ++ [gl_cv_func_stat_file_slash], ++ [touch conftest.tmp ++ # Assume that if we have lstat, we can also check symlinks. ++ if test $ac_cv_func_lstat = yes; then ++ ln -s conftest.tmp conftest.lnk ++ fi ++ AC_RUN_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++]], [[int result = 0; ++ struct stat st; ++ if (!stat ("conftest.tmp/", &st)) ++ result |= 1; ++#if HAVE_LSTAT ++ if (!stat ("conftest.lnk/", &st)) ++ result |= 2; ++#endif ++ return result; ++ ]])], ++ [gl_cv_func_stat_file_slash=yes], [gl_cv_func_stat_file_slash=no], ++ [case "$host_os" in ++ # Guess yes on glibc systems. ++ *-gnu*) gl_cv_func_stat_file_slash="guessing yes" ;; ++ # If we don't know, assume the worst. ++ *) gl_cv_func_stat_file_slash="guessing no" ;; ++ esac ++ ]) ++ rm -f conftest.tmp conftest.lnk]) ++ case $gl_cv_func_stat_dir_slash in ++ *no) REPLACE_STAT=1 ++ AC_DEFINE([REPLACE_FUNC_STAT_DIR], [1], [Define to 1 if stat needs ++ help when passed a directory name with a trailing slash]);; ++ esac ++ case $gl_cv_func_stat_file_slash in ++ *no) REPLACE_STAT=1 ++ AC_DEFINE([REPLACE_FUNC_STAT_FILE], [1], [Define to 1 if stat needs ++ help when passed a file name with a trailing slash]);; ++ esac ++]) ++ ++# Prerequisites of lib/stat.c. ++AC_DEFUN([gl_PREREQ_STAT], [:]) +diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 +new file mode 100644 +index 00000000000..eaa7642ba31 +--- /dev/null ++++ b/m4/sys_stat_h.m4 +@@ -0,0 +1,96 @@ ++# sys_stat_h.m4 serial 28 -*- Autoconf -*- ++dnl Copyright (C) 2006-2014 Free Software Foundation, Inc. ++dnl This file is free software; the Free Software Foundation ++dnl gives unlimited permission to copy and/or distribute it, ++dnl with or without modifications, as long as this notice is preserved. ++ ++dnl From Eric Blake. ++dnl Provide a GNU-like . ++ ++AC_DEFUN([gl_HEADER_SYS_STAT_H], ++[ ++ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) ++ ++ dnl Check for broken stat macros. ++ AC_REQUIRE([AC_HEADER_STAT]) ++ ++ gl_CHECK_NEXT_HEADERS([sys/stat.h]) ++ ++ dnl Ensure the type mode_t gets defined. ++ AC_REQUIRE([AC_TYPE_MODE_T]) ++ ++ dnl Whether to override 'struct stat'. ++ m4_ifdef([gl_LARGEFILE], [ ++ AC_REQUIRE([gl_LARGEFILE]) ++ ], [ ++ WINDOWS_64_BIT_ST_SIZE=0 ++ ]) ++ AC_SUBST([WINDOWS_64_BIT_ST_SIZE]) ++ if test $WINDOWS_64_BIT_ST_SIZE = 1; then ++ AC_DEFINE([_GL_WINDOWS_64_BIT_ST_SIZE], [1], ++ [Define to 1 if Gnulib overrides 'struct stat' on Windows so that ++ struct stat.st_size becomes 64-bit.]) ++ fi ++ ++ dnl Define types that are supposed to be defined in or ++ dnl . ++ AC_CHECK_TYPE([nlink_t], [], ++ [AC_DEFINE([nlink_t], [int], ++ [Define to the type of st_nlink in struct stat, or a supertype.])], ++ [#include ++ #include ]) ++ ++ dnl Check for declarations of anything we want to poison if the ++ dnl corresponding gnulib module is not in use. ++ gl_WARN_ON_USE_PREPARE([[#include ++ ]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat ++ mknod mknodat stat utimensat]) ++]) # gl_HEADER_SYS_STAT_H ++ ++AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR], ++[ ++ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. ++ AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) ++ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) ++ dnl Define it also as a C macro, for the benefit of the unit tests. ++ gl_MODULE_INDICATOR_FOR_TESTS([$1]) ++]) ++ ++AC_DEFUN([gl_SYS_STAT_H_DEFAULTS], ++[ ++ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR ++ GNULIB_FCHMODAT=0; AC_SUBST([GNULIB_FCHMODAT]) ++ GNULIB_FSTAT=0; AC_SUBST([GNULIB_FSTAT]) ++ GNULIB_FSTATAT=0; AC_SUBST([GNULIB_FSTATAT]) ++ GNULIB_FUTIMENS=0; AC_SUBST([GNULIB_FUTIMENS]) ++ GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD]) ++ GNULIB_LSTAT=0; AC_SUBST([GNULIB_LSTAT]) ++ GNULIB_MKDIRAT=0; AC_SUBST([GNULIB_MKDIRAT]) ++ GNULIB_MKFIFO=0; AC_SUBST([GNULIB_MKFIFO]) ++ GNULIB_MKFIFOAT=0; AC_SUBST([GNULIB_MKFIFOAT]) ++ GNULIB_MKNOD=0; AC_SUBST([GNULIB_MKNOD]) ++ GNULIB_MKNODAT=0; AC_SUBST([GNULIB_MKNODAT]) ++ GNULIB_STAT=0; AC_SUBST([GNULIB_STAT]) ++ GNULIB_UTIMENSAT=0; AC_SUBST([GNULIB_UTIMENSAT]) ++ dnl Assume proper GNU behavior unless another module says otherwise. ++ HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT]) ++ HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT]) ++ HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS]) ++ HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD]) ++ HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT]) ++ HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT]) ++ HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO]) ++ HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT]) ++ HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD]) ++ HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT]) ++ HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT]) ++ REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT]) ++ REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT]) ++ REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS]) ++ REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT]) ++ REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR]) ++ REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO]) ++ REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD]) ++ REPLACE_STAT=0; AC_SUBST([REPLACE_STAT]) ++ REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT]) ++]) +diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4 +new file mode 100644 +index 00000000000..5c79300f8ec +--- /dev/null ++++ b/m4/sys_time_h.m4 +@@ -0,0 +1,110 @@ ++# Configure a replacement for . ++# serial 8 ++ ++# Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc. ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# Written by Paul Eggert and Martin Lambers. ++ ++AC_DEFUN([gl_HEADER_SYS_TIME_H], ++[ ++ dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement ++ dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1 ++ dnl statements that occur in other macros. ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY]) ++]) ++ ++AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], ++[ ++ AC_REQUIRE([AC_C_RESTRICT]) ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) ++ AC_CHECK_HEADERS_ONCE([sys/time.h]) ++ gl_CHECK_NEXT_HEADERS([sys/time.h]) ++ ++ if test $ac_cv_header_sys_time_h != yes; then ++ HAVE_SYS_TIME_H=0 ++ fi ++ ++ dnl On native Windows with MSVC, 'struct timeval' is defined in ++ dnl only. So include that header in the list. ++ gl_PREREQ_SYS_H_WINSOCK2 ++ AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#if HAVE_SYS_TIME_H ++ #include ++ #endif ++ #include ++ #if HAVE_WINSOCK2_H ++ # include ++ #endif ++ ]], ++ [[static struct timeval x; x.tv_sec = x.tv_usec;]])], ++ [gl_cv_sys_struct_timeval=yes], ++ [gl_cv_sys_struct_timeval=no]) ++ ]) ++ if test $gl_cv_sys_struct_timeval != yes; then ++ HAVE_STRUCT_TIMEVAL=0 ++ else ++ dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined ++ dnl (in and for mingw64, in only ++ dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is ++ dnl smaller than the 'time_t' type mandated by POSIX. ++ dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but ++ dnl that is good enough. ++ AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member], ++ [gl_cv_sys_struct_timeval_tv_sec], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#if HAVE_SYS_TIME_H ++ #include ++ #endif ++ #include ++ #if HAVE_WINSOCK2_H ++ # include ++ #endif ++ ]], ++ [[static struct timeval x; ++ typedef int verify_tv_sec_type[ ++ sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1 ++ ]; ++ ]])], ++ [gl_cv_sys_struct_timeval_tv_sec=yes], ++ [gl_cv_sys_struct_timeval_tv_sec=no]) ++ ]) ++ if test $gl_cv_sys_struct_timeval_tv_sec != yes; then ++ REPLACE_STRUCT_TIMEVAL=1 ++ fi ++ fi ++ ++ dnl Check for declarations of anything we want to poison if the ++ dnl corresponding gnulib module is not in use. ++ gl_WARN_ON_USE_PREPARE([[ ++#if HAVE_SYS_TIME_H ++# include ++#endif ++#include ++ ]], [gettimeofday]) ++]) ++ ++AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR], ++[ ++ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. ++ AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) ++ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) ++ dnl Define it also as a C macro, for the benefit of the unit tests. ++ gl_MODULE_INDICATOR_FOR_TESTS([$1]) ++]) ++ ++AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS], ++[ ++ GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY]) ++ dnl Assume POSIX behavior unless another module says otherwise. ++ HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY]) ++ HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL]) ++ HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H]) ++ REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY]) ++ REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL]) ++]) +diff --git a/m4/time_h.m4 b/m4/time_h.m4 +new file mode 100644 +index 00000000000..9852778f9a5 +--- /dev/null ++++ b/m4/time_h.m4 +@@ -0,0 +1,118 @@ ++# Configure a more-standard replacement for . ++ ++# Copyright (C) 2000-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc. ++ ++# serial 8 ++ ++# This file is free software; the Free Software Foundation ++# gives unlimited permission to copy and/or distribute it, ++# with or without modifications, as long as this notice is preserved. ++ ++# Written by Paul Eggert and Jim Meyering. ++ ++AC_DEFUN([gl_HEADER_TIME_H], ++[ ++ dnl Use AC_REQUIRE here, so that the default behavior below is expanded ++ dnl once only, before all statements that occur in other macros. ++ AC_REQUIRE([gl_HEADER_TIME_H_BODY]) ++]) ++ ++AC_DEFUN([gl_HEADER_TIME_H_BODY], ++[ ++ AC_REQUIRE([AC_C_RESTRICT]) ++ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) ++ gl_NEXT_HEADERS([time.h]) ++ AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) ++]) ++ ++dnl Check whether 'struct timespec' is declared ++dnl in time.h, sys/time.h, or pthread.h. ++ ++AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], ++[ ++ AC_CHECK_HEADERS_ONCE([sys/time.h]) ++ AC_CACHE_CHECK([for struct timespec in ], ++ [gl_cv_sys_struct_timespec_in_time_h], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ ]], ++ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], ++ [gl_cv_sys_struct_timespec_in_time_h=yes], ++ [gl_cv_sys_struct_timespec_in_time_h=no])]) ++ ++ TIME_H_DEFINES_STRUCT_TIMESPEC=0 ++ SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 ++ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 ++ if test $gl_cv_sys_struct_timespec_in_time_h = yes; then ++ TIME_H_DEFINES_STRUCT_TIMESPEC=1 ++ else ++ AC_CACHE_CHECK([for struct timespec in ], ++ [gl_cv_sys_struct_timespec_in_sys_time_h], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ ]], ++ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], ++ [gl_cv_sys_struct_timespec_in_sys_time_h=yes], ++ [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) ++ if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then ++ SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 ++ else ++ AC_CACHE_CHECK([for struct timespec in ], ++ [gl_cv_sys_struct_timespec_in_pthread_h], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [[#include ++ ]], ++ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], ++ [gl_cv_sys_struct_timespec_in_pthread_h=yes], ++ [gl_cv_sys_struct_timespec_in_pthread_h=no])]) ++ if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then ++ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 ++ fi ++ fi ++ fi ++ AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) ++ AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) ++ AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) ++]) ++ ++AC_DEFUN([gl_TIME_MODULE_INDICATOR], ++[ ++ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. ++ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) ++ gl_MODULE_INDICATOR_SET_VARIABLE([$1]) ++ dnl Define it also as a C macro, for the benefit of the unit tests. ++ gl_MODULE_INDICATOR_FOR_TESTS([$1]) ++]) ++ ++AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], ++[ ++ GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) ++ GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) ++ GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) ++ GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) ++ GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) ++ dnl Assume proper GNU behavior unless another module says otherwise. ++ HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) ++ HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) ++ HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) ++ HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) ++ dnl If another module says to replace or to not replace, do that. ++ dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; ++ dnl this lets maintainers check for portability. ++ REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) ++ REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) ++ REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) ++ REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) ++ ++ dnl Hack so that the time module doesn't depend on the sys_time module. ++ dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent. ++ : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY]) ++ dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME ++ dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier ++ dnl is no longer a big deal. ++ REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME]) ++ REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME]) ++]) diff --git a/0211-Load-arm-with-SB-enabled.patch b/0211-Load-arm-with-SB-enabled.patch deleted file mode 100644 index 7edea37..0000000 --- a/0211-Load-arm-with-SB-enabled.patch +++ /dev/null @@ -1,426 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 18 Sep 2014 11:26:14 -0400 -Subject: [PATCH] Load arm with SB enabled. - -Make sure we actually try to validate secure boot on this platform (even -though we're not shipping it enabled by default.) - -This means giving the kernel grub's loaded image as the vehicle for the -kernel command line, because we can't call systab->bs->LoadImage() if SB -is enabled. ---- - grub-core/Makefile.core.def | 3 + - grub-core/loader/arm64/linux.c | 121 ++++++++++++++++++++------------------ - grub-core/loader/efi/linux.c | 65 ++++++++++++++++++++ - grub-core/loader/i386/efi/linux.c | 39 +----------- - include/grub/arm64/linux.h | 7 +++ - include/grub/efi/linux.h | 31 ++++++++++ - 6 files changed, 173 insertions(+), 93 deletions(-) - create mode 100644 grub-core/loader/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 3f42ce16fad..e675ab2da01 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1704,6 +1704,8 @@ module = { - ia64_efi = loader/ia64/efi/linux.c; - arm = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; -+ arm64 = loader/efi/linux.c; -+ fdt = lib/fdt.c; - common = loader/linux.c; - common = lib/cmdline.c; - enable = noemu; -@@ -1771,6 +1773,7 @@ module = { - name = linuxefi; - efi = loader/i386/efi/linux.c; - efi = lib/cmdline.c; -+ efi = loader/efi/linux.c; - enable = i386_efi; - enable = x86_64_efi; - }; -diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c -index ebe1e730d63..ab0d27ee4df 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 -@@ -40,6 +41,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; -@@ -66,7 +68,8 @@ grub_arm64_uefi_check_image (struct linux_arm64_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; - -@@ -101,79 +104,73 @@ 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_arm64_uefi_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) -+ 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_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, 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 *)kernel_addr, handover_offset, -+ kernel_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_arm64_uefi_boot_image((grub_addr_t)kernel_addr, -- kernel_size, linux_args)); -+ return grub_arm64_uefi_boot_image ((grub_addr_t)kernel_addr, -+ kernel_size, linux_args); - } - - static grub_err_t -@@ -250,6 +247,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - { - grub_file_t file = 0; - struct linux_arm64_kernel_header lh; -+ struct grub_arm64_linux_pe_header *pe; - - grub_dl_ref (my_mod); - -@@ -294,6 +292,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/efi/linux.c b/grub-core/loader/efi/linux.c -new file mode 100644 -index 00000000000..aea378adf5c ---- /dev/null -+++ b/grub-core/loader/efi/linux.c -@@ -0,0 +1,65 @@ -+/* -+ * 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; -+} -+ -+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; -+} -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index b79e6320ba9..e5b778577f9 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -26,6 +26,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -40,52 +41,18 @@ static char *linux_cmdline; - - #define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) - --#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; -- --static 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; --} -- --typedef void(*handover_func)(void *, grub_efi_system_table_t *, struct linux_kernel_params *); -- - static grub_err_t - grub_linuxefi_boot (void) - { -- handover_func hf; - int offset = 0; - - #ifdef __x86_64__ - offset = 512; - #endif -- -- hf = (handover_func)((char *)kernel_mem + handover_offset + offset); -- - asm volatile ("cli"); - -- hf (grub_efi_image_handle, grub_efi_system_table, params); -- -- /* Not reached */ -- return GRUB_ERR_NONE; -+ return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, -+ params); - } - - static grub_err_t -diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h -index b0634762450..6ea38bd95ab 100644 ---- a/include/grub/arm64/linux.h -+++ b/include/grub/arm64/linux.h -@@ -20,6 +20,7 @@ - #define GRUB_ARM64_LINUX_HEADER 1 - - #include -+#include - - #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ - -@@ -41,5 +42,11 @@ struct linux_arm64_kernel_header - grub_err_t grub_arm64_uefi_check_image (struct linux_arm64_kernel_header *lh); - grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, - char *args); -+struct grub_arm64_linux_pe_header -+{ -+ grub_uint32_t magic; -+ struct grub_pe32_coff_header coff; -+ struct grub_pe64_optional_header opt; -+}; - - #endif /* ! GRUB_ARM64_LINUX_HEADER */ -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/0212-Make-editenv-chase-symlinks-including-those-across-d.patch b/0212-Make-editenv-chase-symlinks-including-those-across-d.patch new file mode 100644 index 0000000..73e316e --- /dev/null +++ b/0212-Make-editenv-chase-symlinks-including-those-across-d.patch @@ -0,0 +1,102 @@ +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 | 9 +++++++++ + util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- + 2 files changed, 53 insertions(+), 2 deletions(-) + +diff --git a/Makefile.util.def b/Makefile.util.def +index c7b775bce73..d08713b5500 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -231,8 +231,17 @@ 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 = 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 c6f8d2298c3..d8d1dad6ab9 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); + +@@ -59,7 +60,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/0212-Try-prefix-if-fw_path-doesn-t-work.patch b/0212-Try-prefix-if-fw_path-doesn-t-work.patch deleted file mode 100644 index 1ded908..0000000 --- a/0212-Try-prefix-if-fw_path-doesn-t-work.patch +++ /dev/null @@ -1,208 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 3 Oct 2014 11:08:03 -0400 -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 f5423ce27d9..e01bc6eab19 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -124,23 +124,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 0769bf850d3..16d2ce06d5a 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 7d9c4f09b9b..b69f9e738fa 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -331,74 +331,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); -+ 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); -- 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/0213-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch b/0213-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch new file mode 100644 index 0000000..bbe37b8 --- /dev/null +++ b/0213-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 c548d989b2e..03ea8460bfd 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/0213-Update-info-with-grub.cfg-netboot-selection-order-11.patch b/0213-Update-info-with-grub.cfg-netboot-selection-order-11.patch deleted file mode 100644 index 26de3f4..0000000 --- a/0213-Update-info-with-grub.cfg-netboot-selection-order-11.patch +++ /dev/null @@ -1,66 +0,0 @@ -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 2fd32608c01..a7155c22ffe 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/0214-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch b/0214-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch new file mode 100644 index 0000000..fc29633 --- /dev/null +++ b/0214-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/0214-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch b/0214-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch deleted file mode 100644 index b093cf1..0000000 --- a/0214-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch +++ /dev/null @@ -1,447 +0,0 @@ -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 ---- - configure.ac | 29 +++++ - Makefile.util.def | 16 +++ - util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ - .gitignore | 2 + - util/grub-mkconfig_lib.in | 8 +- - util/grub-rpm-sort.8 | 12 ++ - 6 files changed, 347 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 d5db2803ec4..056df1cbaf9 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -65,6 +65,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]) -@@ -88,6 +89,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]) -@@ -1790,6 +1792,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 d08713b5500..406d96861b6 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -685,6 +685,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 = grub-core/gnulib/libgnu.a; -+ ldadd = libgrubkern.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/.gitignore b/.gitignore -index d95fac5789c..1c85371298c 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -101,6 +101,8 @@ grub-*.tar.* - /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-default -diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 1a4a57898f9..7fe3598435c 100644 ---- a/util/grub-mkconfig_lib.in -+++ b/util/grub-mkconfig_lib.in -@@ -214,6 +214,12 @@ version_sort () - esac - } - -+if [ "x$RPMLIB" = x ]; then -+ kernel_sort=version_sort -+else -+ kernel_sort="${sbindir}/grub-rpm-sort" -+fi -+ - version_test_numeric () - { - version_test_numeric_a="$1" -@@ -230,7 +236,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/0215-Handle-rssd-storage-devices.patch b/0215-Handle-rssd-storage-devices.patch deleted file mode 100644 index 8f25692..0000000 --- a/0215-Handle-rssd-storage-devices.patch +++ /dev/null @@ -1,36 +0,0 @@ -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/0215-Load-arm-with-SB-enabled.patch b/0215-Load-arm-with-SB-enabled.patch new file mode 100644 index 0000000..7edea37 --- /dev/null +++ b/0215-Load-arm-with-SB-enabled.patch @@ -0,0 +1,426 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 18 Sep 2014 11:26:14 -0400 +Subject: [PATCH] Load arm with SB enabled. + +Make sure we actually try to validate secure boot on this platform (even +though we're not shipping it enabled by default.) + +This means giving the kernel grub's loaded image as the vehicle for the +kernel command line, because we can't call systab->bs->LoadImage() if SB +is enabled. +--- + grub-core/Makefile.core.def | 3 + + grub-core/loader/arm64/linux.c | 121 ++++++++++++++++++++------------------ + grub-core/loader/efi/linux.c | 65 ++++++++++++++++++++ + grub-core/loader/i386/efi/linux.c | 39 +----------- + include/grub/arm64/linux.h | 7 +++ + include/grub/efi/linux.h | 31 ++++++++++ + 6 files changed, 173 insertions(+), 93 deletions(-) + create mode 100644 grub-core/loader/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 3f42ce16fad..e675ab2da01 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1704,6 +1704,8 @@ module = { + ia64_efi = loader/ia64/efi/linux.c; + arm = loader/arm/linux.c; + arm64 = loader/arm64/linux.c; ++ arm64 = loader/efi/linux.c; ++ fdt = lib/fdt.c; + common = loader/linux.c; + common = lib/cmdline.c; + enable = noemu; +@@ -1771,6 +1773,7 @@ module = { + name = linuxefi; + efi = loader/i386/efi/linux.c; + efi = lib/cmdline.c; ++ efi = loader/efi/linux.c; + enable = i386_efi; + enable = x86_64_efi; + }; +diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c +index ebe1e730d63..ab0d27ee4df 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 +@@ -40,6 +41,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; +@@ -66,7 +68,8 @@ grub_arm64_uefi_check_image (struct linux_arm64_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; + +@@ -101,79 +104,73 @@ 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_arm64_uefi_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) ++ 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_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, 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 *)kernel_addr, handover_offset, ++ kernel_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_arm64_uefi_boot_image((grub_addr_t)kernel_addr, +- kernel_size, linux_args)); ++ return grub_arm64_uefi_boot_image ((grub_addr_t)kernel_addr, ++ kernel_size, linux_args); + } + + static grub_err_t +@@ -250,6 +247,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + { + grub_file_t file = 0; + struct linux_arm64_kernel_header lh; ++ struct grub_arm64_linux_pe_header *pe; + + grub_dl_ref (my_mod); + +@@ -294,6 +292,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/efi/linux.c b/grub-core/loader/efi/linux.c +new file mode 100644 +index 00000000000..aea378adf5c +--- /dev/null ++++ b/grub-core/loader/efi/linux.c +@@ -0,0 +1,65 @@ ++/* ++ * 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; ++} ++ ++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; ++} +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index b79e6320ba9..e5b778577f9 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -40,52 +41,18 @@ static char *linux_cmdline; + + #define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12) + +-#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; +- +-static 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; +-} +- +-typedef void(*handover_func)(void *, grub_efi_system_table_t *, struct linux_kernel_params *); +- + static grub_err_t + grub_linuxefi_boot (void) + { +- handover_func hf; + int offset = 0; + + #ifdef __x86_64__ + offset = 512; + #endif +- +- hf = (handover_func)((char *)kernel_mem + handover_offset + offset); +- + asm volatile ("cli"); + +- hf (grub_efi_image_handle, grub_efi_system_table, params); +- +- /* Not reached */ +- return GRUB_ERR_NONE; ++ return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset, ++ params); + } + + static grub_err_t +diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h +index b0634762450..6ea38bd95ab 100644 +--- a/include/grub/arm64/linux.h ++++ b/include/grub/arm64/linux.h +@@ -20,6 +20,7 @@ + #define GRUB_ARM64_LINUX_HEADER 1 + + #include ++#include + + #define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */ + +@@ -41,5 +42,11 @@ struct linux_arm64_kernel_header + grub_err_t grub_arm64_uefi_check_image (struct linux_arm64_kernel_header *lh); + grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, + char *args); ++struct grub_arm64_linux_pe_header ++{ ++ grub_uint32_t magic; ++ struct grub_pe32_coff_header coff; ++ struct grub_pe64_optional_header opt; ++}; + + #endif /* ! GRUB_ARM64_LINUX_HEADER */ +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/0216-Try-prefix-if-fw_path-doesn-t-work.patch b/0216-Try-prefix-if-fw_path-doesn-t-work.patch new file mode 100644 index 0000000..1ded908 --- /dev/null +++ b/0216-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: Fri, 3 Oct 2014 11:08:03 -0400 +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 f5423ce27d9..e01bc6eab19 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -124,23 +124,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 0769bf850d3..16d2ce06d5a 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 7d9c4f09b9b..b69f9e738fa 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -331,74 +331,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); ++ 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); +- 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/0216-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch b/0216-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch deleted file mode 100644 index 6faf353..0000000 --- a/0216-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 27 Oct 2014 09:22:55 -0400 -Subject: [PATCH] Try to emit linux16/initrd16 and linuxefi/initrdefi in - 30-os_prober. - -Resolves: rhbz#1108296 - -Signed-off-by: Peter Jones ---- - util/grub.d/30_os-prober.in | 30 ++++++++++++++++++++++++++---- - 1 file changed, 26 insertions(+), 4 deletions(-) - -diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index 9b8f5968e2d..dc98eace934 100644 ---- a/util/grub.d/30_os-prober.in -+++ b/util/grub.d/30_os-prober.in -@@ -141,6 +141,28 @@ for OS in ${OSPROBED} ; do - # os-prober returns text string followed by optional counter - CLASS="--class $(echo "${LABEL}" | LC_ALL=C sed 's,[[:digit:]]*$,,' | cut -d' ' -f1 | tr 'A-Z' 'a-z' | LC_ALL=C sed 's,[^[:alnum:]_],_,g')" - -+ sixteenbit="" -+ linuxefi="linux" -+ initrdefi="initrd" -+ case "$machine" in -+ i?86|x86_64) -+ sixteenbit="16" -+ linuxefi="linuxefi" -+ initrdefi="initrdefi" -+ ;; -+ aarch64) -+ linuxefi="linux" -+ initrdefi="initrd" -+ esac -+ linux="linux${sixteenbit}" -+ initrd="initrd${sixteenbit}" -+ # there's no way to tell that the /other/ os is booting through UEFI, -+ # but if we are it's an okay bet... -+ if [ -d /sys/firmware/efi ]; then -+ linux=$linuxefi -+ initrd=$initrdefi -+ fi -+ - gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2 - - case ${BOOT} in -@@ -241,11 +263,11 @@ EOF - save_default_entry | grub_add_tab - printf '%s\n' "${prepare_boot_cache}" - cat << EOF -- linux ${LKERNEL} ${LPARAMS} -+ ${linux} ${LKERNEL} ${LPARAMS} - EOF - if [ -n "${LINITRD}" ] ; then - cat << EOF -- initrd ${LINITRD} -+ ${initrd} ${LINITRD} - EOF - fi - cat << EOF -@@ -261,11 +283,11 @@ EOF - save_default_entry | sed -e "s/^/$grub_tab$grub_tab/" - printf '%s\n' "${prepare_boot_cache}" | grub_add_tab - cat << EOF -- linux ${LKERNEL} ${LPARAMS} -+ ${linux} ${LKERNEL} ${LPARAMS} - EOF - if [ -n "${LINITRD}" ] ; then - cat << EOF -- initrd ${LINITRD} -+ ${initrd} ${LINITRD} - EOF - fi - cat << EOF diff --git a/0217-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0217-Make-grub2-mkconfig-construct-titles-that-look-like-.patch deleted file mode 100644 index 9beba4e..0000000 --- a/0217-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +++ /dev/null @@ -1,51 +0,0 @@ -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 | 14 +++++++++++--- - 1 file changed, 11 insertions(+), 3 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 03ea8460bfd..a05be9d3047 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -78,6 +78,15 @@ case x"$GRUB_FS" in - ;; - esac - -+mktitle () -+{ -+ local OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" -+ local OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" -+ -+ local titlestr="${OS_NAME} (%s) ${OS_VERS}" -+ echo -n ${titlestr} -+} -+ - title_correction_code= - - linux_entry () -@@ -107,15 +116,14 @@ linux_entry () - if [ x$type != xsimple ] ; then - case $type in - recovery) -- title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;; -+ title="$(printf "$(mktitle) (recovery mode)" "${version}")" ;; - *) -- title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; -+ title="$(printf "$(mktitle)" "${version}")" ;; - esac - 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/0217-Update-info-with-grub.cfg-netboot-selection-order-11.patch b/0217-Update-info-with-grub.cfg-netboot-selection-order-11.patch new file mode 100644 index 0000000..26de3f4 --- /dev/null +++ b/0217-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 2fd32608c01..a7155c22ffe 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/0218-Add-friendly-grub2-password-config-tool-985962.patch b/0218-Add-friendly-grub2-password-config-tool-985962.patch deleted file mode 100644 index c35b90c..0000000 --- a/0218-Add-friendly-grub2-password-config-tool-985962.patch +++ /dev/null @@ -1,272 +0,0 @@ -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 ---- - configure.ac | 1 + - Makefile.util.def | 13 +++++ - .gitignore | 2 + - util/grub-mkconfig.in | 2 + - util/grub-setpassword.8 | 28 +++++++++++ - util/grub-setpassword.in | 123 +++++++++++++++++++++++++++++++++++++++++++++++ - util/grub.d/01_users.in | 11 +++++ - 7 files changed, 180 insertions(+) - create mode 100644 util/grub-setpassword.8 - create mode 100644 util/grub-setpassword.in - create mode 100644 util/grub.d/01_users.in - -diff --git a/configure.ac b/configure.ac -index 056df1cbaf9..679f634ce4c 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-mkrelpath]) - grub_TRANSFORM([grub-mkrescue]) - grub_TRANSFORM([grub-probe]) - grub_TRANSFORM([grub-reboot]) -+grub_TRANSFORM([grub-setpassword]) - 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 406d96861b6..fd91045bd6d 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -440,6 +440,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; -@@ -722,6 +728,13 @@ script = { - installdir = sbin; - }; - -+script = { -+ name = grub-setpassword; -+ common = util/grub-setpassword.in; -+ mansection = 8; -+ installdir = sbin; -+}; -+ - script = { - name = grub-mkconfig_lib; - common = util/grub-mkconfig_lib.in; -diff --git a/.gitignore b/.gitignore -index 1c85371298c..387e3554cd5 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -107,6 +107,8 @@ grub-*.tar.* - /grub*-script-check.1 - /grub*-set-default - /grub*-set-default.8 -+/grub*-setsetpassword -+/grub*-setsetpassword.8 - /grub*-shell - /grub*-shell-tester - /grub*-sparc64-setup -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index f68d4925ee6..bdb9982aefb 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-setpassword.8 b/util/grub-setpassword.8 -new file mode 100644 -index 00000000000..49200a848b7 ---- /dev/null -+++ b/util/grub-setpassword.8 -@@ -0,0 +1,28 @@ -+.TH GRUB-SETPASSWORD 3 "Thu Jun 25 2015" -+.SH NAME -+\fBgrub-setpassword\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. -+ -+.SH SYNOPSIS -+\fBgrub-setpassword\fR [OPTION] -+ -+.SH DESCRIPTION -+\fBgrub-setpassword\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 PATH\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-setpassword.in b/util/grub-setpassword.in -new file mode 100644 -index 00000000000..dd76f00fc0e ---- /dev/null -+++ b/util/grub-setpassword.in -@@ -0,0 +1,123 @@ -+#!/bin/sh -e -+ -+if [ -d /sys/firmware/efi/efivars/ ]; then -+ grubdir=`echo "/@bootdirname@/efi/EFI/redhat/" | 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 <&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} ) | \ -+ ${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 "${grubdir}/user.cfg" 2>/dev/null || : -+chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : -+echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" -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/0218-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch b/0218-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch new file mode 100644 index 0000000..b093cf1 --- /dev/null +++ b/0218-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 +--- + configure.ac | 29 +++++ + Makefile.util.def | 16 +++ + util/grub-rpm-sort.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ + .gitignore | 2 + + util/grub-mkconfig_lib.in | 8 +- + util/grub-rpm-sort.8 | 12 ++ + 6 files changed, 347 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 d5db2803ec4..056df1cbaf9 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -65,6 +65,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]) +@@ -88,6 +89,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]) +@@ -1790,6 +1792,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 d08713b5500..406d96861b6 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -685,6 +685,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 = grub-core/gnulib/libgnu.a; ++ ldadd = libgrubkern.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/.gitignore b/.gitignore +index d95fac5789c..1c85371298c 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -101,6 +101,8 @@ grub-*.tar.* + /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-default +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 1a4a57898f9..7fe3598435c 100644 +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -214,6 +214,12 @@ version_sort () + esac + } + ++if [ "x$RPMLIB" = x ]; then ++ kernel_sort=version_sort ++else ++ kernel_sort="${sbindir}/grub-rpm-sort" ++fi ++ + version_test_numeric () + { + version_test_numeric_a="$1" +@@ -230,7 +236,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/0219-Handle-rssd-storage-devices.patch b/0219-Handle-rssd-storage-devices.patch new file mode 100644 index 0000000..8f25692 --- /dev/null +++ b/0219-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/0219-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0219-Make-grub2-mkconfig-construct-titles-that-look-like-.patch deleted file mode 100644 index c9b0c21..0000000 --- a/0219-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +++ /dev/null @@ -1,64 +0,0 @@ -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 | 32 ++++++++++++++++++++++---------- - 1 file changed, 22 insertions(+), 10 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index a05be9d3047..4ad98fbd767 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -80,11 +80,28 @@ esac - - mktitle () - { -- local OS_NAME="$(eval $(grep ^NAME= /etc/os-release) ; echo ${NAME})" -- local OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})" -+ local title_type -+ local version -+ local OS_NAME -+ local OS_VERS - -- local titlestr="${OS_NAME} (%s) ${OS_VERS}" -- echo -n ${titlestr} -+ 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= -@@ -114,12 +131,7 @@ linux_entry () - boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" - fi - if [ x$type != xsimple ] ; then -- case $type in -- recovery) -- title="$(printf "$(mktitle) (recovery mode)" "${version}")" ;; -- *) -- title="$(printf "$(mktitle)" "${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)" diff --git a/0220-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch b/0220-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch new file mode 100644 index 0000000..6faf353 --- /dev/null +++ b/0220-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch @@ -0,0 +1,74 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 27 Oct 2014 09:22:55 -0400 +Subject: [PATCH] Try to emit linux16/initrd16 and linuxefi/initrdefi in + 30-os_prober. + +Resolves: rhbz#1108296 + +Signed-off-by: Peter Jones +--- + util/grub.d/30_os-prober.in | 30 ++++++++++++++++++++++++++---- + 1 file changed, 26 insertions(+), 4 deletions(-) + +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index 9b8f5968e2d..dc98eace934 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -141,6 +141,28 @@ for OS in ${OSPROBED} ; do + # os-prober returns text string followed by optional counter + CLASS="--class $(echo "${LABEL}" | LC_ALL=C sed 's,[[:digit:]]*$,,' | cut -d' ' -f1 | tr 'A-Z' 'a-z' | LC_ALL=C sed 's,[^[:alnum:]_],_,g')" + ++ sixteenbit="" ++ linuxefi="linux" ++ initrdefi="initrd" ++ case "$machine" in ++ i?86|x86_64) ++ sixteenbit="16" ++ linuxefi="linuxefi" ++ initrdefi="initrdefi" ++ ;; ++ aarch64) ++ linuxefi="linux" ++ initrdefi="initrd" ++ esac ++ linux="linux${sixteenbit}" ++ initrd="initrd${sixteenbit}" ++ # there's no way to tell that the /other/ os is booting through UEFI, ++ # but if we are it's an okay bet... ++ if [ -d /sys/firmware/efi ]; then ++ linux=$linuxefi ++ initrd=$initrdefi ++ fi ++ + gettext_printf "Found %s on %s\n" "${LONGNAME}" "${DEVICE}" >&2 + + case ${BOOT} in +@@ -241,11 +263,11 @@ EOF + save_default_entry | grub_add_tab + printf '%s\n' "${prepare_boot_cache}" + cat << EOF +- linux ${LKERNEL} ${LPARAMS} ++ ${linux} ${LKERNEL} ${LPARAMS} + EOF + if [ -n "${LINITRD}" ] ; then + cat << EOF +- initrd ${LINITRD} ++ ${initrd} ${LINITRD} + EOF + fi + cat << EOF +@@ -261,11 +283,11 @@ EOF + save_default_entry | sed -e "s/^/$grub_tab$grub_tab/" + printf '%s\n' "${prepare_boot_cache}" | grub_add_tab + cat << EOF +- linux ${LKERNEL} ${LPARAMS} ++ ${linux} ${LKERNEL} ${LPARAMS} + EOF + if [ -n "${LINITRD}" ] ; then + cat << EOF +- initrd ${LINITRD} ++ ${initrd} ${LINITRD} + EOF + fi + cat << EOF diff --git a/0220-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch b/0220-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch deleted file mode 100644 index 09061ce..0000000 --- a/0220-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 3 Aug 2015 11:46:42 -0400 -Subject: [PATCH] Try to make sure configure.ac and grub-rpm-sort play nice. - -Apparently the test for whether to use grub-rpm-sort and also the -renaming of it to grub2-rpm-sort on the runtime side weren't right. - -Related: rhbz#1124074 - -Signed-off-by: Peter Jones ---- - configure.ac | 2 +- - util/grub-mkconfig_lib.in | 9 ++++++--- - 2 files changed, 7 insertions(+), 4 deletions(-) - -diff --git a/configure.ac b/configure.ac -index 679f634ce4c..71d1056969e 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1796,7 +1796,7 @@ 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 -+if test x"$enable_rpm_sort" = xno ; then - rpm_sort_excuse="explicitly disabled" - fi - -diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in -index 7fe3598435c..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,10 +217,10 @@ version_sort () - esac - } - --if [ "x$RPMLIB" = x ]; then -+if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then -+ kernel_sort="$grub_rpm_sort" -+else - kernel_sort=version_sort --else -- kernel_sort="${sbindir}/grub-rpm-sort" - fi - - version_test_numeric () diff --git a/0221-Make-grub2-mkconfig-construct-titles-that-look-like-.patch b/0221-Make-grub2-mkconfig-construct-titles-that-look-like-.patch new file mode 100644 index 0000000..5b2a251 --- /dev/null +++ b/0221-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 03ea8460bfd..4ad98fbd767 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 () +@@ -105,17 +131,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/0221-tcp-add-window-scaling-support.patch b/0221-tcp-add-window-scaling-support.patch deleted file mode 100644 index 7d1996c..0000000 --- a/0221-tcp-add-window-scaling-support.patch +++ /dev/null @@ -1,87 +0,0 @@ -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/0222-Add-friendly-grub2-password-config-tool-985962.patch b/0222-Add-friendly-grub2-password-config-tool-985962.patch new file mode 100644 index 0000000..c35b90c --- /dev/null +++ b/0222-Add-friendly-grub2-password-config-tool-985962.patch @@ -0,0 +1,272 @@ +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 +--- + configure.ac | 1 + + Makefile.util.def | 13 +++++ + .gitignore | 2 + + util/grub-mkconfig.in | 2 + + util/grub-setpassword.8 | 28 +++++++++++ + util/grub-setpassword.in | 123 +++++++++++++++++++++++++++++++++++++++++++++++ + util/grub.d/01_users.in | 11 +++++ + 7 files changed, 180 insertions(+) + create mode 100644 util/grub-setpassword.8 + create mode 100644 util/grub-setpassword.in + create mode 100644 util/grub.d/01_users.in + +diff --git a/configure.ac b/configure.ac +index 056df1cbaf9..679f634ce4c 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -65,6 +65,7 @@ grub_TRANSFORM([grub-mkrelpath]) + grub_TRANSFORM([grub-mkrescue]) + grub_TRANSFORM([grub-probe]) + grub_TRANSFORM([grub-reboot]) ++grub_TRANSFORM([grub-setpassword]) + 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 406d96861b6..fd91045bd6d 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -440,6 +440,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; +@@ -722,6 +728,13 @@ script = { + installdir = sbin; + }; + ++script = { ++ name = grub-setpassword; ++ common = util/grub-setpassword.in; ++ mansection = 8; ++ installdir = sbin; ++}; ++ + script = { + name = grub-mkconfig_lib; + common = util/grub-mkconfig_lib.in; +diff --git a/.gitignore b/.gitignore +index 1c85371298c..387e3554cd5 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -107,6 +107,8 @@ grub-*.tar.* + /grub*-script-check.1 + /grub*-set-default + /grub*-set-default.8 ++/grub*-setsetpassword ++/grub*-setsetpassword.8 + /grub*-shell + /grub*-shell-tester + /grub*-sparc64-setup +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index f68d4925ee6..bdb9982aefb 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-setpassword.8 b/util/grub-setpassword.8 +new file mode 100644 +index 00000000000..49200a848b7 +--- /dev/null ++++ b/util/grub-setpassword.8 +@@ -0,0 +1,28 @@ ++.TH GRUB-SETPASSWORD 3 "Thu Jun 25 2015" ++.SH NAME ++\fBgrub-setpassword\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. ++ ++.SH SYNOPSIS ++\fBgrub-setpassword\fR [OPTION] ++ ++.SH DESCRIPTION ++\fBgrub-setpassword\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 PATH\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-setpassword.in b/util/grub-setpassword.in +new file mode 100644 +index 00000000000..dd76f00fc0e +--- /dev/null ++++ b/util/grub-setpassword.in +@@ -0,0 +1,123 @@ ++#!/bin/sh -e ++ ++if [ -d /sys/firmware/efi/efivars/ ]; then ++ grubdir=`echo "/@bootdirname@/efi/EFI/redhat/" | 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 <&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} ) | \ ++ ${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 "${grubdir}/user.cfg" 2>/dev/null || : ++chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : ++echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" +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/0222-efinet-retransmit-if-our-device-is-busy.patch b/0222-efinet-retransmit-if-our-device-is-busy.patch deleted file mode 100644 index 5bbc00b..0000000 --- a/0222-efinet-retransmit-if-our-device-is-busy.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Josef Bacik -Date: Mon, 31 Aug 2015 13:34:35 -0400 -Subject: [PATCH] efinet: retransmit if our device is busy - -When I fixed the txbuf handling I ripped out the retransmission code since it -was flooding our network when we had the buggy behavior. Turns out this was too -heavy handed as we can still have transient tx timeouts. So instead make sure -we retry our transmission once per timeout. This way we can deal with transient -transmission problems without flooding the box. This fixes an issue we were -seeing in production. Thanks, - -Signed-off-by: Josef Bacik ---- - grub-core/net/drivers/efi/efinet.c | 10 ++++++++++ - 1 file changed, 10 insertions(+) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 5388f952ba9..3f112438a93 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -38,6 +38,7 @@ send_card_buffer (struct grub_net_card *dev, - grub_efi_simple_network_t *net = dev->efi_net; - grub_uint64_t limit_time = grub_get_time_ms () + 4000; - void *txbuf; -+ int retry = 0; - - if (dev->txbusy) - while (1) -@@ -60,6 +61,15 @@ send_card_buffer (struct grub_net_card *dev, - dev->txbusy = 0; - break; - } -+ if (!retry) -+ { -+ st = efi_call_7 (net->transmit, net, 0, dev->last_pkt_size, -+ dev->txbuf, NULL, NULL, NULL); -+ if (st != GRUB_EFI_SUCCESS) -+ return grub_error (GRUB_ERR_IO, -+ N_("couldn't send network packet")); -+ retry = 1; -+ } - if (limit_time < grub_get_time_ms ()) - return grub_error (GRUB_ERR_TIMEOUT, - N_("couldn't send network packet")); diff --git a/0223-Be-more-aggro-about-actually-using-the-configured-ne.patch b/0223-Be-more-aggro-about-actually-using-the-configured-ne.patch deleted file mode 100644 index 79e2348..0000000 --- a/0223-Be-more-aggro-about-actually-using-the-configured-ne.patch +++ /dev/null @@ -1,221 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 11 Sep 2015 17:30:49 -0400 -Subject: [PATCH] Be more aggro about actually using the *configured* network - device. - -Right now we use any SNP device with the same mac+IP block, but when -it's discovered there will be more than one of them. We need to pick -the same one we were loaded with, so that it'll be configured the same -way as it was before, and won't be re-used by the system firmware later. - -Resolves: rhbz#1257475 - -Signed-off-by: Peter Jones ---- - grub-core/net/drivers/efi/efinet.c | 124 +++++++++++++++++++++++++++++-------- - include/grub/efi/api.h | 4 ++ - 2 files changed, 102 insertions(+), 26 deletions(-) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index 3f112438a93..a3ce4c67cce 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -239,46 +239,85 @@ grub_efinet_get_device_handle (struct grub_net_card *card) - return card->efi_handle; - } - --static void --grub_efinet_findcards (void) -+static int -+grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, -+ int *i) - { -- grub_efi_uintn_t num_handles; -- grub_efi_handle_t *handles; -+ grub_efi_uintn_t num_handles = 0; -+ grub_efi_handle_t *handles = NULL; - grub_efi_handle_t *handle; -- int i = 0; -+ grub_efi_device_path_t *pdp = NULL, *pp = NULL, *pc = NULL; -+ int ret = 0; - -- /* Find handles which support the disk io interface. */ -+ if (preferred) -+ { -+ grub_efi_device_path_t *pdpc; -+ pdpc = pdp = grub_efi_get_device_path (preferred); -+ if (pdp == NULL) -+ { -+ grub_print_error (); -+ return -1; -+ } -+ -+ for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (pdpc); -+ pdpc = GRUB_EFI_NEXT_DEVICE_PATH (pdpc)) -+ { -+ pp = pc; -+ pc = pdpc; -+ } -+ } -+ -+ /* Find handles which support the SNP interface. */ - handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &net_io_guid, - 0, &num_handles); -- if (! handles) -- return; -- for (handle = handles; num_handles--; handle++) -+ -+ for (handle = handles; handle && num_handles--; handle++) - { - grub_efi_simple_network_t *net; - struct grub_net_card *card; - grub_efi_device_path_t *dp, *parent = NULL, *child = NULL; - -- /* EDK2 UEFI PXE driver creates IPv4 and IPv6 messaging devices as -- children of main MAC messaging device. We only need one device with -- bound SNP per physical card, otherwise they compete with each other -- when polling for incoming packets. -- */ -+ /* if we're looking for only the preferred handle, skip anything that -+ isn't it. */ -+ if (preferred_only && preferred != NULL && *handle != preferred) -+ continue; -+ -+ /* if we're not looking for the preferred handle, skip it if it's -+ found. */ -+ if (!preferred_only && *handle == preferred) -+ continue; -+ - dp = grub_efi_get_device_path (*handle); - if (!dp) - continue; -- for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp); dp = GRUB_EFI_NEXT_DEVICE_PATH (dp)) -+ -+ for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp); -+ dp = GRUB_EFI_NEXT_DEVICE_PATH (dp)) - { - parent = child; - child = dp; - } -- if (child -- && GRUB_EFI_DEVICE_PATH_TYPE (child) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE -- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE -- || GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) -- && parent -- && GRUB_EFI_DEVICE_PATH_TYPE (parent) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE -- && GRUB_EFI_DEVICE_PATH_SUBTYPE (parent) == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE) -- continue; -+ -+ if (!preferred_only) -+ { -+ if (pp && pc -+ && grub_efi_compare_device_paths (pp, parent) == 0 -+ && grub_efi_compare_device_paths (pc, child) == 0) -+ continue; -+ -+ if (child -+ && (GRUB_EFI_DEVICE_PATH_IS_TYPE(child, -+ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, -+ GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) || -+ GRUB_EFI_DEVICE_PATH_IS_TYPE(child, -+ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, -+ GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE)) -+ && parent -+ && (GRUB_EFI_DEVICE_PATH_IS_TYPE(parent, -+ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, -+ GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE))) -+ continue; -+ } - - net = grub_efi_open_protocol (*handle, &net_io_guid, - GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); -@@ -302,7 +341,7 @@ grub_efinet_findcards (void) - { - grub_print_error (); - grub_free (handles); -- return; -+ return -1; - } - - card->mtu = net->mode->max_packet_size; -@@ -313,13 +352,14 @@ grub_efinet_findcards (void) - grub_print_error (); - grub_free (handles); - grub_free (card); -- return; -+ return -1; - } - card->txbusy = 0; - - card->rcvbufsize = ALIGN_UP (card->mtu, 64) + 256; - -- card->name = grub_xasprintf ("efinet%d", i++); -+ card->name = grub_xasprintf ("efinet%d", *i); -+ *i = (*i)+1; - card->driver = &efidriver; - card->flags = 0; - card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; -@@ -330,8 +370,38 @@ grub_efinet_findcards (void) - card->efi_handle = *handle; - - grub_net_card_register (card); -+ ret++; - } - grub_free (handles); -+ -+ return ret; -+} -+ -+static void -+grub_efinet_findcards (void) -+{ -+ grub_efi_loaded_image_t *image = NULL; -+ int rc; -+ int efinet_number = 0; -+ -+ image = grub_efi_get_loaded_image (grub_efi_image_handle); -+ -+ if (image && image->device_handle) -+ { -+ rc = grub_efinet_find_snp_cards (1, image->device_handle, &efinet_number); -+ if (rc < 0) -+ return; -+ -+ rc = grub_efinet_find_snp_cards (0, image->device_handle, &efinet_number); -+ if (rc < 0) -+ return; -+ } -+ else -+ { -+ rc = grub_efinet_find_snp_cards (0, NULL, &efinet_number); -+ if (rc < 0) -+ return; -+ } - } - - static void -@@ -352,6 +422,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - struct grub_efi_pxe_mode *pxe_mode; - if (card->driver != &efidriver) - continue; -+ if (hnd != card->efi_handle) -+ continue; - cdp = grub_efi_get_device_path (card->efi_handle); - if (! cdp) - continue; -diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h -index c7c9f0e1db1..97b9aa7a4d7 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -622,6 +622,10 @@ typedef struct grub_efi_device_path grub_efi_device_path_t; - It seems to be identical to EFI_DEVICE_PATH. */ - typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; - -+#define GRUB_EFI_DEVICE_PATH_IS_TYPE(dp, type, subtype) \ -+ ((GRUB_EFI_DEVICE_PATH_TYPE(dp) == (type)) && \ -+ (GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) == (subtype))) -+ - #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) diff --git a/0223-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch b/0223-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch new file mode 100644 index 0000000..09061ce --- /dev/null +++ b/0223-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 3 Aug 2015 11:46:42 -0400 +Subject: [PATCH] Try to make sure configure.ac and grub-rpm-sort play nice. + +Apparently the test for whether to use grub-rpm-sort and also the +renaming of it to grub2-rpm-sort on the runtime side weren't right. + +Related: rhbz#1124074 + +Signed-off-by: Peter Jones +--- + configure.ac | 2 +- + util/grub-mkconfig_lib.in | 9 ++++++--- + 2 files changed, 7 insertions(+), 4 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 679f634ce4c..71d1056969e 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1796,7 +1796,7 @@ 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 ++if test x"$enable_rpm_sort" = xno ; then + rpm_sort_excuse="explicitly disabled" + fi + +diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in +index 7fe3598435c..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,10 +217,10 @@ version_sort () + esac + } + +-if [ "x$RPMLIB" = x ]; then ++if [ "x$grub_rpm_sort" != x -a -x "$grub_rpm_sort" ]; then ++ kernel_sort="$grub_rpm_sort" ++else + kernel_sort=version_sort +-else +- kernel_sort="${sbindir}/grub-rpm-sort" + fi + + version_test_numeric () diff --git a/0224-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch b/0224-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch deleted file mode 100644 index f337c74..0000000 --- a/0224-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: RHEL Ninjas -Date: Fri, 25 Sep 2015 16:24:23 +0900 -Subject: [PATCH] efinet: add filter for the first exclusive reopen of SNP - ---- - grub-core/net/drivers/efi/efinet.c | 39 ++++++++++++++++++++++++++++++++++++++ - 1 file changed, 39 insertions(+) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index a3ce4c67cce..b870d3f1938 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -465,6 +465,45 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - &pxe_mode->dhcp_ack, - sizeof (pxe_mode->dhcp_ack), - 1, device, path); -+ net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, -+ GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); -+ if (net) { -+ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED -+ && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) -+ continue; -+ -+ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) -+ continue; -+ -+ if (net->mode->state == GRUB_EFI_NETWORK_STARTED -+ && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) -+ continue; -+ -+ /* Enable hardware receive filters if driver declares support for it. -+ We need unicast and broadcast and additionaly all nodes and -+ solicited multicast for IPv6. Solicited multicast is per-IPv6 -+ address and we currently do not have API to do it so simply -+ try to enable receive of all multicast packets or evertyhing in -+ the worst case (i386 PXE driver always enables promiscuous too). -+ -+ This does trust firmware to do what it claims to do. -+ */ -+ if (net->mode->receive_filter_mask) -+ { -+ grub_uint32_t filters = GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | -+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | -+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; -+ -+ filters &= net->mode->receive_filter_mask; -+ if (!(filters & GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST)) -+ filters |= (net->mode->receive_filter_mask & -+ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS); -+ -+ efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL); -+ } -+ -+ card->efi_net = net; -+ } - return; - } - } diff --git a/0224-tcp-add-window-scaling-support.patch b/0224-tcp-add-window-scaling-support.patch new file mode 100644 index 0000000..7d1996c --- /dev/null +++ b/0224-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/0225-Fix-security-issue-when-reading-username-and-passwor.patch b/0225-Fix-security-issue-when-reading-username-and-passwor.patch deleted file mode 100644 index 11bc434..0000000 --- a/0225-Fix-security-issue-when-reading-username-and-passwor.patch +++ /dev/null @@ -1,44 +0,0 @@ -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/0225-efinet-retransmit-if-our-device-is-busy.patch b/0225-efinet-retransmit-if-our-device-is-busy.patch new file mode 100644 index 0000000..5bbc00b --- /dev/null +++ b/0225-efinet-retransmit-if-our-device-is-busy.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Josef Bacik +Date: Mon, 31 Aug 2015 13:34:35 -0400 +Subject: [PATCH] efinet: retransmit if our device is busy + +When I fixed the txbuf handling I ripped out the retransmission code since it +was flooding our network when we had the buggy behavior. Turns out this was too +heavy handed as we can still have transient tx timeouts. So instead make sure +we retry our transmission once per timeout. This way we can deal with transient +transmission problems without flooding the box. This fixes an issue we were +seeing in production. Thanks, + +Signed-off-by: Josef Bacik +--- + grub-core/net/drivers/efi/efinet.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 5388f952ba9..3f112438a93 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -38,6 +38,7 @@ send_card_buffer (struct grub_net_card *dev, + grub_efi_simple_network_t *net = dev->efi_net; + grub_uint64_t limit_time = grub_get_time_ms () + 4000; + void *txbuf; ++ int retry = 0; + + if (dev->txbusy) + while (1) +@@ -60,6 +61,15 @@ send_card_buffer (struct grub_net_card *dev, + dev->txbusy = 0; + break; + } ++ if (!retry) ++ { ++ st = efi_call_7 (net->transmit, net, 0, dev->last_pkt_size, ++ dev->txbuf, NULL, NULL, NULL); ++ if (st != GRUB_EFI_SUCCESS) ++ return grub_error (GRUB_ERR_IO, ++ N_("couldn't send network packet")); ++ retry = 1; ++ } + if (limit_time < grub_get_time_ms ()) + return grub_error (GRUB_ERR_TIMEOUT, + N_("couldn't send network packet")); diff --git a/0226-Be-more-aggro-about-actually-using-the-configured-ne.patch b/0226-Be-more-aggro-about-actually-using-the-configured-ne.patch new file mode 100644 index 0000000..79e2348 --- /dev/null +++ b/0226-Be-more-aggro-about-actually-using-the-configured-ne.patch @@ -0,0 +1,221 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 11 Sep 2015 17:30:49 -0400 +Subject: [PATCH] Be more aggro about actually using the *configured* network + device. + +Right now we use any SNP device with the same mac+IP block, but when +it's discovered there will be more than one of them. We need to pick +the same one we were loaded with, so that it'll be configured the same +way as it was before, and won't be re-used by the system firmware later. + +Resolves: rhbz#1257475 + +Signed-off-by: Peter Jones +--- + grub-core/net/drivers/efi/efinet.c | 124 +++++++++++++++++++++++++++++-------- + include/grub/efi/api.h | 4 ++ + 2 files changed, 102 insertions(+), 26 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index 3f112438a93..a3ce4c67cce 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -239,46 +239,85 @@ grub_efinet_get_device_handle (struct grub_net_card *card) + return card->efi_handle; + } + +-static void +-grub_efinet_findcards (void) ++static int ++grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, ++ int *i) + { +- grub_efi_uintn_t num_handles; +- grub_efi_handle_t *handles; ++ grub_efi_uintn_t num_handles = 0; ++ grub_efi_handle_t *handles = NULL; + grub_efi_handle_t *handle; +- int i = 0; ++ grub_efi_device_path_t *pdp = NULL, *pp = NULL, *pc = NULL; ++ int ret = 0; + +- /* Find handles which support the disk io interface. */ ++ if (preferred) ++ { ++ grub_efi_device_path_t *pdpc; ++ pdpc = pdp = grub_efi_get_device_path (preferred); ++ if (pdp == NULL) ++ { ++ grub_print_error (); ++ return -1; ++ } ++ ++ for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (pdpc); ++ pdpc = GRUB_EFI_NEXT_DEVICE_PATH (pdpc)) ++ { ++ pp = pc; ++ pc = pdpc; ++ } ++ } ++ ++ /* Find handles which support the SNP interface. */ + handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &net_io_guid, + 0, &num_handles); +- if (! handles) +- return; +- for (handle = handles; num_handles--; handle++) ++ ++ for (handle = handles; handle && num_handles--; handle++) + { + grub_efi_simple_network_t *net; + struct grub_net_card *card; + grub_efi_device_path_t *dp, *parent = NULL, *child = NULL; + +- /* EDK2 UEFI PXE driver creates IPv4 and IPv6 messaging devices as +- children of main MAC messaging device. We only need one device with +- bound SNP per physical card, otherwise they compete with each other +- when polling for incoming packets. +- */ ++ /* if we're looking for only the preferred handle, skip anything that ++ isn't it. */ ++ if (preferred_only && preferred != NULL && *handle != preferred) ++ continue; ++ ++ /* if we're not looking for the preferred handle, skip it if it's ++ found. */ ++ if (!preferred_only && *handle == preferred) ++ continue; ++ + dp = grub_efi_get_device_path (*handle); + if (!dp) + continue; +- for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp); dp = GRUB_EFI_NEXT_DEVICE_PATH (dp)) ++ ++ for (; ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp); ++ dp = GRUB_EFI_NEXT_DEVICE_PATH (dp)) + { + parent = child; + child = dp; + } +- if (child +- && GRUB_EFI_DEVICE_PATH_TYPE (child) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE +- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE +- || GRUB_EFI_DEVICE_PATH_SUBTYPE (child) == GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) +- && parent +- && GRUB_EFI_DEVICE_PATH_TYPE (parent) == GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE +- && GRUB_EFI_DEVICE_PATH_SUBTYPE (parent) == GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE) +- continue; ++ ++ if (!preferred_only) ++ { ++ if (pp && pc ++ && grub_efi_compare_device_paths (pp, parent) == 0 ++ && grub_efi_compare_device_paths (pc, child) == 0) ++ continue; ++ ++ if (child ++ && (GRUB_EFI_DEVICE_PATH_IS_TYPE(child, ++ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, ++ GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE) || ++ GRUB_EFI_DEVICE_PATH_IS_TYPE(child, ++ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, ++ GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE)) ++ && parent ++ && (GRUB_EFI_DEVICE_PATH_IS_TYPE(parent, ++ GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE, ++ GRUB_EFI_MAC_ADDRESS_DEVICE_PATH_SUBTYPE))) ++ continue; ++ } + + net = grub_efi_open_protocol (*handle, &net_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); +@@ -302,7 +341,7 @@ grub_efinet_findcards (void) + { + grub_print_error (); + grub_free (handles); +- return; ++ return -1; + } + + card->mtu = net->mode->max_packet_size; +@@ -313,13 +352,14 @@ grub_efinet_findcards (void) + grub_print_error (); + grub_free (handles); + grub_free (card); +- return; ++ return -1; + } + card->txbusy = 0; + + card->rcvbufsize = ALIGN_UP (card->mtu, 64) + 256; + +- card->name = grub_xasprintf ("efinet%d", i++); ++ card->name = grub_xasprintf ("efinet%d", *i); ++ *i = (*i)+1; + card->driver = &efidriver; + card->flags = 0; + card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; +@@ -330,8 +370,38 @@ grub_efinet_findcards (void) + card->efi_handle = *handle; + + grub_net_card_register (card); ++ ret++; + } + grub_free (handles); ++ ++ return ret; ++} ++ ++static void ++grub_efinet_findcards (void) ++{ ++ grub_efi_loaded_image_t *image = NULL; ++ int rc; ++ int efinet_number = 0; ++ ++ image = grub_efi_get_loaded_image (grub_efi_image_handle); ++ ++ if (image && image->device_handle) ++ { ++ rc = grub_efinet_find_snp_cards (1, image->device_handle, &efinet_number); ++ if (rc < 0) ++ return; ++ ++ rc = grub_efinet_find_snp_cards (0, image->device_handle, &efinet_number); ++ if (rc < 0) ++ return; ++ } ++ else ++ { ++ rc = grub_efinet_find_snp_cards (0, NULL, &efinet_number); ++ if (rc < 0) ++ return; ++ } + } + + static void +@@ -352,6 +422,8 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + struct grub_efi_pxe_mode *pxe_mode; + if (card->driver != &efidriver) + continue; ++ if (hnd != card->efi_handle) ++ continue; + cdp = grub_efi_get_device_path (card->efi_handle); + if (! cdp) + continue; +diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h +index c7c9f0e1db1..97b9aa7a4d7 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -622,6 +622,10 @@ typedef struct grub_efi_device_path grub_efi_device_path_t; + It seems to be identical to EFI_DEVICE_PATH. */ + typedef struct grub_efi_device_path grub_efi_device_path_protocol_t; + ++#define GRUB_EFI_DEVICE_PATH_IS_TYPE(dp, type, subtype) \ ++ ((GRUB_EFI_DEVICE_PATH_TYPE(dp) == (type)) && \ ++ (GRUB_EFI_DEVICE_PATH_SUBTYPE(dp) == (subtype))) ++ + #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) diff --git a/0226-Warn-if-grub-password-will-not-be-read-1290803.patch b/0226-Warn-if-grub-password-will-not-be-read-1290803.patch deleted file mode 100644 index de4a6ae..0000000 --- a/0226-Warn-if-grub-password-will-not-be-read-1290803.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Robert Marshall -Date: Mon, 22 Feb 2016 15:30:05 -0500 -Subject: [PATCH] Warn if grub password will not be read (#1290803) - -It is possible for a system to have never run grub-mkconfig and add the -section that reads the user.cfg file which contains a user set GRUB -password. Users in that scenario will now be warned that grub-mkconfig -must be run prior to their newly set password taking effect. - -Resolves: rhbz#1290803 ---- - util/grub-setpassword.in | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in -index dd76f00fc0e..fb9d3a3b6f9 100644 ---- a/util/grub-setpassword.in -+++ b/util/grub-setpassword.in -@@ -121,3 +121,8 @@ fi - install -m 0600 /dev/null "${grubdir}/user.cfg" 2>/dev/null || : - chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : - echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" -+ -+if ! grep -q "^### BEGIN /etc/grub.d/01_users ###$" "${grubdir}/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/0227-Clean-up-grub-setpassword-documentation-1290799.patch b/0227-Clean-up-grub-setpassword-documentation-1290799.patch deleted file mode 100644 index a405e88..0000000 --- a/0227-Clean-up-grub-setpassword-documentation-1290799.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Robert Marshall -Date: Tue, 26 Jan 2016 10:28:35 -0500 -Subject: [PATCH] Clean up grub-setpassword documentation (#1290799) - -The output for --help had some errors. Corrected those and polished the -text to be a little easier to follow. Carried verbage over to man page -to maintain internal consistency. - -Resolves: rhbz#1290799 ---- - util/grub-setpassword.8 | 2 +- - util/grub-setpassword.in | 15 +++++++-------- - 2 files changed, 8 insertions(+), 9 deletions(-) - -diff --git a/util/grub-setpassword.8 b/util/grub-setpassword.8 -index 49200a848b7..dc91dd6697b 100644 ---- a/util/grub-setpassword.8 -+++ b/util/grub-setpassword.8 -@@ -19,7 +19,7 @@ Display program usage and exit. - -v, --version - Display the current version. - .TP ---o, --output[=\fIDIRECTORY PATH\fR] -+-o, --output=<\fIDIRECTORY\fR> - Choose the file path to which user.cfg will be written. - - .SH SEE ALSO -diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in -index fb9d3a3b6f9..c8c0fa4199d 100644 ---- a/util/grub-setpassword.in -+++ b/util/grub-setpassword.in -@@ -16,15 +16,14 @@ grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@" - # Print the usage. - usage () { - cat < put user.cfg in a user-selected directory - - Report bugs at https://bugzilla.redhat.com. - EOF diff --git a/0227-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch b/0227-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch new file mode 100644 index 0000000..f337c74 --- /dev/null +++ b/0227-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: RHEL Ninjas +Date: Fri, 25 Sep 2015 16:24:23 +0900 +Subject: [PATCH] efinet: add filter for the first exclusive reopen of SNP + +--- + grub-core/net/drivers/efi/efinet.c | 39 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 39 insertions(+) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index a3ce4c67cce..b870d3f1938 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -465,6 +465,45 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + &pxe_mode->dhcp_ack, + sizeof (pxe_mode->dhcp_ack), + 1, device, path); ++ net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, ++ GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); ++ if (net) { ++ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED ++ && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) ++ continue; ++ ++ if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) ++ continue; ++ ++ if (net->mode->state == GRUB_EFI_NETWORK_STARTED ++ && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) ++ continue; ++ ++ /* Enable hardware receive filters if driver declares support for it. ++ We need unicast and broadcast and additionaly all nodes and ++ solicited multicast for IPv6. Solicited multicast is per-IPv6 ++ address and we currently do not have API to do it so simply ++ try to enable receive of all multicast packets or evertyhing in ++ the worst case (i386 PXE driver always enables promiscuous too). ++ ++ This does trust firmware to do what it claims to do. ++ */ ++ if (net->mode->receive_filter_mask) ++ { ++ grub_uint32_t filters = GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | ++ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | ++ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; ++ ++ filters &= net->mode->receive_filter_mask; ++ if (!(filters & GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST)) ++ filters |= (net->mode->receive_filter_mask & ++ GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS); ++ ++ efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL); ++ } ++ ++ card->efi_net = net; ++ } + return; + } + } diff --git a/0228-Fix-locale-issue-in-grub-setpassword-1294243.patch b/0228-Fix-locale-issue-in-grub-setpassword-1294243.patch deleted file mode 100644 index 9b315cc..0000000 --- a/0228-Fix-locale-issue-in-grub-setpassword-1294243.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Robert Marshall -Date: Fri, 29 Jan 2016 16:56:11 -0500 -Subject: [PATCH] Fix locale issue in grub-setpassword (#1294243) - -A shell substitution was expecting non-translated output to grab the -hashed password and put it in the user.cfg file. Modified code to force -the generic C locale when this particular piece of code is run. - -Resolves: rhbz#1294243 ---- - util/grub-setpassword.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in -index c8c0fa4199d..d7924af5192 100644 ---- a/util/grub-setpassword.in -+++ b/util/grub-setpassword.in -@@ -104,7 +104,7 @@ getpass() { - P1="$1" && shift - - ( echo ${P0} ; echo ${P1} ) | \ -- ${grub_mkpasswd} | \ -+ LC_ALL=C ${grub_mkpasswd} | \ - grep -v '[eE]nter password:' | \ - sed -e "s/PBKDF2 hash of your password is //" - } diff --git a/0228-Fix-security-issue-when-reading-username-and-passwor.patch b/0228-Fix-security-issue-when-reading-username-and-passwor.patch new file mode 100644 index 0000000..11bc434 --- /dev/null +++ b/0228-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/0229-Warn-if-grub-password-will-not-be-read-1290803.patch b/0229-Warn-if-grub-password-will-not-be-read-1290803.patch new file mode 100644 index 0000000..de4a6ae --- /dev/null +++ b/0229-Warn-if-grub-password-will-not-be-read-1290803.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Mon, 22 Feb 2016 15:30:05 -0500 +Subject: [PATCH] Warn if grub password will not be read (#1290803) + +It is possible for a system to have never run grub-mkconfig and add the +section that reads the user.cfg file which contains a user set GRUB +password. Users in that scenario will now be warned that grub-mkconfig +must be run prior to their newly set password taking effect. + +Resolves: rhbz#1290803 +--- + util/grub-setpassword.in | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in +index dd76f00fc0e..fb9d3a3b6f9 100644 +--- a/util/grub-setpassword.in ++++ b/util/grub-setpassword.in +@@ -121,3 +121,8 @@ fi + install -m 0600 /dev/null "${grubdir}/user.cfg" 2>/dev/null || : + chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : + echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" ++ ++if ! grep -q "^### BEGIN /etc/grub.d/01_users ###$" "${grubdir}/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/0229-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch b/0229-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch deleted file mode 100644 index 0891f8f..0000000 --- a/0229-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Robert Elliott -Date: Fri, 22 Jan 2016 13:32:30 +0100 -Subject: [PATCH] efiemu: Handle persistent RAM and unknown possible future - additions. - -(cherry picked from commit ae3b83a4d4df75a01198a2fed7542391e7c449e0) - -Resolves: rhbz#1288608 ---- - grub-core/efiemu/mm.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c -index 52a032f7b2e..92e7df7e501 100644 ---- a/grub-core/efiemu/mm.c -+++ b/grub-core/efiemu/mm.c -@@ -410,8 +410,8 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, - return grub_efiemu_add_to_mmap (addr, size, - GRUB_EFI_ACPI_MEMORY_NVS); - -- case GRUB_MEMORY_PERSISTENT: -- case GRUB_MEMORY_PERSISTENT_LEGACY: -+ case GRUB_MEMORY_PRAM: -+ case GRUB_MEMORY_PMEM: - return grub_efiemu_add_to_mmap (addr, size, - GRUB_EFI_PERSISTENT_MEMORY); - default: diff --git a/0230-Clean-up-grub-setpassword-documentation-1290799.patch b/0230-Clean-up-grub-setpassword-documentation-1290799.patch new file mode 100644 index 0000000..a405e88 --- /dev/null +++ b/0230-Clean-up-grub-setpassword-documentation-1290799.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 26 Jan 2016 10:28:35 -0500 +Subject: [PATCH] Clean up grub-setpassword documentation (#1290799) + +The output for --help had some errors. Corrected those and polished the +text to be a little easier to follow. Carried verbage over to man page +to maintain internal consistency. + +Resolves: rhbz#1290799 +--- + util/grub-setpassword.8 | 2 +- + util/grub-setpassword.in | 15 +++++++-------- + 2 files changed, 8 insertions(+), 9 deletions(-) + +diff --git a/util/grub-setpassword.8 b/util/grub-setpassword.8 +index 49200a848b7..dc91dd6697b 100644 +--- a/util/grub-setpassword.8 ++++ b/util/grub-setpassword.8 +@@ -19,7 +19,7 @@ Display program usage and exit. + -v, --version + Display the current version. + .TP +--o, --output[=\fIDIRECTORY PATH\fR] ++-o, --output=<\fIDIRECTORY\fR> + Choose the file path to which user.cfg will be written. + + .SH SEE ALSO +diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in +index fb9d3a3b6f9..c8c0fa4199d 100644 +--- a/util/grub-setpassword.in ++++ b/util/grub-setpassword.in +@@ -16,15 +16,14 @@ grub_mkpasswd="${bindir}/@grub_mkpasswd_pbkdf2@" + # Print the usage. + usage () { + cat < put user.cfg in a user-selected directory + + Report bugs at https://bugzilla.redhat.com. + EOF diff --git a/0230-efiemu-Fix-compilation-failure.patch b/0230-efiemu-Fix-compilation-failure.patch deleted file mode 100644 index 0c1c10f..0000000 --- a/0230-efiemu-Fix-compilation-failure.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Vladimir Serbinenko -Date: Fri, 22 Jan 2016 14:10:30 +0100 -Subject: [PATCH] efiemu: Fix compilation failure - -(cherry picked from commit b6a03dfd327489d53ee07c6d7d593b99c7b7cb62) - -Resolves: rhbz#1288608 ---- - grub-core/efiemu/mm.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c -index 92e7df7e501..52a032f7b2e 100644 ---- a/grub-core/efiemu/mm.c -+++ b/grub-core/efiemu/mm.c -@@ -410,8 +410,8 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, - return grub_efiemu_add_to_mmap (addr, size, - GRUB_EFI_ACPI_MEMORY_NVS); - -- case GRUB_MEMORY_PRAM: -- case GRUB_MEMORY_PMEM: -+ case GRUB_MEMORY_PERSISTENT: -+ case GRUB_MEMORY_PERSISTENT_LEGACY: - return grub_efiemu_add_to_mmap (addr, size, - GRUB_EFI_PERSISTENT_MEMORY); - default: diff --git a/0231-Fix-locale-issue-in-grub-setpassword-1294243.patch b/0231-Fix-locale-issue-in-grub-setpassword-1294243.patch new file mode 100644 index 0000000..9b315cc --- /dev/null +++ b/0231-Fix-locale-issue-in-grub-setpassword-1294243.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Fri, 29 Jan 2016 16:56:11 -0500 +Subject: [PATCH] Fix locale issue in grub-setpassword (#1294243) + +A shell substitution was expecting non-translated output to grab the +hashed password and put it in the user.cfg file. Modified code to force +the generic C locale when this particular piece of code is run. + +Resolves: rhbz#1294243 +--- + util/grub-setpassword.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in +index c8c0fa4199d..d7924af5192 100644 +--- a/util/grub-setpassword.in ++++ b/util/grub-setpassword.in +@@ -104,7 +104,7 @@ getpass() { + P1="$1" && shift + + ( echo ${P0} ; echo ${P1} ) | \ +- ${grub_mkpasswd} | \ ++ LC_ALL=C ${grub_mkpasswd} | \ + grep -v '[eE]nter password:' | \ + sed -e "s/PBKDF2 hash of your password is //" + } diff --git a/0231-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0231-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch deleted file mode 100644 index d6f026a..0000000 --- a/0231-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 7 Apr 2016 10:58:06 -0400 -Subject: [PATCH] Revert "reopen SNP protocol for exclusive use by grub" - -I *think* this should have been replaced by upstream's -49426e9fd2e562c73a4f1206f32eff9e424a1a73, so I'm reverting for now. - -May resolve rhbz#1273974. - -This reverts commit 147daeab22db793978f952b6f0d832919a1b0081. ---- - grub-core/net/drivers/efi/efinet.c | 39 -------------------------------------- - 1 file changed, 39 deletions(-) - -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index b870d3f1938..a3ce4c67cce 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -465,45 +465,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, - &pxe_mode->dhcp_ack, - sizeof (pxe_mode->dhcp_ack), - 1, device, path); -- net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, -- GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); -- if (net) { -- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED -- && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) -- continue; -- -- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) -- continue; -- -- if (net->mode->state == GRUB_EFI_NETWORK_STARTED -- && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) -- continue; -- -- /* Enable hardware receive filters if driver declares support for it. -- We need unicast and broadcast and additionaly all nodes and -- solicited multicast for IPv6. Solicited multicast is per-IPv6 -- address and we currently do not have API to do it so simply -- try to enable receive of all multicast packets or evertyhing in -- the worst case (i386 PXE driver always enables promiscuous too). -- -- This does trust firmware to do what it claims to do. -- */ -- if (net->mode->receive_filter_mask) -- { -- grub_uint32_t filters = GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | -- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | -- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; -- -- filters &= net->mode->receive_filter_mask; -- if (!(filters & GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST)) -- filters |= (net->mode->receive_filter_mask & -- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS); -- -- efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL); -- } -- -- card->efi_net = net; -- } - return; - } - } diff --git a/0232-Add-a-url-parser.patch b/0232-Add-a-url-parser.patch deleted file mode 100644 index cc7200d..0000000 --- a/0232-Add-a-url-parser.patch +++ /dev/null @@ -1,1021 +0,0 @@ -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 e675ab2da01..338244f6b47 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -2194,6 +2194,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 8344526be7f..f1fab700048 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 83fd69f4ada..fcaf1201e39 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/0232-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch b/0232-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch new file mode 100644 index 0000000..0891f8f --- /dev/null +++ b/0232-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Robert Elliott +Date: Fri, 22 Jan 2016 13:32:30 +0100 +Subject: [PATCH] efiemu: Handle persistent RAM and unknown possible future + additions. + +(cherry picked from commit ae3b83a4d4df75a01198a2fed7542391e7c449e0) + +Resolves: rhbz#1288608 +--- + grub-core/efiemu/mm.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c +index 52a032f7b2e..92e7df7e501 100644 +--- a/grub-core/efiemu/mm.c ++++ b/grub-core/efiemu/mm.c +@@ -410,8 +410,8 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, + return grub_efiemu_add_to_mmap (addr, size, + GRUB_EFI_ACPI_MEMORY_NVS); + +- case GRUB_MEMORY_PERSISTENT: +- case GRUB_MEMORY_PERSISTENT_LEGACY: ++ case GRUB_MEMORY_PRAM: ++ case GRUB_MEMORY_PMEM: + return grub_efiemu_add_to_mmap (addr, size, + GRUB_EFI_PERSISTENT_MEMORY); + default: diff --git a/0233-efiemu-Fix-compilation-failure.patch b/0233-efiemu-Fix-compilation-failure.patch new file mode 100644 index 0000000..0c1c10f --- /dev/null +++ b/0233-efiemu-Fix-compilation-failure.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Vladimir Serbinenko +Date: Fri, 22 Jan 2016 14:10:30 +0100 +Subject: [PATCH] efiemu: Fix compilation failure + +(cherry picked from commit b6a03dfd327489d53ee07c6d7d593b99c7b7cb62) + +Resolves: rhbz#1288608 +--- + grub-core/efiemu/mm.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c +index 92e7df7e501..52a032f7b2e 100644 +--- a/grub-core/efiemu/mm.c ++++ b/grub-core/efiemu/mm.c +@@ -410,8 +410,8 @@ fill_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type, + return grub_efiemu_add_to_mmap (addr, size, + GRUB_EFI_ACPI_MEMORY_NVS); + +- case GRUB_MEMORY_PRAM: +- case GRUB_MEMORY_PMEM: ++ case GRUB_MEMORY_PERSISTENT: ++ case GRUB_MEMORY_PERSISTENT_LEGACY: + return grub_efiemu_add_to_mmap (addr, size, + GRUB_EFI_PERSISTENT_MEMORY); + default: diff --git a/0233-efinet-and-bootp-add-support-for-dhcpv6.patch b/0233-efinet-and-bootp-add-support-for-dhcpv6.patch deleted file mode 100644 index 924bfa3..0000000 --- a/0233-efinet-and-bootp-add-support-for-dhcpv6.patch +++ /dev/null @@ -1,664 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 8 Jun 2016 21:03:37 -0400 -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 | 55 ++++++++++-- - 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, 480 insertions(+), 14 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index f03eeab2fb4..da3e454466b 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -23,6 +23,7 @@ - #include - #include - #include -+#include - #include - - static char * -@@ -349,6 +350,179 @@ grub_net_configure_by_dhcp_ack (const char *name, - return inter; - } - -+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_net_process_dhcp (struct grub_net_buff *nb, - struct grub_net_card *card) -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index a3ce4c67cce..329024b6f2c 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+"); - -@@ -409,7 +413,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) -@@ -420,16 +424,22 @@ 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; -+ - if (hnd != card->efi_handle) - 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 -@@ -438,7 +448,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)) -@@ -455,16 +464,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 16d2ce06d5a..4be228d9576 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..1157524fc50 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 97b9aa7a4d7..02488ec35ae 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; - -@@ -1454,16 +1460,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 50d62ab0c8c..f8f3ec13acc 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -442,6 +442,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 -@@ -470,6 +515,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/0234-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch b/0234-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch deleted file mode 100644 index ad54932..0000000 --- a/0234-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch +++ /dev/null @@ -1,300 +0,0 @@ -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 +++ - .gitignore | 2 + - util/bash-completion.d/grub-completion.bash.in | 22 ++++++++ - util/grub-get-kernel-settings.3 | 20 +++++++ - util/grub-get-kernel-settings.in | 78 ++++++++++++++++++++++++++ - util/grub-mkconfig.in | 3 + - util/grub.d/10_linux.in | 23 ++++++-- - 8 files changed, 152 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 71d1056969e..aa06ed59c8d 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -58,6 +58,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]) -@@ -75,6 +76,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 fd91045bd6d..2d032643de7 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -714,6 +714,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/.gitignore b/.gitignore -index 387e3554cd5..9f258735aaa 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -64,6 +64,8 @@ grub-*.tar.* - /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 -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..12046219878 ---- /dev/null -+++ b/util/grub-get-kernel-settings.in -@@ -0,0 +1,78 @@ -+#!/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 -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index bdb9982aefb..8218f3d477f 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 4ad98fbd767..24a10f95d2c 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" - - linuxcmd=linux - initrdcmd=initrd -@@ -137,6 +138,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/" -@@ -311,11 +315,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 -@@ -324,10 +332,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/0234-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch b/0234-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch new file mode 100644 index 0000000..d6f026a --- /dev/null +++ b/0234-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 7 Apr 2016 10:58:06 -0400 +Subject: [PATCH] Revert "reopen SNP protocol for exclusive use by grub" + +I *think* this should have been replaced by upstream's +49426e9fd2e562c73a4f1206f32eff9e424a1a73, so I'm reverting for now. + +May resolve rhbz#1273974. + +This reverts commit 147daeab22db793978f952b6f0d832919a1b0081. +--- + grub-core/net/drivers/efi/efinet.c | 39 -------------------------------------- + 1 file changed, 39 deletions(-) + +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index b870d3f1938..a3ce4c67cce 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -465,45 +465,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device, + &pxe_mode->dhcp_ack, + sizeof (pxe_mode->dhcp_ack), + 1, device, path); +- net = grub_efi_open_protocol (card->efi_handle, &net_io_guid, +- GRUB_EFI_OPEN_PROTOCOL_BY_EXCLUSIVE); +- if (net) { +- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED +- && efi_call_1 (net->start, net) != GRUB_EFI_SUCCESS) +- continue; +- +- if (net->mode->state == GRUB_EFI_NETWORK_STOPPED) +- continue; +- +- if (net->mode->state == GRUB_EFI_NETWORK_STARTED +- && efi_call_3 (net->initialize, net, 0, 0) != GRUB_EFI_SUCCESS) +- continue; +- +- /* Enable hardware receive filters if driver declares support for it. +- We need unicast and broadcast and additionaly all nodes and +- solicited multicast for IPv6. Solicited multicast is per-IPv6 +- address and we currently do not have API to do it so simply +- try to enable receive of all multicast packets or evertyhing in +- the worst case (i386 PXE driver always enables promiscuous too). +- +- This does trust firmware to do what it claims to do. +- */ +- if (net->mode->receive_filter_mask) +- { +- grub_uint32_t filters = GRUB_EFI_SIMPLE_NETWORK_RECEIVE_UNICAST | +- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST | +- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; +- +- filters &= net->mode->receive_filter_mask; +- if (!(filters & GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST)) +- filters |= (net->mode->receive_filter_mask & +- GRUB_EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS); +- +- efi_call_6 (net->receive_filters, net, filters, 0, 0, 0, NULL); +- } +- +- card->efi_net = net; +- } + return; + } + } diff --git a/0235-Add-a-url-parser.patch b/0235-Add-a-url-parser.patch new file mode 100644 index 0000000..cc7200d --- /dev/null +++ b/0235-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 e675ab2da01..338244f6b47 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2194,6 +2194,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 8344526be7f..f1fab700048 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 83fd69f4ada..fcaf1201e39 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/0235-Normalize-slashes-in-tftp-paths.patch b/0235-Normalize-slashes-in-tftp-paths.patch deleted file mode 100644 index 5ea5afa..0000000 --- a/0235-Normalize-slashes-in-tftp-paths.patch +++ /dev/null @@ -1,55 +0,0 @@ -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: Peter Jones ---- - grub-core/net/tftp.c | 24 +++++++++++++++++++++++- - 1 file changed, 23 insertions(+), 1 deletion(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 1157524fc50..5ca0a96a6f6 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,7 +356,10 @@ 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); -+ -+ /* 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 (filename) + 1; - rrq += grub_strlen (filename) + 1; - diff --git a/0236-Fix-malformed-tftp-packets.patch b/0236-Fix-malformed-tftp-packets.patch deleted file mode 100644 index 2445137..0000000 --- a/0236-Fix-malformed-tftp-packets.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Mark Salter -Date: Tue, 7 Mar 2017 18:26:17 -0500 -Subject: [PATCH] Fix malformed tftp packets - -0088-Normalize-slashes-in-tftp-paths.patch collapses multiple contiguous -slashes in a filename into one slash in the tftp packet filename field. -However, the packet buffer pointer is advanced using the original name. -This leaves unitialized data between the name field and the type field -leading to tftp errors. Use the length of the normalized name to avoid -this. - -Signed-off-by: Mark Salter ---- - grub-core/net/tftp.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index 5ca0a96a6f6..dcd82494309 100644 ---- a/grub-core/net/tftp.c -+++ b/grub-core/net/tftp.c -@@ -360,8 +360,8 @@ tftp_open (struct grub_file *file, const char *filename) - /* 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 (filename) + 1; -- rrq += grub_strlen (filename) + 1; -+ rrqlen += grub_strlen (rrq) + 1; -+ rrq += grub_strlen (rrq) + 1; - - grub_strcpy (rrq, "octet"); - rrqlen += grub_strlen ("octet") + 1; diff --git a/0236-efinet-and-bootp-add-support-for-dhcpv6.patch b/0236-efinet-and-bootp-add-support-for-dhcpv6.patch new file mode 100644 index 0000000..924bfa3 --- /dev/null +++ b/0236-efinet-and-bootp-add-support-for-dhcpv6.patch @@ -0,0 +1,664 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 8 Jun 2016 21:03:37 -0400 +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 | 55 ++++++++++-- + 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, 480 insertions(+), 14 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index f03eeab2fb4..da3e454466b 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + + static char * +@@ -349,6 +350,179 @@ grub_net_configure_by_dhcp_ack (const char *name, + return inter; + } + ++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_net_process_dhcp (struct grub_net_buff *nb, + struct grub_net_card *card) +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index a3ce4c67cce..329024b6f2c 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+"); + +@@ -409,7 +413,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) +@@ -420,16 +424,22 @@ 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; ++ + if (hnd != card->efi_handle) + 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 +@@ -438,7 +448,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)) +@@ -455,16 +464,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 16d2ce06d5a..4be228d9576 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..1157524fc50 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 97b9aa7a4d7..02488ec35ae 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; + +@@ -1454,16 +1460,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 50d62ab0c8c..f8f3ec13acc 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -442,6 +442,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 +@@ -470,6 +515,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/0237-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch b/0237-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch new file mode 100644 index 0000000..ad54932 --- /dev/null +++ b/0237-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch @@ -0,0 +1,300 @@ +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 +++ + .gitignore | 2 + + util/bash-completion.d/grub-completion.bash.in | 22 ++++++++ + util/grub-get-kernel-settings.3 | 20 +++++++ + util/grub-get-kernel-settings.in | 78 ++++++++++++++++++++++++++ + util/grub-mkconfig.in | 3 + + util/grub.d/10_linux.in | 23 ++++++-- + 8 files changed, 152 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 71d1056969e..aa06ed59c8d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -58,6 +58,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]) +@@ -75,6 +76,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 fd91045bd6d..2d032643de7 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -714,6 +714,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/.gitignore b/.gitignore +index 387e3554cd5..9f258735aaa 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -64,6 +64,8 @@ grub-*.tar.* + /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 +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..12046219878 +--- /dev/null ++++ b/util/grub-get-kernel-settings.in +@@ -0,0 +1,78 @@ ++#!/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 +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index bdb9982aefb..8218f3d477f 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 4ad98fbd767..24a10f95d2c 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" + + linuxcmd=linux + initrdcmd=initrd +@@ -137,6 +138,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/" +@@ -311,11 +315,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 +@@ -324,10 +332,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/0237-Fix-race-in-EFI-validation.patch b/0237-Fix-race-in-EFI-validation.patch deleted file mode 100644 index ce42a83..0000000 --- a/0237-Fix-race-in-EFI-validation.patch +++ /dev/null @@ -1,94 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Tue, 14 Jul 2015 16:58:51 -0700 -Subject: [PATCH] Fix race in EFI validation - ---- - grub-core/loader/i386/efi/linux.c | 44 ++++++++++----------------------------- - 1 file changed, 11 insertions(+), 33 deletions(-) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index e5b778577f9..7ccf32d9d45 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -154,7 +154,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - grub_file_t file = 0; - struct linux_kernel_header lh; - grub_ssize_t len, start, filelen; -- void *kernel; -+ void *kernel = NULL; - - grub_dl_ref (my_mod); - -@@ -191,10 +191,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_file_seek (file, 0); -- -- grub_free(kernel); -- - params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384)); - - if (! params) -@@ -203,15 +199,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- memset (params, 0, 16384); -+ grub_memset (params, 0, 16384); - -- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) -- { -- if (!grub_errno) -- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -- argv[0]); -- goto fail; -- } -+ grub_memcpy (&lh, kernel, sizeof (lh)); - - if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) - { -@@ -271,27 +261,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- if (grub_file_seek (file, start) == (grub_off_t) -1) -- { -- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -- argv[0]); -- goto fail; -- } -+ grub_memcpy (kernel_mem, (char *)kernel + start, len); -+ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); -+ loaded=1; - -- if (grub_file_read (file, kernel_mem, len) != len && !grub_errno) -- { -- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), -- argv[0]); -- } -- -- if (grub_errno == GRUB_ERR_NONE) -- { -- grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); -- loaded = 1; -- lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; -- } -- -- memcpy(params, &lh, 2 * 512); -+ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; -+ grub_memcpy (params, &lh, 2 * 512); - - params->type_of_loader = 0x21; - -@@ -300,6 +275,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - if (file) - grub_file_close (file); - -+ if (kernel) -+ grub_free (kernel); -+ - if (grub_errno != GRUB_ERR_NONE) - { - grub_dl_unref (my_mod); diff --git a/0238-Normalize-slashes-in-tftp-paths.patch b/0238-Normalize-slashes-in-tftp-paths.patch new file mode 100644 index 0000000..5ea5afa --- /dev/null +++ b/0238-Normalize-slashes-in-tftp-paths.patch @@ -0,0 +1,55 @@ +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: Peter Jones +--- + grub-core/net/tftp.c | 24 +++++++++++++++++++++++- + 1 file changed, 23 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 1157524fc50..5ca0a96a6f6 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,7 +356,10 @@ 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); ++ ++ /* 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 (filename) + 1; + rrq += grub_strlen (filename) + 1; + diff --git a/0238-bz1374141-fix-incorrect-mask-for-ppc64.patch b/0238-bz1374141-fix-incorrect-mask-for-ppc64.patch deleted file mode 100644 index 628ff7e..0000000 --- a/0238-bz1374141-fix-incorrect-mask-for-ppc64.patch +++ /dev/null @@ -1,45 +0,0 @@ -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 002446be1c3..3df75357a70 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/0239-Fix-malformed-tftp-packets.patch b/0239-Fix-malformed-tftp-packets.patch new file mode 100644 index 0000000..2445137 --- /dev/null +++ b/0239-Fix-malformed-tftp-packets.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Mark Salter +Date: Tue, 7 Mar 2017 18:26:17 -0500 +Subject: [PATCH] Fix malformed tftp packets + +0088-Normalize-slashes-in-tftp-paths.patch collapses multiple contiguous +slashes in a filename into one slash in the tftp packet filename field. +However, the packet buffer pointer is advanced using the original name. +This leaves unitialized data between the name field and the type field +leading to tftp errors. Use the length of the normalized name to avoid +this. + +Signed-off-by: Mark Salter +--- + grub-core/net/tftp.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index 5ca0a96a6f6..dcd82494309 100644 +--- a/grub-core/net/tftp.c ++++ b/grub-core/net/tftp.c +@@ -360,8 +360,8 @@ tftp_open (struct grub_file *file, const char *filename) + /* 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 (filename) + 1; +- rrq += grub_strlen (filename) + 1; ++ rrqlen += grub_strlen (rrq) + 1; ++ rrq += grub_strlen (rrq) + 1; + + grub_strcpy (rrq, "octet"); + rrqlen += grub_strlen ("octet") + 1; diff --git a/0239-Use-device-part-of-chainloader-target-if-present.patch b/0239-Use-device-part-of-chainloader-target-if-present.patch deleted file mode 100644 index 28efeb0..0000000 --- a/0239-Use-device-part-of-chainloader-target-if-present.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Raymund Will -Date: Fri, 10 Apr 2015 01:45:02 -0400 -Subject: [PATCH] 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 ---- - grub-core/loader/efi/chainloader.c | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index adc85636633..14ce6ddd7ad 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -223,8 +223,11 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - 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; - diff --git a/0240-Add-secureboot-support-on-efi-chainloader.patch b/0240-Add-secureboot-support-on-efi-chainloader.patch deleted file mode 100644 index 538ff34..0000000 --- a/0240-Add-secureboot-support-on-efi-chainloader.patch +++ /dev/null @@ -1,797 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 6 Oct 2015 13:04:37 -0400 -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 ---- - grub-core/loader/efi/chainloader.c | 612 ++++++++++++++++++++++++++++++++++--- - include/grub/efi/pe32.h | 20 +- - 2 files changed, 595 insertions(+), 37 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index 14ce6ddd7ad..87a91e16f17 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; -@@ -191,12 +199,523 @@ 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_error (GRUB_ERR_BAD_ARGUMENT, "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 0; -+} -+ -+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 = -+#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 - 1); -+ -+ grub_dprintf ("chain", "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)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 < data || (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, size; -+ 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; -+ -+ b = grub_efi_system_table->boot_services; -+ -+ if (read_header (data, datasize, &context)) -+ { -+ grub_dprintf ("chain", "Succeed to read header\n"); -+ } -+ else -+ { -+ grub_dprintf ("chain", "Failed to read header\n"); -+ goto error_exit; -+ } -+ -+ section_alignment = context.section_alignment; -+ buffer_size = context.image_size + section_alignment; -+ -+ 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); -+ -+ char *reloc_base, *reloc_base_end; -+ reloc_base = image_address (buffer_aligned, datasize, -+ context.reloc_dir->rva); -+ /* RelocBaseEnd here is the address of the last byte of the table */ -+ reloc_base_end = image_address (buffer_aligned, datasize, -+ context.reloc_dir->rva -+ + context.reloc_dir->size - 1); -+ struct grub_pe32_section_table *reloc_section = NULL; -+ -+ section = context.first_section; -+ for (i = 0; i < context.number_of_sections; i++, section++) -+ { -+ size = section->virtual_size; -+ if (size > section->raw_data_size) -+ size = section->raw_data_size; -+ -+ base = image_address (buffer_aligned, context.image_size, -+ section->virtual_address); -+ end = image_address (buffer_aligned, context.image_size, -+ section->virtual_address + size - 1); -+ -+ -+ /* 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 && reloc_base_end == end) -+ { -+ reloc_section = section; -+ } -+ } -+ -+ if (section->characteristics && GRUB_PE32_SCN_MEM_DISCARDABLE) -+ continue; -+ -+ if (!base || !end) -+ { -+ grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid section size"); -+ goto error_exit; -+ } -+ -+ 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_memcpy (base, (grub_efi_uint8_t*)data + section->raw_data_offset, -+ size); -+ -+ if (size < section->virtual_size) -+ grub_memset (base + size, 0, section->virtual_size - size); -+ -+ grub_dprintf ("chain", "copied section %s\n", section->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; -+ } -+ } -+ -+ entry_point = image_address (buffer_aligned, context.image_size, -+ context.entry_point); -+ -+ if (!entry_point) -+ { -+ grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid 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_printf ("file path: "); -+ grub_efi_print_device_path (li->file_path); -+ } -+ else -+ { -+ grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file path found"); -+ goto error_exit; -+ } -+ -+ efi_status = efi_call_2 (entry_point, grub_efi_image_handle, -+ grub_efi_system_table); -+ -+ grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); -+ efi_status = efi_call_1 (b->free_pool, buffer); -+ -+ return 1; -+ -+error_exit: -+ 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_secureboot_chainloader_boot (void) -+{ -+ handle_image ((void *)address, fsize); -+ 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; -@@ -204,7 +723,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - grub_efi_loaded_image_t *loaded_image; - char *filename; - void *boot_image = 0; -- grub_efi_handle_t dev_handle = 0; - - if (argc == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -@@ -216,9 +734,36 @@ 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); - if (! file) - goto fail; -@@ -267,14 +812,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - 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, -@@ -288,7 +833,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"), -@@ -298,7 +843,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 -@@ -307,6 +852,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)) -@@ -321,21 +874,28 @@ 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 - -+ if (grub_linuxefi_secure_validate((void *)address, fsize)) -+ { -+ grub_file_close (file); -+ grub_loader_set (grub_secureboot_chainloader_boot, -+ grub_secureboot_chainloader_unload, 0); -+ return 0; -+ } -+ - status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, -- boot_image, size, -- &image_handle); -+ boot_image, fsize, &image_handle); - if (status != GRUB_EFI_SUCCESS) - { - if (status == GRUB_EFI_OUT_OF_RESOURCES) -@@ -357,33 +917,10 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - } - loaded_image->device_handle = dev_handle; - -- if (argc > 1) -+ if (cmdline) - { -- 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; -- -- 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; -+ loaded_image->load_options_size = cmdline_len; - } - - grub_file_close (file); -@@ -405,6 +942,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/include/grub/efi/pe32.h b/include/grub/efi/pe32.h -index 7d44732d2c3..6e24dae2cb6 100644 ---- a/include/grub/efi/pe32.h -+++ b/include/grub/efi/pe32.h -@@ -214,7 +214,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; -@@ -265,6 +269,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/0240-Fix-race-in-EFI-validation.patch b/0240-Fix-race-in-EFI-validation.patch new file mode 100644 index 0000000..ce42a83 --- /dev/null +++ b/0240-Fix-race-in-EFI-validation.patch @@ -0,0 +1,94 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Tue, 14 Jul 2015 16:58:51 -0700 +Subject: [PATCH] Fix race in EFI validation + +--- + grub-core/loader/i386/efi/linux.c | 44 ++++++++++----------------------------- + 1 file changed, 11 insertions(+), 33 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index e5b778577f9..7ccf32d9d45 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -154,7 +154,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_file_t file = 0; + struct linux_kernel_header lh; + grub_ssize_t len, start, filelen; +- void *kernel; ++ void *kernel = NULL; + + grub_dl_ref (my_mod); + +@@ -191,10 +191,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_file_seek (file, 0); +- +- grub_free(kernel); +- + params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384)); + + if (! params) +@@ -203,15 +199,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- memset (params, 0, 16384); ++ grub_memset (params, 0, 16384); + +- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh)) +- { +- if (!grub_errno) +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); +- goto fail; +- } ++ grub_memcpy (&lh, kernel, sizeof (lh)); + + if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) + { +@@ -271,27 +261,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- if (grub_file_seek (file, start) == (grub_off_t) -1) +- { +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); +- goto fail; +- } ++ grub_memcpy (kernel_mem, (char *)kernel + start, len); ++ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); ++ loaded=1; + +- if (grub_file_read (file, kernel_mem, len) != len && !grub_errno) +- { +- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), +- argv[0]); +- } +- +- if (grub_errno == GRUB_ERR_NONE) +- { +- grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); +- loaded = 1; +- lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; +- } +- +- memcpy(params, &lh, 2 * 512); ++ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem; ++ grub_memcpy (params, &lh, 2 * 512); + + params->type_of_loader = 0x21; + +@@ -300,6 +275,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + if (file) + grub_file_close (file); + ++ if (kernel) ++ grub_free (kernel); ++ + if (grub_errno != GRUB_ERR_NONE) + { + grub_dl_unref (my_mod); diff --git a/0241-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch b/0241-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch deleted file mode 100644 index b006067..0000000 --- a/0241-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch +++ /dev/null @@ -1,491 +0,0 @@ -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/efi/efi.c | 28 ------------------ - grub-core/kern/efi/sb.c | 58 ++++++++++++++++++++++++++++++++++++++ - 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 + - 19 files changed, 146 insertions(+), 29 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 338244f6b47..423def037c2 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -196,6 +196,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/efi/efi.c b/grub-core/kern/efi/efi.c -index 92e1583b37d..e339f264b3a 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -278,34 +278,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) -- 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/sb.c b/grub-core/kern/efi/sb.c -new file mode 100644 -index 00000000000..a41b6c5b851 ---- /dev/null -+++ b/grub-core/kern/efi/sb.c -@@ -0,0 +1,58 @@ -+/* -+ * 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) -+ 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; -+#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 87a91e16f17..aee8e6becf6 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 7f96515da65..87709aa23e8 100644 ---- a/grub-core/loader/i386/bsd.c -+++ b/grub-core/loader/i386/bsd.c -@@ -38,6 +38,7 @@ - #ifdef GRUB_MACHINE_PCBIOS - #include - #endif -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -2124,6 +2125,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"); - -@@ -2163,6 +2167,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 44301e12659..930a90b1f32 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -35,6 +35,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -1139,6 +1140,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, -@@ -1148,6 +1152,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 b69cb7a3a7f..ebe7630210b 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+"); - -@@ -472,6 +473,9 @@ static grub_command_t cmd_linux, cmd_initrd; - - GRUB_MOD_INIT(linux16) - { -+ if (grub_efi_secure_boot()) -+ return; -+ - cmd_linux = - grub_register_command ("linux16", grub_cmd_linux, - 0, N_("Load Linux.")); -@@ -483,6 +487,9 @@ GRUB_MOD_INIT(linux16) - - GRUB_MOD_FINI(linux16) - { -+ if (grub_efi_secure_boot()) -+ return; -+ - grub_unregister_command (cmd_linux); - grub_unregister_command (cmd_initrd); - } -diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 40c67e82489..26df46a4161 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+"); - -@@ -446,6 +447,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, -@@ -466,6 +470,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 c9885b1bcd7..df8dfdb4ba0 100644 ---- a/grub-core/loader/xnu.c -+++ b/grub-core/loader/xnu.c -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -1469,6 +1470,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, -@@ -1509,6 +1513,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 f68a19de442..3efbafbb418 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -84,7 +84,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 10451384720..f7b4d29b0b3 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/0241-bz1374141-fix-incorrect-mask-for-ppc64.patch b/0241-bz1374141-fix-incorrect-mask-for-ppc64.patch new file mode 100644 index 0000000..628ff7e --- /dev/null +++ b/0241-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 002446be1c3..3df75357a70 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/0242-Make-grub_fatal-also-backtrace.patch b/0242-Make-grub_fatal-also-backtrace.patch deleted file mode 100644 index 520c413..0000000 --- a/0242-Make-grub_fatal-also-backtrace.patch +++ /dev/null @@ -1,172 +0,0 @@ -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 423def037c2..edf249f0002 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -175,6 +175,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; - -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index f1fab700048..5ce89a40c68 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/0242-Use-device-part-of-chainloader-target-if-present.patch b/0242-Use-device-part-of-chainloader-target-if-present.patch new file mode 100644 index 0000000..28efeb0 --- /dev/null +++ b/0242-Use-device-part-of-chainloader-target-if-present.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Raymund Will +Date: Fri, 10 Apr 2015 01:45:02 -0400 +Subject: [PATCH] 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 +--- + grub-core/loader/efi/chainloader.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index adc85636633..14ce6ddd7ad 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -223,8 +223,11 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + 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; + diff --git a/0243-Add-secureboot-support-on-efi-chainloader.patch b/0243-Add-secureboot-support-on-efi-chainloader.patch new file mode 100644 index 0000000..538ff34 --- /dev/null +++ b/0243-Add-secureboot-support-on-efi-chainloader.patch @@ -0,0 +1,797 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 6 Oct 2015 13:04:37 -0400 +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 +--- + grub-core/loader/efi/chainloader.c | 612 ++++++++++++++++++++++++++++++++++--- + include/grub/efi/pe32.h | 20 +- + 2 files changed, 595 insertions(+), 37 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index 14ce6ddd7ad..87a91e16f17 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; +@@ -191,12 +199,523 @@ 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_error (GRUB_ERR_BAD_ARGUMENT, "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 0; ++} ++ ++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 = ++#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 - 1); ++ ++ grub_dprintf ("chain", "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)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 < data || (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, size; ++ 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; ++ ++ b = grub_efi_system_table->boot_services; ++ ++ if (read_header (data, datasize, &context)) ++ { ++ grub_dprintf ("chain", "Succeed to read header\n"); ++ } ++ else ++ { ++ grub_dprintf ("chain", "Failed to read header\n"); ++ goto error_exit; ++ } ++ ++ section_alignment = context.section_alignment; ++ buffer_size = context.image_size + section_alignment; ++ ++ 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); ++ ++ char *reloc_base, *reloc_base_end; ++ reloc_base = image_address (buffer_aligned, datasize, ++ context.reloc_dir->rva); ++ /* RelocBaseEnd here is the address of the last byte of the table */ ++ reloc_base_end = image_address (buffer_aligned, datasize, ++ context.reloc_dir->rva ++ + context.reloc_dir->size - 1); ++ struct grub_pe32_section_table *reloc_section = NULL; ++ ++ section = context.first_section; ++ for (i = 0; i < context.number_of_sections; i++, section++) ++ { ++ size = section->virtual_size; ++ if (size > section->raw_data_size) ++ size = section->raw_data_size; ++ ++ base = image_address (buffer_aligned, context.image_size, ++ section->virtual_address); ++ end = image_address (buffer_aligned, context.image_size, ++ section->virtual_address + size - 1); ++ ++ ++ /* 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 && reloc_base_end == end) ++ { ++ reloc_section = section; ++ } ++ } ++ ++ if (section->characteristics && GRUB_PE32_SCN_MEM_DISCARDABLE) ++ continue; ++ ++ if (!base || !end) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid section size"); ++ goto error_exit; ++ } ++ ++ 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_memcpy (base, (grub_efi_uint8_t*)data + section->raw_data_offset, ++ size); ++ ++ if (size < section->virtual_size) ++ grub_memset (base + size, 0, section->virtual_size - size); ++ ++ grub_dprintf ("chain", "copied section %s\n", section->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; ++ } ++ } ++ ++ entry_point = image_address (buffer_aligned, context.image_size, ++ context.entry_point); ++ ++ if (!entry_point) ++ { ++ grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid 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_printf ("file path: "); ++ grub_efi_print_device_path (li->file_path); ++ } ++ else ++ { ++ grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching file path found"); ++ goto error_exit; ++ } ++ ++ efi_status = efi_call_2 (entry_point, grub_efi_image_handle, ++ grub_efi_system_table); ++ ++ grub_memcpy (li, &li_bak, sizeof (grub_efi_loaded_image_t)); ++ efi_status = efi_call_1 (b->free_pool, buffer); ++ ++ return 1; ++ ++error_exit: ++ 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_secureboot_chainloader_boot (void) ++{ ++ handle_image ((void *)address, fsize); ++ 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; +@@ -204,7 +723,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + grub_efi_loaded_image_t *loaded_image; + char *filename; + void *boot_image = 0; +- grub_efi_handle_t dev_handle = 0; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); +@@ -216,9 +734,36 @@ 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); + if (! file) + goto fail; +@@ -267,14 +812,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + 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, +@@ -288,7 +833,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"), +@@ -298,7 +843,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 +@@ -307,6 +852,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)) +@@ -321,21 +874,28 @@ 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 + ++ if (grub_linuxefi_secure_validate((void *)address, fsize)) ++ { ++ grub_file_close (file); ++ grub_loader_set (grub_secureboot_chainloader_boot, ++ grub_secureboot_chainloader_unload, 0); ++ return 0; ++ } ++ + status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, +- boot_image, size, +- &image_handle); ++ boot_image, fsize, &image_handle); + if (status != GRUB_EFI_SUCCESS) + { + if (status == GRUB_EFI_OUT_OF_RESOURCES) +@@ -357,33 +917,10 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + loaded_image->device_handle = dev_handle; + +- if (argc > 1) ++ if (cmdline) + { +- 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; +- +- 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; ++ loaded_image->load_options_size = cmdline_len; + } + + grub_file_close (file); +@@ -405,6 +942,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/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index 7d44732d2c3..6e24dae2cb6 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -214,7 +214,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; +@@ -265,6 +269,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/0243-Rework-linux-command.patch b/0243-Rework-linux-command.patch deleted file mode 100644 index 2128fe3..0000000 --- a/0243-Rework-linux-command.patch +++ /dev/null @@ -1,104 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Sun, 9 Aug 2015 16:12:39 -0700 -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 | 34 +++++++++++++++++++++------------- - 1 file changed, 21 insertions(+), 13 deletions(-) - -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 930a90b1f32..626ec9fef0c 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -681,12 +681,13 @@ 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, 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); - -@@ -700,7 +701,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"), -@@ -708,6 +717,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"); -@@ -807,13 +819,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - linux_params.ps_mouse = linux_params.padding10 = 0; - - len = sizeof (linux_params) - 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; -- } -+ -+ grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len); -+ kernel_offset += len; - - linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; - -@@ -872,7 +880,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); -@@ -1020,9 +1028,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - (sizeof (LINUX_IMAGE) - 1)); - - 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) - { -@@ -1033,6 +1039,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - fail: - -+ grub_free (kernel); -+ - if (file) - grub_file_close (file); - diff --git a/0244-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch b/0244-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch new file mode 100644 index 0000000..b006067 --- /dev/null +++ b/0244-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch @@ -0,0 +1,491 @@ +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/efi/efi.c | 28 ------------------ + grub-core/kern/efi/sb.c | 58 ++++++++++++++++++++++++++++++++++++++ + 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 + + 19 files changed, 146 insertions(+), 29 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 338244f6b47..423def037c2 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -196,6 +196,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/efi/efi.c b/grub-core/kern/efi/efi.c +index 92e1583b37d..e339f264b3a 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -278,34 +278,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) +- 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/sb.c b/grub-core/kern/efi/sb.c +new file mode 100644 +index 00000000000..a41b6c5b851 +--- /dev/null ++++ b/grub-core/kern/efi/sb.c +@@ -0,0 +1,58 @@ ++/* ++ * 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) ++ 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; ++#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 87a91e16f17..aee8e6becf6 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 7f96515da65..87709aa23e8 100644 +--- a/grub-core/loader/i386/bsd.c ++++ b/grub-core/loader/i386/bsd.c +@@ -38,6 +38,7 @@ + #ifdef GRUB_MACHINE_PCBIOS + #include + #endif ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -2124,6 +2125,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"); + +@@ -2163,6 +2167,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 44301e12659..930a90b1f32 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1139,6 +1140,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, +@@ -1148,6 +1152,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 b69cb7a3a7f..ebe7630210b 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+"); + +@@ -472,6 +473,9 @@ static grub_command_t cmd_linux, cmd_initrd; + + GRUB_MOD_INIT(linux16) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + cmd_linux = + grub_register_command ("linux16", grub_cmd_linux, + 0, N_("Load Linux.")); +@@ -483,6 +487,9 @@ GRUB_MOD_INIT(linux16) + + GRUB_MOD_FINI(linux16) + { ++ if (grub_efi_secure_boot()) ++ return; ++ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); + } +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 40c67e82489..26df46a4161 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+"); + +@@ -446,6 +447,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, +@@ -466,6 +470,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 c9885b1bcd7..df8dfdb4ba0 100644 +--- a/grub-core/loader/xnu.c ++++ b/grub-core/loader/xnu.c +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -1469,6 +1470,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, +@@ -1509,6 +1513,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 f68a19de442..3efbafbb418 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -84,7 +84,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 10451384720..f7b4d29b0b3 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/0244-Rework-linux16-command.patch b/0244-Rework-linux16-command.patch deleted file mode 100644 index ec86d4a..0000000 --- a/0244-Rework-linux16-command.patch +++ /dev/null @@ -1,98 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Sun, 9 Aug 2015 16:20:58 -0700 -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 | 34 +++++++++++++++++++++------------- - 1 file changed, 21 insertions(+), 13 deletions(-) - -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index ebe7630210b..e2bb1a99a74 100644 ---- a/grub-core/loader/i386/pc/linux.c -+++ b/grub-core/loader/i386/pc/linux.c -@@ -124,13 +124,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); - -@@ -144,7 +145,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"), -@@ -152,6 +161,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"); -@@ -315,13 +327,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) -@@ -356,10 +364,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - len = grub_linux16_prot_size; -- if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size) -- != (grub_ssize_t) grub_linux16_prot_size && !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) - { -@@ -369,6 +375,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - fail: - -+ grub_free (kernel); -+ - if (file) - grub_file_close (file); - diff --git a/0245-Make-grub-editenv-build-again.patch b/0245-Make-grub-editenv-build-again.patch deleted file mode 100644 index 64c001f..0000000 --- a/0245-Make-grub-editenv-build-again.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 4 Mar 2016 16:29:13 -0500 -Subject: [PATCH] Make grub-editenv build again. - -36212460d3565b18439a3a8130b28e6c97702c6a split how some of the mkimage -utility functions are defined, and they wind up being linked into -grub-editenv. Most utilities got fixed, but this one was missed. - -Signed-off-by: Peter Jones ---- - Makefile.util.def | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/Makefile.util.def b/Makefile.util.def -index 2d032643de7..879e8eb98a4 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -237,6 +237,8 @@ program = { - 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; diff --git a/0245-Make-grub_fatal-also-backtrace.patch b/0245-Make-grub_fatal-also-backtrace.patch new file mode 100644 index 0000000..520c413 --- /dev/null +++ b/0245-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 423def037c2..edf249f0002 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -175,6 +175,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; + +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index f1fab700048..5ce89a40c68 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/0246-Fix-up-some-man-pages-rpmdiff-noticed.patch b/0246-Fix-up-some-man-pages-rpmdiff-noticed.patch deleted file mode 100644 index 71b0a22..0000000 --- a/0246-Fix-up-some-man-pages-rpmdiff-noticed.patch +++ /dev/null @@ -1,150 +0,0 @@ -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 aa06ed59c8d..f69f8986791 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -80,6 +80,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]) -@@ -98,6 +99,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/0246-Rework-linux-command.patch b/0246-Rework-linux-command.patch new file mode 100644 index 0000000..2128fe3 --- /dev/null +++ b/0246-Rework-linux-command.patch @@ -0,0 +1,104 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Sun, 9 Aug 2015 16:12:39 -0700 +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 | 34 +++++++++++++++++++++------------- + 1 file changed, 21 insertions(+), 13 deletions(-) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 930a90b1f32..626ec9fef0c 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -681,12 +681,13 @@ 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, 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); + +@@ -700,7 +701,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"), +@@ -708,6 +717,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"); +@@ -807,13 +819,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + linux_params.ps_mouse = linux_params.padding10 = 0; + + len = sizeof (linux_params) - 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; +- } ++ ++ grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len); ++ kernel_offset += len; + + linux_params.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; + +@@ -872,7 +880,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); +@@ -1020,9 +1028,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + - (sizeof (LINUX_IMAGE) - 1)); + + 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) + { +@@ -1033,6 +1039,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + fail: + ++ grub_free (kernel); ++ + if (file) + grub_file_close (file); + diff --git a/0247-Re-work-some-intricacies-of-PE-loading.patch b/0247-Re-work-some-intricacies-of-PE-loading.patch deleted file mode 100644 index dc4cdd7..0000000 --- a/0247-Re-work-some-intricacies-of-PE-loading.patch +++ /dev/null @@ -1,350 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 9 Jun 2016 12:22:29 -0400 -Subject: [PATCH] Re-work some intricacies of PE loading. - -The PE spec is not a well written document, and awesomely every place -where there's an ambiguous way to read something, Windows' bootmgfw.efi -takes a different read than either of them. ---- - grub-core/loader/efi/chainloader.c | 156 +++++++++++++++++++++++++++++-------- - include/grub/efi/pe32.h | 32 +++++++- - 2 files changed, 152 insertions(+), 36 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index aee8e6becf6..4b77a7d5adb 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -301,7 +301,7 @@ image_is_64_bit (grub_pe_header_t *pe_hdr) - return 0; - } - --static const grub_uint16_t machine_type = -+static const grub_uint16_t machine_type __attribute__((__unused__)) = - #if defined(__x86_64__) - GRUB_PE32_MACHINE_X86_64; - #elif defined(__aarch64__) -@@ -367,10 +367,10 @@ relocate_coff (pe_coff_loader_image_context_t *context, - - reloc_base = image_address (orig, size, section->raw_data_offset); - reloc_base_end = image_address (orig, size, section->raw_data_offset -- + section->virtual_size - 1); -+ + section->virtual_size); - -- grub_dprintf ("chain", "reloc_base %p reloc_base_end %p\n", reloc_base, -- reloc_base_end); -+ 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; -@@ -507,12 +507,13 @@ handle_image (void *data, grub_efi_uint32_t datasize) - grub_efi_status_t efi_status; - char *buffer = NULL; - char *buffer_aligned = NULL; -- grub_efi_uint32_t i, size; -+ 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; - - b = grub_efi_system_table->boot_services; - -@@ -526,8 +527,28 @@ handle_image (void *data, grub_efi_uint32_t datasize) - goto error_exit; - } - -+ /* -+ * 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 %08lx, datasize is %08x\n", -+ context.image_size, datasize); - - efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, - buffer_size, &buffer); -@@ -539,7 +560,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) - } - - 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")); -@@ -548,27 +568,62 @@ handle_image (void *data, grub_efi_uint32_t datasize) - - 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; -- reloc_base = image_address (buffer_aligned, datasize, -+ grub_dprintf ("chain", "reloc_dir: %p reloc_size: 0x%08x\n", -+ (void *)(unsigned long 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, datasize, -+ 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; - - section = context.first_section; - for (i = 0; i < context.number_of_sections; i++, section++) - { -- size = section->virtual_size; -- if (size > section->raw_data_size) -- size = section->raw_data_size; -+ 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 + size - 1); -+ 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. */ -@@ -587,21 +642,46 @@ handle_image (void *data, grub_efi_uint32_t datasize) - if (section->raw_data_size && section->virtual_size && - base && end && reloc_base == base && reloc_base_end == end) - { -+ grub_dprintf ("chain", " section is relocation section\n"); - reloc_section = section; - } -+ else -+ { -+ 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); -+ } - } - -- if (section->characteristics && GRUB_PE32_SCN_MEM_DISCARDABLE) -- continue; -+ 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->virtual_address < context.size_of_headers || -- section->raw_data_offset < context.size_of_headers) -+ 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); -@@ -609,13 +689,24 @@ handle_image (void *data, grub_efi_uint32_t datasize) - } - - if (section->raw_data_size > 0) -- grub_memcpy (base, (grub_efi_uint8_t*)data + section->raw_data_offset, -- size); -+ { -+ 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 (size < section->virtual_size) -- grub_memset (base + size, 0, section->virtual_size - 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", "copied section %s\n", section->name); -+ grub_dprintf ("chain", " finished section %s\n", name); - } - - /* 5 == EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC */ -@@ -638,12 +729,15 @@ handle_image (void *data, grub_efi_uint32_t datasize) - } - } - -- entry_point = image_address (buffer_aligned, context.image_size, -- context.entry_point); -- -- if (!entry_point) -+ if (!found_entry_point) - { -- grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid 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; - } - -@@ -661,26 +755,24 @@ handle_image (void *data, grub_efi_uint32_t datasize) - 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_printf ("file path: "); -- grub_efi_print_device_path (li->file_path); -- } -- else -+ 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); - -diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h -index 6e24dae2cb6..c03cc599f63 100644 ---- a/include/grub/efi/pe32.h -+++ b/include/grub/efi/pe32.h -@@ -229,12 +229,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 -@@ -243,10 +249,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 diff --git a/0247-Rework-linux16-command.patch b/0247-Rework-linux16-command.patch new file mode 100644 index 0000000..ec86d4a --- /dev/null +++ b/0247-Rework-linux16-command.patch @@ -0,0 +1,98 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Sun, 9 Aug 2015 16:20:58 -0700 +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 | 34 +++++++++++++++++++++------------- + 1 file changed, 21 insertions(+), 13 deletions(-) + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index ebe7630210b..e2bb1a99a74 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -124,13 +124,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); + +@@ -144,7 +145,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"), +@@ -152,6 +161,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"); +@@ -315,13 +327,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) +@@ -356,10 +364,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + len = grub_linux16_prot_size; +- if (grub_file_read (file, grub_linux_prot_chunk, grub_linux16_prot_size) +- != (grub_ssize_t) grub_linux16_prot_size && !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) + { +@@ -369,6 +375,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + fail: + ++ grub_free (kernel); ++ + if (file) + grub_file_close (file); + diff --git a/0248-Make-grub-editenv-build-again.patch b/0248-Make-grub-editenv-build-again.patch new file mode 100644 index 0000000..64c001f --- /dev/null +++ b/0248-Make-grub-editenv-build-again.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 4 Mar 2016 16:29:13 -0500 +Subject: [PATCH] Make grub-editenv build again. + +36212460d3565b18439a3a8130b28e6c97702c6a split how some of the mkimage +utility functions are defined, and they wind up being linked into +grub-editenv. Most utilities got fixed, but this one was missed. + +Signed-off-by: Peter Jones +--- + Makefile.util.def | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/Makefile.util.def b/Makefile.util.def +index 2d032643de7..879e8eb98a4 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -237,6 +237,8 @@ program = { + 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; diff --git a/0248-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch b/0248-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch deleted file mode 100644 index 061999e..0000000 --- a/0248-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch +++ /dev/null @@ -1,412 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 10 Jun 2016 14:06:15 -0400 -Subject: [PATCH] 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 ---- - grub-core/kern/efi/sb.c | 14 +++-- - grub-core/loader/arm64/linux.c | 4 +- - grub-core/loader/efi/chainloader.c | 124 ++++++++++++++++++++++--------------- - grub-core/loader/efi/linux.c | 13 ++-- - grub-core/loader/i386/efi/linux.c | 10 ++- - include/grub/efi/linux.h | 2 +- - 6 files changed, 103 insertions(+), 64 deletions(-) - -diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c -index a41b6c5b851..d74778b0cac 100644 ---- a/grub-core/kern/efi/sb.c -+++ b/grub-core/kern/efi/sb.c -@@ -36,14 +36,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 ab0d27ee4df..fcab2ed37e7 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -248,6 +248,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - grub_file_t file = 0; - struct linux_arm64_kernel_header lh; - struct grub_arm64_linux_pe_header *pe; -+ int rc; - - grub_dl_ref (my_mod); - -@@ -292,7 +293,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 4b77a7d5adb..b977c7b5573 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -182,7 +182,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); - -@@ -252,10 +251,9 @@ read_header (void *data, grub_efi_uint32_t size, - grub_efi_status_t status; - - shim_lock = grub_efi_locate_protocol (&guid, NULL); -- - if (!shim_lock) - { -- grub_error (GRUB_ERR_BAD_ARGUMENT, "no shim lock protocol"); -+ grub_dprintf ("chain", "no shim lock protocol"); - return 0; - } - -@@ -280,7 +278,7 @@ read_header (void *data, grub_efi_uint32_t size, - break; - } - -- return 0; -+ return -1; - } - - static void* -@@ -381,7 +379,7 @@ relocate_coff (pe_coff_loader_image_context_t *context, - return GRUB_EFI_UNSUPPORTED; - } - -- adjust = (grub_uint64_t)data - context->image_address; -+ adjust = (grub_uint64_t)(grub_efi_uintn_t)data - context->image_address; - if (adjust == 0) - return GRUB_EFI_SUCCESS; - -@@ -514,18 +512,25 @@ handle_image (void *data, grub_efi_uint32_t datasize) - grub_uint32_t section_alignment; - grub_uint32_t buffer_size; - int found_entry_point = 0; -+ int rc; - - b = grub_efi_system_table->boot_services; - -- if (read_header (data, datasize, &context)) -- { -- grub_dprintf ("chain", "Succeed to read header\n"); -- } -- else -+ 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: -@@ -547,7 +552,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) - section_alignment = 4096; - - buffer_size = context.image_size + section_alignment; -- grub_dprintf ("chain", "image size is %08lx, datasize is %08x\n", -+ 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, -@@ -580,7 +585,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) - - char *reloc_base, *reloc_base_end; - grub_dprintf ("chain", "reloc_dir: %p reloc_size: 0x%08x\n", -- (void *)(unsigned long long)context.reloc_dir->rva, -+ (void *)(unsigned long)context.reloc_dir->rva, - context.reloc_dir->size); - reloc_base = image_address (buffer_aligned, context.image_size, - context.reloc_dir->rva); -@@ -796,10 +801,56 @@ grub_secureboot_chainloader_unload (void) - 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) - { -- handle_image ((void *)address, fsize); -+ 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; - } -@@ -813,9 +864,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - 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; -+ int rc; - - if (argc == 0) - return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); -@@ -902,9 +953,6 @@ 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); -- - fsize = grub_file_size (file); - if (!fsize) - { -@@ -979,51 +1027,27 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), - } - #endif - -- if (grub_linuxefi_secure_validate((void *)address, fsize)) -+ rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); -+ grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); -+ if (rc > 0) - { - grub_file_close (file); - grub_loader_set (grub_secureboot_chainloader_boot, - grub_secureboot_chainloader_unload, 0); - return 0; - } -- -- status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, -- boot_image, fsize, &image_handle); -- if (status != GRUB_EFI_SUCCESS) -+ else 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_load_and_start_image(boot_image); -+ grub_file_close (file); -+ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 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) -- { -- grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); -- goto fail; -- } -- loaded_image->device_handle = dev_handle; -- -- if (cmdline) -- { -- loaded_image->load_options = cmdline; -- loaded_image->load_options_size = cmdline_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); - -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index aea378adf5c..8890bdf059a 100644 ---- a/grub-core/loader/efi/linux.c -+++ b/grub-core/loader/efi/linux.c -@@ -33,21 +33,24 @@ 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; -+ return 0; - -- if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) -+ status = shim_lock->verify(data, size); -+ grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); -+ if (status == GRUB_EFI_SUCCESS) - return 1; - -- return 0; -+ return -1; - } - - typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 7ccf32d9d45..82f75b7f3ab 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -155,6 +155,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - struct linux_kernel_header lh; - grub_ssize_t len, start, filelen; - void *kernel = NULL; -+ int rc; - - grub_dl_ref (my_mod); - -@@ -180,13 +181,16 @@ 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]); -+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), -+ argv[0]); - grub_free (kernel); - goto fail; - } -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/0249-Fix-up-some-man-pages-rpmdiff-noticed.patch b/0249-Fix-up-some-man-pages-rpmdiff-noticed.patch new file mode 100644 index 0000000..71b0a22 --- /dev/null +++ b/0249-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 aa06ed59c8d..f69f8986791 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -80,6 +80,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]) +@@ -98,6 +99,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/0249-linuxefi-fix-double-free-on-verification-failure.patch b/0249-linuxefi-fix-double-free-on-verification-failure.patch deleted file mode 100644 index 7d1b3c8..0000000 --- a/0249-linuxefi-fix-double-free-on-verification-failure.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Jun 2016 09:50:25 -0400 -Subject: [PATCH] linuxefi: fix double free on verification failure. - -Signed-off-by: Peter Jones ---- - grub-core/loader/i386/efi/linux.c | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 82f75b7f3ab..010bf982d80 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -191,7 +191,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - { - grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), - argv[0]); -- grub_free (kernel); - goto fail; - } - diff --git a/0250-Re-work-some-intricacies-of-PE-loading.patch b/0250-Re-work-some-intricacies-of-PE-loading.patch new file mode 100644 index 0000000..dc4cdd7 --- /dev/null +++ b/0250-Re-work-some-intricacies-of-PE-loading.patch @@ -0,0 +1,350 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 9 Jun 2016 12:22:29 -0400 +Subject: [PATCH] Re-work some intricacies of PE loading. + +The PE spec is not a well written document, and awesomely every place +where there's an ambiguous way to read something, Windows' bootmgfw.efi +takes a different read than either of them. +--- + grub-core/loader/efi/chainloader.c | 156 +++++++++++++++++++++++++++++-------- + include/grub/efi/pe32.h | 32 +++++++- + 2 files changed, 152 insertions(+), 36 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index aee8e6becf6..4b77a7d5adb 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -301,7 +301,7 @@ image_is_64_bit (grub_pe_header_t *pe_hdr) + return 0; + } + +-static const grub_uint16_t machine_type = ++static const grub_uint16_t machine_type __attribute__((__unused__)) = + #if defined(__x86_64__) + GRUB_PE32_MACHINE_X86_64; + #elif defined(__aarch64__) +@@ -367,10 +367,10 @@ relocate_coff (pe_coff_loader_image_context_t *context, + + reloc_base = image_address (orig, size, section->raw_data_offset); + reloc_base_end = image_address (orig, size, section->raw_data_offset +- + section->virtual_size - 1); ++ + section->virtual_size); + +- grub_dprintf ("chain", "reloc_base %p reloc_base_end %p\n", reloc_base, +- reloc_base_end); ++ 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; +@@ -507,12 +507,13 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_efi_status_t efi_status; + char *buffer = NULL; + char *buffer_aligned = NULL; +- grub_efi_uint32_t i, size; ++ 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; + + b = grub_efi_system_table->boot_services; + +@@ -526,8 +527,28 @@ handle_image (void *data, grub_efi_uint32_t datasize) + goto error_exit; + } + ++ /* ++ * 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 %08lx, datasize is %08x\n", ++ context.image_size, datasize); + + efi_status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA, + buffer_size, &buffer); +@@ -539,7 +560,6 @@ handle_image (void *data, grub_efi_uint32_t datasize) + } + + 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")); +@@ -548,27 +568,62 @@ handle_image (void *data, grub_efi_uint32_t datasize) + + 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; +- reloc_base = image_address (buffer_aligned, datasize, ++ grub_dprintf ("chain", "reloc_dir: %p reloc_size: 0x%08x\n", ++ (void *)(unsigned long 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, datasize, ++ 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; + + section = context.first_section; + for (i = 0; i < context.number_of_sections; i++, section++) + { +- size = section->virtual_size; +- if (size > section->raw_data_size) +- size = section->raw_data_size; ++ 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 + size - 1); ++ 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. */ +@@ -587,21 +642,46 @@ handle_image (void *data, grub_efi_uint32_t datasize) + if (section->raw_data_size && section->virtual_size && + base && end && reloc_base == base && reloc_base_end == end) + { ++ grub_dprintf ("chain", " section is relocation section\n"); + reloc_section = section; + } ++ else ++ { ++ 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); ++ } + } + +- if (section->characteristics && GRUB_PE32_SCN_MEM_DISCARDABLE) +- continue; ++ 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->virtual_address < context.size_of_headers || +- section->raw_data_offset < context.size_of_headers) ++ 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); +@@ -609,13 +689,24 @@ handle_image (void *data, grub_efi_uint32_t datasize) + } + + if (section->raw_data_size > 0) +- grub_memcpy (base, (grub_efi_uint8_t*)data + section->raw_data_offset, +- size); ++ { ++ 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 (size < section->virtual_size) +- grub_memset (base + size, 0, section->virtual_size - 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", "copied section %s\n", section->name); ++ grub_dprintf ("chain", " finished section %s\n", name); + } + + /* 5 == EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC */ +@@ -638,12 +729,15 @@ handle_image (void *data, grub_efi_uint32_t datasize) + } + } + +- entry_point = image_address (buffer_aligned, context.image_size, +- context.entry_point); +- +- if (!entry_point) ++ if (!found_entry_point) + { +- grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid 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; + } + +@@ -661,26 +755,24 @@ handle_image (void *data, grub_efi_uint32_t datasize) + 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_printf ("file path: "); +- grub_efi_print_device_path (li->file_path); +- } +- else ++ 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); + +diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h +index 6e24dae2cb6..c03cc599f63 100644 +--- a/include/grub/efi/pe32.h ++++ b/include/grub/efi/pe32.h +@@ -229,12 +229,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 +@@ -243,10 +249,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 diff --git a/0250-fix-machine-type-test-in-30_os-prober.in.patch b/0250-fix-machine-type-test-in-30_os-prober.in.patch deleted file mode 100644 index 11d6f4b..0000000 --- a/0250-fix-machine-type-test-in-30_os-prober.in.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 11 Jul 2016 13:36:45 -0400 -Subject: [PATCH] fix machine type test in 30_os-prober.in - -Signed-off-by: Peter Jones ---- - util/grub.d/30_os-prober.in | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in -index dc98eace934..e40274fc0f4 100644 ---- a/util/grub.d/30_os-prober.in -+++ b/util/grub.d/30_os-prober.in -@@ -144,6 +144,7 @@ for OS in ${OSPROBED} ; do - sixteenbit="" - linuxefi="linux" - initrdefi="initrd" -+ machine=`uname -m` - case "$machine" in - i?86|x86_64) - sixteenbit="16" diff --git a/0251-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch b/0251-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch new file mode 100644 index 0000000..061999e --- /dev/null +++ b/0251-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch @@ -0,0 +1,412 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 10 Jun 2016 14:06:15 -0400 +Subject: [PATCH] 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 +--- + grub-core/kern/efi/sb.c | 14 +++-- + grub-core/loader/arm64/linux.c | 4 +- + grub-core/loader/efi/chainloader.c | 124 ++++++++++++++++++++++--------------- + grub-core/loader/efi/linux.c | 13 ++-- + grub-core/loader/i386/efi/linux.c | 10 ++- + include/grub/efi/linux.h | 2 +- + 6 files changed, 103 insertions(+), 64 deletions(-) + +diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c +index a41b6c5b851..d74778b0cac 100644 +--- a/grub-core/kern/efi/sb.c ++++ b/grub-core/kern/efi/sb.c +@@ -36,14 +36,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 ab0d27ee4df..fcab2ed37e7 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -248,6 +248,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_file_t file = 0; + struct linux_arm64_kernel_header lh; + struct grub_arm64_linux_pe_header *pe; ++ int rc; + + grub_dl_ref (my_mod); + +@@ -292,7 +293,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 4b77a7d5adb..b977c7b5573 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -182,7 +182,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); + +@@ -252,10 +251,9 @@ read_header (void *data, grub_efi_uint32_t size, + grub_efi_status_t status; + + shim_lock = grub_efi_locate_protocol (&guid, NULL); +- + if (!shim_lock) + { +- grub_error (GRUB_ERR_BAD_ARGUMENT, "no shim lock protocol"); ++ grub_dprintf ("chain", "no shim lock protocol"); + return 0; + } + +@@ -280,7 +278,7 @@ read_header (void *data, grub_efi_uint32_t size, + break; + } + +- return 0; ++ return -1; + } + + static void* +@@ -381,7 +379,7 @@ relocate_coff (pe_coff_loader_image_context_t *context, + return GRUB_EFI_UNSUPPORTED; + } + +- adjust = (grub_uint64_t)data - context->image_address; ++ adjust = (grub_uint64_t)(grub_efi_uintn_t)data - context->image_address; + if (adjust == 0) + return GRUB_EFI_SUCCESS; + +@@ -514,18 +512,25 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_uint32_t section_alignment; + grub_uint32_t buffer_size; + int found_entry_point = 0; ++ int rc; + + b = grub_efi_system_table->boot_services; + +- if (read_header (data, datasize, &context)) +- { +- grub_dprintf ("chain", "Succeed to read header\n"); +- } +- else ++ 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: +@@ -547,7 +552,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) + section_alignment = 4096; + + buffer_size = context.image_size + section_alignment; +- grub_dprintf ("chain", "image size is %08lx, datasize is %08x\n", ++ 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, +@@ -580,7 +585,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) + + char *reloc_base, *reloc_base_end; + grub_dprintf ("chain", "reloc_dir: %p reloc_size: 0x%08x\n", +- (void *)(unsigned long long)context.reloc_dir->rva, ++ (void *)(unsigned long)context.reloc_dir->rva, + context.reloc_dir->size); + reloc_base = image_address (buffer_aligned, context.image_size, + context.reloc_dir->rva); +@@ -796,10 +801,56 @@ grub_secureboot_chainloader_unload (void) + 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) + { +- handle_image ((void *)address, fsize); ++ 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; + } +@@ -813,9 +864,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + 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; ++ int rc; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); +@@ -902,9 +953,6 @@ 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); +- + fsize = grub_file_size (file); + if (!fsize) + { +@@ -979,51 +1027,27 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), + } + #endif + +- if (grub_linuxefi_secure_validate((void *)address, fsize)) ++ rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize); ++ grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc); ++ if (rc > 0) + { + grub_file_close (file); + grub_loader_set (grub_secureboot_chainloader_boot, + grub_secureboot_chainloader_unload, 0); + return 0; + } +- +- status = efi_call_6 (b->load_image, 0, grub_efi_image_handle, file_path, +- boot_image, fsize, &image_handle); +- if (status != GRUB_EFI_SUCCESS) ++ else 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_load_and_start_image(boot_image); ++ grub_file_close (file); ++ grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 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) +- { +- grub_error (GRUB_ERR_BAD_OS, "no loaded image available"); +- goto fail; +- } +- loaded_image->device_handle = dev_handle; +- +- if (cmdline) +- { +- loaded_image->load_options = cmdline; +- loaded_image->load_options_size = cmdline_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); + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index aea378adf5c..8890bdf059a 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -33,21 +33,24 @@ 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; ++ return 0; + +- if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS) ++ status = shim_lock->verify(data, size); ++ grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); ++ if (status == GRUB_EFI_SUCCESS) + return 1; + +- return 0; ++ return -1; + } + + typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *); +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 7ccf32d9d45..82f75b7f3ab 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -155,6 +155,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + struct linux_kernel_header lh; + grub_ssize_t len, start, filelen; + void *kernel = NULL; ++ int rc; + + grub_dl_ref (my_mod); + +@@ -180,13 +181,16 @@ 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]); ++ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), ++ argv[0]); + grub_free (kernel); + goto fail; + } +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/0251-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch b/0251-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch deleted file mode 100644 index 27e078c..0000000 --- a/0251-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Laszlo Ersek -Date: Mon, 21 Nov 2016 15:34:00 +0100 -Subject: [PATCH] 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 ---- - grub-core/loader/efi/chainloader.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index b977c7b5573..d5ab21d09c3 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -401,7 +401,7 @@ relocate_coff (pe_coff_loader_image_context_t *context, - reloc_end = (struct grub_pe32_fixup_block *) - ((char *)reloc_base + reloc_base->size); - -- if ((void *)reloc_end < data || (void *)reloc_end > image_end) -+ if ((void *)reloc_end < orig || (void *)reloc_end > image_end) - { - grub_error (GRUB_ERR_BAD_ARGUMENT, "Reloc entry %d overflows binary", - n); diff --git a/0252-efi-chainloader-truncate-overlong-relocation-section.patch b/0252-efi-chainloader-truncate-overlong-relocation-section.patch deleted file mode 100644 index 6931f91..0000000 --- a/0252-efi-chainloader-truncate-overlong-relocation-section.patch +++ /dev/null @@ -1,110 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Laszlo Ersek -Date: Wed, 23 Nov 2016 06:27:09 +0100 -Subject: [PATCH] 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/loader/efi/chainloader.c | 26 +++++++++++++++++++++----- - 1 file changed, 21 insertions(+), 5 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index d5ab21d09c3..7826e794ad9 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -596,7 +596,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) - grub_dprintf ("chain", "reloc_base: %p reloc_base_end: %p\n", - reloc_base, reloc_base_end); - -- struct grub_pe32_section_table *reloc_section = NULL; -+ 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++) -@@ -645,12 +645,28 @@ handle_image (void *data, grub_efi_uint32_t datasize) - * 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 && reloc_base_end == end) -+ base && end && reloc_base == base) - { -- grub_dprintf ("chain", " section is relocation section\n"); -- reloc_section = section; -+ 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; -+ } - } -- else -+ -+ if (!reloc_section) - { - grub_dprintf ("chain", " section is not reloc section?\n"); - grub_dprintf ("chain", " rds: 0x%08x, vs: %08x\n", diff --git a/0252-linuxefi-fix-double-free-on-verification-failure.patch b/0252-linuxefi-fix-double-free-on-verification-failure.patch new file mode 100644 index 0000000..7d1b3c8 --- /dev/null +++ b/0252-linuxefi-fix-double-free-on-verification-failure.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Jun 2016 09:50:25 -0400 +Subject: [PATCH] linuxefi: fix double free on verification failure. + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 82f75b7f3ab..010bf982d80 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -191,7 +191,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + { + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), + argv[0]); +- grub_free (kernel); + goto fail; + } + diff --git a/0253-fix-machine-type-test-in-30_os-prober.in.patch b/0253-fix-machine-type-test-in-30_os-prober.in.patch new file mode 100644 index 0000000..11d6f4b --- /dev/null +++ b/0253-fix-machine-type-test-in-30_os-prober.in.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 11 Jul 2016 13:36:45 -0400 +Subject: [PATCH] fix machine type test in 30_os-prober.in + +Signed-off-by: Peter Jones +--- + util/grub.d/30_os-prober.in | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in +index dc98eace934..e40274fc0f4 100644 +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -144,6 +144,7 @@ for OS in ${OSPROBED} ; do + sixteenbit="" + linuxefi="linux" + initrdefi="initrd" ++ machine=`uname -m` + case "$machine" in + i?86|x86_64) + sixteenbit="16" diff --git a/0253-linuxefi-minor-cleanups.patch b/0253-linuxefi-minor-cleanups.patch deleted file mode 100644 index 057c746..0000000 --- a/0253-linuxefi-minor-cleanups.patch +++ /dev/null @@ -1,86 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Feb 2017 16:31:52 -0500 -Subject: [PATCH] linuxefi: minor cleanups - -Signed-off-by: Peter Jones ---- - grub-core/loader/i386/efi/linux.c | 30 ++++++++++++++++++++---------- - 1 file changed, 20 insertions(+), 10 deletions(-) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 010bf982d80..8b5a817b9d1 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -61,13 +61,18 @@ grub_linuxefi_unload (void) - grub_dl_unref (my_mod); - loaded = 0; - if (initrd_mem) -- grub_efi_free_pages((grub_efi_physical_address_t)initrd_mem, BYTES_TO_PAGES(params->ramdisk_size)); -+ 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)linux_cmdline, BYTES_TO_PAGES(params->cmdline_size + 1)); -+ 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)kernel_mem, BYTES_TO_PAGES(kernel_size)); -+ 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)params, BYTES_TO_PAGES(16384)); -+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -+ BYTES_TO_PAGES(16384)); - return GRUB_ERR_NONE; - } - -@@ -115,7 +120,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - } - - params->ramdisk_size = size; -- params->ramdisk_image = (grub_uint32_t)(grub_uint64_t) initrd_mem; -+ params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; - - ptr = initrd_mem; - -@@ -142,7 +147,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - grub_free (files); - - if (initrd_mem && grub_errno) -- grub_efi_free_pages((grub_efi_physical_address_t)initrd_mem, BYTES_TO_PAGES(size)); -+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, -+ BYTES_TO_PAGES(size)); - - return grub_errno; - } -@@ -244,7 +250,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - linux_cmdline + sizeof (LINUX_IMAGE) - 1, - lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1)); - -- lh.cmd_line_ptr = (grub_uint32_t)(grub_uint64_t)linux_cmdline; -+ lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; - - handover_offset = lh.handover_offset; - -@@ -288,13 +294,17 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - if (linux_cmdline && !loaded) -- grub_efi_free_pages((grub_efi_physical_address_t)linux_cmdline, BYTES_TO_PAGES(lh.cmdline_size + 1)); -+ 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)kernel_mem, BYTES_TO_PAGES(kernel_size)); -+ 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)params, BYTES_TO_PAGES(16384)); -+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, -+ BYTES_TO_PAGES(16384)); - - return grub_errno; - } diff --git a/0254-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch b/0254-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch deleted file mode 100644 index fe3a046..0000000 --- a/0254-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch +++ /dev/null @@ -1,273 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 14 Feb 2017 16:18:54 -0500 -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, 93 insertions(+), 33 deletions(-) - -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index 8890bdf059a..2a7024134da 100644 ---- a/grub-core/loader/efi/linux.c -+++ b/grub-core/loader/efi/linux.c -@@ -56,12 +56,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 8b5a817b9d1..bed5919cab3 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); - } - -@@ -119,6 +115,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -+ grub_dprintf ("linuxefi", "initrd_mem = %lx\n", (unsigned long) initrd_mem); -+ - params->ramdisk_size = size; - params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; - -@@ -153,14 +151,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_kernel_header lh; -+ struct linux_kernel_header *lh; - grub_ssize_t len, start, filelen; - void *kernel = NULL; -+ int setup_header_end_offset; - int rc; - - grub_dl_ref (my_mod); -@@ -200,69 +204,107 @@ 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_memset (params, 0, 16384); -+ grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params); - -- grub_memcpy (&lh, kernel, sizeof (lh)); -+ grub_memset (params, 0, sizeof(*params)); - -- if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) -+ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); -+ grub_dprintf ("linuxefi", "copying %d bytes from %p to %p\n", -+ MIN(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(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); -+ lh = (struct linux_kernel_header *)params; -+ grub_dprintf ("linuxefi", "lh is at %p\n", lh); -+ grub_dprintf ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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")); - goto fail; - } - -+ grub_dprintf ("linuxefi", "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, -- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1)); -+ lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1)); - -- lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; -+ grub_dprintf ("linuxefi", "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 ("linuxefi", "computing handover offset\n"); -+ handover_offset = lh->handover_offset; - -- start = (lh.setup_sects + 1) * 512; -+ start = (lh->setup_sects + 1) * 512; - len = grub_file_size(file) - start; - -- kernel_mem = grub_efi_allocate_pages(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) - { -@@ -270,17 +312,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_memcpy (kernel_mem, (char *)kernel + start, len); -+ grub_dprintf ("linuxefi", "kernel_mem = %lx\n", (unsigned long) kernel_mem); -+ - grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); - loaded=1; -+ grub_dprintf ("linuxefi", "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 ("linuxefi", "setting lh->type_of_loader\n"); -+ lh->type_of_loader = 0x6; -+ -+ grub_dprintf ("linuxefi", "setting lh->ext_loader_{type,ver}\n"); -+ params->ext_loader_type = 0; -+ params->ext_loader_ver = 2; -+ grub_dprintf("linuxefi", "kernel_mem: %p handover_offset: %08x\n", -+ kernel_mem, handover_offset); - - fail: -- - if (file) - grub_file_close (file); - -@@ -296,7 +346,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - 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)); -+ 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 5d8282a7db6..2cfb364b85d 100644 ---- a/include/grub/i386/linux.h -+++ b/include/grub/i386/linux.h -@@ -130,7 +130,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/0254-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch b/0254-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch new file mode 100644 index 0000000..27e078c --- /dev/null +++ b/0254-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Mon, 21 Nov 2016 15:34:00 +0100 +Subject: [PATCH] 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 +--- + grub-core/loader/efi/chainloader.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index b977c7b5573..d5ab21d09c3 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -401,7 +401,7 @@ relocate_coff (pe_coff_loader_image_context_t *context, + reloc_end = (struct grub_pe32_fixup_block *) + ((char *)reloc_base + reloc_base->size); + +- if ((void *)reloc_end < data || (void *)reloc_end > image_end) ++ if ((void *)reloc_end < orig || (void *)reloc_end > image_end) + { + grub_error (GRUB_ERR_BAD_ARGUMENT, "Reloc entry %d overflows binary", + n); diff --git a/0255-Fix-up-linux-params-usage.patch b/0255-Fix-up-linux-params-usage.patch deleted file mode 100644 index 3e089a9..0000000 --- a/0255-Fix-up-linux-params-usage.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 30 May 2017 14:16:07 -0400 -Subject: [PATCH] Fix up linux params usage... - -Signed-off-by: Peter Jones ---- - grub-core/loader/i386/efi/linux.c | 4 ++-- - grub-core/loader/i386/linux.c | 5 ++++- - 2 files changed, 6 insertions(+), 3 deletions(-) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index bed5919cab3..6ff796f56ff 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -161,7 +161,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - int argc, char *argv[]) - { - grub_file_t file = 0; -- struct linux_kernel_header *lh; -+ struct linux_i386_kernel_header *lh; - grub_ssize_t len, start, filelen; - void *kernel = NULL; - int setup_header_end_offset; -@@ -224,7 +224,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - grub_memcpy ((grub_uint8_t *)params + 0x1f1, - (grub_uint8_t *)kernel + 0x1f1, - MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); -- lh = (struct linux_kernel_header *)params; -+ lh = (struct linux_i386_kernel_header *)params; - grub_dprintf ("linuxefi", "lh is at %p\n", lh); - grub_dprintf ("linuxefi", "checking lh->boot_flag\n"); - if (lh->boot_flag != grub_cpu_to_le16 (0xaa55)) -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 626ec9fef0c..35055431247 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -680,6 +680,7 @@ 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, kernel_offset; - grub_ssize_t len; -@@ -811,6 +812,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); - -@@ -820,7 +822,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - len = sizeof (linux_params) - sizeof (lh); - -- grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len); -+ 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; diff --git a/0255-efi-chainloader-truncate-overlong-relocation-section.patch b/0255-efi-chainloader-truncate-overlong-relocation-section.patch new file mode 100644 index 0000000..6931f91 --- /dev/null +++ b/0255-efi-chainloader-truncate-overlong-relocation-section.patch @@ -0,0 +1,110 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Laszlo Ersek +Date: Wed, 23 Nov 2016 06:27:09 +0100 +Subject: [PATCH] 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/loader/efi/chainloader.c | 26 +++++++++++++++++++++----- + 1 file changed, 21 insertions(+), 5 deletions(-) + +diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c +index d5ab21d09c3..7826e794ad9 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -596,7 +596,7 @@ handle_image (void *data, grub_efi_uint32_t datasize) + grub_dprintf ("chain", "reloc_base: %p reloc_base_end: %p\n", + reloc_base, reloc_base_end); + +- struct grub_pe32_section_table *reloc_section = NULL; ++ 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++) +@@ -645,12 +645,28 @@ handle_image (void *data, grub_efi_uint32_t datasize) + * 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 && reloc_base_end == end) ++ base && end && reloc_base == base) + { +- grub_dprintf ("chain", " section is relocation section\n"); +- reloc_section = section; ++ 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; ++ } + } +- else ++ ++ if (!reloc_section) + { + grub_dprintf ("chain", " section is not reloc section?\n"); + grub_dprintf ("chain", " rds: 0x%08x, vs: %08x\n", diff --git a/0256-Make-exit-take-a-return-code.patch b/0256-Make-exit-take-a-return-code.patch deleted file mode 100644 index b886e12..0000000 --- a/0256-Make-exit-take-a-return-code.patch +++ /dev/null @@ -1,53 +0,0 @@ -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/kern/emu/main.c | 6 ++++++ - grub-core/kern/misc.c | 9 +++++++++ - 2 files changed, 15 insertions(+) - -diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 55ea5a11ccd..7e47ec81263 100644 ---- a/grub-core/kern/emu/main.c -+++ b/grub-core/kern/emu/main.c -@@ -72,6 +72,12 @@ grub_exit (int retval __attribute__((unused))) - grub_reboot (); - } - -+void -+grub_exit (int retval __attribute__((unused))) -+{ -+ grub_reboot (); -+} -+ - void - grub_machine_init (void) - { -diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c -index 5ce89a40c68..04371ac49f2 100644 ---- a/grub-core/kern/misc.c -+++ b/grub-core/kern/misc.c -@@ -1120,6 +1120,15 @@ grub_abort (void) - 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/0256-linuxefi-minor-cleanups.patch b/0256-linuxefi-minor-cleanups.patch new file mode 100644 index 0000000..057c746 --- /dev/null +++ b/0256-linuxefi-minor-cleanups.patch @@ -0,0 +1,86 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Feb 2017 16:31:52 -0500 +Subject: [PATCH] linuxefi: minor cleanups + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 30 ++++++++++++++++++++---------- + 1 file changed, 20 insertions(+), 10 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 010bf982d80..8b5a817b9d1 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -61,13 +61,18 @@ grub_linuxefi_unload (void) + grub_dl_unref (my_mod); + loaded = 0; + if (initrd_mem) +- grub_efi_free_pages((grub_efi_physical_address_t)initrd_mem, BYTES_TO_PAGES(params->ramdisk_size)); ++ 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)linux_cmdline, BYTES_TO_PAGES(params->cmdline_size + 1)); ++ 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)kernel_mem, BYTES_TO_PAGES(kernel_size)); ++ 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)params, BYTES_TO_PAGES(16384)); ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, ++ BYTES_TO_PAGES(16384)); + return GRUB_ERR_NONE; + } + +@@ -115,7 +120,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + } + + params->ramdisk_size = size; +- params->ramdisk_image = (grub_uint32_t)(grub_uint64_t) initrd_mem; ++ params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; + + ptr = initrd_mem; + +@@ -142,7 +147,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + grub_free (files); + + if (initrd_mem && grub_errno) +- grub_efi_free_pages((grub_efi_physical_address_t)initrd_mem, BYTES_TO_PAGES(size)); ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, ++ BYTES_TO_PAGES(size)); + + return grub_errno; + } +@@ -244,7 +250,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + linux_cmdline + sizeof (LINUX_IMAGE) - 1, + lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1)); + +- lh.cmd_line_ptr = (grub_uint32_t)(grub_uint64_t)linux_cmdline; ++ lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; + + handover_offset = lh.handover_offset; + +@@ -288,13 +294,17 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + if (linux_cmdline && !loaded) +- grub_efi_free_pages((grub_efi_physical_address_t)linux_cmdline, BYTES_TO_PAGES(lh.cmdline_size + 1)); ++ 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)kernel_mem, BYTES_TO_PAGES(kernel_size)); ++ 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)params, BYTES_TO_PAGES(16384)); ++ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params, ++ BYTES_TO_PAGES(16384)); + + return grub_errno; + } diff --git a/0257-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch b/0257-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch new file mode 100644 index 0000000..fe3a046 --- /dev/null +++ b/0257-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch @@ -0,0 +1,273 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 14 Feb 2017 16:18:54 -0500 +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, 93 insertions(+), 33 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 8890bdf059a..2a7024134da 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -56,12 +56,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 8b5a817b9d1..bed5919cab3 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); + } + +@@ -119,6 +115,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_dprintf ("linuxefi", "initrd_mem = %lx\n", (unsigned long) initrd_mem); ++ + params->ramdisk_size = size; + params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem; + +@@ -153,14 +151,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_kernel_header lh; ++ struct linux_kernel_header *lh; + grub_ssize_t len, start, filelen; + void *kernel = NULL; ++ int setup_header_end_offset; + int rc; + + grub_dl_ref (my_mod); +@@ -200,69 +204,107 @@ 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_memset (params, 0, 16384); ++ grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params); + +- grub_memcpy (&lh, kernel, sizeof (lh)); ++ grub_memset (params, 0, sizeof(*params)); + +- if (lh.boot_flag != grub_cpu_to_le16 (0xaa55)) ++ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); ++ grub_dprintf ("linuxefi", "copying %d bytes from %p to %p\n", ++ MIN(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(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); ++ lh = (struct linux_kernel_header *)params; ++ grub_dprintf ("linuxefi", "lh is at %p\n", lh); ++ grub_dprintf ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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 ("linuxefi", "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")); + goto fail; + } + ++ grub_dprintf ("linuxefi", "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, +- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1)); ++ lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1)); + +- lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline; ++ grub_dprintf ("linuxefi", "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 ("linuxefi", "computing handover offset\n"); ++ handover_offset = lh->handover_offset; + +- start = (lh.setup_sects + 1) * 512; ++ start = (lh->setup_sects + 1) * 512; + len = grub_file_size(file) - start; + +- kernel_mem = grub_efi_allocate_pages(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) + { +@@ -270,17 +312,25 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_memcpy (kernel_mem, (char *)kernel + start, len); ++ grub_dprintf ("linuxefi", "kernel_mem = %lx\n", (unsigned long) kernel_mem); ++ + grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0); + loaded=1; ++ grub_dprintf ("linuxefi", "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 ("linuxefi", "setting lh->type_of_loader\n"); ++ lh->type_of_loader = 0x6; ++ ++ grub_dprintf ("linuxefi", "setting lh->ext_loader_{type,ver}\n"); ++ params->ext_loader_type = 0; ++ params->ext_loader_ver = 2; ++ grub_dprintf("linuxefi", "kernel_mem: %p handover_offset: %08x\n", ++ kernel_mem, handover_offset); + + fail: +- + if (file) + grub_file_close (file); + +@@ -296,7 +346,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + 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)); ++ 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 5d8282a7db6..2cfb364b85d 100644 +--- a/include/grub/i386/linux.h ++++ b/include/grub/i386/linux.h +@@ -130,7 +130,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/0257-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch b/0257-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch deleted file mode 100644 index 8544930..0000000 --- a/0257-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch +++ /dev/null @@ -1,42 +0,0 @@ -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 fcab2ed37e7..84670a053b2 100644 ---- a/grub-core/loader/arm64/linux.c -+++ b/grub-core/loader/arm64/linux.c -@@ -80,7 +80,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/0258-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch b/0258-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch deleted file mode 100644 index 3e3b406..0000000 --- a/0258-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 9 May 2016 14:15:17 -0400 -Subject: [PATCH] Add some grub_dprintf() in the secure boot verify code. - -Signed-off-by: Peter Jones ---- - grub-core/loader/efi/linux.c | 16 +++++++++++++--- - 1 file changed, 13 insertions(+), 3 deletions(-) - -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index 2a7024134da..7fe7201a388 100644 ---- a/grub-core/loader/efi/linux.c -+++ b/grub-core/loader/efi/linux.c -@@ -43,12 +43,22 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) - shim_lock = grub_efi_locate_protocol(&guid, NULL); - grub_dprintf ("secureboot", "shim_lock: %p\n", shim_lock); - if (!shim_lock) -- return 0; -+ { -+ grub_dprintf ("secureboot", "shim not available\n"); -+ return 0; -+ } - -- status = shim_lock->verify(data, size); -+ grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); -+ status = shim_lock->verify (data, size); - grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); - if (status == GRUB_EFI_SUCCESS) -- return 1; -+ { -+ grub_dprintf ("secureboot", "Kernel signature verification passed\n"); -+ return 1; -+ } -+ -+ grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", -+ (unsigned long) status); - - return -1; - } diff --git a/0258-Fix-up-linux-params-usage.patch b/0258-Fix-up-linux-params-usage.patch new file mode 100644 index 0000000..3e089a9 --- /dev/null +++ b/0258-Fix-up-linux-params-usage.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 30 May 2017 14:16:07 -0400 +Subject: [PATCH] Fix up linux params usage... + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 4 ++-- + grub-core/loader/i386/linux.c | 5 ++++- + 2 files changed, 6 insertions(+), 3 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index bed5919cab3..6ff796f56ff 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -161,7 +161,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) + { + grub_file_t file = 0; +- struct linux_kernel_header *lh; ++ struct linux_i386_kernel_header *lh; + grub_ssize_t len, start, filelen; + void *kernel = NULL; + int setup_header_end_offset; +@@ -224,7 +224,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + grub_memcpy ((grub_uint8_t *)params + 0x1f1, + (grub_uint8_t *)kernel + 0x1f1, + MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); +- lh = (struct linux_kernel_header *)params; ++ lh = (struct linux_i386_kernel_header *)params; + grub_dprintf ("linuxefi", "lh is at %p\n", lh); + grub_dprintf ("linuxefi", "checking lh->boot_flag\n"); + if (lh->boot_flag != grub_cpu_to_le16 (0xaa55)) +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 626ec9fef0c..35055431247 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -680,6 +680,7 @@ 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, kernel_offset; + grub_ssize_t len; +@@ -811,6 +812,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); + +@@ -820,7 +822,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + len = sizeof (linux_params) - sizeof (lh); + +- grub_memcpy (&linux_params + sizeof (lh), kernel + kernel_offset, len); ++ 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; diff --git a/0259-Make-exit-take-a-return-code.patch b/0259-Make-exit-take-a-return-code.patch new file mode 100644 index 0000000..b886e12 --- /dev/null +++ b/0259-Make-exit-take-a-return-code.patch @@ -0,0 +1,53 @@ +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/kern/emu/main.c | 6 ++++++ + grub-core/kern/misc.c | 9 +++++++++ + 2 files changed, 15 insertions(+) + +diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c +index 55ea5a11ccd..7e47ec81263 100644 +--- a/grub-core/kern/emu/main.c ++++ b/grub-core/kern/emu/main.c +@@ -72,6 +72,12 @@ grub_exit (int retval __attribute__((unused))) + grub_reboot (); + } + ++void ++grub_exit (int retval __attribute__((unused))) ++{ ++ grub_reboot (); ++} ++ + void + grub_machine_init (void) + { +diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c +index 5ce89a40c68..04371ac49f2 100644 +--- a/grub-core/kern/misc.c ++++ b/grub-core/kern/misc.c +@@ -1120,6 +1120,15 @@ grub_abort (void) + 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/0259-Make-our-info-pages-say-grub2-where-appropriate.patch b/0259-Make-our-info-pages-say-grub2-where-appropriate.patch deleted file mode 100644 index 800f7f1..0000000 --- a/0259-Make-our-info-pages-say-grub2-where-appropriate.patch +++ /dev/null @@ -1,1013 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 6 May 2016 18:43:08 -0400 -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 a9f4de6318c..3ce827ab726 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 a7155c22ffe..2b7b7faf847 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}). - - -@@ -4396,7 +4396,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 - - -@@ -4791,7 +4791,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 - -@@ -5614,8 +5614,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, -@@ -5659,7 +5659,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} -@@ -5684,15 +5684,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 -@@ -5712,8 +5712,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 -@@ -5735,7 +5735,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. - -@@ -6092,10 +6092,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 -@@ -6121,8 +6121,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 -@@ -6134,7 +6134,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. - -@@ -6154,21 +6154,21 @@ support has not yet been added to GRUB. - @end itemize - - --@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 -@@ -6184,13 +6184,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 -@@ -6198,16 +6198,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 -@@ -6220,17 +6220,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 -@@ -6246,17 +6246,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} -@@ -6274,23 +6274,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 -@@ -6301,17 +6301,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 -@@ -6326,7 +6326,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 -@@ -6354,15 +6354,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: -@@ -6394,13 +6394,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: - -@@ -6422,13 +6422,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 -@@ -6446,10 +6446,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 -@@ -6457,7 +6457,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 -@@ -6470,16 +6470,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} -@@ -6532,19 +6532,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/0260-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch b/0260-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch new file mode 100644 index 0000000..8544930 --- /dev/null +++ b/0260-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 fcab2ed37e7..84670a053b2 100644 +--- a/grub-core/loader/arm64/linux.c ++++ b/grub-core/loader/arm64/linux.c +@@ -80,7 +80,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/0260-print-more-debug-info-in-our-module-loader.patch b/0260-print-more-debug-info-in-our-module-loader.patch deleted file mode 100644 index bf2c42f..0000000 --- a/0260-print-more-debug-info-in-our-module-loader.patch +++ /dev/null @@ -1,41 +0,0 @@ -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 e339f264b3a..562d6887e0e 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/0261-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch b/0261-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch new file mode 100644 index 0000000..3e3b406 --- /dev/null +++ b/0261-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 9 May 2016 14:15:17 -0400 +Subject: [PATCH] Add some grub_dprintf() in the secure boot verify code. + +Signed-off-by: Peter Jones +--- + grub-core/loader/efi/linux.c | 16 +++++++++++++--- + 1 file changed, 13 insertions(+), 3 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 2a7024134da..7fe7201a388 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -43,12 +43,22 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) + shim_lock = grub_efi_locate_protocol(&guid, NULL); + grub_dprintf ("secureboot", "shim_lock: %p\n", shim_lock); + if (!shim_lock) +- return 0; ++ { ++ grub_dprintf ("secureboot", "shim not available\n"); ++ return 0; ++ } + +- status = shim_lock->verify(data, size); ++ grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); ++ status = shim_lock->verify (data, size); + grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); + if (status == GRUB_EFI_SUCCESS) +- return 1; ++ { ++ grub_dprintf ("secureboot", "Kernel signature verification passed\n"); ++ return 1; ++ } ++ ++ grub_dprintf ("secureboot", "Kernel signature verification failed (0x%lx)\n", ++ (unsigned long) status); + + return -1; + } diff --git a/0261-macos-just-build-chainloader-entries-don-t-try-any-x.patch b/0261-macos-just-build-chainloader-entries-don-t-try-any-x.patch deleted file mode 100644 index 1038a93..0000000 --- a/0261-macos-just-build-chainloader-entries-don-t-try-any-x.patch +++ /dev/null @@ -1,124 +0,0 @@ -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 e40274fc0f4..d979de1982a 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 - } -@@ -307,11 +264,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/0262-Make-our-info-pages-say-grub2-where-appropriate.patch b/0262-Make-our-info-pages-say-grub2-where-appropriate.patch new file mode 100644 index 0000000..800f7f1 --- /dev/null +++ b/0262-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: Fri, 6 May 2016 18:43:08 -0400 +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 a9f4de6318c..3ce827ab726 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 a7155c22ffe..2b7b7faf847 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}). + + +@@ -4396,7 +4396,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 + + +@@ -4791,7 +4791,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 + +@@ -5614,8 +5614,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, +@@ -5659,7 +5659,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} +@@ -5684,15 +5684,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 +@@ -5712,8 +5712,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 +@@ -5735,7 +5735,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. + +@@ -6092,10 +6092,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 +@@ -6121,8 +6121,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 +@@ -6134,7 +6134,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. + +@@ -6154,21 +6154,21 @@ support has not yet been added to GRUB. + @end itemize + + +-@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 +@@ -6184,13 +6184,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 +@@ -6198,16 +6198,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 +@@ -6220,17 +6220,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 +@@ -6246,17 +6246,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} +@@ -6274,23 +6274,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 +@@ -6301,17 +6301,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 +@@ -6326,7 +6326,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 +@@ -6354,15 +6354,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: +@@ -6394,13 +6394,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: + +@@ -6422,13 +6422,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 +@@ -6446,10 +6446,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 +@@ -6457,7 +6457,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 +@@ -6470,16 +6470,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} +@@ -6532,19 +6532,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/0262-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch b/0262-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch deleted file mode 100644 index eafb894..0000000 --- a/0262-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch +++ /dev/null @@ -1,703 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Jeff Mahoney -Date: Wed, 18 Dec 2013 09:57:04 +0000 -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 be195448dbe..51ed63d429b 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -29,6 +29,9 @@ - #include - #include - #include -+#include -+#include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -64,9 +67,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]; -@@ -105,6 +110,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 -@@ -171,6 +177,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; -@@ -215,6 +229,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 - }; -@@ -837,6 +859,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) - { -@@ -872,6 +950,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; - } - -@@ -1232,6 +1317,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, -@@ -1250,14 +1420,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] == '/') -@@ -1430,9 +1612,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; - } -@@ -1673,18 +1867,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]), -@@ -1693,6 +1879,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); - -@@ -1749,6 +1949,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", - .dir = grub_btrfs_dir, -@@ -1764,12 +2200,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/0263-export-btrfs_subvol-and-btrfs_subvolid.patch b/0263-export-btrfs_subvol-and-btrfs_subvolid.patch deleted file mode 100644 index a0989e8..0000000 --- a/0263-export-btrfs_subvol-and-btrfs_subvolid.patch +++ /dev/null @@ -1,26 +0,0 @@ -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 51ed63d429b..88d727d161f 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -2273,6 +2273,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/0263-print-more-debug-info-in-our-module-loader.patch b/0263-print-more-debug-info-in-our-module-loader.patch new file mode 100644 index 0000000..bf2c42f --- /dev/null +++ b/0263-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 e339f264b3a..562d6887e0e 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/0264-grub2-btrfs-03-follow_default.patch b/0264-grub2-btrfs-03-follow_default.patch deleted file mode 100644 index 26e91f1..0000000 --- a/0264-grub2-btrfs-03-follow_default.patch +++ /dev/null @@ -1,196 +0,0 @@ -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 88d727d161f..a47d297567f 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -920,6 +920,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) - { -@@ -950,11 +951,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; -@@ -1414,24 +1418,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 - { -@@ -1442,15 +1461,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) - { -@@ -1461,7 +1488,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] == '.') -@@ -1492,8 +1521,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; - } - -@@ -1562,7 +1592,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; -@@ -1612,14 +1644,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 - { -@@ -2275,6 +2319,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/0264-macos-just-build-chainloader-entries-don-t-try-any-x.patch b/0264-macos-just-build-chainloader-entries-don-t-try-any-x.patch new file mode 100644 index 0000000..1038a93 --- /dev/null +++ b/0264-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 e40274fc0f4..d979de1982a 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 + } +@@ -307,11 +264,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/0265-grub2-btrfs-04-grub2-install.patch b/0265-grub2-btrfs-04-grub2-install.patch deleted file mode 100644 index af81616..0000000 --- a/0265-grub2-btrfs-04-grub2-install.patch +++ /dev/null @@ -1,174 +0,0 @@ -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 78d0138cb0a..4375c161955 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -816,6 +816,8 @@ fill_core_services (const char *core_services) - free (sysv_plist); - } - -+extern int use_relative_path_on_btrfs; -+ - int - main (int argc, char *argv[]) - { -@@ -849,6 +851,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; -@@ -1321,6 +1326,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/0265-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch b/0265-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch new file mode 100644 index 0000000..eafb894 --- /dev/null +++ b/0265-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: Wed, 18 Dec 2013 09:57:04 +0000 +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 be195448dbe..51ed63d429b 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -29,6 +29,9 @@ + #include + #include + #include ++#include ++#include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -64,9 +67,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]; +@@ -105,6 +110,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 +@@ -171,6 +177,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; +@@ -215,6 +229,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 + }; +@@ -837,6 +859,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) + { +@@ -872,6 +950,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; + } + +@@ -1232,6 +1317,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, +@@ -1250,14 +1420,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] == '/') +@@ -1430,9 +1612,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; + } +@@ -1673,18 +1867,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]), +@@ -1693,6 +1879,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); + +@@ -1749,6 +1949,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", + .dir = grub_btrfs_dir, +@@ -1764,12 +2200,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/0266-export-btrfs_subvol-and-btrfs_subvolid.patch b/0266-export-btrfs_subvol-and-btrfs_subvolid.patch new file mode 100644 index 0000000..a0989e8 --- /dev/null +++ b/0266-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 51ed63d429b..88d727d161f 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2273,6 +2273,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/0266-grub2-btrfs-05-grub2-mkconfig.patch b/0266-grub2-btrfs-05-grub2-mkconfig.patch deleted file mode 100644 index 699bc93..0000000 --- a/0266-grub2-btrfs-05-grub2-mkconfig.patch +++ /dev/null @@ -1,127 +0,0 @@ -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 - ---- - util/grub-mkconfig.in | 3 ++- - util/grub-mkconfig_lib.in | 4 ++++ - util/grub.d/00_header.in | 24 +++++++++++++++++++++++- - util/grub.d/10_linux.in | 4 ++++ - util/grub.d/20_linux_xen.in | 4 ++++ - 5 files changed, 37 insertions(+), 2 deletions(-) - -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 8218f3d477f..4248b9341ab 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..e2a53300126 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 972a4b5a03d..bcdc3ceac02 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/0267-grub2-btrfs-03-follow_default.patch b/0267-grub2-btrfs-03-follow_default.patch new file mode 100644 index 0000000..26e91f1 --- /dev/null +++ b/0267-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 88d727d161f..a47d297567f 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -920,6 +920,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) + { +@@ -950,11 +951,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; +@@ -1414,24 +1418,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 + { +@@ -1442,15 +1461,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) + { +@@ -1461,7 +1488,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] == '.') +@@ -1492,8 +1521,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; + } + +@@ -1562,7 +1592,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; +@@ -1612,14 +1644,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 + { +@@ -2275,6 +2319,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/0267-grub2-btrfs-06-subvol-mount.patch b/0267-grub2-btrfs-06-subvol-mount.patch deleted file mode 100644 index 493f133..0000000 --- a/0267-grub2-btrfs-06-subvol-mount.patch +++ /dev/null @@ -1,537 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Fri, 22 May 2015 11:45:25 +0000 -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 a47d297567f..2e36ac47e8a 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -32,6 +32,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -245,6 +246,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) -@@ -887,9 +894,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); - -@@ -1758,11 +1782,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); -@@ -1864,11 +1897,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); -@@ -2039,6 +2082,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, -@@ -2245,6 +2432,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 * -@@ -2308,6 +2496,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 4375c161955..a0ad99729fd 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -1535,6 +1535,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/0268-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch b/0268-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch deleted file mode 100644 index b51b025..0000000 --- a/0268-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Dusty Mabe -Date: Sat, 18 Jul 2015 15:38:08 +0000 -Subject: [PATCH] No more "Bootable Snapshot" submenu in grub.cfg. - -This breaks grubby (run on kernel upgrades) because grubby just -does a search for "menuentry". ---- - util/grub.d/00_header.in | 12 ------------ - 1 file changed, 12 deletions(-) - -diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in -index e2a53300126..8a16fea347e 100644 ---- a/util/grub.d/00_header.in -+++ b/util/grub.d/00_header.in -@@ -366,15 +366,3 @@ fi - if [ "x${GRUB_BADRAM}" != "x" ] ; then - echo "badram ${GRUB_BADRAM}" - fi -- --if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] && -- [ "x${GRUB_FS}" = "xbtrfs" ] ; then -- # Note: No $snapshot_num on *read-only* rollback! (bsc#901487) -- cat < +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 78d0138cb0a..4375c161955 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -816,6 +816,8 @@ fill_core_services (const char *core_services) + free (sysv_plist); + } + ++extern int use_relative_path_on_btrfs; ++ + int + main (int argc, char *argv[]) + { +@@ -849,6 +851,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; +@@ -1321,6 +1326,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/0269-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch b/0269-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch deleted file mode 100644 index a413446..0000000 --- a/0269-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch +++ /dev/null @@ -1,58 +0,0 @@ -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 2e36ac47e8a..4a31d39ee74 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -924,11 +924,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/0269-grub2-btrfs-05-grub2-mkconfig.patch b/0269-grub2-btrfs-05-grub2-mkconfig.patch new file mode 100644 index 0000000..699bc93 --- /dev/null +++ b/0269-grub2-btrfs-05-grub2-mkconfig.patch @@ -0,0 +1,127 @@ +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 + +--- + util/grub-mkconfig.in | 3 ++- + util/grub-mkconfig_lib.in | 4 ++++ + util/grub.d/00_header.in | 24 +++++++++++++++++++++++- + util/grub.d/10_linux.in | 4 ++++ + util/grub.d/20_linux_xen.in | 4 ++++ + 5 files changed, 37 insertions(+), 2 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 8218f3d477f..4248b9341ab 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..e2a53300126 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 972a4b5a03d..bcdc3ceac02 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/0270-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch b/0270-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch deleted file mode 100644 index 0f4ce50..0000000 --- a/0270-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch +++ /dev/null @@ -1,272 +0,0 @@ -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 4a31d39ee74..7002ad81b7e 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -2446,6 +2446,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", - .dir = grub_btrfs_dir, -@@ -2464,6 +2696,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)), -@@ -2534,6 +2767,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/0270-grub2-btrfs-06-subvol-mount.patch b/0270-grub2-btrfs-06-subvol-mount.patch new file mode 100644 index 0000000..493f133 --- /dev/null +++ b/0270-grub2-btrfs-06-subvol-mount.patch @@ -0,0 +1,537 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Fri, 22 May 2015 11:45:25 +0000 +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 a47d297567f..2e36ac47e8a 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -245,6 +246,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) +@@ -887,9 +894,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); + +@@ -1758,11 +1782,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); +@@ -1864,11 +1897,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); +@@ -2039,6 +2082,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, +@@ -2245,6 +2432,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 * +@@ -2308,6 +2496,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 4375c161955..a0ad99729fd 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -1535,6 +1535,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/0271-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch b/0271-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch deleted file mode 100644 index dee5805..0000000 --- a/0271-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch +++ /dev/null @@ -1,72 +0,0 @@ -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 3efbafbb418..1f31e09b78a 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); -@@ -59,6 +63,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); -@@ -104,10 +135,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/0271-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch b/0271-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch new file mode 100644 index 0000000..b51b025 --- /dev/null +++ b/0271-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dusty Mabe +Date: Sat, 18 Jul 2015 15:38:08 +0000 +Subject: [PATCH] No more "Bootable Snapshot" submenu in grub.cfg. + +This breaks grubby (run on kernel upgrades) because grubby just +does a search for "menuentry". +--- + util/grub.d/00_header.in | 12 ------------ + 1 file changed, 12 deletions(-) + +diff --git a/util/grub.d/00_header.in b/util/grub.d/00_header.in +index e2a53300126..8a16fea347e 100644 +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -366,15 +366,3 @@ fi + if [ "x${GRUB_BADRAM}" != "x" ] ; then + echo "badram ${GRUB_BADRAM}" + fi +- +-if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] && +- [ "x${GRUB_FS}" = "xbtrfs" ] ; then +- # Note: No $snapshot_num on *read-only* rollback! (bsc#901487) +- cat < +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 2e36ac47e8a..4a31d39ee74 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -924,11 +924,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/0272-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0272-Use-grub_efi_.-memory-helpers-where-reasonable.patch deleted file mode 100644 index 415cf92..0000000 --- a/0272-Use-grub_efi_.-memory-helpers-where-reasonable.patch +++ /dev/null @@ -1,106 +0,0 @@ -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 7826e794ad9..d2557b38dce 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 (); - -@@ -500,10 +500,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; -@@ -514,8 +513,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) - { -@@ -555,8 +552,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) - { -@@ -788,14 +785,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; - } -@@ -803,10 +800,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; -@@ -1073,7 +1067,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/0273-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0273-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch deleted file mode 100644 index 9bb4665..0000000 --- a/0273-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch +++ /dev/null @@ -1,46 +0,0 @@ -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 d2557b38dce..2c62faa2943 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -783,7 +783,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 02488ec35ae..ddc5ecfb03d 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/0273-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch b/0273-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch new file mode 100644 index 0000000..0f4ce50 --- /dev/null +++ b/0273-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 4a31d39ee74..7002ad81b7e 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -2446,6 +2446,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", + .dir = grub_btrfs_dir, +@@ -2464,6 +2696,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)), +@@ -2534,6 +2767,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/0274-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch b/0274-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch new file mode 100644 index 0000000..dee5805 --- /dev/null +++ b/0274-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 3efbafbb418..1f31e09b78a 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); +@@ -59,6 +63,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); +@@ -104,10 +135,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/0274-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch b/0274-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch deleted file mode 100644 index 882cf5d..0000000 --- a/0274-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch +++ /dev/null @@ -1,43 +0,0 @@ -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 4be228d9576..fa3e2912643 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/0275-Use-grub_efi_.-memory-helpers-where-reasonable.patch b/0275-Use-grub_efi_.-memory-helpers-where-reasonable.patch new file mode 100644 index 0000000..415cf92 --- /dev/null +++ b/0275-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 7826e794ad9..d2557b38dce 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 (); + +@@ -500,10 +500,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; +@@ -514,8 +513,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) + { +@@ -555,8 +552,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) + { +@@ -788,14 +785,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; + } +@@ -803,10 +800,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; +@@ -1073,7 +1067,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/0275-don-t-ignore-const.patch b/0275-don-t-ignore-const.patch deleted file mode 100644 index 6b4d390..0000000 --- a/0275-don-t-ignore-const.patch +++ /dev/null @@ -1,22 +0,0 @@ -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 dcd82494309..f90071353ad 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/0276-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch b/0276-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch new file mode 100644 index 0000000..9bb4665 --- /dev/null +++ b/0276-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 d2557b38dce..2c62faa2943 100644 +--- a/grub-core/loader/efi/chainloader.c ++++ b/grub-core/loader/efi/chainloader.c +@@ -783,7 +783,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 02488ec35ae..ddc5ecfb03d 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/0276-don-t-use-int-for-efi-status.patch b/0276-don-t-use-int-for-efi-status.patch deleted file mode 100644 index 6328df9..0000000 --- a/0276-don-t-use-int-for-efi-status.patch +++ /dev/null @@ -1,22 +0,0 @@ -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 562d6887e0e..bcae7f4699d 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/0277-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch b/0277-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch new file mode 100644 index 0000000..882cf5d --- /dev/null +++ b/0277-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 4be228d9576..fa3e2912643 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/0277-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch b/0277-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch deleted file mode 100644 index 1d6f4c4..0000000 --- a/0277-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch +++ /dev/null @@ -1,29 +0,0 @@ -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 2bca56ce0e8..b1ed3c33317 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/0278-Clean-up-some-errors-in-the-linuxefi-loader.patch b/0278-Clean-up-some-errors-in-the-linuxefi-loader.patch deleted file mode 100644 index b8e3677..0000000 --- a/0278-Clean-up-some-errors-in-the-linuxefi-loader.patch +++ /dev/null @@ -1,66 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 24 May 2017 15:58:18 -0400 -Subject: [PATCH] Clean up some errors in the linuxefi loader - -Signed-off-by: Peter Jones ---- - grub-core/loader/i386/efi/linux.c | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 6ff796f56ff..cb9631c95e1 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -161,8 +161,8 @@ 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; -@@ -212,18 +212,19 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params); -+ grub_dprintf ("linuxefi", "params = %p\n", params); - - grub_memset (params, 0, sizeof(*params)); - - setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); -- grub_dprintf ("linuxefi", "copying %d bytes from %p to %p\n", -- MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1, -+ grub_dprintf ("linuxefi", "copying %zu 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(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); -+ MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); - lh = (struct linux_i386_kernel_header *)params; - grub_dprintf ("linuxefi", "lh is at %p\n", lh); - grub_dprintf ("linuxefi", "checking lh->boot_flag\n"); -@@ -297,7 +298,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - 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)); -@@ -343,7 +343,7 @@ 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)); diff --git a/0278-don-t-ignore-const.patch b/0278-don-t-ignore-const.patch new file mode 100644 index 0000000..6b4d390 --- /dev/null +++ b/0278-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 dcd82494309..f90071353ad 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/0279-don-t-use-int-for-efi-status.patch b/0279-don-t-use-int-for-efi-status.patch new file mode 100644 index 0000000..6328df9 --- /dev/null +++ b/0279-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 562d6887e0e..bcae7f4699d 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/0279-editenv-handle-relative-symlinks.patch b/0279-editenv-handle-relative-symlinks.patch deleted file mode 100644 index 20e1686..0000000 --- a/0279-editenv-handle-relative-symlinks.patch +++ /dev/null @@ -1,50 +0,0 @@ -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 d8d1dad6ab9..41bc7cb1c9a 100644 ---- a/util/editenv.c -+++ b/util/editenv.c -@@ -28,6 +28,7 @@ - - #include - #include -+#include - - #define DEFAULT_ENVBLK_SIZE 1024 - -@@ -87,9 +88,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/0280-Make-libgrub.pp-depend-on-config-util.h.patch b/0280-Make-libgrub.pp-depend-on-config-util.h.patch deleted file mode 100644 index dc24fb1..0000000 --- a/0280-Make-libgrub.pp-depend-on-config-util.h.patch +++ /dev/null @@ -1,45 +0,0 @@ -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 7795baeb654..c7b0e6a9c46 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/0280-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch b/0280-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch new file mode 100644 index 0000000..1d6f4c4 --- /dev/null +++ b/0280-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 2bca56ce0e8..b1ed3c33317 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/0281-Clean-up-some-errors-in-the-linuxefi-loader.patch b/0281-Clean-up-some-errors-in-the-linuxefi-loader.patch new file mode 100644 index 0000000..b8e3677 --- /dev/null +++ b/0281-Clean-up-some-errors-in-the-linuxefi-loader.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 24 May 2017 15:58:18 -0400 +Subject: [PATCH] Clean up some errors in the linuxefi loader + +Signed-off-by: Peter Jones +--- + grub-core/loader/i386/efi/linux.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 6ff796f56ff..cb9631c95e1 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -161,8 +161,8 @@ 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; +@@ -212,18 +212,19 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_dprintf ("linuxefi", "params = %p\n", (unsigned long) params); ++ grub_dprintf ("linuxefi", "params = %p\n", params); + + grub_memset (params, 0, sizeof(*params)); + + setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201); +- grub_dprintf ("linuxefi", "copying %d bytes from %p to %p\n", +- MIN(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1, ++ grub_dprintf ("linuxefi", "copying %zu 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(0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); ++ MIN((grub_size_t)0x202+setup_header_end_offset,sizeof (*params)) - 0x1f1); + lh = (struct linux_i386_kernel_header *)params; + grub_dprintf ("linuxefi", "lh is at %p\n", lh); + grub_dprintf ("linuxefi", "checking lh->boot_flag\n"); +@@ -297,7 +298,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + 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)); +@@ -343,7 +343,7 @@ 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)); diff --git a/0281-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch b/0281-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch deleted file mode 100644 index 51f5458..0000000 --- a/0281-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch +++ /dev/null @@ -1,41 +0,0 @@ -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 a0ad99729fd..16f137ca854 100644 ---- a/util/grub-install.c -+++ b/util/grub-install.c -@@ -1159,18 +1159,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/0282-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch b/0282-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch deleted file mode 100644 index c26a3d5..0000000 --- a/0282-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 19 Oct 2017 11:29:11 -0400 -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 bcdc3ceac02..2bc03fd36b9 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} -@@ -145,6 +147,7 @@ EOF - message="$(gettext_printf "Loading initial ramdisk ...")" - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' -+ insmod ${module_loader} - ${module_loader} --nounzip ${rel_dirname}/${initrd} - EOF - fi diff --git a/0282-editenv-handle-relative-symlinks.patch b/0282-editenv-handle-relative-symlinks.patch new file mode 100644 index 0000000..20e1686 --- /dev/null +++ b/0282-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 d8d1dad6ab9..41bc7cb1c9a 100644 +--- a/util/editenv.c ++++ b/util/editenv.c +@@ -28,6 +28,7 @@ + + #include + #include ++#include + + #define DEFAULT_ENVBLK_SIZE 1024 + +@@ -87,9 +88,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/0283-Make-libgrub.pp-depend-on-config-util.h.patch b/0283-Make-libgrub.pp-depend-on-config-util.h.patch new file mode 100644 index 0000000..dc24fb1 --- /dev/null +++ b/0283-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 7795baeb654..c7b0e6a9c46 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/0283-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch b/0283-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch deleted file mode 100644 index acfb116..0000000 --- a/0283-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch +++ /dev/null @@ -1,211 +0,0 @@ -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/0284-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch b/0284-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch new file mode 100644 index 0000000..51f5458 --- /dev/null +++ b/0284-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 a0ad99729fd..16f137ca854 100644 +--- a/util/grub-install.c ++++ b/util/grub-install.c +@@ -1159,18 +1159,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/0284-align-struct-efi_variable-better.patch b/0284-align-struct-efi_variable-better.patch deleted file mode 100644 index 65bc91b..0000000 --- a/0284-align-struct-efi_variable-better.patch +++ /dev/null @@ -1,33 +0,0 @@ -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 b93e4820194..f6a9723971d 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/0285-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch b/0285-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch new file mode 100644 index 0000000..c26a3d5 --- /dev/null +++ b/0285-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: Thu, 19 Oct 2017 11:29:11 -0400 +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 bcdc3ceac02..2bc03fd36b9 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} +@@ -145,6 +147,7 @@ EOF + message="$(gettext_printf "Loading initial ramdisk ...")" + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' ++ insmod ${module_loader} + ${module_loader} --nounzip ${rel_dirname}/${initrd} + EOF + fi diff --git a/0285-Add-quicksort-implementation.patch b/0285-Add-quicksort-implementation.patch deleted file mode 100644 index 06fe563..0000000 --- a/0285-Add-quicksort-implementation.patch +++ /dev/null @@ -1,322 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 9 Dec 2016 15:39:47 -0500 -Subject: [PATCH] Add quicksort implementation - -This will be used to sort the boot menu entries that are read from -the BootLoaderSpec config files. ---- - grub-core/kern/qsort.c | 279 +++++++++++++++++++++++++++++++++++++++++++++++++ - include/grub/misc.h | 15 +++ - 2 files changed, 294 insertions(+) - create mode 100644 grub-core/kern/qsort.c - -diff --git a/grub-core/kern/qsort.c b/grub-core/kern/qsort.c -new file mode 100644 -index 00000000000..7f3fc9ffdae ---- /dev/null -+++ b/grub-core/kern/qsort.c -@@ -0,0 +1,279 @@ -+/* quicksort -+ * This file from the GNU C Library. -+ * Copyright (C) 1991-2016 Free Software Foundation, Inc. -+ * Written by Douglas C. Schmidt (schmidt@ics.uci.edu). -+ * -+ * 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 . -+ */ -+ -+/* If you consider tuning this algorithm, you should consult first: -+ Engineering a sort function; Jon Bentley and M. Douglas McIlroy; -+ Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ -+ -+#include -+#include -+#include -+ -+#define CHAR_BIT 8 -+ -+/* Byte-wise swap two items of size SIZE. */ -+#define SWAP(a, b, size) \ -+ do \ -+ { \ -+ grub_size_t __size = (size); \ -+ char *__a = (a), *__b = (b); \ -+ do \ -+ { \ -+ char __tmp = *__a; \ -+ *__a++ = *__b; \ -+ *__b++ = __tmp; \ -+ } while (--__size > 0); \ -+ } while (0) -+ -+/* Discontinue quicksort algorithm when partition gets below this size. -+ This particular magic number was chosen to work best on a Sun 4/260. */ -+#define MAX_THRESH 4 -+ -+/* Stack node declarations used to store unfulfilled partition obligations. */ -+typedef struct -+ { -+ char *lo; -+ char *hi; -+ } stack_node; -+ -+/* The next 4 #defines implement a very fast in-line stack abstraction. */ -+/* The stack needs log (total_elements) entries (we could even subtract -+ log(MAX_THRESH)). Since total_elements has type grub_size_t, we get as -+ upper bound for log (total_elements): -+ bits per byte (CHAR_BIT) * sizeof(grub_size_t). */ -+#define STACK_SIZE (CHAR_BIT * sizeof(grub_size_t)) -+#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) -+#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) -+#define STACK_NOT_EMPTY (stack < top) -+ -+ -+/* Order size using quicksort. This implementation incorporates -+ four optimizations discussed in Sedgewick: -+ -+ 1. Non-recursive, using an explicit stack of pointer that store the -+ next array partition to sort. To save time, this maximum amount -+ of space required to store an array of SIZE_MAX is allocated on the -+ stack. Assuming a 32-bit (64 bit) integer for grub_size_t, this needs -+ only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). -+ Pretty cheap, actually. -+ -+ 2. Chose the pivot element using a median-of-three decision tree. -+ This reduces the probability of selecting a bad pivot value and -+ eliminates certain extraneous comparisons. -+ -+ 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving -+ insertion sort to order the MAX_THRESH items within each partition. -+ This is a big win, since insertion sort is faster for small, mostly -+ sorted array segments. -+ -+ 4. The larger of the two sub-partitions is always pushed onto the -+ stack first, with the algorithm then concentrating on the -+ smaller partition. This *guarantees* no more than log (total_elems) -+ stack size is needed (actually O(1) in this case)! */ -+ -+void -+grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size, -+ grub_compar_d_fn_t cmp, void *arg) -+{ -+ char *base_ptr = (char *) pbase; -+ -+ const grub_size_t max_thresh = MAX_THRESH * size; -+ -+ if (total_elems == 0) -+ /* Avoid lossage with unsigned arithmetic below. */ -+ return; -+ -+ if (total_elems > MAX_THRESH) -+ { -+ char *lo = base_ptr; -+ char *hi = &lo[size * (total_elems - 1)]; -+ stack_node stack[STACK_SIZE]; -+ stack_node *top = stack; -+ -+ PUSH (NULL, NULL); -+ -+ while (STACK_NOT_EMPTY) -+ { -+ char *left_ptr; -+ char *right_ptr; -+ -+ /* Select median value from among LO, MID, and HI. Rearrange -+ LO and HI so the three values are sorted. This lowers the -+ probability of picking a pathological pivot value and -+ skips a comparison for both the LEFT_PTR and RIGHT_PTR in -+ the while loops. */ -+ -+ char *mid = lo + size * ((hi - lo) / size >> 1); -+ -+ if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) -+ SWAP (mid, lo, size); -+ if ((*cmp) ((void *) hi, (void *) mid, arg) < 0) -+ SWAP (mid, hi, size); -+ else -+ goto jump_over; -+ if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) -+ SWAP (mid, lo, size); -+ jump_over:; -+ -+ left_ptr = lo + size; -+ right_ptr = hi - size; -+ -+ /* Here's the famous ``collapse the walls'' section of quicksort. -+ Gotta like those tight inner loops! They are the main reason -+ that this algorithm runs much faster than others. */ -+ do -+ { -+ while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0) -+ left_ptr += size; -+ -+ while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0) -+ right_ptr -= size; -+ -+ if (left_ptr < right_ptr) -+ { -+ SWAP (left_ptr, right_ptr, size); -+ if (mid == left_ptr) -+ mid = right_ptr; -+ else if (mid == right_ptr) -+ mid = left_ptr; -+ left_ptr += size; -+ right_ptr -= size; -+ } -+ else if (left_ptr == right_ptr) -+ { -+ left_ptr += size; -+ right_ptr -= size; -+ break; -+ } -+ } -+ while (left_ptr <= right_ptr); -+ -+ /* Set up pointers for next iteration. First determine whether -+ left and right partitions are below the threshold size. If so, -+ ignore one or both. Otherwise, push the larger partition's -+ bounds on the stack and continue sorting the smaller one. */ -+ -+ if ((grub_size_t) (right_ptr - lo) <= max_thresh) -+ { -+ if ((grub_size_t) (hi - left_ptr) <= max_thresh) -+ /* Ignore both small partitions. */ -+ POP (lo, hi); -+ else -+ /* Ignore small left partition. */ -+ lo = left_ptr; -+ } -+ else if ((grub_size_t) (hi - left_ptr) <= max_thresh) -+ /* Ignore small right partition. */ -+ hi = right_ptr; -+ else if ((right_ptr - lo) > (hi - left_ptr)) -+ { -+ /* Push larger left partition indices. */ -+ PUSH (lo, right_ptr); -+ lo = left_ptr; -+ } -+ else -+ { -+ /* Push larger right partition indices. */ -+ PUSH (left_ptr, hi); -+ hi = right_ptr; -+ } -+ } -+ } -+ -+ /* Once the BASE_PTR array is partially sorted by quicksort the rest -+ is completely sorted using insertion sort, since this is efficient -+ for partitions below MAX_THRESH size. BASE_PTR points to the beginning -+ of the array to sort, and END_PTR points at the very last element in -+ the array (*not* one beyond it!). */ -+ -+#define min(x, y) ((x) < (y) ? (x) : (y)) -+ -+ { -+ char *const end_ptr = &base_ptr[size * (total_elems - 1)]; -+ char *tmp_ptr = base_ptr; -+ char *thresh = min(end_ptr, base_ptr + max_thresh); -+ char *run_ptr; -+ -+ /* Find smallest element in first threshold and place it at the -+ array's beginning. This is the smallest array element, -+ and the operation speeds up insertion sort's inner loop. */ -+ -+ for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) -+ if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) -+ tmp_ptr = run_ptr; -+ -+ if (tmp_ptr != base_ptr) -+ SWAP (tmp_ptr, base_ptr, size); -+ -+ /* Insertion sort, running from left-hand-side up to right-hand-side. */ -+ -+ run_ptr = base_ptr + size; -+ while ((run_ptr += size) <= end_ptr) -+ { -+ tmp_ptr = run_ptr - size; -+ while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) -+ tmp_ptr -= size; -+ -+ tmp_ptr += size; -+ if (tmp_ptr != run_ptr) -+ { -+ char *trav; -+ -+ trav = run_ptr + size; -+ while (--trav >= run_ptr) -+ { -+ char c = *trav; -+ char *hi, *lo; -+ -+ for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo) -+ *hi = *lo; -+ *hi = c; -+ } -+ } -+ } -+ } -+} -+ -+void * -+grub_bsearch (const void *key, const void *base, grub_size_t nmemb, grub_size_t size, -+ grub_compar_d_fn_t compar, void *state) -+{ -+ grub_size_t l, u, idx; -+ const void *p; -+ int comparison; -+ -+ l = 0; -+ u = nmemb; -+ while (l < u) -+ { -+ idx = (l + u) / 2; -+ p = (void *) (((const char *) base) + (idx * size)); -+ comparison = (*compar) (key, p, state); -+ if (comparison < 0) -+ u = idx; -+ else if (comparison > 0) -+ l = idx + 1; -+ else -+ return (void *) p; -+ } -+ -+ return NULL; -+} -diff --git a/include/grub/misc.h b/include/grub/misc.h -index fcaf1201e39..cbfae75a1b4 100644 ---- a/include/grub/misc.h -+++ b/include/grub/misc.h -@@ -507,4 +507,19 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file, - #define grub_max(a, b) (((a) > (b)) ? (a) : (b)) - #define grub_min(a, b) (((a) < (b)) ? (a) : (b)) - -+typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state); -+ -+void *EXPORT_FUNC(grub_bsearch) (const void *key, -+ const void *base, -+ grub_size_t nmemb, -+ grub_size_t size, -+ grub_compar_d_fn_t compar, -+ void *state); -+ -+void EXPORT_FUNC(grub_qsort) (void *const pbase, -+ grub_size_t total_elems, -+ grub_size_t size, -+ grub_compar_d_fn_t cmp, -+ void *state); -+ - #endif /* ! GRUB_MISC_HEADER */ diff --git a/0286-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch b/0286-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch deleted file mode 100644 index cde929e..0000000 --- a/0286-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch +++ /dev/null @@ -1,1139 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 9 Dec 2016 15:40:58 -0500 -Subject: [PATCH] Add blscfg command support to parse BootLoaderSpec config - fragments - -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. - -GRUB2 already has a blscfg modle that can parse the config snippets using -the bls_import command, change it to blscfg and improve the BLS support. ---- - grub-core/Makefile.core.def | 4 +- - grub-core/commands/blscfg.c | 788 ++++++++++++++++++++++++++++++++++++++++--- - grub-core/commands/loadenv.c | 77 +---- - grub-core/commands/loadenv.h | 93 +++++ - include/grub/compiler.h | 2 + - 5 files changed, 832 insertions(+), 132 deletions(-) - create mode 100644 grub-core/commands/loadenv.h - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index edf249f0002..fb661b4abf8 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -129,6 +129,7 @@ kernel = { - common = kern/rescue_parser.c; - common = kern/rescue_reader.c; - common = kern/term.c; -+ common = kern/qsort.c; - - noemu = kern/compiler-rt.c; - noemu = kern/mm.c; -@@ -775,8 +776,7 @@ module = { - module = { - name = blscfg; - common = commands/blscfg.c; -- enable = i386_efi; -- enable = x86_64_efi; -+ enable = efi; - enable = i386_pc; - }; - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 4274aca5a9d..9ab45631465 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -30,32 +30,405 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -+#include "loadenv.h" -+ -+#define GRUB_BLS_CONFIG_PATH "/loader/entries/" -+#define GRUB_BOOT_DEVICE "($root)" - #ifdef GRUB_MACHINE_EFI - #define GRUB_LINUX_CMD "linuxefi" - #define GRUB_INITRD_CMD "initrdefi" --#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/" --#define GRUB_BOOT_DEVICE "($boot)" - #else - #define GRUB_LINUX_CMD "linux" - #define GRUB_INITRD_CMD "initrd" --#define GRUB_BLS_CONFIG_PATH "/loader/entries/" --#define GRUB_BOOT_DEVICE "($root)" - #endif - --static int parse_entry ( -+#define grub_free(x) ({grub_dprintf("blscfg", "%s freeing %p\n", __func__, x); grub_free(x); }) -+ -+struct keyval -+{ -+ const char *key; -+ char *val; -+}; -+ -+struct bls_entry -+{ -+ struct keyval **keyvals; -+ int nkeyvals; -+}; -+ -+static struct bls_entry **entries; -+static int nentries; -+ -+static struct bls_entry *bls_new_entry(void) -+{ -+ struct bls_entry **new_entries; -+ struct bls_entry *entry; -+ int new_n = nentries + 1; -+ -+ new_entries = grub_realloc (entries, new_n * sizeof (struct bls_entry *)); -+ if (!new_entries) -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ "couldn't find space for BLS entry list"); -+ return NULL; -+ } -+ -+ entries = new_entries; -+ -+ entry = grub_malloc (sizeof (*entry)); -+ if (!entry) -+ { -+ grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ "couldn't find space for BLS entry list"); -+ return NULL; -+ } -+ -+ grub_memset (entry, 0, sizeof (*entry)); -+ entries[nentries] = entry; -+ -+ nentries = new_n; -+ -+ return entry; -+} -+ -+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:%p:%p\n", entry->keyvals[entry->nkeyvals], k, v); -+ entry->nkeyvals = new_n; -+ -+ return 0; -+} -+ -+static void bls_free_entry(struct bls_entry *entry) -+{ -+ int i; -+ -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ for (i = 0; i < entry->nkeyvals; i++) -+ { -+ struct keyval *kv = entry->keyvals[i]; -+ grub_free ((void *)kv->key); -+ grub_free (kv->val); -+ grub_free (kv); -+ } -+ -+ grub_free (entry->keyvals); -+ grub_memset (entry, 0, sizeof (*entry)); -+ grub_free (entry); -+} -+ -+static int keyval_cmp (const void *p0, const void *p1, -+ void *state UNUSED) -+{ -+ const struct keyval *kv0 = *(struct keyval * const *)p0; -+ const struct keyval *kv1 = *(struct keyval * const *)p1; -+ int rc; -+ -+ rc = grub_strcmp(kv0->key, kv1->key); -+ -+ return rc; -+} -+ -+/* 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. */ -+static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last) -+{ -+ char *foo = (char *)""; -+ struct keyval *kv = NULL, **kvp, key = {keyname, foo}, *keyp = &key; -+ -+ /* if we've already found an entry that matches, just iterate */ -+ if (last && *last >= 0) -+ { -+ int next = ++last[0]; -+ -+ if (next == entry->nkeyvals) -+ { -+done: -+ *last = -1; -+ return NULL; -+ } -+ -+ kv = entry->keyvals[next]; -+ if (grub_strcmp (keyname, kv->key)) -+ goto done; -+ -+ return kv->val; -+ } -+ -+ kvp = grub_bsearch(&keyp, &entry->keyvals[0], entry->nkeyvals, -+ sizeof (struct keyval *), keyval_cmp, NULL); -+ if (kvp) -+ kv = *kvp; -+ -+ if (kv) -+ { -+ /* if we've got uninitialized but present state, track back until we find -+ * the first match */ -+ if (last) -+ { -+ grub_dprintf("blscfg", "%s trying to find another entry because last was set\n", __func__); -+ /* figure out the position of this entry in the array */ -+ int idx; -+ for (idx = 0 ; idx < entry->nkeyvals; idx++) -+ if (entry->keyvals[idx] == kv) -+ break; -+ *last = idx; -+ -+ while (idx > 0) -+ { -+ struct keyval *kvtmp = entry->keyvals[idx-1]; -+ if (idx == 0 || grub_strcmp (keyname, kvtmp->key)) -+ { -+ /* if we're at the start, or if the previous entry doesn't -+ * match, then we're done */ -+ *last = idx; -+ break; -+ } -+ else -+ /* but if it does match, keep going backwards */ -+ idx--; -+ } -+ } -+ -+ return kv->val; -+ } -+ return NULL; -+} -+ -+#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 got here\n", __func__); -+ 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; -+} -+ -+typedef int (*void_cmp_t)(void *, void *); -+ -+static int nulcmp(char *s0, char *s1, void_cmp_t cmp) -+{ -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ if (s1 && !s0) -+ return 1; -+ if (s0 && !s1) -+ return -1; -+ if (!s0 && !s1) -+ return 0; -+ if (cmp) -+ return cmp(s0, s1); -+ return grub_strcmp(s0, s1); -+} -+ -+static int -+bls_keyval_cmp(struct bls_entry *e0, struct bls_entry *e1, const char *keyname) -+{ -+ char *val0, *val1; -+ -+ val0 = bls_get_val (e0, keyname, NULL); -+ val1 = bls_get_val (e1, keyname, NULL); -+ -+ if (val1 && !val0) -+ return 1; -+ -+ if (val0 && !val1) -+ return -1; -+ -+ if (!val0 && !val1) -+ return 0; -+ -+ return nulcmp(val0, val1, (void_cmp_t)vercmp); -+} -+ -+static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) -+{ -+ struct bls_entry * e0 = *(struct bls_entry **)p0; -+ struct bls_entry * e1 = *(struct bls_entry **)p1; -+ int rc = 0; -+ -+ rc = bls_keyval_cmp (e0, e1, "id"); -+ -+ if (rc == 0) -+ rc = bls_keyval_cmp (e0, e1, "title"); -+ -+ if (rc == 0) -+ rc = bls_keyval_cmp (e0, e1, "linux"); -+ -+ return rc; -+} -+ -+static int read_entry ( - const char *filename, -- const struct grub_dirhook_info *info __attribute__ ((unused)), -- void *data __attribute__ ((unused))) -+ const struct grub_dirhook_info *info UNUSED, -+ void *data) - { - grub_size_t n; - char *p; - grub_file_t f = NULL; - grub_off_t sz; -- char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL; -- const char *args[2] = { NULL, NULL }; -+ struct bls_entry *entry; -+ const char *dirname= (const char *)data; -+ const char *devid = grub_env_get ("boot"); -+ -+ grub_dprintf ("blscfg", "filename: \"%s\"\n", filename); - - if (filename[0] == '.') - return 0; -@@ -67,7 +440,7 @@ static int parse_entry ( - if (grub_strcmp (filename + n - 5, ".conf") != 0) - return 0; - -- p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename); -+ p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename); - - f = grub_file_open (p); - if (!f) -@@ -77,54 +450,169 @@ static int parse_entry ( - if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) - goto finish; - -+ entry = bls_new_entry(); -+ if (!entry) -+ goto finish; -+ - for (;;) - { - char *buf; -+ char *separator; -+ int rc; - - buf = grub_file_getline (f); - if (!buf) - break; - -- if (grub_strncmp (buf, "title ", 6) == 0) -- { -- grub_free (title); -- title = grub_strdup (buf + 6); -- if (!title) -- goto finish; -- } -- else if (grub_strncmp (buf, "options ", 8) == 0) -- { -- grub_free (options); -- options = grub_strdup (buf + 8); -- if (!options) -- goto finish; -- } -- else if (grub_strncmp (buf, "linux ", 6) == 0) -- { -- grub_free (clinux); -- clinux = grub_strdup (buf + 6); -- if (!clinux) -- goto finish; -- } -- else if (grub_strncmp (buf, "initrd ", 7) == 0) -+ 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 (initrd); -- initrd = grub_strdup (buf + 7); -- if (!initrd) -- goto finish; -+ grub_free (buf); -+ break; - } - -- grub_free(buf); -+ separator[0] = '\0'; -+ -+ rc = bls_add_keyval (entry, buf, separator+1); -+ grub_free (buf); -+ if (rc < 0) -+ break; -+ } -+ -+ grub_qsort(&entry->keyvals[0], entry->nkeyvals, sizeof (struct keyval *), -+ keyval_cmp, NULL); -+ -+finish: -+ grub_free (p); -+ -+ if (f) -+ grub_file_close (f); -+ -+ return 0; -+} -+ -+static grub_envblk_t saved_env = NULL; -+ -+static int -+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 -+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 (!linux) -+ 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 void create_entry (struct bls_entry *entry, const char *cfgfile) -+{ -+ int argc = 0; -+ const char **argv = NULL; -+ -+ char *title = NULL; -+ char *clinux = NULL; -+ char *options = NULL; -+ char *initrd = NULL; -+ char *id = NULL; -+ char *hotkey = NULL; -+ -+ char *users = NULL; -+ char **classes = NULL; -+ -+ char **args = NULL; -+ -+ char *src = NULL; -+ int i; -+ -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ clinux = bls_get_val (entry, "linux", NULL); -+ if (!clinux) - { -- grub_printf ("Skipping file %s with no 'linux' key.", p); -+ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", cfgfile); - goto finish; - } - -- args[0] = title ? title : filename; -+ title = bls_get_val (entry, "title", NULL); -+ options = bls_get_val (entry, "options", NULL); -+ initrd = bls_get_val (entry, "initrd", NULL); -+ id = bls_get_val (entry, "id", NULL); - -+ hotkey = bls_get_val (entry, "grub_hotkey", NULL); -+ users = 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; -+ -+ grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title); - src = grub_xasprintf ("load_video\n" - "set gfx_payload=keep\n" - "insmod gzio\n" -@@ -133,40 +621,219 @@ static int parse_entry ( - GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", - initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); - -- grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0); -+ grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); - - finish: -- grub_free (p); -- grub_free (title); -- grub_free (options); -- grub_free (clinux); -- grub_free (initrd); -- grub_free (src); -+ if (classes) -+ grub_free (classes); -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ if (args) -+ grub_free (args); -+ -+ if (argv) -+ grub_free (argv); -+ -+ if (src) -+ grub_free (src); -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+} -+ -+struct find_entry_info { -+ grub_device_t dev; -+ grub_fs_t fs; -+ int efi; -+}; -+ -+/* -+ * filename: if the directory is /EFI/something/ , filename is "something" -+ * info: unused -+ * data: the filesystem object the file is on. -+ */ -+static int find_entry (const char *filename, -+ const struct grub_dirhook_info *dirhook_info UNUSED, -+ void *data) -+{ -+ struct find_entry_info *info = (struct find_entry_info *)data; -+ grub_file_t f = NULL; -+ char *grubenv_path = NULL; -+ grub_envblk_t env = NULL; -+ char *default_blsdir = NULL; -+ const char *blsdir = NULL; -+ char *saved_env_buf = NULL; -+ int r = 0; -+ const char *devid = grub_env_get ("boot"); -+ -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ if (!grub_strcmp (filename, ".") || -+ !grub_strcmp (filename, "..")) -+ return 0; -+ -+ if (info->efi && !grub_strcasecmp (filename, "boot")) -+ return 0; -+ -+ saved_env_buf = grub_malloc (512); -+ -+ // set a default blsdir -+ if (info->efi) -+ default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, -+ GRUB_BLS_CONFIG_PATH); -+ else -+ default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); -+ -+ grub_env_set ("blsdir", default_blsdir); -+ grub_dprintf ("blscfg", "default_blsdir: \"%s\"\n", default_blsdir); -+ -+ /* -+ * try to load a grubenv from /EFI/wherever/grubenv -+ */ -+ if (info->efi) -+ grubenv_path = grub_xasprintf ("(%s)/EFI/%s/grubenv", devid, filename); -+ else -+ grubenv_path = grub_xasprintf ("(%s)/grub2/grubenv", devid); -+ -+ grub_dprintf ("blscfg", "looking for \"%s\"\n", grubenv_path); -+ f = grub_file_open (grubenv_path); -+ -+ grub_dprintf ("blscfg", "%s it\n", f ? "found" : "did not find"); -+ grub_free (grubenv_path); -+ if (f) -+ { -+ grub_off_t sz; -+ -+ grub_dprintf ("blscfg", "getting size\n"); -+ sz = grub_file_size (f); -+ if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) -+ goto finish; -+ -+ grub_dprintf ("blscfg", "reading env\n"); -+ env = read_envblk_file (f); -+ if (!env) -+ goto finish; -+ grub_dprintf ("blscfg", "read env file\n"); -+ -+ grub_memset (saved_env_buf, '#', 512); -+ grub_memcpy (saved_env_buf, GRUB_ENVBLK_SIGNATURE, -+ sizeof (GRUB_ENVBLK_SIGNATURE)); -+ grub_dprintf ("blscfg", "saving env\n"); -+ saved_env = grub_envblk_open (saved_env_buf, 512); -+ if (!saved_env) -+ goto finish; -+ -+ // save everything listed in "env" with values from our existing grub env -+ grub_envblk_iterate (env, NULL, save_var); -+ // set everything from our loaded grubenv into the real grub env -+ grub_envblk_iterate (env, NULL, set_var); -+ } -+ else -+ { -+ grub_err_t e; -+ grub_dprintf ("blscfg", "no such file\n"); -+ do -+ { -+ e = grub_error_pop(); -+ } while (e); -+ -+ } -+ -+ blsdir = grub_env_get ("blsdir"); -+ if (!blsdir) -+ goto finish; -+ -+ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); -+ if (blsdir[0] != '/' && info->efi) -+ blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); -+ else -+ blsdir = grub_strdup (blsdir); -+ -+ if (!blsdir) -+ goto finish; -+ -+ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); -+ r = info->fs->dir (info->dev, blsdir, read_entry, (char *)blsdir); -+ if (r != 0) { -+ grub_dprintf ("blscfg", "read_entry returned error\n"); -+ grub_err_t e; -+ do -+ { -+ e = grub_error_pop(); -+ } while (e); -+ } -+ -+ grub_dprintf ("blscfg", "Sorting %d entries\n", nentries); -+ grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, NULL); -+ -+ grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries); -+ for (r = nentries - 1; r >= 0; r--) -+ create_entry(entries[r], filename); -+ -+ for (r = 0; r < nentries; r++) -+ bls_free_entry (entries[r]); -+finish: -+ nentries = 0; -+ -+ grub_free (entries); -+ entries = NULL; -+ -+ grub_free ((char *)blsdir); -+ -+ grub_env_unset ("blsdir"); -+ -+ if (saved_env) -+ { -+ // remove everything from the real environment that's defined in env -+ grub_envblk_iterate (env, NULL, unset_var); -+ -+ // re-set the things from our original environment -+ grub_envblk_iterate (saved_env, NULL, set_var); -+ grub_envblk_close (saved_env); -+ saved_env = NULL; -+ } -+ else if (saved_env_buf) -+ { -+ // if we have a saved environment, grub_envblk_close() freed this. -+ grub_free (saved_env_buf); -+ } -+ -+ if (env) -+ grub_envblk_close (env); - - if (f) - grub_file_close (f); - -+ grub_free (default_blsdir); -+ - return 0; - } - - static grub_err_t --grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), -- int argc __attribute__ ((unused)), -- char **args __attribute__ ((unused))) -+grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, -+ int argc UNUSED, -+ char **args UNUSED) - { - grub_fs_t fs; - grub_device_t dev; - static grub_err_t r; - const char *devid; -+ struct find_entry_info info = -+ { -+ .dev = NULL, -+ .fs = NULL, -+ .efi = 0, -+ }; - -- devid = grub_env_get ("root"); -+ -+ grub_dprintf ("blscfg", "finding boot\n"); -+ devid = grub_env_get ("boot"); - if (!devid) -- return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root"); -+ 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) - { -@@ -174,7 +841,17 @@ grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), - goto finish; - } - -- r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL); -+ info.dev = dev; -+ info.fs = fs; -+#ifdef GRUB_MACHINE_EFI -+ info.efi = 1; -+ grub_dprintf ("blscfg", "scanning /EFI/\n"); -+ r = fs->dir (dev, "/EFI/", find_entry, &info); -+#else -+ info.efi = 0; -+ grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); -+ r = fs->dir (dev, "/", find_entry, &info); -+#endif - - finish: - if (dev) -@@ -187,8 +864,9 @@ static grub_extcmd_t cmd; - - GRUB_MOD_INIT(bls) - { -- cmd = grub_register_extcmd ("bls_import", -- grub_cmd_bls_import, -+ grub_dprintf("blscfg", "%s got here\n", __func__); -+ cmd = grub_register_extcmd ("blscfg", -+ grub_cmd_blscfg, - 0, - NULL, - N_("Import Boot Loader Specification snippets."), -diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c -index acd93d123ed..91c99456091 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[] = -@@ -84,81 +86,6 @@ open_envblk_file (char *filename, int untrusted) - 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/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/0286-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch b/0286-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch new file mode 100644 index 0000000..acfb116 --- /dev/null +++ b/0286-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/0287-Add-BLS-support-to-grub-mkconfig.patch b/0287-Add-BLS-support-to-grub-mkconfig.patch deleted file mode 100644 index 2857ad3..0000000 --- a/0287-Add-BLS-support-to-grub-mkconfig.patch +++ /dev/null @@ -1,167 +0,0 @@ -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. ---- - util/grub-mkconfig.in | 3 ++- - util/grub-mkconfig_lib.in | 29 +++++++++++++++++++---------- - util/grub.d/10_linux.in | 37 ++++++++++++++++++++++++++++++++++++- - 3 files changed, 57 insertions(+), 12 deletions(-) - -diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in -index 4248b9341ab..c20171919d9 100644 ---- a/util/grub-mkconfig.in -+++ b/util/grub-mkconfig.in -@@ -259,7 +259,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..1acc1d01c39 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 -@@ -127,10 +130,16 @@ EOF - - prepare_grub_to_access_device () - { -+ local device=$1 && shift -+ if [ "$#" -gt 0 ]; then -+ local variable=$1 && shift -+ else -+ local variable=root -+ fi - old_ifs="$IFS" - IFS=' - ' -- partmap="`"${grub_probe}" --device $@ --target=partmap`" -+ partmap="`"${grub_probe}" --device ${device} --target=partmap`" - for module in ${partmap} ; do - case "${module}" in - netbsd | openbsd) -@@ -141,34 +150,34 @@ prepare_grub_to_access_device () - done - - # Abstraction modules aren't auto-loaded. -- abstraction="`"${grub_probe}" --device $@ --target=abstraction`" -+ abstraction="`"${grub_probe}" --device ${device} --target=abstraction`" - for module in ${abstraction} ; do - echo "insmod ${module}" - done - -- fs="`"${grub_probe}" --device $@ --target=fs`" -+ fs="`"${grub_probe}" --device ${device} --target=fs`" - for module in ${fs} ; do - echo "insmod ${module}" - done - - if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then -- for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do -+ for uuid in `"${grub_probe}" --device ${device} --target=cryptodisk_uuid`; do - echo "cryptomount -u $uuid" - done - fi - - # If there's a filesystem UUID that GRUB is capable of identifying, use it; - # otherwise set root as per value in device.map. -- fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`" -+ fs_hint="`"${grub_probe}" --device ${device} --target=compatibility_hint`" - if [ "x$fs_hint" != x ]; then -- echo "set root='$fs_hint'" -+ echo "set ${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= -+ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then -+ hints="`"${grub_probe}" --device ${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=${variable} ${hints} ${fs_uuid}" - echo "else" -- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" -+ echo " search --no-floppy --fs-uuid --set=${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 69415af69b2..aec1ca3eba0 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -135,6 +135,34 @@ linux_entry () - 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 -+ -+ bootefi_device="`${grub_probe} --target=device /boot/efi/`" -+ prepare_grub_to_access_device ${bootefi_device} boot -+ -+ cat << EOF -+insmod blscfg -+blscfg -+if [ -s \$prefix/grubenv ]; then -+ load_env -+fi -+EOF -+ -+ ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" -+ -+ 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 -@@ -239,7 +267,10 @@ submenu_indentation="" - is_top_level=true - while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` -- gettext_printf "Found linux image: %s\n" "$linux" >&2 -+ 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` -@@ -303,6 +334,10 @@ while [ "x$list" != "x" ] ; do - fi - - if test -z "${initramfs}" && test -z "${initrd_real}" ; then -+ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then -+ gettext_printf "Found initrd image: %s\n" "${dirname}/${initramfs}" >&2 -+ fi -+ elif test -z "${initramfs}" ; 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" ] \ diff --git a/0287-align-struct-efi_variable-better.patch b/0287-align-struct-efi_variable-better.patch new file mode 100644 index 0000000..65bc91b --- /dev/null +++ b/0287-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 b93e4820194..f6a9723971d 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/0288-Add-quicksort-implementation.patch b/0288-Add-quicksort-implementation.patch new file mode 100644 index 0000000..06fe563 --- /dev/null +++ b/0288-Add-quicksort-implementation.patch @@ -0,0 +1,322 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 9 Dec 2016 15:39:47 -0500 +Subject: [PATCH] Add quicksort implementation + +This will be used to sort the boot menu entries that are read from +the BootLoaderSpec config files. +--- + grub-core/kern/qsort.c | 279 +++++++++++++++++++++++++++++++++++++++++++++++++ + include/grub/misc.h | 15 +++ + 2 files changed, 294 insertions(+) + create mode 100644 grub-core/kern/qsort.c + +diff --git a/grub-core/kern/qsort.c b/grub-core/kern/qsort.c +new file mode 100644 +index 00000000000..7f3fc9ffdae +--- /dev/null ++++ b/grub-core/kern/qsort.c +@@ -0,0 +1,279 @@ ++/* quicksort ++ * This file from the GNU C Library. ++ * Copyright (C) 1991-2016 Free Software Foundation, Inc. ++ * Written by Douglas C. Schmidt (schmidt@ics.uci.edu). ++ * ++ * 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 . ++ */ ++ ++/* If you consider tuning this algorithm, you should consult first: ++ Engineering a sort function; Jon Bentley and M. Douglas McIlroy; ++ Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ ++ ++#include ++#include ++#include ++ ++#define CHAR_BIT 8 ++ ++/* Byte-wise swap two items of size SIZE. */ ++#define SWAP(a, b, size) \ ++ do \ ++ { \ ++ grub_size_t __size = (size); \ ++ char *__a = (a), *__b = (b); \ ++ do \ ++ { \ ++ char __tmp = *__a; \ ++ *__a++ = *__b; \ ++ *__b++ = __tmp; \ ++ } while (--__size > 0); \ ++ } while (0) ++ ++/* Discontinue quicksort algorithm when partition gets below this size. ++ This particular magic number was chosen to work best on a Sun 4/260. */ ++#define MAX_THRESH 4 ++ ++/* Stack node declarations used to store unfulfilled partition obligations. */ ++typedef struct ++ { ++ char *lo; ++ char *hi; ++ } stack_node; ++ ++/* The next 4 #defines implement a very fast in-line stack abstraction. */ ++/* The stack needs log (total_elements) entries (we could even subtract ++ log(MAX_THRESH)). Since total_elements has type grub_size_t, we get as ++ upper bound for log (total_elements): ++ bits per byte (CHAR_BIT) * sizeof(grub_size_t). */ ++#define STACK_SIZE (CHAR_BIT * sizeof(grub_size_t)) ++#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) ++#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) ++#define STACK_NOT_EMPTY (stack < top) ++ ++ ++/* Order size using quicksort. This implementation incorporates ++ four optimizations discussed in Sedgewick: ++ ++ 1. Non-recursive, using an explicit stack of pointer that store the ++ next array partition to sort. To save time, this maximum amount ++ of space required to store an array of SIZE_MAX is allocated on the ++ stack. Assuming a 32-bit (64 bit) integer for grub_size_t, this needs ++ only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). ++ Pretty cheap, actually. ++ ++ 2. Chose the pivot element using a median-of-three decision tree. ++ This reduces the probability of selecting a bad pivot value and ++ eliminates certain extraneous comparisons. ++ ++ 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving ++ insertion sort to order the MAX_THRESH items within each partition. ++ This is a big win, since insertion sort is faster for small, mostly ++ sorted array segments. ++ ++ 4. The larger of the two sub-partitions is always pushed onto the ++ stack first, with the algorithm then concentrating on the ++ smaller partition. This *guarantees* no more than log (total_elems) ++ stack size is needed (actually O(1) in this case)! */ ++ ++void ++grub_qsort (void *const pbase, grub_size_t total_elems, grub_size_t size, ++ grub_compar_d_fn_t cmp, void *arg) ++{ ++ char *base_ptr = (char *) pbase; ++ ++ const grub_size_t max_thresh = MAX_THRESH * size; ++ ++ if (total_elems == 0) ++ /* Avoid lossage with unsigned arithmetic below. */ ++ return; ++ ++ if (total_elems > MAX_THRESH) ++ { ++ char *lo = base_ptr; ++ char *hi = &lo[size * (total_elems - 1)]; ++ stack_node stack[STACK_SIZE]; ++ stack_node *top = stack; ++ ++ PUSH (NULL, NULL); ++ ++ while (STACK_NOT_EMPTY) ++ { ++ char *left_ptr; ++ char *right_ptr; ++ ++ /* Select median value from among LO, MID, and HI. Rearrange ++ LO and HI so the three values are sorted. This lowers the ++ probability of picking a pathological pivot value and ++ skips a comparison for both the LEFT_PTR and RIGHT_PTR in ++ the while loops. */ ++ ++ char *mid = lo + size * ((hi - lo) / size >> 1); ++ ++ if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) ++ SWAP (mid, lo, size); ++ if ((*cmp) ((void *) hi, (void *) mid, arg) < 0) ++ SWAP (mid, hi, size); ++ else ++ goto jump_over; ++ if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) ++ SWAP (mid, lo, size); ++ jump_over:; ++ ++ left_ptr = lo + size; ++ right_ptr = hi - size; ++ ++ /* Here's the famous ``collapse the walls'' section of quicksort. ++ Gotta like those tight inner loops! They are the main reason ++ that this algorithm runs much faster than others. */ ++ do ++ { ++ while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0) ++ left_ptr += size; ++ ++ while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0) ++ right_ptr -= size; ++ ++ if (left_ptr < right_ptr) ++ { ++ SWAP (left_ptr, right_ptr, size); ++ if (mid == left_ptr) ++ mid = right_ptr; ++ else if (mid == right_ptr) ++ mid = left_ptr; ++ left_ptr += size; ++ right_ptr -= size; ++ } ++ else if (left_ptr == right_ptr) ++ { ++ left_ptr += size; ++ right_ptr -= size; ++ break; ++ } ++ } ++ while (left_ptr <= right_ptr); ++ ++ /* Set up pointers for next iteration. First determine whether ++ left and right partitions are below the threshold size. If so, ++ ignore one or both. Otherwise, push the larger partition's ++ bounds on the stack and continue sorting the smaller one. */ ++ ++ if ((grub_size_t) (right_ptr - lo) <= max_thresh) ++ { ++ if ((grub_size_t) (hi - left_ptr) <= max_thresh) ++ /* Ignore both small partitions. */ ++ POP (lo, hi); ++ else ++ /* Ignore small left partition. */ ++ lo = left_ptr; ++ } ++ else if ((grub_size_t) (hi - left_ptr) <= max_thresh) ++ /* Ignore small right partition. */ ++ hi = right_ptr; ++ else if ((right_ptr - lo) > (hi - left_ptr)) ++ { ++ /* Push larger left partition indices. */ ++ PUSH (lo, right_ptr); ++ lo = left_ptr; ++ } ++ else ++ { ++ /* Push larger right partition indices. */ ++ PUSH (left_ptr, hi); ++ hi = right_ptr; ++ } ++ } ++ } ++ ++ /* Once the BASE_PTR array is partially sorted by quicksort the rest ++ is completely sorted using insertion sort, since this is efficient ++ for partitions below MAX_THRESH size. BASE_PTR points to the beginning ++ of the array to sort, and END_PTR points at the very last element in ++ the array (*not* one beyond it!). */ ++ ++#define min(x, y) ((x) < (y) ? (x) : (y)) ++ ++ { ++ char *const end_ptr = &base_ptr[size * (total_elems - 1)]; ++ char *tmp_ptr = base_ptr; ++ char *thresh = min(end_ptr, base_ptr + max_thresh); ++ char *run_ptr; ++ ++ /* Find smallest element in first threshold and place it at the ++ array's beginning. This is the smallest array element, ++ and the operation speeds up insertion sort's inner loop. */ ++ ++ for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) ++ if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) ++ tmp_ptr = run_ptr; ++ ++ if (tmp_ptr != base_ptr) ++ SWAP (tmp_ptr, base_ptr, size); ++ ++ /* Insertion sort, running from left-hand-side up to right-hand-side. */ ++ ++ run_ptr = base_ptr + size; ++ while ((run_ptr += size) <= end_ptr) ++ { ++ tmp_ptr = run_ptr - size; ++ while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) ++ tmp_ptr -= size; ++ ++ tmp_ptr += size; ++ if (tmp_ptr != run_ptr) ++ { ++ char *trav; ++ ++ trav = run_ptr + size; ++ while (--trav >= run_ptr) ++ { ++ char c = *trav; ++ char *hi, *lo; ++ ++ for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo) ++ *hi = *lo; ++ *hi = c; ++ } ++ } ++ } ++ } ++} ++ ++void * ++grub_bsearch (const void *key, const void *base, grub_size_t nmemb, grub_size_t size, ++ grub_compar_d_fn_t compar, void *state) ++{ ++ grub_size_t l, u, idx; ++ const void *p; ++ int comparison; ++ ++ l = 0; ++ u = nmemb; ++ while (l < u) ++ { ++ idx = (l + u) / 2; ++ p = (void *) (((const char *) base) + (idx * size)); ++ comparison = (*compar) (key, p, state); ++ if (comparison < 0) ++ u = idx; ++ else if (comparison > 0) ++ l = idx + 1; ++ else ++ return (void *) p; ++ } ++ ++ return NULL; ++} +diff --git a/include/grub/misc.h b/include/grub/misc.h +index fcaf1201e39..cbfae75a1b4 100644 +--- a/include/grub/misc.h ++++ b/include/grub/misc.h +@@ -507,4 +507,19 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file, + #define grub_max(a, b) (((a) > (b)) ? (a) : (b)) + #define grub_min(a, b) (((a) < (b)) ? (a) : (b)) + ++typedef int (*grub_compar_d_fn_t) (const void *p0, const void *p1, void *state); ++ ++void *EXPORT_FUNC(grub_bsearch) (const void *key, ++ const void *base, ++ grub_size_t nmemb, ++ grub_size_t size, ++ grub_compar_d_fn_t compar, ++ void *state); ++ ++void EXPORT_FUNC(grub_qsort) (void *const pbase, ++ grub_size_t total_elems, ++ grub_size_t size, ++ grub_compar_d_fn_t cmp, ++ void *state); ++ + #endif /* ! GRUB_MISC_HEADER */ diff --git a/0288-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch b/0288-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch deleted file mode 100644 index 53bf22e..0000000 --- a/0288-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 6 Feb 2018 11:02:09 +0100 -Subject: [PATCH] Remove duplicated grub_exit() definition for grub-emu - platform - -The grub_exit() function signature was changed on all platforms to take a -return code, but latter on a following commit the grub_exit() for the emu -platform was duplicated. It causes a build error so remove the duplicated -function definition. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/kern/emu/main.c | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c -index 7e47ec81263..55ea5a11ccd 100644 ---- a/grub-core/kern/emu/main.c -+++ b/grub-core/kern/emu/main.c -@@ -72,12 +72,6 @@ grub_exit (int retval __attribute__((unused))) - grub_reboot (); - } - --void --grub_exit (int retval __attribute__((unused))) --{ -- grub_reboot (); --} -- - void - grub_machine_init (void) - { diff --git a/0289-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch b/0289-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch new file mode 100644 index 0000000..cde929e --- /dev/null +++ b/0289-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch @@ -0,0 +1,1139 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 9 Dec 2016 15:40:58 -0500 +Subject: [PATCH] Add blscfg command support to parse BootLoaderSpec config + fragments + +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. + +GRUB2 already has a blscfg modle that can parse the config snippets using +the bls_import command, change it to blscfg and improve the BLS support. +--- + grub-core/Makefile.core.def | 4 +- + grub-core/commands/blscfg.c | 788 ++++++++++++++++++++++++++++++++++++++++--- + grub-core/commands/loadenv.c | 77 +---- + grub-core/commands/loadenv.h | 93 +++++ + include/grub/compiler.h | 2 + + 5 files changed, 832 insertions(+), 132 deletions(-) + create mode 100644 grub-core/commands/loadenv.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index edf249f0002..fb661b4abf8 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -129,6 +129,7 @@ kernel = { + common = kern/rescue_parser.c; + common = kern/rescue_reader.c; + common = kern/term.c; ++ common = kern/qsort.c; + + noemu = kern/compiler-rt.c; + noemu = kern/mm.c; +@@ -775,8 +776,7 @@ module = { + module = { + name = blscfg; + common = commands/blscfg.c; +- enable = i386_efi; +- enable = x86_64_efi; ++ enable = efi; + enable = i386_pc; + }; + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 4274aca5a9d..9ab45631465 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -30,32 +30,405 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + ++#include "loadenv.h" ++ ++#define GRUB_BLS_CONFIG_PATH "/loader/entries/" ++#define GRUB_BOOT_DEVICE "($root)" + #ifdef GRUB_MACHINE_EFI + #define GRUB_LINUX_CMD "linuxefi" + #define GRUB_INITRD_CMD "initrdefi" +-#define GRUB_BLS_CONFIG_PATH "/EFI/fedora/loader/entries/" +-#define GRUB_BOOT_DEVICE "($boot)" + #else + #define GRUB_LINUX_CMD "linux" + #define GRUB_INITRD_CMD "initrd" +-#define GRUB_BLS_CONFIG_PATH "/loader/entries/" +-#define GRUB_BOOT_DEVICE "($root)" + #endif + +-static int parse_entry ( ++#define grub_free(x) ({grub_dprintf("blscfg", "%s freeing %p\n", __func__, x); grub_free(x); }) ++ ++struct keyval ++{ ++ const char *key; ++ char *val; ++}; ++ ++struct bls_entry ++{ ++ struct keyval **keyvals; ++ int nkeyvals; ++}; ++ ++static struct bls_entry **entries; ++static int nentries; ++ ++static struct bls_entry *bls_new_entry(void) ++{ ++ struct bls_entry **new_entries; ++ struct bls_entry *entry; ++ int new_n = nentries + 1; ++ ++ new_entries = grub_realloc (entries, new_n * sizeof (struct bls_entry *)); ++ if (!new_entries) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry list"); ++ return NULL; ++ } ++ ++ entries = new_entries; ++ ++ entry = grub_malloc (sizeof (*entry)); ++ if (!entry) ++ { ++ grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ "couldn't find space for BLS entry list"); ++ return NULL; ++ } ++ ++ grub_memset (entry, 0, sizeof (*entry)); ++ entries[nentries] = entry; ++ ++ nentries = new_n; ++ ++ return entry; ++} ++ ++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:%p:%p\n", entry->keyvals[entry->nkeyvals], k, v); ++ entry->nkeyvals = new_n; ++ ++ return 0; ++} ++ ++static void bls_free_entry(struct bls_entry *entry) ++{ ++ int i; ++ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ for (i = 0; i < entry->nkeyvals; i++) ++ { ++ struct keyval *kv = entry->keyvals[i]; ++ grub_free ((void *)kv->key); ++ grub_free (kv->val); ++ grub_free (kv); ++ } ++ ++ grub_free (entry->keyvals); ++ grub_memset (entry, 0, sizeof (*entry)); ++ grub_free (entry); ++} ++ ++static int keyval_cmp (const void *p0, const void *p1, ++ void *state UNUSED) ++{ ++ const struct keyval *kv0 = *(struct keyval * const *)p0; ++ const struct keyval *kv1 = *(struct keyval * const *)p1; ++ int rc; ++ ++ rc = grub_strcmp(kv0->key, kv1->key); ++ ++ return rc; ++} ++ ++/* 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. */ ++static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last) ++{ ++ char *foo = (char *)""; ++ struct keyval *kv = NULL, **kvp, key = {keyname, foo}, *keyp = &key; ++ ++ /* if we've already found an entry that matches, just iterate */ ++ if (last && *last >= 0) ++ { ++ int next = ++last[0]; ++ ++ if (next == entry->nkeyvals) ++ { ++done: ++ *last = -1; ++ return NULL; ++ } ++ ++ kv = entry->keyvals[next]; ++ if (grub_strcmp (keyname, kv->key)) ++ goto done; ++ ++ return kv->val; ++ } ++ ++ kvp = grub_bsearch(&keyp, &entry->keyvals[0], entry->nkeyvals, ++ sizeof (struct keyval *), keyval_cmp, NULL); ++ if (kvp) ++ kv = *kvp; ++ ++ if (kv) ++ { ++ /* if we've got uninitialized but present state, track back until we find ++ * the first match */ ++ if (last) ++ { ++ grub_dprintf("blscfg", "%s trying to find another entry because last was set\n", __func__); ++ /* figure out the position of this entry in the array */ ++ int idx; ++ for (idx = 0 ; idx < entry->nkeyvals; idx++) ++ if (entry->keyvals[idx] == kv) ++ break; ++ *last = idx; ++ ++ while (idx > 0) ++ { ++ struct keyval *kvtmp = entry->keyvals[idx-1]; ++ if (idx == 0 || grub_strcmp (keyname, kvtmp->key)) ++ { ++ /* if we're at the start, or if the previous entry doesn't ++ * match, then we're done */ ++ *last = idx; ++ break; ++ } ++ else ++ /* but if it does match, keep going backwards */ ++ idx--; ++ } ++ } ++ ++ return kv->val; ++ } ++ return NULL; ++} ++ ++#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 got here\n", __func__); ++ 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; ++} ++ ++typedef int (*void_cmp_t)(void *, void *); ++ ++static int nulcmp(char *s0, char *s1, void_cmp_t cmp) ++{ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ if (s1 && !s0) ++ return 1; ++ if (s0 && !s1) ++ return -1; ++ if (!s0 && !s1) ++ return 0; ++ if (cmp) ++ return cmp(s0, s1); ++ return grub_strcmp(s0, s1); ++} ++ ++static int ++bls_keyval_cmp(struct bls_entry *e0, struct bls_entry *e1, const char *keyname) ++{ ++ char *val0, *val1; ++ ++ val0 = bls_get_val (e0, keyname, NULL); ++ val1 = bls_get_val (e1, keyname, NULL); ++ ++ if (val1 && !val0) ++ return 1; ++ ++ if (val0 && !val1) ++ return -1; ++ ++ if (!val0 && !val1) ++ return 0; ++ ++ return nulcmp(val0, val1, (void_cmp_t)vercmp); ++} ++ ++static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) ++{ ++ struct bls_entry * e0 = *(struct bls_entry **)p0; ++ struct bls_entry * e1 = *(struct bls_entry **)p1; ++ int rc = 0; ++ ++ rc = bls_keyval_cmp (e0, e1, "id"); ++ ++ if (rc == 0) ++ rc = bls_keyval_cmp (e0, e1, "title"); ++ ++ if (rc == 0) ++ rc = bls_keyval_cmp (e0, e1, "linux"); ++ ++ return rc; ++} ++ ++static int read_entry ( + const char *filename, +- const struct grub_dirhook_info *info __attribute__ ((unused)), +- void *data __attribute__ ((unused))) ++ const struct grub_dirhook_info *info UNUSED, ++ void *data) + { + grub_size_t n; + char *p; + grub_file_t f = NULL; + grub_off_t sz; +- char *title = NULL, *options = NULL, *clinux = NULL, *initrd = NULL, *src = NULL; +- const char *args[2] = { NULL, NULL }; ++ struct bls_entry *entry; ++ const char *dirname= (const char *)data; ++ const char *devid = grub_env_get ("boot"); ++ ++ grub_dprintf ("blscfg", "filename: \"%s\"\n", filename); + + if (filename[0] == '.') + return 0; +@@ -67,7 +440,7 @@ static int parse_entry ( + if (grub_strcmp (filename + n - 5, ".conf") != 0) + return 0; + +- p = grub_xasprintf (GRUB_BLS_CONFIG_PATH "%s", filename); ++ p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename); + + f = grub_file_open (p); + if (!f) +@@ -77,54 +450,169 @@ static int parse_entry ( + if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) + goto finish; + ++ entry = bls_new_entry(); ++ if (!entry) ++ goto finish; ++ + for (;;) + { + char *buf; ++ char *separator; ++ int rc; + + buf = grub_file_getline (f); + if (!buf) + break; + +- if (grub_strncmp (buf, "title ", 6) == 0) +- { +- grub_free (title); +- title = grub_strdup (buf + 6); +- if (!title) +- goto finish; +- } +- else if (grub_strncmp (buf, "options ", 8) == 0) +- { +- grub_free (options); +- options = grub_strdup (buf + 8); +- if (!options) +- goto finish; +- } +- else if (grub_strncmp (buf, "linux ", 6) == 0) +- { +- grub_free (clinux); +- clinux = grub_strdup (buf + 6); +- if (!clinux) +- goto finish; +- } +- else if (grub_strncmp (buf, "initrd ", 7) == 0) ++ 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 (initrd); +- initrd = grub_strdup (buf + 7); +- if (!initrd) +- goto finish; ++ grub_free (buf); ++ break; + } + +- grub_free(buf); ++ separator[0] = '\0'; ++ ++ rc = bls_add_keyval (entry, buf, separator+1); ++ grub_free (buf); ++ if (rc < 0) ++ break; ++ } ++ ++ grub_qsort(&entry->keyvals[0], entry->nkeyvals, sizeof (struct keyval *), ++ keyval_cmp, NULL); ++ ++finish: ++ grub_free (p); ++ ++ if (f) ++ grub_file_close (f); ++ ++ return 0; ++} ++ ++static grub_envblk_t saved_env = NULL; ++ ++static int ++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 ++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 (!linux) ++ 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 void create_entry (struct bls_entry *entry, const char *cfgfile) ++{ ++ int argc = 0; ++ const char **argv = NULL; ++ ++ char *title = NULL; ++ char *clinux = NULL; ++ char *options = NULL; ++ char *initrd = NULL; ++ char *id = NULL; ++ char *hotkey = NULL; ++ ++ char *users = NULL; ++ char **classes = NULL; ++ ++ char **args = NULL; ++ ++ char *src = NULL; ++ int i; ++ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ clinux = bls_get_val (entry, "linux", NULL); ++ if (!clinux) + { +- grub_printf ("Skipping file %s with no 'linux' key.", p); ++ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", cfgfile); + goto finish; + } + +- args[0] = title ? title : filename; ++ title = bls_get_val (entry, "title", NULL); ++ options = bls_get_val (entry, "options", NULL); ++ initrd = bls_get_val (entry, "initrd", NULL); ++ id = bls_get_val (entry, "id", NULL); + ++ hotkey = bls_get_val (entry, "grub_hotkey", NULL); ++ users = 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; ++ ++ grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title); + src = grub_xasprintf ("load_video\n" + "set gfx_payload=keep\n" + "insmod gzio\n" +@@ -133,40 +621,219 @@ static int parse_entry ( + GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", + initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); + +- grub_normal_add_menu_entry (1, args, NULL, NULL, "bls", NULL, NULL, src, 0); ++ grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); + + finish: +- grub_free (p); +- grub_free (title); +- grub_free (options); +- grub_free (clinux); +- grub_free (initrd); +- grub_free (src); ++ if (classes) ++ grub_free (classes); ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ if (args) ++ grub_free (args); ++ ++ if (argv) ++ grub_free (argv); ++ ++ if (src) ++ grub_free (src); ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++} ++ ++struct find_entry_info { ++ grub_device_t dev; ++ grub_fs_t fs; ++ int efi; ++}; ++ ++/* ++ * filename: if the directory is /EFI/something/ , filename is "something" ++ * info: unused ++ * data: the filesystem object the file is on. ++ */ ++static int find_entry (const char *filename, ++ const struct grub_dirhook_info *dirhook_info UNUSED, ++ void *data) ++{ ++ struct find_entry_info *info = (struct find_entry_info *)data; ++ grub_file_t f = NULL; ++ char *grubenv_path = NULL; ++ grub_envblk_t env = NULL; ++ char *default_blsdir = NULL; ++ const char *blsdir = NULL; ++ char *saved_env_buf = NULL; ++ int r = 0; ++ const char *devid = grub_env_get ("boot"); ++ ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ if (!grub_strcmp (filename, ".") || ++ !grub_strcmp (filename, "..")) ++ return 0; ++ ++ if (info->efi && !grub_strcasecmp (filename, "boot")) ++ return 0; ++ ++ saved_env_buf = grub_malloc (512); ++ ++ // set a default blsdir ++ if (info->efi) ++ default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, ++ GRUB_BLS_CONFIG_PATH); ++ else ++ default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); ++ ++ grub_env_set ("blsdir", default_blsdir); ++ grub_dprintf ("blscfg", "default_blsdir: \"%s\"\n", default_blsdir); ++ ++ /* ++ * try to load a grubenv from /EFI/wherever/grubenv ++ */ ++ if (info->efi) ++ grubenv_path = grub_xasprintf ("(%s)/EFI/%s/grubenv", devid, filename); ++ else ++ grubenv_path = grub_xasprintf ("(%s)/grub2/grubenv", devid); ++ ++ grub_dprintf ("blscfg", "looking for \"%s\"\n", grubenv_path); ++ f = grub_file_open (grubenv_path); ++ ++ grub_dprintf ("blscfg", "%s it\n", f ? "found" : "did not find"); ++ grub_free (grubenv_path); ++ if (f) ++ { ++ grub_off_t sz; ++ ++ grub_dprintf ("blscfg", "getting size\n"); ++ sz = grub_file_size (f); ++ if (sz == GRUB_FILE_SIZE_UNKNOWN || sz > 1024*1024) ++ goto finish; ++ ++ grub_dprintf ("blscfg", "reading env\n"); ++ env = read_envblk_file (f); ++ if (!env) ++ goto finish; ++ grub_dprintf ("blscfg", "read env file\n"); ++ ++ grub_memset (saved_env_buf, '#', 512); ++ grub_memcpy (saved_env_buf, GRUB_ENVBLK_SIGNATURE, ++ sizeof (GRUB_ENVBLK_SIGNATURE)); ++ grub_dprintf ("blscfg", "saving env\n"); ++ saved_env = grub_envblk_open (saved_env_buf, 512); ++ if (!saved_env) ++ goto finish; ++ ++ // save everything listed in "env" with values from our existing grub env ++ grub_envblk_iterate (env, NULL, save_var); ++ // set everything from our loaded grubenv into the real grub env ++ grub_envblk_iterate (env, NULL, set_var); ++ } ++ else ++ { ++ grub_err_t e; ++ grub_dprintf ("blscfg", "no such file\n"); ++ do ++ { ++ e = grub_error_pop(); ++ } while (e); ++ ++ } ++ ++ blsdir = grub_env_get ("blsdir"); ++ if (!blsdir) ++ goto finish; ++ ++ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); ++ if (blsdir[0] != '/' && info->efi) ++ blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); ++ else ++ blsdir = grub_strdup (blsdir); ++ ++ if (!blsdir) ++ goto finish; ++ ++ grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); ++ r = info->fs->dir (info->dev, blsdir, read_entry, (char *)blsdir); ++ if (r != 0) { ++ grub_dprintf ("blscfg", "read_entry returned error\n"); ++ grub_err_t e; ++ do ++ { ++ e = grub_error_pop(); ++ } while (e); ++ } ++ ++ grub_dprintf ("blscfg", "Sorting %d entries\n", nentries); ++ grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, NULL); ++ ++ grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries); ++ for (r = nentries - 1; r >= 0; r--) ++ create_entry(entries[r], filename); ++ ++ for (r = 0; r < nentries; r++) ++ bls_free_entry (entries[r]); ++finish: ++ nentries = 0; ++ ++ grub_free (entries); ++ entries = NULL; ++ ++ grub_free ((char *)blsdir); ++ ++ grub_env_unset ("blsdir"); ++ ++ if (saved_env) ++ { ++ // remove everything from the real environment that's defined in env ++ grub_envblk_iterate (env, NULL, unset_var); ++ ++ // re-set the things from our original environment ++ grub_envblk_iterate (saved_env, NULL, set_var); ++ grub_envblk_close (saved_env); ++ saved_env = NULL; ++ } ++ else if (saved_env_buf) ++ { ++ // if we have a saved environment, grub_envblk_close() freed this. ++ grub_free (saved_env_buf); ++ } ++ ++ if (env) ++ grub_envblk_close (env); + + if (f) + grub_file_close (f); + ++ grub_free (default_blsdir); ++ + return 0; + } + + static grub_err_t +-grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), +- int argc __attribute__ ((unused)), +- char **args __attribute__ ((unused))) ++grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, ++ int argc UNUSED, ++ char **args UNUSED) + { + grub_fs_t fs; + grub_device_t dev; + static grub_err_t r; + const char *devid; ++ struct find_entry_info info = ++ { ++ .dev = NULL, ++ .fs = NULL, ++ .efi = 0, ++ }; + +- devid = grub_env_get ("root"); ++ ++ grub_dprintf ("blscfg", "finding boot\n"); ++ devid = grub_env_get ("boot"); + if (!devid) +- return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"), "root"); ++ 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) + { +@@ -174,7 +841,17 @@ grub_cmd_bls_import (grub_extcmd_context_t ctxt __attribute__ ((unused)), + goto finish; + } + +- r = fs->dir (dev, GRUB_BLS_CONFIG_PATH, parse_entry, NULL); ++ info.dev = dev; ++ info.fs = fs; ++#ifdef GRUB_MACHINE_EFI ++ info.efi = 1; ++ grub_dprintf ("blscfg", "scanning /EFI/\n"); ++ r = fs->dir (dev, "/EFI/", find_entry, &info); ++#else ++ info.efi = 0; ++ grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); ++ r = fs->dir (dev, "/", find_entry, &info); ++#endif + + finish: + if (dev) +@@ -187,8 +864,9 @@ static grub_extcmd_t cmd; + + GRUB_MOD_INIT(bls) + { +- cmd = grub_register_extcmd ("bls_import", +- grub_cmd_bls_import, ++ grub_dprintf("blscfg", "%s got here\n", __func__); ++ cmd = grub_register_extcmd ("blscfg", ++ grub_cmd_blscfg, + 0, + NULL, + N_("Import Boot Loader Specification snippets."), +diff --git a/grub-core/commands/loadenv.c b/grub-core/commands/loadenv.c +index acd93d123ed..91c99456091 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[] = +@@ -84,81 +86,6 @@ open_envblk_file (char *filename, int untrusted) + 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/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/0289-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch b/0289-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch deleted file mode 100644 index 204abbc..0000000 --- a/0289-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch +++ /dev/null @@ -1,26 +0,0 @@ -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/0290-Add-BLS-support-to-grub-mkconfig.patch b/0290-Add-BLS-support-to-grub-mkconfig.patch new file mode 100644 index 0000000..2857ad3 --- /dev/null +++ b/0290-Add-BLS-support-to-grub-mkconfig.patch @@ -0,0 +1,167 @@ +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. +--- + util/grub-mkconfig.in | 3 ++- + util/grub-mkconfig_lib.in | 29 +++++++++++++++++++---------- + util/grub.d/10_linux.in | 37 ++++++++++++++++++++++++++++++++++++- + 3 files changed, 57 insertions(+), 12 deletions(-) + +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index 4248b9341ab..c20171919d9 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -259,7 +259,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..1acc1d01c39 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 +@@ -127,10 +130,16 @@ EOF + + prepare_grub_to_access_device () + { ++ local device=$1 && shift ++ if [ "$#" -gt 0 ]; then ++ local variable=$1 && shift ++ else ++ local variable=root ++ fi + old_ifs="$IFS" + IFS=' + ' +- partmap="`"${grub_probe}" --device $@ --target=partmap`" ++ partmap="`"${grub_probe}" --device ${device} --target=partmap`" + for module in ${partmap} ; do + case "${module}" in + netbsd | openbsd) +@@ -141,34 +150,34 @@ prepare_grub_to_access_device () + done + + # Abstraction modules aren't auto-loaded. +- abstraction="`"${grub_probe}" --device $@ --target=abstraction`" ++ abstraction="`"${grub_probe}" --device ${device} --target=abstraction`" + for module in ${abstraction} ; do + echo "insmod ${module}" + done + +- fs="`"${grub_probe}" --device $@ --target=fs`" ++ fs="`"${grub_probe}" --device ${device} --target=fs`" + for module in ${fs} ; do + echo "insmod ${module}" + done + + if [ x$GRUB_ENABLE_CRYPTODISK = xy ]; then +- for uuid in `"${grub_probe}" --device $@ --target=cryptodisk_uuid`; do ++ for uuid in `"${grub_probe}" --device ${device} --target=cryptodisk_uuid`; do + echo "cryptomount -u $uuid" + done + fi + + # If there's a filesystem UUID that GRUB is capable of identifying, use it; + # otherwise set root as per value in device.map. +- fs_hint="`"${grub_probe}" --device $@ --target=compatibility_hint`" ++ fs_hint="`"${grub_probe}" --device ${device} --target=compatibility_hint`" + if [ "x$fs_hint" != x ]; then +- echo "set root='$fs_hint'" ++ echo "set ${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= ++ if [ "x$GRUB_DISABLE_UUID" != "xtrue" ] && fs_uuid="`"${grub_probe}" --device ${device} --target=fs_uuid 2> /dev/null`" ; then ++ hints="`"${grub_probe}" --device ${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=${variable} ${hints} ${fs_uuid}" + echo "else" +- echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}" ++ echo " search --no-floppy --fs-uuid --set=${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 69415af69b2..aec1ca3eba0 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -135,6 +135,34 @@ linux_entry () + 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 ++ ++ bootefi_device="`${grub_probe} --target=device /boot/efi/`" ++ prepare_grub_to_access_device ${bootefi_device} boot ++ ++ cat << EOF ++insmod blscfg ++blscfg ++if [ -s \$prefix/grubenv ]; then ++ load_env ++fi ++EOF ++ ++ ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" ++ ++ 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 +@@ -239,7 +267,10 @@ submenu_indentation="" + is_top_level=true + while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` +- gettext_printf "Found linux image: %s\n" "$linux" >&2 ++ 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` +@@ -303,6 +334,10 @@ while [ "x$list" != "x" ] ; do + fi + + if test -z "${initramfs}" && test -z "${initrd_real}" ; then ++ if [ "x${GRUB_ENABLE_BLSCFG}" != "xtrue" ]; then ++ gettext_printf "Found initrd image: %s\n" "${dirname}/${initramfs}" >&2 ++ fi ++ elif test -z "${initramfs}" ; 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" ] \ diff --git a/0290-Enable-blscfg-command-for-the-emu-platform.patch b/0290-Enable-blscfg-command-for-the-emu-platform.patch deleted file mode 100644 index ba9207e..0000000 --- a/0290-Enable-blscfg-command-for-the-emu-platform.patch +++ /dev/null @@ -1,164 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 2 Feb 2018 11:36:29 +0100 -Subject: [PATCH] Enable blscfg command for the emu platform - -Allow grub-emu to call a blscfg command. This may be useful for platforms -that don't support GRUB, so grub-emu can be used to parse the BLS configs -and kexec a new kernel using that information. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/Makefile.core.def | 1 + - grub-core/commands/blscfg.c | 46 +++++++++++++++++++++++++++++++++++---------- - 2 files changed, 37 insertions(+), 10 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index fb661b4abf8..8e6110e4bb6 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -778,6 +778,7 @@ module = { - common = commands/blscfg.c; - enable = efi; - enable = i386_pc; -+ enable = emu; - }; - - module = { -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 9ab45631465..e5617c3bc6c 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -37,7 +37,12 @@ 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 -+ - #ifdef GRUB_MACHINE_EFI - #define GRUB_LINUX_CMD "linuxefi" - #define GRUB_INITRD_CMD "initrdefi" -@@ -46,6 +51,13 @@ GRUB_MOD_LICENSE ("GPLv3+"); - #define GRUB_INITRD_CMD "initrd" - #endif - -+enum -+ { -+ PLATFORM_EFI, -+ PLATFORM_EMU, -+ PLATFORM_BIOS, -+ }; -+ - #define grub_free(x) ({grub_dprintf("blscfg", "%s freeing %p\n", __func__, x); grub_free(x); }) - - struct keyval -@@ -641,7 +653,7 @@ finish: - struct find_entry_info { - grub_device_t dev; - grub_fs_t fs; -- int efi; -+ int platform; - }; - - /* -@@ -668,13 +680,16 @@ static int find_entry (const char *filename, - !grub_strcmp (filename, "..")) - return 0; - -- if (info->efi && !grub_strcasecmp (filename, "boot")) -+ if (info->platform == PLATFORM_EFI && !grub_strcasecmp (filename, "boot")) - return 0; - - saved_env_buf = grub_malloc (512); - - // set a default blsdir -- if (info->efi) -+ if (info->platform == PLATFORM_EMU) -+ default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, -+ GRUB_BLS_CONFIG_PATH); -+ else if (info->platform == PLATFORM_EFI) - default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, - GRUB_BLS_CONFIG_PATH); - else -@@ -686,7 +701,7 @@ static int find_entry (const char *filename, - /* - * try to load a grubenv from /EFI/wherever/grubenv - */ -- if (info->efi) -+ if (info->platform == PLATFORM_EFI) - grubenv_path = grub_xasprintf ("(%s)/EFI/%s/grubenv", devid, filename); - else - grubenv_path = grub_xasprintf ("(%s)/grub2/grubenv", devid); -@@ -740,7 +755,7 @@ static int find_entry (const char *filename, - goto finish; - - grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); -- if (blsdir[0] != '/' && info->efi) -+ if (blsdir[0] != '/' && info->platform == PLATFORM_EFI) - blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); - else - blsdir = grub_strdup (blsdir); -@@ -818,15 +833,21 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, - { - .dev = NULL, - .fs = NULL, -- .efi = 0, -+ .platform = PLATFORM_BIOS, - }; - - - grub_dprintf ("blscfg", "finding boot\n"); -+ -+#ifdef GRUB_MACHINE_EMU -+ devid = "host"; -+ grub_env_set ("boot", devid); -+#else - devid = grub_env_get ("boot"); - if (!devid) - return grub_error (GRUB_ERR_FILE_NOT_FOUND, - N_("variable `%s' isn't set"), "boot"); -+#endif - - grub_dprintf ("blscfg", "opening %s\n", devid); - dev = grub_device_open (devid); -@@ -844,11 +865,16 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, - info.dev = dev; - info.fs = fs; - #ifdef GRUB_MACHINE_EFI -- info.efi = 1; -+ info.platform = PLATFORM_EFI; - grub_dprintf ("blscfg", "scanning /EFI/\n"); - r = fs->dir (dev, "/EFI/", find_entry, &info); -+#elif GRUB_MACHINE_EMU -+ info.platform = PLATFORM_EMU; -+ grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, -+ GRUB_BLS_CONFIG_PATH); -+ r = fs->dir (dev, "/boot/loader/", -+ find_entry, &info); - #else -- info.efi = 0; - grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); - r = fs->dir (dev, "/", find_entry, &info); - #endif -@@ -862,7 +888,7 @@ finish: - - static grub_extcmd_t cmd; - --GRUB_MOD_INIT(bls) -+GRUB_MOD_INIT(blscfg) - { - grub_dprintf("blscfg", "%s got here\n", __func__); - cmd = grub_register_extcmd ("blscfg", -@@ -873,7 +899,7 @@ GRUB_MOD_INIT(bls) - NULL); - } - --GRUB_MOD_FINI(bls) -+GRUB_MOD_FINI(blscfg) - { - grub_unregister_extcmd (cmd); - } diff --git a/0291-Add-linux-and-initrd-commands-for-grub-emu.patch b/0291-Add-linux-and-initrd-commands-for-grub-emu.patch deleted file mode 100644 index 3df76a1..0000000 --- a/0291-Add-linux-and-initrd-commands-for-grub-emu.patch +++ /dev/null @@ -1,351 +0,0 @@ -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 | 2 +- - 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, 203 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 8e6110e4bb6..7edff60ccd4 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1710,10 +1710,10 @@ module = { - arm = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; - arm64 = loader/efi/linux.c; -+ emu = loader/emu/linux.c; - fdt = lib/fdt.c; - common = loader/linux.c; - common = lib/cmdline.c; -- enable = noemu; - }; - - module = { -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 82012a72fcb..3d3a4a4a975 100644 ---- a/grub-core/kern/emu/misc.c -+++ b/grub-core/kern/emu/misc.c -@@ -37,6 +37,7 @@ - #include - - int verbosity; -+int kexecute; - - void - grub_util_warn (const char *fmt, ...) -@@ -80,7 +81,7 @@ grub_util_error (const char *fmt, ...) - vfprintf (stderr, fmt, ap); - va_end (ap); - fprintf (stderr, ".\n"); -- exit (1); -+ grub_exit (1); - } - - void * -@@ -140,6 +141,9 @@ void - __attribute__ ((noreturn)) - grub_exit (int rc) - { -+#if defined (GRUB_KERNEL) -+ grub_reboot(); -+#endif - exit (rc < 0 ? 1 : rc); - } - #endif -@@ -201,3 +205,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 8e37d5acb42..12c937a1af9 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 df6085bcb7c..a653132e36a 100644 ---- a/include/grub/emu/misc.h -+++ b/include/grub/emu/misc.h -@@ -60,6 +60,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( - void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); - void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (__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 f7b4d29b0b3..75e8715e631 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -275,6 +275,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/0291-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch b/0291-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch new file mode 100644 index 0000000..53bf22e --- /dev/null +++ b/0291-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 6 Feb 2018 11:02:09 +0100 +Subject: [PATCH] Remove duplicated grub_exit() definition for grub-emu + platform + +The grub_exit() function signature was changed on all platforms to take a +return code, but latter on a following commit the grub_exit() for the emu +platform was duplicated. It causes a build error so remove the duplicated +function definition. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/kern/emu/main.c | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/grub-core/kern/emu/main.c b/grub-core/kern/emu/main.c +index 7e47ec81263..55ea5a11ccd 100644 +--- a/grub-core/kern/emu/main.c ++++ b/grub-core/kern/emu/main.c +@@ -72,12 +72,6 @@ grub_exit (int retval __attribute__((unused))) + grub_reboot (); + } + +-void +-grub_exit (int retval __attribute__((unused))) +-{ +- grub_reboot (); +-} +- + void + grub_machine_init (void) + { diff --git a/0292-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch b/0292-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch new file mode 100644 index 0000000..204abbc --- /dev/null +++ b/0292-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/0292-Fix-the-efidir-in-grub-setpassword.patch b/0292-Fix-the-efidir-in-grub-setpassword.patch deleted file mode 100644 index 2d815e2..0000000 --- a/0292-Fix-the-efidir-in-grub-setpassword.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 15 Mar 2018 14:12:54 -0400 -Subject: [PATCH] Fix the efidir in grub-setpassword - -Signed-off-by: Peter Jones ---- - util/grub-setpassword.in | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in -index d7924af5192..cf70257eed6 100644 ---- a/util/grub-setpassword.in -+++ b/util/grub-setpassword.in -@@ -1,7 +1,8 @@ - #!/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/redhat/" | sed 's,//*,/,g'` -+ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` - else - grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` - fi diff --git a/0293-Add-grub2-switch-to-blscfg.patch b/0293-Add-grub2-switch-to-blscfg.patch deleted file mode 100644 index 1c19175..0000000 --- a/0293-Add-grub2-switch-to-blscfg.patch +++ /dev/null @@ -1,345 +0,0 @@ -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 ---- - Makefile.util.def | 7 ++ - .gitignore | 2 + - util/grub-switch-to-blscfg.8 | 25 ++++ - util/grub-switch-to-blscfg.in | 262 ++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 296 insertions(+) - 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 879e8eb98a4..f4fbd250630 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -1348,6 +1348,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/.gitignore b/.gitignore -index 9f258735aaa..4a945596fea 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -117,6 +117,8 @@ grub-*.tar.* - /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 -diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 -new file mode 100644 -index 00000000000..134dfc62a7b ---- /dev/null -+++ b/util/grub-switch-to-blscfg.8 -@@ -0,0 +1,25 @@ -+.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. -+ -+.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..3ae5e4ea8d0 ---- /dev/null -+++ b/util/grub-switch-to-blscfg.in -@@ -0,0 +1,262 @@ -+#! /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@ -+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_editenv=${bindir}/@grub_editenv@ -+etcdefaultgrub=/etc/default/grub -+ -+EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') -+if [ -d /sys/firmware/efi/efivars/ ]; then -+ startlink=/etc/grub2-efi.cfg -+ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` -+ blsdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/loader/entries" | sed 's,//*,/,g'` -+else -+ startlink=/etc/grub2.cfg -+ grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` -+ blsdir=`echo "/@bootdirname@" | sed 's,//*,/,g'` -+fi -+ -+backupsuffix=.bak -+ -+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}" || $# -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 debugname="" -+ local flavor="" -+ -+ if [[ "$kernelver" == *\+* ]] ; then -+ local flavor=-"${kernelver##*+}" -+ if [[ "${flavor}" == "-debug" ]]; then -+ local debugname=" with debugging" -+ fi -+ fi -+ ( -+ source /etc/os-release -+ -+ cat <"${bls_target}" -+ fi -+done -+ -+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 -+ 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,' \ -+ /etc/default/grub -+ gettext_printf "Updating %s failed\n" "${GRUB_CONFIG_FILE}" -+ exit 1 -+ fi -+fi -+ -+# Bye. -+exit 0 diff --git a/0293-Enable-blscfg-command-for-the-emu-platform.patch b/0293-Enable-blscfg-command-for-the-emu-platform.patch new file mode 100644 index 0000000..ba9207e --- /dev/null +++ b/0293-Enable-blscfg-command-for-the-emu-platform.patch @@ -0,0 +1,164 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 2 Feb 2018 11:36:29 +0100 +Subject: [PATCH] Enable blscfg command for the emu platform + +Allow grub-emu to call a blscfg command. This may be useful for platforms +that don't support GRUB, so grub-emu can be used to parse the BLS configs +and kexec a new kernel using that information. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/Makefile.core.def | 1 + + grub-core/commands/blscfg.c | 46 +++++++++++++++++++++++++++++++++++---------- + 2 files changed, 37 insertions(+), 10 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index fb661b4abf8..8e6110e4bb6 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -778,6 +778,7 @@ module = { + common = commands/blscfg.c; + enable = efi; + enable = i386_pc; ++ enable = emu; + }; + + module = { +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 9ab45631465..e5617c3bc6c 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -37,7 +37,12 @@ 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 ++ + #ifdef GRUB_MACHINE_EFI + #define GRUB_LINUX_CMD "linuxefi" + #define GRUB_INITRD_CMD "initrdefi" +@@ -46,6 +51,13 @@ GRUB_MOD_LICENSE ("GPLv3+"); + #define GRUB_INITRD_CMD "initrd" + #endif + ++enum ++ { ++ PLATFORM_EFI, ++ PLATFORM_EMU, ++ PLATFORM_BIOS, ++ }; ++ + #define grub_free(x) ({grub_dprintf("blscfg", "%s freeing %p\n", __func__, x); grub_free(x); }) + + struct keyval +@@ -641,7 +653,7 @@ finish: + struct find_entry_info { + grub_device_t dev; + grub_fs_t fs; +- int efi; ++ int platform; + }; + + /* +@@ -668,13 +680,16 @@ static int find_entry (const char *filename, + !grub_strcmp (filename, "..")) + return 0; + +- if (info->efi && !grub_strcasecmp (filename, "boot")) ++ if (info->platform == PLATFORM_EFI && !grub_strcasecmp (filename, "boot")) + return 0; + + saved_env_buf = grub_malloc (512); + + // set a default blsdir +- if (info->efi) ++ if (info->platform == PLATFORM_EMU) ++ default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, ++ GRUB_BLS_CONFIG_PATH); ++ else if (info->platform == PLATFORM_EFI) + default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, + GRUB_BLS_CONFIG_PATH); + else +@@ -686,7 +701,7 @@ static int find_entry (const char *filename, + /* + * try to load a grubenv from /EFI/wherever/grubenv + */ +- if (info->efi) ++ if (info->platform == PLATFORM_EFI) + grubenv_path = grub_xasprintf ("(%s)/EFI/%s/grubenv", devid, filename); + else + grubenv_path = grub_xasprintf ("(%s)/grub2/grubenv", devid); +@@ -740,7 +755,7 @@ static int find_entry (const char *filename, + goto finish; + + grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); +- if (blsdir[0] != '/' && info->efi) ++ if (blsdir[0] != '/' && info->platform == PLATFORM_EFI) + blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); + else + blsdir = grub_strdup (blsdir); +@@ -818,15 +833,21 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, + { + .dev = NULL, + .fs = NULL, +- .efi = 0, ++ .platform = PLATFORM_BIOS, + }; + + + grub_dprintf ("blscfg", "finding boot\n"); ++ ++#ifdef GRUB_MACHINE_EMU ++ devid = "host"; ++ grub_env_set ("boot", devid); ++#else + devid = grub_env_get ("boot"); + if (!devid) + return grub_error (GRUB_ERR_FILE_NOT_FOUND, + N_("variable `%s' isn't set"), "boot"); ++#endif + + grub_dprintf ("blscfg", "opening %s\n", devid); + dev = grub_device_open (devid); +@@ -844,11 +865,16 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, + info.dev = dev; + info.fs = fs; + #ifdef GRUB_MACHINE_EFI +- info.efi = 1; ++ info.platform = PLATFORM_EFI; + grub_dprintf ("blscfg", "scanning /EFI/\n"); + r = fs->dir (dev, "/EFI/", find_entry, &info); ++#elif GRUB_MACHINE_EMU ++ info.platform = PLATFORM_EMU; ++ grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, ++ GRUB_BLS_CONFIG_PATH); ++ r = fs->dir (dev, "/boot/loader/", ++ find_entry, &info); + #else +- info.efi = 0; + grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); + r = fs->dir (dev, "/", find_entry, &info); + #endif +@@ -862,7 +888,7 @@ finish: + + static grub_extcmd_t cmd; + +-GRUB_MOD_INIT(bls) ++GRUB_MOD_INIT(blscfg) + { + grub_dprintf("blscfg", "%s got here\n", __func__); + cmd = grub_register_extcmd ("blscfg", +@@ -873,7 +899,7 @@ GRUB_MOD_INIT(bls) + NULL); + } + +-GRUB_MOD_FINI(bls) ++GRUB_MOD_FINI(blscfg) + { + grub_unregister_extcmd (cmd); + } diff --git a/0294-Add-grub_debug_enabled.patch b/0294-Add-grub_debug_enabled.patch deleted file mode 100644 index d8e4bde..0000000 --- a/0294-Add-grub_debug_enabled.patch +++ /dev/null @@ -1,60 +0,0 @@ -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 cbfae75a1b4..f7473c154f0 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/0294-Add-linux-and-initrd-commands-for-grub-emu.patch b/0294-Add-linux-and-initrd-commands-for-grub-emu.patch new file mode 100644 index 0000000..3df76a1 --- /dev/null +++ b/0294-Add-linux-and-initrd-commands-for-grub-emu.patch @@ -0,0 +1,351 @@ +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 | 2 +- + 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, 203 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 8e6110e4bb6..7edff60ccd4 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1710,10 +1710,10 @@ module = { + arm = loader/arm/linux.c; + arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; ++ emu = loader/emu/linux.c; + fdt = lib/fdt.c; + common = loader/linux.c; + common = lib/cmdline.c; +- enable = noemu; + }; + + module = { +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 82012a72fcb..3d3a4a4a975 100644 +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -37,6 +37,7 @@ + #include + + int verbosity; ++int kexecute; + + void + grub_util_warn (const char *fmt, ...) +@@ -80,7 +81,7 @@ grub_util_error (const char *fmt, ...) + vfprintf (stderr, fmt, ap); + va_end (ap); + fprintf (stderr, ".\n"); +- exit (1); ++ grub_exit (1); + } + + void * +@@ -140,6 +141,9 @@ void + __attribute__ ((noreturn)) + grub_exit (int rc) + { ++#if defined (GRUB_KERNEL) ++ grub_reboot(); ++#endif + exit (rc < 0 ? 1 : rc); + } + #endif +@@ -201,3 +205,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 8e37d5acb42..12c937a1af9 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 df6085bcb7c..a653132e36a 100644 +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -60,6 +60,9 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...) __attribute__ ((format ( + void EXPORT_FUNC(grub_util_info) (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); + void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((format (__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 f7b4d29b0b3..75e8715e631 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -275,6 +275,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/0295-Fix-the-efidir-in-grub-setpassword.patch b/0295-Fix-the-efidir-in-grub-setpassword.patch new file mode 100644 index 0000000..2d815e2 --- /dev/null +++ b/0295-Fix-the-efidir-in-grub-setpassword.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 15 Mar 2018 14:12:54 -0400 +Subject: [PATCH] Fix the efidir in grub-setpassword + +Signed-off-by: Peter Jones +--- + util/grub-setpassword.in | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in +index d7924af5192..cf70257eed6 100644 +--- a/util/grub-setpassword.in ++++ b/util/grub-setpassword.in +@@ -1,7 +1,8 @@ + #!/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/redhat/" | sed 's,//*,/,g'` ++ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` + else + grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` + fi diff --git a/0295-make-better-backtraces.patch b/0295-make-better-backtraces.patch deleted file mode 100644 index 7597cd4..0000000 --- a/0295-make-better-backtraces.patch +++ /dev/null @@ -1,884 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Mon, 6 Nov 2017 18:31:56 -0500 -Subject: [PATCH] make better backtraces - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 15 ++-- - 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 | 95 +++++++++++++++++++++++++ - grub-core/kern/dl.c | 45 ++++++++++++ - grub-core/kern/i386/backtrace.c | 121 ++++++++++++++++++++++++++++++++ - 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 + - 23 files changed, 402 insertions(+), 166 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/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 7edff60ccd4..1153ec4d2cf 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -130,6 +130,12 @@ kernel = { - common = kern/rescue_reader.c; - common = kern/term.c; - common = kern/qsort.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; -@@ -176,9 +182,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; - -@@ -2288,13 +2291,11 @@ module = { - - module = { - name = backtrace; -- x86 = 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; - 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..bd6a783f6d0 ---- /dev/null -+++ b/grub-core/kern/backtrace.c -@@ -0,0 +1,95 @@ -+/* -+ * 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) -+{ -+ 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 -+ 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 621070918d4..5028d157c46 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..c4f7e3f0e90 ---- /dev/null -+++ b/grub-core/kern/i386/backtrace.c -@@ -0,0 +1,121 @@ -+/* -+ * 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; -+ -+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 e01bc6eab19..e731a57a47b 100644 ---- a/grub-core/kern/ieee1275/init.c -+++ b/grub-core/kern/ieee1275/init.c -@@ -60,7 +60,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 b1ed3c33317..7b5bfb07ce6 100644 ---- a/include/grub/dl.h -+++ b/include/grub/dl.h -@@ -244,6 +244,8 @@ grub_dl_get (const char *name) - - #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 ecd88ca72c6..ae69218af20 100644 ---- a/include/grub/kernel.h -+++ b/include/grub/kernel.h -@@ -108,6 +108,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 75e8715e631..5c7a2c8f808 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/0296-Add-grub2-switch-to-blscfg.patch b/0296-Add-grub2-switch-to-blscfg.patch new file mode 100644 index 0000000..1c19175 --- /dev/null +++ b/0296-Add-grub2-switch-to-blscfg.patch @@ -0,0 +1,345 @@ +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 +--- + Makefile.util.def | 7 ++ + .gitignore | 2 + + util/grub-switch-to-blscfg.8 | 25 ++++ + util/grub-switch-to-blscfg.in | 262 ++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 296 insertions(+) + 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 879e8eb98a4..f4fbd250630 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -1348,6 +1348,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/.gitignore b/.gitignore +index 9f258735aaa..4a945596fea 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -117,6 +117,8 @@ grub-*.tar.* + /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 +diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 +new file mode 100644 +index 00000000000..134dfc62a7b +--- /dev/null ++++ b/util/grub-switch-to-blscfg.8 +@@ -0,0 +1,25 @@ ++.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. ++ ++.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..3ae5e4ea8d0 +--- /dev/null ++++ b/util/grub-switch-to-blscfg.in +@@ -0,0 +1,262 @@ ++#! /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@ ++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_editenv=${bindir}/@grub_editenv@ ++etcdefaultgrub=/etc/default/grub ++ ++EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') ++if [ -d /sys/firmware/efi/efivars/ ]; then ++ startlink=/etc/grub2-efi.cfg ++ grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` ++ blsdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/loader/entries" | sed 's,//*,/,g'` ++else ++ startlink=/etc/grub2.cfg ++ grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` ++ blsdir=`echo "/@bootdirname@" | sed 's,//*,/,g'` ++fi ++ ++backupsuffix=.bak ++ ++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}" || $# -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 debugname="" ++ local flavor="" ++ ++ if [[ "$kernelver" == *\+* ]] ; then ++ local flavor=-"${kernelver##*+}" ++ if [[ "${flavor}" == "-debug" ]]; then ++ local debugname=" with debugging" ++ fi ++ fi ++ ( ++ source /etc/os-release ++ ++ cat <"${bls_target}" ++ fi ++done ++ ++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 ++ 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,' \ ++ /etc/default/grub ++ gettext_printf "Updating %s failed\n" "${GRUB_CONFIG_FILE}" ++ exit 1 ++ fi ++fi ++ ++# Bye. ++exit 0 diff --git a/0296-normal-don-t-draw-our-startup-message-if-debug-is-se.patch b/0296-normal-don-t-draw-our-startup-message-if-debug-is-se.patch deleted file mode 100644 index d2a8fd0..0000000 --- a/0296-normal-don-t-draw-our-startup-message-if-debug-is-se.patch +++ /dev/null @@ -1,23 +0,0 @@ -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 b69f9e738fa..04ae9ed02f6 100644 ---- a/grub-core/normal/main.c -+++ b/grub-core/normal/main.c -@@ -419,6 +419,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/0297-Add-grub_debug_enabled.patch b/0297-Add-grub_debug_enabled.patch new file mode 100644 index 0000000..d8e4bde --- /dev/null +++ b/0297-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 cbfae75a1b4..f7473c154f0 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/0297-Work-around-some-minor-include-path-weirdnesses.patch b/0297-Work-around-some-minor-include-path-weirdnesses.patch deleted file mode 100644 index 460d792..0000000 --- a/0297-Work-around-some-minor-include-path-weirdnesses.patch +++ /dev/null @@ -1,137 +0,0 @@ -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/0298-Make-it-possible-to-enabled-build-id-sha1.patch b/0298-Make-it-possible-to-enabled-build-id-sha1.patch deleted file mode 100644 index 2ed085c..0000000 --- a/0298-Make-it-possible-to-enabled-build-id-sha1.patch +++ /dev/null @@ -1,61 +0,0 @@ -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 f69f8986791..359cac3c26b 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -1386,7 +1386,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/0298-make-better-backtraces.patch b/0298-make-better-backtraces.patch new file mode 100644 index 0000000..7597cd4 --- /dev/null +++ b/0298-make-better-backtraces.patch @@ -0,0 +1,884 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 6 Nov 2017 18:31:56 -0500 +Subject: [PATCH] make better backtraces + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 15 ++-- + 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 | 95 +++++++++++++++++++++++++ + grub-core/kern/dl.c | 45 ++++++++++++ + grub-core/kern/i386/backtrace.c | 121 ++++++++++++++++++++++++++++++++ + 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 + + 23 files changed, 402 insertions(+), 166 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/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 7edff60ccd4..1153ec4d2cf 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -130,6 +130,12 @@ kernel = { + common = kern/rescue_reader.c; + common = kern/term.c; + common = kern/qsort.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; +@@ -176,9 +182,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; + +@@ -2288,13 +2291,11 @@ module = { + + module = { + name = backtrace; +- x86 = 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; + 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..bd6a783f6d0 +--- /dev/null ++++ b/grub-core/kern/backtrace.c +@@ -0,0 +1,95 @@ ++/* ++ * 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) ++{ ++ 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 ++ 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 621070918d4..5028d157c46 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..c4f7e3f0e90 +--- /dev/null ++++ b/grub-core/kern/i386/backtrace.c +@@ -0,0 +1,121 @@ ++/* ++ * 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; ++ ++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 e01bc6eab19..e731a57a47b 100644 +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -60,7 +60,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 b1ed3c33317..7b5bfb07ce6 100644 +--- a/include/grub/dl.h ++++ b/include/grub/dl.h +@@ -244,6 +244,8 @@ grub_dl_get (const char *name) + + #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 ecd88ca72c6..ae69218af20 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -108,6 +108,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 75e8715e631..5c7a2c8f808 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/0299-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch b/0299-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch deleted file mode 100644 index 8bd5548..0000000 --- a/0299-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch +++ /dev/null @@ -1,56 +0,0 @@ -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 f7473c154f0..5f1c1c1be4e 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/0299-normal-don-t-draw-our-startup-message-if-debug-is-se.patch b/0299-normal-don-t-draw-our-startup-message-if-debug-is-se.patch new file mode 100644 index 0000000..d2a8fd0 --- /dev/null +++ b/0299-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 b69f9e738fa..04ae9ed02f6 100644 +--- a/grub-core/normal/main.c ++++ b/grub-core/normal/main.c +@@ -419,6 +419,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/0300-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0300-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch deleted file mode 100644 index 799eaa4..0000000 --- a/0300-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch +++ /dev/null @@ -1,178 +0,0 @@ -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 5028d157c46..eb8b969cded 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 bcae7f4699d..a2a732ffc0d 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 1f31e09b78a..29b4dbac1e4 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -127,7 +127,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, - void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); - #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/0300-Work-around-some-minor-include-path-weirdnesses.patch b/0300-Work-around-some-minor-include-path-weirdnesses.patch new file mode 100644 index 0000000..460d792 --- /dev/null +++ b/0300-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/0301-Make-it-possible-to-enabled-build-id-sha1.patch b/0301-Make-it-possible-to-enabled-build-id-sha1.patch new file mode 100644 index 0000000..2ed085c --- /dev/null +++ b/0301-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 f69f8986791..359cac3c26b 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -1386,7 +1386,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/0301-Only-attempt-to-scan-different-BLS-directories-on-EF.patch b/0301-Only-attempt-to-scan-different-BLS-directories-on-EF.patch deleted file mode 100644 index b53d4c2..0000000 --- a/0301-Only-attempt-to-scan-different-BLS-directories-on-EF.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 3 Apr 2018 15:42:47 +0200 -Subject: [PATCH] Only attempt to scan different BLS directories on EFI - machines - -Current BLS support attempted to scan for BLS directories, but this only -makes sense on EFI, where BLS fragments are in /loader/$vendor/entries. - -For BIOS, only either the default /loader/entries path should be scanned -or the BLS directory defined in the blsdir GRUB 2 environment variable. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 9 ++++----- - 1 file changed, 4 insertions(+), 5 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index e5617c3bc6c..c0973ff83ea 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -676,8 +676,8 @@ static int find_entry (const char *filename, - const char *devid = grub_env_get ("boot"); - - grub_dprintf("blscfg", "%s got here\n", __func__); -- if (!grub_strcmp (filename, ".") || -- !grub_strcmp (filename, "..")) -+ if (filename && (!grub_strcmp (filename, ".") || -+ !grub_strcmp (filename, ".."))) - return 0; - - if (info->platform == PLATFORM_EFI && !grub_strcasecmp (filename, "boot")) -@@ -872,11 +872,10 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, - info.platform = PLATFORM_EMU; - grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, - GRUB_BLS_CONFIG_PATH); -- r = fs->dir (dev, "/boot/loader/", -- find_entry, &info); -+ find_entry(NULL, NULL, &info); - #else - grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); -- r = fs->dir (dev, "/", find_entry, &info); -+ find_entry(NULL, NULL, &info); - #endif - - finish: diff --git a/0302-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch b/0302-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch new file mode 100644 index 0000000..8bd5548 --- /dev/null +++ b/0302-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 f7473c154f0..5f1c1c1be4e 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/0302-Core-TPM-support.patch b/0302-Core-TPM-support.patch deleted file mode 100644 index 730f01a..0000000 --- a/0302-Core-TPM-support.patch +++ /dev/null @@ -1,786 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Tue, 14 Jul 2015 17:06:35 -0700 -Subject: [PATCH] Core TPM support - -Add support for performing basic TPM measurements. Right now this only -supports extending PCRs statically and only on UEFI and BIOS systems, but -will measure all modules as they're loaded. ---- - grub-core/Makefile.core.def | 3 + - grub-core/kern/dl.c | 3 + - grub-core/kern/efi/tpm.c | 282 +++++++++++++++++++++++++++++++++++++++++++ - grub-core/kern/i386/pc/tpm.c | 132 ++++++++++++++++++++ - grub-core/kern/tpm.c | 13 ++ - include/grub/efi/tpm.h | 153 +++++++++++++++++++++++ - include/grub/tpm.h | 91 ++++++++++++++ - grub-core/Makefile.am | 1 + - 8 files changed, 678 insertions(+) - create mode 100644 grub-core/kern/efi/tpm.c - create mode 100644 grub-core/kern/i386/pc/tpm.c - create mode 100644 grub-core/kern/tpm.c - create mode 100644 include/grub/efi/tpm.h - create mode 100644 include/grub/tpm.h - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 1153ec4d2cf..334ca3fcf46 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -131,6 +131,7 @@ kernel = { - common = kern/term.c; - common = kern/qsort.c; - common = kern/backtrace.c; -+ common = kern/tpm.c; - - x86 = kern/i386/backtrace.c; - i386_xen = kern/i386/backtrace.c; -@@ -199,6 +200,7 @@ kernel = { - efi = kern/acpi.c; - efi = kern/efi/acpi.c; - efi = lib/envblk.c; -+ efi = kern/efi/tpm.c; - i386_coreboot = kern/i386/pc/acpi.c; - i386_multiboot = kern/i386/pc/acpi.c; - i386_coreboot = kern/acpi.c; -@@ -246,6 +248,7 @@ kernel = { - - i386_pc = kern/i386/pc/init.c; - i386_pc = kern/i386/pc/mmap.c; -+ i386_pc = kern/i386/pc/tpm.c; - i386_pc = term/i386/pc/console.c; - - i386_qemu = bus/pci.c; -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index eb8b969cded..387d1e6446d 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include - - /* Platforms where modules are in a readonly area of memory. */ - #if defined(GRUB_MACHINE_QEMU) -@@ -829,6 +830,8 @@ grub_dl_load_file (const char *filename) - opens of the same device. */ - grub_file_close (file); - -+ grub_tpm_measure(core, size, GRUB_TPM_PCR, filename); -+ - mod = grub_dl_load_core (core, size); - grub_free (core); - if (! mod) -diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c -new file mode 100644 -index 00000000000..c9fb3c133f3 ---- /dev/null -+++ b/grub-core/kern/efi/tpm.c -@@ -0,0 +1,282 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+static grub_efi_guid_t tpm_guid = EFI_TPM_GUID; -+static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID; -+ -+static grub_efi_boolean_t grub_tpm_present(grub_efi_tpm_protocol_t *tpm) -+{ -+ grub_efi_status_t status; -+ TCG_EFI_BOOT_SERVICE_CAPABILITY caps; -+ grub_uint32_t flags; -+ grub_efi_physical_address_t eventlog, lastevent; -+ -+ caps.Size = (grub_uint8_t)sizeof(caps); -+ -+ status = efi_call_5(tpm->status_check, tpm, &caps, &flags, &eventlog, -+ &lastevent); -+ -+ if (status != GRUB_EFI_SUCCESS || caps.TPMDeactivatedFlag -+ || !caps.TPMPresentFlag) -+ return 0; -+ -+ return 1; -+} -+ -+static grub_efi_boolean_t grub_tpm2_present(grub_efi_tpm2_protocol_t *tpm) -+{ -+ grub_efi_status_t status; -+ EFI_TCG2_BOOT_SERVICE_CAPABILITY caps; -+ -+ caps.Size = (grub_uint8_t)sizeof(caps); -+ -+ status = efi_call_2(tpm->get_capability, tpm, &caps); -+ -+ if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag) -+ return 0; -+ -+ return 1; -+} -+ -+static grub_efi_boolean_t grub_tpm_handle_find(grub_efi_handle_t *tpm_handle, -+ grub_efi_uint8_t *protocol_version) -+{ -+ grub_efi_handle_t *handles; -+ grub_efi_uintn_t num_handles; -+ -+ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm_guid, NULL, -+ &num_handles); -+ if (handles && num_handles > 0) { -+ *tpm_handle = handles[0]; -+ *protocol_version = 1; -+ return 1; -+ } -+ -+ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm2_guid, NULL, -+ &num_handles); -+ if (handles && num_handles > 0) { -+ *tpm_handle = handles[0]; -+ *protocol_version = 2; -+ return 1; -+ } -+ -+ return 0; -+} -+ -+static grub_err_t -+grub_tpm1_execute(grub_efi_handle_t tpm_handle, -+ PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf) -+{ -+ grub_efi_status_t status; -+ grub_efi_tpm_protocol_t *tpm; -+ grub_uint32_t inhdrsize = sizeof(*inbuf) - sizeof(inbuf->TPMOperandIn); -+ grub_uint32_t outhdrsize = sizeof(*outbuf) - sizeof(outbuf->TPMOperandOut); -+ -+ tpm = grub_efi_open_protocol (tpm_handle, &tpm_guid, -+ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); -+ -+ if (!grub_tpm_present(tpm)) -+ return 0; -+ -+ /* UEFI TPM protocol takes the raw operand block, no param block header */ -+ status = efi_call_5 (tpm->pass_through_to_tpm, tpm, -+ inbuf->IPBLength - inhdrsize, inbuf->TPMOperandIn, -+ outbuf->OPBLength - outhdrsize, outbuf->TPMOperandOut); -+ -+ switch (status) { -+ case GRUB_EFI_SUCCESS: -+ return 0; -+ case GRUB_EFI_DEVICE_ERROR: -+ return grub_error (GRUB_ERR_IO, N_("Command failed")); -+ case GRUB_EFI_INVALID_PARAMETER: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); -+ case GRUB_EFI_BUFFER_TOO_SMALL: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); -+ case GRUB_EFI_NOT_FOUND: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); -+ default: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); -+ } -+} -+ -+static grub_err_t -+grub_tpm2_execute(grub_efi_handle_t tpm_handle, -+ PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf) -+{ -+ grub_efi_status_t status; -+ grub_efi_tpm2_protocol_t *tpm; -+ grub_uint32_t inhdrsize = sizeof(*inbuf) - sizeof(inbuf->TPMOperandIn); -+ grub_uint32_t outhdrsize = sizeof(*outbuf) - sizeof(outbuf->TPMOperandOut); -+ -+ tpm = grub_efi_open_protocol (tpm_handle, &tpm2_guid, -+ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); -+ -+ if (!grub_tpm2_present(tpm)) -+ return 0; -+ -+ /* UEFI TPM protocol takes the raw operand block, no param block header */ -+ status = efi_call_5 (tpm->submit_command, tpm, -+ inbuf->IPBLength - inhdrsize, inbuf->TPMOperandIn, -+ outbuf->OPBLength - outhdrsize, outbuf->TPMOperandOut); -+ -+ switch (status) { -+ case GRUB_EFI_SUCCESS: -+ return 0; -+ case GRUB_EFI_DEVICE_ERROR: -+ return grub_error (GRUB_ERR_IO, N_("Command failed")); -+ case GRUB_EFI_INVALID_PARAMETER: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); -+ case GRUB_EFI_BUFFER_TOO_SMALL: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); -+ case GRUB_EFI_NOT_FOUND: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); -+ default: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); -+ } -+} -+ -+grub_err_t -+grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf) -+{ -+ grub_efi_handle_t tpm_handle; -+ grub_uint8_t protocol_version; -+ -+ /* It's not a hard failure for there to be no TPM */ -+ if (!grub_tpm_handle_find(&tpm_handle, &protocol_version)) -+ return 0; -+ -+ if (protocol_version == 1) { -+ return grub_tpm1_execute(tpm_handle, inbuf, outbuf); -+ } else { -+ return grub_tpm2_execute(tpm_handle, inbuf, outbuf); -+ } -+} -+ -+typedef struct { -+ grub_uint32_t pcrindex; -+ grub_uint32_t eventtype; -+ grub_uint8_t digest[20]; -+ grub_uint32_t eventsize; -+ grub_uint8_t event[1]; -+} Event; -+ -+ -+static grub_err_t -+grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, -+ grub_size_t size, grub_uint8_t pcr, -+ const char *description) -+{ -+ Event *event; -+ grub_efi_status_t status; -+ grub_efi_tpm_protocol_t *tpm; -+ grub_efi_physical_address_t lastevent; -+ grub_uint32_t algorithm; -+ grub_uint32_t eventnum = 0; -+ -+ tpm = grub_efi_open_protocol (tpm_handle, &tpm_guid, -+ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); -+ -+ if (!grub_tpm_present(tpm)) -+ return 0; -+ -+ event = grub_zalloc(sizeof (Event) + grub_strlen(description) + 1); -+ if (!event) -+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ N_("cannot allocate TPM event buffer")); -+ -+ event->pcrindex = pcr; -+ event->eventtype = EV_IPL; -+ event->eventsize = grub_strlen(description) + 1; -+ grub_memcpy(event->event, description, event->eventsize); -+ -+ algorithm = TCG_ALG_SHA; -+ status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size, -+ algorithm, event, &eventnum, &lastevent); -+ -+ switch (status) { -+ case GRUB_EFI_SUCCESS: -+ return 0; -+ case GRUB_EFI_DEVICE_ERROR: -+ return grub_error (GRUB_ERR_IO, N_("Command failed")); -+ case GRUB_EFI_INVALID_PARAMETER: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); -+ case GRUB_EFI_BUFFER_TOO_SMALL: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); -+ case GRUB_EFI_NOT_FOUND: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); -+ default: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); -+ } -+} -+ -+static grub_err_t -+grub_tpm2_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, -+ grub_size_t size, grub_uint8_t pcr, -+ const char *description) -+{ -+ EFI_TCG2_EVENT *event; -+ grub_efi_status_t status; -+ grub_efi_tpm2_protocol_t *tpm; -+ -+ tpm = grub_efi_open_protocol (tpm_handle, &tpm2_guid, -+ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); -+ -+ if (!grub_tpm2_present(tpm)) -+ return 0; -+ -+ event = grub_zalloc(sizeof (EFI_TCG2_EVENT) + grub_strlen(description) + 1); -+ if (!event) -+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ N_("cannot allocate TPM event buffer")); -+ -+ event->Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER); -+ event->Header.HeaderVersion = 1; -+ event->Header.PCRIndex = pcr; -+ event->Header.EventType = EV_IPL; -+ event->Size = sizeof(*event) - sizeof(event->Event) + grub_strlen(description) + 1; -+ grub_memcpy(event->Event, description, grub_strlen(description) + 1); -+ -+ status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf, -+ (grub_uint64_t) size, event); -+ -+ switch (status) { -+ case GRUB_EFI_SUCCESS: -+ return 0; -+ case GRUB_EFI_DEVICE_ERROR: -+ return grub_error (GRUB_ERR_IO, N_("Command failed")); -+ case GRUB_EFI_INVALID_PARAMETER: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); -+ case GRUB_EFI_BUFFER_TOO_SMALL: -+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); -+ case GRUB_EFI_NOT_FOUND: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); -+ default: -+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); -+ } -+} -+ -+grub_err_t -+grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, -+ const char *description) -+{ -+ grub_efi_handle_t tpm_handle; -+ grub_efi_uint8_t protocol_version; -+ -+ if (!grub_tpm_handle_find(&tpm_handle, &protocol_version)) -+ return 0; -+ -+ if (protocol_version == 1) { -+ return grub_tpm1_log_event(tpm_handle, buf, size, pcr, description); -+ } else { -+ return grub_tpm2_log_event(tpm_handle, buf, size, pcr, description); -+ } -+} -diff --git a/grub-core/kern/i386/pc/tpm.c b/grub-core/kern/i386/pc/tpm.c -new file mode 100644 -index 00000000000..8c6c1e6ece2 ---- /dev/null -+++ b/grub-core/kern/i386/pc/tpm.c -@@ -0,0 +1,132 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define TCPA_MAGIC 0x41504354 -+ -+int tpm_present(void); -+ -+int tpm_present(void) -+{ -+ struct grub_bios_int_registers regs; -+ -+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; -+ regs.eax = 0xbb00; -+ regs.ebx = TCPA_MAGIC; -+ grub_bios_interrupt (0x1a, ®s); -+ -+ if (regs.eax == 0) -+ return 1; -+ -+ return 0; -+} -+ -+grub_err_t -+grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf) -+{ -+ struct grub_bios_int_registers regs; -+ grub_addr_t inaddr, outaddr; -+ -+ if (!tpm_present()) -+ return 0; -+ -+ inaddr = (grub_addr_t) inbuf; -+ outaddr = (grub_addr_t) outbuf; -+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; -+ regs.eax = 0xbb02; -+ regs.ebx = TCPA_MAGIC; -+ regs.ecx = 0; -+ regs.edx = 0; -+ regs.es = (inaddr & 0xffff0000) >> 4; -+ regs.edi = inaddr & 0xffff; -+ regs.ds = outaddr >> 4; -+ regs.esi = outaddr & 0xf; -+ -+ grub_bios_interrupt (0x1a, ®s); -+ -+ if (regs.eax) -+ return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); -+ -+ return 0; -+} -+ -+typedef struct { -+ grub_uint32_t pcrindex; -+ grub_uint32_t eventtype; -+ grub_uint8_t digest[20]; -+ grub_uint32_t eventdatasize; -+ grub_uint8_t event[0]; -+} GRUB_PACKED Event; -+ -+typedef struct { -+ grub_uint16_t ipblength; -+ grub_uint16_t reserved; -+ grub_uint32_t hashdataptr; -+ grub_uint32_t hashdatalen; -+ grub_uint32_t pcr; -+ grub_uint32_t reserved2; -+ grub_uint32_t logdataptr; -+ grub_uint32_t logdatalen; -+} GRUB_PACKED EventIncoming; -+ -+typedef struct { -+ grub_uint16_t opblength; -+ grub_uint16_t reserved; -+ grub_uint32_t eventnum; -+ grub_uint8_t hashvalue[20]; -+} GRUB_PACKED EventOutgoing; -+ -+grub_err_t -+grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, -+ const char *description) -+{ -+ struct grub_bios_int_registers regs; -+ EventIncoming incoming; -+ EventOutgoing outgoing; -+ Event *event; -+ grub_uint32_t datalength; -+ -+ if (!tpm_present()) -+ return 0; -+ -+ datalength = grub_strlen(description); -+ event = grub_zalloc(datalength + sizeof(Event)); -+ if (!event) -+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ N_("cannot allocate TPM event buffer")); -+ -+ event->pcrindex = pcr; -+ event->eventtype = 0x0d; -+ event->eventdatasize = grub_strlen(description); -+ grub_memcpy(event->event, description, datalength); -+ -+ incoming.ipblength = sizeof(incoming); -+ incoming.hashdataptr = (grub_uint32_t)buf; -+ incoming.hashdatalen = size; -+ incoming.pcr = pcr; -+ incoming.logdataptr = (grub_uint32_t)event; -+ incoming.logdatalen = datalength + sizeof(Event); -+ -+ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; -+ regs.eax = 0xbb01; -+ regs.ebx = TCPA_MAGIC; -+ regs.ecx = 0; -+ regs.edx = 0; -+ regs.es = (((grub_addr_t) &incoming) & 0xffff0000) >> 4; -+ regs.edi = ((grub_addr_t) &incoming) & 0xffff; -+ regs.ds = (((grub_addr_t) &outgoing) & 0xffff0000) >> 4; -+ regs.esi = ((grub_addr_t) &outgoing) & 0xffff; -+ -+ grub_bios_interrupt (0x1a, ®s); -+ -+ grub_free(event); -+ -+ if (regs.eax) -+ return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); -+ -+ return 0; -+} -diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c -new file mode 100644 -index 00000000000..1a991876c83 ---- /dev/null -+++ b/grub-core/kern/tpm.c -@@ -0,0 +1,13 @@ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+grub_err_t -+grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, -+ const char *description) -+{ -+ return grub_tpm_log_event(buf, size, pcr, description); -+} -diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h -new file mode 100644 -index 00000000000..e2aff4a3c22 ---- /dev/null -+++ b/include/grub/efi/tpm.h -@@ -0,0 +1,153 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2015 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_TPM_HEADER -+#define GRUB_EFI_TPM_HEADER 1 -+ -+#define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }}; -+#define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }}; -+ -+typedef struct { -+ grub_efi_uint8_t Major; -+ grub_efi_uint8_t Minor; -+ grub_efi_uint8_t RevMajor; -+ grub_efi_uint8_t RevMinor; -+} TCG_VERSION; -+ -+typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY { -+ grub_efi_uint8_t Size; /// Size of this structure. -+ TCG_VERSION StructureVersion; -+ TCG_VERSION ProtocolSpecVersion; -+ grub_efi_uint8_t HashAlgorithmBitmap; /// Hash algorithms . -+ char TPMPresentFlag; /// 00h = TPM not present. -+ char TPMDeactivatedFlag; /// 01h = TPM currently deactivated. -+} TCG_EFI_BOOT_SERVICE_CAPABILITY; -+ -+typedef struct { -+ grub_efi_uint32_t PCRIndex; -+ grub_efi_uint32_t EventType; -+ grub_efi_uint8_t digest[20]; -+ grub_efi_uint32_t EventSize; -+ grub_efi_uint8_t Event[1]; -+} TCG_PCR_EVENT; -+ -+struct grub_efi_tpm_protocol -+{ -+ grub_efi_status_t (*status_check) (struct grub_efi_tpm_protocol *this, -+ TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability, -+ grub_efi_uint32_t *TCGFeatureFlags, -+ grub_efi_physical_address_t *EventLogLocation, -+ grub_efi_physical_address_t *EventLogLastEntry); -+ grub_efi_status_t (*hash_all) (struct grub_efi_tpm_protocol *this, -+ grub_efi_uint8_t *HashData, -+ grub_efi_uint64_t HashLen, -+ grub_efi_uint32_t AlgorithmId, -+ grub_efi_uint64_t *HashedDataLen, -+ grub_efi_uint8_t **HashedDataResult); -+ grub_efi_status_t (*log_event) (struct grub_efi_tpm_protocol *this, -+ TCG_PCR_EVENT *TCGLogData, -+ grub_efi_uint32_t *EventNumber, -+ grub_efi_uint32_t Flags); -+ grub_efi_status_t (*pass_through_to_tpm) (struct grub_efi_tpm_protocol *this, -+ grub_efi_uint32_t TpmInputParameterBlockSize, -+ grub_efi_uint8_t *TpmInputParameterBlock, -+ grub_efi_uint32_t TpmOutputParameterBlockSize, -+ grub_efi_uint8_t *TpmOutputParameterBlock); -+ grub_efi_status_t (*log_extend_event) (struct grub_efi_tpm_protocol *this, -+ grub_efi_physical_address_t HashData, -+ grub_efi_uint64_t HashDataLen, -+ grub_efi_uint32_t AlgorithmId, -+ TCG_PCR_EVENT *TCGLogData, -+ grub_efi_uint32_t *EventNumber, -+ grub_efi_physical_address_t *EventLogLastEntry); -+}; -+ -+typedef struct grub_efi_tpm_protocol grub_efi_tpm_protocol_t; -+ -+typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_BITMAP; -+typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_FORMAT; -+typedef grub_efi_uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP; -+ -+typedef struct tdEFI_TCG2_VERSION { -+ grub_efi_uint8_t Major; -+ grub_efi_uint8_t Minor; -+} GRUB_PACKED EFI_TCG2_VERSION; -+ -+typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY { -+ grub_efi_uint8_t Size; -+ EFI_TCG2_VERSION StructureVersion; -+ EFI_TCG2_VERSION ProtocolVersion; -+ EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap; -+ EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs; -+ grub_efi_boolean_t TPMPresentFlag; -+ grub_efi_uint16_t MaxCommandSize; -+ grub_efi_uint16_t MaxResponseSize; -+ grub_efi_uint32_t ManufacturerID; -+ grub_efi_uint32_t NumberOfPcrBanks; -+ EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks; -+} EFI_TCG2_BOOT_SERVICE_CAPABILITY; -+ -+typedef grub_efi_uint32_t TCG_PCRINDEX; -+typedef grub_efi_uint32_t TCG_EVENTTYPE; -+ -+typedef struct tdEFI_TCG2_EVENT_HEADER { -+ grub_efi_uint32_t HeaderSize; -+ grub_efi_uint16_t HeaderVersion; -+ TCG_PCRINDEX PCRIndex; -+ TCG_EVENTTYPE EventType; -+} GRUB_PACKED EFI_TCG2_EVENT_HEADER; -+ -+typedef struct tdEFI_TCG2_EVENT { -+ grub_efi_uint32_t Size; -+ EFI_TCG2_EVENT_HEADER Header; -+ grub_efi_uint8_t Event[1]; -+} GRUB_PACKED EFI_TCG2_EVENT; -+ -+struct grub_efi_tpm2_protocol -+{ -+ grub_efi_status_t (*get_capability) (struct grub_efi_tpm2_protocol *this, -+ EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability); -+ grub_efi_status_t (*get_event_log) (struct grub_efi_tpm2_protocol *this, -+ EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, -+ grub_efi_physical_address_t *EventLogLocation, -+ grub_efi_physical_address_t *EventLogLastEntry, -+ grub_efi_boolean_t *EventLogTruncated); -+ grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *this, -+ grub_efi_uint64_t Flags, -+ grub_efi_physical_address_t *DataToHash, -+ grub_efi_uint64_t DataToHashLen, -+ EFI_TCG2_EVENT *EfiTcgEvent); -+ grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this, -+ grub_efi_uint32_t InputParameterBlockSize, -+ grub_efi_uint8_t *InputParameterBlock, -+ grub_efi_uint32_t OutputParameterBlockSize, -+ grub_efi_uint8_t *OutputParameterBlock); -+ grub_efi_status_t (*get_active_pcr_blanks) (struct grub_efi_tpm2_protocol *this, -+ grub_efi_uint32_t *ActivePcrBanks); -+ grub_efi_status_t (*set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this, -+ grub_efi_uint32_t ActivePcrBanks); -+ grub_efi_status_t (*get_result_of_set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this, -+ grub_efi_uint32_t *OperationPresent, -+ grub_efi_uint32_t *Response); -+}; -+ -+typedef struct grub_efi_tpm2_protocol grub_efi_tpm2_protocol_t; -+ -+#define TCG_ALG_SHA 0x00000004 -+ -+#endif -diff --git a/include/grub/tpm.h b/include/grub/tpm.h -new file mode 100644 -index 00000000000..40d3cf65ba6 ---- /dev/null -+++ b/include/grub/tpm.h -@@ -0,0 +1,91 @@ -+/* -+ * GRUB -- GRand Unified Bootloader -+ * Copyright (C) 2015 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_TPM_HEADER -+#define GRUB_TPM_HEADER 1 -+ -+#define SHA1_DIGEST_SIZE 20 -+ -+#define TPM_BASE 0x0 -+#define TPM_SUCCESS TPM_BASE -+#define TPM_AUTHFAIL (TPM_BASE + 0x1) -+#define TPM_BADINDEX (TPM_BASE + 0x2) -+ -+#define GRUB_TPM_PCR 9 -+#define GRUB_KERNEL_PCR 10 -+#define GRUB_INITRD_PCR 11 -+#define GRUB_CMDLINE_PCR 12 -+ -+#define TPM_TAG_RQU_COMMAND 0x00C1 -+#define TPM_ORD_Extend 0x14 -+ -+#define EV_IPL 0x0d -+ -+/* TCG_PassThroughToTPM Input Parameter Block */ -+typedef struct { -+ grub_uint16_t IPBLength; -+ grub_uint16_t Reserved1; -+ grub_uint16_t OPBLength; -+ grub_uint16_t Reserved2; -+ grub_uint8_t TPMOperandIn[1]; -+} GRUB_PACKED PassThroughToTPM_InputParamBlock; -+ -+/* TCG_PassThroughToTPM Output Parameter Block */ -+typedef struct { -+ grub_uint16_t OPBLength; -+ grub_uint16_t Reserved; -+ grub_uint8_t TPMOperandOut[1]; -+} GRUB_PACKED PassThroughToTPM_OutputParamBlock; -+ -+typedef struct { -+ grub_uint16_t tag; -+ grub_uint32_t paramSize; -+ grub_uint32_t ordinal; -+ grub_uint32_t pcrNum; -+ grub_uint8_t inDigest[SHA1_DIGEST_SIZE]; /* The 160 bit value representing the event to be recorded. */ -+} GRUB_PACKED ExtendIncoming; -+ -+/* TPM_Extend Outgoing Operand */ -+typedef struct { -+ grub_uint16_t tag; -+ grub_uint32_t paramSize; -+ grub_uint32_t returnCode; -+ grub_uint8_t outDigest[SHA1_DIGEST_SIZE]; /* The PCR value after execution of the command. */ -+} GRUB_PACKED ExtendOutgoing; -+ -+grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size, -+ grub_uint8_t pcr, -+ const char *description); -+#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) -+grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf); -+grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size, -+ grub_uint8_t pcr, const char *description); -+#else -+static inline grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, -+ PassThroughToTPM_OutputParamBlock *outbuf) { return 0; }; -+static inline grub_err_t grub_tpm_log_event(unsigned char *buf, -+ grub_size_t size, -+ grub_uint8_t pcr, -+ const char *description) -+{ -+ return 0; -+}; -+#endif -+ -+#endif -diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am -index 5c7a2c8f808..84b076962d8 100644 ---- a/grub-core/Makefile.am -+++ b/grub-core/Makefile.am -@@ -94,6 +94,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h -+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/tpm.h - KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h - - if COND_i386_pc diff --git a/0303-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch b/0303-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch new file mode 100644 index 0000000..799eaa4 --- /dev/null +++ b/0303-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 5028d157c46..eb8b969cded 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 bcae7f4699d..a2a732ffc0d 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 1f31e09b78a..29b4dbac1e4 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -127,7 +127,7 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, + void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); + #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/0303-Measure-kernel-initrd.patch b/0303-Measure-kernel-initrd.patch deleted file mode 100644 index f3f9725..0000000 --- a/0303-Measure-kernel-initrd.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Thu, 16 Jul 2015 15:22:34 -0700 -Subject: [PATCH] Measure kernel + initrd - -Measure the kernel and initrd when loaded on UEFI systems ---- - grub-core/loader/i386/efi/linux.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index cb9631c95e1..95a197743a9 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+"); - -@@ -132,6 +133,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - argv[i]); - goto fail; - } -+ grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "UEFI Linux initrd"); - ptr += cursize; - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr += ALIGN_UP_OVERHEAD (cursize, 4); -@@ -196,6 +198,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -+ grub_tpm_measure (kernel, filelen, GRUB_KERNEL_PCR, "UEFI Linux kernel"); -+ - rc = grub_linuxefi_secure_validate (kernel, filelen); - if (rc < 0) - { diff --git a/0304-Add-BIOS-boot-measurement.patch b/0304-Add-BIOS-boot-measurement.patch deleted file mode 100644 index a428d32..0000000 --- a/0304-Add-BIOS-boot-measurement.patch +++ /dev/null @@ -1,176 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Sun, 9 Aug 2015 15:48:51 -0700 -Subject: [PATCH] Add BIOS boot measurement - -Measure the on-disk grub core on BIOS systems - unlike UEFI, the firmware -can't do this stage for us. ---- - grub-core/boot/i386/pc/boot.S | 30 +++++++++++++++++++++++++- - grub-core/boot/i386/pc/diskboot.S | 44 +++++++++++++++++++++++++++++++++++++++ - 2 files changed, 73 insertions(+), 1 deletion(-) - -diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S -index ea167fe1206..c1df86dec0b 100644 ---- a/grub-core/boot/i386/pc/boot.S -+++ b/grub-core/boot/i386/pc/boot.S -@@ -24,11 +24,14 @@ - * defines for the code go here - */ - -+#define TPM 1 -+ - /* Print message string */ - #define MSG(x) movw $x, %si; call LOCAL(message) - #define ERR(x) movw $x, %si; jmp LOCAL(error_message) - - .macro floppy -+#ifndef TPM - part_start: - - LOCAL(probe_values): -@@ -85,6 +88,7 @@ fd_probe_error_string: .asciz "Floppy" - movb MACRO_DOLLAR(79), %ch - - jmp LOCAL(final_init) -+#endif - .endm - - .macro scratch -@@ -252,6 +256,7 @@ real_start: - /* set %si to the disk address packet */ - movw $disk_address_packet, %si - -+#ifndef TPM - /* check if LBA is supported */ - movb $0x41, %ah - movw $0x55aa, %bx -@@ -271,6 +276,7 @@ real_start: - - andw $1, %cx - jz LOCAL(chs_mode) -+#endif - - LOCAL(lba_mode): - xorw %ax, %ax -@@ -314,6 +320,9 @@ LOCAL(lba_mode): - jmp LOCAL(copy_buffer) - - LOCAL(chs_mode): -+#ifdef TPM -+ jmp LOCAL(general_error) -+#else - /* - * Determine the hard disk geometry from the BIOS! - * We do this first, so that LS-120 IDE floppies work correctly. -@@ -425,7 +434,7 @@ setup_sectors: - jc LOCAL(read_error) - - movw %es, %bx -- -+#endif /* TPM */ - LOCAL(copy_buffer): - /* - * We need to save %cx and %si because the startup code in -@@ -448,6 +457,25 @@ LOCAL(copy_buffer): - popw %ds - popa - -+#ifdef TPM -+ pusha -+ -+ movw $0xBB00, %ax /* TCG_StatusCheck */ -+ int $0x1A -+ test %eax, %eax -+ jnz boot /* No TPM or TPM deactivated */ -+ -+ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */ -+ movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di -+ xorl %esi, %esi -+ movl $0x41504354, %ebx /* TCPA */ -+ movl $0x200, %ecx /* Measure 512 bytes */ -+ movl $0x8, %edx /* PCR 8 */ -+ int $0x1A -+ -+ popa -+#endif -+boot: - /* boot kernel */ - jmp *(LOCAL(kernel_address)) - -diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S -index 68d31de0c4c..f4744ec6fcb 100644 ---- a/grub-core/boot/i386/pc/diskboot.S -+++ b/grub-core/boot/i386/pc/diskboot.S -@@ -19,6 +19,8 @@ - #include - #include - -+#define TPM 1 -+ - /* - * defines for the code go here - */ -@@ -53,6 +55,21 @@ _start: - /* this sets up for the first run through "bootloop" */ - movw $LOCAL(firstlist), %di - -+#ifdef TPM -+ /* clear EAX to remove potential garbage */ -+ xorl %eax, %eax -+ /* 8(%di) = number of sectors to read */ -+ movw 8(%di), %ax -+ -+ /* Multiply number of sectors to read with 512 bytes. EAX is 32bit -+ * which is large enough to hold values of up to 4GB. I doubt there -+ * will ever be a core.img larger than that. ;-) */ -+ shll $9, %eax -+ -+ /* write result to bytes_to_measure var */ -+ movl %eax, bytes_to_measure -+#endif -+ - /* save the sector number of the second sector in %ebp */ - movl (%di), %ebp - -@@ -290,6 +307,29 @@ LOCAL(copy_buffer): - /* END OF MAIN LOOP */ - - LOCAL(bootit): -+#ifdef TPM -+ pusha -+ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */ -+ -+ movw $0x0, %bx -+ movw %bx, %es -+ -+ /* We've already measured the first 512 bytes, now measure the rest */ -+ xorl %edi, %edi -+ movw $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200), %di -+ -+ movl $0x41504354, %ebx /* EBX = "TCPA" */ -+ -+ /* %ecx = The length, in bytes, of the buffer to measure */ -+ movl $bytes_to_measure, %esi -+ movl (%esi), %ecx -+ xorl %esi, %esi -+ movl $0x9, %edx /* PCR 9 */ -+ -+ int $0x1A -+ -+ popa -+#endif - /* print a newline */ - MSG(notification_done) - popw %dx /* this makes sure %dl is our "boot" drive */ -@@ -324,6 +364,10 @@ geometry_error_string: .asciz "Geom" - read_error_string: .asciz "Read" - general_error_string: .asciz " Error" - -+#ifdef TPM -+bytes_to_measure: .long 0 -+#endif -+ - /* - * message: write the string pointed to by %si - * diff --git a/0304-Only-attempt-to-scan-different-BLS-directories-on-EF.patch b/0304-Only-attempt-to-scan-different-BLS-directories-on-EF.patch new file mode 100644 index 0000000..b53d4c2 --- /dev/null +++ b/0304-Only-attempt-to-scan-different-BLS-directories-on-EF.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 3 Apr 2018 15:42:47 +0200 +Subject: [PATCH] Only attempt to scan different BLS directories on EFI + machines + +Current BLS support attempted to scan for BLS directories, but this only +makes sense on EFI, where BLS fragments are in /loader/$vendor/entries. + +For BIOS, only either the default /loader/entries path should be scanned +or the BLS directory defined in the blsdir GRUB 2 environment variable. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index e5617c3bc6c..c0973ff83ea 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -676,8 +676,8 @@ static int find_entry (const char *filename, + const char *devid = grub_env_get ("boot"); + + grub_dprintf("blscfg", "%s got here\n", __func__); +- if (!grub_strcmp (filename, ".") || +- !grub_strcmp (filename, "..")) ++ if (filename && (!grub_strcmp (filename, ".") || ++ !grub_strcmp (filename, ".."))) + return 0; + + if (info->platform == PLATFORM_EFI && !grub_strcasecmp (filename, "boot")) +@@ -872,11 +872,10 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, + info.platform = PLATFORM_EMU; + grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, + GRUB_BLS_CONFIG_PATH); +- r = fs->dir (dev, "/boot/loader/", +- find_entry, &info); ++ find_entry(NULL, NULL, &info); + #else + grub_dprintf ("blscfg", "scanning %s\n", GRUB_BLS_CONFIG_PATH); +- r = fs->dir (dev, "/", find_entry, &info); ++ find_entry(NULL, NULL, &info); + #endif + + finish: diff --git a/0305-Core-TPM-support.patch b/0305-Core-TPM-support.patch new file mode 100644 index 0000000..730f01a --- /dev/null +++ b/0305-Core-TPM-support.patch @@ -0,0 +1,786 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Tue, 14 Jul 2015 17:06:35 -0700 +Subject: [PATCH] Core TPM support + +Add support for performing basic TPM measurements. Right now this only +supports extending PCRs statically and only on UEFI and BIOS systems, but +will measure all modules as they're loaded. +--- + grub-core/Makefile.core.def | 3 + + grub-core/kern/dl.c | 3 + + grub-core/kern/efi/tpm.c | 282 +++++++++++++++++++++++++++++++++++++++++++ + grub-core/kern/i386/pc/tpm.c | 132 ++++++++++++++++++++ + grub-core/kern/tpm.c | 13 ++ + include/grub/efi/tpm.h | 153 +++++++++++++++++++++++ + include/grub/tpm.h | 91 ++++++++++++++ + grub-core/Makefile.am | 1 + + 8 files changed, 678 insertions(+) + create mode 100644 grub-core/kern/efi/tpm.c + create mode 100644 grub-core/kern/i386/pc/tpm.c + create mode 100644 grub-core/kern/tpm.c + create mode 100644 include/grub/efi/tpm.h + create mode 100644 include/grub/tpm.h + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 1153ec4d2cf..334ca3fcf46 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -131,6 +131,7 @@ kernel = { + common = kern/term.c; + common = kern/qsort.c; + common = kern/backtrace.c; ++ common = kern/tpm.c; + + x86 = kern/i386/backtrace.c; + i386_xen = kern/i386/backtrace.c; +@@ -199,6 +200,7 @@ kernel = { + efi = kern/acpi.c; + efi = kern/efi/acpi.c; + efi = lib/envblk.c; ++ efi = kern/efi/tpm.c; + i386_coreboot = kern/i386/pc/acpi.c; + i386_multiboot = kern/i386/pc/acpi.c; + i386_coreboot = kern/acpi.c; +@@ -246,6 +248,7 @@ kernel = { + + i386_pc = kern/i386/pc/init.c; + i386_pc = kern/i386/pc/mmap.c; ++ i386_pc = kern/i386/pc/tpm.c; + i386_pc = term/i386/pc/console.c; + + i386_qemu = bus/pci.c; +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index eb8b969cded..387d1e6446d 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + + /* Platforms where modules are in a readonly area of memory. */ + #if defined(GRUB_MACHINE_QEMU) +@@ -829,6 +830,8 @@ grub_dl_load_file (const char *filename) + opens of the same device. */ + grub_file_close (file); + ++ grub_tpm_measure(core, size, GRUB_TPM_PCR, filename); ++ + mod = grub_dl_load_core (core, size); + grub_free (core); + if (! mod) +diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c +new file mode 100644 +index 00000000000..c9fb3c133f3 +--- /dev/null ++++ b/grub-core/kern/efi/tpm.c +@@ -0,0 +1,282 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++static grub_efi_guid_t tpm_guid = EFI_TPM_GUID; ++static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID; ++ ++static grub_efi_boolean_t grub_tpm_present(grub_efi_tpm_protocol_t *tpm) ++{ ++ grub_efi_status_t status; ++ TCG_EFI_BOOT_SERVICE_CAPABILITY caps; ++ grub_uint32_t flags; ++ grub_efi_physical_address_t eventlog, lastevent; ++ ++ caps.Size = (grub_uint8_t)sizeof(caps); ++ ++ status = efi_call_5(tpm->status_check, tpm, &caps, &flags, &eventlog, ++ &lastevent); ++ ++ if (status != GRUB_EFI_SUCCESS || caps.TPMDeactivatedFlag ++ || !caps.TPMPresentFlag) ++ return 0; ++ ++ return 1; ++} ++ ++static grub_efi_boolean_t grub_tpm2_present(grub_efi_tpm2_protocol_t *tpm) ++{ ++ grub_efi_status_t status; ++ EFI_TCG2_BOOT_SERVICE_CAPABILITY caps; ++ ++ caps.Size = (grub_uint8_t)sizeof(caps); ++ ++ status = efi_call_2(tpm->get_capability, tpm, &caps); ++ ++ if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag) ++ return 0; ++ ++ return 1; ++} ++ ++static grub_efi_boolean_t grub_tpm_handle_find(grub_efi_handle_t *tpm_handle, ++ grub_efi_uint8_t *protocol_version) ++{ ++ grub_efi_handle_t *handles; ++ grub_efi_uintn_t num_handles; ++ ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm_guid, NULL, ++ &num_handles); ++ if (handles && num_handles > 0) { ++ *tpm_handle = handles[0]; ++ *protocol_version = 1; ++ return 1; ++ } ++ ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm2_guid, NULL, ++ &num_handles); ++ if (handles && num_handles > 0) { ++ *tpm_handle = handles[0]; ++ *protocol_version = 2; ++ return 1; ++ } ++ ++ return 0; ++} ++ ++static grub_err_t ++grub_tpm1_execute(grub_efi_handle_t tpm_handle, ++ PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf) ++{ ++ grub_efi_status_t status; ++ grub_efi_tpm_protocol_t *tpm; ++ grub_uint32_t inhdrsize = sizeof(*inbuf) - sizeof(inbuf->TPMOperandIn); ++ grub_uint32_t outhdrsize = sizeof(*outbuf) - sizeof(outbuf->TPMOperandOut); ++ ++ tpm = grub_efi_open_protocol (tpm_handle, &tpm_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!grub_tpm_present(tpm)) ++ return 0; ++ ++ /* UEFI TPM protocol takes the raw operand block, no param block header */ ++ status = efi_call_5 (tpm->pass_through_to_tpm, tpm, ++ inbuf->IPBLength - inhdrsize, inbuf->TPMOperandIn, ++ outbuf->OPBLength - outhdrsize, outbuf->TPMOperandOut); ++ ++ switch (status) { ++ case GRUB_EFI_SUCCESS: ++ return 0; ++ case GRUB_EFI_DEVICE_ERROR: ++ return grub_error (GRUB_ERR_IO, N_("Command failed")); ++ case GRUB_EFI_INVALID_PARAMETER: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); ++ case GRUB_EFI_BUFFER_TOO_SMALL: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); ++ case GRUB_EFI_NOT_FOUND: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); ++ default: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); ++ } ++} ++ ++static grub_err_t ++grub_tpm2_execute(grub_efi_handle_t tpm_handle, ++ PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf) ++{ ++ grub_efi_status_t status; ++ grub_efi_tpm2_protocol_t *tpm; ++ grub_uint32_t inhdrsize = sizeof(*inbuf) - sizeof(inbuf->TPMOperandIn); ++ grub_uint32_t outhdrsize = sizeof(*outbuf) - sizeof(outbuf->TPMOperandOut); ++ ++ tpm = grub_efi_open_protocol (tpm_handle, &tpm2_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!grub_tpm2_present(tpm)) ++ return 0; ++ ++ /* UEFI TPM protocol takes the raw operand block, no param block header */ ++ status = efi_call_5 (tpm->submit_command, tpm, ++ inbuf->IPBLength - inhdrsize, inbuf->TPMOperandIn, ++ outbuf->OPBLength - outhdrsize, outbuf->TPMOperandOut); ++ ++ switch (status) { ++ case GRUB_EFI_SUCCESS: ++ return 0; ++ case GRUB_EFI_DEVICE_ERROR: ++ return grub_error (GRUB_ERR_IO, N_("Command failed")); ++ case GRUB_EFI_INVALID_PARAMETER: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); ++ case GRUB_EFI_BUFFER_TOO_SMALL: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); ++ case GRUB_EFI_NOT_FOUND: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); ++ default: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); ++ } ++} ++ ++grub_err_t ++grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf) ++{ ++ grub_efi_handle_t tpm_handle; ++ grub_uint8_t protocol_version; ++ ++ /* It's not a hard failure for there to be no TPM */ ++ if (!grub_tpm_handle_find(&tpm_handle, &protocol_version)) ++ return 0; ++ ++ if (protocol_version == 1) { ++ return grub_tpm1_execute(tpm_handle, inbuf, outbuf); ++ } else { ++ return grub_tpm2_execute(tpm_handle, inbuf, outbuf); ++ } ++} ++ ++typedef struct { ++ grub_uint32_t pcrindex; ++ grub_uint32_t eventtype; ++ grub_uint8_t digest[20]; ++ grub_uint32_t eventsize; ++ grub_uint8_t event[1]; ++} Event; ++ ++ ++static grub_err_t ++grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, ++ grub_size_t size, grub_uint8_t pcr, ++ const char *description) ++{ ++ Event *event; ++ grub_efi_status_t status; ++ grub_efi_tpm_protocol_t *tpm; ++ grub_efi_physical_address_t lastevent; ++ grub_uint32_t algorithm; ++ grub_uint32_t eventnum = 0; ++ ++ tpm = grub_efi_open_protocol (tpm_handle, &tpm_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!grub_tpm_present(tpm)) ++ return 0; ++ ++ event = grub_zalloc(sizeof (Event) + grub_strlen(description) + 1); ++ if (!event) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("cannot allocate TPM event buffer")); ++ ++ event->pcrindex = pcr; ++ event->eventtype = EV_IPL; ++ event->eventsize = grub_strlen(description) + 1; ++ grub_memcpy(event->event, description, event->eventsize); ++ ++ algorithm = TCG_ALG_SHA; ++ status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size, ++ algorithm, event, &eventnum, &lastevent); ++ ++ switch (status) { ++ case GRUB_EFI_SUCCESS: ++ return 0; ++ case GRUB_EFI_DEVICE_ERROR: ++ return grub_error (GRUB_ERR_IO, N_("Command failed")); ++ case GRUB_EFI_INVALID_PARAMETER: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); ++ case GRUB_EFI_BUFFER_TOO_SMALL: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); ++ case GRUB_EFI_NOT_FOUND: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); ++ default: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); ++ } ++} ++ ++static grub_err_t ++grub_tpm2_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, ++ grub_size_t size, grub_uint8_t pcr, ++ const char *description) ++{ ++ EFI_TCG2_EVENT *event; ++ grub_efi_status_t status; ++ grub_efi_tpm2_protocol_t *tpm; ++ ++ tpm = grub_efi_open_protocol (tpm_handle, &tpm2_guid, ++ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ ++ if (!grub_tpm2_present(tpm)) ++ return 0; ++ ++ event = grub_zalloc(sizeof (EFI_TCG2_EVENT) + grub_strlen(description) + 1); ++ if (!event) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("cannot allocate TPM event buffer")); ++ ++ event->Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER); ++ event->Header.HeaderVersion = 1; ++ event->Header.PCRIndex = pcr; ++ event->Header.EventType = EV_IPL; ++ event->Size = sizeof(*event) - sizeof(event->Event) + grub_strlen(description) + 1; ++ grub_memcpy(event->Event, description, grub_strlen(description) + 1); ++ ++ status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf, ++ (grub_uint64_t) size, event); ++ ++ switch (status) { ++ case GRUB_EFI_SUCCESS: ++ return 0; ++ case GRUB_EFI_DEVICE_ERROR: ++ return grub_error (GRUB_ERR_IO, N_("Command failed")); ++ case GRUB_EFI_INVALID_PARAMETER: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter")); ++ case GRUB_EFI_BUFFER_TOO_SMALL: ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small")); ++ case GRUB_EFI_NOT_FOUND: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable")); ++ default: ++ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error")); ++ } ++} ++ ++grub_err_t ++grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, ++ const char *description) ++{ ++ grub_efi_handle_t tpm_handle; ++ grub_efi_uint8_t protocol_version; ++ ++ if (!grub_tpm_handle_find(&tpm_handle, &protocol_version)) ++ return 0; ++ ++ if (protocol_version == 1) { ++ return grub_tpm1_log_event(tpm_handle, buf, size, pcr, description); ++ } else { ++ return grub_tpm2_log_event(tpm_handle, buf, size, pcr, description); ++ } ++} +diff --git a/grub-core/kern/i386/pc/tpm.c b/grub-core/kern/i386/pc/tpm.c +new file mode 100644 +index 00000000000..8c6c1e6ece2 +--- /dev/null ++++ b/grub-core/kern/i386/pc/tpm.c +@@ -0,0 +1,132 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define TCPA_MAGIC 0x41504354 ++ ++int tpm_present(void); ++ ++int tpm_present(void) ++{ ++ struct grub_bios_int_registers regs; ++ ++ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; ++ regs.eax = 0xbb00; ++ regs.ebx = TCPA_MAGIC; ++ grub_bios_interrupt (0x1a, ®s); ++ ++ if (regs.eax == 0) ++ return 1; ++ ++ return 0; ++} ++ ++grub_err_t ++grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf) ++{ ++ struct grub_bios_int_registers regs; ++ grub_addr_t inaddr, outaddr; ++ ++ if (!tpm_present()) ++ return 0; ++ ++ inaddr = (grub_addr_t) inbuf; ++ outaddr = (grub_addr_t) outbuf; ++ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; ++ regs.eax = 0xbb02; ++ regs.ebx = TCPA_MAGIC; ++ regs.ecx = 0; ++ regs.edx = 0; ++ regs.es = (inaddr & 0xffff0000) >> 4; ++ regs.edi = inaddr & 0xffff; ++ regs.ds = outaddr >> 4; ++ regs.esi = outaddr & 0xf; ++ ++ grub_bios_interrupt (0x1a, ®s); ++ ++ if (regs.eax) ++ return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); ++ ++ return 0; ++} ++ ++typedef struct { ++ grub_uint32_t pcrindex; ++ grub_uint32_t eventtype; ++ grub_uint8_t digest[20]; ++ grub_uint32_t eventdatasize; ++ grub_uint8_t event[0]; ++} GRUB_PACKED Event; ++ ++typedef struct { ++ grub_uint16_t ipblength; ++ grub_uint16_t reserved; ++ grub_uint32_t hashdataptr; ++ grub_uint32_t hashdatalen; ++ grub_uint32_t pcr; ++ grub_uint32_t reserved2; ++ grub_uint32_t logdataptr; ++ grub_uint32_t logdatalen; ++} GRUB_PACKED EventIncoming; ++ ++typedef struct { ++ grub_uint16_t opblength; ++ grub_uint16_t reserved; ++ grub_uint32_t eventnum; ++ grub_uint8_t hashvalue[20]; ++} GRUB_PACKED EventOutgoing; ++ ++grub_err_t ++grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, ++ const char *description) ++{ ++ struct grub_bios_int_registers regs; ++ EventIncoming incoming; ++ EventOutgoing outgoing; ++ Event *event; ++ grub_uint32_t datalength; ++ ++ if (!tpm_present()) ++ return 0; ++ ++ datalength = grub_strlen(description); ++ event = grub_zalloc(datalength + sizeof(Event)); ++ if (!event) ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("cannot allocate TPM event buffer")); ++ ++ event->pcrindex = pcr; ++ event->eventtype = 0x0d; ++ event->eventdatasize = grub_strlen(description); ++ grub_memcpy(event->event, description, datalength); ++ ++ incoming.ipblength = sizeof(incoming); ++ incoming.hashdataptr = (grub_uint32_t)buf; ++ incoming.hashdatalen = size; ++ incoming.pcr = pcr; ++ incoming.logdataptr = (grub_uint32_t)event; ++ incoming.logdatalen = datalength + sizeof(Event); ++ ++ regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; ++ regs.eax = 0xbb01; ++ regs.ebx = TCPA_MAGIC; ++ regs.ecx = 0; ++ regs.edx = 0; ++ regs.es = (((grub_addr_t) &incoming) & 0xffff0000) >> 4; ++ regs.edi = ((grub_addr_t) &incoming) & 0xffff; ++ regs.ds = (((grub_addr_t) &outgoing) & 0xffff0000) >> 4; ++ regs.esi = ((grub_addr_t) &outgoing) & 0xffff; ++ ++ grub_bios_interrupt (0x1a, ®s); ++ ++ grub_free(event); ++ ++ if (regs.eax) ++ return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); ++ ++ return 0; ++} +diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c +new file mode 100644 +index 00000000000..1a991876c83 +--- /dev/null ++++ b/grub-core/kern/tpm.c +@@ -0,0 +1,13 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++grub_err_t ++grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, ++ const char *description) ++{ ++ return grub_tpm_log_event(buf, size, pcr, description); ++} +diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h +new file mode 100644 +index 00000000000..e2aff4a3c22 +--- /dev/null ++++ b/include/grub/efi/tpm.h +@@ -0,0 +1,153 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2015 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_TPM_HEADER ++#define GRUB_EFI_TPM_HEADER 1 ++ ++#define EFI_TPM_GUID {0xf541796d, 0xa62e, 0x4954, {0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd }}; ++#define EFI_TPM2_GUID {0x607f766c, 0x7455, 0x42be, {0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f }}; ++ ++typedef struct { ++ grub_efi_uint8_t Major; ++ grub_efi_uint8_t Minor; ++ grub_efi_uint8_t RevMajor; ++ grub_efi_uint8_t RevMinor; ++} TCG_VERSION; ++ ++typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY { ++ grub_efi_uint8_t Size; /// Size of this structure. ++ TCG_VERSION StructureVersion; ++ TCG_VERSION ProtocolSpecVersion; ++ grub_efi_uint8_t HashAlgorithmBitmap; /// Hash algorithms . ++ char TPMPresentFlag; /// 00h = TPM not present. ++ char TPMDeactivatedFlag; /// 01h = TPM currently deactivated. ++} TCG_EFI_BOOT_SERVICE_CAPABILITY; ++ ++typedef struct { ++ grub_efi_uint32_t PCRIndex; ++ grub_efi_uint32_t EventType; ++ grub_efi_uint8_t digest[20]; ++ grub_efi_uint32_t EventSize; ++ grub_efi_uint8_t Event[1]; ++} TCG_PCR_EVENT; ++ ++struct grub_efi_tpm_protocol ++{ ++ grub_efi_status_t (*status_check) (struct grub_efi_tpm_protocol *this, ++ TCG_EFI_BOOT_SERVICE_CAPABILITY *ProtocolCapability, ++ grub_efi_uint32_t *TCGFeatureFlags, ++ grub_efi_physical_address_t *EventLogLocation, ++ grub_efi_physical_address_t *EventLogLastEntry); ++ grub_efi_status_t (*hash_all) (struct grub_efi_tpm_protocol *this, ++ grub_efi_uint8_t *HashData, ++ grub_efi_uint64_t HashLen, ++ grub_efi_uint32_t AlgorithmId, ++ grub_efi_uint64_t *HashedDataLen, ++ grub_efi_uint8_t **HashedDataResult); ++ grub_efi_status_t (*log_event) (struct grub_efi_tpm_protocol *this, ++ TCG_PCR_EVENT *TCGLogData, ++ grub_efi_uint32_t *EventNumber, ++ grub_efi_uint32_t Flags); ++ grub_efi_status_t (*pass_through_to_tpm) (struct grub_efi_tpm_protocol *this, ++ grub_efi_uint32_t TpmInputParameterBlockSize, ++ grub_efi_uint8_t *TpmInputParameterBlock, ++ grub_efi_uint32_t TpmOutputParameterBlockSize, ++ grub_efi_uint8_t *TpmOutputParameterBlock); ++ grub_efi_status_t (*log_extend_event) (struct grub_efi_tpm_protocol *this, ++ grub_efi_physical_address_t HashData, ++ grub_efi_uint64_t HashDataLen, ++ grub_efi_uint32_t AlgorithmId, ++ TCG_PCR_EVENT *TCGLogData, ++ grub_efi_uint32_t *EventNumber, ++ grub_efi_physical_address_t *EventLogLastEntry); ++}; ++ ++typedef struct grub_efi_tpm_protocol grub_efi_tpm_protocol_t; ++ ++typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_BITMAP; ++typedef grub_efi_uint32_t EFI_TCG2_EVENT_LOG_FORMAT; ++typedef grub_efi_uint32_t EFI_TCG2_EVENT_ALGORITHM_BITMAP; ++ ++typedef struct tdEFI_TCG2_VERSION { ++ grub_efi_uint8_t Major; ++ grub_efi_uint8_t Minor; ++} GRUB_PACKED EFI_TCG2_VERSION; ++ ++typedef struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY { ++ grub_efi_uint8_t Size; ++ EFI_TCG2_VERSION StructureVersion; ++ EFI_TCG2_VERSION ProtocolVersion; ++ EFI_TCG2_EVENT_ALGORITHM_BITMAP HashAlgorithmBitmap; ++ EFI_TCG2_EVENT_LOG_BITMAP SupportedEventLogs; ++ grub_efi_boolean_t TPMPresentFlag; ++ grub_efi_uint16_t MaxCommandSize; ++ grub_efi_uint16_t MaxResponseSize; ++ grub_efi_uint32_t ManufacturerID; ++ grub_efi_uint32_t NumberOfPcrBanks; ++ EFI_TCG2_EVENT_ALGORITHM_BITMAP ActivePcrBanks; ++} EFI_TCG2_BOOT_SERVICE_CAPABILITY; ++ ++typedef grub_efi_uint32_t TCG_PCRINDEX; ++typedef grub_efi_uint32_t TCG_EVENTTYPE; ++ ++typedef struct tdEFI_TCG2_EVENT_HEADER { ++ grub_efi_uint32_t HeaderSize; ++ grub_efi_uint16_t HeaderVersion; ++ TCG_PCRINDEX PCRIndex; ++ TCG_EVENTTYPE EventType; ++} GRUB_PACKED EFI_TCG2_EVENT_HEADER; ++ ++typedef struct tdEFI_TCG2_EVENT { ++ grub_efi_uint32_t Size; ++ EFI_TCG2_EVENT_HEADER Header; ++ grub_efi_uint8_t Event[1]; ++} GRUB_PACKED EFI_TCG2_EVENT; ++ ++struct grub_efi_tpm2_protocol ++{ ++ grub_efi_status_t (*get_capability) (struct grub_efi_tpm2_protocol *this, ++ EFI_TCG2_BOOT_SERVICE_CAPABILITY *ProtocolCapability); ++ grub_efi_status_t (*get_event_log) (struct grub_efi_tpm2_protocol *this, ++ EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat, ++ grub_efi_physical_address_t *EventLogLocation, ++ grub_efi_physical_address_t *EventLogLastEntry, ++ grub_efi_boolean_t *EventLogTruncated); ++ grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *this, ++ grub_efi_uint64_t Flags, ++ grub_efi_physical_address_t *DataToHash, ++ grub_efi_uint64_t DataToHashLen, ++ EFI_TCG2_EVENT *EfiTcgEvent); ++ grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this, ++ grub_efi_uint32_t InputParameterBlockSize, ++ grub_efi_uint8_t *InputParameterBlock, ++ grub_efi_uint32_t OutputParameterBlockSize, ++ grub_efi_uint8_t *OutputParameterBlock); ++ grub_efi_status_t (*get_active_pcr_blanks) (struct grub_efi_tpm2_protocol *this, ++ grub_efi_uint32_t *ActivePcrBanks); ++ grub_efi_status_t (*set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this, ++ grub_efi_uint32_t ActivePcrBanks); ++ grub_efi_status_t (*get_result_of_set_active_pcr_banks) (struct grub_efi_tpm2_protocol *this, ++ grub_efi_uint32_t *OperationPresent, ++ grub_efi_uint32_t *Response); ++}; ++ ++typedef struct grub_efi_tpm2_protocol grub_efi_tpm2_protocol_t; ++ ++#define TCG_ALG_SHA 0x00000004 ++ ++#endif +diff --git a/include/grub/tpm.h b/include/grub/tpm.h +new file mode 100644 +index 00000000000..40d3cf65ba6 +--- /dev/null ++++ b/include/grub/tpm.h +@@ -0,0 +1,91 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2015 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_TPM_HEADER ++#define GRUB_TPM_HEADER 1 ++ ++#define SHA1_DIGEST_SIZE 20 ++ ++#define TPM_BASE 0x0 ++#define TPM_SUCCESS TPM_BASE ++#define TPM_AUTHFAIL (TPM_BASE + 0x1) ++#define TPM_BADINDEX (TPM_BASE + 0x2) ++ ++#define GRUB_TPM_PCR 9 ++#define GRUB_KERNEL_PCR 10 ++#define GRUB_INITRD_PCR 11 ++#define GRUB_CMDLINE_PCR 12 ++ ++#define TPM_TAG_RQU_COMMAND 0x00C1 ++#define TPM_ORD_Extend 0x14 ++ ++#define EV_IPL 0x0d ++ ++/* TCG_PassThroughToTPM Input Parameter Block */ ++typedef struct { ++ grub_uint16_t IPBLength; ++ grub_uint16_t Reserved1; ++ grub_uint16_t OPBLength; ++ grub_uint16_t Reserved2; ++ grub_uint8_t TPMOperandIn[1]; ++} GRUB_PACKED PassThroughToTPM_InputParamBlock; ++ ++/* TCG_PassThroughToTPM Output Parameter Block */ ++typedef struct { ++ grub_uint16_t OPBLength; ++ grub_uint16_t Reserved; ++ grub_uint8_t TPMOperandOut[1]; ++} GRUB_PACKED PassThroughToTPM_OutputParamBlock; ++ ++typedef struct { ++ grub_uint16_t tag; ++ grub_uint32_t paramSize; ++ grub_uint32_t ordinal; ++ grub_uint32_t pcrNum; ++ grub_uint8_t inDigest[SHA1_DIGEST_SIZE]; /* The 160 bit value representing the event to be recorded. */ ++} GRUB_PACKED ExtendIncoming; ++ ++/* TPM_Extend Outgoing Operand */ ++typedef struct { ++ grub_uint16_t tag; ++ grub_uint32_t paramSize; ++ grub_uint32_t returnCode; ++ grub_uint8_t outDigest[SHA1_DIGEST_SIZE]; /* The PCR value after execution of the command. */ ++} GRUB_PACKED ExtendOutgoing; ++ ++grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size, ++ grub_uint8_t pcr, ++ const char *description); ++#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) ++grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf); ++grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size, ++ grub_uint8_t pcr, const char *description); ++#else ++static inline grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, ++ PassThroughToTPM_OutputParamBlock *outbuf) { return 0; }; ++static inline grub_err_t grub_tpm_log_event(unsigned char *buf, ++ grub_size_t size, ++ grub_uint8_t pcr, ++ const char *description) ++{ ++ return 0; ++}; ++#endif ++ ++#endif +diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am +index 5c7a2c8f808..84b076962d8 100644 +--- a/grub-core/Makefile.am ++++ b/grub-core/Makefile.am +@@ -94,6 +94,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h ++KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/tpm.h + KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h + + if COND_i386_pc diff --git a/0305-Measure-kernel-and-initrd-on-BIOS-systems.patch b/0305-Measure-kernel-and-initrd-on-BIOS-systems.patch deleted file mode 100644 index 92c6c60..0000000 --- a/0305-Measure-kernel-and-initrd-on-BIOS-systems.patch +++ /dev/null @@ -1,84 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Sun, 9 Aug 2015 16:28:29 -0700 -Subject: [PATCH] Measure kernel and initrd on BIOS systems - -Measure the kernel and initrd when loaded on BIOS systems ---- - grub-core/loader/i386/linux.c | 5 +++++ - grub-core/loader/i386/pc/linux.c | 3 +++ - grub-core/loader/linux.c | 2 ++ - 3 files changed, 10 insertions(+) - -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 35055431247..24fb1084b25 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+"); - -@@ -718,7 +719,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -+ grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "Linux Kernel"); -+ - grub_memcpy (&lh, kernel, sizeof (lh)); -+ - kernel_offset = sizeof (lh); - - if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) -@@ -1032,6 +1036,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - - len = prot_file_size; - grub_memcpy (prot_mode_mem, kernel + kernel_offset, len); -+ kernel_offset += len; - - if (grub_errno == GRUB_ERR_NONE) - { -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index e2bb1a99a74..654e363e584 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+"); - -@@ -161,6 +162,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -+ grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "BIOS Linux Kernel"); -+ - grub_memcpy (&lh, kernel, sizeof (lh)); - kernel_offset = sizeof (lh); - -diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c -index be6fa0f4d45..3005c0d19c9 100644 ---- a/grub-core/loader/linux.c -+++ b/grub-core/loader/linux.c -@@ -4,6 +4,7 @@ - #include - #include - #include -+#include - - struct newc_head - { -@@ -288,6 +289,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, - grub_initrd_close (initrd_ctx); - return grub_errno; - } -+ grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "Linux Initrd"); - ptr += cursize; - } - if (newc) diff --git a/0306-Measure-kernel-initrd.patch b/0306-Measure-kernel-initrd.patch new file mode 100644 index 0000000..f3f9725 --- /dev/null +++ b/0306-Measure-kernel-initrd.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Thu, 16 Jul 2015 15:22:34 -0700 +Subject: [PATCH] Measure kernel + initrd + +Measure the kernel and initrd when loaded on UEFI systems +--- + grub-core/loader/i386/efi/linux.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index cb9631c95e1..95a197743a9 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+"); + +@@ -132,6 +133,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + argv[i]); + goto fail; + } ++ grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "UEFI Linux initrd"); + ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); +@@ -196,6 +198,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_tpm_measure (kernel, filelen, GRUB_KERNEL_PCR, "UEFI Linux kernel"); ++ + rc = grub_linuxefi_secure_validate (kernel, filelen); + if (rc < 0) + { diff --git a/0306-Measure-the-kernel-commandline.patch b/0306-Measure-the-kernel-commandline.patch deleted file mode 100644 index 7fe2809..0000000 --- a/0306-Measure-the-kernel-commandline.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Sun, 9 Aug 2015 16:32:29 -0700 -Subject: [PATCH] Measure the kernel commandline - -Measure the kernel commandline to ensure that it hasn't been modified ---- - grub-core/lib/cmdline.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c -index 970ea868c14..6b56304d4a7 100644 ---- a/grub-core/lib/cmdline.c -+++ b/grub-core/lib/cmdline.c -@@ -19,6 +19,7 @@ - - #include - #include -+#include - - static int - is_hex(char c) -@@ -79,7 +80,7 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, - { - int i, space; - unsigned int arg_size; -- char *c; -+ char *c, *orig = buf; - - for (i = 0; i < argc; i++) - { -@@ -125,5 +126,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, - - *buf = 0; - -+ grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_CMDLINE_PCR, -+ "Kernel Commandline"); -+ - return i; - } diff --git a/0307-Add-BIOS-boot-measurement.patch b/0307-Add-BIOS-boot-measurement.patch new file mode 100644 index 0000000..a428d32 --- /dev/null +++ b/0307-Add-BIOS-boot-measurement.patch @@ -0,0 +1,176 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Sun, 9 Aug 2015 15:48:51 -0700 +Subject: [PATCH] Add BIOS boot measurement + +Measure the on-disk grub core on BIOS systems - unlike UEFI, the firmware +can't do this stage for us. +--- + grub-core/boot/i386/pc/boot.S | 30 +++++++++++++++++++++++++- + grub-core/boot/i386/pc/diskboot.S | 44 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 73 insertions(+), 1 deletion(-) + +diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S +index ea167fe1206..c1df86dec0b 100644 +--- a/grub-core/boot/i386/pc/boot.S ++++ b/grub-core/boot/i386/pc/boot.S +@@ -24,11 +24,14 @@ + * defines for the code go here + */ + ++#define TPM 1 ++ + /* Print message string */ + #define MSG(x) movw $x, %si; call LOCAL(message) + #define ERR(x) movw $x, %si; jmp LOCAL(error_message) + + .macro floppy ++#ifndef TPM + part_start: + + LOCAL(probe_values): +@@ -85,6 +88,7 @@ fd_probe_error_string: .asciz "Floppy" + movb MACRO_DOLLAR(79), %ch + + jmp LOCAL(final_init) ++#endif + .endm + + .macro scratch +@@ -252,6 +256,7 @@ real_start: + /* set %si to the disk address packet */ + movw $disk_address_packet, %si + ++#ifndef TPM + /* check if LBA is supported */ + movb $0x41, %ah + movw $0x55aa, %bx +@@ -271,6 +276,7 @@ real_start: + + andw $1, %cx + jz LOCAL(chs_mode) ++#endif + + LOCAL(lba_mode): + xorw %ax, %ax +@@ -314,6 +320,9 @@ LOCAL(lba_mode): + jmp LOCAL(copy_buffer) + + LOCAL(chs_mode): ++#ifdef TPM ++ jmp LOCAL(general_error) ++#else + /* + * Determine the hard disk geometry from the BIOS! + * We do this first, so that LS-120 IDE floppies work correctly. +@@ -425,7 +434,7 @@ setup_sectors: + jc LOCAL(read_error) + + movw %es, %bx +- ++#endif /* TPM */ + LOCAL(copy_buffer): + /* + * We need to save %cx and %si because the startup code in +@@ -448,6 +457,25 @@ LOCAL(copy_buffer): + popw %ds + popa + ++#ifdef TPM ++ pusha ++ ++ movw $0xBB00, %ax /* TCG_StatusCheck */ ++ int $0x1A ++ test %eax, %eax ++ jnz boot /* No TPM or TPM deactivated */ ++ ++ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */ ++ movw $GRUB_BOOT_MACHINE_KERNEL_ADDR, %di ++ xorl %esi, %esi ++ movl $0x41504354, %ebx /* TCPA */ ++ movl $0x200, %ecx /* Measure 512 bytes */ ++ movl $0x8, %edx /* PCR 8 */ ++ int $0x1A ++ ++ popa ++#endif ++boot: + /* boot kernel */ + jmp *(LOCAL(kernel_address)) + +diff --git a/grub-core/boot/i386/pc/diskboot.S b/grub-core/boot/i386/pc/diskboot.S +index 68d31de0c4c..f4744ec6fcb 100644 +--- a/grub-core/boot/i386/pc/diskboot.S ++++ b/grub-core/boot/i386/pc/diskboot.S +@@ -19,6 +19,8 @@ + #include + #include + ++#define TPM 1 ++ + /* + * defines for the code go here + */ +@@ -53,6 +55,21 @@ _start: + /* this sets up for the first run through "bootloop" */ + movw $LOCAL(firstlist), %di + ++#ifdef TPM ++ /* clear EAX to remove potential garbage */ ++ xorl %eax, %eax ++ /* 8(%di) = number of sectors to read */ ++ movw 8(%di), %ax ++ ++ /* Multiply number of sectors to read with 512 bytes. EAX is 32bit ++ * which is large enough to hold values of up to 4GB. I doubt there ++ * will ever be a core.img larger than that. ;-) */ ++ shll $9, %eax ++ ++ /* write result to bytes_to_measure var */ ++ movl %eax, bytes_to_measure ++#endif ++ + /* save the sector number of the second sector in %ebp */ + movl (%di), %ebp + +@@ -290,6 +307,29 @@ LOCAL(copy_buffer): + /* END OF MAIN LOOP */ + + LOCAL(bootit): ++#ifdef TPM ++ pusha ++ movw $0xBB07, %ax /* TCG_CompactHashLogExtendEvent */ ++ ++ movw $0x0, %bx ++ movw %bx, %es ++ ++ /* We've already measured the first 512 bytes, now measure the rest */ ++ xorl %edi, %edi ++ movw $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200), %di ++ ++ movl $0x41504354, %ebx /* EBX = "TCPA" */ ++ ++ /* %ecx = The length, in bytes, of the buffer to measure */ ++ movl $bytes_to_measure, %esi ++ movl (%esi), %ecx ++ xorl %esi, %esi ++ movl $0x9, %edx /* PCR 9 */ ++ ++ int $0x1A ++ ++ popa ++#endif + /* print a newline */ + MSG(notification_done) + popw %dx /* this makes sure %dl is our "boot" drive */ +@@ -324,6 +364,10 @@ geometry_error_string: .asciz "Geom" + read_error_string: .asciz "Read" + general_error_string: .asciz " Error" + ++#ifdef TPM ++bytes_to_measure: .long 0 ++#endif ++ + /* + * message: write the string pointed to by %si + * diff --git a/0307-Measure-commands.patch b/0307-Measure-commands.patch deleted file mode 100644 index bac4c8d..0000000 --- a/0307-Measure-commands.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Mon, 10 Aug 2015 15:27:12 -0700 -Subject: [PATCH] Measure commands - -Measure each command executed by grub, which includes script execution. ---- - grub-core/script/execute.c | 25 +++++++++++++++++++++++-- - include/grub/tpm.h | 1 + - 2 files changed, 24 insertions(+), 2 deletions(-) - -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index cf6cd6601d6..9ae04a05160 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -30,6 +30,7 @@ - #ifdef GRUB_MACHINE_IEEE1275 - #include - #endif -+#include - - /* 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. */ -@@ -967,8 +968,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) - grub_err_t ret = 0; - grub_script_function_t func = 0; - char errnobuf[18]; -- char *cmdname; -- int argc; -+ char *cmdname, *cmdstring; -+ int argc, offset = 0, cmdlen = 0; -+ unsigned int i; - char **args; - int invert; - struct grub_script_argv argv = { 0, 0, 0 }; -@@ -977,6 +979,25 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) - if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0]) - return grub_errno; - -+ for (i = 0; i < argv.argc; i++) { -+ cmdlen += grub_strlen (argv.args[i]) + 1; -+ } -+ -+ cmdstring = grub_malloc (cmdlen); -+ if (!cmdstring) -+ { -+ return grub_error (GRUB_ERR_OUT_OF_MEMORY, -+ N_("cannot allocate command buffer")); -+ } -+ -+ for (i = 0; i < argv.argc; i++) { -+ offset += grub_snprintf (cmdstring + offset, cmdlen - offset, "%s ", -+ argv.args[i]); -+ } -+ cmdstring[cmdlen-1]= '\0'; -+ grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_COMMAND_PCR, -+ cmdstring); -+ grub_free(cmdstring); - invert = 0; - argc = argv.argc - 1; - args = argv.args + 1; -diff --git a/include/grub/tpm.h b/include/grub/tpm.h -index 40d3cf65ba6..7fc9d77d277 100644 ---- a/include/grub/tpm.h -+++ b/include/grub/tpm.h -@@ -30,6 +30,7 @@ - #define GRUB_KERNEL_PCR 10 - #define GRUB_INITRD_PCR 11 - #define GRUB_CMDLINE_PCR 12 -+#define GRUB_COMMAND_PCR 13 - - #define TPM_TAG_RQU_COMMAND 0x00C1 - #define TPM_ORD_Extend 0x14 diff --git a/0308-Measure-kernel-and-initrd-on-BIOS-systems.patch b/0308-Measure-kernel-and-initrd-on-BIOS-systems.patch new file mode 100644 index 0000000..92c6c60 --- /dev/null +++ b/0308-Measure-kernel-and-initrd-on-BIOS-systems.patch @@ -0,0 +1,84 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Sun, 9 Aug 2015 16:28:29 -0700 +Subject: [PATCH] Measure kernel and initrd on BIOS systems + +Measure the kernel and initrd when loaded on BIOS systems +--- + grub-core/loader/i386/linux.c | 5 +++++ + grub-core/loader/i386/pc/linux.c | 3 +++ + grub-core/loader/linux.c | 2 ++ + 3 files changed, 10 insertions(+) + +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 35055431247..24fb1084b25 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+"); + +@@ -718,7 +719,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "Linux Kernel"); ++ + grub_memcpy (&lh, kernel, sizeof (lh)); ++ + kernel_offset = sizeof (lh); + + if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) +@@ -1032,6 +1036,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + + len = prot_file_size; + grub_memcpy (prot_mode_mem, kernel + kernel_offset, len); ++ kernel_offset += len; + + if (grub_errno == GRUB_ERR_NONE) + { +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index e2bb1a99a74..654e363e584 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+"); + +@@ -161,6 +162,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + ++ grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "BIOS Linux Kernel"); ++ + grub_memcpy (&lh, kernel, sizeof (lh)); + kernel_offset = sizeof (lh); + +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index be6fa0f4d45..3005c0d19c9 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + + struct newc_head + { +@@ -288,6 +289,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, + grub_initrd_close (initrd_ctx); + return grub_errno; + } ++ grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "Linux Initrd"); + ptr += cursize; + } + if (newc) diff --git a/0308-Measure-multiboot-images-and-modules.patch b/0308-Measure-multiboot-images-and-modules.patch deleted file mode 100644 index 0c19d8d..0000000 --- a/0308-Measure-multiboot-images-and-modules.patch +++ /dev/null @@ -1,75 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Tue, 1 Sep 2015 16:02:55 -0700 -Subject: [PATCH] Measure multiboot images and modules - ---- - grub-core/loader/i386/multiboot_mbi.c | 3 +++ - grub-core/loader/multiboot.c | 2 ++ - grub-core/loader/multiboot_mbi2.c | 4 +++- - 3 files changed, 8 insertions(+), 1 deletion(-) - -diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c -index dc98dbcae25..1c5b0ac25ce 100644 ---- a/grub-core/loader/i386/multiboot_mbi.c -+++ b/grub-core/loader/i386/multiboot_mbi.c -@@ -36,6 +36,7 @@ - #include - #include - #include -+#include - - #ifdef GRUB_MACHINE_EFI - #include -@@ -173,6 +174,8 @@ grub_multiboot_load (grub_file_t file, const char *filename) - return grub_errno; - } - -+ grub_tpm_measure((unsigned char*)buffer, len, GRUB_KERNEL_PCR, filename); -+ - header = find_header (buffer, len); - - if (header == 0) -diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 26df46a4161..93e026c53db 100644 ---- a/grub-core/loader/multiboot.c -+++ b/grub-core/loader/multiboot.c -@@ -51,6 +51,7 @@ - #include - #include - #include -+#include - - GRUB_MOD_LICENSE ("GPLv3+"); - -@@ -440,6 +441,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), - } - - grub_file_close (file); -+ grub_tpm_measure (module, size, GRUB_KERNEL_PCR, argv[0]); - return GRUB_ERR_NONE; - } - -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index 4df6595954d..d5ad02a33a1 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -36,6 +36,7 @@ - #include - #include - #include -+#include - - #if defined (GRUB_MACHINE_EFI) - #include -@@ -131,8 +132,9 @@ grub_multiboot2_load (grub_file_t file, const char *filename) - - COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); - -+ grub_tpm_measure ((unsigned char *)buffer, len, GRUB_KERNEL_PCR, filename); -+ - header = find_header (mld.buffer, len); -- - if (header == 0) - { - grub_free (mld.buffer); diff --git a/0309-Fix-boot-when-there-s-no-TPM.patch b/0309-Fix-boot-when-there-s-no-TPM.patch deleted file mode 100644 index 60efb93..0000000 --- a/0309-Fix-boot-when-there-s-no-TPM.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Wed, 23 Mar 2016 16:49:42 -0700 -Subject: [PATCH] Fix boot when there's no TPM - -If the firmware has TPM support but has no TPM, we're jumping to core.img -without popping the registers back onto the stack. Fix that. - -(cherry picked from commit c2eee36ec08f8ed0cd25b8030276347680be4843) ---- - grub-core/boot/i386/pc/boot.S | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S -index c1df86dec0b..acab37369ae 100644 ---- a/grub-core/boot/i386/pc/boot.S -+++ b/grub-core/boot/i386/pc/boot.S -@@ -473,9 +473,9 @@ LOCAL(copy_buffer): - movl $0x8, %edx /* PCR 8 */ - int $0x1A - -- popa --#endif - boot: -+ popa -+#endif - /* boot kernel */ - jmp *(LOCAL(kernel_address)) - diff --git a/0309-Measure-the-kernel-commandline.patch b/0309-Measure-the-kernel-commandline.patch new file mode 100644 index 0000000..7fe2809 --- /dev/null +++ b/0309-Measure-the-kernel-commandline.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Sun, 9 Aug 2015 16:32:29 -0700 +Subject: [PATCH] Measure the kernel commandline + +Measure the kernel commandline to ensure that it hasn't been modified +--- + grub-core/lib/cmdline.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c +index 970ea868c14..6b56304d4a7 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -19,6 +19,7 @@ + + #include + #include ++#include + + static int + is_hex(char c) +@@ -79,7 +80,7 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + { + int i, space; + unsigned int arg_size; +- char *c; ++ char *c, *orig = buf; + + for (i = 0; i < argc; i++) + { +@@ -125,5 +126,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + + *buf = 0; + ++ grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_CMDLINE_PCR, ++ "Kernel Commandline"); ++ + return i; + } diff --git a/0310-Measure-commands.patch b/0310-Measure-commands.patch new file mode 100644 index 0000000..bac4c8d --- /dev/null +++ b/0310-Measure-commands.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Mon, 10 Aug 2015 15:27:12 -0700 +Subject: [PATCH] Measure commands + +Measure each command executed by grub, which includes script execution. +--- + grub-core/script/execute.c | 25 +++++++++++++++++++++++-- + include/grub/tpm.h | 1 + + 2 files changed, 24 insertions(+), 2 deletions(-) + +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index cf6cd6601d6..9ae04a05160 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -30,6 +30,7 @@ + #ifdef GRUB_MACHINE_IEEE1275 + #include + #endif ++#include + + /* 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. */ +@@ -967,8 +968,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) + grub_err_t ret = 0; + grub_script_function_t func = 0; + char errnobuf[18]; +- char *cmdname; +- int argc; ++ char *cmdname, *cmdstring; ++ int argc, offset = 0, cmdlen = 0; ++ unsigned int i; + char **args; + int invert; + struct grub_script_argv argv = { 0, 0, 0 }; +@@ -977,6 +979,25 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) + if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0]) + return grub_errno; + ++ for (i = 0; i < argv.argc; i++) { ++ cmdlen += grub_strlen (argv.args[i]) + 1; ++ } ++ ++ cmdstring = grub_malloc (cmdlen); ++ if (!cmdstring) ++ { ++ return grub_error (GRUB_ERR_OUT_OF_MEMORY, ++ N_("cannot allocate command buffer")); ++ } ++ ++ for (i = 0; i < argv.argc; i++) { ++ offset += grub_snprintf (cmdstring + offset, cmdlen - offset, "%s ", ++ argv.args[i]); ++ } ++ cmdstring[cmdlen-1]= '\0'; ++ grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_COMMAND_PCR, ++ cmdstring); ++ grub_free(cmdstring); + invert = 0; + argc = argv.argc - 1; + args = argv.args + 1; +diff --git a/include/grub/tpm.h b/include/grub/tpm.h +index 40d3cf65ba6..7fc9d77d277 100644 +--- a/include/grub/tpm.h ++++ b/include/grub/tpm.h +@@ -30,6 +30,7 @@ + #define GRUB_KERNEL_PCR 10 + #define GRUB_INITRD_PCR 11 + #define GRUB_CMDLINE_PCR 12 ++#define GRUB_COMMAND_PCR 13 + + #define TPM_TAG_RQU_COMMAND 0x00C1 + #define TPM_ORD_Extend 0x14 diff --git a/0310-Rework-TPM-measurements.patch b/0310-Rework-TPM-measurements.patch deleted file mode 100644 index 2ff2028..0000000 --- a/0310-Rework-TPM-measurements.patch +++ /dev/null @@ -1,216 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Wed, 23 Mar 2016 17:03:43 -0700 -Subject: [PATCH] Rework TPM measurements - -Rework TPM measurements to use fewer PCRs. After discussion with upstream, -it's preferable to avoid using so many PCRs. Instead, measure into PCRs 8 -and 9 but use a prefix in the event log to indicate which subsystem carried -out the measurements. - -(cherry picked from commit bb3473d7c8741ad5ef7cf8aafbbcf094df08bfc9) ---- - grub-core/kern/dl.c | 2 +- - grub-core/kern/tpm.c | 10 ++++++++-- - grub-core/lib/cmdline.c | 4 ++-- - grub-core/loader/i386/efi/linux.c | 4 ++-- - grub-core/loader/i386/linux.c | 2 +- - grub-core/loader/i386/multiboot_mbi.c | 2 +- - grub-core/loader/i386/pc/linux.c | 2 +- - grub-core/loader/linux.c | 2 +- - grub-core/loader/multiboot.c | 2 +- - grub-core/loader/multiboot_mbi2.c | 2 +- - grub-core/script/execute.c | 4 ++-- - include/grub/tpm.h | 9 +++------ - 12 files changed, 24 insertions(+), 21 deletions(-) - -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index 387d1e6446d..d0989573866 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -830,7 +830,7 @@ grub_dl_load_file (const char *filename) - opens of the same device. */ - grub_file_close (file); - -- grub_tpm_measure(core, size, GRUB_TPM_PCR, filename); -+ grub_tpm_measure(core, size, GRUB_BINARY_PCR, "grub_module", filename); - - mod = grub_dl_load_core (core, size); - grub_free (core); -diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c -index 1a991876c83..cb5a812035d 100644 ---- a/grub-core/kern/tpm.c -+++ b/grub-core/kern/tpm.c -@@ -7,7 +7,13 @@ - - grub_err_t - grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, -- const char *description) -+ const char *kind, const char *description) - { -- return grub_tpm_log_event(buf, size, pcr, description); -+ grub_err_t ret; -+ char *desc = grub_xasprintf("%s %s", kind, description); -+ if (!desc) -+ return GRUB_ERR_OUT_OF_MEMORY; -+ ret = grub_tpm_log_event(buf, size, pcr, description); -+ grub_free(desc); -+ return ret; - } -diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c -index 6b56304d4a7..178f7382f07 100644 ---- a/grub-core/lib/cmdline.c -+++ b/grub-core/lib/cmdline.c -@@ -126,8 +126,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, - - *buf = 0; - -- grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_CMDLINE_PCR, -- "Kernel Commandline"); -+ grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_ASCII_PCR, -+ "grub_kernel_cmdline", orig); - - return i; - } -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 95a197743a9..8bb759d8a91 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -133,7 +133,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - argv[i]); - goto fail; - } -- grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "UEFI Linux initrd"); -+ grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_linuxefi", "Initrd"); - ptr += cursize; - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr += ALIGN_UP_OVERHEAD (cursize, 4); -@@ -198,7 +198,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_tpm_measure (kernel, filelen, GRUB_KERNEL_PCR, "UEFI Linux kernel"); -+ grub_tpm_measure (kernel, filelen, GRUB_BINARY_PCR, "grub_linuxefi", "Kernel"); - - rc = grub_linuxefi_secure_validate (kernel, filelen); - if (rc < 0) -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index 24fb1084b25..e052c5ddebc 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -719,7 +719,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "Linux Kernel"); -+ grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Kernel"); - - grub_memcpy (&lh, kernel, sizeof (lh)); - -diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c -index 1c5b0ac25ce..2ce424a997b 100644 ---- a/grub-core/loader/i386/multiboot_mbi.c -+++ b/grub-core/loader/i386/multiboot_mbi.c -@@ -174,7 +174,7 @@ grub_multiboot_load (grub_file_t file, const char *filename) - return grub_errno; - } - -- grub_tpm_measure((unsigned char*)buffer, len, GRUB_KERNEL_PCR, filename); -+ grub_tpm_measure((unsigned char*)buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); - - header = find_header (buffer, len); - -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 654e363e584..547df29c213 100644 ---- a/grub-core/loader/i386/pc/linux.c -+++ b/grub-core/loader/i386/pc/linux.c -@@ -162,7 +162,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - -- grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "BIOS Linux Kernel"); -+ grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel"); - - grub_memcpy (&lh, kernel, sizeof (lh)); - kernel_offset = sizeof (lh); -diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c -index 3005c0d19c9..78c41e33416 100644 ---- a/grub-core/loader/linux.c -+++ b/grub-core/loader/linux.c -@@ -289,7 +289,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, - grub_initrd_close (initrd_ctx); - return grub_errno; - } -- grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "Linux Initrd"); -+ grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Initrd"); - ptr += cursize; - } - if (newc) -diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 93e026c53db..3b87dc4fab3 100644 ---- a/grub-core/loader/multiboot.c -+++ b/grub-core/loader/multiboot.c -@@ -441,7 +441,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), - } - - grub_file_close (file); -- grub_tpm_measure (module, size, GRUB_KERNEL_PCR, argv[0]); -+ grub_tpm_measure (module, size, GRUB_BINARY_PCR, "grub_multiboot", argv[0]); - return GRUB_ERR_NONE; - } - -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index d5ad02a33a1..60ae4606fda 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -132,7 +132,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) - - COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); - -- grub_tpm_measure ((unsigned char *)buffer, len, GRUB_KERNEL_PCR, filename); -+ grub_tpm_measure ((unsigned char *)mld.buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); - - header = find_header (mld.buffer, len); - if (header == 0) -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index 9ae04a05160..976643c47b0 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -995,8 +995,8 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) - argv.args[i]); - } - cmdstring[cmdlen-1]= '\0'; -- grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_COMMAND_PCR, -- cmdstring); -+ grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_ASCII_PCR, -+ "grub_cmd", cmdstring); - grub_free(cmdstring); - invert = 0; - argc = argv.argc - 1; -diff --git a/include/grub/tpm.h b/include/grub/tpm.h -index 7fc9d77d277..ecb2d09ff5d 100644 ---- a/include/grub/tpm.h -+++ b/include/grub/tpm.h -@@ -26,11 +26,8 @@ - #define TPM_AUTHFAIL (TPM_BASE + 0x1) - #define TPM_BADINDEX (TPM_BASE + 0x2) - --#define GRUB_TPM_PCR 9 --#define GRUB_KERNEL_PCR 10 --#define GRUB_INITRD_PCR 11 --#define GRUB_CMDLINE_PCR 12 --#define GRUB_COMMAND_PCR 13 -+#define GRUB_ASCII_PCR 8 -+#define GRUB_BINARY_PCR 9 - - #define TPM_TAG_RQU_COMMAND 0x00C1 - #define TPM_ORD_Extend 0x14 -@@ -70,7 +67,7 @@ typedef struct { - } GRUB_PACKED ExtendOutgoing; - - grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size, -- grub_uint8_t pcr, -+ grub_uint8_t pcr, const char *kind, - const char *description); - #if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) - grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, diff --git a/0311-Fix-event-log-prefix.patch b/0311-Fix-event-log-prefix.patch deleted file mode 100644 index 7b98f9a..0000000 --- a/0311-Fix-event-log-prefix.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Tue, 29 Mar 2016 15:36:49 -0700 -Subject: [PATCH] Fix event log prefix - -We're not passing the prefixed version of the description to the event log. -Fix that. - -(cherry picked from commit aab446306b8a78c741e229861c4988738cfc6426) ---- - grub-core/kern/tpm.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c -index cb5a812035d..e5e8fced624 100644 ---- a/grub-core/kern/tpm.c -+++ b/grub-core/kern/tpm.c -@@ -13,7 +13,7 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, - char *desc = grub_xasprintf("%s %s", kind, description); - if (!desc) - return GRUB_ERR_OUT_OF_MEMORY; -- ret = grub_tpm_log_event(buf, size, pcr, description); -+ ret = grub_tpm_log_event(buf, size, pcr, desc); - grub_free(desc); - return ret; - } diff --git a/0311-Measure-multiboot-images-and-modules.patch b/0311-Measure-multiboot-images-and-modules.patch new file mode 100644 index 0000000..0c19d8d --- /dev/null +++ b/0311-Measure-multiboot-images-and-modules.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Tue, 1 Sep 2015 16:02:55 -0700 +Subject: [PATCH] Measure multiboot images and modules + +--- + grub-core/loader/i386/multiboot_mbi.c | 3 +++ + grub-core/loader/multiboot.c | 2 ++ + grub-core/loader/multiboot_mbi2.c | 4 +++- + 3 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c +index dc98dbcae25..1c5b0ac25ce 100644 +--- a/grub-core/loader/i386/multiboot_mbi.c ++++ b/grub-core/loader/i386/multiboot_mbi.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + #ifdef GRUB_MACHINE_EFI + #include +@@ -173,6 +174,8 @@ grub_multiboot_load (grub_file_t file, const char *filename) + return grub_errno; + } + ++ grub_tpm_measure((unsigned char*)buffer, len, GRUB_KERNEL_PCR, filename); ++ + header = find_header (buffer, len); + + if (header == 0) +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 26df46a4161..93e026c53db 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -51,6 +51,7 @@ + #include + #include + #include ++#include + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -440,6 +441,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), + } + + grub_file_close (file); ++ grub_tpm_measure (module, size, GRUB_KERNEL_PCR, argv[0]); + return GRUB_ERR_NONE; + } + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 4df6595954d..d5ad02a33a1 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + #if defined (GRUB_MACHINE_EFI) + #include +@@ -131,8 +132,9 @@ grub_multiboot2_load (grub_file_t file, const char *filename) + + COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); + ++ grub_tpm_measure ((unsigned char *)buffer, len, GRUB_KERNEL_PCR, filename); ++ + header = find_header (mld.buffer, len); +- + if (header == 0) + { + grub_free (mld.buffer); diff --git a/0312-Fix-boot-when-there-s-no-TPM.patch b/0312-Fix-boot-when-there-s-no-TPM.patch new file mode 100644 index 0000000..60efb93 --- /dev/null +++ b/0312-Fix-boot-when-there-s-no-TPM.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Wed, 23 Mar 2016 16:49:42 -0700 +Subject: [PATCH] Fix boot when there's no TPM + +If the firmware has TPM support but has no TPM, we're jumping to core.img +without popping the registers back onto the stack. Fix that. + +(cherry picked from commit c2eee36ec08f8ed0cd25b8030276347680be4843) +--- + grub-core/boot/i386/pc/boot.S | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/boot/i386/pc/boot.S b/grub-core/boot/i386/pc/boot.S +index c1df86dec0b..acab37369ae 100644 +--- a/grub-core/boot/i386/pc/boot.S ++++ b/grub-core/boot/i386/pc/boot.S +@@ -473,9 +473,9 @@ LOCAL(copy_buffer): + movl $0x8, %edx /* PCR 8 */ + int $0x1A + +- popa +-#endif + boot: ++ popa ++#endif + /* boot kernel */ + jmp *(LOCAL(kernel_address)) + diff --git a/0312-Set-the-first-boot-menu-entry-as-default-when-using-.patch b/0312-Set-the-first-boot-menu-entry-as-default-when-using-.patch deleted file mode 100644 index 31ddeee..0000000 --- a/0312-Set-the-first-boot-menu-entry-as-default-when-using-.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 6 Apr 2018 14:08:36 +0200 -Subject: [PATCH] Set the first boot menu entry as default when using BLS - fragments - -When BootLoaderSpec configuration files are used, the default boot menu -entry is always set to the first entry as sorted by the blscfg command. - -Suggested-by: Peter Jones -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index aec1ca3eba0..1e7ec7071c3 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -158,6 +158,7 @@ if [ -s \$prefix/grubenv ]; then - fi - EOF - -+ ${grub_editenv} - set saved_entry=0 - ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" - - exit 0 diff --git a/0313-Rework-TPM-measurements.patch b/0313-Rework-TPM-measurements.patch new file mode 100644 index 0000000..2ff2028 --- /dev/null +++ b/0313-Rework-TPM-measurements.patch @@ -0,0 +1,216 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Wed, 23 Mar 2016 17:03:43 -0700 +Subject: [PATCH] Rework TPM measurements + +Rework TPM measurements to use fewer PCRs. After discussion with upstream, +it's preferable to avoid using so many PCRs. Instead, measure into PCRs 8 +and 9 but use a prefix in the event log to indicate which subsystem carried +out the measurements. + +(cherry picked from commit bb3473d7c8741ad5ef7cf8aafbbcf094df08bfc9) +--- + grub-core/kern/dl.c | 2 +- + grub-core/kern/tpm.c | 10 ++++++++-- + grub-core/lib/cmdline.c | 4 ++-- + grub-core/loader/i386/efi/linux.c | 4 ++-- + grub-core/loader/i386/linux.c | 2 +- + grub-core/loader/i386/multiboot_mbi.c | 2 +- + grub-core/loader/i386/pc/linux.c | 2 +- + grub-core/loader/linux.c | 2 +- + grub-core/loader/multiboot.c | 2 +- + grub-core/loader/multiboot_mbi2.c | 2 +- + grub-core/script/execute.c | 4 ++-- + include/grub/tpm.h | 9 +++------ + 12 files changed, 24 insertions(+), 21 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 387d1e6446d..d0989573866 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -830,7 +830,7 @@ grub_dl_load_file (const char *filename) + opens of the same device. */ + grub_file_close (file); + +- grub_tpm_measure(core, size, GRUB_TPM_PCR, filename); ++ grub_tpm_measure(core, size, GRUB_BINARY_PCR, "grub_module", filename); + + mod = grub_dl_load_core (core, size); + grub_free (core); +diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c +index 1a991876c83..cb5a812035d 100644 +--- a/grub-core/kern/tpm.c ++++ b/grub-core/kern/tpm.c +@@ -7,7 +7,13 @@ + + grub_err_t + grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, +- const char *description) ++ const char *kind, const char *description) + { +- return grub_tpm_log_event(buf, size, pcr, description); ++ grub_err_t ret; ++ char *desc = grub_xasprintf("%s %s", kind, description); ++ if (!desc) ++ return GRUB_ERR_OUT_OF_MEMORY; ++ ret = grub_tpm_log_event(buf, size, pcr, description); ++ grub_free(desc); ++ return ret; + } +diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c +index 6b56304d4a7..178f7382f07 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -126,8 +126,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + + *buf = 0; + +- grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_CMDLINE_PCR, +- "Kernel Commandline"); ++ grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_ASCII_PCR, ++ "grub_kernel_cmdline", orig); + + return i; + } +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 95a197743a9..8bb759d8a91 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -133,7 +133,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + argv[i]); + goto fail; + } +- grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "UEFI Linux initrd"); ++ grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_linuxefi", "Initrd"); + ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); +@@ -198,7 +198,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_tpm_measure (kernel, filelen, GRUB_KERNEL_PCR, "UEFI Linux kernel"); ++ grub_tpm_measure (kernel, filelen, GRUB_BINARY_PCR, "grub_linuxefi", "Kernel"); + + rc = grub_linuxefi_secure_validate (kernel, filelen); + if (rc < 0) +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index 24fb1084b25..e052c5ddebc 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -719,7 +719,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "Linux Kernel"); ++ grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Kernel"); + + grub_memcpy (&lh, kernel, sizeof (lh)); + +diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c +index 1c5b0ac25ce..2ce424a997b 100644 +--- a/grub-core/loader/i386/multiboot_mbi.c ++++ b/grub-core/loader/i386/multiboot_mbi.c +@@ -174,7 +174,7 @@ grub_multiboot_load (grub_file_t file, const char *filename) + return grub_errno; + } + +- grub_tpm_measure((unsigned char*)buffer, len, GRUB_KERNEL_PCR, filename); ++ grub_tpm_measure((unsigned char*)buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); + + header = find_header (buffer, len); + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 654e363e584..547df29c213 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -162,7 +162,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + +- grub_tpm_measure (kernel, len, GRUB_KERNEL_PCR, "BIOS Linux Kernel"); ++ grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel"); + + grub_memcpy (&lh, kernel, sizeof (lh)); + kernel_offset = sizeof (lh); +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 3005c0d19c9..78c41e33416 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -289,7 +289,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, + grub_initrd_close (initrd_ctx); + return grub_errno; + } +- grub_tpm_measure (ptr, cursize, GRUB_INITRD_PCR, "Linux Initrd"); ++ grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Initrd"); + ptr += cursize; + } + if (newc) +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 93e026c53db..3b87dc4fab3 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -441,7 +441,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), + } + + grub_file_close (file); +- grub_tpm_measure (module, size, GRUB_KERNEL_PCR, argv[0]); ++ grub_tpm_measure (module, size, GRUB_BINARY_PCR, "grub_multiboot", argv[0]); + return GRUB_ERR_NONE; + } + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index d5ad02a33a1..60ae4606fda 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -132,7 +132,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) + + COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); + +- grub_tpm_measure ((unsigned char *)buffer, len, GRUB_KERNEL_PCR, filename); ++ grub_tpm_measure ((unsigned char *)mld.buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); + + header = find_header (mld.buffer, len); + if (header == 0) +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index 9ae04a05160..976643c47b0 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -995,8 +995,8 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) + argv.args[i]); + } + cmdstring[cmdlen-1]= '\0'; +- grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_COMMAND_PCR, +- cmdstring); ++ grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_ASCII_PCR, ++ "grub_cmd", cmdstring); + grub_free(cmdstring); + invert = 0; + argc = argv.argc - 1; +diff --git a/include/grub/tpm.h b/include/grub/tpm.h +index 7fc9d77d277..ecb2d09ff5d 100644 +--- a/include/grub/tpm.h ++++ b/include/grub/tpm.h +@@ -26,11 +26,8 @@ + #define TPM_AUTHFAIL (TPM_BASE + 0x1) + #define TPM_BADINDEX (TPM_BASE + 0x2) + +-#define GRUB_TPM_PCR 9 +-#define GRUB_KERNEL_PCR 10 +-#define GRUB_INITRD_PCR 11 +-#define GRUB_CMDLINE_PCR 12 +-#define GRUB_COMMAND_PCR 13 ++#define GRUB_ASCII_PCR 8 ++#define GRUB_BINARY_PCR 9 + + #define TPM_TAG_RQU_COMMAND 0x00C1 + #define TPM_ORD_Extend 0x14 +@@ -70,7 +67,7 @@ typedef struct { + } GRUB_PACKED ExtendOutgoing; + + grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size, +- grub_uint8_t pcr, ++ grub_uint8_t pcr, const char *kind, + const char *description); + #if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_PCBIOS) + grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, diff --git a/0313-tpm-fix-warnings-when-compiling-for-platforms-other-.patch b/0313-tpm-fix-warnings-when-compiling-for-platforms-other-.patch deleted file mode 100644 index 9f9373f..0000000 --- a/0313-tpm-fix-warnings-when-compiling-for-platforms-other-.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Michael Marineau -Date: Sun, 21 Aug 2016 18:24:58 -0700 -Subject: [PATCH] tpm: fix warnings when compiling for platforms other than pc - and efi - ---- - include/grub/tpm.h | 17 +++++++++++------ - 1 file changed, 11 insertions(+), 6 deletions(-) - -diff --git a/include/grub/tpm.h b/include/grub/tpm.h -index ecb2d09ff5d..972a5edc836 100644 ---- a/include/grub/tpm.h -+++ b/include/grub/tpm.h -@@ -75,12 +75,17 @@ grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, - grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size, - grub_uint8_t pcr, const char *description); - #else --static inline grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, -- PassThroughToTPM_OutputParamBlock *outbuf) { return 0; }; --static inline grub_err_t grub_tpm_log_event(unsigned char *buf, -- grub_size_t size, -- grub_uint8_t pcr, -- const char *description) -+static inline grub_err_t grub_tpm_execute( -+ PassThroughToTPM_InputParamBlock *inbuf __attribute__ ((unused)), -+ PassThroughToTPM_OutputParamBlock *outbuf __attribute__ ((unused))) -+{ -+ return 0; -+}; -+static inline grub_err_t grub_tpm_log_event( -+ unsigned char *buf __attribute__ ((unused)), -+ grub_size_t size __attribute__ ((unused)), -+ grub_uint8_t pcr __attribute__ ((unused)), -+ const char *description __attribute__ ((unused))) - { - return 0; - }; diff --git a/0314-Fix-event-log-prefix.patch b/0314-Fix-event-log-prefix.patch new file mode 100644 index 0000000..7b98f9a --- /dev/null +++ b/0314-Fix-event-log-prefix.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Tue, 29 Mar 2016 15:36:49 -0700 +Subject: [PATCH] Fix event log prefix + +We're not passing the prefixed version of the description to the event log. +Fix that. + +(cherry picked from commit aab446306b8a78c741e229861c4988738cfc6426) +--- + grub-core/kern/tpm.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/kern/tpm.c b/grub-core/kern/tpm.c +index cb5a812035d..e5e8fced624 100644 +--- a/grub-core/kern/tpm.c ++++ b/grub-core/kern/tpm.c +@@ -13,7 +13,7 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, + char *desc = grub_xasprintf("%s %s", kind, description); + if (!desc) + return GRUB_ERR_OUT_OF_MEMORY; +- ret = grub_tpm_log_event(buf, size, pcr, description); ++ ret = grub_tpm_log_event(buf, size, pcr, desc); + grub_free(desc); + return ret; + } diff --git a/0314-Make-TPM-errors-less-fatal.patch b/0314-Make-TPM-errors-less-fatal.patch deleted file mode 100644 index 12678d3..0000000 --- a/0314-Make-TPM-errors-less-fatal.patch +++ /dev/null @@ -1,208 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Matthew Garrett -Date: Thu, 13 Oct 2016 13:55:26 -0700 -Subject: [PATCH] Make TPM errors less fatal - -Handle TPM errors, and stop trying to use the TPM once we hit one. ---- - grub-core/kern/dl.c | 1 + - grub-core/kern/i386/pc/tpm.c | 21 +++++++++++++++++---- - grub-core/lib/cmdline.c | 1 + - grub-core/loader/i386/efi/linux.c | 2 ++ - grub-core/loader/i386/linux.c | 1 + - grub-core/loader/i386/multiboot_mbi.c | 1 + - grub-core/loader/i386/pc/linux.c | 1 + - grub-core/loader/linux.c | 2 ++ - grub-core/loader/multiboot.c | 1 + - grub-core/loader/multiboot_mbi2.c | 1 + - grub-core/script/execute.c | 1 + - 11 files changed, 29 insertions(+), 4 deletions(-) - -diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c -index d0989573866..91105bc4677 100644 ---- a/grub-core/kern/dl.c -+++ b/grub-core/kern/dl.c -@@ -831,6 +831,7 @@ grub_dl_load_file (const char *filename) - grub_file_close (file); - - grub_tpm_measure(core, size, GRUB_BINARY_PCR, "grub_module", filename); -+ grub_print_error(); - - mod = grub_dl_load_core (core, size); - grub_free (core); -diff --git a/grub-core/kern/i386/pc/tpm.c b/grub-core/kern/i386/pc/tpm.c -index 8c6c1e6ece2..f6f264aff2e 100644 ---- a/grub-core/kern/i386/pc/tpm.c -+++ b/grub-core/kern/i386/pc/tpm.c -@@ -7,21 +7,28 @@ - - #define TCPA_MAGIC 0x41504354 - -+static int tpm_presence = -1; -+ - int tpm_present(void); - - int tpm_present(void) - { - struct grub_bios_int_registers regs; - -+ if (tpm_presence != -1) -+ return tpm_presence; -+ - regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; - regs.eax = 0xbb00; - regs.ebx = TCPA_MAGIC; - grub_bios_interrupt (0x1a, ®s); - - if (regs.eax == 0) -- return 1; -+ tpm_presence = 1; -+ else -+ tpm_presence = 0; - -- return 0; -+ return tpm_presence; - } - - grub_err_t -@@ -49,7 +56,10 @@ grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, - grub_bios_interrupt (0x1a, ®s); - - if (regs.eax) -- return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); -+ { -+ tpm_presence = 0; -+ return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax); -+ } - - return 0; - } -@@ -126,7 +136,10 @@ grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, - grub_free(event); - - if (regs.eax) -- return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); -+ { -+ tpm_presence = 0; -+ return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax); -+ } - - return 0; - } -diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c -index 178f7382f07..d5c12957cad 100644 ---- a/grub-core/lib/cmdline.c -+++ b/grub-core/lib/cmdline.c -@@ -128,6 +128,7 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, - - grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_ASCII_PCR, - "grub_kernel_cmdline", orig); -+ grub_print_error(); - - return i; - } -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 8bb759d8a91..66e58b71e22 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -134,6 +134,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), - goto fail; - } - grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_linuxefi", "Initrd"); -+ grub_print_error(); - ptr += cursize; - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr += ALIGN_UP_OVERHEAD (cursize, 4); -@@ -199,6 +200,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - grub_tpm_measure (kernel, filelen, GRUB_BINARY_PCR, "grub_linuxefi", "Kernel"); -+ grub_print_error(); - - rc = grub_linuxefi_secure_validate (kernel, filelen); - if (rc < 0) -diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c -index e052c5ddebc..cec0a96c022 100644 ---- a/grub-core/loader/i386/linux.c -+++ b/grub-core/loader/i386/linux.c -@@ -720,6 +720,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Kernel"); -+ grub_print_error(); - - grub_memcpy (&lh, kernel, sizeof (lh)); - -diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c -index 2ce424a997b..ca85358f771 100644 ---- a/grub-core/loader/i386/multiboot_mbi.c -+++ b/grub-core/loader/i386/multiboot_mbi.c -@@ -175,6 +175,7 @@ grub_multiboot_load (grub_file_t file, const char *filename) - } - - grub_tpm_measure((unsigned char*)buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); -+ grub_print_error(); - - header = find_header (buffer, len); - -diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c -index 547df29c213..1e369afcbad 100644 ---- a/grub-core/loader/i386/pc/linux.c -+++ b/grub-core/loader/i386/pc/linux.c -@@ -163,6 +163,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel"); -+ grub_print_error(); - - grub_memcpy (&lh, kernel, sizeof (lh)); - kernel_offset = sizeof (lh); -diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c -index 78c41e33416..c2c7cfcd0fd 100644 ---- a/grub-core/loader/linux.c -+++ b/grub-core/loader/linux.c -@@ -290,6 +290,8 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, - return grub_errno; - } - grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Initrd"); -+ grub_print_error(); -+ - ptr += cursize; - } - if (newc) -diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c -index 3b87dc4fab3..9a8dae5565b 100644 ---- a/grub-core/loader/multiboot.c -+++ b/grub-core/loader/multiboot.c -@@ -442,6 +442,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), - - grub_file_close (file); - grub_tpm_measure (module, size, GRUB_BINARY_PCR, "grub_multiboot", argv[0]); -+ grub_print_error(); - return GRUB_ERR_NONE; - } - -diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c -index 60ae4606fda..54078455e2f 100644 ---- a/grub-core/loader/multiboot_mbi2.c -+++ b/grub-core/loader/multiboot_mbi2.c -@@ -133,6 +133,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) - COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); - - grub_tpm_measure ((unsigned char *)mld.buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); -+ grub_print_error(); - - header = find_header (mld.buffer, len); - if (header == 0) -diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c -index 976643c47b0..93965777138 100644 ---- a/grub-core/script/execute.c -+++ b/grub-core/script/execute.c -@@ -997,6 +997,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) - cmdstring[cmdlen-1]= '\0'; - grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_ASCII_PCR, - "grub_cmd", cmdstring); -+ grub_print_error(); - grub_free(cmdstring); - invert = 0; - argc = argv.argc - 1; diff --git a/0315-Set-the-first-boot-menu-entry-as-default-when-using-.patch b/0315-Set-the-first-boot-menu-entry-as-default-when-using-.patch new file mode 100644 index 0000000..31ddeee --- /dev/null +++ b/0315-Set-the-first-boot-menu-entry-as-default-when-using-.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 6 Apr 2018 14:08:36 +0200 +Subject: [PATCH] Set the first boot menu entry as default when using BLS + fragments + +When BootLoaderSpec configuration files are used, the default boot menu +entry is always set to the first entry as sorted by the blscfg command. + +Suggested-by: Peter Jones +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index aec1ca3eba0..1e7ec7071c3 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -158,6 +158,7 @@ if [ -s \$prefix/grubenv ]; then + fi + EOF + ++ ${grub_editenv} - set saved_entry=0 + ${grub_editenv} - set kernelopts="root=${linux_root_device_thisversion} ro ${args}" + + exit 0 diff --git a/0315-blscfg-handle-multiple-initramfs-images.patch b/0315-blscfg-handle-multiple-initramfs-images.patch deleted file mode 100644 index 0e3d873..0000000 --- a/0315-blscfg-handle-multiple-initramfs-images.patch +++ /dev/null @@ -1,104 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Apr 2018 13:44:29 -0400 -Subject: [PATCH] blscfg: handle multiple initramfs images. - -Signed-off-by: Peter Jones ---- - grub-core/commands/blscfg.c | 54 ++++++++++++++++++++++++++++++++++++--------- - 1 file changed, 44 insertions(+), 10 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index c0973ff83ea..1e5972422d6 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -587,6 +587,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - char *title = NULL; - char *clinux = NULL; - char *options = NULL; -+ char **initrds = NULL; - char *initrd = NULL; - char *id = NULL; - char *hotkey = NULL; -@@ -609,7 +610,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - - title = bls_get_val (entry, "title", NULL); - options = bls_get_val (entry, "options", NULL); -- initrd = bls_get_val (entry, "initrd", NULL); -+ initrds = bls_make_list (entry, "initrd", NULL); - id = bls_get_val (entry, "id", NULL); - - hotkey = bls_get_val (entry, "grub_hotkey", NULL); -@@ -624,30 +625,63 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - argv[i] = args[i-1]; - argv[argc] = NULL; - -- grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title); -+ grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title); -+ if (initrds) -+ { -+ int initrd_size = sizeof (GRUB_INITRD_CMD); -+ char *tmp; -+ -+ 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, GRUB_INITRD_CMD); -+ 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 gfx_payload=keep\n" - "insmod gzio\n" - GRUB_LINUX_CMD " %s%s%s%s\n" -- "%s%s%s%s", -+ "%s", - GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", -- initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); -+ initrd ? initrd : ""); - - grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); - - finish: -+ if (initrd) -+ grub_free (initrd); -+ -+ if (initrds) -+ grub_free (initrds); -+ - if (classes) -- grub_free (classes); -- grub_dprintf("blscfg", "%s got here\n", __func__); -+ grub_free (classes); -+ - if (args) -- grub_free (args); -+ grub_free (args); - - if (argv) -- grub_free (argv); -+ grub_free (argv); - - if (src) -- grub_free (src); -- grub_dprintf("blscfg", "%s got here\n", __func__); -+ grub_free (src); - } - - struct find_entry_info { diff --git a/0316-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch b/0316-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch deleted file mode 100644 index a045646..0000000 --- a/0316-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Jan Hlavac -Date: Tue, 10 Apr 2018 16:07:36 +0200 -Subject: [PATCH] BLS: Fix grub2-switch-to-blscfg on non-EFI machines - -On the non-EFI machines the grub2-switch-to-blscfg script places the BLS -snippets into the /boot directory. But the right location is -/boot/loader/entries. ---- - util/grub-switch-to-blscfg.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 3ae5e4ea8d0..f740b8f4d03 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -44,7 +44,7 @@ if [ -d /sys/firmware/efi/efivars/ ]; then - else - startlink=/etc/grub2.cfg - grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` -- blsdir=`echo "/@bootdirname@" | sed 's,//*,/,g'` -+ blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` - fi - - backupsuffix=.bak diff --git a/0316-tpm-fix-warnings-when-compiling-for-platforms-other-.patch b/0316-tpm-fix-warnings-when-compiling-for-platforms-other-.patch new file mode 100644 index 0000000..9f9373f --- /dev/null +++ b/0316-tpm-fix-warnings-when-compiling-for-platforms-other-.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Marineau +Date: Sun, 21 Aug 2016 18:24:58 -0700 +Subject: [PATCH] tpm: fix warnings when compiling for platforms other than pc + and efi + +--- + include/grub/tpm.h | 17 +++++++++++------ + 1 file changed, 11 insertions(+), 6 deletions(-) + +diff --git a/include/grub/tpm.h b/include/grub/tpm.h +index ecb2d09ff5d..972a5edc836 100644 +--- a/include/grub/tpm.h ++++ b/include/grub/tpm.h +@@ -75,12 +75,17 @@ grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, + grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size, + grub_uint8_t pcr, const char *description); + #else +-static inline grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, +- PassThroughToTPM_OutputParamBlock *outbuf) { return 0; }; +-static inline grub_err_t grub_tpm_log_event(unsigned char *buf, +- grub_size_t size, +- grub_uint8_t pcr, +- const char *description) ++static inline grub_err_t grub_tpm_execute( ++ PassThroughToTPM_InputParamBlock *inbuf __attribute__ ((unused)), ++ PassThroughToTPM_OutputParamBlock *outbuf __attribute__ ((unused))) ++{ ++ return 0; ++}; ++static inline grub_err_t grub_tpm_log_event( ++ unsigned char *buf __attribute__ ((unused)), ++ grub_size_t size __attribute__ ((unused)), ++ grub_uint8_t pcr __attribute__ ((unused)), ++ const char *description __attribute__ ((unused))) + { + return 0; + }; diff --git a/0317-BLS-Use-etcdefaultgrub-instead-of-etc.patch b/0317-BLS-Use-etcdefaultgrub-instead-of-etc.patch deleted file mode 100644 index db97410..0000000 --- a/0317-BLS-Use-etcdefaultgrub-instead-of-etc.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Jan Hlavac -Date: Tue, 10 Apr 2018 16:56:28 +0200 -Subject: [PATCH] BLS: Use ${etcdefaultgrub} instead of /etc/... - -Inside the grub-switch-to-blscfg script the ${etcdefaultgrub} variable -is used. So replace the hardcoded /etc/default/grub with it. ---- - util/grub-switch-to-blscfg.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index f740b8f4d03..eae3c379e4a 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -252,7 +252,7 @@ if [[ "${GENERATE}" -eq 1 ]] ; then - cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" - sed -i"${backupsuffix}" \ - -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ -- /etc/default/grub -+ "${etcdefaultgrub}" - gettext_printf "Updating %s failed\n" "${GRUB_CONFIG_FILE}" - exit 1 - fi diff --git a/0317-Make-TPM-errors-less-fatal.patch b/0317-Make-TPM-errors-less-fatal.patch new file mode 100644 index 0000000..12678d3 --- /dev/null +++ b/0317-Make-TPM-errors-less-fatal.patch @@ -0,0 +1,208 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matthew Garrett +Date: Thu, 13 Oct 2016 13:55:26 -0700 +Subject: [PATCH] Make TPM errors less fatal + +Handle TPM errors, and stop trying to use the TPM once we hit one. +--- + grub-core/kern/dl.c | 1 + + grub-core/kern/i386/pc/tpm.c | 21 +++++++++++++++++---- + grub-core/lib/cmdline.c | 1 + + grub-core/loader/i386/efi/linux.c | 2 ++ + grub-core/loader/i386/linux.c | 1 + + grub-core/loader/i386/multiboot_mbi.c | 1 + + grub-core/loader/i386/pc/linux.c | 1 + + grub-core/loader/linux.c | 2 ++ + grub-core/loader/multiboot.c | 1 + + grub-core/loader/multiboot_mbi2.c | 1 + + grub-core/script/execute.c | 1 + + 11 files changed, 29 insertions(+), 4 deletions(-) + +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index d0989573866..91105bc4677 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -831,6 +831,7 @@ grub_dl_load_file (const char *filename) + grub_file_close (file); + + grub_tpm_measure(core, size, GRUB_BINARY_PCR, "grub_module", filename); ++ grub_print_error(); + + mod = grub_dl_load_core (core, size); + grub_free (core); +diff --git a/grub-core/kern/i386/pc/tpm.c b/grub-core/kern/i386/pc/tpm.c +index 8c6c1e6ece2..f6f264aff2e 100644 +--- a/grub-core/kern/i386/pc/tpm.c ++++ b/grub-core/kern/i386/pc/tpm.c +@@ -7,21 +7,28 @@ + + #define TCPA_MAGIC 0x41504354 + ++static int tpm_presence = -1; ++ + int tpm_present(void); + + int tpm_present(void) + { + struct grub_bios_int_registers regs; + ++ if (tpm_presence != -1) ++ return tpm_presence; ++ + regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT; + regs.eax = 0xbb00; + regs.ebx = TCPA_MAGIC; + grub_bios_interrupt (0x1a, ®s); + + if (regs.eax == 0) +- return 1; ++ tpm_presence = 1; ++ else ++ tpm_presence = 0; + +- return 0; ++ return tpm_presence; + } + + grub_err_t +@@ -49,7 +56,10 @@ grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, + grub_bios_interrupt (0x1a, ®s); + + if (regs.eax) +- return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); ++ { ++ tpm_presence = 0; ++ return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax); ++ } + + return 0; + } +@@ -126,7 +136,10 @@ grub_tpm_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, + grub_free(event); + + if (regs.eax) +- return grub_error (GRUB_ERR_IO, N_("TPM error %x\n"), regs.eax); ++ { ++ tpm_presence = 0; ++ return grub_error (GRUB_ERR_IO, N_("TPM error %x, disabling TPM"), regs.eax); ++ } + + return 0; + } +diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c +index 178f7382f07..d5c12957cad 100644 +--- a/grub-core/lib/cmdline.c ++++ b/grub-core/lib/cmdline.c +@@ -128,6 +128,7 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf, + + grub_tpm_measure ((void *)orig, grub_strlen (orig), GRUB_ASCII_PCR, + "grub_kernel_cmdline", orig); ++ grub_print_error(); + + return i; + } +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 8bb759d8a91..66e58b71e22 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -134,6 +134,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + goto fail; + } + grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_linuxefi", "Initrd"); ++ grub_print_error(); + ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); +@@ -199,6 +200,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + grub_tpm_measure (kernel, filelen, GRUB_BINARY_PCR, "grub_linuxefi", "Kernel"); ++ grub_print_error(); + + rc = grub_linuxefi_secure_validate (kernel, filelen); + if (rc < 0) +diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c +index e052c5ddebc..cec0a96c022 100644 +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -720,6 +720,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux", "Kernel"); ++ grub_print_error(); + + grub_memcpy (&lh, kernel, sizeof (lh)); + +diff --git a/grub-core/loader/i386/multiboot_mbi.c b/grub-core/loader/i386/multiboot_mbi.c +index 2ce424a997b..ca85358f771 100644 +--- a/grub-core/loader/i386/multiboot_mbi.c ++++ b/grub-core/loader/i386/multiboot_mbi.c +@@ -175,6 +175,7 @@ grub_multiboot_load (grub_file_t file, const char *filename) + } + + grub_tpm_measure((unsigned char*)buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); ++ grub_print_error(); + + header = find_header (buffer, len); + +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 547df29c213..1e369afcbad 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -163,6 +163,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + grub_tpm_measure (kernel, len, GRUB_BINARY_PCR, "grub_linux16", "Kernel"); ++ grub_print_error(); + + grub_memcpy (&lh, kernel, sizeof (lh)); + kernel_offset = sizeof (lh); +diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c +index 78c41e33416..c2c7cfcd0fd 100644 +--- a/grub-core/loader/linux.c ++++ b/grub-core/loader/linux.c +@@ -290,6 +290,8 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, + return grub_errno; + } + grub_tpm_measure (ptr, cursize, GRUB_BINARY_PCR, "grub_initrd", "Initrd"); ++ grub_print_error(); ++ + ptr += cursize; + } + if (newc) +diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c +index 3b87dc4fab3..9a8dae5565b 100644 +--- a/grub-core/loader/multiboot.c ++++ b/grub-core/loader/multiboot.c +@@ -442,6 +442,7 @@ grub_cmd_module (grub_command_t cmd __attribute__ ((unused)), + + grub_file_close (file); + grub_tpm_measure (module, size, GRUB_BINARY_PCR, "grub_multiboot", argv[0]); ++ grub_print_error(); + return GRUB_ERR_NONE; + } + +diff --git a/grub-core/loader/multiboot_mbi2.c b/grub-core/loader/multiboot_mbi2.c +index 60ae4606fda..54078455e2f 100644 +--- a/grub-core/loader/multiboot_mbi2.c ++++ b/grub-core/loader/multiboot_mbi2.c +@@ -133,6 +133,7 @@ grub_multiboot2_load (grub_file_t file, const char *filename) + COMPILE_TIME_ASSERT (MULTIBOOT_HEADER_ALIGN % 4 == 0); + + grub_tpm_measure ((unsigned char *)mld.buffer, len, GRUB_BINARY_PCR, "grub_multiboot", filename); ++ grub_print_error(); + + header = find_header (mld.buffer, len); + if (header == 0) +diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c +index 976643c47b0..93965777138 100644 +--- a/grub-core/script/execute.c ++++ b/grub-core/script/execute.c +@@ -997,6 +997,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) + cmdstring[cmdlen-1]= '\0'; + grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_ASCII_PCR, + "grub_cmd", cmdstring); ++ grub_print_error(); + grub_free(cmdstring); + invert = 0; + argc = argv.argc - 1; diff --git a/0318-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch b/0318-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch deleted file mode 100644 index 16ab928..0000000 --- a/0318-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 11 Apr 2018 11:36:43 +0200 -Subject: [PATCH] Add missing options to grub2-switch-to-blscfg man page - -The script --bls-directory and --backup-suffix options were not documented -in the man page, add them as well so users can know what these are about. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.8 | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 -index 134dfc62a7b..7d99de2d2f9 100644 ---- a/util/grub-switch-to-blscfg.8 -+++ b/util/grub-switch-to-blscfg.8 -@@ -21,5 +21,13 @@ The grub config file to use. The default value is \fI/etc/grub2-efi.cfg\fR on U - --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 on BIOS machines and \fI/boot/efi/EFI/\fBVENDOR\fI/loader/entries\fR on UEFI machines. -+ -+.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/0318-blscfg-handle-multiple-initramfs-images.patch b/0318-blscfg-handle-multiple-initramfs-images.patch new file mode 100644 index 0000000..0e3d873 --- /dev/null +++ b/0318-blscfg-handle-multiple-initramfs-images.patch @@ -0,0 +1,104 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Apr 2018 13:44:29 -0400 +Subject: [PATCH] blscfg: handle multiple initramfs images. + +Signed-off-by: Peter Jones +--- + grub-core/commands/blscfg.c | 54 ++++++++++++++++++++++++++++++++++++--------- + 1 file changed, 44 insertions(+), 10 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index c0973ff83ea..1e5972422d6 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -587,6 +587,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + char *title = NULL; + char *clinux = NULL; + char *options = NULL; ++ char **initrds = NULL; + char *initrd = NULL; + char *id = NULL; + char *hotkey = NULL; +@@ -609,7 +610,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + + title = bls_get_val (entry, "title", NULL); + options = bls_get_val (entry, "options", NULL); +- initrd = bls_get_val (entry, "initrd", NULL); ++ initrds = bls_make_list (entry, "initrd", NULL); + id = bls_get_val (entry, "id", NULL); + + hotkey = bls_get_val (entry, "grub_hotkey", NULL); +@@ -624,30 +625,63 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + argv[i] = args[i-1]; + argv[argc] = NULL; + +- grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title); ++ grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title); ++ if (initrds) ++ { ++ int initrd_size = sizeof (GRUB_INITRD_CMD); ++ char *tmp; ++ ++ 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, GRUB_INITRD_CMD); ++ 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 gfx_payload=keep\n" + "insmod gzio\n" + GRUB_LINUX_CMD " %s%s%s%s\n" +- "%s%s%s%s", ++ "%s", + GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "", +- initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : ""); ++ initrd ? initrd : ""); + + grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); + + finish: ++ if (initrd) ++ grub_free (initrd); ++ ++ if (initrds) ++ grub_free (initrds); ++ + if (classes) +- grub_free (classes); +- grub_dprintf("blscfg", "%s got here\n", __func__); ++ grub_free (classes); ++ + if (args) +- grub_free (args); ++ grub_free (args); + + if (argv) +- grub_free (argv); ++ grub_free (argv); + + if (src) +- grub_free (src); +- grub_dprintf("blscfg", "%s got here\n", __func__); ++ grub_free (src); + } + + struct find_entry_info { diff --git a/0319-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch b/0319-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch new file mode 100644 index 0000000..a045646 --- /dev/null +++ b/0319-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jan Hlavac +Date: Tue, 10 Apr 2018 16:07:36 +0200 +Subject: [PATCH] BLS: Fix grub2-switch-to-blscfg on non-EFI machines + +On the non-EFI machines the grub2-switch-to-blscfg script places the BLS +snippets into the /boot directory. But the right location is +/boot/loader/entries. +--- + util/grub-switch-to-blscfg.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 3ae5e4ea8d0..f740b8f4d03 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -44,7 +44,7 @@ if [ -d /sys/firmware/efi/efivars/ ]; then + else + startlink=/etc/grub2.cfg + grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` +- blsdir=`echo "/@bootdirname@" | sed 's,//*,/,g'` ++ blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` + fi + + backupsuffix=.bak diff --git a/0319-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch b/0319-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch deleted file mode 100644 index 5e47f2d..0000000 --- a/0319-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 11 Apr 2018 11:49:24 +0200 -Subject: [PATCH] Make grub2-switch-to-blscfg to generate debug BLS when - MAKEDEBUG is set - -If MAKEDEBUG=yes in /etc/sysconfig/kernel, then a debug menu entry should -be created. So for BLS, a debug configuration file has to be created that -contains additional debug kernel command line parameters. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 15 +++++++++++++++ - 1 file changed, 15 insertions(+) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index eae3c379e4a..c59299ffa6a 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -21,6 +21,7 @@ - # Initialize some variables. - prefix=@prefix@ - exec_prefix=@exec_prefix@ -+sbindir=@sbindir@ - bindir=@bindir@ - sysconfdir="@sysconfdir@" - PACKAGE_NAME=@PACKAGE_NAME@ -@@ -33,9 +34,12 @@ 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/') - if [ -d /sys/firmware/efi/efivars/ ]; then - startlink=/etc/grub2-efi.cfg -@@ -226,6 +230,17 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ - >"${bls_target}" - fi -+ -+ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -+ arch="$(uname -m)" -+ bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")" -+ 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 - - GENERATE=0 diff --git a/0320-BLS-Use-etcdefaultgrub-instead-of-etc.patch b/0320-BLS-Use-etcdefaultgrub-instead-of-etc.patch new file mode 100644 index 0000000..db97410 --- /dev/null +++ b/0320-BLS-Use-etcdefaultgrub-instead-of-etc.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jan Hlavac +Date: Tue, 10 Apr 2018 16:56:28 +0200 +Subject: [PATCH] BLS: Use ${etcdefaultgrub} instead of /etc/... + +Inside the grub-switch-to-blscfg script the ${etcdefaultgrub} variable +is used. So replace the hardcoded /etc/default/grub with it. +--- + util/grub-switch-to-blscfg.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index f740b8f4d03..eae3c379e4a 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -252,7 +252,7 @@ if [[ "${GENERATE}" -eq 1 ]] ; then + cp -af "${GRUB_CONFIG_FILE}${backupsuffix}" "${GRUB_CONFIG_FILE}" + sed -i"${backupsuffix}" \ + -e 's,^GRUB_ENABLE_BLSCFG=.*,GRUB_ENABLE_BLSCFG=false,' \ +- /etc/default/grub ++ "${etcdefaultgrub}" + gettext_printf "Updating %s failed\n" "${GRUB_CONFIG_FILE}" + exit 1 + fi diff --git a/0320-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch b/0320-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch deleted file mode 100644 index eb1726b..0000000 --- a/0320-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Wed, 11 Apr 2018 12:39:59 +0200 -Subject: [PATCH] Make grub2-switch-to-blscfg to generate BLS fragment for - rescue kernel - -If a rescue image is available, it should have a BootLoaderSpec fragment. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index c59299ffa6a..bc28053cd30 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -243,6 +243,10 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - fi - done - -+if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then -+ mkbls "0-rescue-${MACHINE_ID}" "0" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" -+fi -+ - GENERATE=0 - if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ - | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then diff --git a/0321-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch b/0321-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch new file mode 100644 index 0000000..16ab928 --- /dev/null +++ b/0321-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 11 Apr 2018 11:36:43 +0200 +Subject: [PATCH] Add missing options to grub2-switch-to-blscfg man page + +The script --bls-directory and --backup-suffix options were not documented +in the man page, add them as well so users can know what these are about. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.8 | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/util/grub-switch-to-blscfg.8 b/util/grub-switch-to-blscfg.8 +index 134dfc62a7b..7d99de2d2f9 100644 +--- a/util/grub-switch-to-blscfg.8 ++++ b/util/grub-switch-to-blscfg.8 +@@ -21,5 +21,13 @@ The grub config file to use. The default value is \fI/etc/grub2-efi.cfg\fR on U + --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 on BIOS machines and \fI/boot/efi/EFI/\fBVENDOR\fI/loader/entries\fR on UEFI machines. ++ ++.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/0321-Only-attempt-to-query-dev-mounted-in-boot-efi-as-boo.patch b/0321-Only-attempt-to-query-dev-mounted-in-boot-efi-as-boo.patch deleted file mode 100644 index 8be87f3..0000000 --- a/0321-Only-attempt-to-query-dev-mounted-in-boot-efi-as-boo.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 24 Apr 2018 02:16:38 +0200 -Subject: [PATCH] Only attempt to query dev mounted in /boot/efi as boot dev on - EFI machines - -The 10_linux script calls grub2-probe to probe the information for the dev -mounted in /boot/efi, but this directory may not exist on non-EFI machines -which leads to the following error when generating the grub2 config file: - -/usr/sbin/grub2-probe: error: failed to get canonical path of `/boot/efi/' - -Instead query for the device mounted in /boot and use that as the boot dev -for non-EFI machines. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 1e7ec7071c3..13a6115056b 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -147,8 +147,13 @@ linux_entry () - fi - fi - -- bootefi_device="`${grub_probe} --target=device /boot/efi/`" -- prepare_grub_to_access_device ${bootefi_device} boot -+ if [ -d /sys/firmware/efi ]; then -+ bootefi_device="`${grub_probe} --target=device /boot/efi/`" -+ prepare_grub_to_access_device ${bootefi_device} boot -+ else -+ boot_device="`${grub_probe} --target=device /boot/`" -+ prepare_grub_to_access_device ${boot_device} boot -+ fi - - cat << EOF - insmod blscfg diff --git a/0322-Include-OSTree-path-when-searching-kernels-images-if.patch b/0322-Include-OSTree-path-when-searching-kernels-images-if.patch deleted file mode 100644 index 2e36989..0000000 --- a/0322-Include-OSTree-path-when-searching-kernels-images-if.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 24 Apr 2018 02:28:04 +0200 -Subject: [PATCH] Include OSTree path when searching kernels images if BLS - config is enabled - -The OSTree based distros (i.e: Fedora Atomic) don't install kernel images -in the /boot directory, but in /boot/ostree. So the 10_linux script isn't -able to include these kernels in its list, so the linux_entry() function -is never called. - -This isn't a problem since the 10_linux script isn't used to populate the -menu entries anyways, but instead a custom 15_ostree script is used. But -for BLS we want the 10_linux script to generate the minimal grub.cfg that -calls the blscfg command, so add the OSTree kernel images to the list. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub.d/10_linux.in | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index 13a6115056b..bcb81943aa2 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -253,6 +253,12 @@ case "x$machine" in - 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" ;; diff --git a/0322-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch b/0322-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch new file mode 100644 index 0000000..5e47f2d --- /dev/null +++ b/0322-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 11 Apr 2018 11:49:24 +0200 +Subject: [PATCH] Make grub2-switch-to-blscfg to generate debug BLS when + MAKEDEBUG is set + +If MAKEDEBUG=yes in /etc/sysconfig/kernel, then a debug menu entry should +be created. So for BLS, a debug configuration file has to be created that +contains additional debug kernel command line parameters. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index eae3c379e4a..c59299ffa6a 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -21,6 +21,7 @@ + # Initialize some variables. + prefix=@prefix@ + exec_prefix=@exec_prefix@ ++sbindir=@sbindir@ + bindir=@bindir@ + sysconfdir="@sysconfdir@" + PACKAGE_NAME=@PACKAGE_NAME@ +@@ -33,9 +34,12 @@ 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/') + if [ -d /sys/firmware/efi/efivars/ ]; then + startlink=/etc/grub2-efi.cfg +@@ -226,6 +230,17 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ + >"${bls_target}" + fi ++ ++ if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then ++ arch="$(uname -m)" ++ bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")" ++ 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 + + GENERATE=0 diff --git a/0323-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch b/0323-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch new file mode 100644 index 0000000..eb1726b --- /dev/null +++ b/0323-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Wed, 11 Apr 2018 12:39:59 +0200 +Subject: [PATCH] Make grub2-switch-to-blscfg to generate BLS fragment for + rescue kernel + +If a rescue image is available, it should have a BootLoaderSpec fragment. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index c59299ffa6a..bc28053cd30 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -243,6 +243,10 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + fi + done + ++if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then ++ mkbls "0-rescue-${MACHINE_ID}" "0" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" ++fi ++ + GENERATE=0 + if grep '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" \ + | grep -vq '^GRUB_ENABLE_BLSCFG="*true"*\s*$' ; then diff --git a/0323-Use-BLS-version-field-to-compare-entries-if-id-field.patch b/0323-Use-BLS-version-field-to-compare-entries-if-id-field.patch deleted file mode 100644 index 84ed52e..0000000 --- a/0323-Use-BLS-version-field-to-compare-entries-if-id-field.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Fri, 27 Apr 2018 17:53:41 +0200 -Subject: [PATCH] Use BLS version field to compare entries if id field isn't - defined - -The BootLoaderSpec fragments generated by OSTree don't have the id field, -so grub2 will attempt to sort the entries by using the title field which -may not be correct. The entries do have a version field though so use it. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 1e5972422d6..72ee497ea2d 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -418,6 +418,9 @@ static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) - - rc = bls_keyval_cmp (e0, e1, "id"); - -+ if (rc == 0) -+ rc = bls_keyval_cmp (e0, e1, "version"); -+ - if (rc == 0) - rc = bls_keyval_cmp (e0, e1, "title"); - diff --git a/0324-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch b/0324-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch deleted file mode 100644 index 27e0a17..0000000 --- a/0324-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 10 May 2018 10:52:11 +0200 -Subject: [PATCH] Add version field to BLS generated by grub2-switch-to-blscfg - -The version field is present in the BLS fragments that are shipped in the -kernel packages, so add it to the BLS generated by grub2-switch-to-blscfg -for consistency. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index bc28053cd30..89487ad611c 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -190,12 +190,14 @@ mkbls() { - local datetime=$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 - ( -@@ -203,6 +205,7 @@ mkbls() { - - cat < +Date: Tue, 24 Apr 2018 02:16:38 +0200 +Subject: [PATCH] Only attempt to query dev mounted in /boot/efi as boot dev on + EFI machines + +The 10_linux script calls grub2-probe to probe the information for the dev +mounted in /boot/efi, but this directory may not exist on non-EFI machines +which leads to the following error when generating the grub2 config file: + +/usr/sbin/grub2-probe: error: failed to get canonical path of `/boot/efi/' + +Instead query for the device mounted in /boot and use that as the boot dev +for non-EFI machines. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 1e7ec7071c3..13a6115056b 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -147,8 +147,13 @@ linux_entry () + fi + fi + +- bootefi_device="`${grub_probe} --target=device /boot/efi/`" +- prepare_grub_to_access_device ${bootefi_device} boot ++ if [ -d /sys/firmware/efi ]; then ++ bootefi_device="`${grub_probe} --target=device /boot/efi/`" ++ prepare_grub_to_access_device ${bootefi_device} boot ++ else ++ boot_device="`${grub_probe} --target=device /boot/`" ++ prepare_grub_to_access_device ${boot_device} boot ++ fi + + cat << EOF + insmod blscfg diff --git a/0325-Fixup-for-newer-compiler.patch b/0325-Fixup-for-newer-compiler.patch deleted file mode 100644 index a63ca6b..0000000 --- a/0325-Fixup-for-newer-compiler.patch +++ /dev/null @@ -1,36 +0,0 @@ -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 7002ad81b7e..dac73b2fa8b 100644 ---- a/grub-core/fs/btrfs.c -+++ b/grub-core/fs/btrfs.c -@@ -198,7 +198,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/0325-Include-OSTree-path-when-searching-kernels-images-if.patch b/0325-Include-OSTree-path-when-searching-kernels-images-if.patch new file mode 100644 index 0000000..2e36989 --- /dev/null +++ b/0325-Include-OSTree-path-when-searching-kernels-images-if.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 24 Apr 2018 02:28:04 +0200 +Subject: [PATCH] Include OSTree path when searching kernels images if BLS + config is enabled + +The OSTree based distros (i.e: Fedora Atomic) don't install kernel images +in the /boot directory, but in /boot/ostree. So the 10_linux script isn't +able to include these kernels in its list, so the linux_entry() function +is never called. + +This isn't a problem since the 10_linux script isn't used to populate the +menu entries anyways, but instead a custom 15_ostree script is used. But +for BLS we want the 10_linux script to generate the minimal grub.cfg that +calls the blscfg command, so add the OSTree kernel images to the list. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub.d/10_linux.in | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 13a6115056b..bcb81943aa2 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -253,6 +253,12 @@ case "x$machine" in + 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" ;; diff --git a/0326-Don-t-attempt-to-export-the-start-and-_start-symbols.patch b/0326-Don-t-attempt-to-export-the-start-and-_start-symbols.patch deleted file mode 100644 index 33ceb3d..0000000 --- a/0326-Don-t-attempt-to-export-the-start-and-_start-symbols.patch +++ /dev/null @@ -1,42 +0,0 @@ -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 ae69218af20..9548d552aad 100644 ---- a/include/grub/kernel.h -+++ b/include/grub/kernel.h -@@ -108,8 +108,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/0326-Use-BLS-version-field-to-compare-entries-if-id-field.patch b/0326-Use-BLS-version-field-to-compare-entries-if-id-field.patch new file mode 100644 index 0000000..84ed52e --- /dev/null +++ b/0326-Use-BLS-version-field-to-compare-entries-if-id-field.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 27 Apr 2018 17:53:41 +0200 +Subject: [PATCH] Use BLS version field to compare entries if id field isn't + defined + +The BootLoaderSpec fragments generated by OSTree don't have the id field, +so grub2 will attempt to sort the entries by using the title field which +may not be correct. The entries do have a version field though so use it. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 1e5972422d6..72ee497ea2d 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -418,6 +418,9 @@ static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) + + rc = bls_keyval_cmp (e0, e1, "id"); + ++ if (rc == 0) ++ rc = bls_keyval_cmp (e0, e1, "version"); ++ + if (rc == 0) + rc = bls_keyval_cmp (e0, e1, "title"); + diff --git a/0327-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch b/0327-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch new file mode 100644 index 0000000..27e0a17 --- /dev/null +++ b/0327-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 10 May 2018 10:52:11 +0200 +Subject: [PATCH] Add version field to BLS generated by grub2-switch-to-blscfg + +The version field is present in the BLS fragments that are shipped in the +kernel packages, so add it to the BLS generated by grub2-switch-to-blscfg +for consistency. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index bc28053cd30..89487ad611c 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -190,12 +190,14 @@ mkbls() { + local datetime=$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 + ( +@@ -203,6 +205,7 @@ mkbls() { + + cat < -Date: Fri, 11 May 2018 23:47:31 +0200 -Subject: [PATCH] Simplify BLS entry key val pairs lookup - -The pairs found in the BLS are being sorted but this isn't -really needed and it makes the implementation complex and error prone. - -For example, the current implementation has the following issues: - -1) Fields not present in the grub2 menu entry - - linux /linuz - initrd /foo - initrd /bar - - load_video - set gfx_payload=keep - insmod gzio - linux /boot/linuz - initrd /boot/bar - -2) Fields present but in the wrong order - - title Fedora (4.16.6-300.fc28.x86_64-tuned) 28 (Twenty Eight) - version 4.16.6-300.fc28.x86_64 - linux /vmlinuz-4.16.6-300.fc28.x86_64 - initrd /foo.img - initrd /bar.img - options $kernelopts - id fedora-20180430150025-4.16.6-300.fc28.x86_64 - - load_video - set gfx_payload=keep - insmod gzio - linux /boot/vmlinuz-4.16.6-300.fc28.x86_64 $kernelopts - initrd /boot/bar.img /boot/foo.img - -It's important to preserve the order in which fields have been defined -in the BLS fragment since for some of the fields the order has meaning. -For example, initramfs images have to be passed to the kernel in order -that were defined in the BLS fragment. - -This patch simplifies the pairs storage and lookup. Rather -than sorting and attempt to later figure out what's the expected order, -just store it in the same order as they were defined in the BLS config -file and return in that same order to callers when these look them up. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 88 ++++++++++----------------------------------- - 1 file changed, 18 insertions(+), 70 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 72ee497ea2d..111972d5f67 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -169,84 +169,35 @@ static void bls_free_entry(struct bls_entry *entry) - grub_free (entry); - } - --static int keyval_cmp (const void *p0, const void *p1, -- void *state UNUSED) --{ -- const struct keyval *kv0 = *(struct keyval * const *)p0; -- const struct keyval *kv1 = *(struct keyval * const *)p1; -- int rc; -- -- rc = grub_strcmp(kv0->key, kv1->key); -- -- return rc; --} -- - /* 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. */ -+ * order as defined in the BLS fragment file */ - static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last) - { -- char *foo = (char *)""; -- struct keyval *kv = NULL, **kvp, key = {keyname, foo}, *keyp = &key; -+ int idx, start = 0; -+ struct keyval *kv = NULL; - -- /* if we've already found an entry that matches, just iterate */ -- if (last && *last >= 0) -- { -- int next = ++last[0]; -+ if (last) -+ start = *last + 1; - -- if (next == entry->nkeyvals) -- { --done: -- *last = -1; -- return NULL; -- } -+ for (idx = start; idx < entry->nkeyvals; idx++) { -+ kv = entry->keyvals[idx]; - -- kv = entry->keyvals[next]; -- if (grub_strcmp (keyname, kv->key)) -- goto done; -+ if (!grub_strcmp (keyname, kv->key)) -+ break; -+ } - -- return kv->val; -- } -+ if (idx == entry->nkeyvals) { -+ if (last) -+ *last = -1; -+ return NULL; -+ } - -- kvp = grub_bsearch(&keyp, &entry->keyvals[0], entry->nkeyvals, -- sizeof (struct keyval *), keyval_cmp, NULL); -- if (kvp) -- kv = *kvp; -+ if (last) -+ *last = idx; - -- if (kv) -- { -- /* if we've got uninitialized but present state, track back until we find -- * the first match */ -- if (last) -- { -- grub_dprintf("blscfg", "%s trying to find another entry because last was set\n", __func__); -- /* figure out the position of this entry in the array */ -- int idx; -- for (idx = 0 ; idx < entry->nkeyvals; idx++) -- if (entry->keyvals[idx] == kv) -- break; -- *last = idx; -- -- while (idx > 0) -- { -- struct keyval *kvtmp = entry->keyvals[idx-1]; -- if (idx == 0 || grub_strcmp (keyname, kvtmp->key)) -- { -- /* if we're at the start, or if the previous entry doesn't -- * match, then we're done */ -- *last = idx; -- break; -- } -- else -- /* but if it does match, keep going backwards */ -- idx--; -- } -- } -- -- return kv->val; -- } -- return NULL; -+ return kv->val; - } - - #define goto_return(x) ({ ret = (x); goto finish; }) -@@ -503,9 +454,6 @@ static int read_entry ( - break; - } - -- grub_qsort(&entry->keyvals[0], entry->nkeyvals, sizeof (struct keyval *), -- keyval_cmp, NULL); -- - finish: - grub_free (p); - diff --git a/0328-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch b/0328-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch deleted file mode 100644 index 5a5a77d..0000000 --- a/0328-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 4 Jun 2018 16:10:22 +0200 -Subject: [PATCH] Add relative path to the kernel and initrds BLS fields if - needed - -The static BLS config file shipped with the kernel package assumes that -the /boot directory is a mount point, and that the kernel and initramfs -images relative path is to the root of a boot partition. - -But there are cases in which this isn't true, for example if a user has -its /boot in a btrfs subvolume or if /boot isn't a mount point at all. - -So instead of always using the BLS fragment file as distributed by the -package, check the relative path that GRUB 2 has to use for the images. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 20 +++++++++++++++++--- - 1 file changed, 17 insertions(+), 3 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 89487ad611c..2482483a437 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -188,6 +188,7 @@ fi - mkbls() { - local kernelver=$1 && shift - local datetime=$1 && shift -+ local bootprefix=$1 && shift - - local debugname="" - local debugid="" -@@ -206,8 +207,8 @@ mkbls() { - cat <"${bls_target}" - fi - -+ linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')" -+ initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')" -+ linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" -+ initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" -+ -+ if [[ $linux != $linux_relpath ]]; then -+ sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" -+ sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" -+ fi -+ - if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then - arch="$(uname -m)" - bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")" -@@ -247,7 +258,10 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - done - - if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then -- mkbls "0-rescue-${MACHINE_ID}" "0" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" -+ if [[ $linux != $linux_relpath ]]; then -+ bootprefix="$(dirname ${linux_relpath})" -+ fi -+ mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" - fi - - GENERATE=0 diff --git a/0328-Fixup-for-newer-compiler.patch b/0328-Fixup-for-newer-compiler.patch new file mode 100644 index 0000000..a63ca6b --- /dev/null +++ b/0328-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 7002ad81b7e..dac73b2fa8b 100644 +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -198,7 +198,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/0329-Don-t-attempt-to-export-the-start-and-_start-symbols.patch b/0329-Don-t-attempt-to-export-the-start-and-_start-symbols.patch new file mode 100644 index 0000000..33ceb3d --- /dev/null +++ b/0329-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 ae69218af20..9548d552aad 100644 +--- a/include/grub/kernel.h ++++ b/include/grub/kernel.h +@@ -108,8 +108,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/0329-Skip-leading-spaces-on-BLS-field-values.patch b/0329-Skip-leading-spaces-on-BLS-field-values.patch deleted file mode 100644 index 8b4cff8..0000000 --- a/0329-Skip-leading-spaces-on-BLS-field-values.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Thu, 7 Jun 2018 00:44:51 +0200 -Subject: [PATCH] Skip leading spaces on BLS field values - -The GRUB 2 blscfg command doesn't parse correctly the BLS fields if these -have extra spaces before the field values. For example, the following BLS -fragment generates a wrong menu entry due using spaces to tabulate values: - -title Fedora 28 (Twenty Eight) -version 4.16.13-300.fc28.x86_64 -machine-id e5c131dfee3249cbb9891c2641d8e350 -linux /vmlinuz-4.16.13-300.fc28.x86_64 -initrd /initramfs-4.16.13-300.fc28.x86_64.img -options root=/dev/mapper/fedora-root ro - -Wrong generated menu entry: - -load_video -set gfx_payload=keep -insmod gzio -linux ($root) /vmlinuz-4.16.13-300.fc28.x86_64 root=/dev/mapper/fedora-root ro -initrd ($root) /initramfs-4.16.13-300.fc28.x86_64.img - -Correct menu entry after the fix: - -load_video -set gfx_payload=keep -insmod gzio -linux ($root)/vmlinuz-4.16.13-300.fc28.x86_64 root=/dev/mapper/fedora-root ro -initrd ($root)/initramfs-4.16.13-300.fc28.x86_64.img - -Resolves: rhbz#1588184 - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 111972d5f67..cd5c29fdf74 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -448,7 +448,11 @@ static int read_entry ( - - separator[0] = '\0'; - -- rc = bls_add_keyval (entry, buf, separator+1); -+ do { -+ separator++; -+ } while (*separator == ' ' || *separator == '\t'); -+ -+ rc = bls_add_keyval (entry, buf, separator); - grub_free (buf); - if (rc < 0) - break; diff --git a/0330-Fixup-for-newer-compiler.patch b/0330-Fixup-for-newer-compiler.patch deleted file mode 100644 index e518af8..0000000 --- a/0330-Fixup-for-newer-compiler.patch +++ /dev/null @@ -1,22 +0,0 @@ -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 044ab3abe88..c75848f5c06 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/0330-Simplify-BLS-entry-key-val-pairs-lookup.patch b/0330-Simplify-BLS-entry-key-val-pairs-lookup.patch new file mode 100644 index 0000000..261cd9a --- /dev/null +++ b/0330-Simplify-BLS-entry-key-val-pairs-lookup.patch @@ -0,0 +1,170 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Fri, 11 May 2018 23:47:31 +0200 +Subject: [PATCH] Simplify BLS entry key val pairs lookup + +The pairs found in the BLS are being sorted but this isn't +really needed and it makes the implementation complex and error prone. + +For example, the current implementation has the following issues: + +1) Fields not present in the grub2 menu entry + + linux /linuz + initrd /foo + initrd /bar + + load_video + set gfx_payload=keep + insmod gzio + linux /boot/linuz + initrd /boot/bar + +2) Fields present but in the wrong order + + title Fedora (4.16.6-300.fc28.x86_64-tuned) 28 (Twenty Eight) + version 4.16.6-300.fc28.x86_64 + linux /vmlinuz-4.16.6-300.fc28.x86_64 + initrd /foo.img + initrd /bar.img + options $kernelopts + id fedora-20180430150025-4.16.6-300.fc28.x86_64 + + load_video + set gfx_payload=keep + insmod gzio + linux /boot/vmlinuz-4.16.6-300.fc28.x86_64 $kernelopts + initrd /boot/bar.img /boot/foo.img + +It's important to preserve the order in which fields have been defined +in the BLS fragment since for some of the fields the order has meaning. +For example, initramfs images have to be passed to the kernel in order +that were defined in the BLS fragment. + +This patch simplifies the pairs storage and lookup. Rather +than sorting and attempt to later figure out what's the expected order, +just store it in the same order as they were defined in the BLS config +file and return in that same order to callers when these look them up. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 88 ++++++++++----------------------------------- + 1 file changed, 18 insertions(+), 70 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 72ee497ea2d..111972d5f67 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -169,84 +169,35 @@ static void bls_free_entry(struct bls_entry *entry) + grub_free (entry); + } + +-static int keyval_cmp (const void *p0, const void *p1, +- void *state UNUSED) +-{ +- const struct keyval *kv0 = *(struct keyval * const *)p0; +- const struct keyval *kv1 = *(struct keyval * const *)p1; +- int rc; +- +- rc = grub_strcmp(kv0->key, kv1->key); +- +- return rc; +-} +- + /* 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. */ ++ * order as defined in the BLS fragment file */ + static char *bls_get_val(struct bls_entry *entry, const char *keyname, int *last) + { +- char *foo = (char *)""; +- struct keyval *kv = NULL, **kvp, key = {keyname, foo}, *keyp = &key; ++ int idx, start = 0; ++ struct keyval *kv = NULL; + +- /* if we've already found an entry that matches, just iterate */ +- if (last && *last >= 0) +- { +- int next = ++last[0]; ++ if (last) ++ start = *last + 1; + +- if (next == entry->nkeyvals) +- { +-done: +- *last = -1; +- return NULL; +- } ++ for (idx = start; idx < entry->nkeyvals; idx++) { ++ kv = entry->keyvals[idx]; + +- kv = entry->keyvals[next]; +- if (grub_strcmp (keyname, kv->key)) +- goto done; ++ if (!grub_strcmp (keyname, kv->key)) ++ break; ++ } + +- return kv->val; +- } ++ if (idx == entry->nkeyvals) { ++ if (last) ++ *last = -1; ++ return NULL; ++ } + +- kvp = grub_bsearch(&keyp, &entry->keyvals[0], entry->nkeyvals, +- sizeof (struct keyval *), keyval_cmp, NULL); +- if (kvp) +- kv = *kvp; ++ if (last) ++ *last = idx; + +- if (kv) +- { +- /* if we've got uninitialized but present state, track back until we find +- * the first match */ +- if (last) +- { +- grub_dprintf("blscfg", "%s trying to find another entry because last was set\n", __func__); +- /* figure out the position of this entry in the array */ +- int idx; +- for (idx = 0 ; idx < entry->nkeyvals; idx++) +- if (entry->keyvals[idx] == kv) +- break; +- *last = idx; +- +- while (idx > 0) +- { +- struct keyval *kvtmp = entry->keyvals[idx-1]; +- if (idx == 0 || grub_strcmp (keyname, kvtmp->key)) +- { +- /* if we're at the start, or if the previous entry doesn't +- * match, then we're done */ +- *last = idx; +- break; +- } +- else +- /* but if it does match, keep going backwards */ +- idx--; +- } +- } +- +- return kv->val; +- } +- return NULL; ++ return kv->val; + } + + #define goto_return(x) ({ ret = (x); goto finish; }) +@@ -503,9 +454,6 @@ static int read_entry ( + break; + } + +- grub_qsort(&entry->keyvals[0], entry->nkeyvals, sizeof (struct keyval *), +- keyval_cmp, NULL); +- + finish: + grub_free (p); + diff --git a/0331-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch b/0331-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch new file mode 100644 index 0000000..5a5a77d --- /dev/null +++ b/0331-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 4 Jun 2018 16:10:22 +0200 +Subject: [PATCH] Add relative path to the kernel and initrds BLS fields if + needed + +The static BLS config file shipped with the kernel package assumes that +the /boot directory is a mount point, and that the kernel and initramfs +images relative path is to the root of a boot partition. + +But there are cases in which this isn't true, for example if a user has +its /boot in a btrfs subvolume or if /boot isn't a mount point at all. + +So instead of always using the BLS fragment file as distributed by the +package, check the relative path that GRUB 2 has to use for the images. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 20 +++++++++++++++++--- + 1 file changed, 17 insertions(+), 3 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 89487ad611c..2482483a437 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -188,6 +188,7 @@ fi + mkbls() { + local kernelver=$1 && shift + local datetime=$1 && shift ++ local bootprefix=$1 && shift + + local debugname="" + local debugid="" +@@ -206,8 +207,8 @@ mkbls() { + cat <"${bls_target}" + fi + ++ linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')" ++ initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')" ++ linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" ++ initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" ++ ++ if [[ $linux != $linux_relpath ]]; then ++ sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" ++ sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" ++ fi ++ + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then + arch="$(uname -m)" + bls_debug="$(echo ${bls_target} | sed -e "s/\.${arch}/-debug.${arch}/")" +@@ -247,7 +258,10 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + done + + if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then +- mkbls "0-rescue-${MACHINE_ID}" "0" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" ++ if [[ $linux != $linux_relpath ]]; then ++ bootprefix="$(dirname ${linux_relpath})" ++ fi ++ mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" + fi + + GENERATE=0 diff --git a/0331-TPM-Fix-hash_log_extend_event-function-prototype.patch b/0331-TPM-Fix-hash_log_extend_event-function-prototype.patch deleted file mode 100644 index 56cd169..0000000 --- a/0331-TPM-Fix-hash_log_extend_event-function-prototype.patch +++ /dev/null @@ -1,50 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Fri, 15 Jun 2018 09:25:00 +0200 -Subject: [PATCH] TPM: Fix hash_log_extend_event function prototype - -The DataToHash argument is a efi_physical_address, not a *pointer* to -a efi_physical_address. - -This distinction is important for 32 bits builds, where the pointer is -only 32 bits where as an efi_physical_address is 64 bits. - -Fixing this fixes the tpm code not working with 32 bits build and grub -showing multiple: - -error: Invalid parameter - -Messages during boot, followed by a "press any key to continue" message. - -Signed-off-by: Hans de Goede ---- - grub-core/kern/efi/tpm.c | 2 +- - include/grub/efi/tpm.h | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c -index c9fb3c133f3..36e1f69df16 100644 ---- a/grub-core/kern/efi/tpm.c -+++ b/grub-core/kern/efi/tpm.c -@@ -245,7 +245,7 @@ grub_tpm2_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, - event->Size = sizeof(*event) - sizeof(event->Event) + grub_strlen(description) + 1; - grub_memcpy(event->Event, description, grub_strlen(description) + 1); - -- status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf, -+ status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (unsigned long) buf, - (grub_uint64_t) size, event); - - switch (status) { -diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h -index e2aff4a3c22..63d8a0fe714 100644 ---- a/include/grub/efi/tpm.h -+++ b/include/grub/efi/tpm.h -@@ -129,7 +129,7 @@ struct grub_efi_tpm2_protocol - grub_efi_boolean_t *EventLogTruncated); - grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *this, - grub_efi_uint64_t Flags, -- grub_efi_physical_address_t *DataToHash, -+ grub_efi_physical_address_t DataToHash, - grub_efi_uint64_t DataToHashLen, - EFI_TCG2_EVENT *EfiTcgEvent); - grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this, diff --git a/0332-Skip-leading-spaces-on-BLS-field-values.patch b/0332-Skip-leading-spaces-on-BLS-field-values.patch new file mode 100644 index 0000000..8b4cff8 --- /dev/null +++ b/0332-Skip-leading-spaces-on-BLS-field-values.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Thu, 7 Jun 2018 00:44:51 +0200 +Subject: [PATCH] Skip leading spaces on BLS field values + +The GRUB 2 blscfg command doesn't parse correctly the BLS fields if these +have extra spaces before the field values. For example, the following BLS +fragment generates a wrong menu entry due using spaces to tabulate values: + +title Fedora 28 (Twenty Eight) +version 4.16.13-300.fc28.x86_64 +machine-id e5c131dfee3249cbb9891c2641d8e350 +linux /vmlinuz-4.16.13-300.fc28.x86_64 +initrd /initramfs-4.16.13-300.fc28.x86_64.img +options root=/dev/mapper/fedora-root ro + +Wrong generated menu entry: + +load_video +set gfx_payload=keep +insmod gzio +linux ($root) /vmlinuz-4.16.13-300.fc28.x86_64 root=/dev/mapper/fedora-root ro +initrd ($root) /initramfs-4.16.13-300.fc28.x86_64.img + +Correct menu entry after the fix: + +load_video +set gfx_payload=keep +insmod gzio +linux ($root)/vmlinuz-4.16.13-300.fc28.x86_64 root=/dev/mapper/fedora-root ro +initrd ($root)/initramfs-4.16.13-300.fc28.x86_64.img + +Resolves: rhbz#1588184 + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 111972d5f67..cd5c29fdf74 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -448,7 +448,11 @@ static int read_entry ( + + separator[0] = '\0'; + +- rc = bls_add_keyval (entry, buf, separator+1); ++ do { ++ separator++; ++ } while (*separator == ' ' || *separator == '\t'); ++ ++ rc = bls_add_keyval (entry, buf, separator); + grub_free (buf); + if (rc < 0) + break; diff --git a/0332-TPM-Fix-compiler-warnings.patch b/0332-TPM-Fix-compiler-warnings.patch deleted file mode 100644 index b19d484..0000000 --- a/0332-TPM-Fix-compiler-warnings.patch +++ /dev/null @@ -1,72 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Fri, 15 Jun 2018 09:58:50 +0200 -Subject: [PATCH] TPM: Fix compiler warnings - -Stop defining our own Event type in tpm.c instead use the one from -the header, so that it matches the function prototype. -Note this requires some further code changes to go from all lowercaps -of the private Event type to the CamelCaps from the header. - -Also cast buf, which gets passed as a efi_physicall_address_t to an -integer, to avoid the compiler complaining about passing a pointer as -an integer. - -Signed-off-by: Hans de Goede ---- - grub-core/kern/efi/tpm.c | 24 ++++++++---------------- - 1 file changed, 8 insertions(+), 16 deletions(-) - -diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c -index 36e1f69df16..0d3ebe22e57 100644 ---- a/grub-core/kern/efi/tpm.c -+++ b/grub-core/kern/efi/tpm.c -@@ -161,21 +161,12 @@ grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, - } - } - --typedef struct { -- grub_uint32_t pcrindex; -- grub_uint32_t eventtype; -- grub_uint8_t digest[20]; -- grub_uint32_t eventsize; -- grub_uint8_t event[1]; --} Event; -- -- - static grub_err_t - grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, - grub_size_t size, grub_uint8_t pcr, - const char *description) - { -- Event *event; -+ TCG_PCR_EVENT *event; - grub_efi_status_t status; - grub_efi_tpm_protocol_t *tpm; - grub_efi_physical_address_t lastevent; -@@ -188,18 +179,19 @@ grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, - if (!grub_tpm_present(tpm)) - return 0; - -- event = grub_zalloc(sizeof (Event) + grub_strlen(description) + 1); -+ event = grub_zalloc(sizeof (TCG_PCR_EVENT) + grub_strlen(description) + 1); - if (!event) - return grub_error (GRUB_ERR_OUT_OF_MEMORY, - N_("cannot allocate TPM event buffer")); - -- event->pcrindex = pcr; -- event->eventtype = EV_IPL; -- event->eventsize = grub_strlen(description) + 1; -- grub_memcpy(event->event, description, event->eventsize); -+ event->PCRIndex = pcr; -+ event->EventType = EV_IPL; -+ event->EventSize = grub_strlen(description) + 1; -+ grub_memcpy(event->Event, description, event->EventSize); - - algorithm = TCG_ALG_SHA; -- status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size, -+ status = efi_call_7 (tpm->log_extend_event, tpm, -+ (unsigned long) buf, (grub_uint64_t) size, - algorithm, event, &eventnum, &lastevent); - - switch (status) { diff --git a/0333-Fixup-for-newer-compiler.patch b/0333-Fixup-for-newer-compiler.patch new file mode 100644 index 0000000..e518af8 --- /dev/null +++ b/0333-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 044ab3abe88..c75848f5c06 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/0333-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch b/0333-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch deleted file mode 100644 index 54c4322..0000000 --- a/0333-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch +++ /dev/null @@ -1,113 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 22 Jun 2018 14:01:06 -0400 -Subject: [PATCH] grub-switch-to-blscfg.in: get rid of a bunch of bashisms - -Since this says /bin/sh at the top, it should work with dash. - -Signed-off-by: Peter Jones ---- - util/grub-switch-to-blscfg.in | 30 +++++++++++++++--------------- - 1 file changed, 15 insertions(+), 15 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 2482483a437..dac41e73836 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -151,18 +151,18 @@ done - - find_grub_cfg() { - local candidate="" -- while [[ -e "${candidate}" || $# -gt 0 ]] -+ while [ -e "${candidate}" -o $# -gt 0 ] - do -- if [[ ! -e "${candidate}" ]] ; then -+ if [ ! -e "${candidate}" ] ; then - candidate="$1" - shift - fi - -- if [[ -L "${candidate}" ]]; then -+ if [ -L "${candidate}" ]; then - candidate="$(realpath "${candidate}")" - fi - -- if [[ -f "${candidate}" ]]; then -+ if [ -f "${candidate}" ]; then - export GRUB_CONFIG_FILE="${candidate}" - return 0 - fi -@@ -175,11 +175,11 @@ if ! find_grub_cfg ${startlink} ${grubdir}/grub.cfg ; then - exit 1 - fi - --if [[ ! -d "${blsdir}" ]]; then -+if [ ! -d "${blsdir}" ]; then - install -m 700 -d "${blsdir}" - fi - --if [[ -f /etc/machine-id ]]; then -+if [ -f /etc/machine-id ]; then - MACHINE_ID=$(cat /etc/machine-id) - else - MACHINE_ID=$(dmesg | sha256sum) -@@ -194,9 +194,9 @@ mkbls() { - local debugid="" - local flavor="" - -- if [[ "$kernelver" == *\+* ]] ; then -+ if [ "$kernelver" == *\+* ] ; then - local flavor=-"${kernelver##*+}" -- if [[ "${flavor}" == "-debug" ]]; then -+ if [ "${flavor}" == "-debug" ]; then - local debugname=" with debugging" - local debugid="-debug" - fi -@@ -219,15 +219,15 @@ EOF - } - - for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do -- if [[ ! -d "/lib/modules/${kernelver}" ]] ; then -+ if [ ! -d "/lib/modules/${kernelver}" ] ; then - continue - fi -- if [[ ! -f "/boot/vmlinuz-${kernelver}" ]]; then -+ if [ ! -f "/boot/vmlinuz-${kernelver}" ]; then - continue - fi - bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" - kernel_dir="/lib/modules/${kernelver}" -- if [[ -f "${kernel_dir}/bls.conf" ]]; then -+ if [ -f "${kernel_dir}/bls.conf" ]; then - cp -af "${kernel_dir}/bls.conf" "${bls_target}" - else - mkbls "${kernelver}" \ -@@ -240,7 +240,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" - initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" - -- if [[ $linux != $linux_relpath ]]; then -+ if [ $linux != $linux_relpath ] ; then - sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" - sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" - fi -@@ -257,8 +257,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - fi - done - --if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then -- if [[ $linux != $linux_relpath ]]; then -+if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then -+ if [ $linux != $linux_relpath ]; then - bootprefix="$(dirname ${linux_relpath})" - fi - mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" -@@ -282,7 +282,7 @@ elif ! grep -q '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" ; then - GENERATE=1 - fi - --if [[ "${GENERATE}" -eq 1 ]] ; then -+if [ "${GENERATE}" -eq 1 ] ; then - 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}" diff --git a/0334-TPM-Fix-hash_log_extend_event-function-prototype.patch b/0334-TPM-Fix-hash_log_extend_event-function-prototype.patch new file mode 100644 index 0000000..56cd169 --- /dev/null +++ b/0334-TPM-Fix-hash_log_extend_event-function-prototype.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Fri, 15 Jun 2018 09:25:00 +0200 +Subject: [PATCH] TPM: Fix hash_log_extend_event function prototype + +The DataToHash argument is a efi_physical_address, not a *pointer* to +a efi_physical_address. + +This distinction is important for 32 bits builds, where the pointer is +only 32 bits where as an efi_physical_address is 64 bits. + +Fixing this fixes the tpm code not working with 32 bits build and grub +showing multiple: + +error: Invalid parameter + +Messages during boot, followed by a "press any key to continue" message. + +Signed-off-by: Hans de Goede +--- + grub-core/kern/efi/tpm.c | 2 +- + include/grub/efi/tpm.h | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c +index c9fb3c133f3..36e1f69df16 100644 +--- a/grub-core/kern/efi/tpm.c ++++ b/grub-core/kern/efi/tpm.c +@@ -245,7 +245,7 @@ grub_tpm2_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, + event->Size = sizeof(*event) - sizeof(event->Event) + grub_strlen(description) + 1; + grub_memcpy(event->Event, description, grub_strlen(description) + 1); + +- status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, buf, ++ status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (unsigned long) buf, + (grub_uint64_t) size, event); + + switch (status) { +diff --git a/include/grub/efi/tpm.h b/include/grub/efi/tpm.h +index e2aff4a3c22..63d8a0fe714 100644 +--- a/include/grub/efi/tpm.h ++++ b/include/grub/efi/tpm.h +@@ -129,7 +129,7 @@ struct grub_efi_tpm2_protocol + grub_efi_boolean_t *EventLogTruncated); + grub_efi_status_t (*hash_log_extend_event) (struct grub_efi_tpm2_protocol *this, + grub_efi_uint64_t Flags, +- grub_efi_physical_address_t *DataToHash, ++ grub_efi_physical_address_t DataToHash, + grub_efi_uint64_t DataToHashLen, + EFI_TCG2_EVENT *EfiTcgEvent); + grub_efi_status_t (*submit_command) (struct grub_efi_tpm2_protocol *this, diff --git a/0334-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch b/0334-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch deleted file mode 100644 index 8437c68..0000000 --- a/0334-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Fri, 22 Jun 2018 14:04:28 -0400 -Subject: [PATCH] grub-switch-to-blscfg.in: Better boot prefix checking - -Signed-off-by: Peter Jones ---- - util/grub-switch-to-blscfg.in | 36 +++++++++++++++++------------------- - 1 file changed, 17 insertions(+), 19 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index dac41e73836..884cf45b1e1 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -219,30 +219,31 @@ EOF - } - - for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do -- if [ ! -d "/lib/modules/${kernelver}" ] ; then -- continue -- fi -- if [ ! -f "/boot/vmlinuz-${kernelver}" ]; then -- continue -- fi - bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" -+ linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]+,,')" - kernel_dir="/lib/modules/${kernelver}" -- if [ -f "${kernel_dir}/bls.conf" ]; then -+ -+ if [ ! -d "${kernel_dir}" ] ; then -+ continue -+ fi -+ if [ ! -f "${linux_path}" ]; then -+ continue -+ fi -+ -+ linux_relpath="$("${grub_mkrelpath}" "${linux}")" -+ bootprefix="${linux%%"${linux_relpath}"}" -+ -+ if [ -f "${kernel_dir}/bls.conf" ] ; then - cp -af "${kernel_dir}/bls.conf" "${bls_target}" - else - mkbls "${kernelver}" \ - "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ -+ "${bootprefix}" \ - >"${bls_target}" - fi - -- linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')" -- initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')" -- linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" -- initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" -- -- if [ $linux != $linux_relpath ] ; then -- sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" -- sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" -+ if [ -n "${bootprefix}" ]; then -+ sed -i -e "s,\([ \t]\)${bootprefix},\1,g" "${bls_target}" - fi - - if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -@@ -257,10 +258,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - fi - done - --if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then -- if [ $linux != $linux_relpath ]; then -- bootprefix="$(dirname ${linux_relpath})" -- fi -+if [ -n "${bootprefix}" -a -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then - mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" - fi - diff --git a/0335-TPM-Fix-compiler-warnings.patch b/0335-TPM-Fix-compiler-warnings.patch new file mode 100644 index 0000000..b19d484 --- /dev/null +++ b/0335-TPM-Fix-compiler-warnings.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Fri, 15 Jun 2018 09:58:50 +0200 +Subject: [PATCH] TPM: Fix compiler warnings + +Stop defining our own Event type in tpm.c instead use the one from +the header, so that it matches the function prototype. +Note this requires some further code changes to go from all lowercaps +of the private Event type to the CamelCaps from the header. + +Also cast buf, which gets passed as a efi_physicall_address_t to an +integer, to avoid the compiler complaining about passing a pointer as +an integer. + +Signed-off-by: Hans de Goede +--- + grub-core/kern/efi/tpm.c | 24 ++++++++---------------- + 1 file changed, 8 insertions(+), 16 deletions(-) + +diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c +index 36e1f69df16..0d3ebe22e57 100644 +--- a/grub-core/kern/efi/tpm.c ++++ b/grub-core/kern/efi/tpm.c +@@ -161,21 +161,12 @@ grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf, + } + } + +-typedef struct { +- grub_uint32_t pcrindex; +- grub_uint32_t eventtype; +- grub_uint8_t digest[20]; +- grub_uint32_t eventsize; +- grub_uint8_t event[1]; +-} Event; +- +- + static grub_err_t + grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, + grub_size_t size, grub_uint8_t pcr, + const char *description) + { +- Event *event; ++ TCG_PCR_EVENT *event; + grub_efi_status_t status; + grub_efi_tpm_protocol_t *tpm; + grub_efi_physical_address_t lastevent; +@@ -188,18 +179,19 @@ grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf, + if (!grub_tpm_present(tpm)) + return 0; + +- event = grub_zalloc(sizeof (Event) + grub_strlen(description) + 1); ++ event = grub_zalloc(sizeof (TCG_PCR_EVENT) + grub_strlen(description) + 1); + if (!event) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, + N_("cannot allocate TPM event buffer")); + +- event->pcrindex = pcr; +- event->eventtype = EV_IPL; +- event->eventsize = grub_strlen(description) + 1; +- grub_memcpy(event->event, description, event->eventsize); ++ event->PCRIndex = pcr; ++ event->EventType = EV_IPL; ++ event->EventSize = grub_strlen(description) + 1; ++ grub_memcpy(event->Event, description, event->EventSize); + + algorithm = TCG_ALG_SHA; +- status = efi_call_7 (tpm->log_extend_event, tpm, buf, (grub_uint64_t) size, ++ status = efi_call_7 (tpm->log_extend_event, tpm, ++ (unsigned long) buf, (grub_uint64_t) size, + algorithm, event, &eventnum, &lastevent); + + switch (status) { diff --git a/0335-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch b/0335-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch deleted file mode 100644 index a0fe366..0000000 --- a/0335-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch +++ /dev/null @@ -1,152 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 25 Jun 2018 11:45:33 +0200 -Subject: [PATCH] Use /boot/loader/entries as BLS directory path also on EFI - systems - -For EFI systems, the BLS fragments were stored in the EFI System Partition -(ESP) while in non-EFI systems it was stored in /boot. - -For consistency, it's better to always store the BLS fragments in the same -path regardless of the firmware interface used. - -Also change the grub2-switch-to-blscfg script default BLS directory. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 48 ++++++++++++++++++++++++++++++++----------- - util/grub-switch-to-blscfg.in | 4 ++-- - 2 files changed, 38 insertions(+), 14 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index cd5c29fdf74..11fe6e2c29f 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -381,9 +381,14 @@ static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) - return rc; - } - -+struct read_entry_info { -+ const char *devid; -+ const char *dirname; -+}; -+ - static int read_entry ( - const char *filename, -- const struct grub_dirhook_info *info UNUSED, -+ const struct grub_dirhook_info *dirhook_info UNUSED, - void *data) - { - grub_size_t n; -@@ -391,8 +396,7 @@ static int read_entry ( - grub_file_t f = NULL; - grub_off_t sz; - struct bls_entry *entry; -- const char *dirname= (const char *)data; -- const char *devid = grub_env_get ("boot"); -+ struct read_entry_info *info = (struct read_entry_info *)data; - - grub_dprintf ("blscfg", "filename: \"%s\"\n", filename); - -@@ -406,7 +410,7 @@ static int read_entry ( - if (grub_strcmp (filename + n - 5, ".conf") != 0) - return 0; - -- p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename); -+ p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename); - - f = grub_file_open (p); - if (!f) -@@ -655,10 +659,13 @@ static int find_entry (const char *filename, - void *data) - { - struct find_entry_info *info = (struct find_entry_info *)data; -+ struct read_entry_info read_entry_info; - grub_file_t f = NULL; - char *grubenv_path = NULL; - grub_envblk_t env = NULL; - char *default_blsdir = NULL; -+ grub_fs_t blsdir_fs = NULL; -+ grub_device_t blsdir_dev = NULL; - const char *blsdir = NULL; - char *saved_env_buf = NULL; - int r = 0; -@@ -678,9 +685,6 @@ static int find_entry (const char *filename, - if (info->platform == PLATFORM_EMU) - default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, - GRUB_BLS_CONFIG_PATH); -- else if (info->platform == PLATFORM_EFI) -- default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, -- GRUB_BLS_CONFIG_PATH); - else - default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); - -@@ -744,16 +748,33 @@ static int find_entry (const char *filename, - goto finish; - - grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); -- if (blsdir[0] != '/' && info->platform == PLATFORM_EFI) -- blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); -- else -- blsdir = grub_strdup (blsdir); -+ blsdir = grub_strdup (blsdir); - - if (!blsdir) - goto finish; - - grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); -- r = info->fs->dir (info->dev, blsdir, read_entry, (char *)blsdir); -+ if (info->platform == PLATFORM_EFI) { -+ read_entry_info.devid = grub_env_get ("root"); -+ if (!read_entry_info.devid) -+ goto finish; -+ -+ blsdir_dev = grub_device_open (read_entry_info.devid); -+ if (!blsdir_dev) -+ goto finish; -+ -+ blsdir_fs = grub_fs_probe (blsdir_dev); -+ if (!blsdir_fs) -+ goto finish; -+ -+ } else { -+ read_entry_info.devid = devid; -+ blsdir_dev = info->dev; -+ blsdir_fs = info->fs; -+ } -+ read_entry_info.dirname = blsdir; -+ -+ r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info); - if (r != 0) { - grub_dprintf ("blscfg", "read_entry returned error\n"); - grub_err_t e; -@@ -773,6 +794,9 @@ static int find_entry (const char *filename, - for (r = 0; r < nentries; r++) - bls_free_entry (entries[r]); - finish: -+ if (info->platform == PLATFORM_EFI && blsdir_dev) -+ grub_device_close (blsdir_dev); -+ - nentries = 0; - - grub_free (entries); -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 884cf45b1e1..2f37a1f740b 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -44,13 +44,13 @@ EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') - if [ -d /sys/firmware/efi/efivars/ ]; then - startlink=/etc/grub2-efi.cfg - grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` -- blsdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/loader/entries" | sed 's,//*,/,g'` - else - startlink=/etc/grub2.cfg - grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` -- blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` - fi - -+blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` -+ - backupsuffix=.bak - - export TEXTDOMAIN=@PACKAGE@ diff --git a/0336-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch b/0336-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch deleted file mode 100644 index 12a3715..0000000 --- a/0336-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch +++ /dev/null @@ -1,134 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Tue, 26 Jun 2018 14:01:26 +0200 -Subject: [PATCH] Use BLS fragment filename as menu entry id and for criteria - to sort - -The BLS config filenames are guaranteed to be unique, so they can be -used as GRUB2 entry id and can also be used to sort the menu entries. - -Signed-off-by: Javier Martinez Canillas ---- - grub-core/commands/blscfg.c | 62 +++++++++------------------------------------ - 1 file changed, 12 insertions(+), 50 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 11fe6e2c29f..23d15adfadc 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -70,6 +70,7 @@ struct bls_entry - { - struct keyval **keyvals; - int nkeyvals; -+ char *filename; - }; - - static struct bls_entry **entries; -@@ -166,6 +167,7 @@ static void bls_free_entry(struct bls_entry *entry) - - grub_free (entry->keyvals); - grub_memset (entry, 0, sizeof (*entry)); -+ grub_free (entry->filename); - grub_free (entry); - } - -@@ -327,58 +329,12 @@ finish: - - typedef int (*void_cmp_t)(void *, void *); - --static int nulcmp(char *s0, char *s1, void_cmp_t cmp) --{ -- grub_dprintf("blscfg", "%s got here\n", __func__); -- if (s1 && !s0) -- return 1; -- if (s0 && !s1) -- return -1; -- if (!s0 && !s1) -- return 0; -- if (cmp) -- return cmp(s0, s1); -- return grub_strcmp(s0, s1); --} -- --static int --bls_keyval_cmp(struct bls_entry *e0, struct bls_entry *e1, const char *keyname) --{ -- char *val0, *val1; -- -- val0 = bls_get_val (e0, keyname, NULL); -- val1 = bls_get_val (e1, keyname, NULL); -- -- if (val1 && !val0) -- return 1; -- -- if (val0 && !val1) -- return -1; -- -- if (!val0 && !val1) -- return 0; -- -- return nulcmp(val0, val1, (void_cmp_t)vercmp); --} -- - static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) - { - struct bls_entry * e0 = *(struct bls_entry **)p0; - struct bls_entry * e1 = *(struct bls_entry **)p1; -- int rc = 0; - -- rc = bls_keyval_cmp (e0, e1, "id"); -- -- if (rc == 0) -- rc = bls_keyval_cmp (e0, e1, "version"); -- -- if (rc == 0) -- rc = bls_keyval_cmp (e0, e1, "title"); -- -- if (rc == 0) -- rc = bls_keyval_cmp (e0, e1, "linux"); -- -- return rc; -+ return vercmp(e0->filename, e1->filename); - } - - struct read_entry_info { -@@ -424,6 +380,12 @@ static int read_entry ( - if (!entry) - goto finish; - -+ entry->filename = grub_strndup(filename, n - 5); -+ if (!entry->filename) -+ goto finish; -+ -+ entry->filename[n - 5] = '\0'; -+ - for (;;) - { - char *buf; -@@ -548,7 +510,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - char *options = NULL; - char **initrds = NULL; - char *initrd = NULL; -- char *id = NULL; -+ char *id = entry->filename; - char *hotkey = NULL; - - char *users = NULL; -@@ -570,7 +532,6 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - title = bls_get_val (entry, "title", NULL); - options = bls_get_val (entry, "options", NULL); - initrds = bls_make_list (entry, "initrd", NULL); -- id = bls_get_val (entry, "id", NULL); - - hotkey = bls_get_val (entry, "grub_hotkey", NULL); - users = bls_get_val (entry, "grub_users", NULL); -@@ -584,7 +545,8 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - argv[i] = args[i-1]; - argv[argc] = NULL; - -- grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title); -+ grub_dprintf ("blscfg", "adding menu entry for \"%s\" with id \"%s\"\n", -+ title, id); - if (initrds) - { - int initrd_size = sizeof (GRUB_INITRD_CMD); diff --git a/0336-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch b/0336-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch new file mode 100644 index 0000000..54c4322 --- /dev/null +++ b/0336-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch @@ -0,0 +1,113 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 22 Jun 2018 14:01:06 -0400 +Subject: [PATCH] grub-switch-to-blscfg.in: get rid of a bunch of bashisms + +Since this says /bin/sh at the top, it should work with dash. + +Signed-off-by: Peter Jones +--- + util/grub-switch-to-blscfg.in | 30 +++++++++++++++--------------- + 1 file changed, 15 insertions(+), 15 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 2482483a437..dac41e73836 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -151,18 +151,18 @@ done + + find_grub_cfg() { + local candidate="" +- while [[ -e "${candidate}" || $# -gt 0 ]] ++ while [ -e "${candidate}" -o $# -gt 0 ] + do +- if [[ ! -e "${candidate}" ]] ; then ++ if [ ! -e "${candidate}" ] ; then + candidate="$1" + shift + fi + +- if [[ -L "${candidate}" ]]; then ++ if [ -L "${candidate}" ]; then + candidate="$(realpath "${candidate}")" + fi + +- if [[ -f "${candidate}" ]]; then ++ if [ -f "${candidate}" ]; then + export GRUB_CONFIG_FILE="${candidate}" + return 0 + fi +@@ -175,11 +175,11 @@ if ! find_grub_cfg ${startlink} ${grubdir}/grub.cfg ; then + exit 1 + fi + +-if [[ ! -d "${blsdir}" ]]; then ++if [ ! -d "${blsdir}" ]; then + install -m 700 -d "${blsdir}" + fi + +-if [[ -f /etc/machine-id ]]; then ++if [ -f /etc/machine-id ]; then + MACHINE_ID=$(cat /etc/machine-id) + else + MACHINE_ID=$(dmesg | sha256sum) +@@ -194,9 +194,9 @@ mkbls() { + local debugid="" + local flavor="" + +- if [[ "$kernelver" == *\+* ]] ; then ++ if [ "$kernelver" == *\+* ] ; then + local flavor=-"${kernelver##*+}" +- if [[ "${flavor}" == "-debug" ]]; then ++ if [ "${flavor}" == "-debug" ]; then + local debugname=" with debugging" + local debugid="-debug" + fi +@@ -219,15 +219,15 @@ EOF + } + + for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do +- if [[ ! -d "/lib/modules/${kernelver}" ]] ; then ++ if [ ! -d "/lib/modules/${kernelver}" ] ; then + continue + fi +- if [[ ! -f "/boot/vmlinuz-${kernelver}" ]]; then ++ if [ ! -f "/boot/vmlinuz-${kernelver}" ]; then + continue + fi + bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" + kernel_dir="/lib/modules/${kernelver}" +- if [[ -f "${kernel_dir}/bls.conf" ]]; then ++ if [ -f "${kernel_dir}/bls.conf" ]; then + cp -af "${kernel_dir}/bls.conf" "${bls_target}" + else + mkbls "${kernelver}" \ +@@ -240,7 +240,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" + initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" + +- if [[ $linux != $linux_relpath ]]; then ++ if [ $linux != $linux_relpath ] ; then + sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" + sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" + fi +@@ -257,8 +257,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + fi + done + +-if [[ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]]; then +- if [[ $linux != $linux_relpath ]]; then ++if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then ++ if [ $linux != $linux_relpath ]; then + bootprefix="$(dirname ${linux_relpath})" + fi + mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" +@@ -282,7 +282,7 @@ elif ! grep -q '^GRUB_ENABLE_BLSCFG=.*' "${etcdefaultgrub}" ; then + GENERATE=1 + fi + +-if [[ "${GENERATE}" -eq 1 ]] ; then ++if [ "${GENERATE}" -eq 1 ] ; then + 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}" diff --git a/0337-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch b/0337-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch deleted file mode 100644 index be7d1a3..0000000 --- a/0337-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Javier Martinez Canillas -Date: Mon, 9 Jul 2018 12:19:03 +0200 -Subject: [PATCH] Fix grub-switch-to-blscfg boot prefix handling - -Commit b3ac18e3265f ("grub-switch-to-blscfg.in: Better boot prefix checking") -simplified the boot prefix checking, but unfortunately introduced a couple of -regressions on the script. Fix them. - -Signed-off-by: Javier Martinez Canillas ---- - util/grub-switch-to-blscfg.in | 12 +++++++----- - 1 file changed, 7 insertions(+), 5 deletions(-) - -diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in -index 2f37a1f740b..40612e00686 100644 ---- a/util/grub-switch-to-blscfg.in -+++ b/util/grub-switch-to-blscfg.in -@@ -220,7 +220,8 @@ EOF - - for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" -- linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]+,,')" -+ linux="/vmlinuz-${kernelver}" -+ linux_path="/boot${linux}" - kernel_dir="/lib/modules/${kernelver}" - - if [ ! -d "${kernel_dir}" ] ; then -@@ -230,8 +231,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - continue - fi - -- linux_relpath="$("${grub_mkrelpath}" "${linux}")" -- bootprefix="${linux%%"${linux_relpath}"}" -+ linux_relpath="$("${grub_mkrelpath}" "${linux_path}")" -+ bootprefix="${linux_relpath%%"${linux}"}" - - if [ -f "${kernel_dir}/bls.conf" ] ; then - cp -af "${kernel_dir}/bls.conf" "${bls_target}" -@@ -243,7 +244,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - fi - - if [ -n "${bootprefix}" ]; then -- sed -i -e "s,\([ \t]\)${bootprefix},\1,g" "${bls_target}" -+ sed -i -e "s,^\(linux[^ \t]*[ \t]\+\).*,\1${bootprefix}${linux},g" "${bls_target}" -+ sed -i -e "/^initrd/ s,\([ \t]\+\)\([^ \t]\+\),\1${bootprefix}\2,g" "${bls_target}" - fi - - if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then -@@ -258,7 +260,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do - fi - done - --if [ -n "${bootprefix}" -a -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then -+if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then - mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" - fi - diff --git a/0337-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch b/0337-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch new file mode 100644 index 0000000..8437c68 --- /dev/null +++ b/0337-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch @@ -0,0 +1,73 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 22 Jun 2018 14:04:28 -0400 +Subject: [PATCH] grub-switch-to-blscfg.in: Better boot prefix checking + +Signed-off-by: Peter Jones +--- + util/grub-switch-to-blscfg.in | 36 +++++++++++++++++------------------- + 1 file changed, 17 insertions(+), 19 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index dac41e73836..884cf45b1e1 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -219,30 +219,31 @@ EOF + } + + for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do +- if [ ! -d "/lib/modules/${kernelver}" ] ; then +- continue +- fi +- if [ ! -f "/boot/vmlinuz-${kernelver}" ]; then +- continue +- fi + bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" ++ linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]+,,')" + kernel_dir="/lib/modules/${kernelver}" +- if [ -f "${kernel_dir}/bls.conf" ]; then ++ ++ if [ ! -d "${kernel_dir}" ] ; then ++ continue ++ fi ++ if [ ! -f "${linux_path}" ]; then ++ continue ++ fi ++ ++ linux_relpath="$("${grub_mkrelpath}" "${linux}")" ++ bootprefix="${linux%%"${linux_relpath}"}" ++ ++ if [ -f "${kernel_dir}/bls.conf" ] ; then + cp -af "${kernel_dir}/bls.conf" "${bls_target}" + else + mkbls "${kernelver}" \ + "$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${kernel_dir}")")" \ ++ "${bootprefix}" \ + >"${bls_target}" + fi + +- linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]*,,')" +- initrd="$(grep '^initrd[ \t]' "${bls_target}" | sed -e 's,^initrd[ \t]*,,')" +- linux_relpath="$("${grub_mkrelpath}" /boot/$linux)" +- initrd_relpath="$("${grub_mkrelpath}" /boot/$initrd)" +- +- if [ $linux != $linux_relpath ] ; then +- sed -i -e "s,^linux.*,linux ${linux_relpath},g" "${bls_target}" +- sed -i -e "s,^initrd.*,initrd ${initrd_relpath},g" "${bls_target}" ++ if [ -n "${bootprefix}" ]; then ++ sed -i -e "s,\([ \t]\)${bootprefix},\1,g" "${bls_target}" + fi + + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then +@@ -257,10 +258,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + fi + done + +-if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then +- if [ $linux != $linux_relpath ]; then +- bootprefix="$(dirname ${linux_relpath})" +- fi ++if [ -n "${bootprefix}" -a -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then + mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" + fi + diff --git a/0338-Revert-trim-arp-packets-with-abnormal-size.patch b/0338-Revert-trim-arp-packets-with-abnormal-size.patch deleted file mode 100644 index 5a169d7..0000000 --- a/0338-Revert-trim-arp-packets-with-abnormal-size.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 18 May 2017 14:25:45 -0400 -Subject: [PATCH] Revert "trim arp packets with abnormal size" - -This reverts commit d11b2eb425d2125f67dd8d8e9b11d9be7d6f3f11. ---- - grub-core/net/arp.c | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c -index d1c69ed2b55..54306e3b16d 100644 ---- a/grub-core/net/arp.c -+++ b/grub-core/net/arp.c -@@ -150,12 +150,6 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, - if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 - && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) - { -- if ((nb->tail - nb->data) > 50) -- { -- grub_dprintf ("net", "arp packet with abnormal size (%ld bytes).\n", -- nb->tail - nb->data); -- nb->tail = nb->data + 50; -- } - grub_net_link_level_address_t target; - struct grub_net_buff nb_reply; - struct arppkt *arp_reply; diff --git a/0338-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch b/0338-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch new file mode 100644 index 0000000..a0fe366 --- /dev/null +++ b/0338-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch @@ -0,0 +1,152 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 25 Jun 2018 11:45:33 +0200 +Subject: [PATCH] Use /boot/loader/entries as BLS directory path also on EFI + systems + +For EFI systems, the BLS fragments were stored in the EFI System Partition +(ESP) while in non-EFI systems it was stored in /boot. + +For consistency, it's better to always store the BLS fragments in the same +path regardless of the firmware interface used. + +Also change the grub2-switch-to-blscfg script default BLS directory. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 48 ++++++++++++++++++++++++++++++++----------- + util/grub-switch-to-blscfg.in | 4 ++-- + 2 files changed, 38 insertions(+), 14 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index cd5c29fdf74..11fe6e2c29f 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -381,9 +381,14 @@ static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) + return rc; + } + ++struct read_entry_info { ++ const char *devid; ++ const char *dirname; ++}; ++ + static int read_entry ( + const char *filename, +- const struct grub_dirhook_info *info UNUSED, ++ const struct grub_dirhook_info *dirhook_info UNUSED, + void *data) + { + grub_size_t n; +@@ -391,8 +396,7 @@ static int read_entry ( + grub_file_t f = NULL; + grub_off_t sz; + struct bls_entry *entry; +- const char *dirname= (const char *)data; +- const char *devid = grub_env_get ("boot"); ++ struct read_entry_info *info = (struct read_entry_info *)data; + + grub_dprintf ("blscfg", "filename: \"%s\"\n", filename); + +@@ -406,7 +410,7 @@ static int read_entry ( + if (grub_strcmp (filename + n - 5, ".conf") != 0) + return 0; + +- p = grub_xasprintf ("(%s)%s/%s", devid, dirname, filename); ++ p = grub_xasprintf ("(%s)%s/%s", info->devid, info->dirname, filename); + + f = grub_file_open (p); + if (!f) +@@ -655,10 +659,13 @@ static int find_entry (const char *filename, + void *data) + { + struct find_entry_info *info = (struct find_entry_info *)data; ++ struct read_entry_info read_entry_info; + grub_file_t f = NULL; + char *grubenv_path = NULL; + grub_envblk_t env = NULL; + char *default_blsdir = NULL; ++ grub_fs_t blsdir_fs = NULL; ++ grub_device_t blsdir_dev = NULL; + const char *blsdir = NULL; + char *saved_env_buf = NULL; + int r = 0; +@@ -678,9 +685,6 @@ static int find_entry (const char *filename, + if (info->platform == PLATFORM_EMU) + default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, + GRUB_BLS_CONFIG_PATH); +- else if (info->platform == PLATFORM_EFI) +- default_blsdir = grub_xasprintf ("/EFI/%s%s", filename, +- GRUB_BLS_CONFIG_PATH); + else + default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); + +@@ -744,16 +748,33 @@ static int find_entry (const char *filename, + goto finish; + + grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); +- if (blsdir[0] != '/' && info->platform == PLATFORM_EFI) +- blsdir = grub_xasprintf ("/EFI/%s/%s/", filename, blsdir); +- else +- blsdir = grub_strdup (blsdir); ++ blsdir = grub_strdup (blsdir); + + if (!blsdir) + goto finish; + + grub_dprintf ("blscfg", "blsdir: \"%s\"\n", blsdir); +- r = info->fs->dir (info->dev, blsdir, read_entry, (char *)blsdir); ++ if (info->platform == PLATFORM_EFI) { ++ read_entry_info.devid = grub_env_get ("root"); ++ if (!read_entry_info.devid) ++ goto finish; ++ ++ blsdir_dev = grub_device_open (read_entry_info.devid); ++ if (!blsdir_dev) ++ goto finish; ++ ++ blsdir_fs = grub_fs_probe (blsdir_dev); ++ if (!blsdir_fs) ++ goto finish; ++ ++ } else { ++ read_entry_info.devid = devid; ++ blsdir_dev = info->dev; ++ blsdir_fs = info->fs; ++ } ++ read_entry_info.dirname = blsdir; ++ ++ r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info); + if (r != 0) { + grub_dprintf ("blscfg", "read_entry returned error\n"); + grub_err_t e; +@@ -773,6 +794,9 @@ static int find_entry (const char *filename, + for (r = 0; r < nentries; r++) + bls_free_entry (entries[r]); + finish: ++ if (info->platform == PLATFORM_EFI && blsdir_dev) ++ grub_device_close (blsdir_dev); ++ + nentries = 0; + + grub_free (entries); +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 884cf45b1e1..2f37a1f740b 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -44,13 +44,13 @@ EFIDIR=$(grep ^ID= /etc/os-release | sed -e 's/^ID=//' -e 's/rhel/redhat/') + if [ -d /sys/firmware/efi/efivars/ ]; then + startlink=/etc/grub2-efi.cfg + grubdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/" | sed 's,//*,/,g'` +- blsdir=`echo "/@bootdirname@/efi/EFI/${EFIDIR}/loader/entries" | sed 's,//*,/,g'` + else + startlink=/etc/grub2.cfg + grubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'` +- blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` + fi + ++blsdir=`echo "/@bootdirname@/loader/entries" | sed 's,//*,/,g'` ++ + backupsuffix=.bak + + export TEXTDOMAIN=@PACKAGE@ diff --git a/0339-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch b/0339-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch new file mode 100644 index 0000000..12a3715 --- /dev/null +++ b/0339-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch @@ -0,0 +1,134 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Tue, 26 Jun 2018 14:01:26 +0200 +Subject: [PATCH] Use BLS fragment filename as menu entry id and for criteria + to sort + +The BLS config filenames are guaranteed to be unique, so they can be +used as GRUB2 entry id and can also be used to sort the menu entries. + +Signed-off-by: Javier Martinez Canillas +--- + grub-core/commands/blscfg.c | 62 +++++++++------------------------------------ + 1 file changed, 12 insertions(+), 50 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 11fe6e2c29f..23d15adfadc 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -70,6 +70,7 @@ struct bls_entry + { + struct keyval **keyvals; + int nkeyvals; ++ char *filename; + }; + + static struct bls_entry **entries; +@@ -166,6 +167,7 @@ static void bls_free_entry(struct bls_entry *entry) + + grub_free (entry->keyvals); + grub_memset (entry, 0, sizeof (*entry)); ++ grub_free (entry->filename); + grub_free (entry); + } + +@@ -327,58 +329,12 @@ finish: + + typedef int (*void_cmp_t)(void *, void *); + +-static int nulcmp(char *s0, char *s1, void_cmp_t cmp) +-{ +- grub_dprintf("blscfg", "%s got here\n", __func__); +- if (s1 && !s0) +- return 1; +- if (s0 && !s1) +- return -1; +- if (!s0 && !s1) +- return 0; +- if (cmp) +- return cmp(s0, s1); +- return grub_strcmp(s0, s1); +-} +- +-static int +-bls_keyval_cmp(struct bls_entry *e0, struct bls_entry *e1, const char *keyname) +-{ +- char *val0, *val1; +- +- val0 = bls_get_val (e0, keyname, NULL); +- val1 = bls_get_val (e1, keyname, NULL); +- +- if (val1 && !val0) +- return 1; +- +- if (val0 && !val1) +- return -1; +- +- if (!val0 && !val1) +- return 0; +- +- return nulcmp(val0, val1, (void_cmp_t)vercmp); +-} +- + static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) + { + struct bls_entry * e0 = *(struct bls_entry **)p0; + struct bls_entry * e1 = *(struct bls_entry **)p1; +- int rc = 0; + +- rc = bls_keyval_cmp (e0, e1, "id"); +- +- if (rc == 0) +- rc = bls_keyval_cmp (e0, e1, "version"); +- +- if (rc == 0) +- rc = bls_keyval_cmp (e0, e1, "title"); +- +- if (rc == 0) +- rc = bls_keyval_cmp (e0, e1, "linux"); +- +- return rc; ++ return vercmp(e0->filename, e1->filename); + } + + struct read_entry_info { +@@ -424,6 +380,12 @@ static int read_entry ( + if (!entry) + goto finish; + ++ entry->filename = grub_strndup(filename, n - 5); ++ if (!entry->filename) ++ goto finish; ++ ++ entry->filename[n - 5] = '\0'; ++ + for (;;) + { + char *buf; +@@ -548,7 +510,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + char *options = NULL; + char **initrds = NULL; + char *initrd = NULL; +- char *id = NULL; ++ char *id = entry->filename; + char *hotkey = NULL; + + char *users = NULL; +@@ -570,7 +532,6 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + title = bls_get_val (entry, "title", NULL); + options = bls_get_val (entry, "options", NULL); + initrds = bls_make_list (entry, "initrd", NULL); +- id = bls_get_val (entry, "id", NULL); + + hotkey = bls_get_val (entry, "grub_hotkey", NULL); + users = bls_get_val (entry, "grub_users", NULL); +@@ -584,7 +545,8 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + argv[i] = args[i-1]; + argv[argc] = NULL; + +- grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title); ++ grub_dprintf ("blscfg", "adding menu entry for \"%s\" with id \"%s\"\n", ++ title, id); + if (initrds) + { + int initrd_size = sizeof (GRUB_INITRD_CMD); diff --git a/0339-Use-xid-to-match-DHCP-replies.patch b/0339-Use-xid-to-match-DHCP-replies.patch deleted file mode 100644 index 657ebb7..0000000 --- a/0339-Use-xid-to-match-DHCP-replies.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Andrzej Kacprowski -Date: Fri, 21 Apr 2017 09:20:38 +0200 -Subject: [PATCH] Use xid to match DHCP replies - -Transaction identifier (xid) from DHCP request -packet is stored in network level interface and used -to match request with the responses it generates. - -Resolves: rhbz#1370642 - -Signed-off-by: Andrzej Kacprowski ---- - grub-core/net/bootp.c | 3 ++- - grub-core/net/ip.c | 1 + - include/grub/net.h | 3 ++- - 3 files changed, 5 insertions(+), 2 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index da3e454466b..2869482fe06 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -777,7 +777,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - grub_errno = GRUB_ERR_NONE; - t = 0; - } -- pack->ident = grub_cpu_to_be32 (t); -+ pack->xid = grub_cpu_to_be32 (t); -+ ifaces[j].dhcp_xid = pack->xid; - pack->seconds = grub_cpu_to_be16 (t); - - grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); -diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c -index 7c95cc7464a..8411e0ecca3 100644 ---- a/grub-core/net/ip.c -+++ b/grub-core/net/ip.c -@@ -275,6 +275,7 @@ handle_dgram (struct grub_net_buff *nb, - FOR_NET_NETWORK_LEVEL_INTERFACES (inf) - if (inf->card == card - && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV -+ && inf->dhcp_xid == bootp->xid - && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET - && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr, - sizeof (inf->hwaddress.mac)) == 0) -diff --git a/include/grub/net.h b/include/grub/net.h -index f8f3ec13acc..de51894cbbf 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -292,6 +292,7 @@ struct grub_net_network_level_interface - struct grub_net_bootp_packet *dhcp_ack; - grub_size_t dhcp_acklen; - grub_uint16_t vlantag; -+ grub_uint32_t dhcp_xid; - void *data; - }; - -@@ -429,7 +430,7 @@ struct grub_net_bootp_packet - grub_uint8_t hw_type; /* hardware type. */ - grub_uint8_t hw_len; /* hardware addr len. */ - grub_uint8_t gate_hops; /* zero it. */ -- grub_uint32_t ident; /* random number chosen by client. */ -+ grub_uint32_t xid; /* transaction id chosen by client. */ - grub_uint16_t seconds; /* seconds since did initial bootstrap. */ - grub_uint16_t flags; - grub_uint32_t client_ip; diff --git a/0340-Add-support-for-non-Ethernet-network-cards.patch b/0340-Add-support-for-non-Ethernet-network-cards.patch deleted file mode 100644 index e61bcc1..0000000 --- a/0340-Add-support-for-non-Ethernet-network-cards.patch +++ /dev/null @@ -1,764 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Andrzej Kacprowski -Date: Fri, 21 Apr 2017 10:06:20 +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 - -Conflicts: - grub-core/net/ip.c ---- - grub-core/net/arp.c | 155 ++++++++++++++++++++++----------- - grub-core/net/bootp.c | 14 ++- - 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 | 48 +++++----- - include/grub/net.h | 19 ++-- - 12 files changed, 216 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 2869482fe06..4e55adc557b 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -219,7 +219,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")]; -@@ -232,12 +231,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; - -@@ -770,7 +765,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - grub_memset (pack, 0, sizeof (*pack) + 64); - pack->opcode = 1; - pack->hw_type = 1; -- pack->hw_len = 6; -+ pack->hw_len = ifaces[j].hwaddress.len > 16 ? 0 -+ : ifaces[j].hwaddress.len; - err = grub_get_datetime (&date); - if (err || !grub_datetime2unixtime (&date, &t)) - { -@@ -781,7 +777,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - ifaces[j].dhcp_xid = pack->xid; - pack->seconds = grub_cpu_to_be16 (t); - -- grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); -+ grub_memcpy (&pack->mac_addr, &ifaces[j].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 329024b6f2c..bf36b446dc4 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -329,6 +329,9 @@ grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, - /* 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; -@@ -366,10 +369,11 @@ grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, - *i = (*i)+1; - 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 3df75357a70..ba50415f5f6 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 8411e0ecca3..b2ca74b6eb1 100644 ---- a/grub-core/net/ip.c -+++ b/grub-core/net/ip.c -@@ -277,8 +277,8 @@ handle_dgram (struct grub_net_buff *nb, - && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV - && inf->dhcp_xid == bootp->xid - && 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->card); - grub_netbuff_free (nb); -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index fa3e2912643..9b8944292c7 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,21 @@ 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; -+ -+ 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; -+ } -+ for (ptr = str, i = 0; i < addr->len; i++) -+ { -+ ptr += grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str), -+ "%02x:", addr->mac[i] & 0xff); - } -- grub_printf (_("Unsupported hw address type %d\n"), addr->type); - } - - int -@@ -784,13 +784,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 de51894cbbf..e9ebc6a1b4f 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; - -@@ -555,11 +558,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/0340-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch b/0340-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch new file mode 100644 index 0000000..be7d1a3 --- /dev/null +++ b/0340-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 9 Jul 2018 12:19:03 +0200 +Subject: [PATCH] Fix grub-switch-to-blscfg boot prefix handling + +Commit b3ac18e3265f ("grub-switch-to-blscfg.in: Better boot prefix checking") +simplified the boot prefix checking, but unfortunately introduced a couple of +regressions on the script. Fix them. + +Signed-off-by: Javier Martinez Canillas +--- + util/grub-switch-to-blscfg.in | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +diff --git a/util/grub-switch-to-blscfg.in b/util/grub-switch-to-blscfg.in +index 2f37a1f740b..40612e00686 100644 +--- a/util/grub-switch-to-blscfg.in ++++ b/util/grub-switch-to-blscfg.in +@@ -220,7 +220,8 @@ EOF + + for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + bls_target="${blsdir}/${MACHINE_ID}-${kernelver}.conf" +- linux="$(grep '^linux[ \t]' "${bls_target}" | sed -e 's,^linux[ \t]+,,')" ++ linux="/vmlinuz-${kernelver}" ++ linux_path="/boot${linux}" + kernel_dir="/lib/modules/${kernelver}" + + if [ ! -d "${kernel_dir}" ] ; then +@@ -230,8 +231,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + continue + fi + +- linux_relpath="$("${grub_mkrelpath}" "${linux}")" +- bootprefix="${linux%%"${linux_relpath}"}" ++ linux_relpath="$("${grub_mkrelpath}" "${linux_path}")" ++ bootprefix="${linux_relpath%%"${linux}"}" + + if [ -f "${kernel_dir}/bls.conf" ] ; then + cp -af "${kernel_dir}/bls.conf" "${bls_target}" +@@ -243,7 +244,8 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + fi + + if [ -n "${bootprefix}" ]; then +- sed -i -e "s,\([ \t]\)${bootprefix},\1,g" "${bls_target}" ++ sed -i -e "s,^\(linux[^ \t]*[ \t]\+\).*,\1${bootprefix}${linux},g" "${bls_target}" ++ sed -i -e "/^initrd/ s,\([ \t]\+\)\([^ \t]\+\),\1${bootprefix}\2,g" "${bls_target}" + fi + + if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then +@@ -258,7 +260,7 @@ for kernelver in $(cd /lib/modules/ ; ls -1) "" ; do + fi + done + +-if [ -n "${bootprefix}" -a -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then ++if [ -f "/boot/vmlinuz-0-rescue-${MACHINE_ID}" ]; then + mkbls "0-rescue-${MACHINE_ID}" "0" "${bootprefix}" >"${blsdir}/${MACHINE_ID}-0-rescue.conf" + fi + diff --git a/0341-Revert-trim-arp-packets-with-abnormal-size.patch b/0341-Revert-trim-arp-packets-with-abnormal-size.patch new file mode 100644 index 0000000..5a169d7 --- /dev/null +++ b/0341-Revert-trim-arp-packets-with-abnormal-size.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 18 May 2017 14:25:45 -0400 +Subject: [PATCH] Revert "trim arp packets with abnormal size" + +This reverts commit d11b2eb425d2125f67dd8d8e9b11d9be7d6f3f11. +--- + grub-core/net/arp.c | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/grub-core/net/arp.c b/grub-core/net/arp.c +index d1c69ed2b55..54306e3b16d 100644 +--- a/grub-core/net/arp.c ++++ b/grub-core/net/arp.c +@@ -150,12 +150,6 @@ grub_net_arp_receive (struct grub_net_buff *nb, struct grub_net_card *card, + if (grub_net_addr_cmp (&inf->address, &target_addr) == 0 + && arp_packet->op == grub_cpu_to_be16_compile_time (ARP_REQUEST)) + { +- if ((nb->tail - nb->data) > 50) +- { +- grub_dprintf ("net", "arp packet with abnormal size (%ld bytes).\n", +- nb->tail - nb->data); +- nb->tail = nb->data + 50; +- } + grub_net_link_level_address_t target; + struct grub_net_buff nb_reply; + struct arppkt *arp_reply; diff --git a/0341-misc-fix-invalid-character-recongition-in-strto-l.patch b/0341-misc-fix-invalid-character-recongition-in-strto-l.patch deleted file mode 100644 index 4006028..0000000 --- a/0341-misc-fix-invalid-character-recongition-in-strto-l.patch +++ /dev/null @@ -1,37 +0,0 @@ -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/0342-Use-xid-to-match-DHCP-replies.patch b/0342-Use-xid-to-match-DHCP-replies.patch new file mode 100644 index 0000000..657ebb7 --- /dev/null +++ b/0342-Use-xid-to-match-DHCP-replies.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrzej Kacprowski +Date: Fri, 21 Apr 2017 09:20:38 +0200 +Subject: [PATCH] Use xid to match DHCP replies + +Transaction identifier (xid) from DHCP request +packet is stored in network level interface and used +to match request with the responses it generates. + +Resolves: rhbz#1370642 + +Signed-off-by: Andrzej Kacprowski +--- + grub-core/net/bootp.c | 3 ++- + grub-core/net/ip.c | 1 + + include/grub/net.h | 3 ++- + 3 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index da3e454466b..2869482fe06 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -777,7 +777,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + grub_errno = GRUB_ERR_NONE; + t = 0; + } +- pack->ident = grub_cpu_to_be32 (t); ++ pack->xid = grub_cpu_to_be32 (t); ++ ifaces[j].dhcp_xid = pack->xid; + pack->seconds = grub_cpu_to_be16 (t); + + grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); +diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c +index 7c95cc7464a..8411e0ecca3 100644 +--- a/grub-core/net/ip.c ++++ b/grub-core/net/ip.c +@@ -275,6 +275,7 @@ handle_dgram (struct grub_net_buff *nb, + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) + if (inf->card == card + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV ++ && inf->dhcp_xid == bootp->xid + && inf->hwaddress.type == GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET + && grub_memcmp (inf->hwaddress.mac, &bootp->mac_addr, + sizeof (inf->hwaddress.mac)) == 0) +diff --git a/include/grub/net.h b/include/grub/net.h +index f8f3ec13acc..de51894cbbf 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -292,6 +292,7 @@ struct grub_net_network_level_interface + struct grub_net_bootp_packet *dhcp_ack; + grub_size_t dhcp_acklen; + grub_uint16_t vlantag; ++ grub_uint32_t dhcp_xid; + void *data; + }; + +@@ -429,7 +430,7 @@ struct grub_net_bootp_packet + grub_uint8_t hw_type; /* hardware type. */ + grub_uint8_t hw_len; /* hardware addr len. */ + grub_uint8_t gate_hops; /* zero it. */ +- grub_uint32_t ident; /* random number chosen by client. */ ++ grub_uint32_t xid; /* transaction id chosen by client. */ + grub_uint16_t seconds; /* seconds since did initial bootstrap. */ + grub_uint16_t flags; + grub_uint32_t client_ip; diff --git a/0342-net-read-bracketed-ipv6-addrs-and-port-numbers.patch b/0342-net-read-bracketed-ipv6-addrs-and-port-numbers.patch deleted file mode 100644 index 4f68187..0000000 --- a/0342-net-read-bracketed-ipv6-addrs-and-port-numbers.patch +++ /dev/null @@ -1,229 +0,0 @@ -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 ---- - grub-core/net/http.c | 21 +++++++++++--- - grub-core/net/net.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ - grub-core/net/tftp.c | 8 ++++-- - include/grub/net.h | 1 + - 4 files changed, 101 insertions(+), 6 deletions(-) - -diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index 5aa4ad3befc..f182d7b871d 100644 ---- a/grub-core/net/http.c -+++ b/grub-core/net/http.c -@@ -312,12 +312,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 +358,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 +367,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,8 +401,10 @@ 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, -+ 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, http_err, - file); - if (!data->sock) -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 9b8944292c7..1f887d44b32 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -439,6 +439,12 @@ 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 +483,9 @@ 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; -@@ -1336,8 +1345,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) - { -@@ -1375,6 +1386,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) -diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c -index f90071353ad..e267af354f4 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 e9ebc6a1b4f..f4cd86e582f 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/0343-Add-support-for-non-Ethernet-network-cards.patch b/0343-Add-support-for-non-Ethernet-network-cards.patch new file mode 100644 index 0000000..e61bcc1 --- /dev/null +++ b/0343-Add-support-for-non-Ethernet-network-cards.patch @@ -0,0 +1,764 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrzej Kacprowski +Date: Fri, 21 Apr 2017 10:06:20 +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 + +Conflicts: + grub-core/net/ip.c +--- + grub-core/net/arp.c | 155 ++++++++++++++++++++++----------- + grub-core/net/bootp.c | 14 ++- + 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 | 48 +++++----- + include/grub/net.h | 19 ++-- + 12 files changed, 216 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 2869482fe06..4e55adc557b 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -219,7 +219,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")]; +@@ -232,12 +231,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; + +@@ -770,7 +765,8 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + grub_memset (pack, 0, sizeof (*pack) + 64); + pack->opcode = 1; + pack->hw_type = 1; +- pack->hw_len = 6; ++ pack->hw_len = ifaces[j].hwaddress.len > 16 ? 0 ++ : ifaces[j].hwaddress.len; + err = grub_get_datetime (&date); + if (err || !grub_datetime2unixtime (&date, &t)) + { +@@ -781,7 +777,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + ifaces[j].dhcp_xid = pack->xid; + pack->seconds = grub_cpu_to_be16 (t); + +- grub_memcpy (&pack->mac_addr, &ifaces[j].hwaddress.mac, 6); ++ grub_memcpy (&pack->mac_addr, &ifaces[j].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 329024b6f2c..bf36b446dc4 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -329,6 +329,9 @@ grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, + /* 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; +@@ -366,10 +369,11 @@ grub_efinet_find_snp_cards (int preferred_only, grub_efi_handle_t preferred, + *i = (*i)+1; + 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 3df75357a70..ba50415f5f6 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 8411e0ecca3..b2ca74b6eb1 100644 +--- a/grub-core/net/ip.c ++++ b/grub-core/net/ip.c +@@ -277,8 +277,8 @@ handle_dgram (struct grub_net_buff *nb, + && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV + && inf->dhcp_xid == bootp->xid + && 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->card); + grub_netbuff_free (nb); +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index fa3e2912643..9b8944292c7 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,21 @@ 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; ++ ++ 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; ++ } ++ for (ptr = str, i = 0; i < addr->len; i++) ++ { ++ ptr += grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str), ++ "%02x:", addr->mac[i] & 0xff); + } +- grub_printf (_("Unsupported hw address type %d\n"), addr->type); + } + + int +@@ -784,13 +784,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 de51894cbbf..e9ebc6a1b4f 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; + +@@ -555,11 +558,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/0343-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch b/0343-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch deleted file mode 100644 index a0f3859..0000000 --- a/0343-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch +++ /dev/null @@ -1,105 +0,0 @@ -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 (pjones - fixup) - -Various bug fixes related to previous patch. - -Signed-off-by: Peter Jones ---- - grub-core/net/http.c | 6 ++++-- - grub-core/net/net.c | 24 ++++++++++++------------ - 2 files changed, 16 insertions(+), 14 deletions(-) - -diff --git a/grub-core/net/http.c b/grub-core/net/http.c -index f182d7b871d..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) - { -@@ -405,7 +407,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) - data->filename, server, port ? port : HTTP_PORT); - data->sock = grub_net_tcp_open (server, - port ? port : HTTP_PORT, http_receive, -- http_err, http_err, -+ http_err, NULL, - file); - if (!data->sock) - { -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index 1f887d44b32..a0f4d00f0be 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -441,10 +441,11 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) - int word, quaddot = -1; - int bracketed = 0; - -- if (ptr[0] == '[') { -- bracketed = 1; -- ptr++; -- } -+ if (ptr[0] == '[') -+ { -+ bracketed = 1; -+ ptr++; -+ } - - if (ptr[0] == ':' && ptr[1] != ':') - return 0; -@@ -483,9 +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 == ']') { -+ if (bracketed && *ptr == ']') - ptr++; -- } - if (rest) - *rest = ptr; - return 1; -@@ -1389,7 +1389,7 @@ grub_net_open_real (const char *name) - char* port_start; - /* ipv6 or port specified? */ - if ((port_start = grub_strchr (server, ':'))) -- { -+ { - char* ipv6_begin; - if((ipv6_begin = grub_strchr (server, '['))) - { -@@ -1461,14 +1461,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; - } -@@ -1543,6 +1542,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/0344-bootp-New-net_bootp6-command.patch b/0344-bootp-New-net_bootp6-command.patch deleted file mode 100644 index 684f540..0000000 --- a/0344-bootp-New-net_bootp6-command.patch +++ /dev/null @@ -1,1357 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Sun, 10 Jul 2016 23:46:06 +0800 -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 ---- - grub-core/net/bootp.c | 1048 ++++++++++++++++++++++++++++++------ - 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, 994 insertions(+), 206 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 4e55adc557b..ff1d7776e7f 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; -+} - - static char * - grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), -@@ -345,178 +437,578 @@ grub_net_configure_by_dhcp_ack (const char *name, - return inter; - } - --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) -+/* 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; - -- *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) -+ 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) - { -- 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; -+ inf = grub_net_add_addr (name, card, dhcp6->ia_addr, &card->default_address, flags); - -- *device = grub_xasprintf ("%s,%s", scheme, tmp); -- grub_free (scheme); -- grub_free (host); -+ 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 (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; -- } -- } -+ if (ret_inf) -+ *ret_inf = inf; -+ } - -- i += len + 4; -- } -+ if (dhcp6->dns_server_addrs) -+ { -+ grub_uint16_t i; - -- grub_print_error (); -+ for (i = 0; i < dhcp6->num_dns_server; ++i) -+ grub_net_add_dns_server (dhcp6->dns_server_addrs + i); - } - -- if (is_def) -+ 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; - -- if (inter) -- grub_net_add_ipv6_local (inter, mask); -- return inter; -+ 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; -+ -+ 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); -+ return inf; -+} - - void - grub_net_process_dhcp (struct grub_net_buff *nb, -@@ -550,6 +1042,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) -@@ -824,7 +1387,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), - return err; - } - --static grub_command_t cmd_getdhcp, cmd_bootp; -+static grub_err_t -+grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)), -+ int argc, char **args) -+{ -+ struct grub_net_card *card; -+ grub_uint32_t iaid = 0; -+ int interval; -+ grub_err_t err; -+ grub_dhcp6_session_t se; -+ -+ err = GRUB_ERR_NONE; -+ -+ FOR_NET_CARDS (card) -+ { -+ struct grub_net_network_level_interface *iface; -+ -+ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) -+ continue; -+ -+ iface = grub_net_ipv6_get_link_local (card, &card->default_address); -+ if (!iface) -+ { -+ grub_dhcp6_session_remove_all (); -+ return grub_errno; -+ } -+ -+ grub_dhcp6_session_add (iface, iaid++); -+ } -+ -+ for (interval = 200; interval < 10000; interval *= 2) -+ { -+ 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); -+ } -+ -+ FOR_DHCP6_SESSIONS (se) -+ { -+ grub_error_push (); -+ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, -+ N_("couldn't autoconfigure %s"), -+ se->iface->card->name); -+ } -+ -+ grub_dhcp6_session_remove_all (); -+ -+ return err; -+} -+ -+static grub_command_t cmd_getdhcp, cmd_bootp, cmd_bootp6; - - void - grub_bootp_init (void) -@@ -835,6 +1565,9 @@ 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 -@@ -842,4 +1575,5 @@ grub_bootp_fini (void) - { - grub_unregister_command (cmd_getdhcp); - grub_unregister_command (cmd_bootp); -+ grub_unregister_command (cmd_bootp6); - } -diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c -index bf36b446dc4..da90f0f40ce 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -477,9 +477,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", -@@ -487,15 +484,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 b2ca74b6eb1..9a4e589aa39 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 ddc5ecfb03d..6a545cc6d5d 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -1511,7 +1511,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 f4cd86e582f..5f78b22e109 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -447,50 +447,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 -@@ -521,12 +536,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); -@@ -543,6 +558,10 @@ void - grub_net_process_dhcp (struct grub_net_buff *nb, - struct grub_net_card *card); - -+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/0344-misc-fix-invalid-character-recongition-in-strto-l.patch b/0344-misc-fix-invalid-character-recongition-in-strto-l.patch new file mode 100644 index 0000000..4006028 --- /dev/null +++ b/0344-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/0345-Put-back-our-code-to-add-a-local-route.patch b/0345-Put-back-our-code-to-add-a-local-route.patch deleted file mode 100644 index e8da589..0000000 --- a/0345-Put-back-our-code-to-add-a-local-route.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 21 Jun 2018 18:32:26 -0400 -Subject: [PATCH] Put back our code to add a local route. - -This was removed by the previous patch. - -Signed-off-by: Peter Jones ---- - grub-core/net/bootp.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index ff1d7776e7f..242cd1f4cbd 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -976,6 +976,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, - { - struct grub_net_network_level_interface *inf; - grub_dhcp6_options_t dhcp6; -+ int mask = -1; - - dhcp6 = grub_dhcp6_options_get (v6h, size); - if (!dhcp6) -@@ -1007,6 +1008,10 @@ grub_net_configure_by_dhcpv6_reply (const char *name, - } - - grub_dhcp6_options_free (dhcp6); -+ -+ if (inf) -+ grub_net_add_ipv6_local (inf, mask); -+ - return inf; - } - diff --git a/0345-net-read-bracketed-ipv6-addrs-and-port-numbers.patch b/0345-net-read-bracketed-ipv6-addrs-and-port-numbers.patch new file mode 100644 index 0000000..4f68187 --- /dev/null +++ b/0345-net-read-bracketed-ipv6-addrs-and-port-numbers.patch @@ -0,0 +1,229 @@ +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 +--- + grub-core/net/http.c | 21 +++++++++++--- + grub-core/net/net.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + grub-core/net/tftp.c | 8 ++++-- + include/grub/net.h | 1 + + 4 files changed, 101 insertions(+), 6 deletions(-) + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index 5aa4ad3befc..f182d7b871d 100644 +--- a/grub-core/net/http.c ++++ b/grub-core/net/http.c +@@ -312,12 +312,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 +358,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 +367,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,8 +401,10 @@ 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, ++ 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, http_err, + file); + if (!data->sock) +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 9b8944292c7..1f887d44b32 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -439,6 +439,12 @@ 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 +483,9 @@ 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; +@@ -1336,8 +1345,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) + { +@@ -1375,6 +1386,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) +diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c +index f90071353ad..e267af354f4 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 e9ebc6a1b4f..f4cd86e582f 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/0346-efinet-UEFI-IPv6-PXE-support.patch b/0346-efinet-UEFI-IPv6-PXE-support.patch deleted file mode 100644 index 9899553..0000000 --- a/0346-efinet-UEFI-IPv6-PXE-support.patch +++ /dev/null @@ -1,126 +0,0 @@ -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 da90f0f40ce..ac58e3e82cf 100644 ---- a/grub-core/net/drivers/efi/efinet.c -+++ b/grub-core/net/drivers/efi/efinet.c -@@ -493,6 +493,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 6a545cc6d5d..7dbd8807b80 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -1503,31 +1503,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; -@@ -1553,6 +1528,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; -@@ -1584,9 +1601,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/0346-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch b/0346-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch new file mode 100644 index 0000000..a0f3859 --- /dev/null +++ b/0346-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch @@ -0,0 +1,105 @@ +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 (pjones + fixup) + +Various bug fixes related to previous patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/http.c | 6 ++++-- + grub-core/net/net.c | 24 ++++++++++++------------ + 2 files changed, 16 insertions(+), 14 deletions(-) + +diff --git a/grub-core/net/http.c b/grub-core/net/http.c +index f182d7b871d..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) + { +@@ -405,7 +407,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial) + data->filename, server, port ? port : HTTP_PORT); + data->sock = grub_net_tcp_open (server, + port ? port : HTTP_PORT, http_receive, +- http_err, http_err, ++ http_err, NULL, + file); + if (!data->sock) + { +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index 1f887d44b32..a0f4d00f0be 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -441,10 +441,11 @@ parse_ip6 (const char *val, grub_uint64_t *ip, const char **rest) + int word, quaddot = -1; + int bracketed = 0; + +- if (ptr[0] == '[') { +- bracketed = 1; +- ptr++; +- } ++ if (ptr[0] == '[') ++ { ++ bracketed = 1; ++ ptr++; ++ } + + if (ptr[0] == ':' && ptr[1] != ':') + return 0; +@@ -483,9 +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 == ']') { ++ if (bracketed && *ptr == ']') + ptr++; +- } + if (rest) + *rest = ptr; + return 1; +@@ -1389,7 +1389,7 @@ grub_net_open_real (const char *name) + char* port_start; + /* ipv6 or port specified? */ + if ((port_start = grub_strchr (server, ':'))) +- { ++ { + char* ipv6_begin; + if((ipv6_begin = grub_strchr (server, '['))) + { +@@ -1461,14 +1461,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; + } +@@ -1543,6 +1542,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/0347-bootp-New-net_bootp6-command.patch b/0347-bootp-New-net_bootp6-command.patch new file mode 100644 index 0000000..684f540 --- /dev/null +++ b/0347-bootp-New-net_bootp6-command.patch @@ -0,0 +1,1357 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Sun, 10 Jul 2016 23:46:06 +0800 +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 +--- + grub-core/net/bootp.c | 1048 ++++++++++++++++++++++++++++++------ + 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, 994 insertions(+), 206 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 4e55adc557b..ff1d7776e7f 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; ++} + + static char * + grub_env_write_readonly (struct grub_env_var *var __attribute__ ((unused)), +@@ -345,178 +437,578 @@ grub_net_configure_by_dhcp_ack (const char *name, + return inter; + } + +-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) ++/* 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; + +- *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) ++ 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) + { +- 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; ++ inf = grub_net_add_addr (name, card, dhcp6->ia_addr, &card->default_address, flags); + +- *device = grub_xasprintf ("%s,%s", scheme, tmp); +- grub_free (scheme); +- grub_free (host); ++ 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 (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; +- } +- } ++ if (ret_inf) ++ *ret_inf = inf; ++ } + +- i += len + 4; +- } ++ if (dhcp6->dns_server_addrs) ++ { ++ grub_uint16_t i; + +- grub_print_error (); ++ for (i = 0; i < dhcp6->num_dns_server; ++i) ++ grub_net_add_dns_server (dhcp6->dns_server_addrs + i); + } + +- if (is_def) ++ 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; + +- if (inter) +- grub_net_add_ipv6_local (inter, mask); +- return inter; ++ 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; ++ ++ 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); ++ return inf; ++} + + void + grub_net_process_dhcp (struct grub_net_buff *nb, +@@ -550,6 +1042,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) +@@ -824,7 +1387,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), + return err; + } + +-static grub_command_t cmd_getdhcp, cmd_bootp; ++static grub_err_t ++grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ struct grub_net_card *card; ++ grub_uint32_t iaid = 0; ++ int interval; ++ grub_err_t err; ++ grub_dhcp6_session_t se; ++ ++ err = GRUB_ERR_NONE; ++ ++ FOR_NET_CARDS (card) ++ { ++ struct grub_net_network_level_interface *iface; ++ ++ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0) ++ continue; ++ ++ iface = grub_net_ipv6_get_link_local (card, &card->default_address); ++ if (!iface) ++ { ++ grub_dhcp6_session_remove_all (); ++ return grub_errno; ++ } ++ ++ grub_dhcp6_session_add (iface, iaid++); ++ } ++ ++ for (interval = 200; interval < 10000; interval *= 2) ++ { ++ 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); ++ } ++ ++ FOR_DHCP6_SESSIONS (se) ++ { ++ grub_error_push (); ++ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, ++ N_("couldn't autoconfigure %s"), ++ se->iface->card->name); ++ } ++ ++ grub_dhcp6_session_remove_all (); ++ ++ return err; ++} ++ ++static grub_command_t cmd_getdhcp, cmd_bootp, cmd_bootp6; + + void + grub_bootp_init (void) +@@ -835,6 +1565,9 @@ 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 +@@ -842,4 +1575,5 @@ grub_bootp_fini (void) + { + grub_unregister_command (cmd_getdhcp); + grub_unregister_command (cmd_bootp); ++ grub_unregister_command (cmd_bootp6); + } +diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c +index bf36b446dc4..da90f0f40ce 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -477,9 +477,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", +@@ -487,15 +484,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 b2ca74b6eb1..9a4e589aa39 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 ddc5ecfb03d..6a545cc6d5d 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -1511,7 +1511,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 f4cd86e582f..5f78b22e109 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -447,50 +447,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 +@@ -521,12 +536,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); +@@ -543,6 +558,10 @@ void + grub_net_process_dhcp (struct grub_net_buff *nb, + struct grub_net_card *card); + ++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/0347-grub.texi-Add-net_bootp6-doument.patch b/0347-grub.texi-Add-net_bootp6-doument.patch deleted file mode 100644 index b66a80c..0000000 --- a/0347-grub.texi-Add-net_bootp6-doument.patch +++ /dev/null @@ -1,48 +0,0 @@ -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 2b7b7faf847..c54bee31679 100644 ---- a/docs/grub.texi -+++ b/docs/grub.texi -@@ -5303,6 +5303,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 -@@ -5384,6 +5385,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/0348-Put-back-our-code-to-add-a-local-route.patch b/0348-Put-back-our-code-to-add-a-local-route.patch new file mode 100644 index 0000000..e8da589 --- /dev/null +++ b/0348-Put-back-our-code-to-add-a-local-route.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 21 Jun 2018 18:32:26 -0400 +Subject: [PATCH] Put back our code to add a local route. + +This was removed by the previous patch. + +Signed-off-by: Peter Jones +--- + grub-core/net/bootp.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index ff1d7776e7f..242cd1f4cbd 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -976,6 +976,7 @@ grub_net_configure_by_dhcpv6_reply (const char *name, + { + struct grub_net_network_level_interface *inf; + grub_dhcp6_options_t dhcp6; ++ int mask = -1; + + dhcp6 = grub_dhcp6_options_get (v6h, size); + if (!dhcp6) +@@ -1007,6 +1008,10 @@ grub_net_configure_by_dhcpv6_reply (const char *name, + } + + grub_dhcp6_options_free (dhcp6); ++ ++ if (inf) ++ grub_net_add_ipv6_local (inf, mask); ++ + return inf; + } + diff --git a/0348-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch b/0348-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch deleted file mode 100644 index 1874107..0000000 --- a/0348-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch +++ /dev/null @@ -1,135 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Thu, 14 Jul 2016 18:45:14 +0800 -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 | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- - include/grub/net.h | 1 + - 2 files changed, 67 insertions(+), 2 deletions(-) - -diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c -index 242cd1f4cbd..8b6fc9f2411 100644 ---- a/grub-core/net/bootp.c -+++ b/grub-core/net/bootp.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -254,6 +255,11 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) - taglength); - break; - -+ case GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER: -+ grub_env_set_net_property (name, "vendor_class_identifier", (const char *) ptr, -+ taglength); -+ break; -+ - case GRUB_NET_BOOTP_EXTENSIONS_PATH: - grub_env_set_net_property (name, "extensionspath", (const char *) ptr, - taglength); -@@ -357,6 +363,66 @@ grub_net_configure_by_dhcp_ack (const char *name, - } - #endif - -+ if (size > OFFSET_OF (vendor, bp)) -+ { -+ char *cidvar; -+ const char *cid; -+ -+ parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); -+ cidvar = grub_xasprintf ("net_%s_%s", name, "vendor_class_identifier"); -+ cid = grub_env_get (cidvar); -+ grub_free (cidvar); -+ -+ if (cid && grub_strcmp (cid, "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; -+ } -+ } -+ - if (size > OFFSET_OF (boot_file, bp)) - grub_env_set_net_property (name, "boot_file", bp->boot_file, - sizeof (bp->boot_file)); -@@ -421,8 +487,6 @@ grub_net_configure_by_dhcp_ack (const char *name, - **path = 0; - } - } -- if (size > OFFSET_OF (vendor, bp)) -- parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); - grub_net_add_ipv4_local (inter, mask); - - inter->dhcp_ack = grub_malloc (size); -diff --git a/include/grub/net.h b/include/grub/net.h -index 5f78b22e109..9cf6da68973 100644 ---- a/include/grub/net.h -+++ b/include/grub/net.h -@@ -522,6 +522,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_BOOTP_END = 0xff diff --git a/0349-efinet-Setting-network-from-UEFI-device-path.patch b/0349-efinet-Setting-network-from-UEFI-device-path.patch deleted file mode 100644 index 6f97886..0000000 --- a/0349-efinet-Setting-network-from-UEFI-device-path.patch +++ /dev/null @@ -1,405 +0,0 @@ -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 ac58e3e82cf..431b72916b6 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+"); - -@@ -412,6 +413,227 @@ grub_efinet_findcards (void) - } - } - -+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) -@@ -427,7 +649,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; -@@ -454,11 +680,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; -@@ -471,23 +707,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 (); -@@ -501,11 +751,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 7dbd8807b80..0b61f791850 100644 ---- a/include/grub/efi/api.h -+++ b/include/grub/efi/api.h -@@ -843,6 +843,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; - -@@ -897,6 +899,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/0349-efinet-UEFI-IPv6-PXE-support.patch b/0349-efinet-UEFI-IPv6-PXE-support.patch new file mode 100644 index 0000000..9899553 --- /dev/null +++ b/0349-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 da90f0f40ce..ac58e3e82cf 100644 +--- a/grub-core/net/drivers/efi/efinet.c ++++ b/grub-core/net/drivers/efi/efinet.c +@@ -493,6 +493,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 6a545cc6d5d..7dbd8807b80 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -1503,31 +1503,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; +@@ -1553,6 +1528,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; +@@ -1584,9 +1601,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/0350-efinet-Setting-DNS-server-from-UEFI-protocol.patch b/0350-efinet-Setting-DNS-server-from-UEFI-protocol.patch deleted file mode 100644 index 11f9f68..0000000 --- a/0350-efinet-Setting-DNS-server-from-UEFI-protocol.patch +++ /dev/null @@ -1,337 +0,0 @@ -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 431b72916b6..c25a68161b8 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, -@@ -413,6 +415,125 @@ grub_efinet_findcards (void) - } - } - -+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) - { -@@ -471,6 +592,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); -@@ -532,6 +655,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) -@@ -564,6 +706,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)); -@@ -627,6 +771,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 0b61f791850..80f6d79cfaf 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; -@@ -1842,6 +1852,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__) - diff --git a/0350-grub.texi-Add-net_bootp6-doument.patch b/0350-grub.texi-Add-net_bootp6-doument.patch new file mode 100644 index 0000000..b66a80c --- /dev/null +++ b/0350-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 2b7b7faf847..c54bee31679 100644 +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -5303,6 +5303,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 +@@ -5384,6 +5385,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/0351-Fix-one-more-coverity-complaint.patch b/0351-Fix-one-more-coverity-complaint.patch deleted file mode 100644 index ba00fbd..0000000 --- a/0351-Fix-one-more-coverity-complaint.patch +++ /dev/null @@ -1,27 +0,0 @@ -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 2c9b9e9312a..93aa0d8eda8 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->dir) (dev, dir, iterate_dir, NULL); diff --git a/0351-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch b/0351-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch new file mode 100644 index 0000000..1874107 --- /dev/null +++ b/0351-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch @@ -0,0 +1,135 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Michael Chang +Date: Thu, 14 Jul 2016 18:45:14 +0800 +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 | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- + include/grub/net.h | 1 + + 2 files changed, 67 insertions(+), 2 deletions(-) + +diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c +index 242cd1f4cbd..8b6fc9f2411 100644 +--- a/grub-core/net/bootp.c ++++ b/grub-core/net/bootp.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -254,6 +255,11 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask) + taglength); + break; + ++ case GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER: ++ grub_env_set_net_property (name, "vendor_class_identifier", (const char *) ptr, ++ taglength); ++ break; ++ + case GRUB_NET_BOOTP_EXTENSIONS_PATH: + grub_env_set_net_property (name, "extensionspath", (const char *) ptr, + taglength); +@@ -357,6 +363,66 @@ grub_net_configure_by_dhcp_ack (const char *name, + } + #endif + ++ if (size > OFFSET_OF (vendor, bp)) ++ { ++ char *cidvar; ++ const char *cid; ++ ++ parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); ++ cidvar = grub_xasprintf ("net_%s_%s", name, "vendor_class_identifier"); ++ cid = grub_env_get (cidvar); ++ grub_free (cidvar); ++ ++ if (cid && grub_strcmp (cid, "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; ++ } ++ } ++ + if (size > OFFSET_OF (boot_file, bp)) + grub_env_set_net_property (name, "boot_file", bp->boot_file, + sizeof (bp->boot_file)); +@@ -421,8 +487,6 @@ grub_net_configure_by_dhcp_ack (const char *name, + **path = 0; + } + } +- if (size > OFFSET_OF (vendor, bp)) +- parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask); + grub_net_add_ipv4_local (inter, mask); + + inter->dhcp_ack = grub_malloc (size); +diff --git a/include/grub/net.h b/include/grub/net.h +index 5f78b22e109..9cf6da68973 100644 +--- a/include/grub/net.h ++++ b/include/grub/net.h +@@ -522,6 +522,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_BOOTP_END = 0xff diff --git a/0352-Fix-grub_net_hwaddr_to_str.patch b/0352-Fix-grub_net_hwaddr_to_str.patch deleted file mode 100644 index 6c17a32..0000000 --- a/0352-Fix-grub_net_hwaddr_to_str.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Mark Salter -Date: Tue, 22 Aug 2017 12:21:12 -0400 -Subject: [PATCH] Fix grub_net_hwaddr_to_str - -commit 5c3b78c92f8 introduced support for larger network hw addresses. -However, grub_net_hwaddr_to_str() relies on GRUB_NET_MAX_STR_ADDRESS_SIZE -to prevent a spurious ':' at the end of the string. So now, if actual -hwaddr size is less than max, an extra ':' appears at the end of the -string. So calculate max string size based on actual hwaddr length to -fix the problem. - -Signed-off-by: Mark Salter ---- - grub-core/net/net.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/grub-core/net/net.c b/grub-core/net/net.c -index a0f4d00f0be..191e8e41bd6 100644 ---- a/grub-core/net/net.c -+++ b/grub-core/net/net.c -@@ -770,6 +770,7 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) - { - char *ptr; - unsigned i; -+ int maxstr; - - if (addr->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE) - { -@@ -778,9 +779,10 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) - addr->type, addr->len); - return; - } -+ maxstr = addr->len * grub_strlen ("XX:"); - for (ptr = str, i = 0; i < addr->len; i++) - { -- ptr += grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str), -+ ptr += grub_snprintf (ptr, maxstr - (ptr - str), - "%02x:", addr->mac[i] & 0xff); - } - } diff --git a/0352-efinet-Setting-network-from-UEFI-device-path.patch b/0352-efinet-Setting-network-from-UEFI-device-path.patch new file mode 100644 index 0000000..6f97886 --- /dev/null +++ b/0352-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 ac58e3e82cf..431b72916b6 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+"); + +@@ -412,6 +413,227 @@ grub_efinet_findcards (void) + } + } + ++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) +@@ -427,7 +649,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; +@@ -454,11 +680,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; +@@ -471,23 +707,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 (); +@@ -501,11 +751,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 7dbd8807b80..0b61f791850 100644 +--- a/include/grub/efi/api.h ++++ b/include/grub/efi/api.h +@@ -843,6 +843,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; + +@@ -897,6 +899,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/0353-Support-UEFI-networking-protocols.patch b/0353-Support-UEFI-networking-protocols.patch deleted file mode 100644 index 90bf7f1..0000000 --- a/0353-Support-UEFI-networking-protocols.patch +++ /dev/null @@ -1,5055 +0,0 @@ -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 ---- - grub-core/Makefile.core.def | 18 + - 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, 4626 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 334ca3fcf46..cdafd91c677 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -2192,6 +2192,18 @@ module = { - common = hook/datehook.c; - }; - -+module = { -+ name = efi_netfs; -+ common = net/efi/efi_netfs.c; -+ common = net/efi/net.c; -+ common = net/efi/http.c; -+ common = net/efi/pxe.c; -+ common = net/efi/ip4_config.c; -+ common = net/efi/ip6_config.c; -+ common = net/efi/dhcp.c; -+ enable = efi; -+}; -+ - module = { - name = net; - common = net/net.c; -@@ -2206,6 +2218,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 dbed6474431..6118bade50d 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 a2a732ffc0d..4d36fe31177 100644 ---- a/grub-core/kern/efi/efi.c -+++ b/grub-core/kern/efi/efi.c -@@ -696,7 +696,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], -@@ -709,33 +709,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: -@@ -775,6 +802,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 c25a68161b8..56305f46a3d 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+"); - -@@ -572,6 +573,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)) -@@ -844,6 +856,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); -@@ -858,6 +871,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; -@@ -929,6 +951,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; - } -@@ -940,5 +965,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..9e0078ac1c6 ---- /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", -+ .dir = grub_efi_netfs_dir, -+ .open = grub_efi_netfs_open, -+ .read = grub_efi_netfs_read, -+ .close = grub_efi_netfs_close, -+ .label = NULL, -+ .uuid = NULL, -+ .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 191e8e41bd6..a571ee92efa 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 82073d5cc94..ae31271bbc0 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; -@@ -154,6 +159,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); -@@ -190,7 +196,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 80f6d79cfaf..5f62a2d4292 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 - { -@@ -869,6 +886,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; - -@@ -918,6 +937,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. */ -@@ -1000,6 +1028,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; -@@ -1549,23 +1594,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 -@@ -1632,17 +1681,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; -@@ -1884,6 +1947,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, -@@ -1918,6 +2019,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__) - -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/0353-efinet-Setting-DNS-server-from-UEFI-protocol.patch b/0353-efinet-Setting-DNS-server-from-UEFI-protocol.patch new file mode 100644 index 0000000..11f9f68 --- /dev/null +++ b/0353-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 431b72916b6..c25a68161b8 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, +@@ -413,6 +415,125 @@ grub_efinet_findcards (void) + } + } + ++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) + { +@@ -471,6 +592,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); +@@ -532,6 +655,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) +@@ -564,6 +706,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)); +@@ -627,6 +771,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 0b61f791850..80f6d79cfaf 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; +@@ -1842,6 +1852,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__) + diff --git a/0354-AUDIT-0-http-boot-tracker-bug.patch b/0354-AUDIT-0-http-boot-tracker-bug.patch deleted file mode 100644 index 3d8d96b..0000000 --- a/0354-AUDIT-0-http-boot-tracker-bug.patch +++ /dev/null @@ -1,62 +0,0 @@ -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 9e0078ac1c6..2bf15447fd5 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/0354-Fix-one-more-coverity-complaint.patch b/0354-Fix-one-more-coverity-complaint.patch new file mode 100644 index 0000000..ba00fbd --- /dev/null +++ b/0354-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 2c9b9e9312a..93aa0d8eda8 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->dir) (dev, dir, iterate_dir, NULL); diff --git a/0355-Fix-grub_net_hwaddr_to_str.patch b/0355-Fix-grub_net_hwaddr_to_str.patch new file mode 100644 index 0000000..6c17a32 --- /dev/null +++ b/0355-Fix-grub_net_hwaddr_to_str.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Mark Salter +Date: Tue, 22 Aug 2017 12:21:12 -0400 +Subject: [PATCH] Fix grub_net_hwaddr_to_str + +commit 5c3b78c92f8 introduced support for larger network hw addresses. +However, grub_net_hwaddr_to_str() relies on GRUB_NET_MAX_STR_ADDRESS_SIZE +to prevent a spurious ':' at the end of the string. So now, if actual +hwaddr size is less than max, an extra ':' appears at the end of the +string. So calculate max string size based on actual hwaddr length to +fix the problem. + +Signed-off-by: Mark Salter +--- + grub-core/net/net.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/grub-core/net/net.c b/grub-core/net/net.c +index a0f4d00f0be..191e8e41bd6 100644 +--- a/grub-core/net/net.c ++++ b/grub-core/net/net.c +@@ -770,6 +770,7 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) + { + char *ptr; + unsigned i; ++ int maxstr; + + if (addr->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE) + { +@@ -778,9 +779,10 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str) + addr->type, addr->len); + return; + } ++ maxstr = addr->len * grub_strlen ("XX:"); + for (ptr = str, i = 0; i < addr->len; i++) + { +- ptr += grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str), ++ ptr += grub_snprintf (ptr, maxstr - (ptr - str), + "%02x:", addr->mac[i] & 0xff); + } + } diff --git a/0355-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch b/0355-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch deleted file mode 100644 index 33cde3b..0000000 --- a/0355-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch +++ /dev/null @@ -1,56 +0,0 @@ -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/0356-Support-UEFI-networking-protocols.patch b/0356-Support-UEFI-networking-protocols.patch new file mode 100644 index 0000000..90bf7f1 --- /dev/null +++ b/0356-Support-UEFI-networking-protocols.patch @@ -0,0 +1,5055 @@ +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 +--- + grub-core/Makefile.core.def | 18 + + 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, 4626 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 334ca3fcf46..cdafd91c677 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2192,6 +2192,18 @@ module = { + common = hook/datehook.c; + }; + ++module = { ++ name = efi_netfs; ++ common = net/efi/efi_netfs.c; ++ common = net/efi/net.c; ++ common = net/efi/http.c; ++ common = net/efi/pxe.c; ++ common = net/efi/ip4_config.c; ++ common = net/efi/ip6_config.c; ++ common = net/efi/dhcp.c; ++ enable = efi; ++}; ++ + module = { + name = net; + common = net/net.c; +@@ -2206,6 +2218,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 dbed6474431..6118bade50d 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 a2a732ffc0d..4d36fe31177 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -696,7 +696,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], +@@ -709,33 +709,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: +@@ -775,6 +802,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 c25a68161b8..56305f46a3d 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+"); + +@@ -572,6 +573,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)) +@@ -844,6 +856,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); +@@ -858,6 +871,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; +@@ -929,6 +951,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; + } +@@ -940,5 +965,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..9e0078ac1c6 +--- /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", ++ .dir = grub_efi_netfs_dir, ++ .open = grub_efi_netfs_open, ++ .read = grub_efi_netfs_read, ++ .close = grub_efi_netfs_close, ++ .label = NULL, ++ .uuid = NULL, ++ .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 191e8e41bd6..a571ee92efa 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 82073d5cc94..ae31271bbc0 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; +@@ -154,6 +159,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); +@@ -190,7 +196,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 80f6d79cfaf..5f62a2d4292 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 + { +@@ -869,6 +886,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; + +@@ -918,6 +937,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. */ +@@ -1000,6 +1028,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; +@@ -1549,23 +1594,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 +@@ -1632,17 +1681,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; +@@ -1884,6 +1947,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, +@@ -1918,6 +2019,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__) + +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/0356-efi-uga-use-64-bit-for-fb_base.patch b/0356-efi-uga-use-64-bit-for-fb_base.patch deleted file mode 100644 index bafcb64..0000000 --- a/0356-efi-uga-use-64-bit-for-fb_base.patch +++ /dev/null @@ -1,105 +0,0 @@ -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/0357-AUDIT-0-http-boot-tracker-bug.patch b/0357-AUDIT-0-http-boot-tracker-bug.patch new file mode 100644 index 0000000..3d8d96b --- /dev/null +++ b/0357-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 9e0078ac1c6..2bf15447fd5 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/0357-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch b/0357-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch deleted file mode 100644 index fd46dd6..0000000 --- a/0357-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch +++ /dev/null @@ -1,184 +0,0 @@ -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 02f64ea7441..6772feaa2f9 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; -@@ -220,14 +225,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; -@@ -242,7 +248,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; -@@ -250,12 +256,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; -@@ -268,7 +274,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; -@@ -288,6 +294,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) { -@@ -312,7 +324,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; -@@ -320,18 +332,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; - } - -@@ -345,7 +377,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, -@@ -361,14 +392,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/0358-EFI-console-Add-grub_console_read_key_stroke-helper-.patch b/0358-EFI-console-Add-grub_console_read_key_stroke-helper-.patch deleted file mode 100644 index 42f0405..0000000 --- a/0358-EFI-console-Add-grub_console_read_key_stroke-helper-.patch +++ /dev/null @@ -1,102 +0,0 @@ -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 6772feaa2f9..bc74b04a368 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -154,27 +154,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/0358-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch b/0358-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch new file mode 100644 index 0000000..33cde3b --- /dev/null +++ b/0358-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/0359-EFI-console-Implement-getkeystatus-support.patch b/0359-EFI-console-Implement-getkeystatus-support.patch deleted file mode 100644 index 26d657a..0000000 --- a/0359-EFI-console-Implement-getkeystatus-support.patch +++ /dev/null @@ -1,72 +0,0 @@ -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 bc74b04a368..a5abaf8e722 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -220,6 +220,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) - { -@@ -400,6 +433,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/0359-efi-uga-use-64-bit-for-fb_base.patch b/0359-efi-uga-use-64-bit-for-fb_base.patch new file mode 100644 index 0000000..bafcb64 --- /dev/null +++ b/0359-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/0360-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch b/0360-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch new file mode 100644 index 0000000..20aadf6 --- /dev/null +++ b/0360-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/0360-Make-grub_getkeystatus-helper-funtion-available-ever.patch b/0360-Make-grub_getkeystatus-helper-funtion-available-ever.patch deleted file mode 100644 index 9840a55..0000000 --- a/0360-Make-grub_getkeystatus-helper-funtion-available-ever.patch +++ /dev/null @@ -1,87 +0,0 @@ -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/0361-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch b/0361-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch deleted file mode 100644 index 2945fd6..0000000 --- a/0361-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch +++ /dev/null @@ -1,94 +0,0 @@ -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 5e2f5283d3d..6cb2a071490 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/0361-EFI-console-Add-grub_console_read_key_stroke-helper-.patch b/0361-EFI-console-Add-grub_console_read_key_stroke-helper-.patch new file mode 100644 index 0000000..6da36b2 --- /dev/null +++ b/0361-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/0362-EFI-console-Implement-getkeystatus-support.patch b/0362-EFI-console-Implement-getkeystatus-support.patch new file mode 100644 index 0000000..74fa253 --- /dev/null +++ b/0362-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/0362-grub-editenv-Add-incr-command-to-increment-integer-v.patch b/0362-grub-editenv-Add-incr-command-to-increment-integer-v.patch deleted file mode 100644 index d836274..0000000 --- a/0362-grub-editenv-Add-incr-command-to-increment-integer-v.patch +++ /dev/null @@ -1,93 +0,0 @@ -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 118e89fe57f..2918bb71cfe 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}, -@@ -246,6 +249,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[]) - { -@@ -285,6 +333,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/0363-Add-auto-hide-menu-support.patch b/0363-Add-auto-hide-menu-support.patch deleted file mode 100644 index 09e96b6..0000000 --- a/0363-Add-auto-hide-menu-support.patch +++ /dev/null @@ -1,191 +0,0 @@ -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/00_menu_auto_hide.in | 50 ++++++++++++++++++++++++++++++++++++++++ - util/grub.d/30_os-prober.in | 18 +++++++++++++++ - 3 files changed, 74 insertions(+) - create mode 100644 util/grub.d/00_menu_auto_hide.in - -diff --git a/Makefile.util.def b/Makefile.util.def -index f4fbd250630..4091d0a1078 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -442,6 +442,12 @@ script = { - installdir = grubconf; - }; - -+script = { -+ name = '00_menu_auto_hide'; -+ common = util/grub.d/00_menu_auto_hide.in; -+ installdir = grubconf; -+}; -+ - script = { - name = '01_users'; - common = util/grub.d/01_users.in; -diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in -new file mode 100644 -index 00000000000..a10fe45bb2c ---- /dev/null -+++ b/util/grub.d/00_menu_auto_hide.in -@@ -0,0 +1,50 @@ -+#! /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 -+ save_env boot_indeterminate -+# Avoid boot_indeterminate causing the menu to be hidden more then once -+elif [ "\${boot_indeterminate}" = "1" ]; then -+ set boot_indeterminate=2 -+ save_env boot_indeterminate -+fi -+set boot_success=0 -+save_env boot_success -+ -+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 -+ unset timeout -+ 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 d979de1982a..4aeca88f5b7 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="" -@@ -125,6 +126,7 @@ for OS in ${OSPROBED} ; do - - case ${BOOT} in - chain) -+ found_other_os=1 - - onstr="$(gettext_printf "(on %s)" "${DEVICE}")" - cat << EOF -@@ -155,6 +157,7 @@ EOF - EOF - ;; - efi) -+ found_other_os=1 - - EFIPATH=${DEVICE#*@} - DEVICE=${DEVICE%@*} -@@ -199,6 +202,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 -@@ -272,6 +276,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}")' { -@@ -298,6 +303,7 @@ EOF - EOF - ;; - minix) -+ found_other_os=1 - cat << EOF - menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" { - EOF -@@ -329,3 +335,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/0363-Make-grub_getkeystatus-helper-funtion-available-ever.patch b/0363-Make-grub_getkeystatus-helper-funtion-available-ever.patch new file mode 100644 index 0000000..9840a55 --- /dev/null +++ b/0363-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/0364-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch b/0364-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch new file mode 100644 index 0000000..2945fd6 --- /dev/null +++ b/0364-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 5e2f5283d3d..6cb2a071490 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/0364-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch b/0364-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch deleted file mode 100644 index 36e76d2..0000000 --- a/0364-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch +++ /dev/null @@ -1,93 +0,0 @@ -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+ - -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 4091d0a1078..57c51a27bc4 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -523,6 +523,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..3c9f533d8c6 ---- /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/vars -+EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c -+OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE/data" -+ -+if [ -e "$OsIndications" ] && \ -+ [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b1)") & 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/0365-Add-grub-set-bootflag-utility.patch b/0365-Add-grub-set-bootflag-utility.patch deleted file mode 100644 index 6b844f9..0000000 --- a/0365-Add-grub-set-bootflag-utility.patch +++ /dev/null @@ -1,316 +0,0 @@ -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 through pkexec, so -running as root if the polkit policy allows this. As such it is written -to not use any existing grubenv related code for easy auditing. - -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 polkit 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 -docs/org.gnu.grub.policy - -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. - -The org.gnu.grub.policy polkit file should be placed in -/usr/share/polkit-1/actions. - -Signed-off-by: Hans de Goede ---- - Makefile.util.def | 7 ++ - util/grub-set-bootflag.c | 158 +++++++++++++++++++++++++++++++++++++++++ - conf/Makefile.extra-dist | 3 + - docs/grub-boot-success.service | 6 ++ - docs/grub-boot-success.timer | 5 ++ - docs/org.gnu.grub.policy | 20 ++++++ - util/grub-set-bootflag.1 | 20 ++++++ - 7 files changed, 219 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 docs/org.gnu.grub.policy - create mode 100644 util/grub-set-bootflag.1 - -diff --git a/Makefile.util.def b/Makefile.util.def -index 57c51a27bc4..72be14449c5 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -1429,3 +1429,10 @@ program = { - ldadd = grub-core/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..f8dc310909a ---- /dev/null -+++ b/util/grub-set-bootflag.c -@@ -0,0 +1,158 @@ -+/* 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 -+ -+#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) -+ { -+ 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 39eb94bded6..5946ec24a65 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..c8c91c34d49 ---- /dev/null -+++ b/docs/grub-boot-success.service -@@ -0,0 +1,6 @@ -+[Unit] -+Description=Mark boot as successful -+ -+[Service] -+Type=oneshot -+ExecStart=/usr/bin/pkexec /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..221b532781b ---- /dev/null -+++ b/docs/grub-boot-success.timer -@@ -0,0 +1,5 @@ -+[Unit] -+Description=Mark boot as successful after the user session has run 2 minutes -+ -+[Timer] -+OnActiveSec=2min -diff --git a/docs/org.gnu.grub.policy b/docs/org.gnu.grub.policy -new file mode 100644 -index 00000000000..18391efc8e7 ---- /dev/null -+++ b/docs/org.gnu.grub.policy -@@ -0,0 +1,20 @@ -+ -+ -+ -+ GNU GRUB -+ https://www.gnu.org/software/grub/ -+ -+ -+ Set GRUB bootflags -+ Authentication is required to modify the bootloaders bootflags -+ -+ no -+ no -+ yes -+ -+ /usr/sbin/grub2-set-bootflag -+ -+ -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/0365-grub-editenv-Add-incr-command-to-increment-integer-v.patch b/0365-grub-editenv-Add-incr-command-to-increment-integer-v.patch new file mode 100644 index 0000000..d836274 --- /dev/null +++ b/0365-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 118e89fe57f..2918bb71cfe 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}, +@@ -246,6 +249,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[]) + { +@@ -285,6 +333,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/0366-Add-auto-hide-menu-support.patch b/0366-Add-auto-hide-menu-support.patch new file mode 100644 index 0000000..09e96b6 --- /dev/null +++ b/0366-Add-auto-hide-menu-support.patch @@ -0,0 +1,191 @@ +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/00_menu_auto_hide.in | 50 ++++++++++++++++++++++++++++++++++++++++ + util/grub.d/30_os-prober.in | 18 +++++++++++++++ + 3 files changed, 74 insertions(+) + create mode 100644 util/grub.d/00_menu_auto_hide.in + +diff --git a/Makefile.util.def b/Makefile.util.def +index f4fbd250630..4091d0a1078 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -442,6 +442,12 @@ script = { + installdir = grubconf; + }; + ++script = { ++ name = '00_menu_auto_hide'; ++ common = util/grub.d/00_menu_auto_hide.in; ++ installdir = grubconf; ++}; ++ + script = { + name = '01_users'; + common = util/grub.d/01_users.in; +diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in +new file mode 100644 +index 00000000000..a10fe45bb2c +--- /dev/null ++++ b/util/grub.d/00_menu_auto_hide.in +@@ -0,0 +1,50 @@ ++#! /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 ++ save_env boot_indeterminate ++# Avoid boot_indeterminate causing the menu to be hidden more then once ++elif [ "\${boot_indeterminate}" = "1" ]; then ++ set boot_indeterminate=2 ++ save_env boot_indeterminate ++fi ++set boot_success=0 ++save_env boot_success ++ ++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 ++ unset timeout ++ 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 d979de1982a..4aeca88f5b7 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="" +@@ -125,6 +126,7 @@ for OS in ${OSPROBED} ; do + + case ${BOOT} in + chain) ++ found_other_os=1 + + onstr="$(gettext_printf "(on %s)" "${DEVICE}")" + cat << EOF +@@ -155,6 +157,7 @@ EOF + EOF + ;; + efi) ++ found_other_os=1 + + EFIPATH=${DEVICE#*@} + DEVICE=${DEVICE%@*} +@@ -199,6 +202,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 +@@ -272,6 +276,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}")' { +@@ -298,6 +303,7 @@ EOF + EOF + ;; + minix) ++ found_other_os=1 + cat << EOF + menuentry "${LONGNAME} (on ${DEVICE}, Multiboot)" { + EOF +@@ -329,3 +335,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/0366-Fix-grub-setpassword-o-s-output-path.patch b/0366-Fix-grub-setpassword-o-s-output-path.patch deleted file mode 100644 index f26da57..0000000 --- a/0366-Fix-grub-setpassword-o-s-output-path.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Andy Lutomirski -Date: Sun, 11 Jun 2017 19:17:40 -0400 -Subject: [PATCH] Fix grub-setpassword -o's output path - -The output path is set up in the command line parsing, but completely ignored -in the code that actually writes the files. This patch fixes that. - -Signed-off-by: Peter Jones ---- - util/grub-setpassword.in | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in -index cf70257eed6..5ebf50576d6 100644 ---- a/util/grub-setpassword.in -+++ b/util/grub-setpassword.in -@@ -118,11 +118,11 @@ 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 "${grubdir}/user.cfg" 2>/dev/null || : --chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : --echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" -+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 ###$" "${grubdir}/grub.cfg"; then -+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/0367-Make-grub-set-password-be-named-like-all-the-other-g.patch b/0367-Make-grub-set-password-be-named-like-all-the-other-g.patch deleted file mode 100644 index 5068a23..0000000 --- a/0367-Make-grub-set-password-be-named-like-all-the-other-g.patch +++ /dev/null @@ -1,88 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Sat, 23 Jun 2018 13:19:15 -0400 -Subject: [PATCH] Make grub-set-password be named like all the other grub - utilities - -Signed-off-by: Peter Jones ---- - configure.ac | 2 +- - Makefile.util.def | 4 ++-- - .gitignore | 4 ++-- - util/{grub-setpassword.8 => grub-set-password.8} | 8 ++++---- - util/{grub-setpassword.in => grub-set-password.in} | 0 - 5 files changed, 9 insertions(+), 9 deletions(-) - rename util/{grub-setpassword.8 => grub-set-password.8} (50%) - rename util/{grub-setpassword.in => grub-set-password.in} (100%) - -diff --git a/configure.ac b/configure.ac -index 359cac3c26b..5f47a9265f3 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -66,7 +66,7 @@ grub_TRANSFORM([grub-mkrelpath]) - grub_TRANSFORM([grub-mkrescue]) - grub_TRANSFORM([grub-probe]) - grub_TRANSFORM([grub-reboot]) --grub_TRANSFORM([grub-setpassword]) -+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 72be14449c5..c81801cdacf 100644 ---- a/Makefile.util.def -+++ b/Makefile.util.def -@@ -750,8 +750,8 @@ script = { - }; - - script = { -- name = grub-setpassword; -- common = util/grub-setpassword.in; -+ name = grub-set-password; -+ common = util/grub-set-password.in; - mansection = 8; - installdir = sbin; - }; -diff --git a/.gitignore b/.gitignore -index 4a945596fea..5c09a474ba9 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -109,8 +109,8 @@ grub-*.tar.* - /grub*-script-check.1 - /grub*-set-default - /grub*-set-default.8 --/grub*-setsetpassword --/grub*-setsetpassword.8 -+/grub*-set-password -+/grub*-set-password.8 - /grub*-shell - /grub*-shell-tester - /grub*-sparc64-setup -diff --git a/util/grub-setpassword.8 b/util/grub-set-password.8 -similarity index 50% -rename from util/grub-setpassword.8 -rename to util/grub-set-password.8 -index dc91dd6697b..9646546e43d 100644 ---- a/util/grub-setpassword.8 -+++ b/util/grub-set-password.8 -@@ -1,12 +1,12 @@ --.TH GRUB-SETPASSWORD 3 "Thu Jun 25 2015" -+.TH GRUB-SET-PASSWORD 3 "Thu Jun 25 2015" - .SH NAME --\fBgrub-setpassword\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. -+\fBgrub-set-password\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. - - .SH SYNOPSIS --\fBgrub-setpassword\fR [OPTION] -+\fBgrub-set-password\fR [OPTION] - - .SH DESCRIPTION --\fBgrub-setpassword\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. -+\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>. -diff --git a/util/grub-setpassword.in b/util/grub-set-password.in -similarity index 100% -rename from util/grub-setpassword.in -rename to util/grub-set-password.in diff --git a/0367-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch b/0367-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch new file mode 100644 index 0000000..36e76d2 --- /dev/null +++ b/0367-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch @@ -0,0 +1,93 @@ +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+ + +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 4091d0a1078..57c51a27bc4 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -523,6 +523,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..3c9f533d8c6 +--- /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/vars ++EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c ++OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE/data" ++ ++if [ -e "$OsIndications" ] && \ ++ [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b1)") & 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/0368-Add-grub-set-bootflag-utility.patch b/0368-Add-grub-set-bootflag-utility.patch new file mode 100644 index 0000000..6b844f9 --- /dev/null +++ b/0368-Add-grub-set-bootflag-utility.patch @@ -0,0 +1,316 @@ +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 through pkexec, so +running as root if the polkit policy allows this. As such it is written +to not use any existing grubenv related code for easy auditing. + +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 polkit 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 +docs/org.gnu.grub.policy + +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. + +The org.gnu.grub.policy polkit file should be placed in +/usr/share/polkit-1/actions. + +Signed-off-by: Hans de Goede +--- + Makefile.util.def | 7 ++ + util/grub-set-bootflag.c | 158 +++++++++++++++++++++++++++++++++++++++++ + conf/Makefile.extra-dist | 3 + + docs/grub-boot-success.service | 6 ++ + docs/grub-boot-success.timer | 5 ++ + docs/org.gnu.grub.policy | 20 ++++++ + util/grub-set-bootflag.1 | 20 ++++++ + 7 files changed, 219 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 docs/org.gnu.grub.policy + create mode 100644 util/grub-set-bootflag.1 + +diff --git a/Makefile.util.def b/Makefile.util.def +index 57c51a27bc4..72be14449c5 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -1429,3 +1429,10 @@ program = { + ldadd = grub-core/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..f8dc310909a +--- /dev/null ++++ b/util/grub-set-bootflag.c +@@ -0,0 +1,158 @@ ++/* 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 ++ ++#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) ++ { ++ 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 39eb94bded6..5946ec24a65 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..c8c91c34d49 +--- /dev/null ++++ b/docs/grub-boot-success.service +@@ -0,0 +1,6 @@ ++[Unit] ++Description=Mark boot as successful ++ ++[Service] ++Type=oneshot ++ExecStart=/usr/bin/pkexec /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..221b532781b +--- /dev/null ++++ b/docs/grub-boot-success.timer +@@ -0,0 +1,5 @@ ++[Unit] ++Description=Mark boot as successful after the user session has run 2 minutes ++ ++[Timer] ++OnActiveSec=2min +diff --git a/docs/org.gnu.grub.policy b/docs/org.gnu.grub.policy +new file mode 100644 +index 00000000000..18391efc8e7 +--- /dev/null ++++ b/docs/org.gnu.grub.policy +@@ -0,0 +1,20 @@ ++ ++ ++ ++ GNU GRUB ++ https://www.gnu.org/software/grub/ ++ ++ ++ Set GRUB bootflags ++ Authentication is required to modify the bootloaders bootflags ++ ++ no ++ no ++ yes ++ ++ /usr/sbin/grub2-set-bootflag ++ ++ +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/0368-docs-Add-grub-boot-indeterminate.service-example.patch b/0368-docs-Add-grub-boot-indeterminate.service-example.patch deleted file mode 100644 index 44f6ad3..0000000 --- a/0368-docs-Add-grub-boot-indeterminate.service-example.patch +++ /dev/null @@ -1,33 +0,0 @@ -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/0369-EFI-console-Fix-the-enter-key-not-working-on-X86-tab.patch b/0369-EFI-console-Fix-the-enter-key-not-working-on-X86-tab.patch deleted file mode 100644 index d434d3c..0000000 --- a/0369-EFI-console-Fix-the-enter-key-not-working-on-X86-tab.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Tue, 26 Jun 2018 20:05:32 +0200 -Subject: [PATCH] EFI: console: Fix the "enter" key not working on X86 tablets - -Most 8" or 7" x86 Windows 10 tablets come with volume up/down buttons and -a power-button. In their UEFI these are almost always mapped to arrow -up/down and enter. - -Pressing the volume buttons (sometimes by accident) will stop the -menu countdown, but the power-button / "enter" key was not being recognized -as enter, so the user would be stuck at the grub menu. - -The problem is that these tablets send scan_code 13 or 0x0d for the -power-button, which officialy maps to the F3 key. They also set -unicode_char to 0x0d. - -This commit recognizes the special case of both scan_code and unicode_char -being set to 0x0d and treats this as an enter key press. - -This fixes things getting stuck at the grub-menu and allows the user -to choice a grub-menu entry using the buttons on the tablet. - -Signed-off-by: Hans de Goede ---- - grub-core/term/efi/console.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c -index a5abaf8e722..59786e30d66 100644 ---- a/grub-core/term/efi/console.c -+++ b/grub-core/term/efi/console.c -@@ -127,6 +127,9 @@ grub_efi_translate_key (grub_efi_input_key_t key) - else - return key.unicode_char; - } -+ /* Some devices send enter with scan_code 0x0d (F3) and unicode_char 0x0d */ -+ else if (key.scan_code == '\r' && key.unicode_char == '\r') -+ return key.unicode_char; - else if (key.scan_code < ARRAY_SIZE (efi_codes)) - return efi_codes[key.scan_code]; - diff --git a/0369-Fix-grub-setpassword-o-s-output-path.patch b/0369-Fix-grub-setpassword-o-s-output-path.patch new file mode 100644 index 0000000..f26da57 --- /dev/null +++ b/0369-Fix-grub-setpassword-o-s-output-path.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andy Lutomirski +Date: Sun, 11 Jun 2017 19:17:40 -0400 +Subject: [PATCH] Fix grub-setpassword -o's output path + +The output path is set up in the command line parsing, but completely ignored +in the code that actually writes the files. This patch fixes that. + +Signed-off-by: Peter Jones +--- + util/grub-setpassword.in | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/util/grub-setpassword.in b/util/grub-setpassword.in +index cf70257eed6..5ebf50576d6 100644 +--- a/util/grub-setpassword.in ++++ b/util/grub-setpassword.in +@@ -118,11 +118,11 @@ 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 "${grubdir}/user.cfg" 2>/dev/null || : +-chmod 0600 "${grubdir}/user.cfg" 2>/dev/null || : +-echo "GRUB2_PASSWORD=${MYPASS}" > "${grubdir}/user.cfg" ++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 ###$" "${grubdir}/grub.cfg"; then ++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/0370-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch b/0370-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch deleted file mode 100644 index 367fc6c..0000000 --- a/0370-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Tue, 26 Jun 2018 12:44:29 +0200 -Subject: [PATCH] 00_menu_auto_hide: Use a timeout of 60s for menu_show_once, - rather then no timeout - -On some UEFI systems with fastboot enabled (USB) keyboards don't work at -all, not even when explictly asking for keyboard input. - -So lets change the timeout from not set (no timeout) to 60 seconds, so -that on such systems if the menu was requested we continue with the -default choice after 60 seconds. - -Signed-off-by: Hans de Goede ---- - util/grub.d/00_menu_auto_hide.in | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in -index a10fe45bb2c..ca95c0d1c9f 100644 ---- a/util/grub.d/00_menu_auto_hide.in -+++ b/util/grub.d/00_menu_auto_hide.in -@@ -33,7 +33,7 @@ if [ x\$feature_timeout_style = xy ] ; then - unset menu_show_once - save_env menu_show_once - set timeout_style=menu -- unset timeout -+ set timeout=60 - elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then - set orig_timeout_style=\${timeout_style} - set orig_timeout=\${timeout} diff --git a/0370-Make-grub-set-password-be-named-like-all-the-other-g.patch b/0370-Make-grub-set-password-be-named-like-all-the-other-g.patch new file mode 100644 index 0000000..5068a23 --- /dev/null +++ b/0370-Make-grub-set-password-be-named-like-all-the-other-g.patch @@ -0,0 +1,88 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Sat, 23 Jun 2018 13:19:15 -0400 +Subject: [PATCH] Make grub-set-password be named like all the other grub + utilities + +Signed-off-by: Peter Jones +--- + configure.ac | 2 +- + Makefile.util.def | 4 ++-- + .gitignore | 4 ++-- + util/{grub-setpassword.8 => grub-set-password.8} | 8 ++++---- + util/{grub-setpassword.in => grub-set-password.in} | 0 + 5 files changed, 9 insertions(+), 9 deletions(-) + rename util/{grub-setpassword.8 => grub-set-password.8} (50%) + rename util/{grub-setpassword.in => grub-set-password.in} (100%) + +diff --git a/configure.ac b/configure.ac +index 359cac3c26b..5f47a9265f3 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -66,7 +66,7 @@ grub_TRANSFORM([grub-mkrelpath]) + grub_TRANSFORM([grub-mkrescue]) + grub_TRANSFORM([grub-probe]) + grub_TRANSFORM([grub-reboot]) +-grub_TRANSFORM([grub-setpassword]) ++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 72be14449c5..c81801cdacf 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -750,8 +750,8 @@ script = { + }; + + script = { +- name = grub-setpassword; +- common = util/grub-setpassword.in; ++ name = grub-set-password; ++ common = util/grub-set-password.in; + mansection = 8; + installdir = sbin; + }; +diff --git a/.gitignore b/.gitignore +index 4a945596fea..5c09a474ba9 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -109,8 +109,8 @@ grub-*.tar.* + /grub*-script-check.1 + /grub*-set-default + /grub*-set-default.8 +-/grub*-setsetpassword +-/grub*-setsetpassword.8 ++/grub*-set-password ++/grub*-set-password.8 + /grub*-shell + /grub*-shell-tester + /grub*-sparc64-setup +diff --git a/util/grub-setpassword.8 b/util/grub-set-password.8 +similarity index 50% +rename from util/grub-setpassword.8 +rename to util/grub-set-password.8 +index dc91dd6697b..9646546e43d 100644 +--- a/util/grub-setpassword.8 ++++ b/util/grub-set-password.8 +@@ -1,12 +1,12 @@ +-.TH GRUB-SETPASSWORD 3 "Thu Jun 25 2015" ++.TH GRUB-SET-PASSWORD 3 "Thu Jun 25 2015" + .SH NAME +-\fBgrub-setpassword\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. ++\fBgrub-set-password\fR \(em Generate the user.cfg file containing the hashed grub bootloader password. + + .SH SYNOPSIS +-\fBgrub-setpassword\fR [OPTION] ++\fBgrub-set-password\fR [OPTION] + + .SH DESCRIPTION +-\fBgrub-setpassword\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. ++\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>. +diff --git a/util/grub-setpassword.in b/util/grub-set-password.in +similarity index 100% +rename from util/grub-setpassword.in +rename to util/grub-set-password.in diff --git a/0371-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch b/0371-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch deleted file mode 100644 index 6993508..0000000 --- a/0371-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Wed, 27 Jun 2018 13:33:43 +0200 -Subject: [PATCH] 00_menu_auto_hide: Reduce number of save_env calls - -Normally boot_success will be 1 on every boot (as normally the -previous boot will have been successful). This means that we end -up in the code-path to set boot_indeterminate to 0 every boot. - -So we do 2 separate save_env calls each boot, one for boot_indeterminate -and one for boot_success. This results in 2 writes to the disk. - -This commit makes us save both boot_success and boot_indeterminate -in a single call, reducing the number of writes, this reducing wear -and tear on the underlying storage. - -Signed-off-by: Hans de Goede ---- - util/grub.d/00_menu_auto_hide.in | 4 +--- - 1 file changed, 1 insertion(+), 3 deletions(-) - -diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in -index ca95c0d1c9f..ad175870a54 100644 ---- a/util/grub.d/00_menu_auto_hide.in -+++ b/util/grub.d/00_menu_auto_hide.in -@@ -19,14 +19,12 @@ fi - # Reset boot_indeterminate after a successful boot - if [ "\${boot_success}" = "1" ] ; then - set boot_indeterminate=0 -- save_env boot_indeterminate - # Avoid boot_indeterminate causing the menu to be hidden more then once - elif [ "\${boot_indeterminate}" = "1" ]; then - set boot_indeterminate=2 -- save_env boot_indeterminate - fi - set boot_success=0 --save_env boot_success -+save_env boot_success boot_indeterminate - - if [ x\$feature_timeout_style = xy ] ; then - if [ "\${menu_show_once}" ]; then diff --git a/0371-docs-Add-grub-boot-indeterminate.service-example.patch b/0371-docs-Add-grub-boot-indeterminate.service-example.patch new file mode 100644 index 0000000..44f6ad3 --- /dev/null +++ b/0371-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/0372-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch b/0372-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch new file mode 100644 index 0000000..367fc6c --- /dev/null +++ b/0372-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Tue, 26 Jun 2018 12:44:29 +0200 +Subject: [PATCH] 00_menu_auto_hide: Use a timeout of 60s for menu_show_once, + rather then no timeout + +On some UEFI systems with fastboot enabled (USB) keyboards don't work at +all, not even when explictly asking for keyboard input. + +So lets change the timeout from not set (no timeout) to 60 seconds, so +that on such systems if the menu was requested we continue with the +default choice after 60 seconds. + +Signed-off-by: Hans de Goede +--- + util/grub.d/00_menu_auto_hide.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in +index a10fe45bb2c..ca95c0d1c9f 100644 +--- a/util/grub.d/00_menu_auto_hide.in ++++ b/util/grub.d/00_menu_auto_hide.in +@@ -33,7 +33,7 @@ if [ x\$feature_timeout_style = xy ] ; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu +- unset timeout ++ set timeout=60 + elif [ "\${menu_auto_hide}" -a "\${last_boot_ok}" = "1" ]; then + set orig_timeout_style=\${timeout_style} + set orig_timeout=\${timeout} diff --git a/0372-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch b/0372-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch deleted file mode 100644 index fa7f994..0000000 --- a/0372-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Tue, 26 Jun 2018 17:16:06 -0400 -Subject: [PATCH] Minor fixes to make armv7hl build as arm-efi - -- /remove/ the code to use use softfloat unconditionally on arm - (I can't get our arm bins to build with it for whatever reason...) -- Fix one type error -- build the secure boot loader code on arm - -Signed-off-by: Peter Jones ---- - configure.ac | 2 +- - grub-core/Makefile.core.def | 1 + - grub-core/loader/efi/linux.c | 2 +- - 3 files changed, 3 insertions(+), 2 deletions(-) - -diff --git a/configure.ac b/configure.ac -index 5f47a9265f3..b3af931e958 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -854,7 +854,7 @@ fi - # 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$target_cpu" != xarm ; 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 -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index cdafd91c677..a656930800e 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1714,6 +1714,7 @@ module = { - sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; - ia64_efi = loader/ia64/efi/linux.c; - arm = loader/arm/linux.c; -+ arm = loader/efi/linux.c; - arm64 = loader/arm64/linux.c; - arm64 = loader/efi/linux.c; - emu = loader/emu/linux.c; -diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c -index 7fe7201a388..8453b5c8017 100644 ---- a/grub-core/loader/efi/linux.c -+++ b/grub-core/loader/efi/linux.c -@@ -50,7 +50,7 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) - - grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); - status = shim_lock->verify (data, size); -- grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); -+ grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", (long int)status); - if (status == GRUB_EFI_SUCCESS) - { - grub_dprintf ("secureboot", "Kernel signature verification passed\n"); diff --git a/0373-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch b/0373-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch new file mode 100644 index 0000000..6993508 --- /dev/null +++ b/0373-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Wed, 27 Jun 2018 13:33:43 +0200 +Subject: [PATCH] 00_menu_auto_hide: Reduce number of save_env calls + +Normally boot_success will be 1 on every boot (as normally the +previous boot will have been successful). This means that we end +up in the code-path to set boot_indeterminate to 0 every boot. + +So we do 2 separate save_env calls each boot, one for boot_indeterminate +and one for boot_success. This results in 2 writes to the disk. + +This commit makes us save both boot_success and boot_indeterminate +in a single call, reducing the number of writes, this reducing wear +and tear on the underlying storage. + +Signed-off-by: Hans de Goede +--- + util/grub.d/00_menu_auto_hide.in | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/util/grub.d/00_menu_auto_hide.in b/util/grub.d/00_menu_auto_hide.in +index ca95c0d1c9f..ad175870a54 100644 +--- a/util/grub.d/00_menu_auto_hide.in ++++ b/util/grub.d/00_menu_auto_hide.in +@@ -19,14 +19,12 @@ fi + # Reset boot_indeterminate after a successful boot + if [ "\${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +- save_env boot_indeterminate + # Avoid boot_indeterminate causing the menu to be hidden more then once + elif [ "\${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 +- save_env boot_indeterminate + fi + set boot_success=0 +-save_env boot_success ++save_env boot_success boot_indeterminate + + if [ x\$feature_timeout_style = xy ] ; then + if [ "\${menu_show_once}" ]; then diff --git a/0373-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch b/0373-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch deleted file mode 100644 index e713d69..0000000 --- a/0373-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Hans de Goede -Date: Fri, 29 Jun 2018 10:08:22 +0200 -Subject: [PATCH] 30_uefi-firmware: fix use with /sys/firmware/efi/efivars - -Fix 30_uefi-firmware checking for the obsolete /sys/firmware/efi/vars -instead of for the new efivarfs mounted at /sys/firmware/efi/efivars. - -Which goes to show that I really should have tested this before blindly -importing it from Ubuntu. - -Signed-off-by: Hans de Goede ---- - util/grub.d/30_uefi-firmware.in | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in -index 3c9f533d8c6..93ececffea7 100644 ---- a/util/grub.d/30_uefi-firmware.in -+++ b/util/grub.d/30_uefi-firmware.in -@@ -26,12 +26,12 @@ export TEXTDOMAINDIR="@localedir@" - - . "@datadir@/@PACKAGE@/grub-mkconfig_lib" - --efi_vars_dir=/sys/firmware/efi/vars -+efi_vars_dir=/sys/firmware/efi/efivars - EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c --OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE/data" -+OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" - - if [ -e "$OsIndications" ] && \ -- [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b1)") & 1 ))" = 1 ]; then -+ [ "$(( $(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 diff --git a/0374-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch b/0374-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch new file mode 100644 index 0000000..fa7f994 --- /dev/null +++ b/0374-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 26 Jun 2018 17:16:06 -0400 +Subject: [PATCH] Minor fixes to make armv7hl build as arm-efi + +- /remove/ the code to use use softfloat unconditionally on arm + (I can't get our arm bins to build with it for whatever reason...) +- Fix one type error +- build the secure boot loader code on arm + +Signed-off-by: Peter Jones +--- + configure.ac | 2 +- + grub-core/Makefile.core.def | 1 + + grub-core/loader/efi/linux.c | 2 +- + 3 files changed, 3 insertions(+), 2 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 5f47a9265f3..b3af931e958 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -854,7 +854,7 @@ fi + # 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$target_cpu" != xarm ; 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 +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index cdafd91c677..a656930800e 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1714,6 +1714,7 @@ module = { + sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; + ia64_efi = loader/ia64/efi/linux.c; + arm = loader/arm/linux.c; ++ arm = loader/efi/linux.c; + arm64 = loader/arm64/linux.c; + arm64 = loader/efi/linux.c; + emu = loader/emu/linux.c; +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 7fe7201a388..8453b5c8017 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -50,7 +50,7 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size) + + grub_dprintf ("secureboot", "Asking shim to verify kernel signature\n"); + status = shim_lock->verify (data, size); +- grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", status); ++ grub_dprintf ("secureboot", "shim_lock->verify(): %ld\n", (long int)status); + if (status == GRUB_EFI_SUCCESS) + { + grub_dprintf ("secureboot", "Kernel signature verification passed\n"); diff --git a/0374-gentpl-add-disable-support.patch b/0374-gentpl-add-disable-support.patch deleted file mode 100644 index d82d633..0000000 --- a/0374-gentpl-add-disable-support.patch +++ /dev/null @@ -1,46 +0,0 @@ -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 bf8439fa743..a8cd540550f 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -589,11 +589,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) - -@@ -652,6 +662,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/0375-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch b/0375-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch new file mode 100644 index 0000000..e713d69 --- /dev/null +++ b/0375-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Fri, 29 Jun 2018 10:08:22 +0200 +Subject: [PATCH] 30_uefi-firmware: fix use with /sys/firmware/efi/efivars + +Fix 30_uefi-firmware checking for the obsolete /sys/firmware/efi/vars +instead of for the new efivarfs mounted at /sys/firmware/efi/efivars. + +Which goes to show that I really should have tested this before blindly +importing it from Ubuntu. + +Signed-off-by: Hans de Goede +--- + util/grub.d/30_uefi-firmware.in | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in +index 3c9f533d8c6..93ececffea7 100644 +--- a/util/grub.d/30_uefi-firmware.in ++++ b/util/grub.d/30_uefi-firmware.in +@@ -26,12 +26,12 @@ export TEXTDOMAINDIR="@localedir@" + + . "@datadir@/@PACKAGE@/grub-mkconfig_lib" + +-efi_vars_dir=/sys/firmware/efi/vars ++efi_vars_dir=/sys/firmware/efi/efivars + EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c +-OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE/data" ++OsIndications="$efi_vars_dir/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" + + if [ -e "$OsIndications" ] && \ +- [ "$(( $(printf 0x%x \'"$(cat $OsIndications | cut -b1)") & 1 ))" = 1 ]; then ++ [ "$(( $(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 diff --git a/0375-gentpl-add-pc-firmware-type.patch b/0375-gentpl-add-pc-firmware-type.patch deleted file mode 100644 index 94737b3..0000000 --- a/0375-gentpl-add-pc-firmware-type.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Jul 2018 13:43:34 -0400 -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 a8cd540550f..baac6a2af69 100644 ---- a/gentpl.py -+++ b/gentpl.py -@@ -49,6 +49,7 @@ GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ] - GROUPS["arm64"] = [ "arm64_efi" ] - - # Groups based on firmware -+GROUPS["pc"] = [ "i386_pc" ] - GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ] - GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] - GROUPS["uboot"] = [ "arm_uboot" ] diff --git a/0376-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch b/0376-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch deleted file mode 100644 index e8e5a03..0000000 --- a/0376-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Jul 2018 13:47:56 -0400 -Subject: [PATCH] Disable the reboot module on EFI builds; it is in kernel. - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 7 +++++-- - 1 file changed, 5 insertions(+), 2 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index a656930800e..3b022555c46 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -192,6 +192,7 @@ kernel = { - i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; - coreboot = video/coreboot/cbfb.c; - -+ efi = commands/reboot.c; - efi = disk/efi/efidisk.c; - efi = kern/efi/efi.c; - efi = kern/efi/init.c; -@@ -890,8 +891,8 @@ module = { - - module = { - name = reboot; -- i386 = lib/i386/reboot.c; -- i386 = lib/i386/reboot_trampoline.S; -+ i386_pc = lib/i386/reboot.c; -+ i386_pc = lib/i386/reboot_trampoline.S; - powerpc_ieee1275 = lib/ieee1275/reboot.c; - sparc64_ieee1275 = lib/ieee1275/reboot.c; - mips_arc = lib/mips/arc/reboot.c; -@@ -901,6 +902,8 @@ module = { - uboot = lib/uboot/reboot.c; - arm_coreboot = lib/dummy/reboot.c; - common = commands/reboot.c; -+ -+ disable = efi; - }; - - module = { diff --git a/0376-gentpl-add-disable-support.patch b/0376-gentpl-add-disable-support.patch new file mode 100644 index 0000000..d82d633 --- /dev/null +++ b/0376-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 bf8439fa743..a8cd540550f 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -589,11 +589,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) + +@@ -652,6 +662,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/0377-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch b/0377-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch deleted file mode 100644 index aed1e9b..0000000 --- a/0377-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Jul 2018 13:48:48 -0400 -Subject: [PATCH] Disable multiboot, multiboot2, and linux16 modules on EFI - builds. - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 3b022555c46..81509b86a0d 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1654,7 +1654,7 @@ module = { - module = { - name = linux16; - common = loader/i386/pc/linux.c; -- enable = x86; -+ enable = i386_pc; - }; - - module = { -@@ -1689,7 +1689,7 @@ module = { - - common = loader/multiboot.c; - common = loader/multiboot_mbi2.c; -- enable = x86; -+ enable = i386_pc; - enable = mips; - }; - -@@ -1698,7 +1698,7 @@ module = { - common = loader/multiboot.c; - x86 = loader/i386/multiboot_mbi.c; - extra_dist = loader/multiboot_elfxx.c; -- enable = x86; -+ enable = i386_pc; - }; - - module = { diff --git a/0377-gentpl-add-pc-firmware-type.patch b/0377-gentpl-add-pc-firmware-type.patch new file mode 100644 index 0000000..94737b3 --- /dev/null +++ b/0377-gentpl-add-pc-firmware-type.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:43:34 -0400 +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 a8cd540550f..baac6a2af69 100644 +--- a/gentpl.py ++++ b/gentpl.py +@@ -49,6 +49,7 @@ GROUPS["arm"] = [ "arm_uboot", "arm_efi", "arm_coreboot" ] + GROUPS["arm64"] = [ "arm64_efi" ] + + # Groups based on firmware ++GROUPS["pc"] = [ "i386_pc" ] + GROUPS["efi"] = [ "i386_efi", "x86_64_efi", "ia64_efi", "arm_efi", "arm64_efi" ] + GROUPS["ieee1275"] = [ "i386_ieee1275", "sparc64_ieee1275", "powerpc_ieee1275" ] + GROUPS["uboot"] = [ "arm_uboot" ] diff --git a/0378-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch b/0378-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch new file mode 100644 index 0000000..e8e5a03 --- /dev/null +++ b/0378-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:47:56 -0400 +Subject: [PATCH] Disable the reboot module on EFI builds; it is in kernel. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index a656930800e..3b022555c46 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -192,6 +192,7 @@ kernel = { + i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c; + coreboot = video/coreboot/cbfb.c; + ++ efi = commands/reboot.c; + efi = disk/efi/efidisk.c; + efi = kern/efi/efi.c; + efi = kern/efi/init.c; +@@ -890,8 +891,8 @@ module = { + + module = { + name = reboot; +- i386 = lib/i386/reboot.c; +- i386 = lib/i386/reboot_trampoline.S; ++ i386_pc = lib/i386/reboot.c; ++ i386_pc = lib/i386/reboot_trampoline.S; + powerpc_ieee1275 = lib/ieee1275/reboot.c; + sparc64_ieee1275 = lib/ieee1275/reboot.c; + mips_arc = lib/mips/arc/reboot.c; +@@ -901,6 +902,8 @@ module = { + uboot = lib/uboot/reboot.c; + arm_coreboot = lib/dummy/reboot.c; + common = commands/reboot.c; ++ ++ disable = efi; + }; + + module = { diff --git a/0378-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch b/0378-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch deleted file mode 100644 index 9bb4dd0..0000000 --- a/0378-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Jul 2018 13:49:17 -0400 -Subject: [PATCH] Make the linuxefi module just be the x86 efi version of linux - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 16 +++++----------- - 1 file changed, 5 insertions(+), 11 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 81509b86a0d..804c964431e 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1710,6 +1710,8 @@ module = { - module = { - name = linux; - x86 = loader/i386/linux.c; -+ x86_efi = loader/i386/efi/linux.c; -+ i386_efi = loader/i386/efi/linux.c; - xen = loader/i386/xen.c; - i386_pc = lib/i386/pc/vesa_modes_table.c; - mips = loader/mips/linux.c; -@@ -1717,13 +1719,14 @@ module = { - sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; - ia64_efi = loader/ia64/efi/linux.c; - arm = loader/arm/linux.c; -- arm = loader/efi/linux.c; - arm64 = loader/arm64/linux.c; -- arm64 = loader/efi/linux.c; - emu = loader/emu/linux.c; - fdt = lib/fdt.c; -+ - common = loader/linux.c; - common = lib/cmdline.c; -+ -+ efi = loader/efi/linux.c; - }; - - module = { -@@ -1784,15 +1787,6 @@ module = { - enable = x86_64_efi; - }; - --module = { -- name = linuxefi; -- efi = loader/i386/efi/linux.c; -- efi = lib/cmdline.c; -- efi = loader/efi/linux.c; -- enable = i386_efi; -- enable = x86_64_efi; --}; -- - module = { - name = chain; - efi = loader/efi/chainloader.c; diff --git a/0379-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch b/0379-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch new file mode 100644 index 0000000..aed1e9b --- /dev/null +++ b/0379-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:48:48 -0400 +Subject: [PATCH] Disable multiboot, multiboot2, and linux16 modules on EFI + builds. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 3b022555c46..81509b86a0d 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1654,7 +1654,7 @@ module = { + module = { + name = linux16; + common = loader/i386/pc/linux.c; +- enable = x86; ++ enable = i386_pc; + }; + + module = { +@@ -1689,7 +1689,7 @@ module = { + + common = loader/multiboot.c; + common = loader/multiboot_mbi2.c; +- enable = x86; ++ enable = i386_pc; + enable = mips; + }; + +@@ -1698,7 +1698,7 @@ module = { + common = loader/multiboot.c; + x86 = loader/i386/multiboot_mbi.c; + extra_dist = loader/multiboot_elfxx.c; +- enable = x86; ++ enable = i386_pc; + }; + + module = { diff --git a/0379-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch b/0379-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch deleted file mode 100644 index 0191f32..0000000 --- a/0379-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Wed, 11 Jul 2018 13:50:00 -0400 -Subject: [PATCH] Make efi_netfs not duplicate symbols from efinet - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 804c964431e..9039a6f73a3 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -2193,12 +2193,6 @@ module = { - module = { - name = efi_netfs; - common = net/efi/efi_netfs.c; -- common = net/efi/net.c; -- common = net/efi/http.c; -- common = net/efi/pxe.c; -- common = net/efi/ip4_config.c; -- common = net/efi/ip6_config.c; -- common = net/efi/dhcp.c; - enable = efi; - }; - diff --git a/0380-Don-t-build-the-fdt-command.patch b/0380-Don-t-build-the-fdt-command.patch deleted file mode 100644 index 70d677e..0000000 --- a/0380-Don-t-build-the-fdt-command.patch +++ /dev/null @@ -1,190 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 12 Jul 2018 11:00:45 -0400 -Subject: [PATCH] Don't build the fdt command - -Don't build the fdt command separately but *do* build it into the arm64 kernel. - -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 | 15 ++++++++++++--- - grub-core/kern/efi/fdt.c | 43 ------------------------------------------- - grub-core/loader/efi/fdt.c | 22 ++++++++++++++++++++++ - include/grub/efi/efi.h | 4 ---- - 4 files changed, 34 insertions(+), 50 deletions(-) - delete mode 100644 grub-core/kern/efi/fdt.c - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index 9039a6f73a3..ff6fa4bd000 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -242,10 +242,8 @@ kernel = { - - arm_efi = kern/arm/efi/init.c; - arm_efi = kern/arm/efi/misc.c; -- arm_efi = kern/efi/fdt.c; - - arm64_efi = kern/arm64/efi/init.c; -- arm64_efi = kern/efi/fdt.c; - - i386_pc = kern/i386/pc/init.c; - i386_pc = kern/i386/pc/mmap.c; -@@ -1701,11 +1699,17 @@ module = { - enable = i386_pc; - }; - -+/* - module = { - name = xen_boot; - arm64 = loader/arm64/xen_boot.c; -+ -+ fdt = lib/fdt.c; -+ fdt = loader/efi/fdt.c; -+ - enable = arm64; - }; -+*/ - - module = { - name = linux; -@@ -1721,7 +1725,9 @@ module = { - arm = loader/arm/linux.c; - arm64 = loader/arm64/linux.c; - emu = loader/emu/linux.c; -+ - fdt = lib/fdt.c; -+ fdt = loader/efi/fdt.c; - - common = loader/linux.c; - common = lib/cmdline.c; -@@ -1729,12 +1735,14 @@ module = { - efi = loader/efi/linux.c; - }; - -+/* - module = { - name = fdt; - arm64 = loader/efi/fdt.c; - common = lib/fdt.c; - enable = fdt; - }; -+*/ - - module = { - name = xnu; -@@ -1795,7 +1803,8 @@ module = { - i386_coreboot = lib/LzmaDec.c; - enable = i386_pc; - enable = i386_coreboot; -- enable = efi; -+ enable = i386_efi; -+ enable = x86_64_efi; - }; - - module = { -diff --git a/grub-core/kern/efi/fdt.c b/grub-core/kern/efi/fdt.c -deleted file mode 100644 -index 30100c61c14..00000000000 ---- a/grub-core/kern/efi/fdt.c -+++ /dev/null -@@ -1,43 +0,0 @@ --/* fdt.c - EFI Flattened Device Tree interaction */ --/* -- * GRUB -- GRand Unified Bootloader -- * Copyright (C) 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 . -- */ -- --#include --#include -- --void * --grub_efi_get_firmware_fdt (void) --{ -- grub_efi_configuration_table_t *tables; -- grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; -- void *firmware_fdt = NULL; -- unsigned int i; -- -- /* Look for FDT in UEFI config tables. */ -- tables = grub_efi_system_table->configuration_table; -- -- for (i = 0; i < grub_efi_system_table->num_table_entries; i++) -- if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) -- { -- firmware_fdt = tables[i].vendor_table; -- grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); -- break; -- } -- -- return firmware_fdt; --} -diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c -index a4c6e803645..55c09a19939 100644 ---- a/grub-core/loader/efi/fdt.c -+++ b/grub-core/loader/efi/fdt.c -@@ -35,6 +35,28 @@ static void *fdt; - sizeof (FDT_ADDR_CELLS_STRING) + \ - sizeof (FDT_SIZE_CELLS_STRING)) - -+static void * -+grub_efi_get_firmware_fdt (void) -+{ -+ grub_efi_configuration_table_t *tables; -+ grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; -+ void *firmware_fdt = NULL; -+ unsigned int i; -+ -+ /* Look for FDT in UEFI config tables. */ -+ tables = grub_efi_system_table->configuration_table; -+ -+ for (i = 0; i < grub_efi_system_table->num_table_entries; i++) -+ if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) -+ { -+ firmware_fdt = tables[i].vendor_table; -+ grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); -+ break; -+ } -+ -+ return firmware_fdt; -+} -+ - void * - grub_fdt_load (grub_size_t additional_size) - { -diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h -index 29b4dbac1e4..f54828aaeae 100644 ---- a/include/grub/efi/efi.h -+++ b/include/grub/efi/efi.h -@@ -123,10 +123,6 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, - char **device, - char **path); - --#if defined(__arm__) || defined(__aarch64__) --void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); --#endif -- - grub_addr_t grub_efi_section_addr (const char *section); - - void grub_efi_mm_init (void); diff --git a/0380-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch b/0380-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch new file mode 100644 index 0000000..9bb4dd0 --- /dev/null +++ b/0380-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch @@ -0,0 +1,56 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:49:17 -0400 +Subject: [PATCH] Make the linuxefi module just be the x86 efi version of linux + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 16 +++++----------- + 1 file changed, 5 insertions(+), 11 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 81509b86a0d..804c964431e 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1710,6 +1710,8 @@ module = { + module = { + name = linux; + x86 = loader/i386/linux.c; ++ x86_efi = loader/i386/efi/linux.c; ++ i386_efi = loader/i386/efi/linux.c; + xen = loader/i386/xen.c; + i386_pc = lib/i386/pc/vesa_modes_table.c; + mips = loader/mips/linux.c; +@@ -1717,13 +1719,14 @@ module = { + sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; + ia64_efi = loader/ia64/efi/linux.c; + arm = loader/arm/linux.c; +- arm = loader/efi/linux.c; + arm64 = loader/arm64/linux.c; +- arm64 = loader/efi/linux.c; + emu = loader/emu/linux.c; + fdt = lib/fdt.c; ++ + common = loader/linux.c; + common = lib/cmdline.c; ++ ++ efi = loader/efi/linux.c; + }; + + module = { +@@ -1784,15 +1787,6 @@ module = { + enable = x86_64_efi; + }; + +-module = { +- name = linuxefi; +- efi = loader/i386/efi/linux.c; +- efi = lib/cmdline.c; +- efi = loader/efi/linux.c; +- enable = i386_efi; +- enable = x86_64_efi; +-}; +- + module = { + name = chain; + efi = loader/efi/chainloader.c; diff --git a/0381-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch b/0381-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch new file mode 100644 index 0000000..0191f32 --- /dev/null +++ b/0381-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 11 Jul 2018 13:50:00 -0400 +Subject: [PATCH] Make efi_netfs not duplicate symbols from efinet + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 804c964431e..9039a6f73a3 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -2193,12 +2193,6 @@ module = { + module = { + name = efi_netfs; + common = net/efi/efi_netfs.c; +- common = net/efi/net.c; +- common = net/efi/http.c; +- common = net/efi/pxe.c; +- common = net/efi/ip4_config.c; +- common = net/efi/ip6_config.c; +- common = net/efi/dhcp.c; + enable = efi; + }; + diff --git a/0381-blscfg-remove-unused-typedef.patch b/0381-blscfg-remove-unused-typedef.patch deleted file mode 100644 index 33be789..0000000 --- a/0381-blscfg-remove-unused-typedef.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Wed, 11 Jul 2018 14:59:52 +0100 -Subject: [PATCH] blscfg: remove unused typedef -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -This is unused since ‘Use BLS fragment filename as menu entry id and for -criteria to sort’. - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 23d15adfadc..243fcda57f9 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -327,8 +327,6 @@ finish: - return ret; - } - --typedef int (*void_cmp_t)(void *, void *); -- - static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) - { - struct bls_entry * e0 = *(struct bls_entry **)p0; diff --git a/0382-Don-t-build-the-fdt-command.patch b/0382-Don-t-build-the-fdt-command.patch new file mode 100644 index 0000000..70d677e --- /dev/null +++ b/0382-Don-t-build-the-fdt-command.patch @@ -0,0 +1,190 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 12 Jul 2018 11:00:45 -0400 +Subject: [PATCH] Don't build the fdt command + +Don't build the fdt command separately but *do* build it into the arm64 kernel. + +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 | 15 ++++++++++++--- + grub-core/kern/efi/fdt.c | 43 ------------------------------------------- + grub-core/loader/efi/fdt.c | 22 ++++++++++++++++++++++ + include/grub/efi/efi.h | 4 ---- + 4 files changed, 34 insertions(+), 50 deletions(-) + delete mode 100644 grub-core/kern/efi/fdt.c + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 9039a6f73a3..ff6fa4bd000 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -242,10 +242,8 @@ kernel = { + + arm_efi = kern/arm/efi/init.c; + arm_efi = kern/arm/efi/misc.c; +- arm_efi = kern/efi/fdt.c; + + arm64_efi = kern/arm64/efi/init.c; +- arm64_efi = kern/efi/fdt.c; + + i386_pc = kern/i386/pc/init.c; + i386_pc = kern/i386/pc/mmap.c; +@@ -1701,11 +1699,17 @@ module = { + enable = i386_pc; + }; + ++/* + module = { + name = xen_boot; + arm64 = loader/arm64/xen_boot.c; ++ ++ fdt = lib/fdt.c; ++ fdt = loader/efi/fdt.c; ++ + enable = arm64; + }; ++*/ + + module = { + name = linux; +@@ -1721,7 +1725,9 @@ module = { + arm = loader/arm/linux.c; + arm64 = loader/arm64/linux.c; + emu = loader/emu/linux.c; ++ + fdt = lib/fdt.c; ++ fdt = loader/efi/fdt.c; + + common = loader/linux.c; + common = lib/cmdline.c; +@@ -1729,12 +1735,14 @@ module = { + efi = loader/efi/linux.c; + }; + ++/* + module = { + name = fdt; + arm64 = loader/efi/fdt.c; + common = lib/fdt.c; + enable = fdt; + }; ++*/ + + module = { + name = xnu; +@@ -1795,7 +1803,8 @@ module = { + i386_coreboot = lib/LzmaDec.c; + enable = i386_pc; + enable = i386_coreboot; +- enable = efi; ++ enable = i386_efi; ++ enable = x86_64_efi; + }; + + module = { +diff --git a/grub-core/kern/efi/fdt.c b/grub-core/kern/efi/fdt.c +deleted file mode 100644 +index 30100c61c14..00000000000 +--- a/grub-core/kern/efi/fdt.c ++++ /dev/null +@@ -1,43 +0,0 @@ +-/* fdt.c - EFI Flattened Device Tree interaction */ +-/* +- * GRUB -- GRand Unified Bootloader +- * Copyright (C) 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 . +- */ +- +-#include +-#include +- +-void * +-grub_efi_get_firmware_fdt (void) +-{ +- grub_efi_configuration_table_t *tables; +- grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; +- void *firmware_fdt = NULL; +- unsigned int i; +- +- /* Look for FDT in UEFI config tables. */ +- tables = grub_efi_system_table->configuration_table; +- +- for (i = 0; i < grub_efi_system_table->num_table_entries; i++) +- if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) +- { +- firmware_fdt = tables[i].vendor_table; +- grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); +- break; +- } +- +- return firmware_fdt; +-} +diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c +index a4c6e803645..55c09a19939 100644 +--- a/grub-core/loader/efi/fdt.c ++++ b/grub-core/loader/efi/fdt.c +@@ -35,6 +35,28 @@ static void *fdt; + sizeof (FDT_ADDR_CELLS_STRING) + \ + sizeof (FDT_SIZE_CELLS_STRING)) + ++static void * ++grub_efi_get_firmware_fdt (void) ++{ ++ grub_efi_configuration_table_t *tables; ++ grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; ++ void *firmware_fdt = NULL; ++ unsigned int i; ++ ++ /* Look for FDT in UEFI config tables. */ ++ tables = grub_efi_system_table->configuration_table; ++ ++ for (i = 0; i < grub_efi_system_table->num_table_entries; i++) ++ if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0) ++ { ++ firmware_fdt = tables[i].vendor_table; ++ grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt); ++ break; ++ } ++ ++ return firmware_fdt; ++} ++ + void * + grub_fdt_load (grub_size_t additional_size) + { +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 29b4dbac1e4..f54828aaeae 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -123,10 +123,6 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, + char **device, + char **path); + +-#if defined(__arm__) || defined(__aarch64__) +-void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); +-#endif +- + grub_addr_t grub_efi_section_addr (const char *section); + + void grub_efi_mm_init (void); diff --git a/0382-blscfg-don-t-dynamically-allocate-default_blsdir.patch b/0382-blscfg-don-t-dynamically-allocate-default_blsdir.patch deleted file mode 100644 index cb0d7ea..0000000 --- a/0382-blscfg-don-t-dynamically-allocate-default_blsdir.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Wed, 11 Jul 2018 15:01:45 +0100 -Subject: [PATCH] blscfg: don't dynamically allocate default_blsdir - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 9 +++------ - 1 file changed, 3 insertions(+), 6 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 243fcda57f9..1d0e6ceaf7d 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -623,7 +623,7 @@ static int find_entry (const char *filename, - grub_file_t f = NULL; - char *grubenv_path = NULL; - grub_envblk_t env = NULL; -- char *default_blsdir = NULL; -+ const char *default_blsdir = NULL; - grub_fs_t blsdir_fs = NULL; - grub_device_t blsdir_dev = NULL; - const char *blsdir = NULL; -@@ -643,10 +643,9 @@ static int find_entry (const char *filename, - - // set a default blsdir - if (info->platform == PLATFORM_EMU) -- default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, -- GRUB_BLS_CONFIG_PATH); -+ default_blsdir = GRUB_BOOT_DEVICE GRUB_BLS_CONFIG_PATH; - else -- default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); -+ default_blsdir = GRUB_BLS_CONFIG_PATH; - - grub_env_set ("blsdir", default_blsdir); - grub_dprintf ("blscfg", "default_blsdir: \"%s\"\n", default_blsdir); -@@ -788,8 +787,6 @@ finish: - if (f) - grub_file_close (f); - -- grub_free (default_blsdir); -- - return 0; - } - diff --git a/0383-blscfg-remove-unused-typedef.patch b/0383-blscfg-remove-unused-typedef.patch new file mode 100644 index 0000000..33be789 --- /dev/null +++ b/0383-blscfg-remove-unused-typedef.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Wed, 11 Jul 2018 14:59:52 +0100 +Subject: [PATCH] blscfg: remove unused typedef +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This is unused since ‘Use BLS fragment filename as menu entry id and for +criteria to sort’. + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 23d15adfadc..243fcda57f9 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -327,8 +327,6 @@ finish: + return ret; + } + +-typedef int (*void_cmp_t)(void *, void *); +- + static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) + { + struct bls_entry * e0 = *(struct bls_entry **)p0; diff --git a/0383-blscfg-sort-BLS-entries-by-version-field.patch b/0383-blscfg-sort-BLS-entries-by-version-field.patch deleted file mode 100644 index 0ad0611..0000000 --- a/0383-blscfg-sort-BLS-entries-by-version-field.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Wed, 11 Jul 2018 15:41:09 +0100 -Subject: [PATCH] blscfg: sort BLS entries by 'version' field -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -This partially reverts ‘Use BLS fragment filename as menu entry id and -for criteria to sort’. Sorting by filename only gives the correct order -if the BLS entries are generated by a version of ostree after this patch -https://github.com/ostreedev/ostree/commit/9f48e212a3bf9ed418fb3216e4f834d581bc520e -to use the version (higher is newer) in the filename. Older ostrees, -including all releases at the time of writing, use the index (lower is -newer) in the filename, so sorting by filename produces the reverse -order. - -Sorting by 'version' field matches libostree's own -compare_boot_loader_configs(), so I think it's more correct than relying -on the filename, particularly since we've already gone to the trouble of -parsing all the fields in the file. - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 1d0e6ceaf7d..84714f0e534 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -327,10 +327,26 @@ finish: - return ret; - } - -+/* return 1: p0 is newer than p1 */ -+/* 0: p0 and p1 are the same version */ -+/* -1: p1 is newer than p0 */ - static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) - { - struct bls_entry * e0 = *(struct bls_entry **)p0; - struct bls_entry * e1 = *(struct bls_entry **)p1; -+ const char *v0, *v1; -+ int r; -+ -+ v0 = bls_get_val(e0, "version", NULL); -+ v1 = bls_get_val(e1, "version", NULL); -+ -+ if (v0 && !v1) -+ return -1; -+ if (!v0 && v1) -+ return 1; -+ -+ if ((r = vercmp(v0, v1)) != 0) -+ return r; - - return vercmp(e0->filename, e1->filename); - } diff --git a/0384-blscfg-don-t-dynamically-allocate-default_blsdir.patch b/0384-blscfg-don-t-dynamically-allocate-default_blsdir.patch new file mode 100644 index 0000000..cb0d7ea --- /dev/null +++ b/0384-blscfg-don-t-dynamically-allocate-default_blsdir.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Wed, 11 Jul 2018 15:01:45 +0100 +Subject: [PATCH] blscfg: don't dynamically allocate default_blsdir + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 9 +++------ + 1 file changed, 3 insertions(+), 6 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 243fcda57f9..1d0e6ceaf7d 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -623,7 +623,7 @@ static int find_entry (const char *filename, + grub_file_t f = NULL; + char *grubenv_path = NULL; + grub_envblk_t env = NULL; +- char *default_blsdir = NULL; ++ const char *default_blsdir = NULL; + grub_fs_t blsdir_fs = NULL; + grub_device_t blsdir_dev = NULL; + const char *blsdir = NULL; +@@ -643,10 +643,9 @@ static int find_entry (const char *filename, + + // set a default blsdir + if (info->platform == PLATFORM_EMU) +- default_blsdir = grub_xasprintf ("%s%s", GRUB_BOOT_DEVICE, +- GRUB_BLS_CONFIG_PATH); ++ default_blsdir = GRUB_BOOT_DEVICE GRUB_BLS_CONFIG_PATH; + else +- default_blsdir = grub_xasprintf ("%s", GRUB_BLS_CONFIG_PATH); ++ default_blsdir = GRUB_BLS_CONFIG_PATH; + + grub_env_set ("blsdir", default_blsdir); + grub_dprintf ("blscfg", "default_blsdir: \"%s\"\n", default_blsdir); +@@ -788,8 +787,6 @@ finish: + if (f) + grub_file_close (f); + +- grub_free (default_blsdir); +- + return 0; + } + diff --git a/0384-blscfg-remove-NULL-guards-around-grub_free.patch b/0384-blscfg-remove-NULL-guards-around-grub_free.patch deleted file mode 100644 index 2624b8a..0000000 --- a/0384-blscfg-remove-NULL-guards-around-grub_free.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Thu, 12 Jul 2018 10:14:43 +0100 -Subject: [PATCH] blscfg: remove NULL guards around grub_free() - -The internal implementation of grub_free() is NULL-safe. In emu builds, -it just delegates to the host's free(), which is specified by ANSI C to -be NULL-safe. - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 23 ++++++----------------- - 1 file changed, 6 insertions(+), 17 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 84714f0e534..f9a5b2d5afa 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -600,23 +600,12 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); - - finish: -- if (initrd) -- grub_free (initrd); -- -- if (initrds) -- grub_free (initrds); -- -- if (classes) -- grub_free (classes); -- -- if (args) -- grub_free (args); -- -- if (argv) -- grub_free (argv); -- -- if (src) -- grub_free (src); -+ grub_free (initrd); -+ grub_free (initrds); -+ grub_free (classes); -+ grub_free (args); -+ grub_free (argv); -+ grub_free (src); - } - - struct find_entry_info { diff --git a/0385-blscfg-fix-filename-in-no-linux-key-error.patch b/0385-blscfg-fix-filename-in-no-linux-key-error.patch deleted file mode 100644 index d9b17f3..0000000 --- a/0385-blscfg-fix-filename-in-no-linux-key-error.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Thu, 12 Jul 2018 10:38:27 +0100 -Subject: [PATCH] blscfg: fix filename in "no 'linux' key" error - -In find_entry(), 'filename' is either NULL or a directory in the ESP. -But previously it was passed to create_entry(), which uses it in an -error message as if it's the filename of the BLS entry in question. - -Since bls_entry now has a 'filename' field, just use that. - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index f9a5b2d5afa..077ca5dfbe6 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -514,7 +514,7 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) - return list; - } - --static void create_entry (struct bls_entry *entry, const char *cfgfile) -+static void create_entry (struct bls_entry *entry) - { - int argc = 0; - const char **argv = NULL; -@@ -539,7 +539,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) - clinux = bls_get_val (entry, "linux", NULL); - if (!clinux) - { -- grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", cfgfile); -+ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", entry->filename); - goto finish; - } - -@@ -753,7 +753,7 @@ static int find_entry (const char *filename, - - grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries); - for (r = nentries - 1; r >= 0; r--) -- create_entry(entries[r], filename); -+ create_entry(entries[r]); - - for (r = 0; r < nentries; r++) - bls_free_entry (entries[r]); diff --git a/0385-blscfg-sort-BLS-entries-by-version-field.patch b/0385-blscfg-sort-BLS-entries-by-version-field.patch new file mode 100644 index 0000000..0ad0611 --- /dev/null +++ b/0385-blscfg-sort-BLS-entries-by-version-field.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Wed, 11 Jul 2018 15:41:09 +0100 +Subject: [PATCH] blscfg: sort BLS entries by 'version' field +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This partially reverts ‘Use BLS fragment filename as menu entry id and +for criteria to sort’. Sorting by filename only gives the correct order +if the BLS entries are generated by a version of ostree after this patch +https://github.com/ostreedev/ostree/commit/9f48e212a3bf9ed418fb3216e4f834d581bc520e +to use the version (higher is newer) in the filename. Older ostrees, +including all releases at the time of writing, use the index (lower is +newer) in the filename, so sorting by filename produces the reverse +order. + +Sorting by 'version' field matches libostree's own +compare_boot_loader_configs(), so I think it's more correct than relying +on the filename, particularly since we've already gone to the trouble of +parsing all the fields in the file. + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 1d0e6ceaf7d..84714f0e534 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -327,10 +327,26 @@ finish: + return ret; + } + ++/* return 1: p0 is newer than p1 */ ++/* 0: p0 and p1 are the same version */ ++/* -1: p1 is newer than p0 */ + static int bls_cmp(const void *p0, const void *p1, void *state UNUSED) + { + struct bls_entry * e0 = *(struct bls_entry **)p0; + struct bls_entry * e1 = *(struct bls_entry **)p1; ++ const char *v0, *v1; ++ int r; ++ ++ v0 = bls_get_val(e0, "version", NULL); ++ v1 = bls_get_val(e1, "version", NULL); ++ ++ if (v0 && !v1) ++ return -1; ++ if (!v0 && v1) ++ return 1; ++ ++ if ((r = vercmp(v0, v1)) != 0) ++ return r; + + return vercmp(e0->filename, e1->filename); + } diff --git a/0386-blscfg-don-t-leak-bls_entry.filename.patch b/0386-blscfg-don-t-leak-bls_entry.filename.patch deleted file mode 100644 index 248663b..0000000 --- a/0386-blscfg-don-t-leak-bls_entry.filename.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Thu, 12 Jul 2018 10:59:10 +0100 -Subject: [PATCH] blscfg: don't leak bls_entry.filename - -Zeroing the bls_entry struct before calling grub_free() on one of its -fields is not going to work too well. - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 077ca5dfbe6..3339d62d541 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -166,8 +166,8 @@ static void bls_free_entry(struct bls_entry *entry) - } - - grub_free (entry->keyvals); -- grub_memset (entry, 0, sizeof (*entry)); - grub_free (entry->filename); -+ grub_memset (entry, 0, sizeof (*entry)); - grub_free (entry); - } - diff --git a/0386-blscfg-remove-NULL-guards-around-grub_free.patch b/0386-blscfg-remove-NULL-guards-around-grub_free.patch new file mode 100644 index 0000000..2624b8a --- /dev/null +++ b/0386-blscfg-remove-NULL-guards-around-grub_free.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 12 Jul 2018 10:14:43 +0100 +Subject: [PATCH] blscfg: remove NULL guards around grub_free() + +The internal implementation of grub_free() is NULL-safe. In emu builds, +it just delegates to the host's free(), which is specified by ANSI C to +be NULL-safe. + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 23 ++++++----------------- + 1 file changed, 6 insertions(+), 17 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 84714f0e534..f9a5b2d5afa 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -600,23 +600,12 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0); + + finish: +- if (initrd) +- grub_free (initrd); +- +- if (initrds) +- grub_free (initrds); +- +- if (classes) +- grub_free (classes); +- +- if (args) +- grub_free (args); +- +- if (argv) +- grub_free (argv); +- +- if (src) +- grub_free (src); ++ grub_free (initrd); ++ grub_free (initrds); ++ grub_free (classes); ++ grub_free (args); ++ grub_free (argv); ++ grub_free (src); + } + + struct find_entry_info { diff --git a/0387-blscfg-fix-compilation-on-EFI-and-EMU.patch b/0387-blscfg-fix-compilation-on-EFI-and-EMU.patch deleted file mode 100644 index d5d82d0..0000000 --- a/0387-blscfg-fix-compilation-on-EFI-and-EMU.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Will Thompson -Date: Thu, 12 Jul 2018 19:00:42 +0100 -Subject: [PATCH] blscfg: fix compilation on !EFI and !EMU -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Neither GRUB_MACHINE_EFI nor GRUB_MACHINE_EMU are defined when compiling -for (eg) i386-pc. In this case, #elif GRUB_MACHINE_EMU is an error: - - commands/blscfg.c: In function ‘grub_cmd_blscfg’: - commands/blscfg.c:835:7: error: "GRUB_MACHINE_EMU" is not defined [-Werror=undef] - #elif GRUB_MACHINE_EMU - ^~~~~~~~~~~~~~~~ - -Signed-off-by: Will Thompson ---- - grub-core/commands/blscfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c -index 3339d62d541..f4283708e21 100644 ---- a/grub-core/commands/blscfg.c -+++ b/grub-core/commands/blscfg.c -@@ -843,7 +843,7 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, - info.platform = PLATFORM_EFI; - grub_dprintf ("blscfg", "scanning /EFI/\n"); - r = fs->dir (dev, "/EFI/", find_entry, &info); --#elif GRUB_MACHINE_EMU -+#elif defined(GRUB_MACHINE_EMU) - info.platform = PLATFORM_EMU; - grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, - GRUB_BLS_CONFIG_PATH); diff --git a/0387-blscfg-fix-filename-in-no-linux-key-error.patch b/0387-blscfg-fix-filename-in-no-linux-key-error.patch new file mode 100644 index 0000000..d9b17f3 --- /dev/null +++ b/0387-blscfg-fix-filename-in-no-linux-key-error.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 12 Jul 2018 10:38:27 +0100 +Subject: [PATCH] blscfg: fix filename in "no 'linux' key" error + +In find_entry(), 'filename' is either NULL or a directory in the ESP. +But previously it was passed to create_entry(), which uses it in an +error message as if it's the filename of the BLS entry in question. + +Since bls_entry now has a 'filename' field, just use that. + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index f9a5b2d5afa..077ca5dfbe6 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -514,7 +514,7 @@ static char **bls_make_list (struct bls_entry *entry, const char *key, int *num) + return list; + } + +-static void create_entry (struct bls_entry *entry, const char *cfgfile) ++static void create_entry (struct bls_entry *entry) + { + int argc = 0; + const char **argv = NULL; +@@ -539,7 +539,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile) + clinux = bls_get_val (entry, "linux", NULL); + if (!clinux) + { +- grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", cfgfile); ++ grub_dprintf ("blscfg", "Skipping file %s with no 'linux' key.\n", entry->filename); + goto finish; + } + +@@ -753,7 +753,7 @@ static int find_entry (const char *filename, + + grub_dprintf ("blscfg", "%s Creating %d entries from bls\n", __func__, nentries); + for (r = nentries - 1; r >= 0; r--) +- create_entry(entries[r], filename); ++ create_entry(entries[r]); + + for (r = 0; r < nentries; r++) + bls_free_entry (entries[r]); diff --git a/0388-Fix-our-linuxefi-linux-command-reunion.patch b/0388-Fix-our-linuxefi-linux-command-reunion.patch deleted file mode 100644 index cda701e..0000000 --- a/0388-Fix-our-linuxefi-linux-command-reunion.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Peter Jones -Date: Thu, 12 Jul 2018 19:39:51 -0400 -Subject: [PATCH] Fix our linuxefi/linux command reunion. - -Signed-off-by: Peter Jones ---- - grub-core/Makefile.core.def | 4 ++-- - grub-core/loader/i386/efi/linux.c | 13 +++++++++++-- - 2 files changed, 13 insertions(+), 4 deletions(-) - -diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def -index ff6fa4bd000..46ebe210263 100644 ---- a/grub-core/Makefile.core.def -+++ b/grub-core/Makefile.core.def -@@ -1713,8 +1713,8 @@ module = { - - module = { - name = linux; -- x86 = loader/i386/linux.c; -- x86_efi = loader/i386/efi/linux.c; -+ i386_pc = loader/i386/linux.c; -+ x86_64_efi = loader/i386/efi/linux.c; - i386_efi = loader/i386/efi/linux.c; - xen = loader/i386/xen.c; - i386_pc = lib/i386/pc/vesa_modes_table.c; -diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c -index 66e58b71e22..498d7ba7158 100644 ---- a/grub-core/loader/i386/efi/linux.c -+++ b/grub-core/loader/i386/efi/linux.c -@@ -366,20 +366,29 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), - } - - static grub_command_t cmd_linux, cmd_initrd; -+static grub_command_t cmd_linuxefi, cmd_initrdefi; - --GRUB_MOD_INIT(linuxefi) -+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(linuxefi) -+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/0388-blscfg-don-t-leak-bls_entry.filename.patch b/0388-blscfg-don-t-leak-bls_entry.filename.patch new file mode 100644 index 0000000..248663b --- /dev/null +++ b/0388-blscfg-don-t-leak-bls_entry.filename.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 12 Jul 2018 10:59:10 +0100 +Subject: [PATCH] blscfg: don't leak bls_entry.filename + +Zeroing the bls_entry struct before calling grub_free() on one of its +fields is not going to work too well. + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 077ca5dfbe6..3339d62d541 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -166,8 +166,8 @@ static void bls_free_entry(struct bls_entry *entry) + } + + grub_free (entry->keyvals); +- grub_memset (entry, 0, sizeof (*entry)); + grub_free (entry->filename); ++ grub_memset (entry, 0, sizeof (*entry)); + grub_free (entry); + } + diff --git a/0389-blscfg-fix-compilation-on-EFI-and-EMU.patch b/0389-blscfg-fix-compilation-on-EFI-and-EMU.patch new file mode 100644 index 0000000..d5d82d0 --- /dev/null +++ b/0389-blscfg-fix-compilation-on-EFI-and-EMU.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Thu, 12 Jul 2018 19:00:42 +0100 +Subject: [PATCH] blscfg: fix compilation on !EFI and !EMU +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Neither GRUB_MACHINE_EFI nor GRUB_MACHINE_EMU are defined when compiling +for (eg) i386-pc. In this case, #elif GRUB_MACHINE_EMU is an error: + + commands/blscfg.c: In function ‘grub_cmd_blscfg’: + commands/blscfg.c:835:7: error: "GRUB_MACHINE_EMU" is not defined [-Werror=undef] + #elif GRUB_MACHINE_EMU + ^~~~~~~~~~~~~~~~ + +Signed-off-by: Will Thompson +--- + grub-core/commands/blscfg.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c +index 3339d62d541..f4283708e21 100644 +--- a/grub-core/commands/blscfg.c ++++ b/grub-core/commands/blscfg.c +@@ -843,7 +843,7 @@ grub_cmd_blscfg (grub_extcmd_context_t ctxt UNUSED, + info.platform = PLATFORM_EFI; + grub_dprintf ("blscfg", "scanning /EFI/\n"); + r = fs->dir (dev, "/EFI/", find_entry, &info); +-#elif GRUB_MACHINE_EMU ++#elif defined(GRUB_MACHINE_EMU) + info.platform = PLATFORM_EMU; + grub_dprintf ("blscfg", "scanning %s%s\n", GRUB_BOOT_DEVICE, + GRUB_BLS_CONFIG_PATH); diff --git a/0390-Fix-our-linuxefi-linux-command-reunion.patch b/0390-Fix-our-linuxefi-linux-command-reunion.patch new file mode 100644 index 0000000..cda701e --- /dev/null +++ b/0390-Fix-our-linuxefi-linux-command-reunion.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 12 Jul 2018 19:39:51 -0400 +Subject: [PATCH] Fix our linuxefi/linux command reunion. + +Signed-off-by: Peter Jones +--- + grub-core/Makefile.core.def | 4 ++-- + grub-core/loader/i386/efi/linux.c | 13 +++++++++++-- + 2 files changed, 13 insertions(+), 4 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index ff6fa4bd000..46ebe210263 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1713,8 +1713,8 @@ module = { + + module = { + name = linux; +- x86 = loader/i386/linux.c; +- x86_efi = loader/i386/efi/linux.c; ++ i386_pc = loader/i386/linux.c; ++ x86_64_efi = loader/i386/efi/linux.c; + i386_efi = loader/i386/efi/linux.c; + xen = loader/i386/xen.c; + i386_pc = lib/i386/pc/vesa_modes_table.c; +diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c +index 66e58b71e22..498d7ba7158 100644 +--- a/grub-core/loader/i386/efi/linux.c ++++ b/grub-core/loader/i386/efi/linux.c +@@ -366,20 +366,29 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + } + + static grub_command_t cmd_linux, cmd_initrd; ++static grub_command_t cmd_linuxefi, cmd_initrdefi; + +-GRUB_MOD_INIT(linuxefi) ++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(linuxefi) ++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/0391-Add-loadenv-to-blscfg-and-loadenv-source-file-list.patch b/0391-Add-loadenv-to-blscfg-and-loadenv-source-file-list.patch new file mode 100644 index 0000000..a9e8151 --- /dev/null +++ b/0391-Add-loadenv-to-blscfg-and-loadenv-source-file-list.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Will Thompson +Date: Fri, 13 Jul 2018 05:51:54 +0100 +Subject: [PATCH] Add loadenv to blscfg and loadenv source file list +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Without this, `make distcheck` fails because loadenv.h is not included +in the source tarball. + +This broke in ‘Add blscfg command support to parse BootLoaderSpec config +fragments’. + +Signed-off-by: Will Thompson +--- + grub-core/Makefile.core.def | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 46ebe210263..4168097732b 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -781,6 +781,7 @@ module = { + module = { + name = blscfg; + common = commands/blscfg.c; ++ common = commands/loadenv.h; + enable = efi; + enable = i386_pc; + enable = emu; +@@ -949,6 +950,7 @@ module = { + module = { + name = loadenv; + common = commands/loadenv.c; ++ common = commands/loadenv.h; + common = lib/envblk.c; + }; + diff --git a/0392-Jettison-the-non-linux16-linux-loader-make-linux16-p.patch b/0392-Jettison-the-non-linux16-linux-loader-make-linux16-p.patch new file mode 100644 index 0000000..3f3b26e --- /dev/null +++ b/0392-Jettison-the-non-linux16-linux-loader-make-linux16-p.patch @@ -0,0 +1,75 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 13 Jul 2018 16:15:27 -0400 +Subject: [PATCH] Jettison the non-linux16 "linux" loader; make linux16 provide + the command. + +--- + grub-core/Makefile.core.def | 9 +-------- + grub-core/loader/i386/pc/linux.c | 10 +++++++++- + 2 files changed, 10 insertions(+), 9 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 4168097732b..f96b1933eea 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1650,13 +1650,6 @@ module = { + enable = i386_pc; + }; + +- +-module = { +- name = linux16; +- common = loader/i386/pc/linux.c; +- enable = i386_pc; +-}; +- + module = { + name = ntldr; + i386_pc = loader/i386/pc/ntldr.c; +@@ -1715,7 +1708,7 @@ module = { + + module = { + name = linux; +- i386_pc = 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; + xen = loader/i386/xen.c; +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 1e369afcbad..cfff25c21b5 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -481,7 +481,7 @@ 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) + { +@@ -489,9 +489,15 @@ GRUB_MOD_INIT(linux16) + return; + + 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; +@@ -503,5 +509,7 @@ GRUB_MOD_FINI(linux16) + return; + + grub_unregister_command (cmd_linux); ++ grub_unregister_command (cmd_linux16); + grub_unregister_command (cmd_initrd); ++ grub_unregister_command (cmd_initrd16); + } diff --git a/grub.patches b/grub.patches index 83f4ea0..1cade54 100644 --- a/grub.patches +++ b/grub.patches @@ -150,239 +150,243 @@ Patch0149: 0149-grub-fs-tester-Fix-losetup-race.patch Patch0150: 0150-fdt-Move-prop_entry_size-to-fdt.h.patch Patch0151: 0151-efi-fdt-Set-address-size-cells-to-2-for-empty-tree.patch Patch0152: 0152-multiboot_elfxx.c-Fix-compilation-by-fixing-undeclar.patch -Patch0153: 0153-re-write-.gitignore.patch -Patch0154: 0154-IBM-client-architecture-CAS-reboot-support.patch -Patch0155: 0155-for-ppc-reset-console-display-attr-when-clear-screen.patch -Patch0156: 0156-Disable-GRUB-video-support-for-IBM-power-machines.patch -Patch0157: 0157-Honor-a-symlink-when-generating-configuration-by-gru.patch -Patch0158: 0158-Move-bash-completion-script-922997.patch -Patch0159: 0159-Update-to-minilzo-2.08.patch -Patch0160: 0160-Allow-fallback-to-include-entries-by-title-not-just-.patch -Patch0161: 0161-Add-GRUB_DISABLE_UUID.patch -Patch0162: 0162-Make-exit-take-a-return-code.patch -Patch0163: 0163-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch -Patch0164: 0164-Make-efi-machines-load-an-env-block-from-a-variable.patch -Patch0165: 0165-DHCP-client-ID-and-UUID-options-added.patch -Patch0166: 0166-trim-arp-packets-with-abnormal-size.patch -Patch0167: 0167-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch -Patch0168: 0168-Add-support-for-UEFI-operating-systems-returned-by-o.patch -Patch0169: 0169-Migrate-PPC-from-Yaboot-to-Grub2.patch -Patch0170: 0170-Add-fw_path-variable-revised.patch -Patch0171: 0171-Add-support-for-linuxefi.patch -Patch0172: 0172-Use-linuxefi-and-initrdefi-where-appropriate.patch -Patch0173: 0173-Don-t-allow-insmod-when-secure-boot-is-enabled.patch -Patch0174: 0174-Pass-x-hex-hex-straight-through-unmolested.patch -Patch0175: 0175-Add-X-option-to-printf-functions.patch -Patch0176: 0176-Search-for-specific-config-file-for-netboot.patch -Patch0177: 0177-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch -Patch0178: 0178-Don-t-write-messages-to-the-screen.patch -Patch0179: 0179-Don-t-print-GNU-GRUB-header.patch -Patch0180: 0180-Don-t-add-to-highlighted-row.patch -Patch0181: 0181-Message-string-cleanups.patch -Patch0182: 0182-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch -Patch0183: 0183-Use-the-correct-indentation-for-the-term-help-text.patch -Patch0184: 0184-Indent-menu-entries.patch -Patch0185: 0185-Fix-margins.patch -Patch0186: 0186-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch -Patch0187: 0187-Use-linux16-when-appropriate-880840.patch -Patch0188: 0188-Enable-pager-by-default.-985860.patch -Patch0189: 0189-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch -Patch0190: 0190-Don-t-say-GNU-Linux-in-generated-menus.patch -Patch0191: 0191-Don-t-draw-a-border-around-the-menu.patch -Patch0192: 0192-Use-the-standard-margin-for-the-timeout-string.patch -Patch0193: 0193-Add-.eh_frame-to-list-of-relocations-stripped.patch -Patch0194: 0194-Make-10_linux-work-with-our-changes-for-linux16-and-.patch -Patch0195: 0195-Don-t-print-during-fdt-loading-method.patch -Patch0196: 0196-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch -Patch0197: 0197-Don-t-require-a-password-to-boot-entries-generated-b.patch -Patch0198: 0198-Don-t-emit-Booting-.-message.patch -Patch0199: 0199-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch -Patch0200: 0200-use-fw_path-prefix-when-fallback-searching-for-grub-.patch -Patch0201: 0201-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch -Patch0202: 0202-Fix-convert-function-to-support-NVMe-devices.patch -Patch0203: 0203-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch -Patch0204: 0204-Use-the-default-device-tree-from-the-grub-default-fi.patch -Patch0205: 0205-reopen-SNP-protocol-for-exclusive-use-by-grub.patch -Patch0206: 0206-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch -Patch0207: 0207-Add-grub_util_readlink.patch -Patch0208: 0208-Make-editenv-chase-symlinks-including-those-across-d.patch -Patch0209: 0209-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch -Patch0210: 0210-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch -Patch0211: 0211-Load-arm-with-SB-enabled.patch -Patch0212: 0212-Try-prefix-if-fw_path-doesn-t-work.patch -Patch0213: 0213-Update-info-with-grub.cfg-netboot-selection-order-11.patch -Patch0214: 0214-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch -Patch0215: 0215-Handle-rssd-storage-devices.patch -Patch0216: 0216-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch -Patch0217: 0217-Make-grub2-mkconfig-construct-titles-that-look-like-.patch -Patch0218: 0218-Add-friendly-grub2-password-config-tool-985962.patch -Patch0219: 0219-Make-grub2-mkconfig-construct-titles-that-look-like-.patch -Patch0220: 0220-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch -Patch0221: 0221-tcp-add-window-scaling-support.patch -Patch0222: 0222-efinet-retransmit-if-our-device-is-busy.patch -Patch0223: 0223-Be-more-aggro-about-actually-using-the-configured-ne.patch -Patch0224: 0224-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch -Patch0225: 0225-Fix-security-issue-when-reading-username-and-passwor.patch -Patch0226: 0226-Warn-if-grub-password-will-not-be-read-1290803.patch -Patch0227: 0227-Clean-up-grub-setpassword-documentation-1290799.patch -Patch0228: 0228-Fix-locale-issue-in-grub-setpassword-1294243.patch -Patch0229: 0229-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch -Patch0230: 0230-efiemu-Fix-compilation-failure.patch -Patch0231: 0231-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch -Patch0232: 0232-Add-a-url-parser.patch -Patch0233: 0233-efinet-and-bootp-add-support-for-dhcpv6.patch -Patch0234: 0234-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch -Patch0235: 0235-Normalize-slashes-in-tftp-paths.patch -Patch0236: 0236-Fix-malformed-tftp-packets.patch -Patch0237: 0237-Fix-race-in-EFI-validation.patch -Patch0238: 0238-bz1374141-fix-incorrect-mask-for-ppc64.patch -Patch0239: 0239-Use-device-part-of-chainloader-target-if-present.patch -Patch0240: 0240-Add-secureboot-support-on-efi-chainloader.patch -Patch0241: 0241-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch -Patch0242: 0242-Make-grub_fatal-also-backtrace.patch -Patch0243: 0243-Rework-linux-command.patch -Patch0244: 0244-Rework-linux16-command.patch -Patch0245: 0245-Make-grub-editenv-build-again.patch -Patch0246: 0246-Fix-up-some-man-pages-rpmdiff-noticed.patch -Patch0247: 0247-Re-work-some-intricacies-of-PE-loading.patch -Patch0248: 0248-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch -Patch0249: 0249-linuxefi-fix-double-free-on-verification-failure.patch -Patch0250: 0250-fix-machine-type-test-in-30_os-prober.in.patch -Patch0251: 0251-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch -Patch0252: 0252-efi-chainloader-truncate-overlong-relocation-section.patch -Patch0253: 0253-linuxefi-minor-cleanups.patch -Patch0254: 0254-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch -Patch0255: 0255-Fix-up-linux-params-usage.patch -Patch0256: 0256-Make-exit-take-a-return-code.patch -Patch0257: 0257-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch -Patch0258: 0258-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch -Patch0259: 0259-Make-our-info-pages-say-grub2-where-appropriate.patch -Patch0260: 0260-print-more-debug-info-in-our-module-loader.patch -Patch0261: 0261-macos-just-build-chainloader-entries-don-t-try-any-x.patch -Patch0262: 0262-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch -Patch0263: 0263-export-btrfs_subvol-and-btrfs_subvolid.patch -Patch0264: 0264-grub2-btrfs-03-follow_default.patch -Patch0265: 0265-grub2-btrfs-04-grub2-install.patch -Patch0266: 0266-grub2-btrfs-05-grub2-mkconfig.patch -Patch0267: 0267-grub2-btrfs-06-subvol-mount.patch -Patch0268: 0268-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch -Patch0269: 0269-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch -Patch0270: 0270-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch -Patch0271: 0271-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch -Patch0272: 0272-Use-grub_efi_.-memory-helpers-where-reasonable.patch -Patch0273: 0273-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch -Patch0274: 0274-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch -Patch0275: 0275-don-t-ignore-const.patch -Patch0276: 0276-don-t-use-int-for-efi-status.patch -Patch0277: 0277-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch -Patch0278: 0278-Clean-up-some-errors-in-the-linuxefi-loader.patch -Patch0279: 0279-editenv-handle-relative-symlinks.patch -Patch0280: 0280-Make-libgrub.pp-depend-on-config-util.h.patch -Patch0281: 0281-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch -Patch0282: 0282-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch -Patch0283: 0283-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch -Patch0284: 0284-align-struct-efi_variable-better.patch -Patch0285: 0285-Add-quicksort-implementation.patch -Patch0286: 0286-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch -Patch0287: 0287-Add-BLS-support-to-grub-mkconfig.patch -Patch0288: 0288-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch -Patch0289: 0289-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch -Patch0290: 0290-Enable-blscfg-command-for-the-emu-platform.patch -Patch0291: 0291-Add-linux-and-initrd-commands-for-grub-emu.patch -Patch0292: 0292-Fix-the-efidir-in-grub-setpassword.patch -Patch0293: 0293-Add-grub2-switch-to-blscfg.patch -Patch0294: 0294-Add-grub_debug_enabled.patch -Patch0295: 0295-make-better-backtraces.patch -Patch0296: 0296-normal-don-t-draw-our-startup-message-if-debug-is-se.patch -Patch0297: 0297-Work-around-some-minor-include-path-weirdnesses.patch -Patch0298: 0298-Make-it-possible-to-enabled-build-id-sha1.patch -Patch0299: 0299-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch -Patch0300: 0300-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch -Patch0301: 0301-Only-attempt-to-scan-different-BLS-directories-on-EF.patch -Patch0302: 0302-Core-TPM-support.patch -Patch0303: 0303-Measure-kernel-initrd.patch -Patch0304: 0304-Add-BIOS-boot-measurement.patch -Patch0305: 0305-Measure-kernel-and-initrd-on-BIOS-systems.patch -Patch0306: 0306-Measure-the-kernel-commandline.patch -Patch0307: 0307-Measure-commands.patch -Patch0308: 0308-Measure-multiboot-images-and-modules.patch -Patch0309: 0309-Fix-boot-when-there-s-no-TPM.patch -Patch0310: 0310-Rework-TPM-measurements.patch -Patch0311: 0311-Fix-event-log-prefix.patch -Patch0312: 0312-Set-the-first-boot-menu-entry-as-default-when-using-.patch -Patch0313: 0313-tpm-fix-warnings-when-compiling-for-platforms-other-.patch -Patch0314: 0314-Make-TPM-errors-less-fatal.patch -Patch0315: 0315-blscfg-handle-multiple-initramfs-images.patch -Patch0316: 0316-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch -Patch0317: 0317-BLS-Use-etcdefaultgrub-instead-of-etc.patch -Patch0318: 0318-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch -Patch0319: 0319-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch -Patch0320: 0320-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch -Patch0321: 0321-Only-attempt-to-query-dev-mounted-in-boot-efi-as-boo.patch -Patch0322: 0322-Include-OSTree-path-when-searching-kernels-images-if.patch -Patch0323: 0323-Use-BLS-version-field-to-compare-entries-if-id-field.patch -Patch0324: 0324-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch -Patch0325: 0325-Fixup-for-newer-compiler.patch -Patch0326: 0326-Don-t-attempt-to-export-the-start-and-_start-symbols.patch -Patch0327: 0327-Simplify-BLS-entry-key-val-pairs-lookup.patch -Patch0328: 0328-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch -Patch0329: 0329-Skip-leading-spaces-on-BLS-field-values.patch -Patch0330: 0330-Fixup-for-newer-compiler.patch -Patch0331: 0331-TPM-Fix-hash_log_extend_event-function-prototype.patch -Patch0332: 0332-TPM-Fix-compiler-warnings.patch -Patch0333: 0333-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch -Patch0334: 0334-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch -Patch0335: 0335-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch -Patch0336: 0336-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch -Patch0337: 0337-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch -Patch0338: 0338-Revert-trim-arp-packets-with-abnormal-size.patch -Patch0339: 0339-Use-xid-to-match-DHCP-replies.patch -Patch0340: 0340-Add-support-for-non-Ethernet-network-cards.patch -Patch0341: 0341-misc-fix-invalid-character-recongition-in-strto-l.patch -Patch0342: 0342-net-read-bracketed-ipv6-addrs-and-port-numbers.patch -Patch0343: 0343-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch -Patch0344: 0344-bootp-New-net_bootp6-command.patch -Patch0345: 0345-Put-back-our-code-to-add-a-local-route.patch -Patch0346: 0346-efinet-UEFI-IPv6-PXE-support.patch -Patch0347: 0347-grub.texi-Add-net_bootp6-doument.patch -Patch0348: 0348-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch -Patch0349: 0349-efinet-Setting-network-from-UEFI-device-path.patch -Patch0350: 0350-efinet-Setting-DNS-server-from-UEFI-protocol.patch -Patch0351: 0351-Fix-one-more-coverity-complaint.patch -Patch0352: 0352-Fix-grub_net_hwaddr_to_str.patch -Patch0353: 0353-Support-UEFI-networking-protocols.patch -Patch0354: 0354-AUDIT-0-http-boot-tracker-bug.patch -Patch0355: 0355-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch -Patch0356: 0356-efi-uga-use-64-bit-for-fb_base.patch -Patch0357: 0357-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch -Patch0358: 0358-EFI-console-Add-grub_console_read_key_stroke-helper-.patch -Patch0359: 0359-EFI-console-Implement-getkeystatus-support.patch -Patch0360: 0360-Make-grub_getkeystatus-helper-funtion-available-ever.patch -Patch0361: 0361-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch -Patch0362: 0362-grub-editenv-Add-incr-command-to-increment-integer-v.patch -Patch0363: 0363-Add-auto-hide-menu-support.patch -Patch0364: 0364-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch -Patch0365: 0365-Add-grub-set-bootflag-utility.patch -Patch0366: 0366-Fix-grub-setpassword-o-s-output-path.patch -Patch0367: 0367-Make-grub-set-password-be-named-like-all-the-other-g.patch -Patch0368: 0368-docs-Add-grub-boot-indeterminate.service-example.patch -Patch0369: 0369-EFI-console-Fix-the-enter-key-not-working-on-X86-tab.patch -Patch0370: 0370-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch -Patch0371: 0371-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch -Patch0372: 0372-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch -Patch0373: 0373-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch -Patch0374: 0374-gentpl-add-disable-support.patch -Patch0375: 0375-gentpl-add-pc-firmware-type.patch -Patch0376: 0376-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch -Patch0377: 0377-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch -Patch0378: 0378-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch -Patch0379: 0379-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch -Patch0380: 0380-Don-t-build-the-fdt-command.patch -Patch0381: 0381-blscfg-remove-unused-typedef.patch -Patch0382: 0382-blscfg-don-t-dynamically-allocate-default_blsdir.patch -Patch0383: 0383-blscfg-sort-BLS-entries-by-version-field.patch -Patch0384: 0384-blscfg-remove-NULL-guards-around-grub_free.patch -Patch0385: 0385-blscfg-fix-filename-in-no-linux-key-error.patch -Patch0386: 0386-blscfg-don-t-leak-bls_entry.filename.patch -Patch0387: 0387-blscfg-fix-compilation-on-EFI-and-EMU.patch -Patch0388: 0388-Fix-our-linuxefi-linux-command-reunion.patch +Patch0153: 0153-grub-setup-Debug-message-cleanup.patch +Patch0154: 0154-efi-console-Fix-the-enter-key-not-working-on-x86-tab.patch +Patch0155: 0155-commands-file-Use-definitions-from-arm-linux.h.patch +Patch0156: 0156-commands-file-Use-definitions-from-arm64-linux.h.patch +Patch0157: 0157-re-write-.gitignore.patch +Patch0158: 0158-IBM-client-architecture-CAS-reboot-support.patch +Patch0159: 0159-for-ppc-reset-console-display-attr-when-clear-screen.patch +Patch0160: 0160-Disable-GRUB-video-support-for-IBM-power-machines.patch +Patch0161: 0161-Honor-a-symlink-when-generating-configuration-by-gru.patch +Patch0162: 0162-Move-bash-completion-script-922997.patch +Patch0163: 0163-Update-to-minilzo-2.08.patch +Patch0164: 0164-Allow-fallback-to-include-entries-by-title-not-just-.patch +Patch0165: 0165-Add-GRUB_DISABLE_UUID.patch +Patch0166: 0166-Make-exit-take-a-return-code.patch +Patch0167: 0167-Mark-po-exclude.pot-as-binary-so-git-won-t-try-to-di.patch +Patch0168: 0168-Make-efi-machines-load-an-env-block-from-a-variable.patch +Patch0169: 0169-DHCP-client-ID-and-UUID-options-added.patch +Patch0170: 0170-trim-arp-packets-with-abnormal-size.patch +Patch0171: 0171-Fix-bad-test-on-GRUB_DISABLE_SUBMENU.patch +Patch0172: 0172-Add-support-for-UEFI-operating-systems-returned-by-o.patch +Patch0173: 0173-Migrate-PPC-from-Yaboot-to-Grub2.patch +Patch0174: 0174-Add-fw_path-variable-revised.patch +Patch0175: 0175-Add-support-for-linuxefi.patch +Patch0176: 0176-Use-linuxefi-and-initrdefi-where-appropriate.patch +Patch0177: 0177-Don-t-allow-insmod-when-secure-boot-is-enabled.patch +Patch0178: 0178-Pass-x-hex-hex-straight-through-unmolested.patch +Patch0179: 0179-Add-X-option-to-printf-functions.patch +Patch0180: 0180-Search-for-specific-config-file-for-netboot.patch +Patch0181: 0181-blscfg-add-blscfg-module-to-parse-Boot-Loader-Specif.patch +Patch0182: 0182-Don-t-write-messages-to-the-screen.patch +Patch0183: 0183-Don-t-print-GNU-GRUB-header.patch +Patch0184: 0184-Don-t-add-to-highlighted-row.patch +Patch0185: 0185-Message-string-cleanups.patch +Patch0186: 0186-Fix-border-spacing-now-that-we-aren-t-displaying-it.patch +Patch0187: 0187-Use-the-correct-indentation-for-the-term-help-text.patch +Patch0188: 0188-Indent-menu-entries.patch +Patch0189: 0189-Fix-margins.patch +Patch0190: 0190-Use-2-instead-of-1-for-our-right-hand-margin-so-line.patch +Patch0191: 0191-Use-linux16-when-appropriate-880840.patch +Patch0192: 0192-Enable-pager-by-default.-985860.patch +Patch0193: 0193-F10-doesn-t-work-on-serial-so-don-t-tell-the-user-to.patch +Patch0194: 0194-Don-t-say-GNU-Linux-in-generated-menus.patch +Patch0195: 0195-Don-t-draw-a-border-around-the-menu.patch +Patch0196: 0196-Use-the-standard-margin-for-the-timeout-string.patch +Patch0197: 0197-Add-.eh_frame-to-list-of-relocations-stripped.patch +Patch0198: 0198-Make-10_linux-work-with-our-changes-for-linux16-and-.patch +Patch0199: 0199-Don-t-print-during-fdt-loading-method.patch +Patch0200: 0200-Don-t-munge-raw-spaces-when-we-re-doing-our-cmdline-.patch +Patch0201: 0201-Don-t-require-a-password-to-boot-entries-generated-b.patch +Patch0202: 0202-Don-t-emit-Booting-.-message.patch +Patch0203: 0203-Replace-a-lot-of-man-pages-with-slightly-nicer-ones.patch +Patch0204: 0204-use-fw_path-prefix-when-fallback-searching-for-grub-.patch +Patch0205: 0205-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch +Patch0206: 0206-Fix-convert-function-to-support-NVMe-devices.patch +Patch0207: 0207-Switch-to-use-APM-Mustang-device-tree-for-hardware-t.patch +Patch0208: 0208-Use-the-default-device-tree-from-the-grub-default-fi.patch +Patch0209: 0209-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +Patch0210: 0210-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +Patch0211: 0211-Add-grub_util_readlink.patch +Patch0212: 0212-Make-editenv-chase-symlinks-including-those-across-d.patch +Patch0213: 0213-Generate-OS-and-CLASS-in-10_linux-from-etc-os-releas.patch +Patch0214: 0214-Minimize-the-sort-ordering-for-.debug-and-rescue-ker.patch +Patch0215: 0215-Load-arm-with-SB-enabled.patch +Patch0216: 0216-Try-prefix-if-fw_path-doesn-t-work.patch +Patch0217: 0217-Update-info-with-grub.cfg-netboot-selection-order-11.patch +Patch0218: 0218-Use-Distribution-Package-Sort-for-grub2-mkconfig-112.patch +Patch0219: 0219-Handle-rssd-storage-devices.patch +Patch0220: 0220-Try-to-emit-linux16-initrd16-and-linuxefi-initrdefi-.patch +Patch0221: 0221-Make-grub2-mkconfig-construct-titles-that-look-like-.patch +Patch0222: 0222-Add-friendly-grub2-password-config-tool-985962.patch +Patch0223: 0223-Try-to-make-sure-configure.ac-and-grub-rpm-sort-play.patch +Patch0224: 0224-tcp-add-window-scaling-support.patch +Patch0225: 0225-efinet-retransmit-if-our-device-is-busy.patch +Patch0226: 0226-Be-more-aggro-about-actually-using-the-configured-ne.patch +Patch0227: 0227-efinet-add-filter-for-the-first-exclusive-reopen-of-.patch +Patch0228: 0228-Fix-security-issue-when-reading-username-and-passwor.patch +Patch0229: 0229-Warn-if-grub-password-will-not-be-read-1290803.patch +Patch0230: 0230-Clean-up-grub-setpassword-documentation-1290799.patch +Patch0231: 0231-Fix-locale-issue-in-grub-setpassword-1294243.patch +Patch0232: 0232-efiemu-Handle-persistent-RAM-and-unknown-possible-fu.patch +Patch0233: 0233-efiemu-Fix-compilation-failure.patch +Patch0234: 0234-Revert-reopen-SNP-protocol-for-exclusive-use-by-grub.patch +Patch0235: 0235-Add-a-url-parser.patch +Patch0236: 0236-efinet-and-bootp-add-support-for-dhcpv6.patch +Patch0237: 0237-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch +Patch0238: 0238-Normalize-slashes-in-tftp-paths.patch +Patch0239: 0239-Fix-malformed-tftp-packets.patch +Patch0240: 0240-Fix-race-in-EFI-validation.patch +Patch0241: 0241-bz1374141-fix-incorrect-mask-for-ppc64.patch +Patch0242: 0242-Use-device-part-of-chainloader-target-if-present.patch +Patch0243: 0243-Add-secureboot-support-on-efi-chainloader.patch +Patch0244: 0244-Make-any-of-the-loaders-that-link-in-efi-mode-honor-.patch +Patch0245: 0245-Make-grub_fatal-also-backtrace.patch +Patch0246: 0246-Rework-linux-command.patch +Patch0247: 0247-Rework-linux16-command.patch +Patch0248: 0248-Make-grub-editenv-build-again.patch +Patch0249: 0249-Fix-up-some-man-pages-rpmdiff-noticed.patch +Patch0250: 0250-Re-work-some-intricacies-of-PE-loading.patch +Patch0251: 0251-Rework-even-more-of-efi-chainload-so-non-sb-cases-wo.patch +Patch0252: 0252-linuxefi-fix-double-free-on-verification-failure.patch +Patch0253: 0253-fix-machine-type-test-in-30_os-prober.in.patch +Patch0254: 0254-efi-chainloader-fix-wrong-sanity-check-in-relocate_c.patch +Patch0255: 0255-efi-chainloader-truncate-overlong-relocation-section.patch +Patch0256: 0256-linuxefi-minor-cleanups.patch +Patch0257: 0257-Handle-multi-arch-64-on-32-boot-in-linuxefi-loader.patch +Patch0258: 0258-Fix-up-linux-params-usage.patch +Patch0259: 0259-Make-exit-take-a-return-code.patch +Patch0260: 0260-arm64-make-sure-fdt-has-address-cells-and-size-cells.patch +Patch0261: 0261-Add-some-grub_dprintf-in-the-secure-boot-verify-code.patch +Patch0262: 0262-Make-our-info-pages-say-grub2-where-appropriate.patch +Patch0263: 0263-print-more-debug-info-in-our-module-loader.patch +Patch0264: 0264-macos-just-build-chainloader-entries-don-t-try-any-x.patch +Patch0265: 0265-grub2-btrfs-Add-ability-to-boot-from-subvolumes.patch +Patch0266: 0266-export-btrfs_subvol-and-btrfs_subvolid.patch +Patch0267: 0267-grub2-btrfs-03-follow_default.patch +Patch0268: 0268-grub2-btrfs-04-grub2-install.patch +Patch0269: 0269-grub2-btrfs-05-grub2-mkconfig.patch +Patch0270: 0270-grub2-btrfs-06-subvol-mount.patch +Patch0271: 0271-No-more-Bootable-Snapshot-submenu-in-grub.cfg.patch +Patch0272: 0272-Fallback-to-old-subvol-name-scheme-to-support-old-sn.patch +Patch0273: 0273-Grub-not-working-correctly-with-btrfs-snapshots-bsc-.patch +Patch0274: 0274-Add-grub_efi_allocate_pool-and-grub_efi_free_pool-wr.patch +Patch0275: 0275-Use-grub_efi_.-memory-helpers-where-reasonable.patch +Patch0276: 0276-Add-PRIxGRUB_EFI_STATUS-and-use-it.patch +Patch0277: 0277-Don-t-use-dynamic-sized-arrays-since-we-don-t-build-.patch +Patch0278: 0278-don-t-ignore-const.patch +Patch0279: 0279-don-t-use-int-for-efi-status.patch +Patch0280: 0280-make-GRUB_MOD_INIT-declare-its-function-prototypes.patch +Patch0281: 0281-Clean-up-some-errors-in-the-linuxefi-loader.patch +Patch0282: 0282-editenv-handle-relative-symlinks.patch +Patch0283: 0283-Make-libgrub.pp-depend-on-config-util.h.patch +Patch0284: 0284-Don-t-guess-boot-efi-as-HFS-on-ppc-machines-in-grub-.patch +Patch0285: 0285-20_linux_xen-load-xen-or-multiboot-2-modules-as-need.patch +Patch0286: 0286-Make-pmtimer-tsc-calibration-not-take-51-seconds-to-.patch +Patch0287: 0287-align-struct-efi_variable-better.patch +Patch0288: 0288-Add-quicksort-implementation.patch +Patch0289: 0289-Add-blscfg-command-support-to-parse-BootLoaderSpec-c.patch +Patch0290: 0290-Add-BLS-support-to-grub-mkconfig.patch +Patch0291: 0291-Remove-duplicated-grub_exit-definition-for-grub-emu-.patch +Patch0292: 0292-Don-t-attempt-to-backtrace-on-grub_abort-for-grub-em.patch +Patch0293: 0293-Enable-blscfg-command-for-the-emu-platform.patch +Patch0294: 0294-Add-linux-and-initrd-commands-for-grub-emu.patch +Patch0295: 0295-Fix-the-efidir-in-grub-setpassword.patch +Patch0296: 0296-Add-grub2-switch-to-blscfg.patch +Patch0297: 0297-Add-grub_debug_enabled.patch +Patch0298: 0298-make-better-backtraces.patch +Patch0299: 0299-normal-don-t-draw-our-startup-message-if-debug-is-se.patch +Patch0300: 0300-Work-around-some-minor-include-path-weirdnesses.patch +Patch0301: 0301-Make-it-possible-to-enabled-build-id-sha1.patch +Patch0302: 0302-Add-grub_qdprintf-grub_dprintf-without-the-file-line.patch +Patch0303: 0303-Make-a-gdb-dprintf-that-tells-us-load-addresses.patch +Patch0304: 0304-Only-attempt-to-scan-different-BLS-directories-on-EF.patch +Patch0305: 0305-Core-TPM-support.patch +Patch0306: 0306-Measure-kernel-initrd.patch +Patch0307: 0307-Add-BIOS-boot-measurement.patch +Patch0308: 0308-Measure-kernel-and-initrd-on-BIOS-systems.patch +Patch0309: 0309-Measure-the-kernel-commandline.patch +Patch0310: 0310-Measure-commands.patch +Patch0311: 0311-Measure-multiboot-images-and-modules.patch +Patch0312: 0312-Fix-boot-when-there-s-no-TPM.patch +Patch0313: 0313-Rework-TPM-measurements.patch +Patch0314: 0314-Fix-event-log-prefix.patch +Patch0315: 0315-Set-the-first-boot-menu-entry-as-default-when-using-.patch +Patch0316: 0316-tpm-fix-warnings-when-compiling-for-platforms-other-.patch +Patch0317: 0317-Make-TPM-errors-less-fatal.patch +Patch0318: 0318-blscfg-handle-multiple-initramfs-images.patch +Patch0319: 0319-BLS-Fix-grub2-switch-to-blscfg-on-non-EFI-machines.patch +Patch0320: 0320-BLS-Use-etcdefaultgrub-instead-of-etc.patch +Patch0321: 0321-Add-missing-options-to-grub2-switch-to-blscfg-man-pa.patch +Patch0322: 0322-Make-grub2-switch-to-blscfg-to-generate-debug-BLS-wh.patch +Patch0323: 0323-Make-grub2-switch-to-blscfg-to-generate-BLS-fragment.patch +Patch0324: 0324-Only-attempt-to-query-dev-mounted-in-boot-efi-as-boo.patch +Patch0325: 0325-Include-OSTree-path-when-searching-kernels-images-if.patch +Patch0326: 0326-Use-BLS-version-field-to-compare-entries-if-id-field.patch +Patch0327: 0327-Add-version-field-to-BLS-generated-by-grub2-switch-t.patch +Patch0328: 0328-Fixup-for-newer-compiler.patch +Patch0329: 0329-Don-t-attempt-to-export-the-start-and-_start-symbols.patch +Patch0330: 0330-Simplify-BLS-entry-key-val-pairs-lookup.patch +Patch0331: 0331-Add-relative-path-to-the-kernel-and-initrds-BLS-fiel.patch +Patch0332: 0332-Skip-leading-spaces-on-BLS-field-values.patch +Patch0333: 0333-Fixup-for-newer-compiler.patch +Patch0334: 0334-TPM-Fix-hash_log_extend_event-function-prototype.patch +Patch0335: 0335-TPM-Fix-compiler-warnings.patch +Patch0336: 0336-grub-switch-to-blscfg.in-get-rid-of-a-bunch-of-bashi.patch +Patch0337: 0337-grub-switch-to-blscfg.in-Better-boot-prefix-checking.patch +Patch0338: 0338-Use-boot-loader-entries-as-BLS-directory-path-also-o.patch +Patch0339: 0339-Use-BLS-fragment-filename-as-menu-entry-id-and-for-c.patch +Patch0340: 0340-Fix-grub-switch-to-blscfg-boot-prefix-handling.patch +Patch0341: 0341-Revert-trim-arp-packets-with-abnormal-size.patch +Patch0342: 0342-Use-xid-to-match-DHCP-replies.patch +Patch0343: 0343-Add-support-for-non-Ethernet-network-cards.patch +Patch0344: 0344-misc-fix-invalid-character-recongition-in-strto-l.patch +Patch0345: 0345-net-read-bracketed-ipv6-addrs-and-port-numbers.patch +Patch0346: 0346-net-read-bracketed-ipv6-addrs-and-port-numbers-pjone.patch +Patch0347: 0347-bootp-New-net_bootp6-command.patch +Patch0348: 0348-Put-back-our-code-to-add-a-local-route.patch +Patch0349: 0349-efinet-UEFI-IPv6-PXE-support.patch +Patch0350: 0350-grub.texi-Add-net_bootp6-doument.patch +Patch0351: 0351-bootp-Add-processing-DHCPACK-packet-from-HTTP-Boot.patch +Patch0352: 0352-efinet-Setting-network-from-UEFI-device-path.patch +Patch0353: 0353-efinet-Setting-DNS-server-from-UEFI-protocol.patch +Patch0354: 0354-Fix-one-more-coverity-complaint.patch +Patch0355: 0355-Fix-grub_net_hwaddr_to_str.patch +Patch0356: 0356-Support-UEFI-networking-protocols.patch +Patch0357: 0357-AUDIT-0-http-boot-tracker-bug.patch +Patch0358: 0358-grub-core-video-efi_gop.c-Add-support-for-BLT_ONLY-a.patch +Patch0359: 0359-efi-uga-use-64-bit-for-fb_base.patch +Patch0360: 0360-EFI-console-Do-not-set-text-mode-until-we-actually-n.patch +Patch0361: 0361-EFI-console-Add-grub_console_read_key_stroke-helper-.patch +Patch0362: 0362-EFI-console-Implement-getkeystatus-support.patch +Patch0363: 0363-Make-grub_getkeystatus-helper-funtion-available-ever.patch +Patch0364: 0364-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch +Patch0365: 0365-grub-editenv-Add-incr-command-to-increment-integer-v.patch +Patch0366: 0366-Add-auto-hide-menu-support.patch +Patch0367: 0367-Output-a-menu-entry-for-firmware-setup-on-UEFI-FastB.patch +Patch0368: 0368-Add-grub-set-bootflag-utility.patch +Patch0369: 0369-Fix-grub-setpassword-o-s-output-path.patch +Patch0370: 0370-Make-grub-set-password-be-named-like-all-the-other-g.patch +Patch0371: 0371-docs-Add-grub-boot-indeterminate.service-example.patch +Patch0372: 0372-00_menu_auto_hide-Use-a-timeout-of-60s-for-menu_show.patch +Patch0373: 0373-00_menu_auto_hide-Reduce-number-of-save_env-calls.patch +Patch0374: 0374-Minor-fixes-to-make-armv7hl-build-as-arm-efi.patch +Patch0375: 0375-30_uefi-firmware-fix-use-with-sys-firmware-efi-efiva.patch +Patch0376: 0376-gentpl-add-disable-support.patch +Patch0377: 0377-gentpl-add-pc-firmware-type.patch +Patch0378: 0378-Disable-the-reboot-module-on-EFI-builds-it-is-in-ker.patch +Patch0379: 0379-Disable-multiboot-multiboot2-and-linux16-modules-on-.patch +Patch0380: 0380-Make-the-linuxefi-module-just-be-the-x86-efi-version.patch +Patch0381: 0381-Make-efi_netfs-not-duplicate-symbols-from-efinet.patch +Patch0382: 0382-Don-t-build-the-fdt-command.patch +Patch0383: 0383-blscfg-remove-unused-typedef.patch +Patch0384: 0384-blscfg-don-t-dynamically-allocate-default_blsdir.patch +Patch0385: 0385-blscfg-sort-BLS-entries-by-version-field.patch +Patch0386: 0386-blscfg-remove-NULL-guards-around-grub_free.patch +Patch0387: 0387-blscfg-fix-filename-in-no-linux-key-error.patch +Patch0388: 0388-blscfg-don-t-leak-bls_entry.filename.patch +Patch0389: 0389-blscfg-fix-compilation-on-EFI-and-EMU.patch +Patch0390: 0390-Fix-our-linuxefi-linux-command-reunion.patch +Patch0391: 0391-Add-loadenv-to-blscfg-and-loadenv-source-file-list.patch +Patch0392: 0392-Jettison-the-non-linux16-linux-loader-make-linux16-p.patch diff --git a/grub2.spec b/grub2.spec index a51e7c7..2b924e7 100644 --- a/grub2.spec +++ b/grub2.spec @@ -7,7 +7,7 @@ Name: grub2 Epoch: 1 Version: 2.02 -Release: 42%{?dist} +Release: 43%{?dist} Summary: Bootloader with support for Linux, Multiboot and more Group: System Environment/Base License: GPLv3+ @@ -457,6 +457,9 @@ fi %endif %changelog +* 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*.