]> git.proxmox.com Git - grub2.git/log
grub2.git
4 years agomultiboot2: Set min address for mbi allocation to 0x1000
Lukasz Hawrylko [Mon, 16 Dec 2019 10:15:55 +0000 (11:15 +0100)]
multiboot2: Set min address for mbi allocation to 0x1000

In some cases GRUB2 allocates multiboot2 structure at 0 address, that is
a confusing behavior. Consumers of that structure can have internal NULL-checks
that will throw an error when get a pointer to data allocated at address 0.
To prevent that, define min address for mbi allocation on x86 and x86_64
platforms.

Signed-off-by: Lukasz Hawrylko <lukasz.hawrylko@linux.intel.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agodocs: Export "superusers" variable to apply to submenus
Paul Menzel [Tue, 10 Dec 2019 12:04:05 +0000 (13:04 +0100)]
docs: Export "superusers" variable to apply to submenus

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agoloader/i386/linux: Fix an underflow in the setup_header length calculation
Daniel Kiper [Mon, 2 Dec 2019 17:29:39 +0000 (18:29 +0100)]
loader/i386/linux: Fix an underflow in the setup_header length calculation

Recent work around x86 Linux kernel loader revealed an underflow in the
setup_header length calculation and another related issue. Both lead to
the memory overwrite and later machine crash.

Currently when the GRUB copies the setup_header into the linux_params
(struct boot_params, traditionally known as "zero page") it assumes the
setup_header size as sizeof(linux_i386_kernel_header/lh). This is
incorrect. It should use the value calculated accordingly to the Linux
kernel boot protocol. Otherwise in case of pretty old kernel, to be
exact Linux kernel boot protocol, the GRUB may write more into
linux_params than it was expected to. Fortunately this is not very big
issue. Though it has to be fixed. However, there is also an underflow
which is grave. It happens when

  sizeof(linux_i386_kernel_header/lh) > "real size of the setup_header".

Then len value wraps around and grub_file_read() reads whole kernel into
the linux_params overwriting memory past it. This leads to the GRUB
memory allocator breakage and finally to its crash during boot.

The patch fixes both issues. Additionally, it moves the code not related to
grub_memset(linux_params)/grub_memcpy(linux_params)/grub_file_read(linux_params)
section outside of it to not confuse the reader.

Fixes: e683cfb0cf5 (loader/i386/linux: Calculate the setup_header length)
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com>
4 years agobtrfs: Add support for new RAID1C34 profiles
David Sterba [Mon, 4 Nov 2019 16:23:22 +0000 (17:23 +0100)]
btrfs: Add support for new RAID1C34 profiles

New 3- and 4-copy variants of RAID1 were merged into Linux kernel 5.5.
Add the two new profiles to the list of recognized ones. As this builds
on the same code as RAID1, only the redundancy level needs to be
adjusted, the rest is done by the existing code.

Signed-off-by: David Sterba <dsterba@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotftp: Normalize slashes in TFTP paths
Lenny Szubowicz [Thu, 31 Oct 2019 10:33:39 +0000 (11:33 +0100)]
tftp: Normalize slashes in TFTP paths

Some TFTP servers do not handle multiple consecutive slashes correctly.
This patch avoids sending TFTP requests with non-normalized paths.

Signed-off-by: Lenny Szubowicz <lszubowi@redhat.com>
Signed-off-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agogrub-editenv: Warn a user against editing environment block
Michael Chang [Tue, 5 Nov 2019 09:20:22 +0000 (09:20 +0000)]
grub-editenv: Warn a user against editing environment block

The environment block is a preallocated 1024-byte file which serves as
persistent storage for environment variables. It has its own format
which is sensitive to corruption if an editor does not know how to
process it. Besides that the editor may inadvertently change grubenv
file size and/or make it sparse which can lead to unexpected results.

This patch adds a message to the grubenv file to warn a user against
editing it by tools other than grub-editenv.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agohostdisk: Set linux file descriptor to O_CLOEXEC as default
Michael Chang [Tue, 5 Nov 2019 09:19:26 +0000 (09:19 +0000)]
hostdisk: Set linux file descriptor to O_CLOEXEC as default

We are often bothered by this sort of lvm warning while running grub-install
every now and then:

  File descriptor 4 (/dev/vda1) leaked on vgs invocation. Parent PID 1991: /usr/sbin/grub2-install

The requirement related to the warning is dictated in the lvm man page:

  "On invocation, lvm requires that only the standard file descriptors stdin,
  stdout and stderr are available.  If others are found, they get closed and
  messages are issued warning about the leak.  This warning can be suppressed by
  setting the environment variable LVM_SUPPRESS_FD_WARNINGS."

While it could be disabled through settings, most Linux distributions seem to
enable it by default and the justification provided by the developer looks to
be valid to me: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466138#15

Rather than trying to close and reopen the file descriptor to the same file
multiple times, which is rather cumbersome, for the sake of no vgs invocation
could happen in between. This patch enables the close-on-exec flag (O_CLOEXEC)
for new file descriptor returned by the open() system call, making it closed
thus not inherited by the child process forked and executed by the exec()
family of functions.

Fixes Debian bug #466138.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agogrub-mkconfig: Use portable "command -v" to detect installed programs
Eli Schwartz [Thu, 17 Oct 2019 03:03:06 +0000 (23:03 -0400)]
grub-mkconfig: Use portable "command -v" to detect installed programs

The "which" utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either.

Conversely, the "command -v" shell builtin is required to exist in all
POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.

Examples of open-source shells likely to be installed as /bin/sh on
Linux, which implement the 11-year-old standard: ash, bash, busybox,
dash, ksh, mksh and zsh.

A side benefit of using the POSIX portable option is that it requires
neither an external disk executable, nor (because unlike "which", the
exit code is reliable) a subshell fork. This therefore represents a mild
speedup.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotemplates: Add GRUB_DISABLE_UUID
Peter Jones [Tue, 22 Oct 2019 08:44:28 +0000 (10:44 +0200)]
templates: Add GRUB_DISABLE_UUID

The grub-mkconfig and 10_linux scripts by default attempt to use a UUID to
set the root kernel command line parameter and the $root GRUB environment
variable.

The former can be disabled by setting the GRUB_DISABLE_LINUX_UUID variable
to "true", but there is currently no way to disable the latter.

The generated grub config uses the search command with the --fs-uuid option
to find the device that has to be set as $root, i.e:

 search --no-floppy --fs-uuid --set=root ...

This is usually more reliable but in some cases it may not be appropriate,
so this patch introduces a new GRUB_DISABLE_UUID variable that can be used
to disable searching for the $root device by filesystem UUID.

When disabled, the $root device will be set to the value specified in the
device.map as found by the grub-probe --target=compatibility_hint option.

When setting GRUB_DISABLE_UUID=true, the GRUB_DISABLE_LINUX_UUID and
GRUB_DISABLE_LINUX_PARTUUID variables will also be set to "true" unless
these have been explicitly set to "false".

That way, the GRUB_DISABLE_UUID variable can be used to force using the
device names for both GRUB and Linux.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Nicholas Vinson <nvinson234@gmail.com>
4 years agoat_keyboard: Fix unreliable key presses
Michael Bideau [Wed, 2 Oct 2019 21:48:10 +0000 (23:48 +0200)]
at_keyboard: Fix unreliable key presses

This patch fixes an issue that prevented the at_keyboard module to work
(for me). The cause was a bad/wrong return value in the
grub_at_keyboard_getkey() function in grub-core/term/at_keyboard.c file
at line 237. My symptoms were to have an unresponsive keyboard. Keys
needed to be pressed 10x and more to effectively be printed sometimes
generating multiple key presses (after 1 or 2 sec of no printing). It
was very problematic when typing passphrase in early stage (with
GRUB_ENABLE_CRYPTODISK). When switched to "console" terminal input
keyboard worked perfectly. It also worked great with the GRUB 2.02
packaged by Debian (2.02+dfsg1-20). It was not an output issue but an
input one.

I've managed to analyze the issue and found that it came from the commit
216950a4e (at_keyboard: Split protocol from controller code.). Three
lines where moved from the fetch_key() function in
grub-core/term/at_keyboard.c file to the beginning of
grub_at_keyboard_getkey() function (same file). However, returning -1
made sense when it happened in fetch_key() function but not anymore in
grub_at_keyboard_getkey() function which should return GRUB_TERM_NO_KEY.
I think it was just an incomplete cut-paste missing a small manual
correction. Let's fix it.

Note: Commit message updated by Daniel Kiper.

Signed-off-by: Michael Bideau <mica.devel@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agotemplates: Fix bad test on GRUB_DISABLE_SUBMENU
Prarit Bhargava [Mon, 30 Sep 2019 15:00:16 +0000 (17:00 +0200)]
templates: Fix bad test on GRUB_DISABLE_SUBMENU

The GRUB_DISABLE_SUBMENU option is different than the others in the sense
that it has to be set to "y" instead of "true" to be enabled.

That causes a lot of confusion to users, some may wrongly set it to "true"
expecting that will work the same than with most options, and some may set
it to "yes" since for other options the value to set is a word and not a
single character.

This patch changes all the grub.d scripts using the GRUB_DISABLE_SUBMENU
option, so they check if it was set to "true" instead of "y", making it
consistent with all the other options.

But to keep backward compatibility for users that set the option to "y" in
/etc/default/grub file, keep testing for this value. And also do it for
"yes", since it is a common mistake made by users caused by this option
being inconsistent with the others.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
4 years agoprobe: Support probing for msdos PARTUUID
Nicholas Vinson [Mon, 30 Sep 2019 12:27:59 +0000 (08:27 -0400)]
probe: Support probing for msdos PARTUUID

Extend partition UUID probing support in GRUB core to display pseudo
partition UUIDs for MBR (MSDOS) partitions.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogrub-mkconfig: Fix typo in --help output
Colin Watson [Fri, 23 Aug 2019 11:00:30 +0000 (12:00 +0100)]
grub-mkconfig: Fix typo in --help output

The short form of "--version" that grub-mkconfig accepts is "-V", not "-v".

Fixes Debian bug #935504.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogrub-install: Define default platform for RISC-V
Andreas Schwab [Thu, 15 Aug 2019 14:55:13 +0000 (16:55 +0200)]
grub-install: Define default platform for RISC-V

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Alexander Graf <agraf@csgraf.de>
5 years agoRISC-V: Add __clzdi2 symbol
Andreas Schwab [Thu, 19 Sep 2019 07:39:04 +0000 (09:39 +0200)]
RISC-V: Add __clzdi2 symbol

This is needed for the zstd module build for riscv64-emu.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogitattributes: Mark po/exclude.pot as binary so git won't try to diff nonprintables
Peter Jones [Tue, 17 Sep 2019 15:50:58 +0000 (17:50 +0200)]
gitattributes: Mark po/exclude.pot as binary so git won't try to diff nonprintables

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogrub-mkconfig: Honor a symlink when generating configuration by grub-mkconfig
Marcel Kolaja [Tue, 17 Sep 2019 15:47:36 +0000 (17:47 +0200)]
grub-mkconfig: Honor a symlink when generating configuration by grub-mkconfig

Honor a symlink when generating configuration by grub-mkconfig, so that
the -o option follows it rather than overwriting it with a regular file.

Signed-off-by: Marcel Kolaja <mkolaja@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet: Fix crash on http
Gustavo Luiz Duarte [Tue, 17 Sep 2019 15:44:58 +0000 (17:44 +0200)]
net: Fix crash on http

Don't free file->data on receiving FIN flag since it is used all over
without checking. http_close() will be called later to free that memory.

Fixes bug: https://bugzilla.redhat.com/show_bug.cgi?id=860834

Signed-off-by: Gustavo Luiz Duarte <gustavold@linux.vnet.ibm.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agodocs: Document newly introduced net_dhcp command
Andre Przywara [Wed, 21 Aug 2019 15:58:34 +0000 (16:58 +0100)]
docs: Document newly introduced net_dhcp command

Commit 5bc41db756c5 ("net/dhcp: Add explicit net_dhcp command")
introduced the new command "net_dhcp", which (for now) is an alias for
the existing "net_bootp". Unfortunately the TEXI documentation was not
adjusted accordingly.

Rename the existing paragraph about net_bootp to read net_dhcp instead,
and make the net_bootp stanza point to this new command.

On the way add the newly parsed TFTP_SERVER_NAME and BOOTFILE_NAME
packets to the list of supported DHCP options.

Fixes bug: https://savannah.gnu.org/bugs/?56725

Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years ago[PATCH] sparc64: Fix BIOS Boot Partition support
James Clarke [Thu, 18 Jul 2019 12:31:55 +0000 (14:31 +0200)]
[PATCH] sparc64: Fix BIOS Boot Partition support

Currently, gpt_offset is uninitialised when using a BIOS Boot Partition
but is used unconditionally inside save_blocklists. Instead, ensure it
is always initialised to 0 (note that there is already separate code to
do the equivalent adjustment after we call save_blocklists on this code
path).

This patch has been tested on a T5-2 LDOM.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 util/setup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

5 years agoconfigure: Add -fno-ident when available
Vladimir Serbinenko [Tue, 9 Jul 2019 15:46:25 +0000 (17:46 +0200)]
configure: Add -fno-ident when available

MinGW for i386-pc without this option generates a .rdata$zzz symbol that is
page-aligned and hence lzma_decompress no longer fits in its allocated space.
Additionally, MinGW with -fno-ident also saves a bit of space in modules. In
case of other compilers we already strip the relevant sections, so, this
option has no effect.

More info can be found at https://github.com/msys2/MINGW-packages/issues/21

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agolsefisystab: Add support for device tree table
Heinrich Schuchardt [Sat, 6 Jul 2019 09:11:02 +0000 (11:11 +0200)]
lsefisystab: Add support for device tree table

The device tree may passed by the firmware as UEFI configuration
table. Let lsefisystab display a short text and not only the GUID
for the device tree.

Here is an example output:

  grub> lsefisystab
  Address: 0xbff694d8
  Signature: 5453595320494249 revision: 00020046
  Vendor: Das U-Boot, Version=20190700
  2 tables:
  0xbe741000  eb9d2d31-2d88-11d3-9a160090273fc14d   SMBIOS
  0x87f00000  b1b621d5-f19c-41a5-830bd9152c69aae0   DEVICE TREE

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agosmbios: Add a module for retrieving SMBIOS information
David Michael [Fri, 5 Jul 2019 12:47:09 +0000 (08:47 -0400)]
smbios: Add a module for retrieving SMBIOS information

The following are two use cases from Rajat Jain <rajatjain@juniper.net>:

  1) We have a board that boots Linux and this board itself can be plugged
     into one of different chassis types. We need to pass different
     parameters to the kernel based on the "CHASSIS_TYPE" information
     that is passed by the bios in the DMI/SMBIOS tables.

  2) We may have a USB stick that can go into multiple boards, and the
     exact kernel to be loaded depends on the machine information
     (PRODUCT_NAME etc) passed via the DMI.

Signed-off-by: David Michael <fedora.dm0@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agolsefisystab: Define SMBIOS3 entry point structures for EFI
David Michael [Fri, 5 Jul 2019 12:47:02 +0000 (08:47 -0400)]
lsefisystab: Define SMBIOS3 entry point structures for EFI

This adds the GUID and includes it in lsefisystab output.

Signed-off-by: David Michael <fedora.dm0@gmail.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoverifiers: Blocklist fallout cleanup
David Michael [Fri, 5 Jul 2019 11:45:59 +0000 (07:45 -0400)]
verifiers: Blocklist fallout cleanup

Blocklist fallout cleanup after commit 5c6f9bc15 (generic/blocklist: Fix
implicit declaration of function grub_file_filter_disable_compression()).

Signed-off-by: David Michael <fedora.dm0@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoRISC-V: Fix computation of pc-relative relocation offset
Andreas Schwab [Wed, 26 Jun 2019 14:50:03 +0000 (16:50 +0200)]
RISC-V: Fix computation of pc-relative relocation offset

The offset calculation was missing the relocation addend.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Tested-by: Chester Lin <clin@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoconfigure: Disable arm movw/movt relocations for GCC
Leif Lindholm [Tue, 4 Jun 2019 11:39:16 +0000 (12:39 +0100)]
configure: Disable arm movw/movt relocations for GCC

When building for arm, we already disable movw/movt relocations for clang,
since they are incompatible with PE.

When building with bare metal GCC toolchains (like the one used in the
travis ci scripts), we end up with these relocations again. So add an
additional test for the '-mword-relocations' flag used by GCC.

Reported-by: Alexander Graf <agraf@csgraf.de>
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoprobe: Support probing for partition UUID with --part-uuid
Jacob Kroon [Wed, 15 May 2019 19:04:43 +0000 (21:04 +0200)]
probe: Support probing for partition UUID with --part-uuid

Linux supports root=PARTUUID=<partuuid> boot argument, so add
support for probing it. Compared to the fs UUID, the partition
UUID does not change when reformatting a partition.

For now, only disks using a GPT partition table are supported.

Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoBump version to 2.05
Daniel Kiper [Fri, 5 Jul 2019 09:30:53 +0000 (11:30 +0200)]
Bump version to 2.05

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoRelease 2.04
Daniel Kiper [Mon, 1 Jul 2019 11:19:25 +0000 (13:19 +0200)]
Release 2.04

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agodocs: Document workaround for grub-mkrescue with older MacBooks
Thomas Schmitt [Thu, 20 Jun 2019 08:36:42 +0000 (10:36 +0200)]
docs: Document workaround for grub-mkrescue with older MacBooks

Add a description of the workaround for firmware of older MacBooks
which stalls with a grub-mkrescue ISO image for x86_64-efi target
on an USB stick.

Signed-off-by: Thomas Schmitt <scdbackup@gmx.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agodocs: Bootstrap changes required for older distros
Eric Snowberg [Wed, 19 Jun 2019 23:13:23 +0000 (17:13 -0600)]
docs: Bootstrap changes required for older distros

Some older distros do not contain gettext 0.18. Document the workaround
to use the bootstrap utility on these systems.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoia64: build fix in cache.h
Leif Lindholm [Thu, 6 Jun 2019 09:13:00 +0000 (10:13 +0100)]
ia64: build fix in cache.h

Add IA64 to the architectures excluding a declaration for
grub_arch_sync_dma_caches().

IA64 does not include any of the source files that require the function,
but was overlooked for d8901e3ba115 ("cache: Fix compilation for ppc,
sparc and arm64").

Add it to the list of excluding architectures in order to not get
missing symbol errors when running grub-mkimage.

Reported-by: Alexander Graf <agraf@csgraf.de>
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agohostfs: #undef open and close.
Vladimir 'phcoder' Serbinenko [Mon, 25 Mar 2019 15:24:50 +0000 (16:24 +0100)]
hostfs: #undef open and close.

Unlike in case of disks in this case it's just a single place, so it's easier
to just #undef

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agof2fs: Disable gcc9 -Waddress-of-packed-member
John Paul Adrian Glaubitz [Wed, 29 May 2019 06:34:55 +0000 (08:34 +0200)]
f2fs: Disable gcc9 -Waddress-of-packed-member

Disable the -Wadress-of-packaed-member diagnostic for the grub_f2fs_label
function since the result is found to be false postive.

A pointer to the 'volume_name' member of 'struct grub_f2fs_superblock' is
guaranteed to be aligned as the offset of 'volume_name' within the struct
is dividable by the natural alignment on both 32- and 64-bit targets.

grub-core/fs/f2fs.c: In function ‘grub_f2fs_label’:
grub-core/fs/f2fs.c:1253:60: error: taking address of packed member of ‘struct grub_f2fs_superblock’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
 1253 |     *label = (char *) grub_f2fs_utf16_to_utf8 (data->sblock.volume_name);
      |                                                ~~~~~~~~~~~~^~~~~~~~~~~~
cc1: all warnings being treated as errors

Reported-by: Neil MacLeod <neil@nmacleod.com>
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Tested-by: Neil MacLeod <neil@nmacleod.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogrub-mkrescue: Fix error message about the wrong command having failed: mformat inste...
Vincent Legoll [Sat, 27 Apr 2019 23:21:49 +0000 (01:21 +0200)]
grub-mkrescue: Fix error message about the wrong command having failed: mformat instead of mcopy

Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agovideo: skip 'text' gfxpayload if not supported, to fallback to default
Mathieu Trudel-Lapierre [Mon, 29 Apr 2019 17:57:02 +0000 (13:57 -0400)]
video: skip 'text' gfxpayload if not supported, to fallback to default

On UEFI, 'text' gfxpayload is not supported, but we still reach parse_modespec()
with it, which will obviously fail. Fortunately, whatever gfxpayload is set,
we still still have the 'auto' default to fall back to. Allow getting to this
fallback by not trying to parse 'text' as a modespec.

This is because 'text' correctly doesn't parse as a modespec, and ought to have
been ignored before we got to that point, just like it is immediately picked if
we're running on a system where 'text' is a supported video mode.

Bug: https://savannah.gnu.org/bugs/index.php?56217

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogrub-mkconfig: Use -c instead of --printf for stat
Ovidiu Panait [Tue, 14 May 2019 08:40:55 +0000 (11:40 +0300)]
grub-mkconfig: Use -c instead of --printf for stat

"--printf" only works with the stat variant provided by coreutils.

With busybox, stat will fail with the following error:
stat: unrecognized option '--printf=%T'

Usage: stat [OPTIONS] FILE...

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agof2fs: Fix gcc9 error -Werror=maybe-uninitialized
Michael Chang [Fri, 17 May 2019 09:00:19 +0000 (17:00 +0800)]
f2fs: Fix gcc9 error -Werror=maybe-uninitialized

The function grub_get_node_path() could return uninitialized offset with
level == 0 if the block is greater than direct_index + 2 * direct_blks +
2 * indirect_blks + dindirect_blks. The uninitialized offset is then used
by function grub_f2fs_get_block() because level == 0 is valid and
meaningful return to be processed.

The fix is to set level = -1 as return value by grub_get_node_path() to
signify an error that the input block cannot be handled. Any caller
should therefore check level is negative or not before processing the
output.

Reported-by: Neil MacLeod <neil@nmacleod.com>
Signed-off-by: Michael Chang <mchang@suse.com>
Tested-by: Neil MacLeod <neil@nmacleod.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoarm: Align section alignment with manual relocation offset code
Alexander Graf [Tue, 30 Apr 2019 20:43:57 +0000 (22:43 +0200)]
arm: Align section alignment with manual relocation offset code

The arm relocation code has a manual special case for EFI binaries to
add the natural alignment to its own relocation awareness.

Since commit a51f953f4ee87 ("mkimage: Align efi sections on 4k
boundary") we changed that alignment from 0x400 to 0x1000 bytes. Reflect
the change in that branch that we forgot as well.

This fixes running 32bit arm grub efi binaries for me again.

Fixes: a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary")
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reported-by: Steve McIntyre <steve@einval.com>
Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Julien ROBIN <julien.robin28@free.fr>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoarm: Move trampolines into code section
Alexander Graf [Tue, 30 Apr 2019 20:43:56 +0000 (22:43 +0200)]
arm: Move trampolines into code section

When creating T32->A32 transition jumps, the relocation code in grub
will generate trampolines. These trampolines live in the .data section
of our PE binary which means they are not marked as executable.

This misbehavior was unmasked by commit a51f953f4ee87 ("mkimage: Align
efi sections on 4k boundary") which made the X/NX boundary more obvious
because everything became page aligned.

To put things into proper order, let's move the arm trampolines into the
.text section instead. That way everyone knows they are executable.

Fixes: a51f953f4ee87 ("mkimage: Align efi sections on 4k boundary")
Reported-by: Julien ROBIN <julien.robin28@free.fr>
Reported-by: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Alexander Graf <agraf@csgraf.de>
Tested-by: Julien ROBIN <julien.robin28@free.fr>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoefi: Fix gcc9 error -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:09 +0000 (17:14 +0800)]
efi: Fix gcc9 error -Waddress-of-packed-member

The address of fp->path_name could be unaligned since seeking into the
device path buffer for a given node could end in byte boundary.

The fix is allocating aligned buffer by grub_malloc for holding the
UTF16 string copied from fp->path_name, and after using that buffer as
argument for grub_utf16_to_utf8 to convert it to UTF8 string.

[  255s] ../../grub-core/kern/efi/efi.c: In function 'grub_efi_get_filename':
[  255s] ../../grub-core/kern/efi/efi.c:410:60: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  255s]   410 |    p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len);
[  255s]       |                                                          ~~^~~~~~~~~~~
[  255s] ../../grub-core/kern/efi/efi.c: In function 'grub_efi_print_device_path':
[  255s] ../../grub-core/kern/efi/efi.c:900:33: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  255s]   900 |     *grub_utf16_to_utf8 (buf, fp->path_name,
[  255s]       |                               ~~^~~~~~~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agochainloader: Fix gcc9 error -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:08 +0000 (17:14 +0800)]
chainloader: Fix gcc9 error -Waddress-of-packed-member

The address of fp->path_name could be unaligned since seeking into the
device path buffer for a given node could end in byte boundary.

The fix is using aligned buffer allocated by grub_malloc for receiving
the converted UTF16 string by grub_utf8_to_utf16 and also the processing
after. The resulting string then gets copied to fp->path_name.

[  243s] ../../grub-core/loader/efi/chainloader.c: In function 'copy_file_path':
[  243s] ../../grub-core/loader/efi/chainloader.c:136:32: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  243s]   136 |   size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8,
[  243s]       |                              ~~^~~~~~~~~~~
[  243s] ../../grub-core/loader/efi/chainloader.c:138:12: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  243s]   138 |   for (p = fp->path_name; p < fp->path_name + size; p++)
[  243s]       |            ^~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agousbtest: Disable gcc9 -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:07 +0000 (17:14 +0800)]
usbtest: Disable gcc9 -Waddress-of-packed-member

Disable the -Wadress-of-packaed-member diagnostic for the
grub_usb_get_string function since the result is false postive. The
descstrp->str is found to be aligned in the buffer allocated for 'struct
grub_usb_desc_str'.

[  229s] ../../grub-core/commands/usbtest.c: In function 'grub_usb_get_string':
[  229s] ../../grub-core/commands/usbtest.c:104:58: error: taking address of packed member of 'struct grub_usb_desc_str' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  229s]   104 |   *grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str,
[  229s]       |                                                  ~~~~~~~~^~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoacpi: Fix gcc9 error -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:06 +0000 (17:14 +0800)]
acpi: Fix gcc9 error -Waddress-of-packed-member

Simply adds the missing packed attribute to 'struct grub_acpi_madt'.

[  233s] ../../grub-core/commands/lsacpi.c: In function 'disp_acpi_xsdt_table':
[  233s] ../../grub-core/commands/lsacpi.c:201:27: error: converting a packed 'struct grub_acpi_table_header' pointer (alignment 1) to a 'struct grub_acpi_madt' pointer (alignment 4) may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  233s]   201 |  disp_madt_table ((struct grub_acpi_madt *) t);
[  233s]       |                           ^~~~~~~~~~~~~~
[  233s] In file included from ../../grub-core/commands/lsacpi.c:23:
[  233s] ../../include/grub/acpi.h:50:8: note: defined here
[  233s]    50 | struct grub_acpi_table_header
[  233s]       |        ^~~~~~~~~~~~~~~~~~~~~~
[  233s] ../../include/grub/acpi.h:90:8: note: defined here
[  233s]    90 | struct grub_acpi_madt
[  233s]       |        ^~~~~~~~~~~~~~
[  233s] ../../grub-core/commands/lsacpi.c: In function 'disp_acpi_rsdt_table':
[  233s] ../../grub-core/commands/lsacpi.c:225:27: error: converting a packed 'struct grub_acpi_table_header' pointer (alignment 1) to a 'struct grub_acpi_madt' pointer (alignment 4) may result in an unaligned pointer value [-Werror=address-of-packed-member]
[  233s]   225 |  disp_madt_table ((struct grub_acpi_madt *) t);
[  233s]       |                           ^~~~~~~~~~~~~~
[  233s] In file included from ../../grub-core/commands/lsacpi.c:23:
[  233s] ../../include/grub/acpi.h:50:8: note: defined here
[  233s]    50 | struct grub_acpi_table_header
[  233s]       |        ^~~~~~~~~~~~~~~~~~~~~~
[  233s] ../../include/grub/acpi.h:90:8: note: defined here
[  233s]    90 | struct grub_acpi_madt
[  233s]       |        ^~~~~~~~~~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agohfsplus: Fix gcc9 error with -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:05 +0000 (17:14 +0800)]
hfsplus: Fix gcc9 error with -Waddress-of-packed-member

The catkey->name could be unaligned since the address of 'void* record'
is calculated as offset in bytes to a malloc buffer.

The fix is using aligned buffer allocated by grub_malloc for holding
the UTF16 string copied from catkey->name. And use that buffer as
argument for grub_utf16_to_utf8 to convert to UTF8 strings.

In addition, using a new copy of buffer rather than catkey->name itself
for processing the endianess conversion, we can also get rid of the hunk
restoring byte order of catkey->name to what it was previously.

[   59s] ../grub-core/fs/hfsplus.c: In function 'list_nodes':
[   59s] ../grub-core/fs/hfsplus.c:738:57: error: taking address of packed member of 'struct grub_hfsplus_catkey' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]   738 |   *grub_utf16_to_utf8 ((grub_uint8_t *) filename, catkey->name,
[   59s]       |                                                   ~~~~~~^~~~~~
[   59s] ../grub-core/fs/hfsplus.c: In function 'grub_hfsplus_label':
[   59s] ../grub-core/fs/hfsplus.c:1019:57: error: taking address of packed member of 'struct grub_hfsplus_catkey' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]  1019 |   *grub_utf16_to_utf8 ((grub_uint8_t *) (*label), catkey->name,
[   59s]       |                                                   ~~~~~~^~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agohfs: Fix gcc9 error -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:04 +0000 (17:14 +0800)]
hfs: Fix gcc9 error -Waddress-of-packed-member

Simply adds the missing packed attribute to 'struct grub_hfs_extent'.

[   83s] ../grub-core/fs/hfs.c: In function 'grub_hfs_iterate_records':
[   83s] ../grub-core/fs/hfs.c:699:9: error: taking address of packed member of 'struct grub_hfs_sblock' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   83s]   699 |      ? (&data->sblock.catalog_recs)
[   83s]       |        ~^~~~~~~~~~~~~~~~~~~~~~~~~~~
[   83s] ../grub-core/fs/hfs.c:700:9: error: taking address of packed member of 'struct grub_hfs_sblock' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   83s]   700 |      : (&data->sblock.extent_recs));
[   83s]       |        ~^~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agojfs: Disable gcc9 -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:03 +0000 (17:14 +0800)]
jfs: Disable gcc9 -Waddress-of-packed-member

Disable the -Wadress-of-packaed-member diagnostic for the
grub_jfs_getent function since the result is found to be false postive.

The leaf is read into memory as continous chunks in size of 32 bytes and
the pointer to its base is aligned, which also guarentee its member
leaf->namepart is aligned.

[   60s] ../grub-core/fs/jfs.c: In function 'grub_jfs_getent':
[   60s] ../grub-core/fs/jfs.c:557:44: error: taking address of packed member of 'struct grub_jfs_leaf_dirent' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   60s]   557 |   le_to_cpu16_copy (filename + strpos, leaf->namepart, len < diro->data->namecomponentlen ? len
[   60s]       |                                        ~~~~^~~~~~~~~~
[   60s] ../grub-core/fs/jfs.c:570:48: error: taking address of packed member of 'struct grub_jfs_leaf_next_dirent' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   60s]   570 |  le_to_cpu16_copy (filename + strpos, next_leaf->namepart, len < 15 ? len : 15);
[   60s]       |                                       ~~~~~~~~~^~~~~~~~~~
[   60s] cc1: all warnings being treated as errors

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agocpio: Disable gcc9 -Waddress-of-packed-member
Michael Chang [Thu, 11 Apr 2019 09:14:02 +0000 (17:14 +0800)]
cpio: Disable gcc9 -Waddress-of-packed-member

Disable the -Wadress-of-packaed-member diagnostic for the
grub_cpio_find_file function since the result is found to be false
postive. Any pointers to member of the 'struct head hd' is aligned even
if the structure is packed without paddings.

[   59s] In file included from ../grub-core/fs/cpio.c:51:
[   59s] ../grub-core/fs/cpio_common.c: In function 'grub_cpio_find_file':
[   59s] ../grub-core/fs/cpio_common.c:58:31: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    58 |   data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize));
[   59s]       |                             ~~^~~~~~~~~
[   59s] ../grub-core/fs/cpio_common.c:60:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    60 |     *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime));
[   59s]       |                           ~~^~~~~~
[   59s] ../grub-core/fs/cpio_common.c:61:28: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    61 |   modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode));
[   59s]       |                          ~~^~~~~
[   59s] ../grub-core/fs/cpio_common.c:62:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    62 |   namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize));
[   59s]       |                           ~~^~~~~~~~~
[   59s] In file included from ../grub-core/fs/cpio_be.c:51:
[   59s] ../grub-core/fs/cpio_common.c: In function 'grub_cpio_find_file':
[   59s] ../grub-core/fs/cpio_common.c:58:31: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    58 |   data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize));
[   59s]       |                             ~~^~~~~~~~~
[   59s] ../grub-core/fs/cpio_common.c:60:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    60 |     *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime));
[   59s]       |                           ~~^~~~~~
[   59s] ../grub-core/fs/cpio_common.c:61:28: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    61 |   modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode));
[   59s]       |                          ~~^~~~~
[   59s] ../grub-core/fs/cpio_common.c:62:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    62 |   namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize));
[   59s]       |                           ~~^~~~~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoefi: Avoid NULL dereference if FilePath is NULL
Heinrich Schuchardt [Wed, 17 Apr 2019 05:12:56 +0000 (07:12 +0200)]
efi: Avoid NULL dereference if FilePath is NULL

The UEFI specification allows LoadImage() to be called with a memory
location only and without a device path. In this case FilePath will not be
set in the EFI_LOADED_IMAGE_PROTOCOL.

So in function grub_efi_get_filename() the device path argument may be
NULL. As we cannot determine the device path in this case just return NULL
from the function.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agox86/msr: Fix build with older GCC versions
Daniel Kiper [Fri, 12 Apr 2019 10:50:04 +0000 (12:50 +0200)]
x86/msr: Fix build with older GCC versions

Some older GCC versions produce following error when x86 MSR modules are build:

  In file included from commands/i386/rdmsr.c:29:0:
  ../include/grub/i386/rdmsr.h:27:29: error: no previous prototype for ‘grub_msr_read’ [-Werror=missing-prototypes]
   extern inline grub_uint64_t grub_msr_read (grub_uint32_t msr_id)
                               ^
  cc1: all warnings being treated as errors

This happens due to lack of support for a such usage of extern keyword
in older GCCs. Additionally, this usage is not consistent with the rest
of codebase. So, replace it with static keyword.

Additionally, fix incorrect coding style.

Reported-by: Eric Snowberg <eric.snowberg@oracle.com>
Reported-by: adrian15 <adrian15sgd@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Reviewed-by: Eric Snowberg <eric.snowberg@oracle.com>
Tested-by: adrian15 <adrian15sgd@gmail.com>
5 years agoRelease 2.04~rc1
Vladimir Serbinenko [Mon, 8 Apr 2019 05:30:56 +0000 (07:30 +0200)]
Release 2.04~rc1

5 years agoChange fs functions to add fs_ prefix
Vladimir Serbinenko [Mon, 8 Apr 2019 05:24:24 +0000 (07:24 +0200)]
Change fs functions to add fs_ prefix

This avoid conflict with gnulib

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoA workaround for clang problem assembling startup_raw.S
Vladimir Serbinenko [Tue, 26 Mar 2019 13:56:59 +0000 (14:56 +0100)]
A workaround for clang problem assembling startup_raw.S

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoieee1275: NULL pointer dereference in grub_ieee1275_encode_devname()
Eric Snowberg [Tue, 2 Apr 2019 16:40:31 +0000 (09:40 -0700)]
ieee1275: NULL pointer dereference in grub_ieee1275_encode_devname()

Function grub_strndup() may return NULL, this is called from
function grub_ieee1275_get_devname() which is then called from
function grub_ieee1275_encode_devname() to set device. The device
variable could then be used with a NULL pointer.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agodocs/grub-dev: Change comments rules
Daniel Kiper [Fri, 29 Mar 2019 15:11:04 +0000 (16:11 +0100)]
docs/grub-dev: Change comments rules

Current comments forms are annoying, so, some of them are disallowed
starting from now. New rules are more flexible and mostly aligned
with, e.g., Linux kernel comments rules.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoloader/i386/linux: Calculate the setup_header length
Andrew Jeddeloh [Fri, 29 Mar 2019 15:09:54 +0000 (16:09 +0100)]
loader/i386/linux: Calculate the setup_header length

Previously the setup_header length was just assumed to be the size of the
linux_kernel_params struct. The linux x86 32-bit boot protocol says that the
end of the linux_i386_kernel_header is at 0x202 + the byte value at 0x201 in
the linux_i386_kernel_header. So, calculate the size of the header using the
end of the linux_i386_kernel_header, rather than assume it is the size of the
linux_kernel_params struct.

Additionally, add some required members to the linux_kernel_params
struct and align the content of linux_i386_kernel_header struct with
it. New members naming was taken directly from Linux kernel source.

linux_kernel_params and linux_i386_kernel_header structs require more
cleanup. However, this is not urgent, so, let's do this after release.
Just in case...

Signed-off-by: Andrew Jeddeloh <andrew.jeddeloh@coreos.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agoefidisk: NULL pointer dereference in grub_efidisk_get_device_name()
Eric Snowberg [Thu, 28 Mar 2019 21:26:37 +0000 (15:26 -0600)]
efidisk: NULL pointer dereference in grub_efidisk_get_device_name()

Function grub_efi_find_last_device_path() may return NULL when called
from grub_efidisk_get_device_name().

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoefidisk: NULL pointer dereference in is_child()
Eric Snowberg [Thu, 28 Mar 2019 21:26:36 +0000 (15:26 -0600)]
efidisk: NULL pointer dereference in is_child()

Function grub_efi_find_last_device() path may return NULL when called
from is_child().

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoefidisk: Write to NULL pointer ldp
Eric Snowberg [Thu, 28 Mar 2019 20:32:31 +0000 (14:32 -0600)]
efidisk: Write to NULL pointer ldp

Function grub_efi_find_last_device_path() may return constant NULL when
called from find_parent_device().

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoclang: Pair -Qn with -Qunused-arguments.
Vladimir Serbinenko [Mon, 25 Mar 2019 16:43:18 +0000 (17:43 +0100)]
clang: Pair -Qn with -Qunused-arguments.

When assembling module wirh clang -Qn ends up on command line but later ignored
To avoid it breaking the compile, add -Qunused-arguments.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoieee1275: Fix path reference in comment of sparc64 boot loader code
John Paul Adrian Glaubitz [Tue, 26 Mar 2019 10:21:56 +0000 (11:21 +0100)]
ieee1275: Fix path reference in comment of sparc64 boot loader code

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoieee1275: Include a.out header in assembly of sparc64 boot loader
John Paul Adrian Glaubitz [Tue, 26 Mar 2019 09:47:16 +0000 (10:47 +0100)]
ieee1275: Include a.out header in assembly of sparc64 boot loader

Recent versions of binutils dropped support for the a.out and COFF
formats on sparc64 targets. Since the boot loader on sparc64 is
supposed to be an a.out binary and the a.out header entries are
rather simple to calculate in our case, we just write the header
ourselves instead of relying on external tools to do that.

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoPropagate GNU_PRINTF from gnulib vfprintf
Vladimir Serbinenko [Fri, 22 Mar 2019 15:13:11 +0000 (16:13 +0100)]
Propagate GNU_PRINTF from gnulib vfprintf

gnulib now replaces vfprintf and hence its format becomes GNU_PRINTF format

This also fixes matching definitions to always use GNU format

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoefi/tpm.c: Add missing casts
Vladimir Serbinenko [Fri, 22 Mar 2019 15:07:47 +0000 (16:07 +0100)]
efi/tpm.c: Add missing casts

Without those casts we get a warning about implicit conversion of pointer
to integer.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoPOTFILES: Don't include gnulib in grub.pot
Vladimir Serbinenko [Fri, 22 Mar 2019 15:06:18 +0000 (16:06 +0100)]
POTFILES: Don't include gnulib in grub.pot

They're translated as a separate project, so we
don't want to submit them again.

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoconfigure.ac: Use nostdlib when checking for nostdinc
Vladimir Serbinenko [Mon, 25 Mar 2019 15:09:04 +0000 (16:09 +0100)]
configure.ac: Use nostdlib when checking for nostdinc

With clang nostdinc behaviour is influenced by nostdlib. Since we
always add nostdlib, add it in test as well

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoefi/tpm.h: Fix hash_log_extend_event definition.
Vladimir Serbinenko [Fri, 22 Mar 2019 16:12:57 +0000 (17:12 +0100)]
efi/tpm.h: Fix hash_log_extend_event definition.

I didn't check the spec but pointer to address doesn't make much sense
and doesn't match the code.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoRename grub_disk members
Vladimir Serbinenko [Fri, 22 Mar 2019 16:07:00 +0000 (17:07 +0100)]
Rename grub_disk members

Otherwise it horribly clashes with gnulib when it's
replacing open/write/read/close

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agogrub-mkimagexx: Fix RISCV error message
Vladimir Serbinenko [Fri, 22 Mar 2019 16:11:14 +0000 (17:11 +0100)]
grub-mkimagexx: Fix RISCV error message

Outputting a raw pointer doesn't match the format and is
also useless. Output offset instead.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agokern/emu/misc.c: Don't include config-util.h when running as GRUB_BUILD
Vladimir Serbinenko [Fri, 22 Mar 2019 16:19:38 +0000 (17:19 +0100)]
kern/emu/misc.c: Don't include config-util.h when running as GRUB_BUILD

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agoSupport R_PPC_PLTREL24
Vladimir Serbinenko [Fri, 22 Mar 2019 20:24:24 +0000 (21:24 +0100)]
Support R_PPC_PLTREL24

It's emitted by clang 7. It's the same as R_PPC_REL24.

Signed-off-by: Vladimir Serbinenko <phcoder@google.com>
5 years agosparc: Enable __clzsi2() and __clzdi2()
Daniel Kiper [Tue, 19 Mar 2019 09:51:01 +0000 (10:51 +0100)]
sparc: Enable __clzsi2() and __clzdi2()

This patch is similiar to commit e795b9011 (RISC-V: Add libgcc helpers
for clz) but for SPARC target.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agomips: Enable __clzsi2()
Daniel Kiper [Mon, 18 Mar 2019 12:19:05 +0000 (13:19 +0100)]
mips: Enable __clzsi2()

This patch is similiar to commit e795b9011 (RISC-V: Add libgcc helpers
for clz) but for MIPS target.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agoverifiers: MIPS fallout cleanup
Daniel Kiper [Mon, 18 Mar 2019 12:09:22 +0000 (13:09 +0100)]
verifiers: MIPS fallout cleanup

MIPS fallout cleanup after commit 4d4a8c96e (verifiers: Add possibility
to verify kernel and modules command lines).

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agoverifiers: PowerPC fallout cleanup
Daniel Kiper [Thu, 14 Mar 2019 18:45:17 +0000 (19:45 +0100)]
verifiers: PowerPC fallout cleanup

PowerPC fallout cleanup after commit 4d4a8c96e (verifiers: Add possibility
to verify kernel and modules command lines) and ca0a4f689 (verifiers: File
type for fine-grained signature-verification controlling).

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agoverifiers: IA-64 fallout cleanup
Daniel Kiper [Thu, 14 Mar 2019 15:18:31 +0000 (16:18 +0100)]
verifiers: IA-64 fallout cleanup

IA-64 fallout cleanup after commit 4d4a8c96e (verifiers: Add possibility
to verify kernel and modules command lines).

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
5 years agoposix_wrap: Flesh out posix_wrap/limits.h a little more
Colin Watson [Tue, 19 Mar 2019 10:26:18 +0000 (10:26 +0000)]
posix_wrap: Flesh out posix_wrap/limits.h a little more

In addition to what was already there, Gnulib's <intprops.h> needs SCHAR_MIN,
SCHAR_MAX, SHRT_MIN, INT_MIN, LONG_MIN, and LONG_MAX. Fixes build on CentOS 7.

Reported-by: "Chen, Farrah" <farrah.chen@intel.com>
Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoxen: Look for Xen notes in section headers too
Marek Marczykowski-Górecki [Thu, 14 Mar 2019 01:57:08 +0000 (02:57 +0100)]
xen: Look for Xen notes in section headers too

Mirror behaviour of ELF loader in libxc: first look for Xen notes in
PT_NOTE segment, then in SHT_NOTE section and only then fallback to
a section with __xen_guest name. This fixes loading PV kernels that
Xen note have outside of PT_NOTE. While this may be result of a buggy
linker script, loading such kernel directly works fine, so make it work
with GRUB too. Specifically, this applies to binaries built from Unikraft.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agogetroot: Save/restore CWD more reliably on Unix
Colin Watson [Sat, 9 Mar 2019 14:37:17 +0000 (14:37 +0000)]
getroot: Save/restore CWD more reliably on Unix

Various GRUB utilities fail if the current directory doesn't exist,
because grub_find_device() chdirs to a different directory and then
fails when trying to chdir back.  Gnulib's save-cwd module uses fchdir()
instead when it can, avoiding this category of problem.

Fixes Debian bug #918700.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Add explicit net_dhcp command
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:16 +0000 (15:14 +0000)]
net/dhcp: Add explicit net_dhcp command

Mostly for cosmetic reasons, we add a "net_dhcp" command, which is (at the
moment) identical to the existing "net_bootp" command. Both actually trigger
a DHCP handshake now, and both should be able to deal with pure BOOTP servers.
We could think about dropping the DHCP options from the initial DISCOVER packet
when the user issues the net_bootp command, but it's unclear whether this is
really useful, as both protocols should be able to coexist.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Actually send out DHCPv4 DISCOVER and REQUEST messages
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:15 +0000 (15:14 +0000)]
net/dhcp: Actually send out DHCPv4 DISCOVER and REQUEST messages

Even though we were parsing some DHCP options sent by the server, so far
we are only using the BOOTP 2-way handshake, even when talking to a DHCP
server.

Change this by actually sending out DHCP DISCOVER packets instead of the
generic (mostly empty) BOOTP BOOTREQUEST packets.

A pure BOOTP server would ignore the extra DHCP options in the DISCOVER
packet and would just reply with a BOOTREPLY packet, which we also
handle in the code.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Allow receiving DHCP OFFER and ACK packets
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:14 +0000 (15:14 +0000)]
net/dhcp: Allow receiving DHCP OFFER and ACK packets

In respone to a BOOTREQUEST packet a BOOTP server would answer with a BOOTREPLY
packet, which ends the conversation for good. DHCP uses a 4-way handshake,
where the initial server respone is an OFFER, which has to be answered with
REQUEST by the client again, only to be completed by an ACKNOWLEDGE packet
from the server.

Teach the grub_net_process_dhcp() function to deal with OFFER packets,
and treat ACK packets the same es BOOTREPLY packets.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Use DHCP options for name and bootfile
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:13 +0000 (15:14 +0000)]
net/dhcp: Use DHCP options for name and bootfile

The BOOTP RFC describes the boot file name and the server name as being part
of the integral BOOTP data structure, with some limits on the size of them.
DHCP extends this by allowing them to be separate DHCP options, which is more
flexible.

Teach the code dealing with those fields to check for those DHCP options first
and use this information, if provided. We fall back to using the BOOTP
information if those options are not used.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Introduce per-interface timeout
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:12 +0000 (15:14 +0000)]
net/dhcp: Introduce per-interface timeout

Currently we have a global timeout for all network cards in the BOOTP/DHCP
discovery process.

Make this timeout a per-interface one, so better accommodate the upcoming
4-way DHCP handshake and to also cover the lease time limit a DHCP offer
will come with.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Make grub_net_process_dhcp() take an interface
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:11 +0000 (15:14 +0000)]
net/dhcp: Make grub_net_process_dhcp() take an interface

Change the interface of the function dealing with incoming BOOTP packets
to take an interface instead of a card, to allow more fine per-interface
state (timeout, handshake state) later on.

Use the opportunity to clean up the code a bit.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Refactor DHCP packet transmission into separate function
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:10 +0000 (15:14 +0000)]
net/dhcp: Refactor DHCP packet transmission into separate function

In contrast to BOOTP, DHCP uses a 4-way handshake, so requires to send
packets more often.

Refactor the generation and sending of the BOOTREQUEST packet into
a separate function, so that future code can more easily reuse this.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Allow overloading legacy bootfile and name field
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:09 +0000 (15:14 +0000)]
net/dhcp: Allow overloading legacy bootfile and name field

DHCP specifies a special dummy option OVERLOAD, to allow DHCP options to
spill over into the (legacy) BOOTFILE and SNAME fields.

Parse and handle this option properly.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Replace parse_dhcp_vendor() with find_dhcp_option()
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:08 +0000 (15:14 +0000)]
net/dhcp: Replace parse_dhcp_vendor() with find_dhcp_option()

For proper DHCP support we will need to parse DHCP options from a packet
more often and at various places.

Refactor the option parsing into a new function, which will scan a packet to
find *a particular* option field. Use that new function in places where we
were dealing with DHCP options before.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agonet/dhcp: Remove dead code
Andrei Borzenkov [Thu, 7 Mar 2019 15:14:07 +0000 (15:14 +0000)]
net/dhcp: Remove dead code

The comment is right, the "giaddr" fields holds the IP address of the BOOTP
relay, not a general purpose router address. Just remove the commented code,
archeologists can find it in the git history.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agomsr: Add new MSR modules (rdmsr/wrmsr)
Jesús Diéguez Fernández [Fri, 8 Mar 2019 00:26:37 +0000 (01:26 +0100)]
msr: Add new MSR modules (rdmsr/wrmsr)

In order to be able to read from and write to model-specific registers,
two new modules are added. They are i386 specific, as the cpuid module.

rdmsr module registers the command rdmsr that allows reading from a MSR.
wrmsr module registers the command wrmsr that allows writing to a MSR.

wrmsr module is disabled if UEFI secure boot is enabled.

Please note that on SMP systems, interacting with a MSR that has a scope
per hardware thread, implies that the value only applies to the
particular cpu/core/thread that ran the command.

Also, if you specify a reserved or unimplemented MSR address, it will
cause a general protection exception (which is not currently being
handled) and the system will reboot.

Signed-off-by: Jesús Diéguez Fernández <jesusdf@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoasm: Replace "__asm__ __volatile__" with "asm volatile"
Jesús Diéguez Fernández [Fri, 8 Mar 2019 00:26:36 +0000 (01:26 +0100)]
asm: Replace "__asm__ __volatile__" with "asm volatile"

In order to maintain the coding style consistency, it was requested to
replace the methods that use "__asm__ __volatile__" with "asm volatile".

Signed-off-by: Jesús Diéguez Fernández <jesusdf@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agosparc64: Add bios boot partition support
Eric Snowberg [Tue, 5 Mar 2019 01:34:01 +0000 (17:34 -0800)]
sparc64: Add bios boot partition support

Add BIOS Boot Partition support for sparc64 platforms.  This will work a
little different than x86.  With GPT, both the OBP "load" and "boot" commands
are partition aware and neither command can see the partition table.  Therefore
the entire boot-loader is stored within the BIOS Boot Partition and nothing
is stored within the bootstrap code area of MBR.

To use it, the end user will issue the boot command with the path pointing to
the BIOS Boot Partition.

For example with the disk below:

Model: Unknown (unknown)
Disk /dev/nvme1n1: 1600GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name  Flags
1      1049kB  1075MB  1074MB   ext3
2      1075MB  1076MB  1049kB                     bios_grub
3      1076MB  1600GB  1599GB                     lvm

To boot grub2 from OBP, you would use:

boot /pci@302/pci@1/pci@0/pci@13/nvme@0/disk@1:b

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoieee1275: obdisk driver
Eric Snowberg [Tue, 5 Mar 2019 01:27:39 +0000 (17:27 -0800)]
ieee1275: obdisk driver

Add a new disk driver called obdisk for IEEE1275 platforms.  Currently
the only platform using this disk driver is SPARC, however other IEEE1275
platforms could start using it if they so choose.  While the functionality
within the current IEEE1275 ofdisk driver may be suitable for PPC and x86, it
presented too many problems on SPARC hardware.

Within the old ofdisk, there is not a way to determine the true canonical
name for the disk.  Within Open Boot, the same disk can have multiple names
but all reference the same disk.  For example the same disk can be referenced
by its SAS WWN, using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@w5000cca02f037d6d,0

It can also be referenced by its PHY identifier using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@p0

It can also be referenced by its Target identifier using this form:

/pci@302/pci@2/pci@0/pci@17/LSI,sas@0/disk@0

Also, when the LUN=0, it is legal to omit the ,0 from the device name.  So with
the disk above, before taking into account the device aliases, there are 6 ways
to reference the same disk.

Then it is possible to have 0 .. n device aliases all representing the same disk.
Within this new driver the true canonical name is determined using the the
IEEE1275 encode-unit and decode-unit commands when address_cells == 4.  This
will determine the true single canonical name for the device so multiple ihandles
are not opened for the same device.  This is what frequently happens with the old
ofdisk driver.  With some devices when they are opened multiple times it causes
the entire system to hang.

Another problem solved with this driver is devices that do not have a device
alias can be booted and used within GRUB. Within the old ofdisk, this was not
possible, unless it was the original boot device.  All devices behind a SAS
or SCSI parent can be found.   Within the old ofdisk, finding these disks
relied on there being an alias defined.  The alias requirement is not
necessary with this new driver.  It can also find devices behind a parent
after they have been hot-plugged.  This is something that is not possible
with the old ofdisk driver.

The old ofdisk driver also incorrectly assumes that the device pointing to by a
device alias is in its true canonical form. This assumption is never made with
this new driver.

Another issue solved with this driver is that it properly caches the ihandle
for all open devices.  The old ofdisk tries to do this by caching the last
opened ihandle.  However this does not work properly because the layer above
does not use a consistent device name for the same disk when calling into the
driver.  This is because the upper layer uses the bootpath value returned within
/chosen, other times it uses the device alias, and other times it uses the
value within grub.cfg.  It does not have a way to figure out that these devices
are the same disk.  This is not a problem with this new driver.

Due to the way GRUB repeatedly opens and closes the same disk. Caching the
ihandle is important on SPARC.  Without caching, some SAS devices can take
15 - 20 minutes to get to the GRUB menu. This ihandle caching is not possible
without correctly having the canonical disk name.

When available, this driver also tries to use the deblocker #blocks and
a way of determining the disk size.

Finally and probably most importantly, this new driver is also capable of
seeing all partitions on a GPT disk.  With the old driver, the GPT
partition table can not be read and only the first partition on the disk
can be seen.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoMakefile: Allow to set file systems modules for default_payload.elf
Paul Menzel [Thu, 7 Mar 2019 11:16:06 +0000 (12:16 +0100)]
Makefile: Allow to set file systems modules for default_payload.elf

By default all file system modules are added to the GRUB coreboot
payload `default_payload.elf`. This makes the image quite big,
especially as often not all modules are needed.

Introduce the variable `FS_PAYLOAD_MODULES`, which can be used to
explicitly set file systems modules to be added.

    $ make default_payload.elf
    test -f default_payload.elf && rm default_payload.elf || true
    pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o default_payload.elf --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu affs afs bfs btrfs cbfs cpio cpio_be exfat ext2 f2fs fat hfs hfsplus iso9660 jfs minix minix2 minix2_be minix3 minix3_be minix_be newc nilfs2 ntfs odc procfs reiserfs romfs sfs squash4 tar udf ufs1 ufs1_be ufs2 xfs zfs password_pbkdf2 ' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=./coreboot.cfg
    $ ls -l default_payload.elf
    -rw-rw---- 1 joey joey 1199568 Mar  6 13:58 default_payload.elf

    $ make default_payload.elf FS_PAYLOAD_MODULES="" # ext2 already in `--modules`
    test -f default_payload.elf && rm default_payload.elf || true
    pkgdatadir=. ./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o default_payload.elf --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs' --install-modules='ls linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test serial multiboot cbmemc linux16 gzio echo help syslinuxcfg xnu  password_pbkdf2 ' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=./coreboot.cfg
    $ ls -l default_payload.elf
    -rw-rw---- 1 joey joey 832976 Mar  7 12:13 default_payload.elf

So, the resulting payload size is around 370 kB smaller. (Adding it to
the CBFS, it will be compressed, so the effective size difference will
be smaller.)

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agowindows/platform.c: Fix compilation errors
Vladimir Serbinenko [Thu, 7 Mar 2019 13:19:27 +0000 (14:19 +0100)]
windows/platform.c: Fix compilation errors

5 years agognulib: Upgrade Gnulib and switch to bootstrap tool
Colin Watson [Wed, 27 Feb 2019 10:03:55 +0000 (10:03 +0000)]
gnulib: Upgrade Gnulib and switch to bootstrap tool

Upgrade Gnulib files to 20190105.

It's much easier to maintain GRUB's use of portability support files
from Gnulib when the process is automatic and driven by a single
configuration file, rather than by maintainers occasionally running
gnulib-tool and committing the result.  Removing these
automatically-copied files from revision control also removes the
temptation to hack the output in ways that are difficult for future
maintainers to follow.  Gnulib includes a "bootstrap" program which is
designed for this.

The canonical way to bootstrap GRUB from revision control is now
"./bootstrap", but "./autogen.sh" is still useful if you just want to
generate the GRUB-specific parts of the build system.

GRUB now requires Autoconf >= 2.63 and Automake >= 1.11, in line with
Gnulib.

Gnulib source code is now placed in grub-core/lib/gnulib/ (which should
not be edited directly), and GRUB's patches are in
grub-core/lib/gnulib-patches/.  I've added a few notes to the developer
manual on how to maintain this.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agosyslinux: Fix syslinux_test in out-of-tree builds
Colin Watson [Wed, 27 Feb 2019 10:26:30 +0000 (10:26 +0000)]
syslinux: Fix syslinux_test in out-of-tree builds

syslinux_parse simplifies some filenames by removing things like ".."
segments, but the tests assumed that @abs_top_srcdir@ would be
untouched, which is not true in the case of out-of-tree builds where
@abs_top_srcdir@ may contain ".." segments.

Performing the substitution requires some awkwardness in Makefile.am due
to details of how config.status works.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoutil: Detect more I/O errors
Colin Watson [Wed, 27 Feb 2019 09:10:08 +0000 (09:10 +0000)]
util: Detect more I/O errors

Many of GRUB's utilities don't check anywhere near all the possible
write errors.  For example, if grub-install runs out of space when
copying a file, it won't notice.  There were missing checks for the
return values of write, fflush, fsync, and close (or the equivalents on
other OSes), all of which must be checked.

I tried to be consistent with the existing logging practices of the
various hostdisk implementations, but they weren't entirely consistent
to start with so I used my judgement.  The result at least looks
reasonable on GNU/Linux when I provoke a write error:

  Installing for x86_64-efi platform.
  grub-install: error: cannot copy `/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed' to `/boot/efi/EFI/debian/grubx64.efi': No space left on device.

There are more missing checks in other utilities, but this should fix
the most critical ones.

Fixes Debian bug #922741.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Steve McIntyre <93sam@debian.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
5 years agoosdep/freebsd: Fix partition calculation for EBR entries
James Clarke [Tue, 26 Feb 2019 18:40:14 +0000 (18:40 +0000)]
osdep/freebsd: Fix partition calculation for EBR entries

For EBR partitions, "start" is the relative starting sector of the EBR
header itself, whereas "offset" is the relative starting byte of the
partition's contents, excluding the EBR header and any padding. Thus we
must use "offset", and divide by the sector size to convert to sectors.

Fixes Debian bug #923253.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Reviewed-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>